@@ -77,7 +77,7 @@ bool ShaderCompiler::Compile( const ShaderType shaderType, const char* pShader,
7777
7878 std::vector<ShaderReflectionBinding> reflectionBindings = {};
7979 ShaderReflectionInfo shaderReflectionInfo = {};
80-
80+
8181 {
8282 slang::ProgramLayout* layout = program->getLayout ( targetIndex );
8383 auto globalScope = layout->getGlobalParamsVarLayout ();
@@ -116,12 +116,53 @@ bool ShaderCompiler::Compile( const ShaderType shaderType, const char* pShader,
116116 break ;
117117 }
118118
119- reflectionBindings.push_back ( ShaderReflectionBinding{
120- .Set = ( int )set, .Binding = ( int )binding, .Type = mochaReflectionType, .Name = name } );
119+ // get attributes
120+ auto attributeCount = param->getVariable ()->getUserAttributeCount ();
121+ spdlog::info ( " Variable {} has {} attributes" , name, attributeCount );
122+
123+ std::vector<ShaderReflectionAttribute> reflectedAttributes{};
124+
125+ for ( int attributeIndex = 0 ; attributeIndex < attributeCount; ++attributeIndex )
126+ {
127+ auto attribute = param->getVariable ()->getUserAttributeByIndex ( attributeIndex );
128+ auto attributeName = attribute->getName ();
129+
130+ auto attributeArgumentCount = attribute->getArgumentCount ();
131+
132+ ShaderReflectionAttribute reflectedAttribute;
133+
134+ if ( strcmp ( attributeName, " Default" ) == 0 )
135+ {
136+ // Default attribute
137+ reflectedAttribute.Type = SHADER_REFLECTION_ATTRIBUTE_TYPE_DEFAULT;
138+ reflectedAttribute.Data = new DefaultAttributeData ();
139+ attribute->getArgumentValueFloat ( 0 , &( ( DefaultAttributeData* )reflectedAttribute.Data )->ValueR );
140+ attribute->getArgumentValueFloat ( 1 , &( ( DefaultAttributeData* )reflectedAttribute.Data )->ValueG );
141+ attribute->getArgumentValueFloat ( 2 , &( ( DefaultAttributeData* )reflectedAttribute.Data )->ValueB );
142+ attribute->getArgumentValueFloat ( 3 , &( ( DefaultAttributeData* )reflectedAttribute.Data )->ValueA );
143+ }
144+ else if ( strcmp ( attributeName, " SrgbRead" ) == 0 )
145+ {
146+ // SRGB read attribute
147+ reflectedAttribute.Type = SHADER_REFLECTION_ATTRIBUTE_TYPE_SRGB_READ;
148+ }
149+ else
150+ {
151+ spdlog::warn ( " Unhandled attribute '{}'" , attributeName );
152+ }
153+
154+ reflectedAttributes.emplace_back ( reflectedAttribute );
155+ }
156+
157+ reflectionBindings.push_back ( ShaderReflectionBinding{ .Set = ( int )set,
158+ .Binding = ( int )binding,
159+ .Type = mochaReflectionType,
160+ .Name = name,
161+ .Attributes = UtilArray::FromVector<ShaderReflectionAttribute>( reflectedAttributes ) } );
121162 }
122163 }
123164
124- outResult.ReflectionData = ShaderReflectionInfo { .Bindings = UtilArray::FromVector ( reflectionBindings ) };
165+ outResult.ReflectionData = ShaderReflectionInfo{ .Bindings = UtilArray::FromVector ( reflectionBindings ) };
125166
126167 return true ;
127168}
0 commit comments