1 // Copyright (c) 2015-2016 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Performs validation on instructions that appear inside of a SPIR-V block.
16
17 #include <cassert>
18 #include <sstream>
19 #include <string>
20 #include <vector>
21
22 #include "source/enum_set.h"
23 #include "source/enum_string_mapping.h"
24 #include "source/extensions.h"
25 #include "source/opcode.h"
26 #include "source/operand.h"
27 #include "source/spirv_constant.h"
28 #include "source/spirv_target_env.h"
29 #include "source/spirv_validator_options.h"
30 #include "source/util/string_utils.h"
31 #include "source/val/validate.h"
32 #include "source/val/validation_state.h"
33
34 namespace spvtools {
35 namespace val {
36 namespace {
37
ToString(const CapabilitySet & capabilities,const AssemblyGrammar & grammar)38 std::string ToString(const CapabilitySet& capabilities,
39 const AssemblyGrammar& grammar) {
40 std::stringstream ss;
41 for (auto capability : capabilities) {
42 spv_operand_desc desc;
43 if (SPV_SUCCESS == grammar.lookupOperand(SPV_OPERAND_TYPE_CAPABILITY,
44 uint32_t(capability), &desc))
45 ss << desc->name << " ";
46 else
47 ss << uint32_t(capability) << " ";
48 }
49 return ss.str();
50 }
51
52 // Returns capabilities that enable an opcode. An empty result is interpreted
53 // as no prohibition of use of the opcode. If the result is non-empty, then
54 // the opcode may only be used if at least one of the capabilities is specified
55 // by the module.
EnablingCapabilitiesForOp(const ValidationState_t & state,spv::Op opcode)56 CapabilitySet EnablingCapabilitiesForOp(const ValidationState_t& state,
57 spv::Op opcode) {
58 // Exceptions for SPV_AMD_shader_ballot
59 switch (opcode) {
60 // Normally these would require Group capability
61 case spv::Op::OpGroupIAddNonUniformAMD:
62 case spv::Op::OpGroupFAddNonUniformAMD:
63 case spv::Op::OpGroupFMinNonUniformAMD:
64 case spv::Op::OpGroupUMinNonUniformAMD:
65 case spv::Op::OpGroupSMinNonUniformAMD:
66 case spv::Op::OpGroupFMaxNonUniformAMD:
67 case spv::Op::OpGroupUMaxNonUniformAMD:
68 case spv::Op::OpGroupSMaxNonUniformAMD:
69 if (state.HasExtension(kSPV_AMD_shader_ballot)) return CapabilitySet();
70 break;
71 default:
72 break;
73 }
74 // Look it up in the grammar
75 spv_opcode_desc opcode_desc = {};
76 if (SPV_SUCCESS == state.grammar().lookupOpcode(opcode, &opcode_desc)) {
77 return state.grammar().filterCapsAgainstTargetEnv(
78 opcode_desc->capabilities, opcode_desc->numCapabilities);
79 }
80 return CapabilitySet();
81 }
82
83 // Returns SPV_SUCCESS if, for the given operand, the target environment
84 // satsifies minimum version requirements, or if the module declares an
85 // enabling extension for the operand. Otherwise emit a diagnostic and
86 // return an error code.
OperandVersionExtensionCheck(ValidationState_t & _,const Instruction * inst,size_t which_operand,const spv_operand_desc_t & operand_desc,uint32_t word)87 spv_result_t OperandVersionExtensionCheck(
88 ValidationState_t& _, const Instruction* inst, size_t which_operand,
89 const spv_operand_desc_t& operand_desc, uint32_t word) {
90 const uint32_t module_version = _.version();
91 const uint32_t operand_min_version = operand_desc.minVersion;
92 const uint32_t operand_last_version = operand_desc.lastVersion;
93 const bool reserved = operand_min_version == 0xffffffffu;
94 const bool version_satisfied = !reserved &&
95 (operand_min_version <= module_version) &&
96 (module_version <= operand_last_version);
97
98 if (version_satisfied) {
99 return SPV_SUCCESS;
100 }
101
102 if (operand_last_version < module_version) {
103 return _.diag(SPV_ERROR_WRONG_VERSION, inst)
104 << spvtools::utils::CardinalToOrdinal(which_operand)
105 << " operand of " << spvOpcodeString(inst->opcode()) << ": operand "
106 << operand_desc.name << "(" << word << ") requires SPIR-V version "
107 << SPV_SPIRV_VERSION_MAJOR_PART(operand_last_version) << "."
108 << SPV_SPIRV_VERSION_MINOR_PART(operand_last_version)
109 << " or earlier";
110 }
111
112 if (!reserved && operand_desc.numExtensions == 0) {
113 return _.diag(SPV_ERROR_WRONG_VERSION, inst)
114 << spvtools::utils::CardinalToOrdinal(which_operand)
115 << " operand of " << spvOpcodeString(inst->opcode()) << ": operand "
116 << operand_desc.name << "(" << word << ") requires SPIR-V version "
117 << SPV_SPIRV_VERSION_MAJOR_PART(operand_min_version) << "."
118 << SPV_SPIRV_VERSION_MINOR_PART(operand_min_version) << " or later";
119 } else {
120 ExtensionSet required_extensions(operand_desc.numExtensions,
121 operand_desc.extensions);
122 if (!_.HasAnyOfExtensions(required_extensions)) {
123 return _.diag(SPV_ERROR_MISSING_EXTENSION, inst)
124 << spvtools::utils::CardinalToOrdinal(which_operand)
125 << " operand of " << spvOpcodeString(inst->opcode())
126 << ": operand " << operand_desc.name << "(" << word
127 << ") requires one of these extensions: "
128 << ExtensionSetToString(required_extensions);
129 }
130 }
131 return SPV_SUCCESS;
132 }
133
134 // Returns SPV_SUCCESS if the given operand is enabled by capabilities declared
135 // in the module. Otherwise issues an error message and returns
136 // SPV_ERROR_INVALID_CAPABILITY.
CheckRequiredCapabilities(ValidationState_t & state,const Instruction * inst,size_t which_operand,const spv_parsed_operand_t & operand,uint32_t word)137 spv_result_t CheckRequiredCapabilities(ValidationState_t& state,
138 const Instruction* inst,
139 size_t which_operand,
140 const spv_parsed_operand_t& operand,
141 uint32_t word) {
142 // Mere mention of PointSize, ClipDistance, or CullDistance in a Builtin
143 // decoration does not require the associated capability. The use of such
144 // a variable value should trigger the capability requirement, but that's
145 // not implemented yet. This rule is independent of target environment.
146 // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
147 if (operand.type == SPV_OPERAND_TYPE_BUILT_IN) {
148 switch (spv::BuiltIn(word)) {
149 case spv::BuiltIn::PointSize:
150 case spv::BuiltIn::ClipDistance:
151 case spv::BuiltIn::CullDistance:
152 return SPV_SUCCESS;
153 default:
154 break;
155 }
156 } else if (operand.type == SPV_OPERAND_TYPE_FP_ROUNDING_MODE) {
157 // Allow all FP rounding modes if requested
158 if (state.features().free_fp_rounding_mode) {
159 return SPV_SUCCESS;
160 }
161 } else if (operand.type == SPV_OPERAND_TYPE_GROUP_OPERATION &&
162 state.features().group_ops_reduce_and_scans &&
163 (word <= uint32_t(spv::GroupOperation::ExclusiveScan))) {
164 // Allow certain group operations if requested.
165 return SPV_SUCCESS;
166 }
167
168 CapabilitySet enabling_capabilities;
169 spv_operand_desc operand_desc = nullptr;
170 const auto lookup_result =
171 state.grammar().lookupOperand(operand.type, word, &operand_desc);
172 if (lookup_result == SPV_SUCCESS) {
173 // Allow FPRoundingMode decoration if requested.
174 if (operand.type == SPV_OPERAND_TYPE_DECORATION &&
175 spv::Decoration(operand_desc->value) ==
176 spv::Decoration::FPRoundingMode) {
177 if (state.features().free_fp_rounding_mode) return SPV_SUCCESS;
178
179 // Vulkan API requires more capabilities on rounding mode.
180 if (spvIsVulkanEnv(state.context()->target_env)) {
181 enabling_capabilities.insert(
182 spv::Capability::StorageUniformBufferBlock16);
183 enabling_capabilities.insert(spv::Capability::StorageUniform16);
184 enabling_capabilities.insert(spv::Capability::StoragePushConstant16);
185 enabling_capabilities.insert(spv::Capability::StorageInputOutput16);
186 }
187 } else {
188 enabling_capabilities = state.grammar().filterCapsAgainstTargetEnv(
189 operand_desc->capabilities, operand_desc->numCapabilities);
190 }
191
192 // When encountering an OpCapability instruction, the instruction pass
193 // registers a capability with the module *before* checking capabilities.
194 // So in the case of an OpCapability instruction, don't bother checking
195 // enablement by another capability.
196 if (inst->opcode() != spv::Op::OpCapability) {
197 const bool enabled_by_cap =
198 state.HasAnyOfCapabilities(enabling_capabilities);
199 if (!enabling_capabilities.empty() && !enabled_by_cap) {
200 return state.diag(SPV_ERROR_INVALID_CAPABILITY, inst)
201 << "Operand " << which_operand << " of "
202 << spvOpcodeString(inst->opcode())
203 << " requires one of these capabilities: "
204 << ToString(enabling_capabilities, state.grammar());
205 }
206 }
207 return OperandVersionExtensionCheck(state, inst, which_operand,
208 *operand_desc, word);
209 }
210 return SPV_SUCCESS;
211 }
212
213 // Returns SPV_ERROR_INVALID_BINARY and emits a diagnostic if the instruction
214 // is explicitly reserved in the SPIR-V core spec. Otherwise return
215 // SPV_SUCCESS.
ReservedCheck(ValidationState_t & _,const Instruction * inst)216 spv_result_t ReservedCheck(ValidationState_t& _, const Instruction* inst) {
217 const spv::Op opcode = inst->opcode();
218 switch (opcode) {
219 // These instructions are enabled by a capability, but should never
220 // be used anyway.
221 case spv::Op::OpImageSparseSampleProjImplicitLod:
222 case spv::Op::OpImageSparseSampleProjExplicitLod:
223 case spv::Op::OpImageSparseSampleProjDrefImplicitLod:
224 case spv::Op::OpImageSparseSampleProjDrefExplicitLod: {
225 spv_opcode_desc inst_desc;
226 _.grammar().lookupOpcode(opcode, &inst_desc);
227 return _.diag(SPV_ERROR_INVALID_BINARY, inst)
228 << "Invalid Opcode name 'Op" << inst_desc->name << "'";
229 }
230 default:
231 break;
232 }
233 return SPV_SUCCESS;
234 }
235
236 // Returns SPV_ERROR_INVALID_CAPABILITY and emits a diagnostic if the
237 // instruction is invalid because the required capability isn't declared
238 // in the module.
CapabilityCheck(ValidationState_t & _,const Instruction * inst)239 spv_result_t CapabilityCheck(ValidationState_t& _, const Instruction* inst) {
240 const spv::Op opcode = inst->opcode();
241 CapabilitySet opcode_caps = EnablingCapabilitiesForOp(_, opcode);
242 if (!_.HasAnyOfCapabilities(opcode_caps)) {
243 return _.diag(SPV_ERROR_INVALID_CAPABILITY, inst)
244 << "Opcode " << spvOpcodeString(opcode)
245 << " requires one of these capabilities: "
246 << ToString(opcode_caps, _.grammar());
247 }
248 for (size_t i = 0; i < inst->operands().size(); ++i) {
249 const auto& operand = inst->operand(i);
250 const auto word = inst->word(operand.offset);
251 if (spvOperandIsConcreteMask(operand.type)) {
252 // Check for required capabilities for each bit position of the mask.
253 for (uint32_t mask_bit = 0x80000000; mask_bit; mask_bit >>= 1) {
254 if (word & mask_bit) {
255 spv_result_t status =
256 CheckRequiredCapabilities(_, inst, i + 1, operand, mask_bit);
257 if (status != SPV_SUCCESS) return status;
258 }
259 }
260 } else if (spvIsIdType(operand.type)) {
261 // TODO(dneto): Check the value referenced by this Id, if we can compute
262 // it. For now, just punt, to fix issue 248:
263 // https://github.com/KhronosGroup/SPIRV-Tools/issues/248
264 } else {
265 // Check the operand word as a whole.
266 spv_result_t status =
267 CheckRequiredCapabilities(_, inst, i + 1, operand, word);
268 if (status != SPV_SUCCESS) return status;
269 }
270 }
271 return SPV_SUCCESS;
272 }
273
274 // Checks that the instruction can be used in this target environment's base
275 // version. Assumes that CapabilityCheck has checked direct capability
276 // dependencies for the opcode.
VersionCheck(ValidationState_t & _,const Instruction * inst)277 spv_result_t VersionCheck(ValidationState_t& _, const Instruction* inst) {
278 const auto opcode = inst->opcode();
279 spv_opcode_desc inst_desc;
280 const spv_result_t r = _.grammar().lookupOpcode(opcode, &inst_desc);
281 assert(r == SPV_SUCCESS);
282 (void)r;
283
284 const auto min_version = inst_desc->minVersion;
285 const auto last_version = inst_desc->lastVersion;
286 const auto module_version = _.version();
287
288 if (last_version < module_version) {
289 return _.diag(SPV_ERROR_WRONG_VERSION, inst)
290 << spvOpcodeString(opcode) << " requires SPIR-V version "
291 << SPV_SPIRV_VERSION_MAJOR_PART(last_version) << "."
292 << SPV_SPIRV_VERSION_MINOR_PART(last_version) << " or earlier";
293 }
294
295 // OpTerminateInvocation is special because it is enabled by Shader
296 // capability, but also requires an extension and/or version check.
297 const bool capability_check_is_sufficient =
298 inst->opcode() != spv::Op::OpTerminateInvocation;
299
300 if (capability_check_is_sufficient && (inst_desc->numCapabilities > 0u)) {
301 // We already checked that the direct capability dependency has been
302 // satisfied. We don't need to check any further.
303 return SPV_SUCCESS;
304 }
305
306 ExtensionSet exts(inst_desc->numExtensions, inst_desc->extensions);
307 if (exts.empty()) {
308 // If no extensions can enable this instruction, then emit error
309 // messages only concerning core SPIR-V versions if errors happen.
310 if (min_version == ~0u) {
311 return _.diag(SPV_ERROR_WRONG_VERSION, inst)
312 << spvOpcodeString(opcode) << " is reserved for future use.";
313 }
314
315 if (module_version < min_version) {
316 return _.diag(SPV_ERROR_WRONG_VERSION, inst)
317 << spvOpcodeString(opcode) << " requires SPIR-V version "
318 << SPV_SPIRV_VERSION_MAJOR_PART(min_version) << "."
319 << SPV_SPIRV_VERSION_MINOR_PART(min_version) << " at minimum.";
320 }
321 } else if (!_.HasAnyOfExtensions(exts)) {
322 // Otherwise, we only error out when no enabling extensions are
323 // registered.
324 if (min_version == ~0u) {
325 return _.diag(SPV_ERROR_MISSING_EXTENSION, inst)
326 << spvOpcodeString(opcode)
327 << " requires one of the following extensions: "
328 << ExtensionSetToString(exts);
329 }
330
331 if (module_version < min_version) {
332 return _.diag(SPV_ERROR_WRONG_VERSION, inst)
333 << spvOpcodeString(opcode) << " requires SPIR-V version "
334 << SPV_SPIRV_VERSION_MAJOR_PART(min_version) << "."
335 << SPV_SPIRV_VERSION_MINOR_PART(min_version)
336 << " at minimum or one of the following extensions: "
337 << ExtensionSetToString(exts);
338 }
339 }
340
341 return SPV_SUCCESS;
342 }
343
344 // Checks that the Resuld <id> is within the valid bound.
LimitCheckIdBound(ValidationState_t & _,const Instruction * inst)345 spv_result_t LimitCheckIdBound(ValidationState_t& _, const Instruction* inst) {
346 if (inst->id() >= _.getIdBound()) {
347 return _.diag(SPV_ERROR_INVALID_BINARY, inst)
348 << "Result <id> '" << inst->id()
349 << "' must be less than the ID bound '" << _.getIdBound() << "'.";
350 }
351 return SPV_SUCCESS;
352 }
353
354 // Checks that the number of OpTypeStruct members is within the limit.
LimitCheckStruct(ValidationState_t & _,const Instruction * inst)355 spv_result_t LimitCheckStruct(ValidationState_t& _, const Instruction* inst) {
356 if (spv::Op::OpTypeStruct != inst->opcode()) {
357 return SPV_SUCCESS;
358 }
359
360 // Number of members is the number of operands of the instruction minus 1.
361 // One operand is the result ID.
362 const uint16_t limit =
363 static_cast<uint16_t>(_.options()->universal_limits_.max_struct_members);
364 if (inst->operands().size() - 1 > limit) {
365 return _.diag(SPV_ERROR_INVALID_BINARY, inst)
366 << "Number of OpTypeStruct members (" << inst->operands().size() - 1
367 << ") has exceeded the limit (" << limit << ").";
368 }
369
370 // Section 2.17 of SPIRV Spec specifies that the "Structure Nesting Depth"
371 // must be less than or equal to 255.
372 // This is interpreted as structures including other structures as
373 // members. The code does not follow pointers or look into arrays to see
374 // if we reach a structure downstream. The nesting depth of a struct is
375 // 1+(largest depth of any member). Scalars are at depth 0.
376 uint32_t max_member_depth = 0;
377 // Struct members start at word 2 of OpTypeStruct instruction.
378 for (size_t word_i = 2; word_i < inst->words().size(); ++word_i) {
379 auto member = inst->word(word_i);
380 auto memberTypeInstr = _.FindDef(member);
381 if (memberTypeInstr && spv::Op::OpTypeStruct == memberTypeInstr->opcode()) {
382 max_member_depth = std::max(
383 max_member_depth, _.struct_nesting_depth(memberTypeInstr->id()));
384 }
385 }
386
387 const uint32_t depth_limit = _.options()->universal_limits_.max_struct_depth;
388 const uint32_t cur_depth = 1 + max_member_depth;
389 _.set_struct_nesting_depth(inst->id(), cur_depth);
390 if (cur_depth > depth_limit) {
391 return _.diag(SPV_ERROR_INVALID_BINARY, inst)
392 << "Structure Nesting Depth may not be larger than " << depth_limit
393 << ". Found " << cur_depth << ".";
394 }
395 return SPV_SUCCESS;
396 }
397
398 // Checks that the number of (literal, label) pairs in OpSwitch is within
399 // the limit.
LimitCheckSwitch(ValidationState_t & _,const Instruction * inst)400 spv_result_t LimitCheckSwitch(ValidationState_t& _, const Instruction* inst) {
401 if (spv::Op::OpSwitch == inst->opcode()) {
402 // The instruction syntax is as follows:
403 // OpSwitch <selector ID> <Default ID> literal label literal label ...
404 // literal,label pairs come after the first 2 operands.
405 // It is guaranteed at this point that num_operands is an even number.
406 size_t num_pairs = (inst->operands().size() - 2) / 2;
407 const unsigned int num_pairs_limit =
408 _.options()->universal_limits_.max_switch_branches;
409 if (num_pairs > num_pairs_limit) {
410 return _.diag(SPV_ERROR_INVALID_BINARY, inst)
411 << "Number of (literal, label) pairs in OpSwitch (" << num_pairs
412 << ") exceeds the limit (" << num_pairs_limit << ").";
413 }
414 }
415 return SPV_SUCCESS;
416 }
417
418 // Ensure the number of variables of the given class does not exceed the
419 // limit.
LimitCheckNumVars(ValidationState_t & _,const uint32_t var_id,const spv::StorageClass storage_class)420 spv_result_t LimitCheckNumVars(ValidationState_t& _, const uint32_t var_id,
421 const spv::StorageClass storage_class) {
422 if (spv::StorageClass::Function == storage_class) {
423 _.registerLocalVariable(var_id);
424 const uint32_t num_local_vars_limit =
425 _.options()->universal_limits_.max_local_variables;
426 if (_.num_local_vars() > num_local_vars_limit) {
427 return _.diag(SPV_ERROR_INVALID_BINARY, nullptr)
428 << "Number of local variables ('Function' Storage Class) "
429 "exceeded the valid limit ("
430 << num_local_vars_limit << ").";
431 }
432 } else {
433 _.registerGlobalVariable(var_id);
434 const uint32_t num_global_vars_limit =
435 _.options()->universal_limits_.max_global_variables;
436 if (_.num_global_vars() > num_global_vars_limit) {
437 return _.diag(SPV_ERROR_INVALID_BINARY, nullptr)
438 << "Number of Global Variables (Storage Class other than "
439 "'Function') exceeded the valid limit ("
440 << num_global_vars_limit << ").";
441 }
442 }
443 return SPV_SUCCESS;
444 }
445
446 // Parses OpExtension instruction and logs warnings if unsuccessful.
CheckIfKnownExtension(ValidationState_t & _,const Instruction * inst)447 spv_result_t CheckIfKnownExtension(ValidationState_t& _,
448 const Instruction* inst) {
449 const std::string extension_str = GetExtensionString(&(inst->c_inst()));
450 Extension extension;
451 if (!GetExtensionFromString(extension_str.c_str(), &extension)) {
452 return _.diag(SPV_WARNING, inst)
453 << "Found unrecognized extension " << extension_str;
454 }
455 return SPV_SUCCESS;
456 }
457
458 } // namespace
459
InstructionPass(ValidationState_t & _,const Instruction * inst)460 spv_result_t InstructionPass(ValidationState_t& _, const Instruction* inst) {
461 const spv::Op opcode = inst->opcode();
462 if (opcode == spv::Op::OpExtension) {
463 CheckIfKnownExtension(_, inst);
464 } else if (opcode == spv::Op::OpCapability) {
465 _.RegisterCapability(inst->GetOperandAs<spv::Capability>(0));
466 } else if (opcode == spv::Op::OpMemoryModel) {
467 if (_.has_memory_model_specified()) {
468 return _.diag(SPV_ERROR_INVALID_LAYOUT, inst)
469 << "OpMemoryModel should only be provided once.";
470 }
471 _.set_addressing_model(inst->GetOperandAs<spv::AddressingModel>(0));
472 _.set_memory_model(inst->GetOperandAs<spv::MemoryModel>(1));
473 } else if (opcode == spv::Op::OpExecutionMode ||
474 opcode == spv::Op::OpExecutionModeId) {
475 const uint32_t entry_point = inst->word(1);
476 _.RegisterExecutionModeForEntryPoint(entry_point,
477 spv::ExecutionMode(inst->word(2)));
478 if (inst->GetOperandAs<spv::ExecutionMode>(1) ==
479 spv::ExecutionMode::LocalSize ||
480 inst->GetOperandAs<spv::ExecutionMode>(1) ==
481 spv::ExecutionMode::LocalSizeId) {
482 _.RegisterEntryPointLocalSize(entry_point, inst);
483 }
484 } else if (opcode == spv::Op::OpVariable) {
485 const auto storage_class = inst->GetOperandAs<spv::StorageClass>(2);
486 if (auto error = LimitCheckNumVars(_, inst->id(), storage_class)) {
487 return error;
488 }
489 } else if (opcode == spv::Op::OpSamplerImageAddressingModeNV) {
490 if (!_.HasCapability(spv::Capability::BindlessTextureNV)) {
491 return _.diag(SPV_ERROR_MISSING_EXTENSION, inst)
492 << "OpSamplerImageAddressingModeNV supported only with extension "
493 "SPV_NV_bindless_texture";
494 }
495 uint32_t bitwidth = inst->GetOperandAs<uint32_t>(0);
496 if (_.samplerimage_variable_address_mode() != 0) {
497 return _.diag(SPV_ERROR_INVALID_LAYOUT, inst)
498 << "OpSamplerImageAddressingModeNV should only be provided once";
499 }
500 if (bitwidth != 32 && bitwidth != 64) {
501 return _.diag(SPV_ERROR_INVALID_DATA, inst)
502 << "OpSamplerImageAddressingModeNV bitwidth should be 64 or 32";
503 }
504 _.set_samplerimage_variable_address_mode(bitwidth);
505 }
506
507 if (auto error = ReservedCheck(_, inst)) return error;
508 if (auto error = CapabilityCheck(_, inst)) return error;
509 if (auto error = LimitCheckIdBound(_, inst)) return error;
510 if (auto error = LimitCheckStruct(_, inst)) return error;
511 if (auto error = LimitCheckSwitch(_, inst)) return error;
512 if (auto error = VersionCheck(_, inst)) return error;
513
514 // All instruction checks have passed.
515 return SPV_SUCCESS;
516 }
517
518 } // namespace val
519 } // namespace spvtools
520