From 7eb5ced2a0819534a2efd79ae0fa591e66898336 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 2 May 2022 15:27:09 +0200 Subject: [PATCH] Refactor out query for operation type/result IDs. --- spirv_common.hpp | 4 ++++ spirv_cross.cpp | 48 ++++++++++++------------------------------------ spirv_cross.hpp | 3 +++ spirv_glsl.cpp | 7 ++----- 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/spirv_common.hpp b/spirv_common.hpp index 60ef25e3..1c8a7253 100644 --- a/spirv_common.hpp +++ b/spirv_common.hpp @@ -24,7 +24,11 @@ #ifndef SPIRV_CROSS_COMMON_HPP #define SPIRV_CROSS_COMMON_HPP +#ifndef SPV_ENABLE_UTILITY_CODE +#define SPV_ENABLE_UTILITY_CODE +#endif #include "spirv.hpp" + #include "spirv_cross_containers.hpp" #include "spirv_cross_error_handling.hpp" #include diff --git a/spirv_cross.cpp b/spirv_cross.cpp index a68ef757..0617a149 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -4710,46 +4710,22 @@ bool Compiler::reflection_ssbo_instance_name_is_significant() const return aliased_ssbo_types; } -bool Compiler::instruction_to_result_type(uint32_t &result_type, uint32_t &result_id, spv::Op op, const uint32_t *args, - uint32_t length) +bool Compiler::instruction_to_result_type(uint32_t &result_type, uint32_t &result_id, spv::Op op, + const uint32_t *args, uint32_t length) { - // Most instructions follow the pattern of . - // There are some exceptions. - switch (op) - { - case OpStore: - case OpCopyMemory: - case OpCopyMemorySized: - case OpImageWrite: - case OpAtomicStore: - case OpAtomicFlagClear: - case OpEmitStreamVertex: - case OpEndStreamPrimitive: - case OpControlBarrier: - case OpMemoryBarrier: - case OpGroupWaitEvents: - case OpRetainEvent: - case OpReleaseEvent: - case OpSetUserEventStatus: - case OpCaptureEventProfilingInfo: - case OpCommitReadPipe: - case OpCommitWritePipe: - case OpGroupCommitReadPipe: - case OpGroupCommitWritePipe: - case OpLine: - case OpNoLine: + if (length < 2) return false; - default: - if (length > 1 && maybe_get(args[0]) != nullptr) - { - result_type = args[0]; - result_id = args[1]; - return true; - } - else - return false; + bool has_result_id = false, has_result_type = false; + HasResultAndType(op, &has_result_id, &has_result_type); + if (has_result_id && has_result_type) + { + result_type = args[0]; + result_id = args[1]; + return true; } + else + return false; } Bitset Compiler::combined_decoration_for_member(const SPIRType &type, uint32_t index) const diff --git a/spirv_cross.hpp b/spirv_cross.hpp index f4599ec8..1d7e7c48 100644 --- a/spirv_cross.hpp +++ b/spirv_cross.hpp @@ -24,6 +24,9 @@ #ifndef SPIRV_CROSS_HPP #define SPIRV_CROSS_HPP +#ifndef SPV_ENABLE_UTILITY_CODE +#define SPV_ENABLE_UTILITY_CODE +#endif #include "spirv.hpp" #include "spirv_cfg.hpp" #include "spirv_cross_parsed_ir.hpp" diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 5b2f7633..9779c394 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -21,7 +21,6 @@ * 2. The MIT License, found at . */ -#define SPV_ENABLE_UTILITY_CODE #include "spirv_glsl.hpp" #include "GLSL.std.450.h" #include "spirv_common.hpp" @@ -10495,10 +10494,8 @@ CompilerGLSL::TemporaryCopy CompilerGLSL::handle_instruction_precision(const Ins forward_relaxed_precision(ops[1], &ops[2], forwarding_length); } - bool has_type_id = false; - bool has_result_id = false; - HasResultAndType(opcode, &has_result_id, &has_type_id); - if (has_result_id && has_type_id) + uint32_t result_type = 0, result_id = 0; + if (instruction_to_result_type(result_type, result_id, opcode, ops, length)) { auto itr = temporary_to_mirror_precision_alias.find(ops[1]); if (itr != temporary_to_mirror_precision_alias.end())