Skip to content

Commit 0168df1

Browse files
authored
[SER] HitObject_FromRayQuery[WithAttrs] DXIL opcodes and check-pass tests (#7277)
Add the DXIL operations and a passing validation test for: - HitObject_FromRayQuery - HitObject_FromRayQueryWithAttrs DXC SER implementation tracker: #7214
1 parent bc9044a commit 0168df1

File tree

5 files changed

+230
-30
lines changed

5 files changed

+230
-30
lines changed

include/dxc/DXIL/DxilConstants.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ enum class OpCode : unsigned {
503503
ReservedA1 = 260, // reserved
504504
ReservedA2 = 261, // reserved
505505
ReservedB0 = 262, // reserved
506-
ReservedB1 = 263, // reserved
507506
ReservedB10 = 272, // reserved
508507
ReservedB11 = 273, // reserved
509508
ReservedB12 = 274, // reserved
@@ -514,7 +513,6 @@ enum class OpCode : unsigned {
514513
ReservedB17 = 279, // reserved
515514
ReservedB18 = 280, // reserved
516515
ReservedB19 = 281, // reserved
517-
ReservedB2 = 264, // reserved
518516
ReservedB20 = 282, // reserved
519517
ReservedB21 = 283, // reserved
520518
ReservedB22 = 284, // reserved
@@ -916,6 +914,11 @@ enum class OpCode : unsigned {
916914
// operation with a mipmap-level offset
917915

918916
// Shader Execution Reordering
917+
HitObject_FromRayQuery = 263, // Creates a new HitObject representing a
918+
// committed hit from a RayQuery
919+
HitObject_FromRayQueryWithAttrs =
920+
264, // Creates a new HitObject representing a committed hit from a
921+
// RayQuery and committed attributes
919922
HitObject_MakeMiss = 265, // Creates a new HitObject representing a miss
920923
HitObject_MakeNop = 266, // Creates an empty nop HitObject
921924

@@ -1294,6 +1297,8 @@ enum class OpCodeClass : unsigned {
12941297
WriteSamplerFeedbackLevel,
12951298

12961299
// Shader Execution Reordering
1300+
HitObject_FromRayQuery,
1301+
HitObject_FromRayQueryWithAttrs,
12971302
HitObject_MakeMiss,
12981303
HitObject_MakeNop,
12991304

@@ -1361,7 +1366,7 @@ enum class OpCodeClass : unsigned {
13611366
NumOpClasses_Dxil_1_7 = 153,
13621367
NumOpClasses_Dxil_1_8 = 174,
13631368

1364-
NumOpClasses = 179 // exclusive last value of enumeration
1369+
NumOpClasses = 181 // exclusive last value of enumeration
13651370
};
13661371
// OPCODECLASS-ENUM:END
13671372

include/dxc/DXIL/DxilInstructions.h

+63
Original file line numberDiff line numberDiff line change
@@ -8850,6 +8850,69 @@ struct DxilInst_AllocateRayQuery2 {
88508850
}
88518851
};
88528852

8853+
/// This instruction Creates a new HitObject representing a committed hit from a
8854+
/// RayQuery
8855+
struct DxilInst_HitObject_FromRayQuery {
8856+
llvm::Instruction *Instr;
8857+
// Construction and identification
8858+
DxilInst_HitObject_FromRayQuery(llvm::Instruction *pInstr) : Instr(pInstr) {}
8859+
operator bool() const {
8860+
return hlsl::OP::IsDxilOpFuncCallInst(
8861+
Instr, hlsl::OP::OpCode::HitObject_FromRayQuery);
8862+
}
8863+
// Validation support
8864+
bool isAllowed() const { return true; }
8865+
bool isArgumentListValid() const {
8866+
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
8867+
return false;
8868+
return true;
8869+
}
8870+
// Metadata
8871+
bool requiresUniformInputs() const { return false; }
8872+
// Operand indexes
8873+
enum OperandIdx {
8874+
arg_rayQueryHandle = 1,
8875+
};
8876+
// Accessors
8877+
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
8878+
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
8879+
};
8880+
8881+
/// This instruction Creates a new HitObject representing a committed hit from a
8882+
/// RayQuery and committed attributes
8883+
struct DxilInst_HitObject_FromRayQueryWithAttrs {
8884+
llvm::Instruction *Instr;
8885+
// Construction and identification
8886+
DxilInst_HitObject_FromRayQueryWithAttrs(llvm::Instruction *pInstr)
8887+
: Instr(pInstr) {}
8888+
operator bool() const {
8889+
return hlsl::OP::IsDxilOpFuncCallInst(
8890+
Instr, hlsl::OP::OpCode::HitObject_FromRayQueryWithAttrs);
8891+
}
8892+
// Validation support
8893+
bool isAllowed() const { return true; }
8894+
bool isArgumentListValid() const {
8895+
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
8896+
return false;
8897+
return true;
8898+
}
8899+
// Metadata
8900+
bool requiresUniformInputs() const { return false; }
8901+
// Operand indexes
8902+
enum OperandIdx {
8903+
arg_rayQueryHandle = 1,
8904+
arg_HitKind = 2,
8905+
arg_CommittedAttribs = 3,
8906+
};
8907+
// Accessors
8908+
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
8909+
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
8910+
llvm::Value *get_HitKind() const { return Instr->getOperand(2); }
8911+
void set_HitKind(llvm::Value *val) { Instr->setOperand(2, val); }
8912+
llvm::Value *get_CommittedAttribs() const { return Instr->getOperand(3); }
8913+
void set_CommittedAttribs(llvm::Value *val) { Instr->setOperand(3, val); }
8914+
};
8915+
88538916
/// This instruction Creates a new HitObject representing a miss
88548917
struct DxilInst_HitObject_MakeMiss {
88558918
llvm::Instruction *Instr;

lib/DXIL/DxilOperations.cpp

+31-25
Original file line numberDiff line numberDiff line change
@@ -2311,24 +2311,24 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
23112311
0,
23122312
{},
23132313
{}}, // Overloads: v
2314-
{OC::ReservedB1,
2315-
"ReservedB1",
2316-
OCC::Reserved,
2317-
"reserved",
2318-
Attribute::None,
2319-
0,
2320-
{},
2321-
{}}, // Overloads: v
2322-
{OC::ReservedB2,
2323-
"ReservedB2",
2324-
OCC::Reserved,
2325-
"reserved",
2326-
Attribute::None,
2314+
2315+
// Shader Execution Reordering
2316+
{OC::HitObject_FromRayQuery,
2317+
"HitObject_FromRayQuery",
2318+
OCC::HitObject_FromRayQuery,
2319+
"hitObject_FromRayQuery",
2320+
Attribute::ReadOnly,
23272321
0,
23282322
{},
23292323
{}}, // Overloads: v
2330-
2331-
// Shader Execution Reordering
2324+
{OC::HitObject_FromRayQueryWithAttrs,
2325+
"HitObject_FromRayQueryWithAttrs",
2326+
OCC::HitObject_FromRayQueryWithAttrs,
2327+
"hitObject_FromRayQueryWithAttrs",
2328+
Attribute::ReadOnly,
2329+
1,
2330+
{{0x100}},
2331+
{{0x0}}}, // Overloads: u
23322332
{OC::HitObject_MakeMiss,
23332333
"HitObject_MakeMiss",
23342334
OCC::HitObject_MakeMiss,
@@ -3446,8 +3446,10 @@ void OP::GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
34463446
minor = 9;
34473447
return;
34483448
}
3449-
// Instructions: HitObject_MakeMiss=265, HitObject_MakeNop=266
3450-
if ((265 <= op && op <= 266)) {
3449+
// Instructions: HitObject_FromRayQuery=263,
3450+
// HitObject_FromRayQueryWithAttrs=264, HitObject_MakeMiss=265,
3451+
// HitObject_MakeNop=266
3452+
if ((263 <= op && op <= 266)) {
34513453
major = 6;
34523454
minor = 9;
34533455
mask =
@@ -5622,16 +5624,20 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
56225624
A(pV);
56235625
A(pI32);
56245626
break;
5625-
case OpCode::ReservedB1:
5626-
A(pV);
5627+
5628+
// Shader Execution Reordering
5629+
case OpCode::HitObject_FromRayQuery:
5630+
A(pHit);
5631+
A(pI32);
56275632
A(pI32);
56285633
break;
5629-
case OpCode::ReservedB2:
5630-
A(pV);
5634+
case OpCode::HitObject_FromRayQueryWithAttrs:
5635+
A(pHit);
5636+
A(pI32);
5637+
A(pI32);
56315638
A(pI32);
5639+
A(udt);
56325640
break;
5633-
5634-
// Shader Execution Reordering
56355641
case OpCode::HitObject_MakeMiss:
56365642
A(pHit);
56375643
A(pI32);
@@ -5997,6 +6003,7 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
59976003
return nullptr;
59986004
return FT->getParamType(15);
59996005
case OpCode::ReportHit:
6006+
case OpCode::HitObject_FromRayQueryWithAttrs:
60006007
if (FT->getNumParams() <= 3)
60016008
return nullptr;
60026009
return FT->getParamType(3);
@@ -6080,8 +6087,7 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
60806087
case OpCode::ReservedA1:
60816088
case OpCode::ReservedA2:
60826089
case OpCode::ReservedB0:
6083-
case OpCode::ReservedB1:
6084-
case OpCode::ReservedB2:
6090+
case OpCode::HitObject_FromRayQuery:
60856091
case OpCode::HitObject_MakeMiss:
60866092
case OpCode::HitObject_MakeNop:
60876093
case OpCode::ReservedB5:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
; REQUIRES: dxil-1-9
2+
; RUN: %dxv %s | FileCheck %s
3+
4+
; CHECK: Validation succeeded.
5+
6+
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
7+
target triple = "dxil-ms-dx"
8+
9+
%dx.types.Handle = type { i8* }
10+
%struct.Payload = type { <3 x float> }
11+
%struct.CustomAttrs = type { float, float }
12+
%dx.types.ResourceProperties = type { i32, i32 }
13+
%dx.types.HitObject = type { i8* }
14+
%struct.RaytracingAccelerationStructure = type { i32 }
15+
16+
@"\01?RTAS@@3URaytracingAccelerationStructure@@A" = external constant %dx.types.Handle, align 4
17+
18+
; Function Attrs: nounwind
19+
declare void @llvm.lifetime.start(i64, i8* nocapture) #0
20+
21+
; Function Attrs: nounwind
22+
declare void @llvm.lifetime.end(i64, i8* nocapture) #0
23+
24+
; Function Attrs: nounwind
25+
define void @"\01?main@@YAXXZ"() #0 {
26+
%1 = load %dx.types.Handle, %dx.types.Handle* @"\01?RTAS@@3URaytracingAccelerationStructure@@A", align 4
27+
%2 = alloca %struct.CustomAttrs, align 4
28+
%3 = call i32 @dx.op.allocateRayQuery(i32 178, i32 5) ; AllocateRayQuery(constRayFlags)
29+
%4 = call %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32 160, %dx.types.Handle %1) ; CreateHandleForLib(Resource)
30+
%5 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %4, %dx.types.ResourceProperties { i32 16, i32 0 }) ; AnnotateHandle(res,props) resource: RTAccelerationStructure
31+
call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %3, %dx.types.Handle %5, i32 0, i32 255, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 9.999000e+03) ; RayQuery_TraceRayInline(rayQueryHandle,accelerationStructure,rayFlags,instanceInclusionMask,origin_X,origin_Y,origin_Z,tMin,direction_X,direction_Y,direction_Z,tMax)
32+
%6 = call %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32 263, i32 %3) ; HitObject_FromRayQuery(rayQueryHandle)
33+
%7 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %3, i32 16, %struct.CustomAttrs* nonnull %2) ; HitObject_FromRayQueryWithAttrs(rayQueryHandle,HitKind,CommittedAttribs)
34+
ret void
35+
}
36+
37+
; Function Attrs: nounwind
38+
declare i32 @dx.op.allocateRayQuery(i32, i32) #0
39+
40+
; Function Attrs: nounwind
41+
declare void @dx.op.rayQuery_TraceRayInline(i32, i32, %dx.types.Handle, i32, i32, float, float, float, float, float, float, float, float) #0
42+
43+
; Function Attrs: nounwind readonly
44+
declare %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32, i32, i32, %struct.CustomAttrs*) #1
45+
46+
; Function Attrs: nounwind readonly
47+
declare %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32, i32) #1
48+
49+
; Function Attrs: nounwind readnone
50+
declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #2
51+
52+
; Function Attrs: nounwind readonly
53+
declare %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32, %dx.types.Handle) #1
54+
55+
attributes #0 = { nounwind }
56+
attributes #1 = { nounwind readonly }
57+
attributes #2 = { nounwind readnone }
58+
59+
!dx.version = !{!0}
60+
!dx.valver = !{!0}
61+
!dx.shaderModel = !{!1}
62+
!dx.resources = !{!2}
63+
!dx.typeAnnotations = !{!6}
64+
!dx.dxrPayloadAnnotations = !{!10}
65+
!dx.entryPoints = !{!13, !15}
66+
67+
!0 = !{i32 1, i32 9}
68+
!1 = !{!"lib", i32 6, i32 9}
69+
!2 = !{!3, null, null, null}
70+
!3 = !{!4}
71+
!4 = !{i32 0, %struct.RaytracingAccelerationStructure* bitcast (%dx.types.Handle* @"\01?RTAS@@3URaytracingAccelerationStructure@@A" to %struct.RaytracingAccelerationStructure*), !"RTAS", i32 -1, i32 -1, i32 1, i32 16, i32 0, !5}
72+
!5 = !{i32 0, i32 4}
73+
!6 = !{i32 1, void ()* @"\01?main@@YAXXZ", !7}
74+
!7 = !{!8}
75+
!8 = !{i32 1, !9, !9}
76+
!9 = !{}
77+
!10 = !{i32 0, %struct.Payload undef, !11}
78+
!11 = !{!12}
79+
!12 = !{i32 0, i32 8210}
80+
!13 = !{null, !"", null, !2, !14}
81+
!14 = !{i32 0, i64 33554432}
82+
!15 = !{void ()* @"\01?main@@YAXXZ", !"\01?main@@YAXXZ", null, null, !16}
83+
!16 = !{i32 8, i32 7, i32 5, !17}
84+
!17 = !{i32 0}

utils/hct/hctdb.py

+44-2
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,10 @@ def populate_categories_and_models(self):
848848
self.name_idx[i].category = "Extended Command Information"
849849
self.name_idx[i].shader_stages = ("vertex",)
850850
self.name_idx[i].shader_model = 6, 8
851-
for i in ("HitObject_MakeMiss,HitObject_MakeNop").split(","):
851+
for i in (
852+
"HitObject_MakeMiss,HitObject_MakeNop"
853+
+ ",HitObject_FromRayQuery,HitObject_FromRayQueryWithAttrs"
854+
).split(","):
852855
self.name_idx[i].category = "Shader Execution Reordering"
853856
self.name_idx[i].shader_model = 6, 9
854857
self.name_idx[i].shader_stages = (
@@ -5739,7 +5742,46 @@ def UFI(name, **mappings):
57395742
next_op_idx = self.reserve_dxil_op_range("ReservedA", next_op_idx, 3)
57405743

57415744
# Shader Execution Reordering
5742-
next_op_idx = self.reserve_dxil_op_range("ReservedB", next_op_idx, 3)
5745+
next_op_idx = self.reserve_dxil_op_range("ReservedB", next_op_idx, 1)
5746+
5747+
self.add_dxil_op(
5748+
"HitObject_FromRayQuery",
5749+
next_op_idx,
5750+
"HitObject_FromRayQuery",
5751+
"Creates a new HitObject representing a committed hit from a RayQuery",
5752+
"v",
5753+
"ro",
5754+
[
5755+
db_dxil_param(
5756+
0, "hit_object", "", "HitObject created from RayQuery object"
5757+
),
5758+
db_dxil_param(2, "i32", "rayQueryHandle", "RayQuery handle"),
5759+
],
5760+
)
5761+
next_op_idx += 1
5762+
5763+
self.add_dxil_op(
5764+
"HitObject_FromRayQueryWithAttrs",
5765+
next_op_idx,
5766+
"HitObject_FromRayQueryWithAttrs",
5767+
"Creates a new HitObject representing a committed hit from a RayQuery and committed attributes",
5768+
"u",
5769+
"ro",
5770+
[
5771+
db_dxil_param(
5772+
0, "hit_object", "", "HitObject created from RayQuery object"
5773+
),
5774+
db_dxil_param(2, "i32", "rayQueryHandle", "RayQuery handle"),
5775+
db_dxil_param(
5776+
3,
5777+
"i32",
5778+
"HitKind",
5779+
"User-specified value in range of 0-127 to identify the type of hit",
5780+
),
5781+
db_dxil_param(4, "udt", "CommittedAttribs", "Committed attributes"),
5782+
],
5783+
)
5784+
next_op_idx += 1
57435785

57445786
self.add_dxil_op(
57455787
"HitObject_MakeMiss",

0 commit comments

Comments
 (0)