Skip to content

Commit 847d5ad

Browse files
authored
[SER] HitObject::GetAttributes HLSL -> DXIL lowering and attributes sema (#7361)
Lowering for `HitObject::GetAttributes<T>()` Specification: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0027-shader-execution-reordering.md DXC SER implementation tracker:: #7214
1 parent bddee27 commit 847d5ad

File tree

9 files changed

+284
-25
lines changed

9 files changed

+284
-25
lines changed

lib/HLSL/HLOperationLower.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6375,7 +6375,23 @@ Value *TranslateHitObjectGetAttributes(CallInst *CI, IntrinsicOp IOP,
63756375
HLOperationLowerHelper &Helper,
63766376
HLObjectOperationLowerHelper *pObjHelper,
63776377
bool &Translated) {
6378-
return UndefValue::get(CI->getType()); // TODO: Merge SER DXIL patches
6378+
hlsl::OP *OP = &Helper.hlslOP;
6379+
IRBuilder<> Builder(CI);
6380+
6381+
Value *HitObjectPtr = CI->getArgOperand(1);
6382+
Value *HitObject = Builder.CreateLoad(HitObjectPtr);
6383+
6384+
Type *AttrTy = cast<PointerType>(CI->getType())->getPointerElementType();
6385+
6386+
IRBuilder<> EntryBuilder(
6387+
dxilutil::FindAllocaInsertionPt(CI->getParent()->getParent()));
6388+
unsigned AttrAlign = Helper.dataLayout.getABITypeAlignment(AttrTy);
6389+
AllocaInst *AttrMem = EntryBuilder.CreateAlloca(AttrTy);
6390+
AttrMem->setAlignment(AttrAlign);
6391+
Constant *opArg = OP->GetU32Const((unsigned)OpCode);
6392+
TrivialDxilOperation(OpCode, {opArg, HitObject, AttrMem}, CI->getType(),
6393+
Helper.voidTy, OP, Builder);
6394+
return AttrMem;
63796395
}
63806396

63816397
Value *TranslateHitObjectScalarGetter(CallInst *CI, IntrinsicOp IOP,

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7646,7 +7646,7 @@ def err_payload_requires_inout : Error<
76467646
def err_attributes_requiers_in : Error<
76477647
"intersection attributes parameter %0 must be 'in'">;
76487648
def err_payload_attrs_must_be_udt : Error<
7649-
"%select{payload|attributes|callable}0 parameter %1 must be a user-defined type composed of only numeric types">;
7649+
"%select{payload|attributes|callable}0 %select{parameter %2|type}1 must be a user-defined type composed of only numeric types">;
76507650
def err_shader_must_return_void : Error<
76517651
"return type for '%0' shaders must be void">;
76527652
def err_raytracing_entry_param_count : Error<
@@ -7885,7 +7885,7 @@ def err_hlsl_unsupported_long_vector
78857885
"cbuffers or tbuffers|user-defined struct parameter|"
78867886
"entry function parameters|entry function return type|"
78877887
"patch constant function parameters|patch constant function return type|"
7888-
"payload parameters}0 are not supported">;
7888+
"payload parameters|attributes}0 are not supported">;
78897889
def err_hlsl_logical_binop_scalar : Error<
78907890
"operands for short-circuiting logical binary operator must be scalar, for non-scalar types use '%select{and|or}0'">;
78917891
def err_hlsl_ternary_scalar : Error<

tools/clang/lib/Sema/SemaDXR.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ void DiagnoseBuiltinCallWithPayload(Sema &S, const VarDecl *Payload,
829829
// Verify that the payload type is legal
830830
if (!hlsl::IsHLSLCopyableAnnotatableRecord(Payload->getType())) {
831831
S.Diag(Payload->getLocation(), diag::err_payload_attrs_must_be_udt)
832-
<< /*payload|attributes|callable*/ 0 << Payload;
832+
<< /*payload|attributes|callable*/ 0 << /*parameter %2|type*/ 0
833+
<< Payload;
833834
return;
834835
}
835836

@@ -1194,7 +1195,8 @@ void DiagnoseCallableEntry(Sema &S, FunctionDecl *FD,
11941195

11951196
if (!(hlsl::IsHLSLCopyableAnnotatableRecord(Ty)))
11961197
S.Diag(Param->getLocation(), diag::err_payload_attrs_must_be_udt)
1197-
<< /*payload|attributes|callable*/ 2 << Param;
1198+
<< /*payload|attributes|callable*/ 2 << /*parameter %2|type*/ 0
1199+
<< Param;
11981200
}
11991201
return;
12001202
}
@@ -1235,7 +1237,8 @@ void DiagnoseMissOrAnyHitEntry(Sema &S, FunctionDecl *FD,
12351237

12361238
if (!(hlsl::IsHLSLCopyableAnnotatableRecord(Ty))) {
12371239
S.Diag(Param->getLocation(), diag::err_payload_attrs_must_be_udt)
1238-
<< /*payload|attributes|callable*/ Idx << Param;
1240+
<< /*payload|attributes|callable*/ Idx << /*parameter %2|type*/ 0
1241+
<< Param;
12391242
}
12401243
}
12411244
return;
@@ -1288,7 +1291,8 @@ void DiagnoseClosestHitEntry(Sema &S, FunctionDecl *FD,
12881291

12891292
if (!(hlsl::IsHLSLCopyableAnnotatableRecord(Ty))) {
12901293
S.Diag(Param->getLocation(), diag::err_payload_attrs_must_be_udt)
1291-
<< /*payload|attributes|callable*/ Idx << Param;
1294+
<< /*payload|attributes|callable*/ Idx << /*parameter %2|type*/ 0
1295+
<< Param;
12921296
}
12931297
}
12941298
return;

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10770,6 +10770,22 @@ HLSLExternalSource::ApplyTypeSpecSignToParsedType(clang::QualType &type,
1077010770
}
1077110771
}
1077210772

10773+
bool DiagnoseIntersectionAttributes(Sema &S, SourceLocation Loc, QualType Ty) {
10774+
// Must be a UDT
10775+
if (Ty.isNull() || !hlsl::IsHLSLCopyableAnnotatableRecord(Ty)) {
10776+
S.Diag(Loc, diag::err_payload_attrs_must_be_udt)
10777+
<< /*payload|attributes|callable*/ 1 << /*parameter %2|type*/ 1;
10778+
return false;
10779+
}
10780+
10781+
if (ContainsLongVector(Ty)) {
10782+
const unsigned AttributesIdx = 11;
10783+
S.Diag(Loc, diag::err_hlsl_unsupported_long_vector) << AttributesIdx;
10784+
return false;
10785+
}
10786+
return true;
10787+
}
10788+
1077310789
Sema::TemplateDeductionResult
1077410790
HLSLExternalSource::DeduceTemplateArgumentsForHLSL(
1077510791
FunctionTemplateDecl *FunctionTemplate,
@@ -10878,6 +10894,7 @@ HLSLExternalSource::DeduceTemplateArgumentsForHLSL(
1087810894
LPCSTR tableName = cursor.GetTableName();
1087910895
// Currently only intrinsic we allow for explicit template arguments are
1088010896
// for Load/Store for ByteAddressBuffer/RWByteAddressBuffer
10897+
// and HitObject::GetAttributes with user-defined intersection attributes.
1088110898

1088210899
// Check Explicit template arguments
1088310900
UINT intrinsicOp = (*cursor)->Op;
@@ -10892,28 +10909,38 @@ HLSLExternalSource::DeduceTemplateArgumentsForHLSL(
1089210909
IsBABLoad = intrinsicOp == (UINT)IntrinsicOp::MOP_Load;
1089310910
IsBABStore = intrinsicOp == (UINT)IntrinsicOp::MOP_Store;
1089410911
}
10895-
if (ExplicitTemplateArgs && ExplicitTemplateArgs->size() > 0) {
10896-
bool isLegalTemplate = false;
10912+
bool IsHitObjectGetAttributes =
10913+
intrinsicOp == (UINT)IntrinsicOp::MOP_DxHitObject_GetAttributes;
10914+
if (ExplicitTemplateArgs && ExplicitTemplateArgs->size() >= 1) {
1089710915
SourceLocation Loc = ExplicitTemplateArgs->getLAngleLoc();
10898-
auto TemplateDiag = diag::err_hlsl_intrinsic_template_arg_unsupported;
10899-
if (ExplicitTemplateArgs->size() >= 1 && (IsBABLoad || IsBABStore)) {
10900-
TemplateDiag = diag::err_hlsl_intrinsic_template_arg_requires_2018;
10901-
Loc = (*ExplicitTemplateArgs)[0].getLocation();
10902-
if (Is2018) {
10903-
TemplateDiag = diag::err_hlsl_intrinsic_template_arg_numeric;
10904-
if (ExplicitTemplateArgs->size() == 1 &&
10905-
!functionTemplateTypeArg.isNull() &&
10906-
hlsl::IsHLSLNumericOrAggregateOfNumericType(
10907-
functionTemplateTypeArg)) {
10908-
isLegalTemplate = true;
10909-
}
10910-
}
10916+
if (!IsBABLoad && !IsBABStore && !IsHitObjectGetAttributes) {
10917+
getSema()->Diag(Loc, diag::err_hlsl_intrinsic_template_arg_unsupported)
10918+
<< intrinsicName;
10919+
return Sema::TemplateDeductionResult::TDK_Invalid;
1091110920
}
10912-
10913-
if (!isLegalTemplate) {
10914-
getSema()->Diag(Loc, TemplateDiag) << intrinsicName;
10921+
Loc = (*ExplicitTemplateArgs)[0].getLocation();
10922+
if (!Is2018) {
10923+
getSema()->Diag(Loc,
10924+
diag::err_hlsl_intrinsic_template_arg_requires_2018)
10925+
<< intrinsicName;
1091510926
return Sema::TemplateDeductionResult::TDK_Invalid;
1091610927
}
10928+
10929+
if (IsBABLoad || IsBABStore) {
10930+
const bool IsLegalTemplate =
10931+
!functionTemplateTypeArg.isNull() &&
10932+
hlsl::IsHLSLNumericOrAggregateOfNumericType(
10933+
functionTemplateTypeArg);
10934+
if (!IsLegalTemplate) {
10935+
getSema()->Diag(Loc, diag::err_hlsl_intrinsic_template_arg_numeric)
10936+
<< intrinsicName;
10937+
return Sema::TemplateDeductionResult::TDK_Invalid;
10938+
}
10939+
}
10940+
if (IsHitObjectGetAttributes &&
10941+
!DiagnoseIntersectionAttributes(*getSema(), Loc,
10942+
functionTemplateTypeArg))
10943+
return Sema::TemplateDeductionResult::TDK_Invalid;
1091710944
} else if (IsBABStore) {
1091810945
// Prior to HLSL 2018, Store operation only stored scalar uint.
1091910946
if (!Is2018) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %dxc -T lib_6_9 -E main %s | FileCheck %s --check-prefix DXIL
2+
3+
// DXIL: %[[APTR:[^ ]+]] = alloca %struct.CustomAttrs, align 4
4+
// DXIL: %[[NOP:[^ ]+]] = call %dx.types.HitObject @dx.op.hitObject_MakeNop(i32 266) ; HitObject_MakeNop()
5+
// DXIL: call void @dx.op.hitObject_Attributes.struct.CustomAttrs(i32 289, %dx.types.HitObject %[[NOP]], %struct.CustomAttrs* nonnull %[[APTR]]) ; HitObject_Attributes(hitObject,attributes)
6+
// DXIL: %[[VPTR:[^ ]+]] = getelementptr inbounds %struct.CustomAttrs, %struct.CustomAttrs* %[[APTR]], i32 0, i32 0
7+
// DXIL: %{{[^ ]+}} = load <4 x float>, <4 x float>* %[[VPTR]], align 4
8+
// DXIL: %[[IPTR:[^ ]+]] = getelementptr inbounds %struct.CustomAttrs, %struct.CustomAttrs* %[[APTR]], i32 0, i32 1
9+
// DXIL: %{{[^ ]+}} = load i32, i32* %[[IPTR]], align 4
10+
// DXIL: ret void
11+
12+
RWByteAddressBuffer outbuf;
13+
14+
struct
15+
CustomAttrs {
16+
float4 v;
17+
int y;
18+
};
19+
20+
[shader("raygeneration")]
21+
void main() {
22+
dx::HitObject hit;
23+
CustomAttrs attrs = hit.GetAttributes<CustomAttrs>();
24+
float sum = attrs.v.x + attrs.v.y + attrs.v.z + attrs.v.w + attrs.y;
25+
outbuf.Store(0, sum);
26+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
; RUN: %dxopt %s -hlsl-passes-resume -dxilgen -S | FileCheck %s
2+
; REQUIRES: dxil-1-9
3+
4+
;
5+
; Buffer Definitions:
6+
;
7+
;
8+
; Resource Bindings:
9+
;
10+
; Name Type Format Dim ID HLSL Bind Count
11+
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
12+
; outbuf UAV byte r/w U0u4294967295,space4294967295 1
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+
%struct.RWByteAddressBuffer = type { i32 }
18+
%dx.types.HitObject = type { i8* }
19+
%struct.CustomAttrs = type { <4 x float>, i32 }
20+
%dx.types.Handle = type { i8* }
21+
%dx.types.ResourceProperties = type { i32, i32 }
22+
%"class.dx::HitObject" = type { i32 }
23+
24+
@"\01?outbuf@@3URWByteAddressBuffer@@A" = external global %struct.RWByteAddressBuffer, align 4
25+
26+
; CHECK: %[[ATTRA:[^ ]+]] = alloca %struct.CustomAttrs, align 4
27+
; CHECK: call void @dx.op.hitObject_Attributes.struct.CustomAttrs(i32 289, %dx.types.HitObject %{{[^ ]+}}, %struct.CustomAttrs* %[[ATTRA]])
28+
29+
; Function Attrs: nounwind
30+
define void @"\01?main@@YAXXZ"() #0 {
31+
entry:
32+
%hit = alloca %dx.types.HitObject, align 4
33+
%0 = bitcast %dx.types.HitObject* %hit to i8*, !dbg !21 ; line:22 col:3
34+
call void @llvm.lifetime.start(i64 4, i8* %0) #0, !dbg !21 ; line:22 col:3
35+
%1 = call %dx.types.HitObject* @"dx.hl.op..%dx.types.HitObject* (i32, %dx.types.HitObject*)"(i32 358, %dx.types.HitObject* %hit), !dbg !25 ; line:22 col:17
36+
%2 = call %struct.CustomAttrs* @"dx.hl.op..%struct.CustomAttrs* (i32, %dx.types.HitObject*)"(i32 364, %dx.types.HitObject* %hit), !dbg !26 ; line:23 col:23
37+
%3 = getelementptr inbounds %struct.CustomAttrs, %struct.CustomAttrs* %2, i32 0, i32 0, !dbg !26 ; line:23 col:23
38+
%4 = load <4 x float>, <4 x float>* %3, !dbg !26 ; line:23 col:23
39+
%5 = getelementptr inbounds %struct.CustomAttrs, %struct.CustomAttrs* %2, i32 0, i32 1, !dbg !26 ; line:23 col:23
40+
%6 = load i32, i32* %5, !dbg !26 ; line:23 col:23
41+
%7 = extractelement <4 x float> %4, i32 0, !dbg !27 ; line:24 col:15
42+
%8 = extractelement <4 x float> %4, i32 1, !dbg !28 ; line:24 col:27
43+
%add = fadd float %7, %8, !dbg !29 ; line:24 col:25
44+
%9 = extractelement <4 x float> %4, i32 2, !dbg !30 ; line:24 col:39
45+
%add4 = fadd float %add, %9, !dbg !31 ; line:24 col:37
46+
%10 = extractelement <4 x float> %4, i32 3, !dbg !32 ; line:24 col:51
47+
%add6 = fadd float %add4, %10, !dbg !33 ; line:24 col:49
48+
%conv = sitofp i32 %6 to float, !dbg !34 ; line:24 col:63
49+
%add7 = fadd float %add6, %conv, !dbg !35 ; line:24 col:61
50+
%11 = load %struct.RWByteAddressBuffer, %struct.RWByteAddressBuffer* @"\01?outbuf@@3URWByteAddressBuffer@@A", !dbg !36 ; line:25 col:3
51+
%12 = call %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.RWByteAddressBuffer)"(i32 0, %struct.RWByteAddressBuffer %11), !dbg !36 ; line:25 col:3
52+
%13 = call %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer)"(i32 14, %dx.types.Handle %12, %dx.types.ResourceProperties { i32 4107, i32 0 }, %struct.RWByteAddressBuffer zeroinitializer), !dbg !36 ; line:25 col:3
53+
call void @"dx.hl.op..void (i32, %dx.types.Handle, i32, float)"(i32 277, %dx.types.Handle %13, i32 0, float %add7), !dbg !36 ; line:25 col:3
54+
%14 = bitcast %dx.types.HitObject* %hit to i8*, !dbg !37 ; line:26 col:1
55+
call void @llvm.lifetime.end(i64 4, i8* %14) #0, !dbg !37 ; line:26 col:1
56+
ret void, !dbg !37 ; line:26 col:1
57+
}
58+
59+
; Function Attrs: nounwind
60+
declare void @llvm.lifetime.start(i64, i8* nocapture) #0
61+
62+
; Function Attrs: nounwind
63+
declare void @llvm.lifetime.end(i64, i8* nocapture) #0
64+
65+
; Function Attrs: nounwind
66+
declare %dx.types.HitObject* @"dx.hl.op..%dx.types.HitObject* (i32, %dx.types.HitObject*)"(i32, %dx.types.HitObject*) #0
67+
68+
; Function Attrs: nounwind
69+
declare %struct.CustomAttrs* @"dx.hl.op..%struct.CustomAttrs* (i32, %dx.types.HitObject*)"(i32, %dx.types.HitObject*) #0
70+
71+
; Function Attrs: nounwind
72+
declare void @"dx.hl.op..void (i32, %dx.types.Handle, i32, float)"(i32, %dx.types.Handle, i32, float) #0
73+
74+
; Function Attrs: nounwind readnone
75+
declare %dx.types.Handle @"dx.hl.createhandle..%dx.types.Handle (i32, %struct.RWByteAddressBuffer)"(i32, %struct.RWByteAddressBuffer) #1
76+
77+
; Function Attrs: nounwind readnone
78+
declare %dx.types.Handle @"dx.hl.annotatehandle..%dx.types.Handle (i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer)"(i32, %dx.types.Handle, %dx.types.ResourceProperties, %struct.RWByteAddressBuffer) #1
79+
80+
attributes #0 = { nounwind }
81+
attributes #1 = { nounwind readnone }
82+
83+
!llvm.module.flags = !{!0}
84+
!pauseresume = !{!1}
85+
!dx.version = !{!2}
86+
!dx.valver = !{!2}
87+
!dx.shaderModel = !{!3}
88+
!dx.typeAnnotations = !{!4, !10}
89+
!dx.entryPoints = !{!14}
90+
!dx.fnprops = !{!18}
91+
!dx.options = !{!19, !20}
92+
93+
!0 = !{i32 2, !"Debug Info Version", i32 3}
94+
!1 = !{!"hlsl-hlemit", !"hlsl-hlensure"}
95+
!2 = !{i32 1, i32 9}
96+
!3 = !{!"lib", i32 6, i32 9}
97+
!4 = !{i32 0, %"class.dx::HitObject" undef, !5, %struct.CustomAttrs undef, !7}
98+
!5 = !{i32 4, !6}
99+
!6 = !{i32 6, !"h", i32 3, i32 0, i32 7, i32 4}
100+
!7 = !{i32 20, !8, !9}
101+
!8 = !{i32 6, !"v", i32 3, i32 0, i32 7, i32 9, i32 13, i32 4}
102+
!9 = !{i32 6, !"y", i32 3, i32 16, i32 7, i32 4}
103+
!10 = !{i32 1, void ()* @"\01?main@@YAXXZ", !11}
104+
!11 = !{!12}
105+
!12 = !{i32 1, !13, !13}
106+
!13 = !{}
107+
!14 = !{null, !"", null, !15, null}
108+
!15 = !{null, !16, null, null}
109+
!16 = !{!17}
110+
!17 = !{i32 0, %struct.RWByteAddressBuffer* @"\01?outbuf@@3URWByteAddressBuffer@@A", !"outbuf", i32 -1, i32 -1, i32 1, i32 11, i1 false, i1 false, i1 false, null}
111+
!18 = !{void ()* @"\01?main@@YAXXZ", i32 7}
112+
!19 = !{i32 -2147483584}
113+
!20 = !{i32 -1}
114+
!21 = !DILocation(line: 22, column: 3, scope: !22)
115+
!22 = !DISubprogram(name: "main", scope: !23, file: !23, line: 21, type: !24, isLocal: false, isDefinition: true, scopeLine: 21, flags: DIFlagPrototyped, isOptimized: false, function: void ()* @"\01?main@@YAXXZ")
116+
!23 = !DIFile(filename: "tools/clang/test/CodeGenDXIL/hlsl/objects/HitObject/hitobject_attributes.hlsl", directory: "")
117+
!24 = !DISubroutineType(types: !13)
118+
!25 = !DILocation(line: 22, column: 17, scope: !22)
119+
!26 = !DILocation(line: 23, column: 23, scope: !22)
120+
!27 = !DILocation(line: 24, column: 15, scope: !22)
121+
!28 = !DILocation(line: 24, column: 27, scope: !22)
122+
!29 = !DILocation(line: 24, column: 25, scope: !22)
123+
!30 = !DILocation(line: 24, column: 39, scope: !22)
124+
!31 = !DILocation(line: 24, column: 37, scope: !22)
125+
!32 = !DILocation(line: 24, column: 51, scope: !22)
126+
!33 = !DILocation(line: 24, column: 49, scope: !22)
127+
!34 = !DILocation(line: 24, column: 63, scope: !22)
128+
!35 = !DILocation(line: 24, column: 61, scope: !22)
129+
!36 = !DILocation(line: 25, column: 3, scope: !22)
130+
!37 = !DILocation(line: 26, column: 1, scope: !22)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %dxc -T lib_6_9 -E main %s -ast-dump-implicit | FileCheck %s --check-prefix AST
2+
// RUN: %dxc -T lib_6_9 -E main %s -fcgl | FileCheck %s --check-prefix FCGL
3+
4+
// AST: | | |-FunctionTemplateDecl {{[^ ]+}} <<invalid sloc>> <invalid sloc> GetAttributes
5+
// AST-NEXT: | | | |-TemplateTypeParmDecl {{[^ ]+}} <<invalid sloc>> <invalid sloc> class TResult
6+
// AST-NEXT: | | | |-CXXMethodDecl {{[^ ]+}} <<invalid sloc>> <invalid sloc> implicit GetAttributes 'TResult () const'
7+
// AST-NEXT: | | | `-CXXMethodDecl {{[^ ]+}} <<invalid sloc>> <invalid sloc> used GetAttributes 'CustomAttrs &()' extern
8+
// AST-NEXT: | | | |-TemplateArgument type 'CustomAttrs'
9+
// AST-NEXT: | | | |-HLSLIntrinsicAttr {{[^ ]+}} <<invalid sloc>> Implicit "op" "" 364
10+
// AST-NEXT: | | | `-AvailabilityAttr {{[^ ]+}} <<invalid sloc>> Implicit 6.9 0 0 ""
11+
12+
// FCGL: %{{[^ ]+}} = call %struct.CustomAttrs* @"dx.hl.op..%struct.CustomAttrs* (i32, %dx.types.HitObject*)"(i32 364, %dx.types.HitObject* %{{[^ ]+}})
13+
14+
RWByteAddressBuffer outbuf;
15+
16+
struct
17+
CustomAttrs {
18+
float4 v;
19+
int y;
20+
};
21+
22+
[shader("raygeneration")]
23+
void main() {
24+
dx::HitObject hit;
25+
CustomAttrs attrs = hit.GetAttributes<CustomAttrs>();
26+
float sum = attrs.v.x + attrs.v.y + attrs.v.z + attrs.v.w + attrs.y;
27+
outbuf.Store(0, sum);
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %dxc -T lib_6_9 -E main %s -verify
2+
3+
struct
4+
CustomAttrs {
5+
vector<float, 32> v;
6+
int y;
7+
};
8+
9+
[shader("raygeneration")]
10+
void main() {
11+
dx::HitObject hit;
12+
// expected-error@+1{{vectors of over 4 elements in attributes are not supported}}
13+
CustomAttrs attrs = hit.GetAttributes<CustomAttrs>();
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %dxc -T lib_6_9 -E main %s -verify
2+
3+
struct
4+
CustomAttrs {
5+
vector<float, 32> v;
6+
RWStructuredBuffer<float> buf;
7+
};
8+
9+
[shader("raygeneration")]
10+
void main() {
11+
dx::HitObject hit;
12+
// expected-error@+1{{attributes type must be a user-defined type composed of only numeric types}}
13+
CustomAttrs attrs = hit.GetAttributes<CustomAttrs>();
14+
}

0 commit comments

Comments
 (0)