mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-12-25 17:21:06 +00:00
Add WebGPU specific validation for FragCoord BuiltIn decoration (#2331)
Part of resolving #2276
This commit is contained in:
parent
b6698e0d83
commit
0c14583f15
@ -937,12 +937,14 @@ spv_result_t BuiltInsValidator::ValidateClipOrCullDistanceAtReference(
|
||||
|
||||
spv_result_t BuiltInsValidator::ValidateFragCoordAtDefinition(
|
||||
const Decoration& decoration, const Instruction& inst) {
|
||||
if (spvIsVulkanEnv(_.context()->target_env)) {
|
||||
if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
||||
if (spv_result_t error = ValidateF32Vec(
|
||||
decoration, inst, 4,
|
||||
[this, &inst](const std::string& message) -> spv_result_t {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, &inst)
|
||||
<< "According to the Vulkan spec BuiltIn FragCoord "
|
||||
<< "According to the "
|
||||
<< spvLogStringForEnv(_.context()->target_env)
|
||||
<< " spec BuiltIn FragCoord "
|
||||
"variable needs to be a 4-component 32-bit float "
|
||||
"vector. "
|
||||
<< message;
|
||||
@ -959,12 +961,13 @@ spv_result_t BuiltInsValidator::ValidateFragCoordAtReference(
|
||||
const Decoration& decoration, const Instruction& built_in_inst,
|
||||
const Instruction& referenced_inst,
|
||||
const Instruction& referenced_from_inst) {
|
||||
if (spvIsVulkanEnv(_.context()->target_env)) {
|
||||
if (spvIsVulkanOrWebGPUEnv(_.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)
|
||||
<< "Vulkan spec allows BuiltIn FragCoord to be only used for "
|
||||
<< spvLogStringForEnv(_.context()->target_env)
|
||||
<< " spec allows BuiltIn FragCoord to be only used for "
|
||||
"variables with Input storage class. "
|
||||
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
||||
referenced_from_inst)
|
||||
@ -974,7 +977,8 @@ spv_result_t BuiltInsValidator::ValidateFragCoordAtReference(
|
||||
for (const SpvExecutionModel execution_model : execution_models_) {
|
||||
if (execution_model != SpvExecutionModelFragment) {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
||||
<< "Vulkan spec allows BuiltIn FragCoord to be used only with "
|
||||
<< spvLogStringForEnv(_.context()->target_env)
|
||||
<< " spec allows BuiltIn FragCoord to be used only with "
|
||||
"Fragment execution model. "
|
||||
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
||||
referenced_from_inst, execution_model);
|
||||
|
@ -502,6 +502,11 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
Combine(Values("FragCoord"), Values("Fragment"), Values("Input"),
|
||||
Values("%f32vec4"), Values(TestResult())));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordSuccess, ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("FragCoord"), Values("Fragment"), Values("Input"),
|
||||
Values("%f32vec4"), Values(TestResult())));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotFragment,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
@ -513,6 +518,15 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"to be used only with Fragment execution model"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotFragment,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(
|
||||
Values("FragCoord"), Values("Vertex", "GLCompute"), Values("Input"),
|
||||
Values("%f32vec4"),
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"to be used only with Fragment execution model"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotInput, ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("FragCoord"), Values("Fragment"), Values("Output"),
|
||||
@ -522,6 +536,15 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
"to be only used for variables with Input storage class",
|
||||
"uses storage class Output"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotInput, ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("FragCoord"), Values("Fragment"), Values("Output"),
|
||||
Values("%f32vec4"),
|
||||
Values(TestResult(
|
||||
SPV_ERROR_INVALID_DATA,
|
||||
"to be only used for variables with Input storage class",
|
||||
"uses storage class Output"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotFloatVector,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
@ -531,6 +554,15 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
"needs to be a 4-component 32-bit float vector",
|
||||
"is not a float vector"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotFloatVector,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("FragCoord"), Values("Fragment"), Values("Input"),
|
||||
Values("%f32arr4", "%u32vec4"),
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"needs to be a 4-component 32-bit float vector",
|
||||
"is not a float vector"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotFloatVec4,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
@ -540,6 +572,15 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
"needs to be a 4-component 32-bit float vector",
|
||||
"has 3 components"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotFloatVec4,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("FragCoord"), Values("Fragment"), Values("Input"),
|
||||
Values("%f32vec3"),
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"needs to be a 4-component 32-bit float vector",
|
||||
"has 3 components"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FragCoordNotF32Vec4,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
|
Loading…
Reference in New Issue
Block a user