Skip to content

Commit dd2f7ca

Browse files
author
joaosaffran
committed
adding validation
1 parent 75d0703 commit dd2f7ca

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
1-
// RUN: %clang_dxc -triple dxil-pc-shadermodel6.3-library -x hlsl -o - %s -verify
21

32
#define ROOT_SIGNATURE \
43
"RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
5-
"CBV(b0, visibility=SHADER_VISIBILITY_ALL), " \
6-
"DescriptorTable(SRV(t0, numDescriptors=3), visibility=SHADER_VISIBILITY_PIXEL), " \
7-
"DescriptorTable(Sampler(s0, numDescriptors=2), visibility=SHADER_VISIBILITY_PIXEL), " \
8-
"DescriptorTable(UAV(u0, numDescriptors=1), visibility=SHADER_VISIBILITY_ALL)"
4+
"CBV(b3, space=1, visibility=SHADER_VISIBILITY_ALL), " \
5+
"DescriptorTable(SRV(t0, space=0, numDescriptors=1), visibility=SHADER_VISIBILITY_ALL), " \
6+
"DescriptorTable(Sampler(s0, numDescriptors=2), visibility=SHADER_VISIBILITY_ALL), " \
7+
"DescriptorTable(UAV(u0, numDescriptors=unbounded), visibility=SHADER_VISIBILITY_ALL)"
98

109
cbuffer CB : register(b3, space2) {
1110
float a;
1211
}
1312

14-
StructuredBuffer<int> In : register(t0);
13+
StructuredBuffer<int> In : register(t0, space0);
1514
RWStructuredBuffer<int> Out : register(u0);
1615

1716
RWBuffer<float> UAV : register(u3);
1817

1918
RWBuffer<float> UAV1 : register(u2), UAV2 : register(u4);
2019

21-
RWBuffer<float> UAV3 : register(space5);
20+
RWBuffer<float> UAV3 : register(space0);
2221

23-
float f : register(c5);
2422

25-
int4 intv : register(c2);
26-
27-
double dar[5] : register(c3);
28-
29-
struct S {
30-
int a;
31-
};
32-
33-
S s : register(c10);
3423

3524
// Compute Shader for UAV testing
3625
[numthreads(8, 8, 1)]
3726
[RootSignature(ROOT_SIGNATURE)]
38-
void CSMain(uint3 id : SV_DispatchThreadID)
27+
void CSMain(uint id : SV_GroupID)
3928
{
40-
In[0] = id;
41-
Out[0] = In[0];
29+
Out[0] = a + id + In[0] + UAV[0] + UAV1[0] + UAV3[0];
4230
}

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "DXILRootSignature.h"
1111
#include "DXILShaderFlags.h"
1212
#include "DirectX.h"
13+
#include "llvm/ADT/IntervalMap.h"
1314
#include "llvm/ADT/STLForwardCompat.h"
1415
#include "llvm/ADT/SmallString.h"
1516
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -86,7 +87,9 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
8687
}
8788
}
8889
}
89-
90+
uint64_t combine_uint32_to_uint64(uint32_t high, uint32_t low) {
91+
return (static_cast<uint64_t>(high) << 32) | low;
92+
}
9093
static void reportErrors(Module &M, DXILResourceMap &DRM,
9194
DXILResourceBindingInfo &DRBI,
9295
RootSignatureBindingInfo &RSBI,
@@ -101,27 +104,52 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
101104
"DXILResourceImplicitBinding pass");
102105
// Assuming this is used to validate only the root signature assigned to the
103106
// entry function.
107+
//Start test stuff
108+
if(MMI.EntryPropertyVec.size() == 0)
109+
return;
110+
104111
std::optional<mcdxbc::RootSignatureDesc> RootSigDesc =
105112
RSBI.getDescForFunction(MMI.EntryPropertyVec[0].Entry);
106113
if (!RootSigDesc)
107114
return;
108115

109-
for (const mcdxbc::RootParameterInfo &Info :
110-
RootSigDesc->ParametersContainer) {
116+
using MapT = llvm::IntervalMap<uint64_t, llvm::dxil::ResourceInfo::ResourceBinding, sizeof(llvm::dxil::ResourceInfo::ResourceBinding), llvm::IntervalMapInfo<uint64_t>>;
117+
MapT::Allocator Allocator;
118+
MapT BindingsMap(Allocator);
119+
auto RSD = *RootSigDesc;
120+
for (size_t I = 0; I < RSD.ParametersContainer.size(); I++) {
111121
const auto &[Type, Loc] =
112-
RootSigDesc->ParametersContainer.getTypeAndLocForParameter(
113-
Info.Location);
122+
RootSigDesc->ParametersContainer.getTypeAndLocForParameter(I);
114123
switch (Type) {
115-
case llvm::to_underlying(dxbc::RootParameterType::CBV):
124+
case llvm::to_underlying(dxbc::RootParameterType::CBV):{
116125
dxbc::RTS0::v2::RootDescriptor Desc =
117126
RootSigDesc->ParametersContainer.getRootDescriptor(Loc);
118127

119128
llvm::dxil::ResourceInfo::ResourceBinding Binding;
120129
Binding.LowerBound = Desc.ShaderRegister;
121130
Binding.Space = Desc.RegisterSpace;
122131
Binding.Size = 1;
132+
133+
BindingsMap.insert(combine_uint32_to_uint64(Binding.Space, Binding.LowerBound), combine_uint32_to_uint64(Binding.Space, Binding.LowerBound + Binding.Size -1), Binding);
123134
break;
124135
}
136+
// case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):{
137+
// mcdxbc::DescriptorTable Table =
138+
// RootSigDesc->ParametersContainer.getDescriptorTable(Loc);
139+
// for (const dxbc::RTS0::v2::DescriptorRange &Range : Table){
140+
// Range.
141+
// }
142+
143+
// break;
144+
// }
145+
}
146+
147+
}
148+
149+
for(const auto &CBuf : DRM.cbuffers()) {
150+
auto Binding = CBuf.getBinding();
151+
if(!BindingsMap.overlaps(combine_uint32_to_uint64(Binding.Space, Binding.LowerBound), combine_uint32_to_uint64(Binding.Space, Binding.LowerBound + Binding.Size -1)))
152+
auto X = 1;
125153
}
126154
}
127155
} // namespace
@@ -146,7 +174,7 @@ class DXILPostOptimizationValidationLegacy : public ModulePass {
146174
DXILResourceBindingInfo &DRBI =
147175
getAnalysis<DXILResourceBindingWrapperPass>().getBindingInfo();
148176

149-
RootSignatureBindingInfo &RSBI =
177+
RootSignatureBindingInfo& RSBI =
150178
getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
151179
dxil::ModuleMetadataInfo &MMI =
152180
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();

0 commit comments

Comments
 (0)