From dcb434a5fe801d42d1b5f385fd27d0c500687647 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 8 Mar 2022 14:34:53 -0800 Subject: GFX Vulkan: deferred shader compilation and pipeline creation. (#2153) * Vulkan: deferred shader compilation and pipeline creation. * Fix 32bit build. Co-authored-by: Yong He --- tools/gfx/renderer-shared.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tools/gfx/renderer-shared.cpp') 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 kernelCode; + ComPtr 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 kernelCode) +{ + SLANG_UNUSED(entryPointInfo); + SLANG_UNUSED(kernelCode); + return SLANG_OK; +} + Result RendererBase::maybeSpecializePipeline( PipelineStateBase* currentPipeline, ShaderObjectBase* rootObject, -- cgit v1.2.3