diff options
Diffstat (limited to 'tools/render-test/shader-renderer-util.cpp')
| -rw-r--r-- | tools/render-test/shader-renderer-util.cpp | 295 |
1 files changed, 0 insertions, 295 deletions
diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp index 903164567..ede744445 100644 --- a/tools/render-test/shader-renderer-util.cpp +++ b/tools/render-test/shader-renderer-util.cpp @@ -7,30 +7,6 @@ namespace renderer_test { using namespace Slang; using Slang::Result; -void BindingStateImpl::apply(ICommandEncoder* encoder, PipelineType pipelineType) -{ - switch (pipelineType) - { - case PipelineType::Compute: - { - ComPtr<IComputeCommandEncoder> computeEncoder; - encoder->queryInterface(SLANG_UUID_IComputeCommandEncoder, (void**)computeEncoder.writeRef()); - computeEncoder->setDescriptorSet(pipelineLayout, 0, descriptorSet); - } - break; - case PipelineType::Graphics: - { - ComPtr<IRenderCommandEncoder> renderEncoder; - encoder->queryInterface( - SLANG_UUID_IRenderCommandEncoder, (void**)renderEncoder.writeRef()); - renderEncoder->setDescriptorSet(pipelineLayout, 0, descriptorSet); - } - break; - default: - throw "unknown pipeline type"; - } -} - /* static */ Result ShaderRendererUtil::generateTextureResource( const InputTextureDesc& inputDesc, int bindFlags, @@ -178,275 +154,4 @@ ComPtr<ISamplerState> _createSamplerState(IDevice* device, return device->createSamplerState(_calcSamplerDesc(srcDesc)); } -/* static */ Result ShaderRendererUtil::createBindingState( - const ShaderInputLayout& layout, - IDevice* device, - IBufferResource* addedConstantBuffer, - BindingStateImpl** outBindingState) -{ - auto srcEntries = layout.entries.getBuffer(); - auto numEntries = layout.entries.getCount(); - - const int textureBindFlags = IResource::BindFlag::NonPixelShaderResource | IResource::BindFlag::PixelShaderResource; - - List<IDescriptorSetLayout::SlotRangeDesc> slotRangeDescs; - List<Index> mapEntryToSlotRange; - - if(addedConstantBuffer) - { - IDescriptorSetLayout::SlotRangeDesc slotRangeDesc; - slotRangeDesc.type = DescriptorSlotType::UniformBuffer; - - slotRangeDescs.add(slotRangeDesc); - } - - for (Index i = 0; i < numEntries; i++) - { - const ShaderInputLayoutEntry& srcEntry = srcEntries[i]; - SLANG_ASSERT(srcEntry.onlyCPULikeBinding == false); - - mapEntryToSlotRange.add(slotRangeDescs.getCount()); - IDescriptorSetLayout::SlotRangeDesc slotRangeDesc; - - switch (srcEntry.type) - { - case ShaderInputType::Buffer: - { - const InputBufferDesc& srcBuffer = srcEntry.bufferDesc; - - switch (srcBuffer.type) - { - case InputBufferType::ConstantBuffer: - slotRangeDesc.type = DescriptorSlotType::UniformBuffer; - break; - - case InputBufferType::StorageBuffer: - slotRangeDesc.type = DescriptorSlotType::StorageBuffer; - break; - - case InputBufferType::RootConstantBuffer: - { - // A root constant buffer maps to a root constant range - // where the `count` of slots is equal to the number - // of bytes of data. - // - Slang::UInt size = srcEntry.bufferData.getCount() * sizeof(srcEntry.bufferData[0]); - slotRangeDesc.type = DescriptorSlotType::RootConstant; - slotRangeDesc.count = size; - } - break; - } - } - break; - - case ShaderInputType::CombinedTextureSampler: - { - slotRangeDesc.type = DescriptorSlotType::CombinedImageSampler; - } - break; - - case ShaderInputType::Texture: - { - if (srcEntry.textureDesc.isRWTexture) - { - slotRangeDesc.type = DescriptorSlotType::StorageImage; - } - else - { - slotRangeDesc.type = DescriptorSlotType::SampledImage; - } - } - break; - - case ShaderInputType::Sampler: - slotRangeDesc.type = DescriptorSlotType::Sampler; - break; - - case ShaderInputType::Object: - // We ignore the `Object` case here, knowing that it is meant for the shader-object path. - continue; - - default: - assert(!"Unhandled type"); - return SLANG_FAIL; - } - slotRangeDescs.add(slotRangeDesc); - } - - IDescriptorSetLayout::Desc descriptorSetLayoutDesc; - descriptorSetLayoutDesc.slotRangeCount = slotRangeDescs.getCount(); - descriptorSetLayoutDesc.slotRanges = slotRangeDescs.getBuffer(); - - auto descriptorSetLayout = device->createDescriptorSetLayout(descriptorSetLayoutDesc); - if(!descriptorSetLayout) return SLANG_FAIL; - - List<IPipelineLayout::DescriptorSetDesc> pipelineDescriptorSets; - pipelineDescriptorSets.add(IPipelineLayout::DescriptorSetDesc(descriptorSetLayout)); - - IPipelineLayout::Desc pipelineLayoutDesc; - pipelineLayoutDesc.renderTargetCount = layout.numRenderTargets; - pipelineLayoutDesc.descriptorSetCount = pipelineDescriptorSets.getCount(); - pipelineLayoutDesc.descriptorSets = pipelineDescriptorSets.getBuffer(); - - auto pipelineLayout = device->createPipelineLayout(pipelineLayoutDesc); - if(!pipelineLayout) return SLANG_FAIL; - - auto descriptorSet = - device->createDescriptorSet(descriptorSetLayout, IDescriptorSet::Flag::Transient); - if(!descriptorSet) return SLANG_FAIL; - - List<BindingStateImpl::OutputBinding> outputBindings; - - if(addedConstantBuffer) - { - descriptorSet->setConstantBuffer(0, 0, addedConstantBuffer); - } - for (int i = 0; i < numEntries; i++) - { - const ShaderInputLayoutEntry& srcEntry = srcEntries[i]; - - auto rangeIndex = mapEntryToSlotRange[i]; - - switch (srcEntry.type) - { - case ShaderInputType::Buffer: - { - const InputBufferDesc& srcBuffer = srcEntry.bufferDesc; - const size_t bufferSize = srcEntry.bufferData.getCount() * sizeof(uint32_t); - - if( srcBuffer.type == InputBufferType::RootConstantBuffer ) - { - // A root constant buffer at the HLSL/Slang level actually - // maps to root constant data stored directly in the descriptor - // set, and thus does not need/want us to allocate a buffer - // to hold the data. - // - // Instead, we set the data directly here and then bypass - // the logic that handles the buffer-backed cases below. - // - descriptorSet->setRootConstants(rangeIndex, 0, bufferSize, srcEntry.bufferData.getBuffer()); - break; - } - - ComPtr<IBufferResource> bufferResource; - SLANG_RETURN_ON_FAIL(createBufferResource( - srcEntry.bufferDesc, - srcEntry.isOutput, - bufferSize, - srcEntry.bufferData.getBuffer(), - device, - bufferResource)); - - switch(srcBuffer.type) - { - case InputBufferType::ConstantBuffer: - descriptorSet->setConstantBuffer(rangeIndex, 0, bufferResource); - break; - - case InputBufferType::StorageBuffer: - { - IResourceView::Desc viewDesc; - viewDesc.type = IResourceView::Type::UnorderedAccess; - viewDesc.format = srcBuffer.format; - auto bufferView = device->createBufferView( - bufferResource, - viewDesc); - descriptorSet->setResource(rangeIndex, 0, bufferView); - } - break; - } - - if(srcEntry.isOutput) - { - BindingStateImpl::OutputBinding binding; - binding.entryIndex = i; - binding.resource = bufferResource; - outputBindings.add(binding); - } - } - break; - - case ShaderInputType::CombinedTextureSampler: - { - ComPtr<ITextureResource> texture; - SLANG_RETURN_ON_FAIL(generateTextureResource( - srcEntry.textureDesc, textureBindFlags, device, texture)); - - auto sampler = _createSamplerState(device, srcEntry.samplerDesc); - - IResourceView::Desc viewDesc; - viewDesc.type = IResourceView::Type::ShaderResource; - auto textureView = device->createTextureView( - texture, - viewDesc); - - descriptorSet->setCombinedTextureSampler(rangeIndex, 0, textureView, sampler); - - if(srcEntry.isOutput) - { - BindingStateImpl::OutputBinding binding; - binding.entryIndex = i; - binding.resource = texture; - outputBindings.add(binding); - } - } - break; - - case ShaderInputType::Texture: - { - ComPtr<ITextureResource> texture; - SLANG_RETURN_ON_FAIL(generateTextureResource( - srcEntry.textureDesc, textureBindFlags, device, texture)); - - // TODO: support UAV textures... - - IResourceView::Desc viewDesc; - viewDesc.type = IResourceView::Type::ShaderResource; - auto textureView = device->createTextureView( - texture, - viewDesc); - - if (!textureView) - { - return SLANG_FAIL; - } - - descriptorSet->setResource(rangeIndex, 0, textureView); - - if(srcEntry.isOutput) - { - BindingStateImpl::OutputBinding binding; - binding.entryIndex = i; - binding.resource = texture; - outputBindings.add(binding); - } - } - break; - - case ShaderInputType::Sampler: - { - auto sampler = _createSamplerState(device, srcEntry.samplerDesc); - descriptorSet->setSampler(rangeIndex, 0, sampler); - } - break; - - case ShaderInputType::Object: - break; - - default: - assert(!"Unhandled type"); - return SLANG_FAIL; - } - } - - BindingStateImpl* bindingState = new BindingStateImpl(); - bindingState->descriptorSet = descriptorSet; - bindingState->pipelineLayout = pipelineLayout; - bindingState->outputBindings = outputBindings; - bindingState->m_numRenderTargets = layout.numRenderTargets; - - *outBindingState = bindingState; - return SLANG_OK; -} - } // renderer_test |
