Skip to content

Commit fd85828

Browse files
committed
Respect scalar swizzles while preserving out-of-bounds clamp behaviour
1 parent 631144f commit fd85828

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

renderdoc/driver/shaders/dxbc/dxbc_debug.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -3440,13 +3440,17 @@ void ThreadState::StepNext(ShaderDebugState *state, DebugAPIWrapper *apiWrapper,
34403440
{
34413441
data += dataOffset;
34423442

3443+
int boundsClampedComps = 4;
3444+
34433445
uint32_t srcIdx = 1;
34443446
if(op.operation == OPCODE_LD_STRUCTURED)
34453447
{
34463448
srcIdx = 2;
34473449
fmt.byteWidth = 4;
34483450

34493451
fmt.numComps = 4;
3452+
boundsClampedComps = int((stride - structOffset) / sizeof(uint32_t));
3453+
fmt.numComps = RDCMIN(fmt.numComps, boundsClampedComps);
34503454

34513455
if(op.operands[0].comps[0] != 0xff && op.operands[0].comps[1] == 0xff &&
34523456
op.operands[0].comps[2] == 0xff && op.operands[0].comps[3] == 0xff)
@@ -3468,7 +3472,8 @@ void ThreadState::StepNext(ShaderDebugState *state, DebugAPIWrapper *apiWrapper,
34683472
fmt.numComps = 4;
34693473

34703474
// do not allow writing beyond the stride (we don't expect fxc to emit writes like this anyway)
3471-
fmt.numComps = RDCMIN(fmt.numComps, int((stride - structOffset) / sizeof(uint32_t)));
3475+
boundsClampedComps = int((stride - structOffset) / sizeof(uint32_t));
3476+
fmt.numComps = RDCMIN(fmt.numComps, boundsClampedComps);
34723477

34733478
for(int c = 0; c < 4; c++)
34743479
{
@@ -3489,7 +3494,8 @@ void ThreadState::StepNext(ShaderDebugState *state, DebugAPIWrapper *apiWrapper,
34893494
fmt.numComps = 4;
34903495

34913496
// clamp to out of bounds based on numElems
3492-
fmt.numComps = RDCMIN(fmt.numComps, int(numElems - elemIdx) / 4);
3497+
boundsClampedComps = int(numElems - elemIdx) / 4;
3498+
fmt.numComps = RDCMIN(fmt.numComps, boundsClampedComps);
34933499

34943500
if(op.operands[0].comps[0] != 0xff && op.operands[0].comps[1] == 0xff &&
34953501
op.operands[0].comps[2] == 0xff && op.operands[0].comps[3] == 0xff)
@@ -3510,7 +3516,7 @@ void ThreadState::StepNext(ShaderDebugState *state, DebugAPIWrapper *apiWrapper,
35103516
fmt.numComps = 4;
35113517

35123518
// clamp to out of bounds based on numElems
3513-
int boundsClampedComps = int(numElems - elemIdx) / 4;
3519+
boundsClampedComps = int(numElems - elemIdx) / 4;
35143520
fmt.numComps = RDCMIN(fmt.numComps, boundsClampedComps);
35153521

35163522
for(int c = 0; c < boundsClampedComps; c++)
@@ -3528,10 +3534,17 @@ void ThreadState::StepNext(ShaderDebugState *state, DebugAPIWrapper *apiWrapper,
35283534
{
35293535
ShaderVariable result = TypedUAVLoad(fmt, data);
35303536

3537+
// clamp the result to any out of bounds loads so that we don't fill in with w=1
3538+
for(int c = boundsClampedComps; c < 4; c++)
3539+
result.value.u32v[c] = 0;
3540+
35313541
// apply the swizzle on the resource operand
35323542
ShaderVariable fetch("", 0U, 0U, 0U, 0U);
35333543

3534-
for(int c = 0; c < fmt.numComps; c++)
3544+
// always process all 4 components, as this is applying a swizzle to the returned resource
3545+
// data, and we could swizzle a 1-component texture result into .y with .yxzw if we then
3546+
// go on to scalar-assign it to .y of the output
3547+
for(int c = 0; c < 4; c++)
35353548
{
35363549
uint8_t comp = resComps[c];
35373550
if(comp == 0xff)

0 commit comments

Comments
 (0)