Skip to content

Commit 328d1d3

Browse files
committed
[DirectX] Set the EnableRawAndStructuredBuffers shader flag
When raw or structured buffers are used, we need to set the DXIL flag saying so. Fixes #122663.
1 parent acbd822 commit 328d1d3

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
@@ -54,11 +54,22 @@ static void updateFunctionFlags(ComputedShaderFlags &CSF, const Instruction &I,
5454
switch (II->getIntrinsicID()) {
5555
default:
5656
break;
57+
case Intrinsic::dx_resource_handlefrombinding:
58+
switch (DRTM[cast<TargetExtType>(II->getType())].getResourceKind()) {
59+
case dxil::ResourceKind::StructuredBuffer:
60+
case dxil::ResourceKind::RawBuffer:
61+
CSF.EnableRawAndStructuredBuffers = true;
62+
break;
63+
default:
64+
break;
65+
}
66+
break;
5767
case Intrinsic::dx_resource_load_typedbuffer: {
5868
dxil::ResourceTypeInfo &RTI =
5969
DRTM[cast<TargetExtType>(II->getArgOperand(0)->getType())];
6070
if (RTI.isTyped())
6171
CSF.TypedUAVLoadAdditionalFormats |= RTI.getTyped().ElementCount > 1;
72+
break;
6273
}
6374
}
6475
}
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)