spirv-val: Add Subgroup VUIDs (#4074)

This commit is contained in:
sfricke-samsung 2020-12-17 05:37:43 -08:00 committed by GitHub
parent 4e31fdd4aa
commit 8f4b35c332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 98 deletions

View File

@ -142,15 +142,28 @@ typedef enum VUIDError_ {
VUIDErrorMax, VUIDErrorMax,
} VUIDError; } VUIDError;
const static uint32_t NumRtBuiltins = 16; const static uint32_t NumVUIDBuiltins = 29;
typedef struct { typedef struct {
SpvBuiltIn builtIn; SpvBuiltIn builtIn;
uint32_t vuid[VUIDErrorMax]; // execution mode, storage class, type VUIDs uint32_t vuid[VUIDErrorMax]; // execution mode, storage class, type VUIDs
} RtBuiltinVUIDMapping; } BuiltinVUIDMapping;
std::array<RtBuiltinVUIDMapping, NumRtBuiltins> rtBuiltinInfo = {{ std::array<BuiltinVUIDMapping, NumVUIDBuiltins> builtinVUIDInfo = {{
// clang-format off // clang-format off
{SpvBuiltInSubgroupEqMask, {0, 4370, 4371}},
{SpvBuiltInSubgroupGeMask, {0, 4372, 4373}},
{SpvBuiltInSubgroupGtMask, {0, 4374, 4375}},
{SpvBuiltInSubgroupLeMask, {0, 4376, 4377}},
{SpvBuiltInSubgroupLtMask, {0, 4378, 4379}},
{SpvBuiltInSubgroupLocalInvocationId, {0, 4380, 4381}},
{SpvBuiltInSubgroupSize, {0, 4382, 4383}},
{SpvBuiltInGlobalInvocationId, {4236, 4237, 4238}},
{SpvBuiltInLocalInvocationId, {4281, 4282, 4283}},
{SpvBuiltInNumWorkgroups, {4296, 4297, 4298}},
{SpvBuiltInNumSubgroups, {4293, 4294, 4295}},
{SpvBuiltInSubgroupId, {4367, 4368, 4369}},
{SpvBuiltInWorkgroupId, {4422, 4423, 4424}},
{SpvBuiltInHitKindKHR, {4242, 4243, 4244}}, {SpvBuiltInHitKindKHR, {4242, 4243, 4244}},
{SpvBuiltInHitTNV, {4245, 4246, 4247}}, {SpvBuiltInHitTNV, {4245, 4246, 4247}},
{SpvBuiltInInstanceCustomIndexKHR, {4251, 4252, 4253}}, {SpvBuiltInInstanceCustomIndexKHR, {4251, 4252, 4253}},
@ -170,9 +183,9 @@ std::array<RtBuiltinVUIDMapping, NumRtBuiltins> rtBuiltinInfo = {{
// clang-format off // clang-format off
} }; } };
uint32_t GetVUIDForRTBuiltin(SpvBuiltIn builtIn, VUIDError type) { uint32_t GetVUIDForBuiltin(SpvBuiltIn builtIn, VUIDError type) {
uint32_t vuid = 0; uint32_t vuid = 0;
for (const auto& iter: rtBuiltinInfo) { for (const auto& iter: builtinVUIDInfo) {
if (iter.builtIn == builtIn) { if (iter.builtIn == builtIn) {
assert(type < VUIDErrorMax); assert(type < VUIDErrorMax);
vuid = iter.vuid[type]; vuid = iter.vuid[type];
@ -2826,32 +2839,17 @@ spv_result_t BuiltInsValidator::ValidateLayerOrViewportIndexAtReference(
spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtDefinition( spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtDefinition(
const Decoration& decoration, const Instruction& inst) { const Decoration& decoration, const Instruction& inst) {
if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) { if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
if (spv_result_t error = ValidateI32Vec( if (spv_result_t error = ValidateI32Vec(
decoration, inst, 3, decoration, inst, 3,
[this, &decoration, [this, &inst, builtin](const std::string& message) -> spv_result_t {
&inst](const std::string& message) -> spv_result_t { uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
uint32_t operand = decoration.params()[0];
uint32_t vuid = 0;
switch (operand) {
case SpvBuiltInGlobalInvocationId:
vuid = 4238;
break;
case SpvBuiltInLocalInvocationId:
vuid = 4283;
break;
case SpvBuiltInNumWorkgroups:
vuid = 4298;
break;
case SpvBuiltInWorkgroupId:
vuid = 4424;
break;
};
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid) << "According to the " << _.VkErrorID(vuid) << "According to the "
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec BuiltIn " << " spec BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN,
operand) builtin)
<< " variable needs to be a 3-component 32-bit int " << " variable needs to be a 3-component 32-bit int "
"vector. " "vector. "
<< message; << message;
@ -2869,31 +2867,16 @@ spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtReference(
const Decoration& decoration, const Instruction& built_in_inst, const Decoration& decoration, const Instruction& built_in_inst,
const Instruction& referenced_inst, const Instruction& referenced_inst,
const Instruction& referenced_from_inst) { const Instruction& referenced_from_inst) {
uint32_t operand = decoration.params()[0];
if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) { if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst); const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
if (storage_class != SpvStorageClassMax && if (storage_class != SpvStorageClassMax &&
storage_class != SpvStorageClassInput) { storage_class != SpvStorageClassInput) {
uint32_t vuid = 0; uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorStorageClass);
switch (operand) {
case SpvBuiltInGlobalInvocationId:
vuid = 4237;
break;
case SpvBuiltInLocalInvocationId:
vuid = 4282;
break;
case SpvBuiltInNumWorkgroups:
vuid = 4297;
break;
case SpvBuiltInWorkgroupId:
vuid = 4423;
break;
};
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< _.VkErrorID(vuid) << spvLogStringForEnv(_.context()->target_env) << _.VkErrorID(vuid) << spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn " << " spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " to be only used for variables with Input storage class. " << " to be only used for variables with Input storage class. "
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst, << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
referenced_from_inst) referenced_from_inst)
@ -2907,27 +2890,12 @@ spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtReference(
bool has_webgpu_model = execution_model == SpvExecutionModelGLCompute; bool has_webgpu_model = execution_model == SpvExecutionModelGLCompute;
if ((spvIsVulkanEnv(_.context()->target_env) && !has_vulkan_model) || if ((spvIsVulkanEnv(_.context()->target_env) && !has_vulkan_model) ||
(spvIsWebGPUEnv(_.context()->target_env) && !has_webgpu_model)) { (spvIsWebGPUEnv(_.context()->target_env) && !has_webgpu_model)) {
uint32_t vuid = 0; uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorExecutionModel);
switch (operand) {
case SpvBuiltInGlobalInvocationId:
vuid = 4236;
break;
case SpvBuiltInLocalInvocationId:
vuid = 4281;
break;
case SpvBuiltInNumWorkgroups:
vuid = 4296;
break;
case SpvBuiltInWorkgroupId:
vuid = 4422;
break;
};
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< _.VkErrorID(vuid) << _.VkErrorID(vuid)
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn " << " spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " to be used only with GLCompute execution model. " << " to be used only with GLCompute execution model. "
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst, << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
referenced_from_inst, execution_model); referenced_from_inst, execution_model);
@ -2949,23 +2917,23 @@ spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtReference(
spv_result_t BuiltInsValidator::ValidateComputeI32InputAtDefinition( spv_result_t BuiltInsValidator::ValidateComputeI32InputAtDefinition(
const Decoration& decoration, const Instruction& inst) { const Decoration& decoration, const Instruction& inst) {
if (spvIsVulkanEnv(_.context()->target_env)) { if (spvIsVulkanEnv(_.context()->target_env)) {
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
if (decoration.struct_member_index() != Decoration::kInvalidMember) { if (decoration.struct_member_index() != Decoration::kInvalidMember) {
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< "BuiltIn " << "BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " cannot be used as a member decoration "; << " cannot be used as a member decoration ";
} }
if (spv_result_t error = ValidateI32( if (spv_result_t error = ValidateI32(
decoration, inst, decoration, inst,
[this, &decoration, [this, &inst, builtin](const std::string& message) -> spv_result_t {
&inst](const std::string& message) -> spv_result_t { uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid)
<< "According to the " << "According to the "
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec BuiltIn " << " spec BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " variable needs to be a 32-bit int " << " variable needs to be a 32-bit int "
"vector. " "vector. "
<< message; << message;
@ -2983,14 +2951,16 @@ spv_result_t BuiltInsValidator::ValidateComputeI32InputAtReference(
const Instruction& referenced_inst, const Instruction& referenced_inst,
const Instruction& referenced_from_inst) { const Instruction& referenced_from_inst) {
if (spvIsVulkanEnv(_.context()->target_env)) { if (spvIsVulkanEnv(_.context()->target_env)) {
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst); const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
if (storage_class != SpvStorageClassMax && if (storage_class != SpvStorageClassMax &&
storage_class != SpvStorageClassInput) { storage_class != SpvStorageClassInput) {
uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorStorageClass);
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< _.VkErrorID(vuid)
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn " << " spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " to be only used for variables with Input storage class. " << " to be only used for variables with Input storage class. "
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst, << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
referenced_from_inst) referenced_from_inst)
@ -3002,11 +2972,12 @@ spv_result_t BuiltInsValidator::ValidateComputeI32InputAtReference(
execution_model == SpvExecutionModelTaskNV || execution_model == SpvExecutionModelTaskNV ||
execution_model == SpvExecutionModelMeshNV; execution_model == SpvExecutionModelMeshNV;
if (spvIsVulkanEnv(_.context()->target_env) && !has_vulkan_model) { if (spvIsVulkanEnv(_.context()->target_env) && !has_vulkan_model) {
uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorExecutionModel);
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< _.VkErrorID(vuid)
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn " << " spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " to be used only with GLCompute execution model. " << " to be used only with GLCompute execution model. "
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst, << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
referenced_from_inst, execution_model); referenced_from_inst, execution_model);
@ -3028,23 +2999,23 @@ spv_result_t BuiltInsValidator::ValidateComputeI32InputAtReference(
spv_result_t BuiltInsValidator::ValidateI32InputAtDefinition( spv_result_t BuiltInsValidator::ValidateI32InputAtDefinition(
const Decoration& decoration, const Instruction& inst) { const Decoration& decoration, const Instruction& inst) {
if (spvIsVulkanEnv(_.context()->target_env)) { if (spvIsVulkanEnv(_.context()->target_env)) {
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
if (decoration.struct_member_index() != Decoration::kInvalidMember) { if (decoration.struct_member_index() != Decoration::kInvalidMember) {
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< "BuiltIn " << "BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " cannot be used as a member decoration "; << " cannot be used as a member decoration ";
} }
if (spv_result_t error = ValidateI32( if (spv_result_t error = ValidateI32(
decoration, inst, decoration, inst,
[this, &decoration, [this, &inst, builtin](const std::string& message) -> spv_result_t {
&inst](const std::string& message) -> spv_result_t { uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid)
<< "According to the " << "According to the "
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec BuiltIn " << " spec BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " variable needs to be a 32-bit int. " << message; << " variable needs to be a 32-bit int. " << message;
})) { })) {
return error; return error;
@ -3053,11 +3024,12 @@ spv_result_t BuiltInsValidator::ValidateI32InputAtDefinition(
const SpvStorageClass storage_class = GetStorageClass(inst); const SpvStorageClass storage_class = GetStorageClass(inst);
if (storage_class != SpvStorageClassMax && if (storage_class != SpvStorageClassMax &&
storage_class != SpvStorageClassInput) { storage_class != SpvStorageClassInput) {
uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorStorageClass);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid)
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn " << " spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " to be only used for variables with Input storage class. " << " to be only used for variables with Input storage class. "
<< GetReferenceDesc(decoration, inst, inst, inst) << " " << GetReferenceDesc(decoration, inst, inst, inst) << " "
<< GetStorageClassDesc(inst); << GetStorageClassDesc(inst);
@ -3070,23 +3042,23 @@ spv_result_t BuiltInsValidator::ValidateI32InputAtDefinition(
spv_result_t BuiltInsValidator::ValidateI32Vec4InputAtDefinition( spv_result_t BuiltInsValidator::ValidateI32Vec4InputAtDefinition(
const Decoration& decoration, const Instruction& inst) { const Decoration& decoration, const Instruction& inst) {
if (spvIsVulkanEnv(_.context()->target_env)) { if (spvIsVulkanEnv(_.context()->target_env)) {
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
if (decoration.struct_member_index() != Decoration::kInvalidMember) { if (decoration.struct_member_index() != Decoration::kInvalidMember) {
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< "BuiltIn " << "BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " cannot be used as a member decoration "; << " cannot be used as a member decoration ";
} }
if (spv_result_t error = ValidateI32Vec( if (spv_result_t error = ValidateI32Vec(
decoration, inst, 4, decoration, inst, 4,
[this, &decoration, [this, &inst, builtin](const std::string& message) -> spv_result_t {
&inst](const std::string& message) -> spv_result_t { uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid)
<< "According to the " << "According to the "
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec BuiltIn " << " spec BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " variable needs to be a 4-component 32-bit int " << " variable needs to be a 4-component 32-bit int "
"vector. " "vector. "
<< message; << message;
@ -3097,11 +3069,12 @@ spv_result_t BuiltInsValidator::ValidateI32Vec4InputAtDefinition(
const SpvStorageClass storage_class = GetStorageClass(inst); const SpvStorageClass storage_class = GetStorageClass(inst);
if (storage_class != SpvStorageClassMax && if (storage_class != SpvStorageClassMax &&
storage_class != SpvStorageClassInput) { storage_class != SpvStorageClassInput) {
uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorStorageClass);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid)
<< spvLogStringForEnv(_.context()->target_env) << spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn " << " spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, builtin)
decoration.params()[0])
<< " to be only used for variables with Input storage class. " << " to be only used for variables with Input storage class. "
<< GetReferenceDesc(decoration, inst, inst, inst) << " " << GetReferenceDesc(decoration, inst, inst, inst) << " "
<< GetStorageClassDesc(inst); << GetStorageClassDesc(inst);
@ -3628,7 +3601,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtDefinition(
decoration, inst, decoration, inst,
[this, &inst, [this, &inst,
builtin](const std::string& message) -> spv_result_t { builtin](const std::string& message) -> spv_result_t {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorType); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid) << _.VkErrorID(vuid)
<< "According to the Vulkan spec BuiltIn " << "According to the Vulkan spec BuiltIn "
@ -3650,7 +3623,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtDefinition(
decoration, inst, decoration, inst,
[this, &inst, [this, &inst,
builtin](const std::string& message) -> spv_result_t { builtin](const std::string& message) -> spv_result_t {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorType); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid) << _.VkErrorID(vuid)
<< "According to the Vulkan spec BuiltIn " << "According to the Vulkan spec BuiltIn "
@ -3671,7 +3644,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtDefinition(
decoration, inst, 3, decoration, inst, 3,
[this, &inst, [this, &inst,
builtin](const std::string& message) -> spv_result_t { builtin](const std::string& message) -> spv_result_t {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorType); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid) << _.VkErrorID(vuid)
<< "According to the Vulkan spec BuiltIn " << "According to the Vulkan spec BuiltIn "
@ -3691,7 +3664,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtDefinition(
decoration, inst, 3, decoration, inst, 3,
[this, &inst, [this, &inst,
builtin](const std::string& message) -> spv_result_t { builtin](const std::string& message) -> spv_result_t {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorType); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid) << _.VkErrorID(vuid)
<< "According to the Vulkan spec BuiltIn " << "According to the Vulkan spec BuiltIn "
@ -3711,7 +3684,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtDefinition(
decoration, inst, 3, 4, decoration, inst, 3, 4,
[this, &inst, [this, &inst,
builtin](const std::string& message) -> spv_result_t { builtin](const std::string& message) -> spv_result_t {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorType); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorType);
return _.diag(SPV_ERROR_INVALID_DATA, &inst) return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< _.VkErrorID(vuid) << _.VkErrorID(vuid)
<< "According to the Vulkan spec BuiltIn " << "According to the Vulkan spec BuiltIn "
@ -3744,7 +3717,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtReference(
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst); const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
if (storage_class != SpvStorageClassMax && if (storage_class != SpvStorageClassMax &&
storage_class != SpvStorageClassInput) { storage_class != SpvStorageClassInput) {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorStorageClass); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorStorageClass);
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< _.VkErrorID(vuid) << "Vulkan spec allows BuiltIn " << _.VkErrorID(vuid) << "Vulkan spec allows BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN,
@ -3757,7 +3730,7 @@ spv_result_t BuiltInsValidator::ValidateRayTracingBuiltinsAtReference(
for (const SpvExecutionModel execution_model : execution_models_) { for (const SpvExecutionModel execution_model : execution_models_) {
if (!IsExecutionModelValidForRtBuiltIn(builtin, execution_model)) { if (!IsExecutionModelValidForRtBuiltIn(builtin, execution_model)) {
uint32_t vuid = GetVUIDForRTBuiltin(builtin, VUIDErrorExecutionModel); uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorExecutionModel);
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst) return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< _.VkErrorID(vuid) << "Vulkan spec does not allow BuiltIn " << _.VkErrorID(vuid) << "Vulkan spec does not allow BuiltIn "
<< _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN, << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN,

View File

@ -1445,6 +1445,12 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04282); return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04282);
case 4283: case 4283:
return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04283); return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04283);
case 4293:
return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04293);
case 4294:
return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04294);
case 4295:
return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04295);
case 4296: case 4296:
return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04296); return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04296);
case 4297: case 4297:
@ -1539,6 +1545,40 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-SamplePosition-SamplePosition-04361); return VUID_WRAP(VUID-SamplePosition-SamplePosition-04361);
case 4362: case 4362:
return VUID_WRAP(VUID-SamplePosition-SamplePosition-04362); return VUID_WRAP(VUID-SamplePosition-SamplePosition-04362);
case 4367:
return VUID_WRAP(VUID-SubgroupId-SubgroupId-04367);
case 4368:
return VUID_WRAP(VUID-SubgroupId-SubgroupId-04368);
case 4369:
return VUID_WRAP(VUID-SubgroupId-SubgroupId-04369);
case 4370:
return VUID_WRAP(VUID-SubgroupEqMask-SubgroupEqMask-04370);
case 4371:
return VUID_WRAP(VUID-SubgroupEqMask-SubgroupEqMask-04371);
case 4372:
return VUID_WRAP(VUID-SubgroupGeMask-SubgroupGeMask-04372);
case 4373:
return VUID_WRAP(VUID-SubgroupGeMask-SubgroupGeMask-04373);
case 4374:
return VUID_WRAP(VUID-SubgroupGtMask-SubgroupGtMask-04374);
case 4375:
return VUID_WRAP(VUID-SubgroupGtMask-SubgroupGtMask-04375);
case 4376:
return VUID_WRAP(VUID-SubgroupLeMask-SubgroupLeMask-04376);
case 4377:
return VUID_WRAP(VUID-SubgroupLeMask-SubgroupLeMask-04377);
case 4378:
return VUID_WRAP(VUID-SubgroupLtMask-SubgroupLtMask-04378);
case 4379:
return VUID_WRAP(VUID-SubgroupLtMask-SubgroupLtMask-04379);
case 4380:
return VUID_WRAP(VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-04380);
case 4381:
return VUID_WRAP(VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-04381);
case 4382:
return VUID_WRAP(VUID-SubgroupSize-SubgroupSize-04382);
case 4383:
return VUID_WRAP(VUID-SubgroupSize-SubgroupSize-04383);
case 4387: case 4387:
return VUID_WRAP(VUID-TessCoord-TessCoord-04387); return VUID_WRAP(VUID-TessCoord-TessCoord-04387);
case 4388: case 4388:

View File

@ -54,8 +54,9 @@ using ::testing::Values;
using ::testing::ValuesIn; using ::testing::ValuesIn;
using ValidateBuiltIns = spvtest::ValidateBase<bool>; using ValidateBuiltIns = spvtest::ValidateBase<bool>;
using ValidateVulkanSubgroupBuiltIns = spvtest::ValidateBase< using ValidateVulkanSubgroupBuiltIns =
std::tuple<const char*, const char*, const char*, const char*, TestResult>>; spvtest::ValidateBase<std::tuple<const char*, const char*, const char*,
const char*, const char*, TestResult>>;
using ValidateVulkanCombineBuiltInExecutionModelDataTypeResult = using ValidateVulkanCombineBuiltInExecutionModelDataTypeResult =
spvtest::ValidateBase<std::tuple<const char*, const char*, const char*, spvtest::ValidateBase<std::tuple<const char*, const char*, const char*,
const char*, const char*, TestResult>>; const char*, const char*, TestResult>>;
@ -4082,7 +4083,8 @@ TEST_P(ValidateVulkanSubgroupBuiltIns, InMain) {
const char* const execution_model = std::get<1>(GetParam()); const char* const execution_model = std::get<1>(GetParam());
const char* const storage_class = std::get<2>(GetParam()); const char* const storage_class = std::get<2>(GetParam());
const char* const data_type = std::get<3>(GetParam()); const char* const data_type = std::get<3>(GetParam());
const TestResult& test_result = std::get<4>(GetParam()); const char* const vuid = std::get<4>(GetParam());
const TestResult& test_result = std::get<5>(GetParam());
CodeGenerator generator = CodeGenerator::GetDefaultShaderCodeGenerator(); CodeGenerator generator = CodeGenerator::GetDefaultShaderCodeGenerator();
generator.capabilities_ += R"( generator.capabilities_ += R"(
@ -4142,6 +4144,9 @@ OpCapability GroupNonUniformBallot
if (test_result.error_str2) { if (test_result.error_str2) {
EXPECT_THAT(getDiagnosticString(), HasSubstr(test_result.error_str2)); EXPECT_THAT(getDiagnosticString(), HasSubstr(test_result.error_str2));
} }
if (vuid) {
EXPECT_THAT(getDiagnosticString(), AnyVUID(vuid));
}
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -4149,6 +4154,11 @@ INSTANTIATE_TEST_SUITE_P(
Combine(Values("SubgroupEqMask", "SubgroupGeMask", "SubgroupGtMask", Combine(Values("SubgroupEqMask", "SubgroupGeMask", "SubgroupGtMask",
"SubgroupLeMask", "SubgroupLtMask"), "SubgroupLeMask", "SubgroupLtMask"),
Values("GLCompute"), Values("Input"), Values("%u32vec3"), Values("GLCompute"), Values("Input"), Values("%u32vec3"),
Values("VUID-SubgroupEqMask-SubgroupEqMask-04371 "
"VUID-SubgroupGeMask-SubgroupGeMask-04373 "
"VUID-SubgroupGtMask-SubgroupGtMask-04375 "
"VUID-SubgroupLeMask-SubgroupLeMask-04377 "
"VUID-SubgroupLtMask-SubgroupLtMask-04379"),
Values(TestResult(SPV_ERROR_INVALID_DATA, Values(TestResult(SPV_ERROR_INVALID_DATA,
"needs to be a 4-component 32-bit int vector")))); "needs to be a 4-component 32-bit int vector"))));
@ -4157,6 +4167,11 @@ INSTANTIATE_TEST_SUITE_P(
Combine(Values("SubgroupEqMask", "SubgroupGeMask", "SubgroupGtMask", Combine(Values("SubgroupEqMask", "SubgroupGeMask", "SubgroupGtMask",
"SubgroupLeMask", "SubgroupLtMask"), "SubgroupLeMask", "SubgroupLtMask"),
Values("GLCompute"), Values("Input"), Values("%f32vec4"), Values("GLCompute"), Values("Input"), Values("%f32vec4"),
Values("VUID-SubgroupEqMask-SubgroupEqMask-04371 "
"VUID-SubgroupGeMask-SubgroupGeMask-04373 "
"VUID-SubgroupGtMask-SubgroupGtMask-04375 "
"VUID-SubgroupLeMask-SubgroupLeMask-04377 "
"VUID-SubgroupLtMask-SubgroupLtMask-04379"),
Values(TestResult(SPV_ERROR_INVALID_DATA, Values(TestResult(SPV_ERROR_INVALID_DATA,
"needs to be a 4-component 32-bit int vector")))); "needs to be a 4-component 32-bit int vector"))));
@ -4166,6 +4181,11 @@ INSTANTIATE_TEST_SUITE_P(
"SubgroupLeMask", "SubgroupLtMask"), "SubgroupLeMask", "SubgroupLtMask"),
Values("GLCompute"), Values("Output", "Workgroup", "Private"), Values("GLCompute"), Values("Output", "Workgroup", "Private"),
Values("%u32vec4"), Values("%u32vec4"),
Values("VUID-SubgroupEqMask-SubgroupEqMask-04370 "
"VUID-SubgroupGeMask-SubgroupGeMask-04372 "
"VUID-SubgroupGtMask-SubgroupGtMask-04374 "
"VUID-SubgroupLeMask-SubgroupLeMask-04376 "
"VUID-SubgroupLtMask-SubgroupLtMask-04378"),
Values(TestResult( Values(TestResult(
SPV_ERROR_INVALID_DATA, SPV_ERROR_INVALID_DATA,
"to be only used for variables with Input storage class")))); "to be only used for variables with Input storage class"))));
@ -4175,7 +4195,7 @@ INSTANTIATE_TEST_SUITE_P(SubgroupMaskOk, ValidateVulkanSubgroupBuiltIns,
"SubgroupGtMask", "SubgroupLeMask", "SubgroupGtMask", "SubgroupLeMask",
"SubgroupLtMask"), "SubgroupLtMask"),
Values("GLCompute"), Values("Input"), Values("GLCompute"), Values("Input"),
Values("%u32vec4"), Values("%u32vec4"), Values(nullptr),
Values(TestResult(SPV_SUCCESS, "")))); Values(TestResult(SPV_SUCCESS, ""))));
TEST_F(ValidateBuiltIns, SubgroupMaskMemberDecorate) { TEST_F(ValidateBuiltIns, SubgroupMaskMemberDecorate) {
@ -4208,6 +4228,8 @@ INSTANTIATE_TEST_SUITE_P(
SubgroupInvocationIdAndSizeNotU32, ValidateVulkanSubgroupBuiltIns, SubgroupInvocationIdAndSizeNotU32, ValidateVulkanSubgroupBuiltIns,
Combine(Values("SubgroupLocalInvocationId", "SubgroupSize"), Combine(Values("SubgroupLocalInvocationId", "SubgroupSize"),
Values("GLCompute"), Values("Input"), Values("%f32"), Values("GLCompute"), Values("Input"), Values("%f32"),
Values("VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-"
"04381 VUID-SubgroupSize-SubgroupSize-04383"),
Values(TestResult(SPV_ERROR_INVALID_DATA, Values(TestResult(SPV_ERROR_INVALID_DATA,
"needs to be a 32-bit int")))); "needs to be a 32-bit int"))));
@ -4216,6 +4238,8 @@ INSTANTIATE_TEST_SUITE_P(
Combine(Values("SubgroupLocalInvocationId", "SubgroupSize"), Combine(Values("SubgroupLocalInvocationId", "SubgroupSize"),
Values("GLCompute"), Values("Output", "Workgroup", "Private"), Values("GLCompute"), Values("Output", "Workgroup", "Private"),
Values("%u32"), Values("%u32"),
Values("VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-"
"04380 VUID-SubgroupSize-SubgroupSize-04382"),
Values(TestResult( Values(TestResult(
SPV_ERROR_INVALID_DATA, SPV_ERROR_INVALID_DATA,
"to be only used for variables with Input storage class")))); "to be only used for variables with Input storage class"))));
@ -4224,7 +4248,7 @@ INSTANTIATE_TEST_SUITE_P(
SubgroupInvocationIdAndSizeOk, ValidateVulkanSubgroupBuiltIns, SubgroupInvocationIdAndSizeOk, ValidateVulkanSubgroupBuiltIns,
Combine(Values("SubgroupLocalInvocationId", "SubgroupSize"), Combine(Values("SubgroupLocalInvocationId", "SubgroupSize"),
Values("GLCompute"), Values("Input"), Values("%u32"), Values("GLCompute"), Values("Input"), Values("%u32"),
Values(TestResult(SPV_SUCCESS, "")))); Values(nullptr), Values(TestResult(SPV_SUCCESS, ""))));
TEST_F(ValidateBuiltIns, SubgroupSizeMemberDecorate) { TEST_F(ValidateBuiltIns, SubgroupSizeMemberDecorate) {
const std::string text = R"( const std::string text = R"(
@ -4251,10 +4275,22 @@ OpFunctionEnd
HasSubstr("BuiltIn SubgroupSize cannot be used as a member decoration")); HasSubstr("BuiltIn SubgroupSize cannot be used as a member decoration"));
} }
INSTANTIATE_TEST_SUITE_P(
SubgroupNumAndIdNotCompute, ValidateVulkanSubgroupBuiltIns,
Combine(
Values("SubgroupId", "NumSubgroups"), Values("Vertex"), Values("Input"),
Values("%u32"),
Values("VUID-SubgroupId-SubgroupId-04367 "
"VUID-NumSubgroups-NumSubgroups-04293"),
Values(TestResult(SPV_ERROR_INVALID_DATA,
"to be used only with GLCompute execution model"))));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
SubgroupNumAndIdNotU32, ValidateVulkanSubgroupBuiltIns, SubgroupNumAndIdNotU32, ValidateVulkanSubgroupBuiltIns,
Combine(Values("SubgroupId", "NumSubgroups"), Values("GLCompute"), Combine(Values("SubgroupId", "NumSubgroups"), Values("GLCompute"),
Values("Input"), Values("%f32"), Values("Input"), Values("%f32"),
Values("VUID-SubgroupId-SubgroupId-04369 "
"VUID-NumSubgroups-NumSubgroups-04295"),
Values(TestResult(SPV_ERROR_INVALID_DATA, Values(TestResult(SPV_ERROR_INVALID_DATA,
"needs to be a 32-bit int")))); "needs to be a 32-bit int"))));
@ -4262,6 +4298,8 @@ INSTANTIATE_TEST_SUITE_P(
SubgroupNumAndIdNotInput, ValidateVulkanSubgroupBuiltIns, SubgroupNumAndIdNotInput, ValidateVulkanSubgroupBuiltIns,
Combine(Values("SubgroupId", "NumSubgroups"), Values("GLCompute"), Combine(Values("SubgroupId", "NumSubgroups"), Values("GLCompute"),
Values("Output", "Workgroup", "Private"), Values("%u32"), Values("Output", "Workgroup", "Private"), Values("%u32"),
Values("VUID-SubgroupId-SubgroupId-04368 "
"VUID-NumSubgroups-NumSubgroups-04294"),
Values(TestResult( Values(TestResult(
SPV_ERROR_INVALID_DATA, SPV_ERROR_INVALID_DATA,
"to be only used for variables with Input storage class")))); "to be only used for variables with Input storage class"))));
@ -4269,7 +4307,7 @@ INSTANTIATE_TEST_SUITE_P(
INSTANTIATE_TEST_SUITE_P(SubgroupNumAndIdOk, ValidateVulkanSubgroupBuiltIns, INSTANTIATE_TEST_SUITE_P(SubgroupNumAndIdOk, ValidateVulkanSubgroupBuiltIns,
Combine(Values("SubgroupId", "NumSubgroups"), Combine(Values("SubgroupId", "NumSubgroups"),
Values("GLCompute"), Values("Input"), Values("GLCompute"), Values("Input"),
Values("%u32"), Values("%u32"), Values(nullptr),
Values(TestResult(SPV_SUCCESS, "")))); Values(TestResult(SPV_SUCCESS, ""))));
TEST_F(ValidateBuiltIns, SubgroupIdMemberDecorate) { TEST_F(ValidateBuiltIns, SubgroupIdMemberDecorate) {