From a3a0aae660ff69378a8ad68d241db147d9da5b4d Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 19 Jul 2021 14:26:28 +0100 Subject: [PATCH] Handle fixed index lookups in array resources --- .../driver/d3d12/d3d12_shader_feedback.cpp | 45 ++++++++++++------- .../demos/d3d12/d3d12_descriptor_indexing.cpp | 1 + .../tests/D3D12/D3D12_Descriptor_Indexing.py | 3 +- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp b/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp index 4cd9548f1..ef812d8eb 100644 --- a/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp +++ b/renderdoc/driver/d3d12/d3d12_shader_feedback.cpp @@ -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)})); diff --git a/util/test/demos/d3d12/d3d12_descriptor_indexing.cpp b/util/test/demos/d3d12/d3d12_descriptor_indexing.cpp index 379802fd1..e17a9060d 100644 --- a/util/test/demos/d3d12/d3d12_descriptor_indexing.cpp +++ b/util/test/demos/d3d12/d3d12_descriptor_indexing.cpp @@ -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) { diff --git a/util/test/tests/D3D12/D3D12_Descriptor_Indexing.py b/util/test/tests/D3D12/D3D12_Descriptor_Indexing.py index 645c21664..0da5b5a4b 100644 --- a/util/test/tests/D3D12/D3D12_Descriptor_Indexing.py +++ b/util/test/tests/D3D12/D3D12_Descriptor_Indexing.py @@ -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: