MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / build

Method build

source/MaterialXRenderSlang/SlangProgram.cpp:83–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83bool SlangProgram::build()
84{
85 using namespace rhi;
86
87 clearBuiltData();
88
89 ComPtr<slang::ISession> slangSession = _context->getDevice()->getSlangSession();
90
91 ComPtr<slang::IBlob> diagnosticsBlob;
92 std::vector<slang::IComponentType*> componentTypes;
93 StringVec diagnosticVec;
94
95 _name = _context->deduplicateName(_name);
96
97 const std::string& vertexShaderSource = _stages[Stage::VERTEX];
98 if (!vertexShaderSource.empty())
99 {
100 slang::IModule* module = slangSession->loadModuleFromSourceString(
101 (_name + "VertexShaders").c_str(),
102 (_name + ".VertexShaders").c_str(),
103 vertexShaderSource.c_str(),
104 diagnosticsBlob.writeRef());
105
106 if (diagnosticsBlob)
107 diagnosticVec.push_back((const char*) diagnosticsBlob->getBufferPointer());
108
109 if (!module)
110 throw ExceptionRenderError("Failed to compile vertex shaders", diagnosticVec);
111
112 ComPtr<slang::IEntryPoint> entryPoint;
113 SLANG_RETURN_ON_FAIL(module->findEntryPointByName("vertexMain", entryPoint.writeRef()));
114
115 componentTypes.push_back(module);
116 componentTypes.push_back(entryPoint);
117 }
118
119 const std::string& pixelShaderSource = _stages[Stage::PIXEL];
120 if (!pixelShaderSource.empty())
121 {
122 slang::IModule* module = slangSession->loadModuleFromSourceString(
123 (_name + "PixelShaders").c_str(),
124 (_name + ".PixelShaders").c_str(),
125 pixelShaderSource.c_str(),
126 diagnosticsBlob.writeRef());
127
128 if (diagnosticsBlob)
129 diagnosticVec.push_back((const char*) diagnosticsBlob->getBufferPointer());
130
131 if (!module)
132 throw ExceptionRenderError("Failed to compile frament shaders", diagnosticVec);
133
134 ComPtr<slang::IEntryPoint> entryPoint;
135 SLANG_RETURN_ON_FAIL(module->findEntryPointByName("fragmentMain", entryPoint.writeRef()));
136
137 componentTypes.push_back(module);
138 componentTypes.push_back(entryPoint);
139 }
140

Callers 3

loadSourceMethod · 0.45
generateShaderMethod · 0.45
createProgramMethod · 0.45

Calls 9

ExceptionRenderErrorFunction · 0.85
isTransparentFunction · 0.85
deduplicateNameMethod · 0.80
c_strMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected