Skip to content

Commit c7aea41

Browse files
Merge remote-tracking branch 'origin/master' into anupamac/outer-prod-acc-matrix-layout-main
2 parents f915958 + 1198c30 commit c7aea41

7 files changed

Lines changed: 425 additions & 1 deletion

File tree

lib/DxilValidation/DxilValidation.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,32 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
23132313
break;
23142314
}
23152315

2316+
// Shader Execution Reordering - from ray query
2317+
case DXIL::OpCode::HitObject_FromRayQuery:
2318+
case DXIL::OpCode::HitObject_FromRayQueryWithAttrs: {
2319+
for (unsigned i = 1; i < CI->getNumOperands(); ++i) {
2320+
Value *Arg = CI->getArgOperand(i);
2321+
if (isa<UndefValue>(Arg))
2322+
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
2323+
}
2324+
break;
2325+
}
2326+
2327+
case DXIL::OpCode::HitObject_Invoke: {
2328+
if (isa<UndefValue>(CI->getArgOperand(1)))
2329+
ValCtx.EmitInstrError(CI, ValidationRule::InstrUndefHitObject);
2330+
if (isa<UndefValue>(CI->getArgOperand(2)))
2331+
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
2332+
} break;
2333+
case DXIL::OpCode::HitObject_TraceRay: {
2334+
Value *Hdl = CI->getArgOperand(
2335+
DxilInst_HitObject_TraceRay::arg_accelerationStructure);
2336+
ValidateASHandle(CI, Hdl, ValCtx);
2337+
for (unsigned ArgIdx = 2; ArgIdx < CI->getNumArgOperands(); ++ArgIdx)
2338+
if (isa<UndefValue>(CI->getArgOperand(ArgIdx)))
2339+
ValCtx.EmitInstrError(CI, ValidationRule::InstrNoReadingUninitialized);
2340+
DxilInst_HitObject_TraceRay HOTraceRay(CI);
2341+
} break;
23162342
case DXIL::OpCode::AtomicBinOp:
23172343
case DXIL::OpCode::AtomicCompareExchange: {
23182344
Type *pOverloadType = OP::GetOverloadType(Opcode, CI->getCalledFunction());

tools/clang/lib/SPIRV/EmitVisitor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,13 @@ bool EmitVisitor::visit(SpirvIntrinsicInstruction *inst) {
20002000
}
20012001
}
20022002

2003-
finalizeInstruction(&mainBinary);
2003+
auto opcode = static_cast<spv::Op>(inst->getInstruction());
2004+
if ((opcode == spv::Op::OpSpecConstant || opcode == spv::Op::OpConstant) &&
2005+
!inst->getInstructionSet()) {
2006+
finalizeInstruction(&typeConstantBinary);
2007+
} else {
2008+
finalizeInstruction(&mainBinary);
2009+
}
20042010
return true;
20052011
}
20062012

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %dxc -Od -T cs_6_8 -spirv -fcgl %s | FileCheck %s
2+
3+
// CHECK: %spirvIntrinsicType = OpTypeInt 8 0
4+
using uint8_t [[vk::ext_capability(/* Int8 */ 39)]] =
5+
vk::SpirvType</* OpTypeInt */ 21, 8, 8, vk::Literal<vk::integral_constant<uint, 8> >,
6+
vk::Literal<vk::integral_constant<bool, false> > >;
7+
8+
[[vk::ext_instruction(/* OpConstant */ 43)]] uint8_t mkconsant([[vk::ext_literal]] int v);
9+
10+
// CHECK: OpConstant %spirvIntrinsicType 42
11+
static const uint8_t K = mkconsant(42);
12+
13+
[numthreads(1, 1, 1)] void main() {}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
; REQUIRES: dxil-1-9
2+
; RUN: not %dxv %s 2>&1 | FileCheck %s
3+
4+
; CHECK: Function: ?main@@YAXXZ: error: Instructions should not read uninitialized value.
5+
; CHECK-NEXT: note: at '%attrsud3 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %rq, i32 16, %struct.CustomAttrs* nonnull undef)' in block '#0' of function '?main@@YAXXZ'.
6+
; CHECK-NEXT: Function: ?main@@YAXXZ: error: Instructions should not read uninitialized value.
7+
; CHECK-NEXT: note: at '%attrsud2 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %rq, i32 undef, %struct.CustomAttrs* nonnull %attra)' in block '#0' of function '?main@@YAXXZ'.
8+
; CHECK-NEXT: Function: ?main@@YAXXZ: error: Instructions should not read uninitialized value.
9+
; CHECK-NEXT: note: at '%attrsud1 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 undef, i32 16, %struct.CustomAttrs* nonnull %attra)' in block '#0' of function '?main@@YAXXZ'.
10+
; CHECK-NEXT: Function: ?main@@YAXXZ: error: Instructions should not read uninitialized value.
11+
; CHECK-NEXT: note: at '%ud1 = call %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32 263, i32 undef)' in block '#0' of function '?main@@YAXXZ'.
12+
; CHECK-NEXT: Validation failed.
13+
14+
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"
15+
target triple = "dxil-ms-dx"
16+
17+
%dx.types.Handle = type { i8* }
18+
%struct.Payload = type { <3 x float> }
19+
%struct.CustomAttrs = type { float, float }
20+
%dx.types.ResourceProperties = type { i32, i32 }
21+
%dx.types.HitObject = type { i8* }
22+
%struct.RaytracingAccelerationStructure = type { i32 }
23+
24+
@"\01?RTAS@@3URaytracingAccelerationStructure@@A" = external constant %dx.types.Handle, align 4
25+
26+
; Function Attrs: nounwind
27+
declare void @llvm.lifetime.start(i64, i8* nocapture) #0
28+
29+
; Function Attrs: nounwind
30+
declare void @llvm.lifetime.end(i64, i8* nocapture) #0
31+
32+
; Function Attrs: nounwind
33+
define void @"\01?main@@YAXXZ"() #0 {
34+
%ldh = load %dx.types.Handle, %dx.types.Handle* @"\01?RTAS@@3URaytracingAccelerationStructure@@A", align 4
35+
%attra = alloca %struct.CustomAttrs, align 4
36+
%rq = call i32 @dx.op.allocateRayQuery(i32 178, i32 5) ; AllocateRayQuery(constRayFlags)
37+
%createh = call %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32 160, %dx.types.Handle %ldh) ; CreateHandleForLib(Resource)
38+
%annoth = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %createh, %dx.types.ResourceProperties { i32 16, i32 0 }) ; AnnotateHandle(res,props) resource: RTAccelerationStructure
39+
call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %rq, %dx.types.Handle %annoth, 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)
40+
41+
%ok = call %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32 263, i32 %rq) ; HitObject_FromRayQuery(rayQueryHandle)
42+
%ud1 = call %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32 263, i32 undef) ; HitObject_FromRayQuery(rayQueryHandle)
43+
44+
%attrsok = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %rq, i32 16, %struct.CustomAttrs* nonnull %attra) ; HitObject_FromRayQueryWithAttrs(rayQueryHandle,HitKind,CommittedAttribs)
45+
%attrsud1 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 undef, i32 16, %struct.CustomAttrs* nonnull %attra) ; HitObject_FromRayQueryWithAttrs(rayQueryHandle,HitKind,CommittedAttribs)
46+
%attrsud2 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %rq, i32 undef, %struct.CustomAttrs* nonnull %attra) ; HitObject_FromRayQueryWithAttrs(rayQueryHandle,HitKind,CommittedAttribs)
47+
%attrsud3 = call %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32 264, i32 %rq, i32 16, %struct.CustomAttrs* nonnull undef) ; HitObject_FromRayQueryWithAttrs(rayQueryHandle,HitKind,CommittedAttribs)
48+
49+
ret void
50+
}
51+
52+
; Function Attrs: nounwind
53+
declare i32 @dx.op.allocateRayQuery(i32, i32) #0
54+
55+
; Function Attrs: nounwind
56+
declare void @dx.op.rayQuery_TraceRayInline(i32, i32, %dx.types.Handle, i32, i32, float, float, float, float, float, float, float, float) #0
57+
58+
; Function Attrs: nounwind readonly
59+
declare %dx.types.HitObject @dx.op.hitObject_FromRayQueryWithAttrs.struct.CustomAttrs(i32, i32, i32, %struct.CustomAttrs*) #1
60+
61+
; Function Attrs: nounwind readonly
62+
declare %dx.types.HitObject @dx.op.hitObject_FromRayQuery(i32, i32) #1
63+
64+
; Function Attrs: nounwind readnone
65+
declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #2
66+
67+
; Function Attrs: nounwind readonly
68+
declare %dx.types.Handle @dx.op.createHandleForLib.dx.types.Handle(i32, %dx.types.Handle) #1
69+
70+
attributes #0 = { nounwind }
71+
attributes #1 = { nounwind readonly }
72+
attributes #2 = { nounwind readnone }
73+
74+
!dx.version = !{!0}
75+
!dx.valver = !{!0}
76+
!dx.shaderModel = !{!1}
77+
!dx.resources = !{!2}
78+
!dx.typeAnnotations = !{!6}
79+
!dx.dxrPayloadAnnotations = !{!10}
80+
!dx.entryPoints = !{!13, !15}
81+
82+
!0 = !{i32 1, i32 9}
83+
!1 = !{!"lib", i32 6, i32 9}
84+
!2 = !{!3, null, null, null}
85+
!3 = !{!4}
86+
!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}
87+
!5 = !{i32 0, i32 4}
88+
!6 = !{i32 1, void ()* @"\01?main@@YAXXZ", !7}
89+
!7 = !{!8}
90+
!8 = !{i32 1, !9, !9}
91+
!9 = !{}
92+
!10 = !{i32 0, %struct.Payload undef, !11}
93+
!11 = !{!12}
94+
!12 = !{i32 0, i32 8210}
95+
!13 = !{null, !"", null, !2, !14}
96+
!14 = !{i32 0, i64 33554432}
97+
!15 = !{void ()* @"\01?main@@YAXXZ", !"\01?main@@YAXXZ", null, null, !16}
98+
!16 = !{i32 8, i32 7, i32 5, !17}
99+
!17 = !{i32 0}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
; REQUIRES: dxil-1-9
2+
; RUN: not %dxv %s 2>&1 | FileCheck %s
3+
4+
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"
5+
target triple = "dxil-ms-dx"
6+
7+
%struct.Payload = type { <3 x float> }
8+
%dx.types.HitObject = type { i8* }
9+
10+
; CHECK: Function: ?main@@YAXXZ: error: Instructions should not read uninitialized value.
11+
; CHECK-NEXT: note: at 'call void @dx.op.hitObject_Invoke.struct.Payload(i32 267, %dx.types.HitObject %nop, %struct.Payload* nonnull undef)' in block '#0' of function '?main@@YAXXZ'.
12+
; CHECK-NEXT: Function: ?main@@YAXXZ: error: HitObject is undef.
13+
; CHECK-NEXT: note: at 'call void @dx.op.hitObject_Invoke.struct.Payload(i32 267, %dx.types.HitObject undef, %struct.Payload* nonnull %pld)' in block '#0' of function '?main@@YAXXZ'.
14+
15+
; CHECK-NEXT: Validation failed.
16+
17+
; Function Attrs: nounwind
18+
define void @"\01?main@@YAXXZ"() #0 {
19+
%pld = alloca %struct.Payload, align 4
20+
%nop = call %dx.types.HitObject @dx.op.hitObject_MakeNop(i32 266) ; HitObject_MakeNop()
21+
call void @dx.op.hitObject_Invoke.struct.Payload(i32 267, %dx.types.HitObject %nop, %struct.Payload* nonnull %pld) ; HitObject_Invoke(hitObject,payload)
22+
call void @dx.op.hitObject_Invoke.struct.Payload(i32 267, %dx.types.HitObject undef, %struct.Payload* nonnull %pld) ; HitObject_Invoke(hitObject,payload)
23+
call void @dx.op.hitObject_Invoke.struct.Payload(i32 267, %dx.types.HitObject %nop, %struct.Payload* nonnull undef) ; HitObject_Invoke(hitObject,payload)
24+
25+
ret void
26+
}
27+
28+
; Function Attrs: nounwind readnone
29+
declare %dx.types.HitObject @dx.op.hitObject_MakeNop(i32) #1
30+
31+
; Function Attrs: nounwind
32+
declare void @dx.op.hitObject_Invoke.struct.Payload(i32, %dx.types.HitObject, %struct.Payload*) #0
33+
34+
attributes #0 = { nounwind }
35+
attributes #1 = { nounwind readnone }
36+
attributes #2 = { nounwind readonly }
37+
38+
!dx.version = !{!0}
39+
!dx.valver = !{!0}
40+
!dx.shaderModel = !{!1}
41+
!dx.typeAnnotations = !{!2}
42+
!dx.dxrPayloadAnnotations = !{!3}
43+
!dx.entryPoints = !{!4, !6}
44+
45+
!0 = !{i32 1, i32 9}
46+
!1 = !{!"lib", i32 6, i32 9}
47+
!2 = !{i32 1, void ()* @"\01?main@@YAXXZ", !7}
48+
!3 = !{i32 0, %struct.Payload undef, !8}
49+
!4 = !{null, !"", null, null, !5}
50+
!5 = !{i32 0, i64 0}
51+
!6 = !{void ()* @"\01?main@@YAXXZ", !"\01?main@@YAXXZ", null, null, !9}
52+
!7 = !{!10}
53+
!8 = !{!11}
54+
!9 = !{i32 8, i32 7, i32 5, !12}
55+
!10 = !{i32 1, !13, !13}
56+
!11 = !{i32 0, i32 8210}
57+
!12 = !{i32 0}
58+
!13 = !{}

0 commit comments

Comments
 (0)