Skip to content

Commit 22bbcaf

Browse files
committed
[SER] Validate HitObject::TraceRay|Invoke
Validate: HitObject_Invoke HitObject_TraceRay Rules: No undef params Resource handle must be AS SER implementation tracker: #7214
1 parent 8209d53 commit 22bbcaf

3 files changed

Lines changed: 254 additions & 1 deletion

File tree

lib/DxilValidation/DxilValidation.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,21 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
20252025
ValidateConstantRangeUnsigned(Col, "column", 0, 3, CI, Opcode, ValCtx);
20262026
break;
20272027
}
2028-
2028+
case DXIL::OpCode::HitObject_Invoke: {
2029+
if (isa<UndefValue>(CI->getArgOperand(1)))
2030+
ValCtx.EmitInstrError(CI, ValidationRule::InstrUndefHitObject);
2031+
if (isa<UndefValue>(CI->getArgOperand(2)))
2032+
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
2033+
} break;
2034+
case DXIL::OpCode::HitObject_TraceRay: {
2035+
Value *Hdl = CI->getArgOperand(
2036+
DxilInst_HitObject_TraceRay::arg_accelerationStructure);
2037+
ValidateASHandle(CI, Hdl, ValCtx);
2038+
for (unsigned ArgIdx = 2; ArgIdx < CI->getNumArgOperands(); ++ArgIdx)
2039+
if (isa<UndefValue>(CI->getArgOperand(ArgIdx)))
2040+
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
2041+
DxilInst_HitObject_TraceRay HOTraceRay(CI);
2042+
} break;
20292043
case DXIL::OpCode::AtomicBinOp:
20302044
case DXIL::OpCode::AtomicCompareExchange: {
20312045
Type *pOverloadType = OP::GetOverloadType(Opcode, CI->getCalledFunction());
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
; REQUIRES: dxil-1-9
2+
; RUN: not %dxv %s 2>&1 | FileCheck %s
3+
4+
; shader hash: b22988e7874179601860019e56fb877e
5+
;
6+
; Buffer Definitions:
7+
;
8+
;
9+
; Resource Bindings:
10+
;
11+
; Name Type Format Dim ID HLSL Bind Count
12+
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
13+
; RTAS texture i32 ras T0t4294967295,space4294967295 1
14+
; nonas_buf UAV byte r/w U0u4294967295,space4294967295 1
15+
;
16+
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"
17+
target triple = "dxil-ms-dx"
18+
19+
%dx.types.Handle = type { i8* }
20+
%struct.Payload = type { <3 x float> }
21+
%dx.types.ResourceProperties = type { i32, i32 }
22+
%dx.types.HitObject = type { i8* }
23+
%struct.RaytracingAccelerationStructure = type { i32 }
24+
%struct.RWByteAddressBuffer = type { i32 }
25+
26+
@"\01?RTAS@@3URaytracingAccelerationStructure@@A" = external constant %dx.types.Handle, align 4
27+
@"\01?nonas_buf@@3URWByteAddressBuffer@@A" = external constant %dx.types.Handle, align 4
28+
29+
; CHECK: Function: ?main@@YAXXZ: error: TraceRay should only use RTAccelerationStructure.
30+
; CHECK-NEXT: note: at '%invalid = call %dx.types.HitObject @dx.op.hitObject_TraceRay.struct.Payload(i32 262, %dx.types.Handle %7, i32 513, i32 1, i32 2, i32 4, i32 0, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, %struct.Payload* nonnull %3)' in block '#0' of function '?main@@YAXXZ'.
31+
; CHECK-NEXT: Function: dx.op.hitObject_Invoke.struct.Payload: error: External function 'dx.op.hitObject_Invoke.struct.Payload' is unused.
32+
; CHECK-NEXT: Validation failed.
33+
34+
; Function Attrs: nounwind
35+
define void @"\01?main@@YAXXZ"() #0 {
36+
%1 = load %dx.types.Handle, %dx.types.Handle* @"\01?RTAS@@3URaytracingAccelerationStructure@@A", align 4
37+
%2 = load %dx.types.Handle, %dx.types.Handle* @"\01?nonas_buf@@3URWByteAddressBuffer@@A", align 4
38+
%3 = alloca %struct.Payload, align 4
39+
%4 = bitcast %struct.Payload* %3 to i8*
40+
call void @llvm.lifetime.start(i64 12, i8* %4) #0
41+
%5 = getelementptr inbounds %struct.Payload, %struct.Payload* %3, i32 0, i32 0
42+
store <3 x float> <float 7.000000e+00, float 8.000000e+00, float 9.000000e+00>, <3 x float>* %5, align 4, !tbaa !20
43+
%6 = call %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32 160, %dx.types.Handle %2) ; CreateHandleForLib(Resource)
44+
%7 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %6, %dx.types.ResourceProperties { i32 4107, i32 0 }) ; AnnotateHandle(res,props) resource: RWByteAddressBuffer
45+
call void @dx.op.rawBufferStore.f32(i32 140, %dx.types.Handle %7, i32 0, i32 undef, float 1.100000e+01, float undef, float undef, float undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment)
46+
%8 = call %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32 160, %dx.types.Handle %1) ; CreateHandleForLib(Resource)
47+
%9 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %8, %dx.types.ResourceProperties { i32 16, i32 0 }) ; AnnotateHandle(res,props) resource: RTAccelerationStructure
48+
49+
%valid = call %dx.types.HitObject @dx.op.hitObject_TraceRay.struct.Payload(i32 262, %dx.types.Handle %9, i32 513, i32 1, i32 2, i32 4, i32 0, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, %struct.Payload* nonnull %3) ; HitObject_TraceRay(accelerationStructure,rayFlags,instanceInclusionMask,rayContributionToHitGroupIndex,multiplierForGeometryContributionToHitGroupIndex,missShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload)
50+
51+
%invalid = call %dx.types.HitObject @dx.op.hitObject_TraceRay.struct.Payload(i32 262, %dx.types.Handle %7, i32 513, i32 1, i32 2, i32 4, i32 0, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, %struct.Payload* nonnull %3) ; HitObject_TraceRay(accelerationStructure,rayFlags,instanceInclusionMask,rayContributionToHitGroupIndex,multiplierForGeometryContributionToHitGroupIndex,missShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload)
52+
53+
call void @llvm.lifetime.end(i64 12, i8* %4) #0
54+
ret void
55+
}
56+
57+
; Function Attrs: nounwind
58+
declare void @llvm.lifetime.start(i64, i8* nocapture) #0
59+
60+
; Function Attrs: nounwind
61+
declare void @llvm.lifetime.end(i64, i8* nocapture) #0
62+
63+
; Function Attrs: nounwind
64+
declare void @dx.op.rawBufferStore.f32(i32, %dx.types.Handle, i32, i32, float, float, float, float, i8, i32) #0
65+
66+
; Function Attrs: nounwind
67+
declare %dx.types.HitObject @dx.op.hitObject_TraceRay.struct.Payload(i32, %dx.types.Handle, i32, i32, i32, i32, i32, float, float, float, float, float, float, float, float, %struct.Payload*) #0
68+
69+
; Function Attrs: nounwind
70+
declare void @dx.op.hitObject_Invoke.struct.Payload(i32, %dx.types.HitObject, %struct.Payload*) #0
71+
72+
; Function Attrs: nounwind readnone
73+
declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #1
74+
75+
; Function Attrs: nounwind readonly
76+
declare %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32, %dx.types.Handle) #2
77+
78+
attributes #0 = { nounwind }
79+
attributes #1 = { nounwind readnone }
80+
attributes #2 = { nounwind readonly }
81+
82+
!dx.version = !{!0}
83+
!dx.valver = !{!0}
84+
!dx.shaderModel = !{!1}
85+
!dx.resources = !{!2}
86+
!dx.typeAnnotations = !{!8}
87+
!dx.dxrPayloadAnnotations = !{!12}
88+
!dx.entryPoints = !{!15, !17}
89+
90+
!0 = !{i32 1, i32 9}
91+
!1 = !{!"lib", i32 6, i32 9}
92+
!2 = !{!3, !6, null, null}
93+
!3 = !{!4}
94+
!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}
95+
!5 = !{i32 0, i32 4}
96+
!6 = !{!7}
97+
!7 = !{i32 0, %struct.RWByteAddressBuffer* bitcast (%dx.types.Handle* @"\01?nonas_buf@@3URWByteAddressBuffer@@A" to %struct.RWByteAddressBuffer*), !"nonas_buf", i32 -1, i32 -1, i32 1, i32 11, i1 false, i1 false, i1 false, null}
98+
!8 = !{i32 1, void ()* @"\01?main@@YAXXZ", !9}
99+
!9 = !{!10}
100+
!10 = !{i32 1, !11, !11}
101+
!11 = !{}
102+
!12 = !{i32 0, %struct.Payload undef, !13}
103+
!13 = !{!14}
104+
!14 = !{i32 0, i32 8210}
105+
!15 = !{null, !"", null, !2, !16}
106+
!16 = !{i32 0, i64 8589934608}
107+
!17 = !{void ()* @"\01?main@@YAXXZ", !"\01?main@@YAXXZ", null, null, !18}
108+
!18 = !{i32 8, i32 7, i32 5, !19}
109+
!19 = !{i32 0}
110+
!20 = !{!21, !21, i64 0}
111+
!21 = !{!"omnipotent char", !22, i64 0}
112+
!22 = !{!"Simple C/C++ TBAA"}

0 commit comments

Comments
 (0)