diff options
| author | Yong He <yonghe@outlook.com> | 2021-03-24 13:57:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-24 13:57:55 -0700 |
| commit | 98afb421f408aa8651afff3dba1b21fad71131fe (patch) | |
| tree | a8610d12ac7d74a8772cb6ecdd810da8216baa67 /examples/gpu-printing/main.cpp | |
| parent | d0f7b7f0ed1d0d1388ce944cd1ad906bbd9afb35 (diff) | |
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
Diffstat (limited to 'examples/gpu-printing/main.cpp')
| -rw-r--r-- | examples/gpu-printing/main.cpp | 56 |
1 files changed, 3 insertions, 53 deletions
diff --git a/examples/gpu-printing/main.cpp b/examples/gpu-printing/main.cpp index 3fd1e460a..0315d4827 100644 --- a/examples/gpu-printing/main.cpp +++ b/examples/gpu-printing/main.cpp @@ -56,9 +56,7 @@ ComPtr<slang::ISession> gSlangSession; ComPtr<slang::IModule> gSlangModule; ComPtr<gfx::IShaderProgram> gProgram; -ComPtr<gfx::IPipelineLayout> gPipelineLayout; ComPtr<gfx::IPipelineState> gPipelineState; -ComPtr<gfx::IDescriptorSet> gDescriptorSet; Slang::Dictionary<int, std::string> gHashedStrings; @@ -74,21 +72,9 @@ ComPtr<gfx::IShaderProgram> loadComputeProgram(slang::IModule* slangModule, char gGPUPrinting.loadStrings(linkedProgram->getLayout()); - ComPtr<ISlangBlob> codeBlob; - linkedProgram->getEntryPointCode(0, 0, codeBlob.writeRef()); - - char const* code = (char const*) codeBlob->getBufferPointer(); - char const* codeEnd = code + codeBlob->getBufferSize(); - - gfx::IShaderProgram::KernelDesc kernelDescs[] = - { - { gfx::StageType::Compute, code, codeEnd }, - }; - gfx::IShaderProgram::Desc programDesc = {}; programDesc.pipelineType = gfx::PipelineType::Compute; - programDesc.kernels = &kernelDescs[0]; - programDesc.kernelCount = 2; + programDesc.slangProgram = linkedProgram; auto shaderProgram = gDevice->createProgram(programDesc); @@ -107,40 +93,7 @@ Result execute() gProgram = loadComputeProgram(gSlangModule, "computeMain"); if(!gProgram) return SLANG_FAIL; - IDescriptorSetLayout::SlotRangeDesc slotRanges[] = - { - IDescriptorSetLayout::SlotRangeDesc(DescriptorSlotType::StorageBuffer), - }; - IDescriptorSetLayout::Desc descriptorSetLayoutDesc; - descriptorSetLayoutDesc.slotRangeCount = 1; - descriptorSetLayoutDesc.slotRanges = &slotRanges[0]; - auto descriptorSetLayout = gDevice->createDescriptorSetLayout(descriptorSetLayoutDesc); - if(!descriptorSetLayout) return SLANG_FAIL; - - IPipelineLayout::DescriptorSetDesc descriptorSets[] = - { - IPipelineLayout::DescriptorSetDesc( descriptorSetLayout ), - }; - IPipelineLayout::Desc pipelineLayoutDesc; - pipelineLayoutDesc.renderTargetCount = 1; - pipelineLayoutDesc.descriptorSetCount = 1; - pipelineLayoutDesc.descriptorSets = &descriptorSets[0]; - auto pipelineLayout = gDevice->createPipelineLayout(pipelineLayoutDesc); - if(!pipelineLayout) return SLANG_FAIL; - - gPipelineLayout = pipelineLayout; - - // Once we have the descriptor set layout, we can allocate - // and fill in a descriptor set to hold our parameters. - // - auto descriptorSet = - gDevice->createDescriptorSet(descriptorSetLayout, IDescriptorSet::Flag::Transient); - if(!descriptorSet) return SLANG_FAIL; - - gDescriptorSet = descriptorSet; - ComputePipelineStateDesc desc; - desc.pipelineLayout = gPipelineLayout; desc.program = gProgram; auto pipelineState = gDevice->createComputePipelineState(desc); if(!pipelineState) return SLANG_FAIL; @@ -164,12 +117,9 @@ Result execute() auto queue = gDevice->createCommandQueue(queueDesc); auto commandBuffer = queue->createCommandBuffer(); auto encoder = commandBuffer->encodeComputeCommands(); - // TODO: need to copy a zero into the start of the print buffer! - - gDescriptorSet->setResource(0, 0, printBufferView); - encoder->setDescriptorSet(gPipelineLayout, 0, gDescriptorSet); - + auto rootShaderObject = gDevice->createRootShaderObject(gProgram); encoder->setPipelineState(gPipelineState); + encoder->bindRootShaderObject(rootShaderObject); encoder->dispatchCompute(1, 1, 1); encoder->endEncoding(); commandBuffer->close(); |
