diff options
Diffstat (limited to 'tools/gfx/renderer-shared.cpp')
| -rw-r--r-- | tools/gfx/renderer-shared.cpp | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index d1cedaa61..f9ffe8dfd 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -298,8 +298,17 @@ void PipelineStateBase::initializeBase(const PipelineStateDesc& inDesc) auto program = desc.getProgram(); m_program = program; - isSpecializable = (program->slangProgram && program->slangProgram->getSpecializationParamCount() != 0); - + isSpecializable = false; + if (program->slangGlobalScope && program->slangGlobalScope->getSpecializationParamCount() != 0) + isSpecializable = true; + for (auto& entryPoint : program->slangEntryPoints) + { + if (entryPoint->getSpecializationParamCount() != 0) + { + isSpecializable = true; + break; + } + } // Hold a strong reference to inputLayout and framebufferLayout objects to prevent it from // destruction. if (inDesc.type == PipelineType::Graphics) @@ -716,12 +725,12 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView( viewDesc.format = Format::Unknown; viewDesc.type = IResourceView::Type::ShaderResource; SLANG_RETURN_NULL_ON_FAIL(device->createBufferView( - bufferResource.get(), viewDesc, resourceView.writeRef())); + bufferResource.get(), nullptr, viewDesc, resourceView.writeRef())); m_structuredBufferView = static_cast<ResourceViewBase*>(resourceView.get()); viewDesc.type = IResourceView::Type::UnorderedAccess; SLANG_RETURN_NULL_ON_FAIL( device->createBufferView( - bufferResource.get(), viewDesc, resourceView.writeRef())); + bufferResource.get(), nullptr, viewDesc, resourceView.writeRef())); m_rwStructuredBufferView = static_cast<ResourceViewBase*>(resourceView.get()); } @@ -737,6 +746,57 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView( } } +void ShaderProgramBase::init(const IShaderProgram::Desc& inDesc) +{ + desc = inDesc; + + slangGlobalScope = desc.slangGlobalScope; + for (uint32_t i = 0; i < desc.entryPointCount; i++) + { + slangEntryPoints.add(ComPtr<slang::IComponentType>(desc.slangEntryPoints[i])); + } + + auto session = desc.slangGlobalScope ? desc.slangGlobalScope->getSession() : nullptr; + if (desc.linkingStyle == IShaderProgram::LinkingStyle::SingleProgram) + { + List<slang::IComponentType*> components; + if (desc.slangGlobalScope) + { + components.add(desc.slangGlobalScope); + } + for (uint32_t i = 0; i < desc.entryPointCount; i++) + { + if (!session) + { + session = desc.slangEntryPoints[i]->getSession(); + } + components.add(desc.slangEntryPoints[i]); + } + session->createCompositeComponentType( + components.getBuffer(), components.getCount(), linkedProgram.writeRef()); + } + else + { + for (uint32_t i = 0; i < desc.entryPointCount; i++) + { + if (desc.slangGlobalScope) + { + slang::IComponentType* entryPointComponents[2] = { + desc.slangGlobalScope, desc.slangEntryPoints[i]}; + ComPtr<slang::IComponentType> linkedEntryPoint; + session->createCompositeComponentType( + entryPointComponents, 2, linkedEntryPoint.writeRef()); + linkedEntryPoints.add(linkedEntryPoint); + } + else + { + linkedEntryPoints.add(ComPtr<slang::IComponentType>(desc.slangEntryPoints[i])); + } + } + linkedProgram = desc.slangGlobalScope; + } +} + Result RendererBase::maybeSpecializePipeline( PipelineStateBase* currentPipeline, ShaderObjectBase* rootObject, @@ -766,11 +826,11 @@ Result RendererBase::maybeSpecializePipeline( auto unspecializedProgram = static_cast<ShaderProgramBase*>(pipelineType == PipelineType::Compute ? currentPipeline->desc.compute.program : currentPipeline->desc.graphics.program); - auto unspecializedProgramLayout = unspecializedProgram->slangProgram->getLayout(); + auto unspecializedProgramLayout = unspecializedProgram->linkedProgram->getLayout(); ComPtr<slang::IComponentType> specializedComponentType; ComPtr<slang::IBlob> diagnosticBlob; - auto compileRs = unspecializedProgram->slangProgram->specialize( + auto compileRs = unspecializedProgram->linkedProgram->specialize( specializationArgs.components.getArrayView().getBuffer(), specializationArgs.getCount(), specializedComponentType.writeRef(), @@ -784,10 +844,18 @@ Result RendererBase::maybeSpecializePipeline( } SLANG_RETURN_ON_FAIL(compileRs); - // Now create specialized shader program using compiled binaries. + // Now create the specialized shader program using compiled binaries. ComPtr<IShaderProgram> specializedProgram; - IShaderProgram::Desc specializedProgramDesc = {}; - specializedProgramDesc.slangProgram = specializedComponentType; + IShaderProgram::Desc specializedProgramDesc = unspecializedProgram->desc; + specializedProgramDesc.slangGlobalScope = specializedComponentType; + + if (specializedProgramDesc.linkingStyle == IShaderProgram::LinkingStyle::SingleProgram) + { + // When linking style is GraphicsCompute, the specialized global scope already contains + // entry-points, so we do not need to supply them again when creating the specialized + // pipeline. + specializedProgramDesc.entryPointCount = 0; + } SLANG_RETURN_ON_FAIL(createProgram(specializedProgramDesc, specializedProgram.writeRef())); // Create specialized pipeline state. @@ -904,5 +972,17 @@ Result ShaderTableBase::init(const IShaderTable::Desc& desc) return SLANG_OK; } +bool isDepthFormat(Format format) +{ + switch (format) + { + case Format::D16_UNORM: + case Format::D32_FLOAT: + return true; + default: + return false; + } +} + } // namespace gfx |
