diff options
author | Ryan Harrison <zoddicus@users.noreply.github.com> | 2018-11-27 16:20:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-27 16:20:01 -0500 |
commit | 4759082bbc068643acaafa04a747bcd16a1d628b (patch) | |
tree | 0dc55ed8ac3cc3ec7df343e6afd1ae25df117aeb /source/val/validate_extensions.cpp | |
parent | dab634da93d39763bc5b526de9d25104a3bd3b65 (diff) | |
download | SPIRV-Tools-4759082bbc068643acaafa04a747bcd16a1d628b.tar.gz |
Ensure that imported extended instructions for WebGPU are only "GLSL.std.450" (#2119)
Ensure that imported extended instructions for WebGPU are GLSL.std.450
Fixes #2059
Diffstat (limited to 'source/val/validate_extensions.cpp')
-rw-r--r-- | source/val/validate_extensions.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/val/validate_extensions.cpp b/source/val/validate_extensions.cpp new file mode 100644 index 00000000..f3b2305b --- /dev/null +++ b/source/val/validate_extensions.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2018 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Validates correctness of extension SPIR-V instructions. + +#include "source/val/validate.h" + +#include <string> +#include <vector> + +#include "source/diagnostic.h" +#include "source/opcode.h" +#include "source/spirv_target_env.h" +#include "source/val/instruction.h" +#include "source/val/validation_state.h" + +namespace spvtools { +namespace val { + +spv_result_t ValidateExtInstImport(ValidationState_t& _, + const Instruction* inst) { + if (spvIsWebGPUEnv(_.context()->target_env)) { + const auto name_id = 1; + const std::string name(reinterpret_cast<const char*>( + inst->words().data() + inst->operands()[name_id].offset)); + if (name != "GLSL.std.450") { + return _.diag(SPV_ERROR_INVALID_DATA, inst) + << "For WebGPU, the only valid parameter to OpExtInstImport is " + "\"GLSL.std.450\"."; + } + } + + return SPV_SUCCESS; +} + +spv_result_t ExtensionPass(ValidationState_t& _, const Instruction* inst) { + const SpvOp opcode = inst->opcode(); + if (opcode == SpvOpExtInstImport) return ValidateExtInstImport(_, inst); + + return SPV_SUCCESS; +} + +} // namespace val +} // namespace spvtools |