Skip to content

Commit 59c89d1

Browse files
committed
[SER] HitObject_FromRayQuery[WithAttrs] DXIL opcodes and check-pass
tests DXC SER implementation tracker: microsoft#7214
1 parent 206b775 commit 59c89d1

File tree

5 files changed

+220
-29
lines changed

5 files changed

+220
-29
lines changed

include/dxc/DXIL/DxilConstants.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ enum class OpCode : unsigned {
498498
ReservedA1 = 260, // reserved
499499
ReservedA2 = 261, // reserved
500500
ReservedB0 = 262, // reserved
501-
ReservedB1 = 263, // reserved
502501
ReservedB10 = 272, // reserved
503502
ReservedB11 = 273, // reserved
504503
ReservedB12 = 274, // reserved
@@ -509,7 +508,6 @@ enum class OpCode : unsigned {
509508
ReservedB17 = 279, // reserved
510509
ReservedB18 = 280, // reserved
511510
ReservedB19 = 281, // reserved
512-
ReservedB2 = 264, // reserved
513511
ReservedB20 = 282, // reserved
514512
ReservedB21 = 283, // reserved
515513
ReservedB22 = 284, // reserved
@@ -908,6 +906,11 @@ enum class OpCode : unsigned {
908906
// operation with a mipmap-level offset
909907

910908
// Shader Execution Reordering
909+
HitObject_FromRayQuery = 263, // Creates a new HitObject representing a
910+
// committed hit from a RayQuery
911+
HitObject_FromRayQueryWithAttrs =
912+
264, // Creates a new HitObject representing a committed hit from a
913+
// RayQuery and committed attributes
911914
HitObject_MakeMiss = 265, // Creates a new HitObject representing a miss
912915
HitObject_MakeNop = 266, // Creates an empty nop HitObject
913916

@@ -1284,6 +1287,8 @@ enum class OpCodeClass : unsigned {
12841287
WriteSamplerFeedbackLevel,
12851288

12861289
// Shader Execution Reordering
1290+
HitObject_FromRayQuery,
1291+
HitObject_FromRayQueryWithAttrs,
12871292
HitObject_MakeMiss,
12881293
HitObject_MakeNop,
12891294

@@ -1351,7 +1356,7 @@ enum class OpCodeClass : unsigned {
13511356
NumOpClasses_Dxil_1_7 = 153,
13521357
NumOpClasses_Dxil_1_8 = 174,
13531358

1354-
NumOpClasses = 177 // exclusive last value of enumeration
1359+
NumOpClasses = 179 // exclusive last value of enumeration
13551360
};
13561361
// OPCODECLASS-ENUM:END
13571362

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

+30-24
Original file line numberDiff line numberDiff line change
@@ -2652,27 +2652,27 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
26522652
false},
26532653
Attribute::None,
26542654
},
2655+
2656+
// Shader Execution Reordering void, h, f, d, i1, i8, i16,
2657+
// i32, i64, udt, obj , function attribute
26552658
{
2656-
OC::ReservedB1,
2657-
"ReservedB1",
2658-
OCC::Reserved,
2659-
"reserved",
2659+
OC::HitObject_FromRayQuery,
2660+
"HitObject_FromRayQuery",
2661+
OCC::HitObject_FromRayQuery,
2662+
"hitObject_FromRayQuery",
26602663
{true, false, false, false, false, false, false, false, false, false,
26612664
false},
2662-
Attribute::None,
2665+
Attribute::ArgMemOnly,
26632666
},
26642667
{
2665-
OC::ReservedB2,
2666-
"ReservedB2",
2667-
OCC::Reserved,
2668-
"reserved",
2669-
{true, false, false, false, false, false, false, false, false, false,
2668+
OC::HitObject_FromRayQueryWithAttrs,
2669+
"HitObject_FromRayQueryWithAttrs",
2670+
OCC::HitObject_FromRayQueryWithAttrs,
2671+
"hitObject_FromRayQueryWithAttrs",
2672+
{false, false, false, false, false, false, false, false, false, true,
26702673
false},
2671-
Attribute::None,
2674+
Attribute::ArgMemOnly,
26722675
},
2673-
2674-
// Shader Execution Reordering void, h, f, d, i1, i8, i16,
2675-
// i32, i64, udt, obj , function attribute
26762676
{
26772677
OC::HitObject_MakeMiss,
26782678
"HitObject_MakeMiss",
@@ -3755,8 +3755,10 @@ void OP::GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
37553755
minor = 9;
37563756
return;
37573757
}
3758-
// Instructions: HitObject_MakeMiss=265, HitObject_MakeNop=266
3759-
if ((265 <= op && op <= 266)) {
3758+
// Instructions: HitObject_FromRayQuery=263,
3759+
// HitObject_FromRayQueryWithAttrs=264, HitObject_MakeMiss=265,
3760+
// HitObject_MakeNop=266
3761+
if ((263 <= op && op <= 266)) {
37603762
major = 6;
37613763
minor = 9;
37623764
mask =
@@ -5879,16 +5881,20 @@ Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
58795881
A(pV);
58805882
A(pI32);
58815883
break;
5882-
case OpCode::ReservedB1:
5883-
A(pV);
5884+
5885+
// Shader Execution Reordering
5886+
case OpCode::HitObject_FromRayQuery:
5887+
A(pHit);
5888+
A(pI32);
58845889
A(pI32);
58855890
break;
5886-
case OpCode::ReservedB2:
5887-
A(pV);
5891+
case OpCode::HitObject_FromRayQueryWithAttrs:
5892+
A(pHit);
5893+
A(pI32);
5894+
A(pI32);
58885895
A(pI32);
5896+
A(udt);
58895897
break;
5890-
5891-
// Shader Execution Reordering
58925898
case OpCode::HitObject_MakeMiss:
58935899
A(pHit);
58945900
A(pI32);
@@ -6233,6 +6239,7 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
62336239
return nullptr;
62346240
return FT->getParamType(15);
62356241
case OpCode::ReportHit:
6242+
case OpCode::HitObject_FromRayQueryWithAttrs:
62366243
if (FT->getNumParams() <= 3)
62376244
return nullptr;
62386245
return FT->getParamType(3);
@@ -6316,8 +6323,7 @@ llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
63166323
case OpCode::ReservedA1:
63176324
case OpCode::ReservedA2:
63186325
case OpCode::ReservedB0:
6319-
case OpCode::ReservedB1:
6320-
case OpCode::ReservedB2:
6326+
case OpCode::HitObject_FromRayQuery:
63216327
case OpCode::HitObject_MakeMiss:
63226328
case OpCode::HitObject_MakeNop:
63236329
case OpCode::ReservedB5:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
; RUN: %dxv %s | FileCheck %s
2+
3+
; CHECK: Validation succeeded.
4+
5+
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"
6+
target triple = "dxil-ms-dx"
7+
8+
%dx.types.Handle = type { i8* }
9+
%struct.CustomAttrs = type { float, float }
10+
%dx.types.ResourceProperties = type { i32, i32 }
11+
%dx.types.HitObject = type { i8* }
12+
%struct.RaytracingAccelerationStructure = type { i32 }
13+
14+
@"\01?RTAS@@3URaytracingAccelerationStructure@@A" = external constant %dx.types.Handle, align 4
15+
16+
; Function Attrs: nounwind
17+
define void @"\01?main@@YAXXZ"() #0 {
18+
%attrs = alloca %struct.CustomAttrs, align 4
19+
%1 = load %dx.types.Handle, %dx.types.Handle* @"\01?RTAS@@3URaytracingAccelerationStructure@@A", align 4
20+
%rayQuery = call i32 @dx.op.allocateRayQuery(i32 178, i32 5) ; AllocateRayQuery(constRayFlags)
21+
%handle = call %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32 160, %dx.types.Handle %1) ; CreateHandleForLib(Resource)
22+
%annotatedHandle = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %handle, %dx.types.ResourceProperties { i32 16, i32 0 }) ; AnnotateHandle(res,props) resource: RTAccelerationStructure
23+
call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %rayQuery, %dx.types.Handle %annotatedHandle, 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)
24+
25+
; Test HitObject_FromRayQuery (opcode 263)
26+
%r263 = call %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32 263, i32 %rayQuery) ; HitObject_FromRayQuery(rayQueryHandle)
27+
28+
; Test HitObject_FromRayQueryWithAttrs (opcode 264)
29+
%r264 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %rayQuery, i32 16, %struct.CustomAttrs* nonnull %attrs) ; HitObject_FromRayQueryWithAttrs(rayQueryHandle,HitKind,CommittedAttribs)
30+
31+
ret void
32+
}
33+
34+
; Function Attrs: nounwind
35+
declare i32 @dx.op.allocateRayQuery(i32, i32) #0
36+
37+
; Function Attrs: nounwind
38+
declare void @dx.op.rayQuery_TraceRayInline(i32, i32, %dx.types.Handle, i32, i32, float, float, float, float, float, float, float, float) #0
39+
40+
; Function Attrs: nounwind argmemonly
41+
declare %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32, i32) #1
42+
43+
; Function Attrs: nounwind argmemonly
44+
declare %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32, i32, i32, %struct.CustomAttrs*) #1
45+
46+
; Function Attrs: nounwind readnone
47+
declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #2
48+
49+
; Function Attrs: nounwind readonly
50+
declare %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32, %dx.types.Handle) #3
51+
52+
attributes #0 = { nounwind }
53+
attributes #1 = { nounwind argmemonly }
54+
attributes #2 = { nounwind readnone }
55+
attributes #3 = { nounwind readonly }
56+
57+
!dx.version = !{!0}
58+
!dx.valver = !{!0}
59+
!dx.shaderModel = !{!1}
60+
!dx.resources = !{!2}
61+
!dx.typeAnnotations = !{!3}
62+
!dx.entryPoints = !{!4, !5}
63+
64+
!0 = !{i32 1, i32 9}
65+
!1 = !{!"lib", i32 6, i32 9}
66+
!2 = !{!6, null, null, null}
67+
!3 = !{i32 1, void ()* @"\01?main@@YAXXZ", !7}
68+
!4 = !{null, !"", null, !2, !8}
69+
!5 = !{void ()* @"\01?main@@YAXXZ", !"\01?main@@YAXXZ", null, null, !9}
70+
!6 = !{!7}
71+
!7 = !{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, !10}
72+
!8 = !{i32 0, i64 33554432}
73+
!9 = !{i32 8, i32 7, i32 5, !11}
74+
!10 = !{i32 0, i32 4}
75+
!11 = !{i32 0}

utils/hct/hctdb.py

+44-2
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,10 @@ def populate_categories_and_models(self):
699699
self.name_idx[i].category = "Extended Command Information"
700700
self.name_idx[i].shader_stages = ("vertex",)
701701
self.name_idx[i].shader_model = 6, 8
702-
for i in ("HitObject_MakeMiss,HitObject_MakeNop").split(","):
702+
for i in (
703+
"HitObject_MakeMiss,HitObject_MakeNop"
704+
+ ",HitObject_FromRayQuery,HitObject_FromRayQueryWithAttrs"
705+
).split(","):
703706
self.name_idx[i].category = "Shader Execution Reordering"
704707
self.name_idx[i].shader_model = 6, 9
705708
self.name_idx[i].shader_stages = (
@@ -5590,7 +5593,46 @@ def UFI(name, **mappings):
55905593
next_op_idx = self.reserve_dxil_op_range("ReservedA", next_op_idx, 3)
55915594

55925595
# Shader Execution Reordering
5593-
next_op_idx = self.reserve_dxil_op_range("ReservedB", next_op_idx, 3)
5596+
next_op_idx = self.reserve_dxil_op_range("ReservedB", next_op_idx, 1)
5597+
5598+
self.add_dxil_op(
5599+
"HitObject_FromRayQuery",
5600+
next_op_idx,
5601+
"HitObject_FromRayQuery",
5602+
"Creates a new HitObject representing a committed hit from a RayQuery",
5603+
"v",
5604+
"amo",
5605+
[
5606+
db_dxil_param(
5607+
0, "hit_object", "", "HitObject created from RayQuery object"
5608+
),
5609+
db_dxil_param(2, "i32", "rayQueryHandle", "RayQuery handle"),
5610+
],
5611+
)
5612+
next_op_idx += 1
5613+
5614+
self.add_dxil_op(
5615+
"HitObject_FromRayQueryWithAttrs",
5616+
next_op_idx,
5617+
"HitObject_FromRayQueryWithAttrs",
5618+
"Creates a new HitObject representing a committed hit from a RayQuery and committed attributes",
5619+
"u",
5620+
"amo",
5621+
[
5622+
db_dxil_param(
5623+
0, "hit_object", "", "HitObject created from RayQuery object"
5624+
),
5625+
db_dxil_param(2, "i32", "rayQueryHandle", "RayQuery handle"),
5626+
db_dxil_param(
5627+
3,
5628+
"i32",
5629+
"HitKind",
5630+
"User-specified value in range of 0-127 to identify the type of hit",
5631+
),
5632+
db_dxil_param(4, "udt", "CommittedAttribs", "Committed attributes"),
5633+
],
5634+
)
5635+
next_op_idx += 1
55945636

55955637
self.add_dxil_op(
55965638
"HitObject_MakeMiss",

0 commit comments

Comments
 (0)