@@ -118,13 +118,15 @@ typedef enum VUIDError_ {
118
118
VUIDErrorMax,
119
119
} VUIDError;
120
120
121
- const static uint32_t NumVUIDBuiltins = 36 ;
121
+ const static uint32_t NumVUIDBuiltins = 39 ;
122
122
123
123
typedef struct {
124
124
spv::BuiltIn builtIn;
125
125
uint32_t vuid[VUIDErrorMax]; // execution mode, storage class, type VUIDs
126
126
} BuiltinVUIDMapping;
127
127
128
+ // Many built-ins have the same checks (Storage Class, Type, etc)
129
+ // This table provides a nice LUT for the VUIDs
128
130
std::array<BuiltinVUIDMapping, NumVUIDBuiltins> builtinVUIDInfo = {{
129
131
// clang-format off
130
132
{spv::BuiltIn::SubgroupEqMask, {0 , 4370 , 4371 }},
@@ -163,8 +165,11 @@ std::array<BuiltinVUIDMapping, NumVUIDBuiltins> builtinVUIDInfo = {{
163
165
{spv::BuiltIn::CullMaskKHR, {6735 , 6736 , 6737 }},
164
166
{spv::BuiltIn::BaryCoordKHR, {4154 , 4155 , 4156 }},
165
167
{spv::BuiltIn::BaryCoordNoPerspKHR, {4160 , 4161 , 4162 }},
166
- // clang-format off
167
- } };
168
+ {spv::BuiltIn::PrimitivePointIndicesEXT, {7041 , 7043 , 7044 }},
169
+ {spv::BuiltIn::PrimitiveLineIndicesEXT, {7047 , 7049 , 7050 }},
170
+ {spv::BuiltIn::PrimitiveTriangleIndicesEXT, {7053 , 7055 , 7056 }},
171
+ // clang-format on
172
+ }};
168
173
169
174
uint32_t GetVUIDForBuiltin (spv::BuiltIn builtIn, VUIDError type) {
170
175
uint32_t vuid = 0 ;
@@ -356,6 +361,9 @@ class BuiltInsValidator {
356
361
spv_result_t ValidateRayTracingBuiltinsAtDefinition (
357
362
const Decoration& decoration, const Instruction& inst);
358
363
364
+ spv_result_t ValidateMeshShadingEXTBuiltinsAtDefinition (
365
+ const Decoration& decoration, const Instruction& inst);
366
+
359
367
// The following section contains functions which are called when id defined
360
368
// by |referenced_inst| is
361
369
// 1. referenced by |referenced_from_inst|
@@ -546,6 +554,11 @@ class BuiltInsValidator {
546
554
const Instruction& referenced_inst,
547
555
const Instruction& referenced_from_inst);
548
556
557
+ spv_result_t ValidateMeshShadingEXTBuiltinsAtReference (
558
+ const Decoration& decoration, const Instruction& built_in_inst,
559
+ const Instruction& referenced_inst,
560
+ const Instruction& referenced_from_inst);
561
+
549
562
// Validates that |built_in_inst| is not (even indirectly) referenced from
550
563
// within a function which can be called with |execution_model|.
551
564
//
@@ -581,6 +594,10 @@ class BuiltInsValidator {
581
594
spv_result_t ValidateI32Arr (
582
595
const Decoration& decoration, const Instruction& inst,
583
596
const std::function<spv_result_t (const std::string& message)>& diag);
597
+ spv_result_t ValidateArrayedI32Vec (
598
+ const Decoration& decoration, const Instruction& inst,
599
+ uint32_t num_components,
600
+ const std::function<spv_result_t (const std::string& message)>& diag);
584
601
spv_result_t ValidateOptionalArrayedI32 (
585
602
const Decoration& decoration, const Instruction& inst,
586
603
const std::function<spv_result_t (const std::string& message)>& diag);
@@ -909,6 +926,45 @@ spv_result_t BuiltInsValidator::ValidateI32Vec(
909
926
return SPV_SUCCESS;
910
927
}
911
928
929
+ spv_result_t BuiltInsValidator::ValidateArrayedI32Vec (
930
+ const Decoration& decoration, const Instruction& inst,
931
+ uint32_t num_components,
932
+ const std::function<spv_result_t (const std::string& message)>& diag) {
933
+ uint32_t underlying_type = 0 ;
934
+ if (spv_result_t error =
935
+ GetUnderlyingType (_, decoration, inst, &underlying_type)) {
936
+ return error;
937
+ }
938
+
939
+ const Instruction* const type_inst = _.FindDef (underlying_type);
940
+ if (type_inst->opcode () != spv::Op::OpTypeArray) {
941
+ return diag (GetDefinitionDesc (decoration, inst) + " is not an array." );
942
+ }
943
+
944
+ const uint32_t component_type = type_inst->word (2 );
945
+ if (!_.IsIntVectorType (component_type)) {
946
+ return diag (GetDefinitionDesc (decoration, inst) + " is not an int vector." );
947
+ }
948
+
949
+ const uint32_t actual_num_components = _.GetDimension (component_type);
950
+ if (_.GetDimension (component_type) != num_components) {
951
+ std::ostringstream ss;
952
+ ss << GetDefinitionDesc (decoration, inst) << " has "
953
+ << actual_num_components << " components." ;
954
+ return diag (ss.str ());
955
+ }
956
+
957
+ const uint32_t bit_width = _.GetBitWidth (component_type);
958
+ if (bit_width != 32 ) {
959
+ std::ostringstream ss;
960
+ ss << GetDefinitionDesc (decoration, inst)
961
+ << " has components with bit width " << bit_width << " ." ;
962
+ return diag (ss.str ());
963
+ }
964
+
965
+ return SPV_SUCCESS;
966
+ }
967
+
912
968
spv_result_t BuiltInsValidator::ValidateOptionalArrayedF32Vec (
913
969
const Decoration& decoration, const Instruction& inst,
914
970
uint32_t num_components,
@@ -4108,6 +4164,119 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtReference(
4108
4164
return SPV_SUCCESS;
4109
4165
}
4110
4166
4167
+ spv_result_t BuiltInsValidator::ValidateMeshShadingEXTBuiltinsAtDefinition (
4168
+ const Decoration& decoration, const Instruction& inst) {
4169
+ if (spvIsVulkanEnv (_.context ()->target_env )) {
4170
+ const spv::BuiltIn builtin = spv::BuiltIn (decoration.params ()[0 ]);
4171
+ uint32_t vuid = GetVUIDForBuiltin (builtin, VUIDErrorType);
4172
+ if (builtin == spv::BuiltIn::PrimitivePointIndicesEXT) {
4173
+ if (spv_result_t error = ValidateI32Arr (
4174
+ decoration, inst,
4175
+ [this , &inst, &decoration,
4176
+ &vuid](const std::string& message) -> spv_result_t {
4177
+ return _.diag (SPV_ERROR_INVALID_DATA, &inst)
4178
+ << _.VkErrorID (vuid) << " According to the "
4179
+ << spvLogStringForEnv (_.context ()->target_env )
4180
+ << " spec BuiltIn "
4181
+ << _.grammar ().lookupOperandName (
4182
+ SPV_OPERAND_TYPE_BUILT_IN, decoration.params ()[0 ])
4183
+ << " variable needs to be a 32-bit int array."
4184
+ << message;
4185
+ })) {
4186
+ return error;
4187
+ }
4188
+ }
4189
+ if (builtin == spv::BuiltIn::PrimitiveLineIndicesEXT) {
4190
+ if (spv_result_t error = ValidateArrayedI32Vec (
4191
+ decoration, inst, 2 ,
4192
+ [this , &inst, &decoration,
4193
+ &vuid](const std::string& message) -> spv_result_t {
4194
+ return _.diag (SPV_ERROR_INVALID_DATA, &inst)
4195
+ << _.VkErrorID (vuid) << " According to the "
4196
+ << spvLogStringForEnv (_.context ()->target_env )
4197
+ << " spec BuiltIn "
4198
+ << _.grammar ().lookupOperandName (
4199
+ SPV_OPERAND_TYPE_BUILT_IN, decoration.params ()[0 ])
4200
+ << " variable needs to be a 2-component 32-bit int "
4201
+ " array."
4202
+ << message;
4203
+ })) {
4204
+ return error;
4205
+ }
4206
+ }
4207
+ if (builtin == spv::BuiltIn::PrimitiveTriangleIndicesEXT) {
4208
+ if (spv_result_t error = ValidateArrayedI32Vec (
4209
+ decoration, inst, 3 ,
4210
+ [this , &inst, &decoration,
4211
+ &vuid](const std::string& message) -> spv_result_t {
4212
+ return _.diag (SPV_ERROR_INVALID_DATA, &inst)
4213
+ << _.VkErrorID (vuid) << " According to the "
4214
+ << spvLogStringForEnv (_.context ()->target_env )
4215
+ << " spec BuiltIn "
4216
+ << _.grammar ().lookupOperandName (
4217
+ SPV_OPERAND_TYPE_BUILT_IN, decoration.params ()[0 ])
4218
+ << " variable needs to be a 3-component 32-bit int "
4219
+ " array."
4220
+ << message;
4221
+ })) {
4222
+ return error;
4223
+ }
4224
+ }
4225
+ }
4226
+ // Seed at reference checks with this built-in.
4227
+ return ValidateMeshShadingEXTBuiltinsAtReference (decoration, inst, inst,
4228
+ inst);
4229
+ }
4230
+
4231
+ spv_result_t BuiltInsValidator::ValidateMeshShadingEXTBuiltinsAtReference (
4232
+ const Decoration& decoration, const Instruction& built_in_inst,
4233
+ const Instruction& referenced_inst,
4234
+ const Instruction& referenced_from_inst) {
4235
+ if (spvIsVulkanEnv (_.context ()->target_env )) {
4236
+ const spv::BuiltIn builtin = spv::BuiltIn (decoration.params ()[0 ]);
4237
+ const spv::StorageClass storage_class =
4238
+ GetStorageClass (referenced_from_inst);
4239
+ if (storage_class != spv::StorageClass::Max &&
4240
+ storage_class != spv::StorageClass::Output) {
4241
+ uint32_t vuid = GetVUIDForBuiltin (builtin, VUIDErrorStorageClass);
4242
+ return _.diag (SPV_ERROR_INVALID_DATA, &referenced_from_inst)
4243
+ << _.VkErrorID (vuid) << spvLogStringForEnv (_.context ()->target_env )
4244
+ << " spec allows BuiltIn "
4245
+ << _.grammar ().lookupOperandName (SPV_OPERAND_TYPE_BUILT_IN,
4246
+ uint32_t (builtin))
4247
+ << " to be only used for variables with Output storage class. "
4248
+ << GetReferenceDesc (decoration, built_in_inst, referenced_inst,
4249
+ referenced_from_inst)
4250
+ << " " << GetStorageClassDesc (referenced_from_inst);
4251
+ }
4252
+
4253
+ for (const spv::ExecutionModel execution_model : execution_models_) {
4254
+ if (execution_model != spv::ExecutionModel::MeshEXT) {
4255
+ uint32_t vuid = GetVUIDForBuiltin (builtin, VUIDErrorExecutionModel);
4256
+ return _.diag (SPV_ERROR_INVALID_DATA, &referenced_from_inst)
4257
+ << _.VkErrorID (vuid)
4258
+ << spvLogStringForEnv (_.context ()->target_env )
4259
+ << " spec allows BuiltIn "
4260
+ << _.grammar ().lookupOperandName (SPV_OPERAND_TYPE_BUILT_IN,
4261
+ uint32_t (builtin))
4262
+ << " to be used only with MeshEXT execution model. "
4263
+ << GetReferenceDesc (decoration, built_in_inst, referenced_inst,
4264
+ referenced_from_inst, execution_model);
4265
+ }
4266
+ }
4267
+ }
4268
+
4269
+ if (function_id_ == 0 ) {
4270
+ // Propagate this rule to all dependant ids in the global scope.
4271
+ id_to_at_reference_checks_[referenced_from_inst.id ()].push_back (
4272
+ std::bind (&BuiltInsValidator::ValidateMeshShadingEXTBuiltinsAtReference,
4273
+ this , decoration, built_in_inst, referenced_from_inst,
4274
+ std::placeholders::_1));
4275
+ }
4276
+
4277
+ return SPV_SUCCESS;
4278
+ }
4279
+
4111
4280
spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition (
4112
4281
const Decoration& decoration, const Instruction& inst) {
4113
4282
const spv::BuiltIn label = spv::BuiltIn (decoration.params ()[0 ]);
@@ -4283,6 +4452,11 @@ spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition(
4283
4452
case spv::BuiltIn::CullMaskKHR: {
4284
4453
return ValidateRayTracingBuiltinsAtDefinition (decoration, inst);
4285
4454
}
4455
+ case spv::BuiltIn::PrimitivePointIndicesEXT:
4456
+ case spv::BuiltIn::PrimitiveLineIndicesEXT:
4457
+ case spv::BuiltIn::PrimitiveTriangleIndicesEXT: {
4458
+ return ValidateMeshShadingEXTBuiltinsAtDefinition (decoration, inst);
4459
+ }
4286
4460
case spv::BuiltIn::PrimitiveShadingRateKHR: {
4287
4461
return ValidatePrimitiveShadingRateAtDefinition (decoration, inst);
4288
4462
}
0 commit comments