Skip to content

Commit 7a1c0bd

Browse files
jeffnntex3d
authored andcommitted
PIX SM 6.6 resource access tracking (#3594)
This change updates the existing PIX resource-tracking code to handle dynamic resources (and SM6.6's resource binding apparatus in general). The output UAV is now segmented into three parts: the original formatted buffer at the beginning, for old-style createHandle resources, followed by a block for resource (texture, buffer etc) access, followed by a block for sampler access. The latter two are divided into 8-byte records. The first dword records writes to a resource/sampler, the second reads. The writes are encoded bit fields denoting the access performed by the shader. (cherry picked from commit 880c135)
1 parent feef2ff commit 7a1c0bd

10 files changed

Lines changed: 544 additions & 140 deletions

lib/DxilPIXPasses/DxilShaderAccessTracking.cpp

Lines changed: 428 additions & 134 deletions
Large diffs are not rendered by default.

tools/clang/test/HLSLFileCheck/pix/AccessTracking.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %dxc -ECSMain -Tcs_6_0 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=S0:1:1i1;U0:2:10i0;.. | %FileCheck %s
1+
// RUN: %dxc -ECSMain -Tcs_6_0 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=S0:1:1i1;U0:2:10i0;.0;0;0. | %FileCheck %s
22

33
// Check we added the UAV:
44
// CHECK: %PIX_CountUAV_Handle = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 1, i32 0, i1 false)

tools/clang/test/HLSLFileCheck/pix/AccessTrackingForSamplerFeedback.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %dxc -Emain -Tcs_6_5 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=M0:0:1i0;S0:1:1i0;U0:2:10i0;.. | %FileCheck %s
1+
// RUN: %dxc -Emain -Tcs_6_5 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=M0:0:1i0;S0:1:1i0;U0:2:10i0;.0;0;0. | %FileCheck %s
22

33
// Check we added the UAV:
44
// CHECK: %PIX_CountUAV_Handle = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 1, i32 0, i1 false)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %dxc -EMain -Tcs_6_6 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=.256;512;1024. | %FileCheck %s
2+
3+
static RWByteAddressBuffer DynamicBuffer = ResourceDescriptorHeap[1];
4+
[numthreads(1, 1, 1)]
5+
void Main()
6+
{
7+
uint val = DynamicBuffer.Load(0u);
8+
DynamicBuffer.Store(0u, val);
9+
}
10+
11+
// check it's 6.6:
12+
// CHECK: call %dx.types.Handle @dx.op.createHandleFromBinding
13+
14+
// Check we wrote to the PIX UAV:
15+
// CHECK: call void @dx.op.bufferStore.i32
16+
17+
// Offset for buffer Load should be 256 + 8 (skip out-of-bounds record) + 8 (it's the 1th resource) + 4 (offset to the "read" field) = 276
18+
// The large integer is encoded flags for the ResourceAccessStyle (an enumerated type in lib\DxilPIXPasses\DxilShaderAccessTracking.cpp) for this access
19+
// CHECK:i32 276, i32 undef, i32 1375731712
20+
// CHECK:rawBufferLoad
21+
22+
// Offset for buffer Store should be 256 + 8 (skip out-of-bounds record) + 8 (it's the 1th resource) + 0 (offset to the "write" field) = 272
23+
// The large integer is encoded flags for the ResourceAccessStyle (an enumerated type in lib\DxilPIXPasses\DxilShaderAccessTracking.cpp) for this access
24+
// CHECK:i32 272, i32 undef, i32 1392508928
25+
// CHECK:rawBufferStore
26+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %dxc -EMain -Tcs_6_6 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=.256;272;1024. | %FileCheck %s
2+
3+
static RWByteAddressBuffer DynamicBuffer = ResourceDescriptorHeap[1];
4+
[numthreads(1, 1, 1)]
5+
void Main()
6+
{
7+
uint val = DynamicBuffer.Load(0u);
8+
DynamicBuffer.Store(0u, val);
9+
}
10+
11+
// check it's 6.6:
12+
// CHECK: call %dx.types.Handle @dx.op.createHandleFromBinding
13+
14+
// The start of resource records has been passed in as 256. The limit of resource records is 272. 272-256 = 16.
15+
// 8 bytes per record means we have one record for out-of-bounds (that comes first), and one record for resource index 0.
16+
// The above HLSL references resource descriptor 1, so is out-of-bounds. Offset for out-of-bounds should thus be 256:
17+
// The large integer is encoded flags for the ResourceAccessStyle (an enumerated type in lib\DxilPIXPasses\DxilShaderAccessTracking.cpp) for this access
18+
// CHECK:i32 256, i32 undef, i32 1375731712
19+
// CHECK:rawBufferLoad
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %dxc -EMain -Tps_6_6 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=S0:1:1i1;.256;512;1024. | %FileCheck %s
2+
3+
static sampler sampler0 = SamplerDescriptorHeap[0];
4+
static sampler sampler3 = SamplerDescriptorHeap[3];
5+
Texture2D tx : register(t2);
6+
7+
float4 Main() : SV_Target
8+
{
9+
float4 a = tx.Sample(sampler0, float2(0,0));
10+
float4 b = tx.Sample(sampler3, float2(0,0));
11+
return a + b;
12+
}
13+
14+
// check it's 6.6:
15+
// CHECK: call %dx.types.Handle @dx.op.createHandleFromBinding
16+
17+
// The large integers are encoded flags for the ResourceAccessStyle (an enumerated type in lib\DxilPIXPasses\DxilShaderAccessTracking.cpp) for this access
18+
19+
// Check we wrote sampler data to the PIX UAV. We told the pass to output starting at offset 512.
20+
// Add 8 to skip the "out of bounds" record. Add 4 to point to the "read" field within the next entry = 524
21+
// CHECK: call void @dx.op.bufferStore.i32(
22+
// CHECK:i32 524, i32 undef, i32 16777216
23+
24+
// twice: 512 + 8 + 8*3+4 = 548
25+
// CHECK: call void @dx.op.bufferStore.i32(
26+
// CHECK:i32 548, i32 undef, i32 16777216
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %dxc -EMain -Tps_6_6 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=S0:1:1i1;.256;512;520. | %FileCheck %s
2+
3+
static sampler sampler0 = SamplerDescriptorHeap[0];
4+
static sampler sampler3 = SamplerDescriptorHeap[3];
5+
Texture2D tx : register(t2);
6+
7+
float4 Main() : SV_Target
8+
{
9+
float4 a = tx.Sample(sampler0, float2(0,0));
10+
float4 b = tx.Sample(sampler3, float2(0,0));
11+
return a + b;
12+
}
13+
14+
// check it's 6.6:
15+
// CHECK: call %dx.types.Handle @dx.op.createHandleFromBinding
16+
17+
// The large integers are encoded flags for the ResourceAccessStyle (an enumerated type in lib\DxilPIXPasses\DxilShaderAccessTracking.cpp) for this access
18+
19+
// The start of sampler records has been passed in as 512. The limit of the whole buffer is 520, leaving just one eight-byte record for the out-of-bounds record.
20+
// There are therefore no expected in-bounds references to samplers, so any such reference should go to the out-of-bounds offset at 512:
21+
22+
// Out of bounds sampler access should be at offset 512
23+
// CHECK: call void @dx.op.bufferStore.i32(
24+
// CHECK:i32 512, i32 undef, i32 16777216

tools/clang/test/HLSLFileCheck/pix/TraceRayInline.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %dxc -T vs_6_5 -E main %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=S0:1:1i1;U0:2:10i0;.. | FileCheck %s
1+
// RUN: %dxc -T vs_6_5 -E main %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=S0:1:1i1;U0:2:10i0;.0;0;0. | FileCheck %s
22

33
// CHECK: call void @dx.op.rayQuery_TraceRayInline
44
// CHECK: call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle

tools/clang/test/HLSLFileCheck/pix/rawBufferStore.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %dxc -enable-16bit-types -Emain -Tcs_6_3 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=U0:2:10i0;.. | %FileCheck %s
1+
// RUN: %dxc -enable-16bit-types -Emain -Tcs_6_3 %s | %opt -S -hlsl-dxil-pix-shader-access-instrumentation,config=U0:2:10i0;.0;0;0. | %FileCheck %s
22

33
// Check that the expected PIX UAV read-tracking is emitted (the atomicBinOp "|= 1") followed by the expected raw read:
44

tools/clang/unittests/HLSL/CompilerTest.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class CompilerTest : public ::testing::Test {
202202
TEST_METHOD(BatchPasses)
203203
TEST_METHOD(BatchShaderTargets)
204204
TEST_METHOD(BatchValidation)
205+
TEST_METHOD(BatchPIX)
205206

206207
TEST_METHOD(SubobjectCodeGenErrors)
207208
BEGIN_TEST_METHOD(ManualFileCheckTest)
@@ -468,10 +469,20 @@ class CompilerTest : public ::testing::Test {
468469
dumpStr = dumpPath + (wRelPath.m_psz + suitePath.size());
469470
}
470471

471-
WEX::Logging::Log::StartGroup(wRelPath);
472+
class ScopedLogGroup
473+
{
474+
LPWSTR m_path;
475+
476+
public:
477+
ScopedLogGroup(LPWSTR path)
478+
: m_path(path)
479+
{ WEX::Logging::Log::StartGroup(m_path); }
480+
~ScopedLogGroup() { WEX::Logging::Log::EndGroup(m_path); }
481+
};
482+
483+
ScopedLogGroup cleanup(wRelPath);
472484
CodeGenTestCheck(wRelPath, /*implicitDir*/ false,
473485
dumpStr.empty() ? nullptr : dumpStr.c_str());
474-
WEX::Logging::Log::EndGroup(wRelPath);
475486

476487
numTestsRun++;
477488
}
@@ -3138,6 +3149,10 @@ TEST_F(CompilerTest, BatchValidation) {
31383149
CodeGenTestCheckBatchDir(L"validation");
31393150
}
31403151

3152+
TEST_F(CompilerTest, BatchPIX) {
3153+
CodeGenTestCheckBatchDir(L"PIX");
3154+
}
3155+
31413156
TEST_F(CompilerTest, BatchSamples) {
31423157
CodeGenTestCheckBatchDir(L"samples");
31433158
}

0 commit comments

Comments
 (0)