Refactor out query for operation type/result IDs.

This commit is contained in:
Hans-Kristian Arntzen 2022-05-02 15:27:09 +02:00
parent 7a6c2da9aa
commit 7eb5ced2a0
4 changed files with 21 additions and 41 deletions

View File

@ -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 <functional>

View File

@ -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 <result-type> <result-id> <arguments>.
// 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<SPIRType>(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

View File

@ -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"

View File

@ -21,7 +21,6 @@
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
*/
#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())