MCPcopy Create free account
hub / github.com/carbonengine/trinity / AddShaderTableArguments

Function AddShaderTableArguments

shadercompiler/EffectCompilerMetal.cpp:881–957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879}
880
881void AddShaderTableArguments( ParserState& state, const std::map<Symbol*, ASTNode*>& functions )
882{
883 auto traceRays = find_if( begin( state.GetDX9Functions() ), end( state.GetDX9Functions() ), []( auto& name ) { return strcmp( name.first, "TraceRay" ) == 0; } );
884 if( traceRays == end( state.GetDX9Functions() ) )
885 {
886 return;
887 }
888
889 // Find TraceRay calls and map them to the payload type.
890 std::map<Symbol*, Type> payloadTypes;
891 // Maps function to the shader table argument symbol.
892 std::map<Symbol*, Symbol*> patchedHeaders;
893 patchedHeaders[traceRays->second] = nullptr;
894
895 // Add shader table argument to functions that end up calling TraceRay.
896 bool modified = true;
897 while( modified )
898 {
899 modified = false;
900 for( auto& func : functions )
901 {
902 func.second->Map( [&]( ASTNode* node ) {
903 if( node->GetNodeType() == NT_FUNCTION_CALL )
904 {
905 Symbol* funcSymbol = node->GetSymbol();
906 if( patchedHeaders.find( funcSymbol ) != end( patchedHeaders ) )
907 {
908 if( patchedHeaders.find( func.first ) == patchedHeaders.end() )
909 {
910 Type payloadType;
911 if( funcSymbol == traceRays->second )
912 {
913 if( auto payloadArg = node->GetChildOrNull( 7 ) )
914 {
915 payloadType = payloadArg->GetType();
916 }
917 }
918 else
919 {
920 payloadType = payloadTypes[funcSymbol];
921 }
922 auto shaderTable = CreateShaderTableArgument( state, payloadType, node->GetScope() );
923
924 ASTNode* header = func.second->GetChild( 0 );
925 header->InsertChild( 0, shaderTable );
926 patchedHeaders[func.first] = shaderTable->GetSymbol();
927 payloadTypes[func.first] = payloadType;
928
929 modified = true;
930 }
931 }
932 }
933 return node;
934 } );
935 }
936 }
937
938 // Add shader table argument to function calls.

Callers 1

CompileEffectMethod · 0.85

Calls 13

NewVarIdentifierFunction · 0.85
GetNodeTypeMethod · 0.80
GetSymbolMethod · 0.80
GetChildOrNullMethod · 0.80
GetScopeMethod · 0.80
InsertChildMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
MapMethod · 0.45
endMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected