From 74b2115b72e43304c474a1b706c757f649caaa49 Mon Sep 17 00:00:00 2001 From: Jeff Noyle Date: Thu, 14 Nov 2024 10:45:58 -0800 Subject: [PATCH 1/2] Fix+test --- .../DxilShaderAccessTracking.cpp | 3 + tools/clang/unittests/HLSL/PixTest.cpp | 79 +++++++++++++++++-- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/lib/DxilPIXPasses/DxilShaderAccessTracking.cpp b/lib/DxilPIXPasses/DxilShaderAccessTracking.cpp index 03ab62c50b..4f4cc7c620 100644 --- a/lib/DxilPIXPasses/DxilShaderAccessTracking.cpp +++ b/lib/DxilPIXPasses/DxilShaderAccessTracking.cpp @@ -1052,6 +1052,9 @@ bool DxilShaderAccessTracking::runOnModule(Module &M) { // Done with these guys: m_GEPOperandAsInstructionDestroyers.clear(); + if (OSOverride != nullptr && !Modified) { + *OSOverride << "\nNotModified\n"; + } return Modified; } char DxilShaderAccessTracking::ID = 0; diff --git a/tools/clang/unittests/HLSL/PixTest.cpp b/tools/clang/unittests/HLSL/PixTest.cpp index df964bf433..6a5a63715c 100644 --- a/tools/clang/unittests/HLSL/PixTest.cpp +++ b/tools/clang/unittests/HLSL/PixTest.cpp @@ -112,6 +112,11 @@ class PixTest : public ::testing::Test { TEST_METHOD(SignatureModification_VertexIdAlready) TEST_METHOD(SignatureModification_SomethingElseFirst) + TEST_METHOD(AccessTracking_ModificationReport_Nothing) + TEST_METHOD(AccessTracking_ModificationReport_Read) + TEST_METHOD(AccessTracking_ModificationReport_Write) + TEST_METHOD(AccessTracking_ModificationReport_SM66) + TEST_METHOD(PixStructAnnotation_Lib_DualRaygen) TEST_METHOD(PixStructAnnotation_Lib_RaygenAllocaStructAlignment) @@ -348,6 +353,8 @@ class PixTest : public ::testing::Test { *ppNewShaderOut = pNewContainer.Detach(); } + void ValidateAccessTrackingMods(const char *hlsl, bool modsExpected); + class ModuleAndHangersOn { std::unique_ptr llvmContext; std::unique_ptr llvmModule; @@ -429,7 +436,7 @@ class PixTest : public ::testing::Test { const wchar_t *profile = L"as_6_5"); void ValidateAllocaWrite(std::vector const &allocaWrites, size_t index, const char *name); - CComPtr RunShaderAccessTrackingPass(IDxcBlob *blob); + PassOutput RunShaderAccessTrackingPass(IDxcBlob *blob); std::string RunDxilPIXAddTidToAmplificationShaderPayloadPass(IDxcBlob *blob); CComPtr RunDxilPIXMeshShaderOutputPass(IDxcBlob *blob); CComPtr RunDxilPIXDXRInvocationsLog(IDxcBlob *blob); @@ -576,13 +583,13 @@ TEST_F(PixTest, CompileDebugDisasmPDB) { VERIFY_SUCCEEDED(pCompiler->Disassemble(pPdbBlob, &pDisasm)); } -CComPtr PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) { +PassOutput PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) { CComPtr pOptimizer; VERIFY_SUCCEEDED( m_dllSupport.CreateInstance(CLSID_DxcOptimizer, &pOptimizer)); std::vector Options; Options.push_back(L"-opt-mod-passes"); - Options.push_back(L"-hlsl-dxil-pix-shader-access-instrumentation,config="); + Options.push_back(L"-hlsl-dxil-pix-shader-access-instrumentation,config=U0:0:10i0;U0:1:2i0;.0;0;0."); CComPtr pOptimizedModule; CComPtr pText; @@ -604,7 +611,12 @@ CComPtr PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) { CComPtr pNewContainer; VERIFY_SUCCEEDED(pAssembleResult->GetResult(&pNewContainer)); - return pNewContainer; + PassOutput ret; + ret.blob = pNewContainer; + std::string outputText = BlobToUtf8(pText); + ret.lines = Tokenize(outputText.c_str(), "\n"); + + return ret; } CComPtr PixTest::RunDxilPIXMeshShaderOutputPass(IDxcBlob *blob) { @@ -816,6 +828,61 @@ TEST_F(PixTest, SignatureModification_SomethingElseFirst) { VERIFY_ARE_EQUAL(sig.GetElement(2).GetStartRow(), 2); } +void PixTest::ValidateAccessTrackingMods(const char *hlsl, bool modsExpected) { + auto code = Compile(m_dllSupport, hlsl, L"ps_6_6", {L"-Od"}, L"main"); + auto result = RunShaderAccessTrackingPass(code).lines; + bool hasMods = true; + for (auto const& line : result) + if (line.find("NotModified") != std::string::npos) + hasMods = false; + VERIFY_ARE_EQUAL(modsExpected, hasMods); +} + +TEST_F(PixTest, AccessTracking_ModificationReport_Nothing) { + const char *hlsl = R"( +float main() : SV_Target +{ + return 0; +} +)"; + ValidateAccessTrackingMods(hlsl, false); +} + +TEST_F(PixTest, AccessTracking_ModificationReport_Read) { + const char *hlsl = R"( +RWByteAddressBuffer g_texture; +float main() : SV_Target +{ + return g_texture.Load(0); +} +)"; + ValidateAccessTrackingMods(hlsl, true); +} + +TEST_F(PixTest, AccessTracking_ModificationReport_Write) { + const char *hlsl = R"( +RWByteAddressBuffer g_texture; +float main() : SV_Target +{ + g_texture.Store(0, 0); + return 0; +} +)"; + ValidateAccessTrackingMods(hlsl, true); +} + +TEST_F(PixTest, AccessTracking_ModificationReport_SM66) { + const char *hlsl = R"( +float main() : SV_Target +{ + RWByteAddressBuffer g_texture = ResourceDescriptorHeap[0]; + g_texture.Store(0, 0); + return 0; +} +)"; + ValidateAccessTrackingMods(hlsl, true); +} + TEST_F(PixTest, AddToASGroupSharedPayload) { const char *hlsl = R"( @@ -2720,7 +2787,7 @@ void MyMiss(inout MyPayload payload) CComPtr compiled; VERIFY_SUCCEEDED(pResult->GetResult(&compiled)); - auto optimizedContainer = RunShaderAccessTrackingPass(compiled); + auto optimizedContainer = RunShaderAccessTrackingPass(compiled).blob; const char *pBlobContent = reinterpret_cast(optimizedContainer->GetBufferPointer()); @@ -2790,7 +2857,7 @@ float4 main(int i : A, float j : B) : SV_TARGET )x"; auto compiled = Compile(m_dllSupport, dynamicTextureAccess, L"ps_6_6"); - auto pOptimizedContainer = RunShaderAccessTrackingPass(compiled); + auto pOptimizedContainer = RunShaderAccessTrackingPass(compiled).blob; const char *pBlobContent = reinterpret_cast(pOptimizedContainer->GetBufferPointer()); From 7c1751ddb82cfd5b4f7a5e1ad14370a7f665dc63 Mon Sep 17 00:00:00 2001 From: Jeff Noyle Date: Thu, 14 Nov 2024 10:51:45 -0800 Subject: [PATCH 2/2] format --- tools/clang/unittests/HLSL/PixTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/clang/unittests/HLSL/PixTest.cpp b/tools/clang/unittests/HLSL/PixTest.cpp index 6a5a63715c..886a3a576a 100644 --- a/tools/clang/unittests/HLSL/PixTest.cpp +++ b/tools/clang/unittests/HLSL/PixTest.cpp @@ -589,7 +589,8 @@ PassOutput PixTest::RunShaderAccessTrackingPass(IDxcBlob *blob) { m_dllSupport.CreateInstance(CLSID_DxcOptimizer, &pOptimizer)); std::vector Options; Options.push_back(L"-opt-mod-passes"); - Options.push_back(L"-hlsl-dxil-pix-shader-access-instrumentation,config=U0:0:10i0;U0:1:2i0;.0;0;0."); + Options.push_back(L"-hlsl-dxil-pix-shader-access-instrumentation,config=U0:0:" + L"10i0;U0:1:2i0;.0;0;0."); CComPtr pOptimizedModule; CComPtr pText; @@ -832,7 +833,7 @@ void PixTest::ValidateAccessTrackingMods(const char *hlsl, bool modsExpected) { auto code = Compile(m_dllSupport, hlsl, L"ps_6_6", {L"-Od"}, L"main"); auto result = RunShaderAccessTrackingPass(code).lines; bool hasMods = true; - for (auto const& line : result) + for (auto const &line : result) if (line.find("NotModified") != std::string::npos) hasMods = false; VERIFY_ARE_EQUAL(modsExpected, hasMods);