Skip to content

Commit 6986ad8

Browse files
bob80905tex3dgithub-actions[bot]
authored
Write usage masks for mesh nodes in libraries into RDAT (#6522)
Previously, the step that is typically taken to set the usage mask for signature elements was not executed, due to mesh nodes being defined in library shaders. The mask was only written for non-lib shaders. Now that mesh nodes exist in library shaders, we need to allow usage masks to be set for mesh nodes, even though they are in library shaders. This PR adds an alternative case for mesh nodes. In this case, usage masks are written for all mesh nodes defined in a library shader, by iterating over all functions declared in a library module. An accompanying test was written that shows the RDAT now contains the usage mask, and it is non-null. Fixes #6521 --------- Co-authored-by: Tex Riddell <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 8a59115 commit 6986ad8

4 files changed

Lines changed: 370 additions & 14 deletions

File tree

lib/HLSL/DxilPreparePasses.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static bool GetUnsignedVal(Value *V, uint32_t *pValue) {
287287
return true;
288288
}
289289

290-
static void MarkUsedSignatureElements(Function *F, DxilModule &DM) {
290+
static void MarkUsedSignatureElements(Function *F, DxilEntryProps &entryProps) {
291291
DXASSERT_NOMSG(F != nullptr);
292292
// For every loadInput/storeOutput, update the corresponding ReadWriteMask.
293293
// F is a pointer to a Function instance
@@ -309,54 +309,54 @@ static void MarkUsedSignatureElements(Function *F, DxilModule &DM) {
309309
continue;
310310
if (!GetUnsignedVal(LI.get_rowIndex(), &row))
311311
bDynIdx = true;
312-
pSig = &DM.GetInputSignature();
312+
pSig = &entryProps.sig.InputSignature;
313313
} else if (SO) {
314314
if (!GetUnsignedVal(SO.get_outputSigId(), &sigId))
315315
continue;
316316
if (!GetUnsignedVal(SO.get_colIndex(), &col))
317317
continue;
318318
if (!GetUnsignedVal(SO.get_rowIndex(), &row))
319319
bDynIdx = true;
320-
pSig = &DM.GetOutputSignature();
320+
pSig = &entryProps.sig.OutputSignature;
321321
} else if (SPC) {
322322
if (!GetUnsignedVal(SPC.get_outputSigID(), &sigId))
323323
continue;
324324
if (!GetUnsignedVal(SPC.get_col(), &col))
325325
continue;
326326
if (!GetUnsignedVal(SPC.get_row(), &row))
327327
bDynIdx = true;
328-
pSig = &DM.GetPatchConstOrPrimSignature();
328+
pSig = &entryProps.sig.PatchConstOrPrimSignature;
329329
} else if (LPC) {
330330
if (!GetUnsignedVal(LPC.get_inputSigId(), &sigId))
331331
continue;
332332
if (!GetUnsignedVal(LPC.get_col(), &col))
333333
continue;
334334
if (!GetUnsignedVal(LPC.get_row(), &row))
335335
bDynIdx = true;
336-
pSig = &DM.GetPatchConstOrPrimSignature();
336+
pSig = &entryProps.sig.PatchConstOrPrimSignature;
337337
} else if (SVO) {
338338
if (!GetUnsignedVal(SVO.get_outputSigId(), &sigId))
339339
continue;
340340
if (!GetUnsignedVal(SVO.get_colIndex(), &col))
341341
continue;
342342
if (!GetUnsignedVal(SVO.get_rowIndex(), &row))
343343
bDynIdx = true;
344-
pSig = &DM.GetOutputSignature();
344+
pSig = &entryProps.sig.OutputSignature;
345345
} else if (SPO) {
346346
if (!GetUnsignedVal(SPO.get_outputSigId(), &sigId))
347347
continue;
348348
if (!GetUnsignedVal(SPO.get_colIndex(), &col))
349349
continue;
350350
if (!GetUnsignedVal(SPO.get_rowIndex(), &row))
351351
bDynIdx = true;
352-
pSig = &DM.GetPatchConstOrPrimSignature();
352+
pSig = &entryProps.sig.PatchConstOrPrimSignature;
353353
} else {
354354
continue;
355355
}
356356

357357
// Consider being more fine-grained about masks.
358358
// We report sometimes-read on input as always-read.
359-
auto &El = pSig->GetElement(sigId);
359+
hlsl::DxilSignatureElement &El = pSig->GetElement(sigId);
360360
unsigned UsageMask = El.GetUsageMask();
361361
unsigned colBit = 1 << col;
362362
if (!(colBit & UsageMask)) {
@@ -843,9 +843,25 @@ class DxilFinalizeModule : public ModulePass {
843843

844844
if (!IsLib) {
845845
// Set used masks for signature elements
846-
MarkUsedSignatureElements(DM.GetEntryFunction(), DM);
847-
if (DM.GetShaderModel()->IsHS())
848-
MarkUsedSignatureElements(DM.GetPatchConstantFunction(), DM);
846+
Function *F = DM.GetEntryFunction();
847+
// Assume entry props are available for entry function.
848+
DxilEntryProps &entryProps = DM.GetDxilEntryProps(F);
849+
MarkUsedSignatureElements(F, entryProps);
850+
if (entryProps.props.IsHS() &&
851+
entryProps.props.ShaderProps.HS.patchConstantFunc)
852+
MarkUsedSignatureElements(
853+
entryProps.props.ShaderProps.HS.patchConstantFunc, entryProps);
854+
} else {
855+
for (auto &function : M.getFunctionList()) {
856+
if (!function.isDeclaration()) {
857+
if (DM.HasDxilEntryProps(&function)) {
858+
auto &entryProps = DM.GetDxilEntryProps(&function);
859+
if (entryProps.props.IsMeshNode()) {
860+
MarkUsedSignatureElements(&function, entryProps);
861+
}
862+
}
863+
}
864+
}
849865
}
850866

851867
// Adding warning for pixel shader with unassigned target

tools/clang/test/CodeGenDXIL/hlsl/shaders/node/mesh-node.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void node_setmeshoutputcounts(DispatchNodeInputRecord<MeshPayload> mpl,
104104
op.layer[5] = mpl.Get().layer[5];
105105

106106
// CHECK: %[[GSGEP2:[0-9]+]] = getelementptr [16 x float], [16 x float] addrspace(3)* @"\01?gsMem@@3PAMA", i32 0, i32 %[[GIDIV]]
107-
// CHECK: store float %[[NRM]], float addrspace(3)* %[[GSGEP2]], align 4, !tbaa !29
107+
// CHECK: store float %[[NRM]], float addrspace(3)* %[[GSGEP2]], align 4
108108
gsMem[tig / 3] = op.normal;
109109
// CHECK: call void @dx.op.storePrimitiveOutput.f32(i32 172, i32 0, i32 0, i8 0, float %[[NRM]], i32 %[[GIDIV]])
110110
// CHECK: call void @dx.op.storePrimitiveOutput.f32(i32 172, i32 1, i32 0, i8 0, float %[[GS]], i32 %[[GIDIV]])

0 commit comments

Comments
 (0)