NAP
Public Attributes | List of all members
ShaderConstant Class Reference

#include <shaderconstant.h>

Public Attributes

std::string mName
 Property: 'Name' The name of the specialization constant variable in the shader interface. More...
 
uint mValue = 0
 Property: 'Value' The value to overwrite the default specialization constant variable with. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual bool init (utility::ErrorState &errorState)
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 
- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Shader constant resource. Assigns an unsigned integer constant to a material.

Shaders are parsed on initialization, but not actually compiled until creation of a graphics pipeline. Shader constants implement Vulkan specialization constants and are a powerful way to compile specialized versions of shaders per material instance. Graphics and compute pipeline keys are distinguished by a shader constant hash that is generated from the material instance resource. This way you can benefit from compiler optimizations like loop unrolling and branch elimination per material setup.

layout (constant_id = 0) const uint SAMPLE_COUNT = 8;
layout (constant_id = 1) const uint USE_EXPENSIVE_ROUTINE = 0;
// main()
// Loop unrolling
for (uint i = 0; i < SAMPLE_COUNT; i++)
{
// Perform expensive texture samples here
}
// Branch elimination
if (USE_EXPENSIVE_ROUTINE > 0)
{
// Perform an expensive computation here
}
else
{
// Exit early here
}
Inheritance diagram for ShaderConstant:
[legend]
Collaboration diagram for ShaderConstant:
[legend]

Member Data Documentation

◆ mName

std::string mName

Property: 'Name' The name of the specialization constant variable in the shader interface.

◆ mValue

uint mValue = 0

Property: 'Value' The value to overwrite the default specialization constant variable with.