Skip to content

Commit b6287fd

Browse files
authored
[DirectX] Set the EnableRawAndStructuredBuffers shader flag (#122667)
When raw or structured buffers are used, we need to set the DXIL flag saying so. Fixes #122663.
1 parent 06c54bc commit b6287fd

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
5858
DXIL_MODULE_FLAG( 0, DisableOptimizations, "D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION")
5959
DXIL_MODULE_FLAG( 1, DisableMathRefactoring, "D3D10_SB_GLOBAL_FLAG_REFACTORING_ALLOWED")
6060
DXIL_MODULE_FLAG( 3, ForceEarlyDepthStencil, "D3D11_SB_GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL")
61-
DXIL_MODULE_FLAG( 4, EnableRawAndStructuredBuffers, "D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS")
61+
DXIL_MODULE_FLAG( 4, EnableRawAndStructuredBuffers, "Raw and Structured buffers")
6262
DXIL_MODULE_FLAG( 5, LowPrecisionPresent, "D3D11_1_SB_GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION")
6363
DXIL_MODULE_FLAG( 8, AllResourcesBound, "D3D12_SB_GLOBAL_FLAG_ALL_RESOURCES_BOUND")
6464
DXIL_MODULE_FLAG(23, UseNativeLowPrecision, "Native 16bit types enabled")

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,22 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
6464
switch (II->getIntrinsicID()) {
6565
default:
6666
break;
67+
case Intrinsic::dx_resource_handlefrombinding:
68+
switch (DRTM[cast<TargetExtType>(II->getType())].getResourceKind()) {
69+
case dxil::ResourceKind::StructuredBuffer:
70+
case dxil::ResourceKind::RawBuffer:
71+
CSF.EnableRawAndStructuredBuffers = true;
72+
break;
73+
default:
74+
break;
75+
}
76+
break;
6777
case Intrinsic::dx_resource_load_typedbuffer: {
6878
dxil::ResourceTypeInfo &RTI =
6979
DRTM[cast<TargetExtType>(II->getArgOperand(0)->getType())];
7080
if (RTI.isTyped())
7181
CSF.TypedUAVLoadAdditionalFormats |= RTI.getTyped().ElementCount > 1;
82+
break;
7283
}
7384
}
7485
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
2+
3+
; Note: there is no feature flag here (only a module flag), so we don't have an
4+
; object test.
5+
6+
target triple = "dxil-pc-shadermodel6.7-library"
7+
8+
; CHECK: Combined Shader Flags for Module
9+
; CHECK-NEXT: Shader Flags Value: 0x00000010
10+
11+
; CHECK: Note: shader requires additional functionality:
12+
; CHECK: Raw and Structured buffers
13+
14+
; CHECK: Function rawbuf : 0x00000010
15+
define float @rawbuf() "hlsl.export" {
16+
%buffer = call target("dx.RawBuffer", i8, 0, 0, 0)
17+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)
18+
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer.f32(
19+
target("dx.RawBuffer", i8, 0, 0, 0) %buffer, i32 0, i32 0)
20+
%data = extractvalue {float, i1} %load, 0
21+
ret float %data
22+
}
23+
24+
; CHECK: Function structbuf : 0x00000010
25+
define float @structbuf() "hlsl.export" {
26+
%buffer = call target("dx.RawBuffer", float, 0, 0, 0)
27+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)
28+
%load = call {float, i1} @llvm.dx.resource.load.rawbuffer.f32(
29+
target("dx.RawBuffer", float, 0, 0, 0) %buffer, i32 0, i32 0)
30+
%data = extractvalue {float, i1} %load, 0
31+
ret float %data
32+
}
33+
34+
; CHECK: Function typedbuf : 0x00000000
35+
define float @typedbuf(<4 x float> %val) "hlsl.export" {
36+
%buffer = call target("dx.TypedBuffer", float, 0, 0, 0)
37+
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false)
38+
%load = call {float, i1} @llvm.dx.resource.load.typedbuffer(
39+
target("dx.TypedBuffer", float, 0, 0, 0) %buffer, i32 0)
40+
%data = extractvalue {float, i1} %load, 0
41+
ret float %data
42+
}

0 commit comments

Comments
 (0)