Skip to content

Commit eb425c5

Browse files
Joao SaffranJoao Saffran
authored andcommitted
making validation function according to spec
1 parent 4400e2e commit eb425c5

5 files changed

+48
-18
lines changed

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/InitializePasses.h"
2222
#include "llvm/MC/DXContainerRootSignature.h"
2323
#include "llvm/Support/DXILABI.h"
24+
#include "llvm/Support/ErrorHandling.h"
2425

2526
#define DEBUG_TYPE "dxil-post-optimization-validation"
2627

@@ -274,8 +275,9 @@ static void reportIfDeniedShaderStageAccess(Module &M, dxbc::RootFlags Flags,
274275
}
275276
}
276277

277-
static void validateRootFlags(Module &M, const mcdxbc::RootSignatureDesc &RSD,
278-
const dxil::ModuleMetadataInfo &MMI) {
278+
static void validateDeniedStagedNotInUse(Module &M,
279+
const mcdxbc::RootSignatureDesc &RSD,
280+
const dxil::ModuleMetadataInfo &MMI) {
279281
dxbc::RootFlags Flags = dxbc::RootFlags(RSD.Flags);
280282

281283
switch (MMI.ShaderProfile) {
@@ -308,7 +310,7 @@ static void validateRootFlags(Module &M, const mcdxbc::RootSignatureDesc &RSD,
308310
M, Flags, dxbc::RootFlags::DenyAmplificationShaderRootAccess);
309311
break;
310312
default:
311-
break;
313+
llvm_unreachable("Invalid triple to shader stage conversion");
312314
}
313315
}
314316

@@ -372,7 +374,7 @@ static void validateDescriptorTables(Module &M,
372374
}
373375
}
374376

375-
static void validateRootSignatureBindings(Module &M,
377+
static bool validateRootSignatureBindings(Module &M,
376378
const mcdxbc::RootSignatureDesc &RSD,
377379
dxil::ModuleMetadataInfo &MMI,
378380
DXILResourceMap &DRM) {
@@ -444,6 +446,8 @@ static void validateRootSignatureBindings(Module &M,
444446
Builder.findOverlapping(ReportedBinding);
445447
reportOverlappingRegisters(M, ReportedBinding, Overlaping);
446448
});
449+
bool HasBindings = false;
450+
447451
// Next checks require that the root signature definition is valid.
448452
if (!HasOverlap) {
449453
SmallVector<ResourceInfo::ResourceBinding> RDs =
@@ -460,10 +464,13 @@ static void validateRootSignatureBindings(Module &M,
460464

461465
if (!Info.isBound(ResList.first, ResBinding.Space, ResRange))
462466
reportRegNotBound(M, ResList.first, ResBinding);
467+
else
468+
HasBindings = true;
463469
}
464470
reportInvalidHandleTy(M, RDs, ResList.second);
465471
}
466472
}
473+
return HasBindings;
467474
}
468475

469476
mcdxbc::RootSignatureDesc *getRootSignature(RootSignatureBindingInfo &RSBI,
@@ -487,9 +494,10 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
487494
"DXILResourceImplicitBinding pass");
488495

489496
if (mcdxbc::RootSignatureDesc *RSD = getRootSignature(RSBI, MMI)) {
490-
validateRootSignatureBindings(M, *RSD, MMI, DRM);
497+
bool HasBindings = validateRootSignatureBindings(M, *RSD, MMI, DRM);
491498
validateDescriptorTables(M, *RSD);
492-
validateRootFlags(M, *RSD, MMI);
499+
if (HasBindings && MMI.ShaderProfile != Triple::Compute)
500+
validateDeniedStagedNotInUse(M, *RSD, MMI);
493501
}
494502
}
495503

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: opt -S -passes='dxil-post-optimization-validation' %s 2>&1
2+
; expected-no-diagnostics
3+
target triple = "dxil-pc-shadermodel6.6-pixel"
4+
5+
define void @CSMain() #0 {
6+
entry:
7+
ret void
8+
}
9+
attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="geometry" }
10+
11+
!dx.rootsignatures = !{!0}
12+
13+
!0 = !{ptr @CSMain, !1, i32 2}
14+
!1 = !{!2}
15+
!2 = !{ !"RootFlags", i32 294 } ; 32 = deny_pixel/hull/vertex/amplification_shader_root_access

llvm/test/CodeGen/DirectX/rootsignature-validation-deny-shader.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1"
1313
!0 = !{ptr @CSMain, !1, i32 2}
1414
!1 = !{!2}
1515
!2 = !{ !"RootFlags", i32 294 } ; 32 = deny_pixel/hull/vertex/amplification_shader_root_access
16-
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
; RUN: not opt -S -passes='dxil-post-optimization-validation' %s 2>&1 | FileCheck %s
22

33
; CHECK: error: Shader has root bindings but root signature uses a DENY flag to disallow root binding access to the shader stage.
4-
target triple = "dxil-pc-shadermodel6.6-hull"
4+
target triple = "dxil-pc-shadermodel6.6-pixel"
55

6-
define void @CSMain() #0 {
6+
%__cblayout_CB = type <{ float }>
7+
8+
@CB.str = private unnamed_addr constant [3 x i8] c"CB\00", align 1
9+
10+
define void @CSMain() "hlsl.shader"="compute" {
711
entry:
12+
%CB = tail call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB, 4, 0)) @llvm.dx.resource.handlefrombinding(i32 0, i32 2, i32 1, i32 0, i1 false, ptr nonnull @CB.str)
813
ret void
914
}
10-
attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="hull" }
1115

1216
!dx.rootsignatures = !{!0}
1317

1418
!0 = !{ptr @CSMain, !1, i32 2}
15-
!1 = !{!2}
16-
!2 = !{ !"RootFlags", i32 294 } ; 32 = deny_pixel/hull/vertex/amplification_shader_root_access
17-
19+
!1 = !{!2, !3}
20+
!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}
21+
!3 = !{!"RootFlags", i32 294} ; 294 = deny_pixel/hull/vertex/amplification_shader_root_access

llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-single-shader.ll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
; CHECK: error: Shader has root bindings but root signature uses a DENY flag to disallow root binding access to the shader stage.
44
target triple = "dxil-pc-shadermodel6.6-pixel"
55

6-
define void @CSMain() #0 {
6+
%__cblayout_CB = type <{ float }>
7+
8+
@CB.str = private unnamed_addr constant [3 x i8] c"CB\00", align 1
9+
10+
define void @CSMain() "hlsl.shader"="compute" {
711
entry:
12+
%CB = tail call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB, 4, 0)) @llvm.dx.resource.handlefrombinding(i32 0, i32 2, i32 1, i32 0, i1 false, ptr nonnull @CB.str)
813
ret void
914
}
10-
attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="pixel" }
1115

1216
!dx.rootsignatures = !{!0}
1317

1418
!0 = !{ptr @CSMain, !1, i32 2}
15-
!1 = !{!2}
16-
!2 = !{ !"RootFlags", i32 32 } ; 32 = deny_pixel_shader_root_access
17-
19+
!1 = !{!2, !3}
20+
!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}
21+
!3 = !{!"RootFlags", i32 32} ; 32 = deny_pixel_shader_root_access

0 commit comments

Comments
 (0)