From 98afb421f408aa8651afff3dba1b21fad71131fe Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Mar 2021 13:57:55 -0700 Subject: Reimplement Vulkan shader objects. (#1764) * Reimplement Vulkan shader objects. This change reimplements Vulkan shader objects in the `gfx` layer so that it is no longer layered on top of the `DescriptorSet` abstraction. Since this is the last implementation that uses `DescriptorSet`, the change also removes all `DescriptorSet` related API from public `gfx` interface. The Vulkan implementation now passes all test cases, but it still have two issues: 1. The PushConstant setting is not correct, this is because we don't seem to be able to get correct reflection data about the size of push constants for an entry-point. 2. The `shader-toy` example can't run on Vulkan, because it currently sets nullptr to `Texture` bindings, and this change doesn't properly handle setting resource to null in `ShaderObject`s yet. If we can use the `nullDescriptor` feature on vulkan, this implementation will be simple. However we still want to decide whether we want to use a Vulkan 1.2 feature for this. * Fix up --- tools/gfx/cuda/render-cuda.cpp | 62 ++++++++++-------------------------------- 1 file changed, 15 insertions(+), 47 deletions(-) (limited to 'tools/gfx/cuda/render-cuda.cpp') diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index dbdc27628..383ccc924 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -12,7 +12,6 @@ #include "slang-com-helper.h" #include "../command-writer.h" #include "../renderer-shared.h" -#include "../render-graphics-common.h" #include "../slang-context.h" # ifdef RENDER_TEST_OPTIX @@ -1038,14 +1037,6 @@ public: m_writer->bindRootShaderObject(PipelineType::Compute, object); } - virtual SLANG_NO_THROW void SLANG_MCALL setDescriptorSet( - IPipelineLayout* layout, - UInt index, - IDescriptorSet* descriptorSet) override - { - m_writer->setDescriptorSet(PipelineType::Compute, layout, index, descriptorSet); - } - virtual SLANG_NO_THROW void SLANG_MCALL dispatchCompute(int x, int y, int z) override { m_writer->dispatchCompute(x, y, z); @@ -1861,27 +1852,29 @@ public: // If this is a specializable program, we just keep a reference to the slang program and // don't actually create any kernels. This program will be specialized later when we know // the shader object bindings. - if (desc.slangProgram && desc.slangProgram->getSpecializationParamCount() != 0) + RefPtr cudaProgram = new CUDAShaderProgram(); + cudaProgram->slangProgram = desc.slangProgram; + if (desc.slangProgram->getSpecializationParamCount() != 0) { - RefPtr cudaProgram = new CUDAShaderProgram(); - cudaProgram->slangProgram = desc.slangProgram; cudaProgram->layout = new CUDAProgramLayout(this, desc.slangProgram->getLayout()); *outProgram = cudaProgram.detach(); return SLANG_OK; } - if( desc.kernelCount == 0 ) + ComPtr kernelCode; + ComPtr diagnostics; + auto compileResult = desc.slangProgram->getEntryPointCode( + (SlangInt)0, 0, kernelCode.writeRef(), diagnostics.writeRef()); + if (diagnostics) { - return createProgramFromSlang(this, desc, outProgram); + // TODO: report compile error. } - - if (desc.kernelCount != 1) - return SLANG_E_INVALID_ARG; - RefPtr cudaProgram = new CUDAShaderProgram(); - SLANG_CUDA_RETURN_ON_FAIL(cuModuleLoadData(&cudaProgram->cudaModule, desc.kernels[0].codeBegin)); - SLANG_CUDA_RETURN_ON_FAIL( - cuModuleGetFunction(&cudaProgram->cudaKernel, cudaProgram->cudaModule, desc.kernels[0].entryPointName)); - cudaProgram->kernelName = desc.kernels[0].entryPointName; + SLANG_RETURN_ON_FAIL(compileResult); + + SLANG_CUDA_RETURN_ON_FAIL(cuModuleLoadData(&cudaProgram->cudaModule, kernelCode->getBufferPointer())); + cudaProgram->kernelName = desc.slangProgram->getLayout()->getEntryPointByIndex(0)->getName(); + SLANG_CUDA_RETURN_ON_FAIL(cuModuleGetFunction( + &cudaProgram->cudaKernel, cudaProgram->cudaModule, cudaProgram->kernelName.getBuffer())); auto slangProgram = desc.slangProgram; if( slangProgram ) @@ -1985,31 +1978,6 @@ public: return SLANG_E_NOT_AVAILABLE; } - virtual SLANG_NO_THROW Result SLANG_MCALL createDescriptorSetLayout( - const IDescriptorSetLayout::Desc& desc, IDescriptorSetLayout** outLayout) override - { - SLANG_UNUSED(desc); - SLANG_UNUSED(outLayout); - return SLANG_E_NOT_AVAILABLE; - } - - virtual SLANG_NO_THROW Result SLANG_MCALL - createPipelineLayout(const IPipelineLayout::Desc& desc, IPipelineLayout** outLayout) override - { - SLANG_UNUSED(desc); - SLANG_UNUSED(outLayout); - return SLANG_E_NOT_AVAILABLE; - } - - virtual SLANG_NO_THROW Result SLANG_MCALL - createDescriptorSet(IDescriptorSetLayout* layout, IDescriptorSet::Flag::Enum flags, IDescriptorSet** outDescriptorSet) override - { - SLANG_UNUSED(layout); - SLANG_UNUSED(flags); - SLANG_UNUSED(outDescriptorSet); - return SLANG_E_NOT_AVAILABLE; - } - virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState( const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override { -- cgit v1.2.3