diff --git a/src/shader_recompiler/ir/ir_emitter.cpp b/src/shader_recompiler/ir/ir_emitter.cpp index 7830f3c8b..b35ecb64a 100644 --- a/src/shader_recompiler/ir/ir_emitter.cpp +++ b/src/shader_recompiler/ir/ir_emitter.cpp @@ -5,9 +5,11 @@ #include #include #include +#include "common/assert.h" #include "shader_recompiler/exception.h" #include "shader_recompiler/ir/debug_print.h" #include "shader_recompiler/ir/ir_emitter.h" +#include "shader_recompiler/ir/opcodes.h" #include "shader_recompiler/ir/value.h" namespace Shader::IR { @@ -1558,13 +1560,17 @@ void IREmitter::ImageWrite(const Value& handle, const Value& coords, const Value void IREmitter::DebugPrint(std::string_view format, boost::container::small_vector format_args) { - std::array args; + constexpr size_t PRINT_MAX_ARGS = NumArgsOf(IR::Opcode::DebugPrint); + std::array args; + + ASSERT_MSG(format_args.size() < PRINT_MAX_ARGS, "DebugPrint only supports up to {} format args", + PRINT_MAX_ARGS); for (int i = 0; i < format_args.size(); i++) { args[i] = format_args[i]; } - for (int i = format_args.size(); i < 4; i++) { + for (int i = format_args.size(); i < PRINT_MAX_ARGS; i++) { args[i] = Inst(Opcode::Void); } diff --git a/src/shader_recompiler/ir/opcodes.h b/src/shader_recompiler/ir/opcodes.h index 06f1a6117..783984fc9 100644 --- a/src/shader_recompiler/ir/opcodes.h +++ b/src/shader_recompiler/ir/opcodes.h @@ -52,7 +52,7 @@ constexpr Type F64x2{Type::F64x2}; constexpr Type F64x3{Type::F64x3}; constexpr Type F64x4{Type::F64x4}; -constexpr OpcodeMeta META_TABLE[]{ +constexpr OpcodeMeta META_TABLE[] { #define OPCODE(name_token, type_token, ...) \ { \ .name{#name_token}, \ @@ -81,7 +81,7 @@ constexpr u8 NUM_ARGS[]{ } /// Get the number of arguments an opcode accepts -[[nodiscard]] inline size_t NumArgsOf(Opcode op) noexcept { +[[nodiscard]] constexpr inline size_t NumArgsOf(Opcode op) noexcept { return static_cast(Detail::NUM_ARGS[static_cast(op)]); }