Skip to content

Commit a23497d

Browse files
committed
Fix invalid sample count for typed buffers in struct (#2763)
* Fix invalid sample count for typed buffers in struct * Decode resource prop in disasm, update tests
1 parent 547f5c8 commit a23497d

6 files changed

Lines changed: 176 additions & 6 deletions

File tree

lib/DXIL/DxilResourceProperties.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ DxilResourceProperties loadFromResourceBase(DxilResourceBase *Res) {
172172
Type *Ty = Res.GetRetType();
173173
RP.Typed.SingleComponent = dxilutil::IsResourceSingleComponent(Ty);
174174
RP.Typed.CompType = Res.GetCompType().GetKind();
175+
RP.Typed.SampleCountPow2 =
176+
DxilResourceProperties::kSampleCountUndefined;
175177
break;
176178
}
177179
};

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/annotateHandle.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// Make sure sampler and texture get correct annotateHandle.
44

5-
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle {{.*}}, i8 0, i8 2, %dx.types.ResourceProperties { i32 9, i32 0 }
6-
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle {{.*}}, i8 3, i8 14, %dx.types.ResourceProperties zeroinitializer
5+
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle {{.*}}, i8 0, i8 2, %dx.types.ResourceProperties { i32 457, i32 0 }) ; AnnotateHandle(res,resourceClass,resourceKind,props) resource: Texture2D<F32>
6+
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle {{.*}}, i8 3, i8 14, %dx.types.ResourceProperties zeroinitializer) ; AnnotateHandle(res,resourceClass,resourceKind,props) resource: SamplerState
77

88
SamplerState samplers : register(s0);
99
SamplerState foo() { return samplers; }

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/createFromHeap.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %dxc -T ps_6_6 %s | %FileCheck %s
22
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 216
3-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 0, i8 10, %dx.types.ResourceProperties { i32 41, i32 0 })
3+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 0, i8 10, %dx.types.ResourceProperties { i32 489, i32 0 }) ; AnnotateHandle(res,resourceClass,resourceKind,props) resource: TypedBuffer<F32>
44

55
uint ID;
66
float main(uint i:I): SV_Target {

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/createFromHeap2.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 216
55
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 216
66
// CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 216
7-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 1, i8 10, %dx.types.ResourceProperties { i32 46, i32 0 })
8-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 1, i8 10, %dx.types.ResourceProperties { i32 45, i32 2 })
9-
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 1, i8 10, %dx.types.ResourceProperties { i32 45, i32 2 })
7+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 1, i8 10, %dx.types.ResourceProperties { i32 494, i32 0 }) ; AnnotateHandle(res,resourceClass,resourceKind,props) resource: RWTypedBuffer<UNormF32>
8+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 1, i8 10, %dx.types.ResourceProperties { i32 493, i32 2 }) ; AnnotateHandle(res,resourceClass,resourceKind,props) resource: globallycoherent RWTypedBuffer<SNormF32>
9+
// CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle %{{.*}}, i8 1, i8 10, %dx.types.ResourceProperties { i32 493, i32 2 }) ; AnnotateHandle(res,resourceClass,resourceKind,props) resource: globallycoherent RWTypedBuffer<SNormF32>
1010

1111

1212
struct S {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s
2+
3+
// CHECK: ; Note: shader requires additional functionality:
4+
// CHECK: ; UAVs at every shader stage
5+
// CHECK: ; Typed UAV Load Additional Formats
6+
7+
// CHECK: call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32
8+
9+
struct S {
10+
RWBuffer<float4> buf;
11+
} s;
12+
13+
float4 main() : OUT {
14+
return s.buf[0];
15+
}

tools/clang/tools/dxcompiler/dxcdisassembler.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "dxc/Support/FileIOHelper.h"
3636
#include "dxc/DXIL/DxilUtil.h"
3737
#include "dxcutil.h"
38+
#include "dxc/DXIL/DxilInstructions.h"
39+
#include "dxc/DXIL/DxilResourceProperties.h"
3840

3941
using namespace llvm;
4042
using namespace hlsl;
@@ -1285,6 +1287,141 @@ static const char *OpCodeSignatures[] = {
12851287
};
12861288
// OPCODE-SIGS:END
12871289

1290+
LPCSTR ResourceKindToString(DXIL::ResourceKind RK) {
1291+
switch (RK)
1292+
{
1293+
case DXIL::ResourceKind::Texture1D: return "Texture1D";
1294+
case DXIL::ResourceKind::Texture2D: return "Texture2D";
1295+
case DXIL::ResourceKind::Texture2DMS: return "Texture2DMS";
1296+
case DXIL::ResourceKind::Texture3D: return "Texture3D";
1297+
case DXIL::ResourceKind::TextureCube: return "TextureCube";
1298+
case DXIL::ResourceKind::Texture1DArray: return "Texture1DArray";
1299+
case DXIL::ResourceKind::Texture2DArray: return "Texture2DArray";
1300+
case DXIL::ResourceKind::Texture2DMSArray: return "Texture2DMSArray";
1301+
case DXIL::ResourceKind::TextureCubeArray: return "TextureCubeArray";
1302+
case DXIL::ResourceKind::TypedBuffer: return "TypedBuffer";
1303+
case DXIL::ResourceKind::RawBuffer: return "ByteAddressBuffer";
1304+
case DXIL::ResourceKind::StructuredBuffer: return "StructuredBuffer";
1305+
case DXIL::ResourceKind::CBuffer: return "CBuffer";
1306+
case DXIL::ResourceKind::Sampler: return "Sampler";
1307+
case DXIL::ResourceKind::TBuffer: return "TBuffer";
1308+
case DXIL::ResourceKind::RTAccelerationStructure: return "RTAccelerationStructure";
1309+
case DXIL::ResourceKind::FeedbackTexture2D: return "FeedbackTexture2D";
1310+
case DXIL::ResourceKind::FeedbackTexture2DArray: return "FeedbackTexture2DArray";
1311+
case DXIL::ResourceKind::StructuredBufferWithCounter: return "StructuredBufferWithCounter";
1312+
case DXIL::ResourceKind::SamplerComparison: return "SamplerComparison";
1313+
default:
1314+
return "<invalid ResourceKind>";
1315+
}
1316+
}
1317+
1318+
LPCSTR CompTypeToString(DXIL::ComponentType CompType) {
1319+
switch (CompType) {
1320+
case DXIL::ComponentType::I1: return "I1";
1321+
case DXIL::ComponentType::I16: return "I16";
1322+
case DXIL::ComponentType::U16: return "U16";
1323+
case DXIL::ComponentType::I32: return "I32";
1324+
case DXIL::ComponentType::U32: return "U32";
1325+
case DXIL::ComponentType::I64: return "I64";
1326+
case DXIL::ComponentType::U64: return "U64";
1327+
case DXIL::ComponentType::F16: return "F16";
1328+
case DXIL::ComponentType::F32: return "F32";
1329+
case DXIL::ComponentType::F64: return "F64";
1330+
case DXIL::ComponentType::SNormF16: return "SNormF16";
1331+
case DXIL::ComponentType::UNormF16: return "UNormF16";
1332+
case DXIL::ComponentType::SNormF32: return "SNormF32";
1333+
case DXIL::ComponentType::UNormF32: return "UNormF32";
1334+
case DXIL::ComponentType::SNormF64: return "SNormF64";
1335+
case DXIL::ComponentType::UNormF64: return "UNormF64";
1336+
default:
1337+
return "<invalid CompType>";
1338+
}
1339+
}
1340+
1341+
LPCSTR SamplerFeedbackTypeToString(DXIL::SamplerFeedbackType SFT) {
1342+
switch(SFT) {
1343+
case DXIL::SamplerFeedbackType::MinMip: return "MinMip";
1344+
case DXIL::SamplerFeedbackType::MipRegionUsed: return "MipRegionUsed";
1345+
default:
1346+
return "<invalid sampler feedback type>";
1347+
}
1348+
}
1349+
1350+
void PrintResourceProperties(DxilResourceProperties &RP,
1351+
formatted_raw_ostream &OS) {
1352+
OS << " resource: ";
1353+
1354+
if (RP.Class == DXIL::ResourceClass::CBuffer) {
1355+
OS << "CBuffer";
1356+
return;
1357+
} else if (RP.Class == DXIL::ResourceClass::SRV &&
1358+
RP.Kind == DXIL::ResourceKind::TBuffer) {
1359+
OS << "TBuffer";
1360+
return;
1361+
}
1362+
1363+
if (RP.Class == DXIL::ResourceClass::Sampler) {
1364+
if (RP.Kind == DXIL::ResourceKind::Sampler)
1365+
OS << "SamplerState";
1366+
else if (RP.Kind == DXIL::ResourceKind::SamplerComparison)
1367+
OS << "SamplerComparisonState";
1368+
return;
1369+
}
1370+
1371+
bool bUAV = RP.Class == DXIL::ResourceClass::UAV;
1372+
LPCSTR RW = bUAV ? (RP.UAV.bROV ? "ROV" : "RW") : "";
1373+
LPCSTR GC = bUAV && RP.UAV.bGloballyCoherent ? "globallycoherent " : "";
1374+
1375+
switch (RP.Kind)
1376+
{
1377+
case DXIL::ResourceKind::Texture1D:
1378+
case DXIL::ResourceKind::Texture2D:
1379+
case DXIL::ResourceKind::Texture3D:
1380+
case DXIL::ResourceKind::TextureCube:
1381+
case DXIL::ResourceKind::Texture1DArray:
1382+
case DXIL::ResourceKind::Texture2DArray:
1383+
case DXIL::ResourceKind::TextureCubeArray:
1384+
case DXIL::ResourceKind::TypedBuffer:
1385+
OS << GC << RW << ResourceKindToString(RP.Kind);
1386+
OS << "<" << CompTypeToString(RP.Typed.CompType)
1387+
<< (bUAV && !RP.Typed.SingleComponent ? "[vec]" : "")
1388+
<< ">";
1389+
break;
1390+
1391+
case DXIL::ResourceKind::Texture2DMS:
1392+
case DXIL::ResourceKind::Texture2DMSArray:
1393+
OS << ResourceKindToString(RP.Kind);
1394+
OS << "<" << CompTypeToString(RP.Typed.CompType)
1395+
<< ", samples=" << RP.getSampleCount()
1396+
<< ">";
1397+
break;
1398+
1399+
case DXIL::ResourceKind::RawBuffer:
1400+
OS << GC << RW << ResourceKindToString(RP.Kind);
1401+
break;
1402+
1403+
case DXIL::ResourceKind::StructuredBuffer:
1404+
case DXIL::ResourceKind::StructuredBufferWithCounter:
1405+
OS << GC << RW << ResourceKindToString(RP.Kind);
1406+
OS << "<stride=" << RP.ElementStride << ">";
1407+
break;
1408+
1409+
case DXIL::ResourceKind::RTAccelerationStructure:
1410+
OS << ResourceKindToString(RP.Kind);
1411+
break;
1412+
1413+
case DXIL::ResourceKind::FeedbackTexture2D:
1414+
case DXIL::ResourceKind::FeedbackTexture2DArray:
1415+
OS << ResourceKindToString(RP.Kind);
1416+
OS << "<" << SamplerFeedbackTypeToString(RP.SamplerFeedbackType) << ">";
1417+
break;
1418+
1419+
default:
1420+
OS << "<invalid resource properties>";
1421+
break;
1422+
}
1423+
}
1424+
12881425
class DxcAssemblyAnnotationWriter : public llvm::AssemblyAnnotationWriter {
12891426
public:
12901427
~DxcAssemblyAnnotationWriter() {}
@@ -1339,6 +1476,22 @@ class DxcAssemblyAnnotationWriter : public llvm::AssemblyAnnotationWriter {
13391476
DXIL::OpCode opcode = (DXIL::OpCode)opcodeVal;
13401477
OS << " ; " << hlsl::OP::GetOpCodeName(opcode)
13411478
<< OpCodeSignatures[opcodeVal];
1479+
1480+
// Add extra decoding for certain ops
1481+
switch (opcode) {
1482+
case DXIL::OpCode::AnnotateHandle: {
1483+
// Decode resource properties
1484+
DxilInst_AnnotateHandle AH(const_cast<CallInst*>(CI));
1485+
if (Constant *Props = dyn_cast<Constant>(AH.get_props())) {
1486+
DXIL::ResourceClass RC = static_cast<DXIL::ResourceClass>(AH.get_resourceClass_val());
1487+
DXIL::ResourceKind RK = static_cast<DXIL::ResourceKind>(AH.get_resourceKind_val());
1488+
DxilResourceProperties RP = resource_helper::loadFromConstant(*Props, RC, RK);
1489+
PrintResourceProperties(RP, OS);
1490+
}
1491+
} break;
1492+
default:
1493+
break;
1494+
}
13421495
}
13431496
};
13441497

0 commit comments

Comments
 (0)