Skip to content

Commit a13938d

Browse files
authored
PIX: Check for existing PIX UAV in roots sigs before adding it again (microsoft#7238)
The DXR invocation counting pass calls a function to add an output UAV twice. As part of adding the UAV, any DXIL-defined rootsigs will be extended to include this new UAV. If the UAV already exists in the rootsig, we should not add it again. (Doing so results in root sig that will fail validation.) Note: the test is not a file-check style because dxil-defined subobjects don't get rehydrated into the DxilModule when the output of dxc.exe is piped into the input of opt.exe, meaning that the broken case can't be exercised.
1 parent 30bfd82 commit a13938d

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

lib/DxilPIXPasses/PixPassHelpers.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ constexpr uint32_t toolsUAVRegister = 0;
199199
template <typename RootSigDesc, typename RootParameterDesc>
200200
void ExtendRootSig(RootSigDesc &rootSigDesc) {
201201
auto *existingParams = rootSigDesc.pParameters;
202+
for (uint32_t i = 0; i < rootSigDesc.NumParameters; ++i) {
203+
if (rootSigDesc.pParameters[i].ParameterType ==
204+
DxilRootParameterType::UAV) {
205+
if (rootSigDesc.pParameters[i].Descriptor.RegisterSpace ==
206+
toolsRegisterSpace &&
207+
rootSigDesc.pParameters[i].Descriptor.ShaderRegister ==
208+
toolsUAVRegister) {
209+
// Already added
210+
return;
211+
}
212+
}
213+
}
202214
auto *newParams = new RootParameterDesc[rootSigDesc.NumParameters + 1];
203215
if (existingParams != nullptr) {
204216
memcpy(newParams, existingParams,

tools/clang/unittests/HLSL/PixTest.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class PixTest : public ::testing::Test {
146146
TEST_METHOD(RootSignatureUpgrade_Annotation)
147147

148148
TEST_METHOD(DxilPIXDXRInvocationsLog_SanityTest)
149+
TEST_METHOD(DxilPIXDXRInvocationsLog_EmbeddedRootSigs)
149150

150151
TEST_METHOD(DebugInstrumentation_TextOutput)
151152
TEST_METHOD(DebugInstrumentation_BlockReport)
@@ -660,7 +661,7 @@ CComPtr<IDxcBlob> PixTest::RunDxilPIXDXRInvocationsLog(IDxcBlob *blob) {
660661
CComPtr<IDxcBlob> pOptimizedModule;
661662
CComPtr<IDxcBlobEncoding> pText;
662663
VERIFY_SUCCEEDED(pOptimizer->RunOptimizer(
663-
dxil, Options.data(), Options.size(), &pOptimizedModule, &pText));
664+
blob, Options.data(), Options.size(), &pOptimizedModule, &pText));
664665

665666
std::string outputText;
666667
if (pText->GetBufferSize() != 0) {
@@ -2945,6 +2946,43 @@ void MyMiss(inout MyPayload payload)
29452946
RunDxilPIXDXRInvocationsLog(compiledLib);
29462947
}
29472948

2949+
TEST_F(PixTest, DxilPIXDXRInvocationsLog_EmbeddedRootSigs) {
2950+
2951+
const char *source = R"x(
2952+
2953+
GlobalRootSignature grs = {"CBV(b0)"};
2954+
struct MyPayload
2955+
{
2956+
float4 color;
2957+
};
2958+
2959+
[shader("raygeneration")]
2960+
void MyRayGen()
2961+
{
2962+
}
2963+
2964+
[shader("closesthit")]
2965+
void MyClosestHit(inout MyPayload payload, in BuiltInTriangleIntersectionAttributes attr)
2966+
{
2967+
}
2968+
2969+
[shader("anyhit")]
2970+
void MyAnyHit(inout MyPayload payload, in BuiltInTriangleIntersectionAttributes attr)
2971+
{
2972+
}
2973+
2974+
[shader("miss")]
2975+
void MyMiss(inout MyPayload payload)
2976+
{
2977+
}
2978+
2979+
)x";
2980+
2981+
auto compiledLib = Compile(m_dllSupport, source, L"lib_6_3",
2982+
{L"-Qstrip_reflect"}, L"RootSig");
2983+
RunDxilPIXDXRInvocationsLog(compiledLib);
2984+
}
2985+
29482986
TEST_F(PixTest, DebugInstrumentation_TextOutput) {
29492987

29502988
const char *source = R"x(

tools/clang/unittests/HLSL/PixTestUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ CComPtr<IDxcBlob> Compile(dxc::DxcDllSupport &dllSupport, const char *hlsl,
397397
CheckOperationSucceeded(pResult, &pProgram);
398398

399399
CComPtr<IDxcLibrary> pLib;
400-
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &pLib));
400+
VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcLibrary, &pLib));
401401
const hlsl::DxilContainerHeader *pContainer = hlsl::IsDxilContainerLike(
402402
pProgram->GetBufferPointer(), pProgram->GetBufferSize());
403403
VERIFY_IS_NOT_NULL(pContainer);

0 commit comments

Comments
 (0)