Skip to content

Commit

Permalink
Added more tests and updated logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooper Partin committed Nov 5, 2024
1 parent 0d820cc commit 931a684
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 26 deletions.
34 changes: 26 additions & 8 deletions llvm/lib/Target/DirectX/DXILShaderFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,37 @@ static void updateResourceFlags(ComputedShaderFlags &Flags, Module &M,
if (DRM.empty())
return;

const dxil::ModuleMetadataInfo &MMDI = AM->getResult<DXILMetadataAnalysis>(M);
VersionTuple SM = MMDI.ShaderModelVersion;
Triple::EnvironmentType SP = MMDI.ShaderProfile;

// RWBuffer
for (const ResourceInfo &RI : DRM.uavs()) {
if (RI.getResourceKind() == ResourceKind::TypedBuffer) {
switch (RI.getResourceKind()) {
case ResourceKind::RawBuffer:
case ResourceKind::StructuredBuffer:
Flags.EnableRawAndStructuredBuffers = true;
Flags.ComputeShadersPlusRawAndStructuredBuffers =
(SP == Triple::EnvironmentType::Compute && SM.getMajor() == 4);
break;
default:
break;
}
}

for (const ResourceInfo &RI : DRM.srvs()) {
switch (RI.getResourceKind()) {
case ResourceKind::RawBuffer:
case ResourceKind::StructuredBuffer:
Flags.EnableRawAndStructuredBuffers = true;
break;
default:
break;
}
}

if (Flags.EnableRawAndStructuredBuffers) {
const dxil::ModuleMetadataInfo &MMDI =
AM->getResult<DXILMetadataAnalysis>(M);
VersionTuple SM = MMDI.ShaderModelVersion;
Triple::EnvironmentType SP = MMDI.ShaderProfile;

Flags.ComputeShadersPlusRawAndStructuredBuffers =
(SP == Triple::EnvironmentType::Compute && SM.getMajor() == 4);
}
}

ComputedShaderFlags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ target triple = "dxil-pc-shadermodel6.3-compute"

define void @test_bufferflags() {

; RWBuffer<int> Buf : register(u7, space2)
%uav0 = call target("dx.TypedBuffer", i32, 1, 0, 1)
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t(
i32 2, i32 7, i32 1, i32 0, i1 false)
; ByteAddressBuffer Buf : register(t8, space1)
%srv0 = call target("dx.RawBuffer", i8, 0, 0)
@llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
i32 1, i32 8, i32 1, i32 0, i1 false)

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

; CHECK: ; Shader Flags Value: 0x00000010
; CHECK: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
; CHECK-NEXT: {{^;$}}

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ target triple = "dxil-pc-shadermodel4.0-compute"

define void @test_bufferflags() {

; RWBuffer<int> Buf : register(u7, space2)
%uav0 = call target("dx.TypedBuffer", i32, 1, 0, 1)
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t(
i32 2, i32 7, i32 1, i32 0, i1 false)
; ByteAddressBuffer Buf : register(t8, space1)
%srv0 = call target("dx.RawBuffer", i8, 0, 0)
@llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
i32 1, i32 8, i32 1, i32 0, i1 false)

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

; CHECK: ; Shader Flags Value: 0x00020010
; CHECK: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Raw and Structured buffers
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
; CHECK-NEXT: {{^;$}}

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/DirectX/ShaderFlags/rwbuffer.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s

target triple = "dxil-pc-shadermodel6.3-compute"

@G = external constant <4 x float>, align 4

define void @test_bufferflags() {

; RWByteAddressBuffer Buf : register(u8, space1)
%uav0 = call target("dx.RawBuffer", i8, 1, 0)
@llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
i32 1, i32 8, i32 1, i32 0, i1 false)

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

; CHECK: ; Shader Flags Value: 0x00000010
; CHECK: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
; CHECK-NEXT: {{^;$}}
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/DirectX/ShaderFlags/rwstructuredbuffer.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s

target triple = "dxil-pc-shadermodel6.7-library"

@G = external constant <4 x float>, align 4

define void @test_bufferflags() {

; struct S { float4 a; uint4 b; };
; RWStructuredBuffer<S> Buf : register(u2, space4)
%struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 1, 0)
@llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
i32 4, i32 2, i32 1, i32 10, i1 true)

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

; CHECK: ; Shader Flags Value: 0x00000010
; CHECK: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
; CHECK-NEXT: {{^;$}}
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/DirectX/ShaderFlags/structuredbuffer.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s

target triple = "dxil-pc-shadermodel6.7-library"

@G = external constant <4 x float>, align 4

define void @test_bufferflags() {

; struct S { float4 a; uint4 b; };
; StructuredBuffer<S> Buf : register(t2, space4)
%struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0)
@llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
i32 4, i32 2, i32 1, i32 10, i1 true)

ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

; CHECK: ; Shader Flags Value: 0x00000010
; CHECK: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
; CHECK-NEXT: {{^;$}}

0 comments on commit 931a684

Please sign in to comment.