Add sampler slots usage and inputs/outputs count to GPU shader program bindings meta

This commit is contained in:
Wojtek Figat
2026-02-26 12:02:52 +01:00
parent ac4526744a
commit 20c9ed27fb
7 changed files with 35 additions and 14 deletions

View File

@@ -79,6 +79,9 @@ namespace
{
bool ProcessShader(ShaderCompilationContext* context, Array<ShaderCompiler::ShaderResourceBuffer>& constantBuffers, ID3D11ShaderReflection* reflector, D3D11_SHADER_DESC& desc, ShaderBindings& bindings)
{
bindings.InputsCount = desc.InputParameters;
bindings.OutputsCount = desc.OutputParameters;
// Extract constant buffers usage information
for (uint32 a = 0; a < desc.ConstantBuffers; a++)
{
@@ -131,13 +134,12 @@ namespace
{
// Sampler
case D3D_SIT_SAMPLER:
bindings.UsedSamplersMask |= 1 << resDesc.BindPoint;
break;
// Constant Buffer
case D3D_SIT_CBUFFER:
case D3D_SIT_TBUFFER:
break;
// Shader Resource
case D3D_SIT_TEXTURE:
case D3D_SIT_STRUCTURED:
@@ -145,7 +147,6 @@ namespace
for (UINT shift = 0; shift < resDesc.BindCount; shift++)
bindings.UsedSRsMask |= 1 << (resDesc.BindPoint + shift);
break;
// Unordered Access
case D3D_SIT_UAV_RWTYPED:
case D3D_SIT_UAV_RWSTRUCTURED:
@@ -316,7 +317,7 @@ bool ShaderCompilerD3D::CompileShader(ShaderFunctionMeta& meta, WritePermutation
additionalDataVS.Inputs.Add({ ParseVertexElementType(inputDesc.SemanticName, inputDesc.SemanticIndex), 0, 0, 0, format });
}
}
ShaderBindings bindings = { desc.InstructionCount, 0, 0, 0 };
ShaderBindings bindings = { desc.InstructionCount };
if (ProcessShader(_context, _constantBuffers, reflector.Get(), desc, bindings))
return true;

View File

@@ -372,7 +372,9 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
}
DxShaderHeader header;
Platform::MemoryClear(&header, sizeof(header));
ShaderBindings bindings = { desc.InstructionCount, 0, 0, 0 };
ShaderBindings bindings = { desc.InstructionCount };
bindings.InputsCount = desc.InputParameters;
bindings.OutputsCount = desc.OutputParameters;
for (uint32 a = 0; a < desc.ConstantBuffers; a++)
{
auto cb = shaderReflection->GetConstantBufferByIndex(a);
@@ -422,13 +424,12 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
{
// Sampler
case D3D_SIT_SAMPLER:
bindings.UsedSamplersMask |= 1 << resDesc.BindPoint;
break;
// Constant Buffer
case D3D_SIT_CBUFFER:
case D3D_SIT_TBUFFER:
break;
// Shader Resource
case D3D_SIT_TEXTURE:
for (UINT shift = 0; shift < resDesc.BindCount; shift++)
@@ -445,7 +446,6 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
header.SrDimensions[resDesc.BindPoint + shift] = D3D_SRV_DIMENSION_BUFFER;
}
break;
// Unordered Access
case D3D_SIT_UAV_RWTYPED:
case D3D_SIT_UAV_RWSTRUCTURED:

View File

@@ -728,7 +728,9 @@ bool ShaderCompilerVulkan::CompileShader(ShaderFunctionMeta& meta, WritePermutat
void* additionalData = nullptr;
SpirvShaderHeader header;
Platform::MemoryClear(&header, sizeof(header));
ShaderBindings bindings = { 0, 0, 0, 0 };
ShaderBindings bindings = {};
bindings.InputsCount = program.getNumPipeInputs();
bindings.OutputsCount = program.getNumPipeOutputs();
if (type == ShaderStage::Vertex)
{
additionalData = &additionalDataVS;
@@ -822,6 +824,10 @@ bool ShaderCompilerVulkan::CompileShader(ShaderFunctionMeta& meta, WritePermutat
switch (descriptor.BindingType)
{
case SpirvShaderResourceBindingType::SAMPLER:
ASSERT_LOW_LAYER(descriptor.Slot >= 0 && descriptor.Slot < GPU_MAX_SAMPLER_BINDED);
bindings.UsedSamplersMask |= 1 << descriptor.Slot;
break;
case SpirvShaderResourceBindingType::CB:
ASSERT_LOW_LAYER(descriptor.Slot >= 0 && descriptor.Slot < GPU_MAX_CB_BINDED);
bindings.UsedCBsMask |= 1 << descriptor.Slot;