Fix UsedSRsMask/UsedUAsMask when binding arrays to the shader

This commit is contained in:
Wojciech Figat
2022-03-22 12:55:13 +01:00
parent d58584e1fd
commit c10cdc3d90
12 changed files with 250 additions and 265 deletions

View File

@@ -381,13 +381,19 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
// Shader Resource
case D3D_SIT_TEXTURE:
bindings.UsedSRsMask |= 1 << resDesc.BindPoint;
header.SrDimensions[resDesc.BindPoint] = resDesc.Dimension;
for (UINT shift = 0; shift < resDesc.BindCount; shift++)
{
bindings.UsedSRsMask |= 1 << (resDesc.BindPoint + shift);
header.SrDimensions[resDesc.BindPoint + shift] = resDesc.Dimension;
}
break;
case D3D_SIT_STRUCTURED:
case D3D_SIT_BYTEADDRESS:
bindings.UsedSRsMask |= 1 << resDesc.BindPoint;
header.SrDimensions[resDesc.BindPoint] = D3D_SRV_DIMENSION_BUFFER;
for (UINT shift = 0; shift < resDesc.BindCount; shift++)
{
bindings.UsedSRsMask |= 1 << (resDesc.BindPoint + shift);
header.SrDimensions[resDesc.BindPoint + shift] = D3D_SRV_DIMENSION_BUFFER;
}
break;
// Unordered Access
@@ -397,30 +403,10 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
case D3D_SIT_UAV_APPEND_STRUCTURED:
case D3D_SIT_UAV_CONSUME_STRUCTURED:
case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
bindings.UsedUAsMask |= 1 << resDesc.BindPoint;
switch (resDesc.Dimension)
for (UINT shift = 0; shift < resDesc.BindCount; shift++)
{
case D3D_SRV_DIMENSION_BUFFER:
header.UaDimensions[resDesc.BindPoint] = 1; // D3D12_UAV_DIMENSION_BUFFER;
break;
case D3D_SRV_DIMENSION_TEXTURE1D:
header.UaDimensions[resDesc.BindPoint] = 2; // D3D12_UAV_DIMENSION_TEXTURE1D;
break;
case D3D_SRV_DIMENSION_TEXTURE1DARRAY:
header.UaDimensions[resDesc.BindPoint] = 3; // D3D12_UAV_DIMENSION_TEXTURE1DARRAY;
break;
case D3D_SRV_DIMENSION_TEXTURE2D:
header.UaDimensions[resDesc.BindPoint] = 4; // D3D12_UAV_DIMENSION_TEXTURE2D;
break;
case D3D_SRV_DIMENSION_TEXTURE2DARRAY:
header.UaDimensions[resDesc.BindPoint] = 5; // D3D12_UAV_DIMENSION_TEXTURE2DARRAY;
break;
case D3D_SRV_DIMENSION_TEXTURE3D:
header.UaDimensions[resDesc.BindPoint] = 8; // D3D12_UAV_DIMENSION_TEXTURE3D;
break;
default:
LOG(Error, "Unknown UAV resource {2} of type {0} at slot {1}", resDesc.Dimension, resDesc.BindPoint, String(resDesc.Name));
return true;
bindings.UsedUAsMask |= 1 << (resDesc.BindPoint + shift);
header.SrDimensions[resDesc.BindPoint + shift] = (byte)resDesc.Dimension; // D3D_SRV_DIMENSION matches D3D12_UAV_DIMENSION
}
break;
}