Handle fixed index lookups in array resources

This commit is contained in:
baldurk
2021-07-19 14:26:28 +01:00
parent 6130a120ef
commit a3a0aae660
3 changed files with 33 additions and 16 deletions
@@ -110,10 +110,34 @@ static bool AnnotateShader(const DXBC::DXBCContainer *dxbc, uint32_t space,
if(decl->operand.indices[1].index == decl->operand.indices[2].index)
continue;
// the operand should be relative addressing like r0.x + 6 for a t6 resource being indexed
// with [r0.x]
RDCASSERT(operand.indices[1].relative &&
operand.indices[1].index == decl->operand.indices[1].index);
bool dynamic = operand.indices[1].relative;
Operand idx;
if(dynamic)
{
// the operand should be relative addressing like r0.x + 6 for a t6 resource being indexed
// with [r0.x]
RDCASSERT(operand.indices[1].index == decl->operand.indices[1].index);
idx = operand.indices[1].operand;
// should be getting a scalar index
if(idx.comps[1] != 0xff || idx.comps[2] != 0xff || idx.comps[3] != 0xff)
{
RDCERR("Unexpected vector index for resource: %s",
operand.toString(dxbc->GetReflection(), ToString::None).c_str());
continue;
}
}
else
{
// shader could be indexing into an array with a fixed index. Handle that by subtracting the
// base manually
RDCASSERT(operand.indices[1].index >= decl->operand.indices[1].index);
idx = imm(uint32_t(operand.indices[1].index - decl->operand.indices[1].index));
}
D3D12FeedbackKey key;
key.type = operand.type;
@@ -129,21 +153,12 @@ static bool AnnotateShader(const DXBC::DXBCContainer *dxbc, uint32_t space,
continue;
}
// should be getting a scalar index
if(operand.indices[1].operand.comps[1] != 0xff ||
operand.indices[1].operand.comps[2] != 0xff || operand.indices[1].operand.comps[3] != 0xff)
{
RDCERR("Unexpected vector index for resource: %s",
operand.toString(dxbc->GetReflection(), ToString::None).c_str());
continue;
}
if(u.first == ~0U && u.second == ~0U)
u = editor.DeclareUAV(desc, space, 0, 0);
// resource base plus index
editor.InsertOperation(i++, oper(OPCODE_IADD, {temp(t).swizzle(0), imm(it->second.Slot()),
operand.indices[1].operand}));
editor.InsertOperation(i++,
oper(OPCODE_IADD, {temp(t).swizzle(0), imm(it->second.Slot()), idx}));
// multiply by 4 for byte index
editor.InsertOperation(i++,
oper(OPCODE_ISHL, {temp(t).swizzle(0), temp(t).swizzle(0), imm(2)}));
@@ -114,6 +114,7 @@ float4 main(v2f IN) : SV_Target0
{
ret *= texArray2[t.binding].SampleLevel(s, uv.xy, 0);
ret *= texArray2[t.binding+10].SampleLevel(s, uv.xy, 0);
ret *= texArray2[20].SampleLevel(s, uv.xy, 0);
}
else if(t.tex == 2)
{
@@ -53,10 +53,11 @@ class D3D12_Descriptor_Indexing(rdtest.TestCase):
# image 15 in root range 0 should also be statically used
# - images 19, 20, 21 in root range 1 should be used for the non-uniform index
# images 49 & 59 in root range 1 should be used for a second array in the same range
# image 60 in root range 1 should be used for a fixed index in an array
# image 99 and 103 in root range 1 should be used
bind_info = {
0: [8, 12],
1: [19, 20, 21, 49, 59, 99, 103],
1: [19, 20, 21, 49, 59, 60, 99, 103],
}
if len(pipe.rootElements) != 3: