summaryrefslogtreecommitdiffstats
path: root/tools/gfx/renderer-shared.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-03-08 14:34:53 -0800
committerGitHub <noreply@github.com>2022-03-08 14:34:53 -0800
commitdcb434a5fe801d42d1b5f385fd27d0c500687647 (patch)
tree600d63ccce42e0ca3b5c63df23013044c4cea96c /tools/gfx/renderer-shared.cpp
parent771f29435d664f7344bc5596056146af5d64d352 (diff)
GFX Vulkan: deferred shader compilation and pipeline creation. (#2153)
* Vulkan: deferred shader compilation and pipeline creation. * Fix 32bit build. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx/renderer-shared.cpp')
-rw-r--r--tools/gfx/renderer-shared.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index b476bd284..d01f6fe72 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -827,6 +827,62 @@ void ShaderProgramBase::init(const IShaderProgram::Desc& inDesc)
}
}
+Result ShaderProgramBase::compileShaders()
+{
+ // For a fully specialized program, read and store its kernel code in `shaderProgram`.
+ auto compileShader = [&](slang::EntryPointReflection* entryPointInfo,
+ slang::IComponentType* entryPointComponent,
+ SlangInt entryPointIndex)
+ {
+ auto stage = entryPointInfo->getStage();
+ ComPtr<ISlangBlob> kernelCode;
+ ComPtr<ISlangBlob> diagnostics;
+ auto compileResult = entryPointComponent->getEntryPointCode(
+ entryPointIndex, 0, kernelCode.writeRef(), diagnostics.writeRef());
+ if (diagnostics)
+ {
+ getDebugCallback()->handleMessage(
+ compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
+ DebugMessageSource::Slang,
+ (char*)diagnostics->getBufferPointer());
+ }
+ SLANG_RETURN_ON_FAIL(compileResult);
+ SLANG_RETURN_ON_FAIL(createShaderModule(entryPointInfo, kernelCode));
+ return SLANG_OK;
+ };
+
+ if (linkedEntryPoints.getCount() == 0)
+ {
+ // If the user does not explicitly specify entry point components, find them from
+ // `linkedEntryPoints`.
+ auto programReflection = linkedProgram->getLayout();
+ for (SlangUInt i = 0; i < programReflection->getEntryPointCount(); i++)
+ {
+ SLANG_RETURN_ON_FAIL(compileShader(
+ programReflection->getEntryPointByIndex(i), linkedProgram, (SlangInt)i));
+ }
+ }
+ else
+ {
+ // If the user specifies entry point components via the separated entry point array,
+ // compile code from there.
+ for (auto& entryPoint : linkedEntryPoints)
+ {
+ SLANG_RETURN_ON_FAIL(
+ compileShader(entryPoint->getLayout()->getEntryPointByIndex(0), entryPoint, 0));
+ }
+ }
+ return SLANG_OK;
+}
+
+Result ShaderProgramBase::createShaderModule(
+ slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode)
+{
+ SLANG_UNUSED(entryPointInfo);
+ SLANG_UNUSED(kernelCode);
+ return SLANG_OK;
+}
+
Result RendererBase::maybeSpecializePipeline(
PipelineStateBase* currentPipeline,
ShaderObjectBase* rootObject,