@@ -144,6 +144,7 @@ struct BuiltinTypeMethodBuilder {
144
144
_2,
145
145
_3,
146
146
_4,
147
+ _5,
147
148
Handle = 128 ,
148
149
CounterHandle,
149
150
LastStmt
@@ -190,6 +191,9 @@ struct BuiltinTypeMethodBuilder {
190
191
template <typename T>
191
192
BuiltinTypeMethodBuilder &
192
193
accessCounterHandleFieldOnResource (T ResourceRecord);
194
+ template <typename ResourceT, typename ValueT>
195
+ BuiltinTypeMethodBuilder &
196
+ setCounterHandleFieldOnResource (ResourceT ResourceRecord, ValueT HandleValue);
193
197
template <typename T> BuiltinTypeMethodBuilder &returnValue (T ReturnValue);
194
198
BuiltinTypeMethodBuilder &returnThis ();
195
199
BuiltinTypeDeclBuilder &finalize ();
@@ -205,6 +209,11 @@ struct BuiltinTypeMethodBuilder {
205
209
if (!Method)
206
210
createDecl ();
207
211
}
212
+
213
+ template <typename ResourceT, typename ValueT>
214
+ BuiltinTypeMethodBuilder &setFieldOnResource (ResourceT ResourceRecord,
215
+ ValueT HandleValue,
216
+ FieldDecl *HandleField);
208
217
};
209
218
210
219
TemplateParameterListBuilder::~TemplateParameterListBuilder () {
@@ -592,13 +601,27 @@ template <typename ResourceT, typename ValueT>
592
601
BuiltinTypeMethodBuilder &
593
602
BuiltinTypeMethodBuilder::setHandleFieldOnResource (ResourceT ResourceRecord,
594
603
ValueT HandleValue) {
604
+ return setFieldOnResource (ResourceRecord, HandleValue,
605
+ DeclBuilder.getResourceHandleField ());
606
+ }
607
+
608
+ template <typename ResourceT, typename ValueT>
609
+ BuiltinTypeMethodBuilder &
610
+ BuiltinTypeMethodBuilder::setCounterHandleFieldOnResource (
611
+ ResourceT ResourceRecord, ValueT HandleValue) {
612
+ return setFieldOnResource (ResourceRecord, HandleValue,
613
+ DeclBuilder.getResourceCounterHandleField ());
614
+ }
615
+
616
+ template <typename ResourceT, typename ValueT>
617
+ BuiltinTypeMethodBuilder &BuiltinTypeMethodBuilder::setFieldOnResource (
618
+ ResourceT ResourceRecord, ValueT HandleValue, FieldDecl *HandleField) {
595
619
ensureCompleteDecl ();
596
620
597
621
Expr *ResourceExpr = convertPlaceholder (ResourceRecord);
598
622
Expr *HandleValueExpr = convertPlaceholder (HandleValue);
599
623
600
624
ASTContext &AST = DeclBuilder.SemaRef .getASTContext ();
601
- FieldDecl *HandleField = DeclBuilder.getResourceHandleField ();
602
625
MemberExpr *HandleMemberExpr = MemberExpr::CreateImplicit (
603
626
AST, ResourceExpr, false , HandleField, HandleField->getType (), VK_LValue,
604
627
OK_Ordinary);
@@ -829,6 +852,18 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addDefaultHandleConstructor() {
829
852
.finalize ();
830
853
}
831
854
855
+ BuiltinTypeDeclBuilder &
856
+ BuiltinTypeDeclBuilder::addStaticInitializationFunctions (bool HasCounter) {
857
+ if (HasCounter) {
858
+ addCreateFromBindingWithImplicitCounter ();
859
+ addCreateFromImplicitBindingWithImplicitCounter ();
860
+ } else {
861
+ addCreateFromBinding ();
862
+ addCreateFromImplicitBinding ();
863
+ }
864
+ return *this ;
865
+ }
866
+
832
867
// Adds static method that initializes resource from binding:
833
868
//
834
869
// static Resource<T> __createFromBinding(unsigned registerNo,
@@ -903,6 +938,73 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCreateFromImplicitBinding() {
903
938
.finalize ();
904
939
}
905
940
941
+ BuiltinTypeDeclBuilder &
942
+ BuiltinTypeDeclBuilder::addCreateFromBindingWithImplicitCounter () {
943
+ if (Record->isCompleteDefinition ())
944
+ return *this ;
945
+
946
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
947
+ ASTContext &AST = SemaRef.getASTContext ();
948
+ QualType HandleType = getResourceHandleField ()->getType ();
949
+ QualType RecordType = AST.getTypeDeclType (cast<TypeDecl>(Record));
950
+ BuiltinTypeMethodBuilder::LocalVar TmpVar (" tmp" , RecordType);
951
+
952
+ return BuiltinTypeMethodBuilder (*this ,
953
+ " __createFromBindingWithImplicitCounter" ,
954
+ RecordType, false , false , SC_Static)
955
+ .addParam (" registerNo" , AST.UnsignedIntTy )
956
+ .addParam (" spaceNo" , AST.UnsignedIntTy )
957
+ .addParam (" range" , AST.IntTy )
958
+ .addParam (" index" , AST.UnsignedIntTy )
959
+ .addParam (" name" , AST.getPointerType (AST.CharTy .withConst ()))
960
+ .addParam (" counterOrderId" , AST.UnsignedIntTy )
961
+ .declareLocalVar (TmpVar)
962
+ .accessHandleFieldOnResource (TmpVar)
963
+ .callBuiltin (" __builtin_hlsl_resource_handlefrombinding" , HandleType,
964
+ PH::LastStmt, PH::_0, PH::_1, PH::_2, PH::_3, PH::_4)
965
+ .setHandleFieldOnResource (TmpVar, PH::LastStmt)
966
+ .accessHandleFieldOnResource (TmpVar)
967
+ .callBuiltin (" __builtin_hlsl_resource_counterhandlefromimplicitbinding" ,
968
+ HandleType, PH::LastStmt, PH::_5, PH::_1)
969
+ .setCounterHandleFieldOnResource (TmpVar, PH::LastStmt)
970
+ .returnValue (TmpVar)
971
+ .finalize ();
972
+ }
973
+
974
+ BuiltinTypeDeclBuilder &
975
+ BuiltinTypeDeclBuilder::addCreateFromImplicitBindingWithImplicitCounter () {
976
+ if (Record->isCompleteDefinition ())
977
+ return *this ;
978
+
979
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
980
+ ASTContext &AST = SemaRef.getASTContext ();
981
+ QualType HandleType = getResourceHandleField ()->getType ();
982
+ QualType RecordType = AST.getTypeDeclType (cast<TypeDecl>(Record));
983
+ BuiltinTypeMethodBuilder::LocalVar TmpVar (" tmp" , RecordType);
984
+
985
+ return BuiltinTypeMethodBuilder (
986
+ *this , " __createFromImplicitBindingWithImplicitCounter" ,
987
+ RecordType, false , false , SC_Static)
988
+ .addParam (" orderId" , AST.UnsignedIntTy )
989
+ .addParam (" spaceNo" , AST.UnsignedIntTy )
990
+ .addParam (" range" , AST.IntTy )
991
+ .addParam (" index" , AST.UnsignedIntTy )
992
+ .addParam (" name" , AST.getPointerType (AST.CharTy .withConst ()))
993
+ .addParam (" counterOrderId" , AST.UnsignedIntTy )
994
+ .declareLocalVar (TmpVar)
995
+ .accessHandleFieldOnResource (TmpVar)
996
+ .callBuiltin (" __builtin_hlsl_resource_handlefromimplicitbinding" ,
997
+ HandleType, PH::LastStmt, PH::_0, PH::_1, PH::_2, PH::_3,
998
+ PH::_4)
999
+ .setHandleFieldOnResource (TmpVar, PH::LastStmt)
1000
+ .accessHandleFieldOnResource (TmpVar)
1001
+ .callBuiltin (" __builtin_hlsl_resource_counterhandlefromimplicitbinding" ,
1002
+ HandleType, PH::LastStmt, PH::_5, PH::_1)
1003
+ .setCounterHandleFieldOnResource (TmpVar, PH::LastStmt)
1004
+ .returnValue (TmpVar)
1005
+ .finalize ();
1006
+ }
1007
+
906
1008
BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCopyConstructor () {
907
1009
assert (!Record->isCompleteDefinition () && " record is already complete" );
908
1010
@@ -1048,7 +1150,7 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addIncrementCounterMethod() {
1048
1150
return BuiltinTypeMethodBuilder (*this , " IncrementCounter" ,
1049
1151
SemaRef.getASTContext ().UnsignedIntTy )
1050
1152
.callBuiltin (" __builtin_hlsl_buffer_update_counter" , QualType (),
1051
- PH::Handle , getConstantIntExpr (1 ))
1153
+ PH::CounterHandle , getConstantIntExpr (1 ))
1052
1154
.finalize ();
1053
1155
}
1054
1156
@@ -1057,7 +1159,7 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addDecrementCounterMethod() {
1057
1159
return BuiltinTypeMethodBuilder (*this , " DecrementCounter" ,
1058
1160
SemaRef.getASTContext ().UnsignedIntTy )
1059
1161
.callBuiltin (" __builtin_hlsl_buffer_update_counter" , QualType (),
1060
- PH::Handle , getConstantIntExpr (-1 ))
1162
+ PH::CounterHandle , getConstantIntExpr (-1 ))
1061
1163
.finalize ();
1062
1164
}
1063
1165
@@ -1102,7 +1204,7 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addAppendMethod() {
1102
1204
return BuiltinTypeMethodBuilder (*this , " Append" , AST.VoidTy )
1103
1205
.addParam (" value" , ElemTy)
1104
1206
.callBuiltin (" __builtin_hlsl_buffer_update_counter" , AST.UnsignedIntTy ,
1105
- PH::Handle , getConstantIntExpr (1 ))
1207
+ PH::CounterHandle , getConstantIntExpr (1 ))
1106
1208
.callBuiltin (" __builtin_hlsl_resource_getpointer" ,
1107
1209
AST.getPointerType (AddrSpaceElemTy), PH::Handle,
1108
1210
PH::LastStmt)
@@ -1119,7 +1221,7 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addConsumeMethod() {
1119
1221
AST.getAddrSpaceQualType (ElemTy, LangAS::hlsl_device);
1120
1222
return BuiltinTypeMethodBuilder (*this , " Consume" , ElemTy)
1121
1223
.callBuiltin (" __builtin_hlsl_buffer_update_counter" , AST.UnsignedIntTy ,
1122
- PH::Handle , getConstantIntExpr (-1 ))
1224
+ PH::CounterHandle , getConstantIntExpr (-1 ))
1123
1225
.callBuiltin (" __builtin_hlsl_resource_getpointer" ,
1124
1226
AST.getPointerType (AddrSpaceElemTy), PH::Handle,
1125
1227
PH::LastStmt)
0 commit comments