Skip to content

Commit ccdc4fd

Browse files
authored
PIX: Test for source locations for class methods (#5176)
As tested in the accompanying test, the DebugLoc for a class method contains a DICompositeType as part of its scope hierarchy. Lack of a test for this was breaking PIX shader debugging for class methods.
1 parent f9389db commit ccdc4fd

2 files changed

Lines changed: 115 additions & 15 deletions

File tree

tools/clang/unittests/HLSL/PixDiaTest.cpp

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ class PixDiaTest {
156156
TEST_METHOD(PixTypeManager_SamplersAndResources)
157157
TEST_METHOD(PixTypeManager_XBoxDiaAssert)
158158

159-
TEST_METHOD(DxcPixDxilDebugInfo_InstructionOffsets)
160-
161159
TEST_METHOD(PixDebugCompileInfo)
162160

163161
TEST_METHOD(SymbolManager_Embedded2DArray)
@@ -168,6 +166,9 @@ class PixDiaTest {
168166
DxcPixDxilDebugInfo_GlobalBackedGlobalStaticEmbeddedArrays_WithDbgValue)
169167
TEST_METHOD(
170168
DxcPixDxilDebugInfo_GlobalBackedGlobalStaticEmbeddedArrays_ArrayInValues)
169+
170+
TEST_METHOD(DxcPixDxilDebugInfo_InstructionOffsets)
171+
TEST_METHOD(DxcPixDxilDebugInfo_InstructionOffsetsInClassMethods)
171172
TEST_METHOD(DxcPixDxilDebugInfo_DuplicateGlobals)
172173
TEST_METHOD(DxcPixDxilDebugInfo_StructInheritance)
173174
TEST_METHOD(DxcPixDxilDebugInfo_StructContainedResource)
@@ -1916,6 +1917,105 @@ void MyMissShader(inout RayPayload payload)
19161917
}
19171918
}
19181919

1920+
TEST_F(PixDiaTest, DxcPixDxilDebugInfo_InstructionOffsetsInClassMethods) {
1921+
1922+
if (m_ver.SkipDxilVersion(1, 5))
1923+
return;
1924+
1925+
const char *hlsl = R"(
1926+
RWByteAddressBuffer RawUAV: register(u1);
1927+
1928+
class AClass
1929+
{
1930+
float Saturate(float f) // StartClassMethod
1931+
{
1932+
float l = RawUAV.Load(0);
1933+
return saturate(f * l);
1934+
} //EndClassMethod
1935+
};
1936+
1937+
[numthreads(1, 1, 1)]
1938+
void main()
1939+
{
1940+
uint orig;
1941+
AClass aClass;
1942+
float i = orig;
1943+
float f = aClass.Saturate(i);
1944+
uint fi = (uint)f;
1945+
RawUAV.InterlockedAdd(0, 42, fi);
1946+
}
1947+
1948+
)";
1949+
1950+
auto lines = SplitAndPreserveEmptyLines(std::string(hlsl), '\n');
1951+
1952+
CComPtr<IDiaDataSource> pDiaDataSource;
1953+
CompileAndRunAnnotationAndLoadDiaSource(m_dllSupport, hlsl, L"cs_6_6",
1954+
nullptr, &pDiaDataSource);
1955+
1956+
CComPtr<IDiaSession> session;
1957+
VERIFY_SUCCEEDED(pDiaDataSource->openSession(&session));
1958+
1959+
CComPtr<IDxcPixDxilDebugInfoFactory> Factory;
1960+
VERIFY_SUCCEEDED(session->QueryInterface(IID_PPV_ARGS(&Factory)));
1961+
1962+
CComPtr<IDxcPixDxilDebugInfo> dxilDebugger;
1963+
VERIFY_SUCCEEDED(Factory->NewDxcPixDxilDebugInfo(&dxilDebugger));
1964+
1965+
size_t lineAfterMethod = 0;
1966+
size_t lineBeforeMethod = static_cast<size_t>(-1);
1967+
for (size_t line = 0; line < lines.size(); ++line) {
1968+
if (lines[line].find("StartClassMethod") != std::string::npos)
1969+
lineBeforeMethod = line;
1970+
if (lines[line].find("EndClassMethod") != std::string::npos)
1971+
lineAfterMethod = line;
1972+
}
1973+
1974+
VERIFY_IS_TRUE(lineAfterMethod > lineBeforeMethod);
1975+
1976+
// For each source line, get the instruction numbers.
1977+
// For each instruction number, map back to source line.
1978+
// Some of them better be in the class method
1979+
1980+
bool foundClassMethodLines = false;
1981+
1982+
for (size_t line = 0; line < lines.size(); ++line) {
1983+
1984+
auto lineNumber = static_cast<DWORD>(line);
1985+
1986+
constexpr DWORD sourceLocationReaderOnlySupportsColumnZero = 0;
1987+
CComPtr<IDxcPixDxilInstructionOffsets> offsets;
1988+
dxilDebugger->InstructionOffsetsFromSourceLocation(
1989+
defaultFilename, lineNumber, sourceLocationReaderOnlySupportsColumnZero,
1990+
&offsets);
1991+
1992+
auto offsetCount = offsets->GetCount();
1993+
for (DWORD offsetOrdinal = 0; offsetOrdinal < offsetCount;
1994+
++offsetOrdinal) {
1995+
1996+
DWORD instructionOffsetFromSource =
1997+
offsets->GetOffsetByIndex(offsetOrdinal);
1998+
1999+
CComPtr<IDxcPixDxilSourceLocations> sourceLocations;
2000+
VERIFY_SUCCEEDED(dxilDebugger->SourceLocationsFromInstructionOffset(
2001+
instructionOffsetFromSource, &sourceLocations));
2002+
2003+
auto count = sourceLocations->GetCount();
2004+
for (DWORD sourceLocationOrdinal = 0; sourceLocationOrdinal < count;
2005+
++sourceLocationOrdinal) {
2006+
DWORD lineNumber =
2007+
sourceLocations->GetLineNumberByIndex(sourceLocationOrdinal);
2008+
2009+
if (lineNumber >= lineBeforeMethod && lineNumber <= lineAfterMethod) {
2010+
foundClassMethodLines = true;
2011+
}
2012+
}
2013+
}
2014+
}
2015+
2016+
VERIFY_IS_TRUE(foundClassMethodLines);
2017+
}
2018+
19192019
TEST_F(PixDiaTest, PixTypeManager_InheritancePointerTypedef) {
19202020
if (m_ver.SkipDxilVersion(1, 5))
19212021
return;

tools/clang/unittests/HLSL/PixTest.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ void RaygenCommon()
10331033
{
10341034
float3 rayDir;
10351035
float3 origin;
1036-
1036+
10371037
// Generate a ray for a camera pixel corresponding to an index from the dispatched 2D grid.
10381038
GenerateCameraRay(DispatchRaysIndex().xy, origin, rayDir);
10391039
@@ -1119,7 +1119,7 @@ void RaygenCommon()
11191119
{
11201120
float3 rayDir;
11211121
float3 origin;
1122-
1122+
11231123
// Generate a ray for a camera pixel corresponding to an index from the dispatched 2D grid.
11241124
GenerateCameraRay(DispatchRaysIndex().xy, origin, rayDir);
11251125
@@ -1797,7 +1797,7 @@ Texture2DArray<uint4> g_gbuffer : register(t0, space0);
17971797
17981798
[numthreads(1, 1, 1)]
17991799
void main()
1800-
{
1800+
{
18011801
const Gbuffer gbuffer = loadGbuffer(int2(0,0), g_gbuffer);
18021802
smallPayload p;
18031803
p.i = gbuffer.materialParams1.x + gbuffer.materialParams1.y + gbuffer.materialParams1.z + gbuffer.materialParams1.w;
@@ -2161,7 +2161,7 @@ void RaygenCommon()
21612161
{
21622162
float3 rayDir;
21632163
float3 origin;
2164-
2164+
21652165
// Generate a ray for a camera pixel corresponding to an index from the dispatched 2D grid.
21662166
GenerateCameraRay(DispatchRaysIndex().xy, origin, rayDir);
21672167
@@ -2366,21 +2366,21 @@ GlobalRootSignature so_GlobalRootSignature =
23662366
"RootConstants(num32BitConstants=1, b8), "
23672367
};
23682368
2369-
StateObjectConfig so_StateObjectConfig =
2370-
{
2369+
StateObjectConfig so_StateObjectConfig =
2370+
{
23712371
STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS
23722372
};
23732373
2374-
LocalRootSignature so_LocalRootSignature1 =
2374+
LocalRootSignature so_LocalRootSignature1 =
23752375
{
23762376
"RootConstants(num32BitConstants=3, b2), "
2377-
"UAV(u6),RootFlags(LOCAL_ROOT_SIGNATURE)"
2377+
"UAV(u6),RootFlags(LOCAL_ROOT_SIGNATURE)"
23782378
};
23792379
2380-
LocalRootSignature so_LocalRootSignature2 =
2380+
LocalRootSignature so_LocalRootSignature2 =
23812381
{
23822382
"RootConstants(num32BitConstants=3, b2), "
2383-
"UAV(u8, flags=DATA_STATIC), "
2383+
"UAV(u8, flags=DATA_STATIC), "
23842384
"RootFlags(LOCAL_ROOT_SIGNATURE)"
23852385
};
23862386
@@ -2404,13 +2404,13 @@ TriangleHitGroup MyHitGroup =
24042404
SubobjectToExportsAssociation so_Association1 =
24052405
{
24062406
"so_LocalRootSignature1", // subobject name
2407-
"MyRayGen" // export association
2407+
"MyRayGen" // export association
24082408
};
24092409
24102410
SubobjectToExportsAssociation so_Association2 =
24112411
{
24122412
"so_LocalRootSignature2", // subobject name
2413-
"MyAnyHit" // export association
2413+
"MyAnyHit" // export association
24142414
};
24152415
24162416
struct MyPayload
@@ -2425,7 +2425,7 @@ void MyRayGen()
24252425
24262426
[shader("closesthit")]
24272427
void MyClosestHit(inout MyPayload payload, in BuiltInTriangleIntersectionAttributes attr)
2428-
{
2428+
{
24292429
}
24302430
24312431
[shader("anyhit")]

0 commit comments

Comments
 (0)