Skip to content

Commit 9f3888e

Browse files
author
joaosaffran
committed
adding root constants
1 parent edb015d commit 9f3888e

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
#include "DXILPostOptimizationValidation.h"
1010
#include "DXILShaderFlags.h"
1111
#include "DirectX.h"
12+
#include "llvm/ADT/STLForwardCompat.h"
1213
#include "llvm/ADT/SmallString.h"
1314
#include "llvm/ADT/SmallVector.h"
1415
#include "llvm/Analysis/DXILMetadataAnalysis.h"
1516
#include "llvm/Analysis/DXILResource.h"
17+
#include "llvm/BinaryFormat/DXContainer.h"
1618
#include "llvm/IR/DiagnosticInfo.h"
1719
#include "llvm/IR/Instructions.h"
1820
#include "llvm/IR/IntrinsicsDirectX.h"
@@ -153,6 +155,22 @@ initRSBindingValidation(const mcdxbc::RootSignatureDesc &RSD,
153155
continue;
154156

155157
switch (Type) {
158+
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
159+
dxbc::RTS0::v1::RootConstants Const =
160+
RSD.ParametersContainer.getConstant(Loc);
161+
162+
llvm::dxil::ResourceInfo::ResourceBinding Binding;
163+
Binding.LowerBound = Const.ShaderRegister;
164+
Binding.Space = Const.RegisterSpace;
165+
Binding.Size = 1;
166+
167+
// Root Constants Bind to CBuffers
168+
Validation.addBinding(llvm::to_underlying(dxbc::DescriptorRangeType::CBV),
169+
Binding);
170+
171+
break;
172+
}
173+
156174
case llvm::to_underlying(dxbc::RootParameterType::SRV):
157175
case llvm::to_underlying(dxbc::RootParameterType::UAV):
158176
case llvm::to_underlying(dxbc::RootParameterType::CBV): {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1
2+
; expected-no-diagnostics
3+
; Root Signature(RootConstants(num32BitConstants=4, b2))
4+
5+
%__cblayout_CB = type <{ float }>
6+
7+
@CB.str = private unnamed_addr constant [3 x i8] c"CB\00", align 1
8+
9+
define void @CSMain() "hlsl.shader"="compute" {
10+
entry:
11+
; cbuffer CB : register(b2, space0) {
12+
; float a;
13+
; }
14+
%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)
15+
ret void
16+
}
17+
18+
!dx.rootsignatures = !{!0}
19+
20+
!0 = !{ptr @CSMain, !1, i32 2}
21+
!1 = !{!2}
22+
!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1 | FileCheck %s
2+
; CHECK: error: register CB (space=666, register=2) is not defined in Root Signature
3+
; Root Signature(RootConstants(num32BitConstants=4, b2))
4+
5+
%__cblayout_CB = type <{ float }>
6+
7+
@CB.str = private unnamed_addr constant [3 x i8] c"CB\00", align 1
8+
9+
define void @CSMain() "hlsl.shader"="compute" {
10+
entry:
11+
; cbuffer CB : register(b2, space666) {
12+
; float a;
13+
; }
14+
%CB = tail call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB, 4, 0)) @llvm.dx.resource.handlefrombinding(i32 666, i32 2, i32 1, i32 0, i1 false, ptr nonnull @CB.str)
15+
ret void
16+
}
17+
18+
!dx.rootsignatures = !{!0}
19+
20+
!0 = !{ptr @CSMain, !1, i32 2}
21+
!1 = !{!2}
22+
!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}

0 commit comments

Comments
 (0)