|
|
@@ -113,28 +113,6 @@ SpvStorageClass GetStorageClass(const Instruction& inst) {
|
|
|
return SpvStorageClassMax;
|
|
|
}
|
|
|
|
|
|
-bool IsBuiltInValidForWebGPU(SpvBuiltIn label) {
|
|
|
- switch (label) {
|
|
|
- case SpvBuiltInPosition:
|
|
|
- case SpvBuiltInVertexIndex:
|
|
|
- case SpvBuiltInInstanceIndex:
|
|
|
- case SpvBuiltInFrontFacing:
|
|
|
- case SpvBuiltInFragCoord:
|
|
|
- case SpvBuiltInFragDepth:
|
|
|
- case SpvBuiltInNumWorkgroups:
|
|
|
- case SpvBuiltInWorkgroupSize:
|
|
|
- case SpvBuiltInLocalInvocationId:
|
|
|
- case SpvBuiltInGlobalInvocationId:
|
|
|
- case SpvBuiltInLocalInvocationIndex: {
|
|
|
- return true;
|
|
|
- }
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
typedef enum VUIDError_ {
|
|
|
VUIDErrorExecutionModel = 0,
|
|
|
VUIDErrorStorageClass = 1,
|
|
|
@@ -1260,7 +1238,7 @@ spv_result_t BuiltInsValidator::ValidateClipOrCullDistanceAtReference(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateFragCoordAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
if (spv_result_t error = ValidateF32Vec(
|
|
|
decoration, inst, 4,
|
|
|
[this, &inst](const std::string& message) -> spv_result_t {
|
|
|
@@ -1284,7 +1262,7 @@ spv_result_t BuiltInsValidator::ValidateFragCoordAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
if (storage_class != SpvStorageClassMax &&
|
|
|
storage_class != SpvStorageClassInput) {
|
|
|
@@ -1322,7 +1300,7 @@ spv_result_t BuiltInsValidator::ValidateFragCoordAtReference(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateFragDepthAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
if (spv_result_t error = ValidateF32(
|
|
|
decoration, inst,
|
|
|
[this, &inst](const std::string& message) -> spv_result_t {
|
|
|
@@ -1345,7 +1323,7 @@ spv_result_t BuiltInsValidator::ValidateFragDepthAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
if (storage_class != SpvStorageClassMax &&
|
|
|
storage_class != SpvStorageClassOutput) {
|
|
|
@@ -1398,7 +1376,7 @@ spv_result_t BuiltInsValidator::ValidateFragDepthAtReference(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateFrontFacingAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
if (spv_result_t error = ValidateBool(
|
|
|
decoration, inst,
|
|
|
[this, &inst](const std::string& message) -> spv_result_t {
|
|
|
@@ -1421,7 +1399,7 @@ spv_result_t BuiltInsValidator::ValidateFrontFacingAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
if (storage_class != SpvStorageClassMax &&
|
|
|
storage_class != SpvStorageClassInput) {
|
|
|
@@ -1579,7 +1557,7 @@ spv_result_t BuiltInsValidator::ValidateInvocationIdAtReference(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateInstanceIndexAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
if (spv_result_t error = ValidateI32(
|
|
|
decoration, inst,
|
|
|
[this, &inst](const std::string& message) -> spv_result_t {
|
|
|
@@ -1602,7 +1580,7 @@ spv_result_t BuiltInsValidator::ValidateInstanceIndexAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
if (storage_class != SpvStorageClassMax &&
|
|
|
storage_class != SpvStorageClassInput) {
|
|
|
@@ -1992,46 +1970,6 @@ spv_result_t BuiltInsValidator::ValidatePositionAtReference(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (spvIsWebGPUEnv(_.context()->target_env)) {
|
|
|
- const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
- if (storage_class != SpvStorageClassMax &&
|
|
|
- storage_class != SpvStorageClassOutput) {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
- << "WebGPU spec allows BuiltIn Position to be only used for "
|
|
|
- "variables with Output storage class. "
|
|
|
- << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
|
|
- referenced_from_inst)
|
|
|
- << " " << GetStorageClassDesc(referenced_from_inst);
|
|
|
- }
|
|
|
-
|
|
|
- for (const SpvExecutionModel execution_model : execution_models_) {
|
|
|
- switch (execution_model) {
|
|
|
- case SpvExecutionModelVertex: {
|
|
|
- if (spv_result_t error = ValidateF32Vec(
|
|
|
- decoration, built_in_inst, 4,
|
|
|
- [this, &referenced_from_inst](
|
|
|
- const std::string& message) -> spv_result_t {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
- << "According to the WebGPU spec BuiltIn Position "
|
|
|
- "variable needs to be a 4-component 32-bit float "
|
|
|
- "vector. "
|
|
|
- << message;
|
|
|
- })) {
|
|
|
- return error;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- default: {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
- << "WebGPU spec allows BuiltIn Position to be used only "
|
|
|
- "with the Vertex execution model. "
|
|
|
- << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
|
|
- referenced_from_inst, execution_model);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if (function_id_ == 0) {
|
|
|
// Propagate this rule to all dependant ids in the global scope.
|
|
|
id_to_at_reference_checks_[referenced_from_inst.id()].push_back(std::bind(
|
|
|
@@ -2547,7 +2485,7 @@ spv_result_t BuiltInsValidator::ValidateTessLevelAtReference(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateVertexIndexAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
if (spv_result_t error = ValidateI32(
|
|
|
decoration, inst,
|
|
|
[this, &inst](const std::string& message) -> spv_result_t {
|
|
|
@@ -2580,51 +2518,14 @@ spv_result_t BuiltInsValidator::ValidateVertexIdAtDefinition(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateLocalInvocationIndexAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsWebGPUEnv(_.context()->target_env)) {
|
|
|
- if (spv_result_t error = ValidateI32(
|
|
|
- decoration, inst,
|
|
|
- [this, &inst](const std::string& message) -> spv_result_t {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &inst)
|
|
|
- << "According to the WebGPU spec BuiltIn "
|
|
|
- "LocalInvocationIndex variable needs to be a 32-bit "
|
|
|
- "int."
|
|
|
- << message;
|
|
|
- })) {
|
|
|
- return error;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// Seed at reference checks with this built-in.
|
|
|
return ValidateLocalInvocationIndexAtReference(decoration, inst, inst, inst);
|
|
|
}
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateLocalInvocationIndexAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
- const Instruction& referenced_inst,
|
|
|
+ const Instruction&,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsWebGPUEnv(_.context()->target_env)) {
|
|
|
- const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
- if (storage_class != SpvStorageClassMax &&
|
|
|
- storage_class != SpvStorageClassInput) {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
- << "WebGPU spec allows BuiltIn LocalInvocationIndex to be only "
|
|
|
- "used for variables with Input storage class. "
|
|
|
- << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
|
|
- referenced_from_inst)
|
|
|
- << " " << GetStorageClassDesc(referenced_from_inst);
|
|
|
- }
|
|
|
-
|
|
|
- for (const SpvExecutionModel execution_model : execution_models_) {
|
|
|
- if (execution_model != SpvExecutionModelGLCompute) {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
- << "WebGPU spec allows BuiltIn VertexIndex to be used only "
|
|
|
- "with GLCompute execution model. "
|
|
|
- << GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
|
|
- referenced_from_inst, execution_model);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if (function_id_ == 0) {
|
|
|
// Propagate this rule to all dependant ids in the global scope.
|
|
|
id_to_at_reference_checks_[referenced_from_inst.id()].push_back(
|
|
|
@@ -2640,7 +2541,7 @@ spv_result_t BuiltInsValidator::ValidateVertexIndexAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
if (storage_class != SpvStorageClassMax &&
|
|
|
storage_class != SpvStorageClassInput) {
|
|
|
@@ -2838,7 +2739,7 @@ spv_result_t BuiltInsValidator::ValidateLayerOrViewportIndexAtReference(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
|
|
|
if (spv_result_t error = ValidateI32Vec(
|
|
|
decoration, inst, 3,
|
|
|
@@ -2867,7 +2768,7 @@ spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
const SpvBuiltIn builtin = SpvBuiltIn(decoration.params()[0]);
|
|
|
const SpvStorageClass storage_class = GetStorageClass(referenced_from_inst);
|
|
|
if (storage_class != SpvStorageClassMax &&
|
|
|
@@ -2887,9 +2788,7 @@ spv_result_t BuiltInsValidator::ValidateComputeShaderI32Vec3InputAtReference(
|
|
|
bool has_vulkan_model = execution_model == SpvExecutionModelGLCompute ||
|
|
|
execution_model == SpvExecutionModelTaskNV ||
|
|
|
execution_model == SpvExecutionModelMeshNV;
|
|
|
- bool has_webgpu_model = execution_model == SpvExecutionModelGLCompute;
|
|
|
- if ((spvIsVulkanEnv(_.context()->target_env) && !has_vulkan_model) ||
|
|
|
- (spvIsWebGPUEnv(_.context()->target_env) && !has_webgpu_model)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env) && !has_vulkan_model) {
|
|
|
uint32_t vuid = GetVUIDForBuiltin(builtin, VUIDErrorExecutionModel);
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
<< _.VkErrorID(vuid)
|
|
|
@@ -3086,7 +2985,7 @@ spv_result_t BuiltInsValidator::ValidateI32Vec4InputAtDefinition(
|
|
|
|
|
|
spv_result_t BuiltInsValidator::ValidateWorkgroupSizeAtDefinition(
|
|
|
const Decoration& decoration, const Instruction& inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
if (spvIsVulkanEnv(_.context()->target_env) &&
|
|
|
!spvOpcodeIsConstant(inst.opcode())) {
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, &inst)
|
|
|
@@ -3118,7 +3017,7 @@ spv_result_t BuiltInsValidator::ValidateWorkgroupSizeAtReference(
|
|
|
const Decoration& decoration, const Instruction& built_in_inst,
|
|
|
const Instruction& referenced_inst,
|
|
|
const Instruction& referenced_from_inst) {
|
|
|
- if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
+ if (spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
for (const SpvExecutionModel execution_model : execution_models_) {
|
|
|
if (execution_model != SpvExecutionModelGLCompute) {
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
|
|
@@ -3768,26 +3667,17 @@ spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition(
|
|
|
<< "BuiltIns can only target variables, structs or constants";
|
|
|
}
|
|
|
|
|
|
- if (!spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
|
|
- // Early return. All currently implemented rules are based on Vulkan or
|
|
|
- // WebGPU spec.
|
|
|
+ if (!spvIsVulkanEnv(_.context()->target_env)) {
|
|
|
+ // Early return. All currently implemented rules are based on Vulkan spec.
|
|
|
//
|
|
|
// TODO: If you are adding validation rules for environments other than
|
|
|
- // Vulkan or WebGPU (or general rules which are not environment
|
|
|
- // independent), then you need to modify or remove this condition. Consider
|
|
|
- // also adding early returns into BuiltIn-specific rules, so that the system
|
|
|
- // doesn't spawn new rules which don't do anything.
|
|
|
+ // Vulkan (or general rules which are not environment independent), then
|
|
|
+ // you need to modify or remove this condition. Consider also adding early
|
|
|
+ // returns into BuiltIn-specific rules, so that the system doesn't spawn new
|
|
|
+ // rules which don't do anything.
|
|
|
return SPV_SUCCESS;
|
|
|
}
|
|
|
|
|
|
- if (spvIsWebGPUEnv(_.context()->target_env) &&
|
|
|
- !IsBuiltInValidForWebGPU(label)) {
|
|
|
- return _.diag(SPV_ERROR_INVALID_DATA, &inst)
|
|
|
- << "WebGPU does not allow BuiltIn "
|
|
|
- << _.grammar().lookupOperandName(SPV_OPERAND_TYPE_BUILT_IN,
|
|
|
- decoration.params()[0]);
|
|
|
- }
|
|
|
-
|
|
|
// If you are adding a new BuiltIn enum, please register it here.
|
|
|
// If the newly added enum has validation rules associated with it
|
|
|
// consider leaving a TODO and/or creating an issue.
|