Add WebGPU specific validation for VertexIndex BuiltIn decoration (#2328)

Part of resolving #2276
This commit is contained in:
Ryan Harrison 2019-01-30 12:22:30 -05:00 committed by GitHub
parent 464111eaef
commit b947ecfe79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 7 deletions

View File

@ -2115,13 +2115,15 @@ spv_result_t BuiltInsValidator::ValidateTessLevelAtReference(
spv_result_t BuiltInsValidator::ValidateVertexIndexAtDefinition(
const Decoration& decoration, const Instruction& inst) {
if (spvIsVulkanEnv(_.context()->target_env)) {
if (spvIsVulkanOrWebGPUEnv(_.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 Vulkan spec BuiltIn VertexIndex "
"variable needs to be a 32-bit int scalar. "
<< "According to the "
<< spvLogStringForEnv(_.context()->target_env)
<< " spec BuiltIn VertexIndex variable needs to be a "
"32-bit int scalar. "
<< message;
})) {
return error;
@ -2187,12 +2189,13 @@ spv_result_t BuiltInsValidator::ValidateVertexIndexAtReference(
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 VertexIndex to be only used for "
<< spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn VertexIndex to be only used for "
"variables with Input storage class. "
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst,
referenced_from_inst)
@ -2202,8 +2205,8 @@ spv_result_t BuiltInsValidator::ValidateVertexIndexAtReference(
for (const SpvExecutionModel execution_model : execution_models_) {
if (execution_model != SpvExecutionModelVertex) {
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
<< "Vulkan spec allows BuiltIn VertexIndex to be used only "
"with "
<< spvLogStringForEnv(_.context()->target_env)
<< " spec allows BuiltIn VertexIndex to be used only with "
"Vertex execution model. "
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst,
referenced_from_inst, execution_model);

View File

@ -1544,6 +1544,12 @@ INSTANTIATE_TEST_SUITE_P(
Combine(Values("VertexIndex"), Values("Vertex"), Values("Input"),
Values("%u32"), Values(TestResult())));
INSTANTIATE_TEST_SUITE_P(
VertexIndexSuccess,
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
Combine(Values("VertexIndex"), Values("Vertex"), Values("Input"),
Values("%u32"), Values(TestResult())));
INSTANTIATE_TEST_SUITE_P(
VertexIndexInvalidExecutionModel,
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
@ -1554,6 +1560,14 @@ INSTANTIATE_TEST_SUITE_P(
Values(TestResult(SPV_ERROR_INVALID_DATA,
"to be used only with Vertex execution model"))));
INSTANTIATE_TEST_SUITE_P(
VertexIndexInvalidExecutionModel,
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
Combine(Values("VertexIndex"), Values("Fragment", "GLCompute"),
Values("Input"), Values("%u32"),
Values(TestResult(SPV_ERROR_INVALID_DATA,
"to be used only with Vertex execution model"))));
INSTANTIATE_TEST_SUITE_P(
VertexIndexNotInput,
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
@ -1564,6 +1578,16 @@ INSTANTIATE_TEST_SUITE_P(
"Vulkan spec allows BuiltIn VertexIndex to be only "
"used for variables with Input storage class"))));
INSTANTIATE_TEST_SUITE_P(
VertexIndexNotInput,
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
Combine(
Values("VertexIndex"), Values("Vertex"), Values("Output"),
Values("%u32"),
Values(TestResult(SPV_ERROR_INVALID_DATA,
"WebGPU spec allows BuiltIn VertexIndex to be only "
"used for variables with Input storage class"))));
INSTANTIATE_TEST_SUITE_P(
VertexIndexNotIntScalar,
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
@ -1573,6 +1597,15 @@ INSTANTIATE_TEST_SUITE_P(
"needs to be a 32-bit int scalar",
"is not an int scalar"))));
INSTANTIATE_TEST_SUITE_P(
VertexIndexNotIntScalar,
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
Combine(Values("VertexIndex"), Values("Vertex"), Values("Input"),
Values("%f32", "%u32vec3"),
Values(TestResult(SPV_ERROR_INVALID_DATA,
"needs to be a 32-bit int scalar",
"is not an int scalar"))));
INSTANTIATE_TEST_SUITE_P(
VertexIndexNotInt32,
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,