mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-12-25 17:21:06 +00:00
Add WebGPU specific validation for InstanceIndex BuiltIn decoration (#2329)
Part of resolving #2276
This commit is contained in:
parent
b947ecfe79
commit
734def1447
@ -1233,12 +1233,14 @@ spv_result_t BuiltInsValidator::ValidateInvocationIdAtReference(
|
||||
|
||||
spv_result_t BuiltInsValidator::ValidateInstanceIndexAtDefinition(
|
||||
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 InstanceIndex "
|
||||
<< "According to the "
|
||||
<< spvLogStringForEnv(_.context()->target_env)
|
||||
<< " spec BuiltIn InstanceIndex "
|
||||
"variable needs to be a 32-bit int scalar. "
|
||||
<< message;
|
||||
})) {
|
||||
@ -1254,12 +1256,13 @@ spv_result_t BuiltInsValidator::ValidateInstanceIndexAtReference(
|
||||
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 InstanceIndex to be only used for "
|
||||
<< spvLogStringForEnv(_.context()->target_env)
|
||||
<< " spec allows BuiltIn InstanceIndex to be only used for "
|
||||
"variables with Input storage class. "
|
||||
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
||||
referenced_from_inst)
|
||||
@ -1269,7 +1272,8 @@ spv_result_t BuiltInsValidator::ValidateInstanceIndexAtReference(
|
||||
for (const SpvExecutionModel execution_model : execution_models_) {
|
||||
if (execution_model != SpvExecutionModelVertex) {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, &referenced_from_inst)
|
||||
<< "Vulkan spec allows BuiltIn InstanceIndex to be used only "
|
||||
<< spvLogStringForEnv(_.context()->target_env)
|
||||
<< " spec allows BuiltIn InstanceIndex to be used only "
|
||||
"with Vertex execution model. "
|
||||
<< GetReferenceDesc(decoration, built_in_inst, referenced_inst,
|
||||
referenced_from_inst, execution_model);
|
||||
|
@ -740,6 +740,12 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
Combine(Values("InstanceIndex"), Values("Vertex"), Values("Input"),
|
||||
Values("%u32"), Values(TestResult())));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InstanceIndexSuccess,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("InstanceIndex"), Values("Vertex"), Values("Input"),
|
||||
Values("%u32"), Values(TestResult())));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InstanceIndexInvalidExecutionModel,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
@ -750,6 +756,14 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"to be used only with Vertex execution model"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InstanceIndexInvalidExecutionModel,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("InstanceIndex"), 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(
|
||||
InstanceIndexNotInput,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
@ -760,6 +774,16 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
"to be only used for variables with Input storage class",
|
||||
"uses storage class Output"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InstanceIndexNotInput,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("InstanceIndex"), Values("Vertex"), Values("Output"),
|
||||
Values("%u32"),
|
||||
Values(TestResult(
|
||||
SPV_ERROR_INVALID_DATA,
|
||||
"to be only used for variables with Input storage class",
|
||||
"uses storage class Output"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InstanceIndexNotIntScalar,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
@ -769,6 +793,15 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
"needs to be a 32-bit int scalar",
|
||||
"is not an int scalar"))));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InstanceIndexNotIntScalar,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("InstanceIndex"), 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(
|
||||
InstanceIndexNotInt32,
|
||||
ValidateVulkanCombineBuiltInExecutionModelDataTypeResult,
|
||||
|
Loading…
Reference in New Issue
Block a user