Skip to content

Commit c5bb883

Browse files
committed
fixing metadata and format generation
1 parent 12f0e48 commit c5bb883

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ class ResourceTypeInfo {
293293

294294
struct TypedInfo {
295295
dxil::ElementType ElementTy;
296+
// Some 64 byte types are treated as 32 byte types in DXIL.
297+
dxil::ElementType DXILTargetTy;
296298
uint32_t ElementCount;
297299

298300
bool operator==(const TypedInfo &RHS) const {

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
206206
return ElementType::Invalid;
207207
}
208208

209+
static dxil::ElementType toDXILTargetType(Type *Ty, bool IsSigned) {
210+
// TODO: Handle unorm, snorm, and packed.
211+
Type *ScalarTy = Ty->getScalarType();
212+
if (ScalarTy->isIntegerTy(64) || ScalarTy->isDoubleTy())
213+
return ElementType::U32;
214+
return toDXILElementType(Ty, IsSigned);
215+
}
216+
209217
ResourceTypeInfo::ResourceTypeInfo(TargetExtType *HandleTy,
210218
const dxil::ResourceClass RC_,
211219
const dxil::ResourceKind Kind_)
@@ -569,10 +577,11 @@ ResourceTypeInfo::TypedInfo ResourceTypeInfo::getTyped() const {
569577

570578
auto [ElTy, IsSigned] = getTypedElementType(Kind, HandleTy);
571579
dxil::ElementType ET = toDXILElementType(ElTy, IsSigned);
580+
dxil::ElementType DXILTargetTy = toDXILTargetType(ElTy, IsSigned);
572581
uint32_t Count = 1;
573582
if (auto *VTy = dyn_cast<FixedVectorType>(ElTy))
574583
Count = VTy->getNumElements();
575-
return {ET, Count};
584+
return {ET, DXILTargetTy, Count};
576585
}
577586

578587
dxil::SamplerFeedbackType ResourceTypeInfo::getFeedbackType() const {
@@ -714,7 +723,8 @@ MDTuple *ResourceInfo::getAsMetadata(Module &M,
714723
Tags.push_back(getIntMD(RTI.getStruct(DL).Stride));
715724
} else if (RTI.isTyped()) {
716725
Tags.push_back(getIntMD(llvm::to_underlying(ExtPropTags::ElementType)));
717-
Tags.push_back(getIntMD(llvm::to_underlying(RTI.getTyped().ElementTy)));
726+
Tags.push_back(
727+
getIntMD(llvm::to_underlying(RTI.getTyped().DXILTargetTy)));
718728
} else if (RTI.isFeedback()) {
719729
Tags.push_back(
720730
getIntMD(llvm::to_underlying(ExtPropTags::SamplerFeedbackKind)));

llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static StringRef getRCPrefix(dxil::ResourceClass RC) {
4949

5050
static StringRef getFormatName(const dxil::ResourceTypeInfo &RI) {
5151
if (RI.isTyped()) {
52-
switch (RI.getTyped().ElementTy) {
52+
switch (RI.getTyped().DXILTargetTy) {
5353
case dxil::ElementType::I1:
5454
return "i1";
5555
case dxil::ElementType::I16:

llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ target triple = "dxil-pc-shadermodel6.6-compute"
2222
; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ---------
2323
; PRINT-NEXT:; Zero texture f16 buf T0 t0 1
2424
; PRINT-NEXT:; One texture f32 buf T1 t1 1
25-
; PRINT-NEXT:; Two texture f64 buf T2 t2 1
25+
; PRINT-NEXT:; Two texture u32 buf T2 t2 1
2626
; PRINT-NEXT:; Three texture i32 buf T3 t3 1
2727
; PRINT-NEXT:; Four texture byte r/o T4 t5 1
2828
; PRINT-NEXT:; Five texture struct r/o T5 t6 1
29-
; PRINT-NEXT:; Six texture u64 buf T6 t10,space2 1
29+
; PRINT-NEXT:; Six texture u32 buf T6 t10,space2 1
3030
; PRINT-NEXT:; Array texture f32 buf T7 t4,space3 100
31-
; PRINT-NEXT:; Array2 texture f64 buf T8 t2,space4 unbounded
32-
; PRINT-NEXT:; Seven texture u64 buf T9 t20,space5 1
31+
; PRINT-NEXT:; Array2 texture u32 buf T8 t2,space4 unbounded
32+
; PRINT-NEXT:; Seven texture u32 buf T9 t20,space5 1
3333
;
3434

3535
define void @test() #0 {
@@ -120,15 +120,14 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
120120
; CHECK: ![[Half]] = !{i32 0, i32 8}
121121
; CHECK: ![[One]] = !{i32 1, ptr @One, !"One", i32 0, i32 1, i32 1, i32 10, i32 0, ![[Float:[0-9]+]]}
122122
; CHECK: ![[Float]] = !{i32 0, i32 9}
123-
; CHECK: ![[Two]] = !{i32 2, ptr @Two, !"Two", i32 0, i32 2, i32 1, i32 10, i32 0, ![[Double:[0-9]+]]}
124-
; CHECK: ![[Double]] = !{i32 0, i32 10}
123+
; CHECK: ![[Two]] = !{i32 2, ptr @Two, !"Two", i32 0, i32 2, i32 1, i32 10, i32 0, ![[U32:[0-9]+]]}
124+
; CHECK: ![[U32]] = !{i32 0, i32 5}
125125
; CHECK: ![[Three]] = !{i32 3, ptr @Three, !"Three", i32 0, i32 3, i32 1, i32 10, i32 0, ![[I32:[0-9]+]]}
126126
; CHECK: ![[I32]] = !{i32 0, i32 4}
127127
; CHECK: ![[Four]] = !{i32 4, ptr @Four, !"Four", i32 0, i32 5, i32 1, i32 11, i32 0, null}
128128
; CHECK: ![[Five]] = !{i32 5, ptr @Five, !"Five", i32 0, i32 6, i32 1, i32 12, i32 0, ![[FiveStride:[0-9]+]]}
129129
; CHECK: ![[FiveStride]] = !{i32 1, i32 2}
130-
; CHECK: ![[Six]] = !{i32 6, ptr @Six, !"Six", i32 2, i32 10, i32 1, i32 10, i32 0, ![[U64:[0-9]+]]}
131-
; CHECK: ![[U64]] = !{i32 0, i32 7}
130+
; CHECK: ![[Six]] = !{i32 6, ptr @Six, !"Six", i32 2, i32 10, i32 1, i32 10, i32 0, ![[U32:[0-9]+]]}
132131
; CHECK: ![[Array]] = !{i32 7, ptr @Array, !"Array", i32 3, i32 4, i32 100, i32 10, i32 0, ![[Float]]}
133-
; CHECK: ![[Array2]] = !{i32 8, ptr @Array2, !"Array2", i32 4, i32 2, i32 -1, i32 10, i32 0, ![[Double]]}
134-
; CHECK: ![[Seven]] = !{i32 9, ptr @Seven, !"Seven", i32 5, i32 20, i32 1, i32 10, i32 0, ![[U64]]}
132+
; CHECK: ![[Array2]] = !{i32 8, ptr @Array2, !"Array2", i32 4, i32 2, i32 -1, i32 10, i32 0, ![[U32]]}
133+
; CHECK: ![[Seven]] = !{i32 9, ptr @Seven, !"Seven", i32 5, i32 20, i32 1, i32 10, i32 0, ![[U32]]}

llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ target triple = "dxil-pc-shadermodel6.6-compute"
2525
; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ---------
2626
; PRINT-NEXT:; Zero UAV f16 buf U0 u0 1
2727
; PRINT-NEXT:; One UAV f32 buf U1 u1 1
28-
; PRINT-NEXT:; Two UAV f64 buf U2 u2 1
28+
; PRINT-NEXT:; Two UAV u32 buf U2 u2 1
2929
; PRINT-NEXT:; Three UAV i32 buf U3 u3 1
3030
; PRINT-NEXT:; Four UAV byte r/w U4 u5 1
3131
; PRINT-NEXT:; Five UAV struct r/w U5 u6 1
3232
; PRINT-NEXT:; Six UAV i32 buf U6 u7 1
3333
; PRINT-NEXT:; Seven UAV struct r/w U7 u8 1
3434
; PRINT-NEXT:; Eight UAV byte r/w U8 u9 1
35-
; PRINT-NEXT:; Nine UAV u64 buf U9 u10,space2 1
35+
; PRINT-NEXT:; Nine UAV u32 buf U9 u10,space2 1
3636
; PRINT-NEXT:; Array UAV f32 buf U10 u4,space3 100
37-
; PRINT-NEXT:; Array2 UAV f64 buf U11 u2,space4 unbounded
38-
; PRINT-NEXT:; Ten UAV u64 buf U12 u22,space5 1
37+
; PRINT-NEXT:; Array2 UAV u32 buf U11 u2,space4 unbounded
38+
; PRINT-NEXT:; Ten UAV u32 buf U12 u22,space5 1
3939

4040
define void @test() #0 {
4141
; RWBuffer<half4> Zero : register(u0)
@@ -144,8 +144,8 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
144144
; CHECK: ![[Half]] = !{i32 0, i32 8}
145145
; CHECK: ![[One]] = !{i32 1, ptr @One, !"One", i32 0, i32 1, i32 1, i32 10, i1 false, i1 false, i1 false, ![[Float:[0-9]+]]}
146146
; CHECK: ![[Float]] = !{i32 0, i32 9}
147-
; CHECK: ![[Two]] = !{i32 2, ptr @Two, !"Two", i32 0, i32 2, i32 1, i32 10, i1 false, i1 false, i1 false, ![[Double:[0-9]+]]}
148-
; CHECK: ![[Double]] = !{i32 0, i32 10}
147+
; CHECK: ![[Two]] = !{i32 2, ptr @Two, !"Two", i32 0, i32 2, i32 1, i32 10, i1 false, i1 false, i1 false, ![[U32:[0-9]+]]}
148+
; CHECK: ![[U32]] = !{i32 0, i32 5}
149149
; CHECK: ![[Three]] = !{i32 3, ptr @Three, !"Three", i32 0, i32 3, i32 1, i32 10, i1 false, i1 false, i1 false, ![[I32:[0-9]+]]}
150150
; CHECK: ![[I32]] = !{i32 0, i32 4}
151151
; CHECK: ![[Four]] = !{i32 4, ptr @Four, !"Four", i32 0, i32 5, i32 1, i32 11, i1 false, i1 false, i1 false, null}
@@ -155,8 +155,7 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
155155
; CHECK: ![[Seven]] = !{i32 7, ptr @Seven, !"Seven", i32 0, i32 8, i32 1, i32 12, i1 false, i1 false, i1 true, ![[SevenStride:[0-9]+]]}
156156
; CHECK: ![[SevenStride]] = !{i32 1, i32 16}
157157
; CHECK: ![[Eight]] = !{i32 8, ptr @Eight, !"Eight", i32 0, i32 9, i32 1, i32 11, i1 false, i1 false, i1 true, null}
158-
; CHECK: ![[Nine]] = !{i32 9, ptr @Nine, !"Nine", i32 2, i32 10, i32 1, i32 10, i1 false, i1 false, i1 false, ![[U64:[0-9]+]]}
159-
; CHECK: ![[U64]] = !{i32 0, i32 7}
158+
; CHECK: ![[Nine]] = !{i32 9, ptr @Nine, !"Nine", i32 2, i32 10, i32 1, i32 10, i1 false, i1 false, i1 false, ![[U32]]}
160159
; CHECK: ![[Array]] = !{i32 10, ptr @Array, !"Array", i32 3, i32 4, i32 100, i32 10, i1 false, i1 false, i1 false, ![[Float]]}
161-
; CHECK: ![[Array2]] = !{i32 11, ptr @Array2, !"Array2", i32 4, i32 2, i32 -1, i32 10, i1 false, i1 false, i1 false, ![[Double]]}
160+
; CHECK: ![[Array2]] = !{i32 11, ptr @Array2, !"Array2", i32 4, i32 2, i32 -1, i32 10, i1 false, i1 false, i1 false, ![[U32]]}
162161
; CHECK: ![[Ten]] = !{i32 12, ptr @Ten, !"Ten", i32 5, i32 22, i32 1, i32 10, i1 false, i1 false, i1 false, ![[U64:[0-9]+]]}

0 commit comments

Comments
 (0)