mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2025-01-11 09:00:06 +00:00
Add whitelist of allowed BuiltIn decorations for WebGPU (#2337)
Part of resolving #2276
This commit is contained in:
parent
d17fcf8abd
commit
3d2afb78c2
@ -101,6 +101,28 @@ 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;
|
||||
}
|
||||
|
||||
// Helper class managing validation of built-ins.
|
||||
// TODO: Generic functionality of this class can be moved into
|
||||
// ValidationState_t to be made available to other users.
|
||||
@ -2548,6 +2570,15 @@ spv_result_t BuiltInsValidator::ValidateWorkgroupSizeAtReference(
|
||||
spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition(
|
||||
const Decoration& decoration, const Instruction& inst) {
|
||||
const SpvBuiltIn label = SpvBuiltIn(decoration.params()[0]);
|
||||
|
||||
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.
|
||||
|
@ -1790,6 +1790,16 @@ INSTANTIATE_TEST_CASE_P(
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"needs to be a 32-bit int", "is not an int"))), );
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
WhitelistRejection,
|
||||
ValidateWebGPUCombineBuiltInExecutionModelDataTypeResult,
|
||||
Combine(Values("PointSize", "ClipDistance", "CullDistance", "VertexId",
|
||||
"InstanceId", "PointCoord", "SampleMask", "HelperInvocation",
|
||||
"WorkgroupId"),
|
||||
Values("Vertex"), Values("Input"), Values("%u32"),
|
||||
Values(TestResult(SPV_ERROR_INVALID_DATA,
|
||||
"WebGPU does not allow BuiltIn"))), );
|
||||
|
||||
CodeGenerator GetArrayedVariableCodeGenerator(spv_target_env env,
|
||||
const char* const built_in,
|
||||
const char* const execution_model,
|
||||
|
Loading…
Reference in New Issue
Block a user