MCPcopy Create free account
hub / github.com/Autodesk/Aurora / compileLibrary

Method compileLibrary

Libraries/Aurora/Source/DirectX/PTShaderLibrary.cpp:196–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194const LPWSTR PTShaderLibrary::kShadowMissEntryPointName = L"ShadowMissShader";
195
196bool PTShaderLibrary::compileLibrary(const ComPtr<IDxcLibrary>& pDXCLibrary, const string source,
197 const string& name, const string& target, const string& entryPoint,
198 const vector<pair<wstring, string>>& defines, bool debug, ComPtr<IDxcBlob>& pOutput,
199 string* pErrorMessage)
200{
201 // Pass the auto-generated map of minified HLSL code to an include handler.
202 IncludeHandler includeHandler(pDXCLibrary, CommonShaders::g_sDirectory);
203
204 // Create blob from HLSL source.
205 ComPtr<IDxcBlobEncoding> pSource;
206 if (pDXCLibrary->CreateBlobWithEncodingFromPinned(
207 source.c_str(), (uint32)source.size(), CP_UTF8, pSource.GetAddressOf()) != S_OK)
208 {
209 AU_ERROR("Failed to create blob.");
210 return false;
211 }
212
213 // Build vector of argument flags to pass to compiler.
214 vector<const wchar_t*> args;
215 args.push_back(L"-WX"); // Warning as error.
216 args.push_back(L"-Zi"); // Debug info
217 if (debug)
218 {
219 args.push_back(L"-Qembed_debug"); // Embed debug info into the shader
220 args.push_back(L"-Od"); // Disable optimization
221 }
222 else
223 {
224 args.push_back(L"-O3"); // Optimization level 3
225 }
226
227 // Build DXC wide-string preprocessor defines from defines argument.
228 vector<DxcDefine> dxcDefines(defines.size());
229 vector<wstring> defValues(defines.size());
230 for (size_t i = 0; i < defines.size(); ++i)
231 {
232 // Store the wide-string value (DxcDefine points to this).
233 defValues[i] = Foundation::s2w(defines[i].second.c_str());
234 DxcDefine& m = dxcDefines[i];
235 m.Name = defines[i].first.c_str();
236 m.Value = defValues[i].c_str();
237 }
238
239 // Convert string arguments to wide-string.
240 wstring nameWide = Foundation::s2w(name);
241 wstring entryPointWide = Foundation::s2w(entryPoint);
242 wstring targetWide = Foundation::s2w(target);
243
244 // Run the compiler and get the result.
245 ComPtr<IDxcOperationResult> pCompileResult;
246 if (_pDXCompiler->Compile(pSource.Get(), nameWide.c_str(), entryPointWide.c_str(),
247 targetWide.c_str(), (LPCWSTR*)&args[0], (unsigned int)args.size(), dxcDefines.data(),
248 (uint32)dxcDefines.size(), &includeHandler, pCompileResult.GetAddressOf()) != S_OK)
249 {
250 // Print error and return false if DXC fails.
251 AU_ERROR("DXCompiler compile failed");
252 return false;
253 }

Callers

nothing calls this directly

Calls 5

s2wFunction · 0.85
GetBufferPointerMethod · 0.80
GetBufferSizeMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected