[DirectX] Add shader flags for heap resources - #216461
Conversation
- `DXILResourceMap` now handles a new `llvm.dx.resource.handlefromheap` intrisics and adds the heap resources to the resource map. - A new member `HeapResourceID` has been added to `ResourceInfo` to distinguish between heap resource instances created from different indices. The `HeapResourceID` is unique for each heap index `Value*`, so multiple handle creation calls using the same index `Value*` resolve to the same resource. - Heap resources do not have register bindings, so the `Binding` member on `ResourceInfo` is now optional. - All places that were always expecting binding are updated to handle heap resources. In most cases that means skipping them, such as when generating DXIL resource metadata, creating PSV resource entries or pretty-printing the resource table comment for the module disassembly output. - Diagnostics of conflicting increment and decrement operations now works on heap resources.
…rce table or metadata
|
@llvm/pr-subscribers-backend-directx Author: Helena Kotas (hekota) ChangesDescriptor-heap usage must be recorded in the shader feature flags. The Fixes #213825 Depends on #216454 Full diff: https://github.com/llvm/llvm-project/pull/216461.diff 2 Files Affected:
diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
index 64d8dc33e3e60..b7c296b2bde6d 100644
--- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
+++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
@@ -274,6 +274,16 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
}
break;
}
+ case Intrinsic::dx_resource_handlefromheap: {
+ if (auto *ConstInt = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
+ bool IsSamplerHeap = ConstInt->getValue().getBoolValue();
+ if (IsSamplerHeap)
+ CSF.SamplerDescriptorHeapIndexing = true;
+ else
+ CSF.ResourceDescriptorHeapIndexing = true;
+ }
+ break;
+ }
case Intrinsic::dx_resource_load_typedbuffer: {
dxil::ResourceTypeInfo &RTI =
DRTM[cast<TargetExtType>(II->getArgOperand(0)->getType())];
@@ -342,7 +352,7 @@ ModuleShaderFlags::gatherGlobalModuleFlags(const Module &M,
if (MMDI.ValidatorVersion < VersionTuple(1, 6)) {
NumUAVs++;
} else { // MMDI.ValidatorVersion >= VersionTuple(1, 6)
- uint32_t Size = UAV.getBinding().Size;
+ uint32_t Size = UAV.getSize();
uint32_t NewNum = NumUAVs + (Size == 0 ? ~0U : Size);
if (NewNum < NumUAVs)
NewNum = ~0U;
diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/heap-resources.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/heap-resources.ll
new file mode 100644
index 0000000000000..d7e15a65aea3a
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ShaderFlags/heap-resources.ll
@@ -0,0 +1,42 @@
+; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
+; RUN: llc %s -disable-dxil-remove-unused-resources --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
+
+; This test makes sure that the shader flags 'Resource descriptor heap indexing'
+; is set when the shader uses CreateHandleFromHeap instruction on a resource
+; descriptor heap.
+
+target triple = "dxil-pc-shadermodel6.6-library"
+
+; CHECK: Combined Shader Flags for Module
+; CHECK-NEXT: Shader Flags Value: 0xc0000000
+
+; CHECK: Note: shader requires additional functionality:
+; CHECK: Resource descriptor heap indexing
+; CHECK: Sampler descriptor heap indexing
+;
+; CHECK: Function test_1 : 0x40000000
+define void @test_1() "hlsl.export" {
+ ; RWBuffer<float4> Buf = ResourceDescriptorHeap[3]
+ %typed = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
+ @llvm.dx.resource.handlefromheap.tdx.TypedBuffer_v4f32_1_0_0(i32 3, i1 false)
+ ret void
+}
+
+; CHECK: Function test_2 : 0x80000000
+define void @test_2() "hlsl.export" {
+ ; SamplerState Samp = ResourceDescriptorHeap[100];
+ %samp = call target("dx.Sampler", 0)
+ @llvm.dx.resource.handlefromheap.tdx.Sampler_0(i32 100, i1 true)
+ ret void
+}
+
+!dx.valver = !{!0}
+!0 = !{i32 1, i32 8}
+
+; DXC: - Name: SFI0
+; DXC-NEXT: Size: 8
+; DXC-NEXT: Flags:
+; DXC: ResourceDescriptorHeapIndexing: true
+; DXC: SamplerDescriptorHeapIndexing: true
+; DXC: NextUnusedBit: false
+
|
bob80905
left a comment
There was a problem hiding this comment.
looks good, just some nits. Also, random curiosity, we expect a diagnostic / a validation failure if the operand (the index) is not a constant? Has that been previously validated by the point of the code you've written?
The |
…/github.com/llvm/llvm-project into dyn-res-shader-flags
…tEveryStage, add tests
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
…res-shader-flags
Descriptor-heap usage must be recorded in the shader feature flags. The
DXILShaderFlagspass inspects eachllvm.dx.resource.handlefromheapcall and sets theSamplerDescriptorHeapIndexingshader flag whenIsSamplerHeapistrue, orResourceDescriptorHeapIndexingflag when it isfalse.Fixes #213825