diff options
author | Andrey Tuganov <andreyt@google.com> | 2018-02-06 12:10:11 -0500 |
---|---|---|
committer | David Neto <dneto@google.com> | 2018-02-07 13:31:35 -0500 |
commit | 2f0c3aaa119960a38309598e7b77905d4e38d046 (patch) | |
tree | 9f4cb5154484dc03fe757432144316e0d0dd07c2 /source/val | |
parent | 30138975561d568010e39960401cccd815f55edd (diff) | |
download | spirv-tools-2f0c3aaa119960a38309598e7b77905d4e38d046.tar.gz |
Add Vulkan-specific validation rules for atomics
Added atomic instructions validation rules from
https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#spirvenv-module-validation
Diffstat (limited to 'source/val')
-rw-r--r-- | source/val/validation_state.cpp | 18 | ||||
-rw-r--r-- | source/val/validation_state.h | 5 |
2 files changed, 23 insertions, 0 deletions
diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index b76620ea..ed4cd70f 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -766,4 +766,22 @@ bool ValidationState_t::GetConstantValUint64(uint32_t id, uint64_t* val) const { return true; } +std::tuple<bool, bool, uint32_t> ValidationState_t::EvalInt32IfConst( + uint32_t id) { + const Instruction* const inst = FindDef(id); + assert(inst); + const uint32_t type = inst->type_id(); + + if (!IsIntScalarType(type) || GetBitWidth(type) != 32) { + return std::make_tuple(false, false, 0); + } + + if (inst->opcode() != SpvOpConstant && inst->opcode() != SpvOpSpecConstant) { + return std::make_tuple(true, false, 0); + } + + assert(inst->words().size() == 4); + return std::make_tuple(true, true, inst->word(3)); +} + } // namespace libspirv diff --git a/source/val/validation_state.h b/source/val/validation_state.h index 986d7592..d63ac025 100644 --- a/source/val/validation_state.h +++ b/source/val/validation_state.h @@ -18,6 +18,7 @@ #include <deque> #include <set> #include <string> +#include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> @@ -413,6 +414,10 @@ class ValidationState_t { bool GetPointerTypeInfo(uint32_t id, uint32_t* data_type, uint32_t* storage_class) const; + // Tries to evaluate a 32-bit signed or unsigned scalar integer constant. + // Returns tuple <is_int32, is_const_int32, value>. + std::tuple<bool, bool, uint32_t> EvalInt32IfConst(uint32_t id); + private: ValidationState_t(const ValidationState_t&); |