NAP
Public Member Functions | Public Attributes | List of all members
ShaderConstantInstance Class Reference

#include <shaderconstant.h>

Public Member Functions

 ShaderConstantInstance (const ShaderConstantDeclaration &declaration, const ShaderConstant *constant)
 
const ShaderConstantDeclarationgetDeclaration () const
 
const uint getValue () const
 

Public Attributes

const ShaderConstantDeclarationmDeclaration
 
const ShaderConstantmConstant = nullptr
 
uint mValue = 0
 

Description

Shader constant instance. Assigns a unsigned integer constant to a material instance.

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
}
Collaboration diagram for ShaderConstantInstance:
[legend]

Constructor & Destructor Documentation

◆ ShaderConstantInstance()

ShaderConstantInstance ( const ShaderConstantDeclaration declaration,
const ShaderConstant constant 
)

Member Function Documentation

◆ getDeclaration()

const ShaderConstantDeclaration& getDeclaration ( ) const
Returns
constant declaration

◆ getValue()

const uint getValue ( ) const
Returns
constant value

Member Data Documentation

◆ mConstant

const ShaderConstant* mConstant = nullptr

◆ mDeclaration

const ShaderConstantDeclaration& mDeclaration

◆ mValue

uint mValue = 0