2014-07-26 19:17:09 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-26 19:17:09 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <cmath>
|
2016-03-17 05:55:55 +01:00
|
|
|
#include <numeric>
|
2016-12-16 07:30:43 +01:00
|
|
|
#include <boost/container/static_vector.hpp>
|
2016-12-17 10:21:16 +01:00
|
|
|
#include <boost/range/algorithm/fill.hpp>
|
2014-12-16 00:32:49 +01:00
|
|
|
#include <nihstro/shader_bytecode.h>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/logging/log.h"
|
2016-12-17 10:21:16 +01:00
|
|
|
#include "common/microprofile.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "common/vector_math.h"
|
2016-03-03 04:16:38 +01:00
|
|
|
#include "video_core/pica_state.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "video_core/pica_types.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/shader/shader.h"
|
2015-09-11 13:20:02 +02:00
|
|
|
#include "video_core/shader/shader_interpreter.h"
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2014-12-16 00:32:49 +01:00
|
|
|
using nihstro::Instruction;
|
2018-03-09 18:54:43 +01:00
|
|
|
using nihstro::OpCode;
|
2014-12-16 00:32:49 +01:00
|
|
|
using nihstro::RegisterType;
|
|
|
|
using nihstro::SourceRegister;
|
|
|
|
using nihstro::SwizzlePattern;
|
|
|
|
|
2014-07-26 19:17:09 +02:00
|
|
|
namespace Pica {
|
|
|
|
|
2015-07-22 01:04:05 +02:00
|
|
|
namespace Shader {
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2016-05-12 10:25:38 +02:00
|
|
|
struct CallStackElement {
|
|
|
|
u32 final_address; // Address upon which we jump to return_address
|
|
|
|
u32 return_address; // Where to jump when leaving scope
|
|
|
|
u8 repeat_counter; // How often to repeat until this call stack element is removed
|
|
|
|
u8 loop_increment; // Which value to add to the loop counter after an iteration
|
|
|
|
// TODO: Should this be a signed value? Does it even matter?
|
|
|
|
u32 loop_address; // The address where we'll return to after each loop iteration
|
|
|
|
};
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
template <bool Debug>
|
2016-12-17 10:21:16 +01:00
|
|
|
static void RunInterpreter(const ShaderSetup& setup, UnitState& state, DebugData<Debug>& debug_data,
|
|
|
|
unsigned offset) {
|
2016-05-12 10:25:38 +02:00
|
|
|
// TODO: Is there a maximal size for this?
|
|
|
|
boost::container::static_vector<CallStackElement, 16> call_stack;
|
2016-05-13 09:38:40 +02:00
|
|
|
u32 program_counter = offset;
|
2016-05-12 10:25:38 +02:00
|
|
|
|
2016-12-17 23:09:02 +01:00
|
|
|
state.conditional_code[0] = false;
|
|
|
|
state.conditional_code[1] = false;
|
|
|
|
|
2016-12-16 08:04:44 +01:00
|
|
|
auto call = [&program_counter, &call_stack](u32 offset, u32 num_instructions, u32 return_offset,
|
|
|
|
u8 repeat_count, u8 loop_increment) {
|
|
|
|
// -1 to make sure when incrementing the PC we end up at the correct offset
|
|
|
|
program_counter = offset - 1;
|
|
|
|
ASSERT(call_stack.size() < call_stack.capacity());
|
|
|
|
call_stack.push_back(
|
|
|
|
{offset + num_instructions, return_offset, repeat_count, loop_increment, offset});
|
|
|
|
};
|
|
|
|
|
2016-12-16 08:47:42 +01:00
|
|
|
auto evaluate_condition = [&state](Instruction::FlowControlType flow_control) {
|
|
|
|
using Op = Instruction::FlowControlType::Op;
|
|
|
|
|
|
|
|
bool result_x = flow_control.refx.Value() == state.conditional_code[0];
|
|
|
|
bool result_y = flow_control.refy.Value() == state.conditional_code[1];
|
|
|
|
|
|
|
|
switch (flow_control.op) {
|
|
|
|
case Op::Or:
|
|
|
|
return result_x || result_y;
|
|
|
|
case Op::And:
|
|
|
|
return result_x && result_y;
|
|
|
|
case Op::JustX:
|
|
|
|
return result_x;
|
|
|
|
case Op::JustY:
|
|
|
|
return result_y;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-17 11:33:43 +01:00
|
|
|
const auto& uniforms = setup.uniforms;
|
|
|
|
const auto& swizzle_data = setup.swizzle_data;
|
|
|
|
const auto& program_code = setup.program_code;
|
2014-12-19 19:58:21 +01:00
|
|
|
|
|
|
|
// Placeholder for invalid inputs
|
|
|
|
static float24 dummy_vec4_float24[4];
|
|
|
|
|
2015-07-12 01:57:59 +02:00
|
|
|
unsigned iteration = 0;
|
|
|
|
bool exit_loop = false;
|
|
|
|
while (!exit_loop) {
|
2016-05-12 10:25:38 +02:00
|
|
|
if (!call_stack.empty()) {
|
|
|
|
auto& top = call_stack.back();
|
|
|
|
if (program_counter == top.final_address) {
|
2014-12-21 03:01:35 +01:00
|
|
|
state.address_registers[2] += top.loop_increment;
|
|
|
|
|
|
|
|
if (top.repeat_counter-- == 0) {
|
2016-05-12 10:25:38 +02:00
|
|
|
program_counter = top.return_address;
|
|
|
|
call_stack.pop_back();
|
2015-02-21 18:52:21 +01:00
|
|
|
} else {
|
2016-05-12 10:25:38 +02:00
|
|
|
program_counter = top.loop_address;
|
2014-12-21 03:01:35 +01:00
|
|
|
}
|
2014-12-13 21:30:13 +01:00
|
|
|
|
|
|
|
// TODO: Is "trying again" accurate to hardware?
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
const Instruction instr = {program_code[program_counter]};
|
|
|
|
const SwizzlePattern swizzle = {swizzle_data[instr.common.operand_desc_id]};
|
2014-12-12 18:31:37 +01:00
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::CUR_INSTR>(debug_data, iteration, program_counter);
|
2015-07-12 01:57:59 +02:00
|
|
|
if (iteration > 0)
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::NEXT_INSTR>(debug_data, iteration - 1, program_counter);
|
2015-07-12 01:57:59 +02:00
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
debug_data.max_offset = std::max<u32>(debug_data.max_offset, 1 + program_counter);
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2014-12-16 00:32:49 +01:00
|
|
|
auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* {
|
|
|
|
switch (source_reg.GetRegisterType()) {
|
|
|
|
case RegisterType::Input:
|
2015-08-15 22:51:32 +02:00
|
|
|
return &state.registers.input[source_reg.GetIndex()].x;
|
2014-12-16 00:32:49 +01:00
|
|
|
|
|
|
|
case RegisterType::Temporary:
|
2015-08-15 22:51:32 +02:00
|
|
|
return &state.registers.temporary[source_reg.GetIndex()].x;
|
2014-12-16 00:32:49 +01:00
|
|
|
|
|
|
|
case RegisterType::FloatUniform:
|
2015-05-14 05:29:27 +02:00
|
|
|
return &uniforms.f[source_reg.GetIndex()].x;
|
2014-12-19 19:58:21 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return dummy_vec4_float24;
|
2014-12-16 00:32:49 +01:00
|
|
|
}
|
|
|
|
};
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
switch (instr.opcode.Value().GetInfo().type) {
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Type::Arithmetic: {
|
|
|
|
const bool is_inverted =
|
|
|
|
(0 != (instr.opcode.Value().GetInfo().subtype & OpCode::Info::SrcInversed));
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
const int address_offset =
|
|
|
|
(instr.common.address_register_index == 0)
|
|
|
|
? 0
|
|
|
|
: state.address_registers[instr.common.address_register_index - 1];
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
const float24* src1_ = LookupSourceRegister(instr.common.GetSrc1(is_inverted) +
|
2016-09-16 08:18:58 +02:00
|
|
|
(is_inverted ? 0 : address_offset));
|
2016-09-18 02:38:01 +02:00
|
|
|
const float24* src2_ = LookupSourceRegister(instr.common.GetSrc2(is_inverted) +
|
2016-09-16 08:18:58 +02:00
|
|
|
(is_inverted ? address_offset : 0));
|
2014-12-12 18:31:37 +01:00
|
|
|
|
2014-12-21 18:34:20 +01:00
|
|
|
const bool negate_src1 = ((bool)swizzle.negate_src1 != false);
|
|
|
|
const bool negate_src2 = ((bool)swizzle.negate_src2 != false);
|
2014-12-12 18:31:37 +01:00
|
|
|
|
|
|
|
float24 src1[4] = {
|
2016-09-16 08:18:58 +02:00
|
|
|
src1_[(int)swizzle.src1_selector_0.Value()],
|
|
|
|
src1_[(int)swizzle.src1_selector_1.Value()],
|
|
|
|
src1_[(int)swizzle.src1_selector_2.Value()],
|
|
|
|
src1_[(int)swizzle.src1_selector_3.Value()],
|
2014-12-12 18:31:37 +01:00
|
|
|
};
|
|
|
|
if (negate_src1) {
|
2016-09-16 08:18:58 +02:00
|
|
|
src1[0] = -src1[0];
|
|
|
|
src1[1] = -src1[1];
|
|
|
|
src1[2] = -src1[2];
|
|
|
|
src1[3] = -src1[3];
|
2014-12-12 18:31:37 +01:00
|
|
|
}
|
|
|
|
float24 src2[4] = {
|
2016-09-16 08:18:58 +02:00
|
|
|
src2_[(int)swizzle.src2_selector_0.Value()],
|
|
|
|
src2_[(int)swizzle.src2_selector_1.Value()],
|
|
|
|
src2_[(int)swizzle.src2_selector_2.Value()],
|
|
|
|
src2_[(int)swizzle.src2_selector_3.Value()],
|
2014-12-12 18:31:37 +01:00
|
|
|
};
|
|
|
|
if (negate_src2) {
|
2016-09-16 08:18:58 +02:00
|
|
|
src2[0] = -src2[0];
|
|
|
|
src2[1] = -src2[1];
|
|
|
|
src2[2] = -src2[2];
|
|
|
|
src2[3] = -src2[3];
|
2014-12-12 18:31:37 +01:00
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
float24* dest =
|
|
|
|
(instr.common.dest.Value() < 0x10)
|
2016-12-17 23:38:03 +01:00
|
|
|
? &state.registers.output[instr.common.dest.Value().GetIndex()][0]
|
2016-09-18 02:38:01 +02:00
|
|
|
: (instr.common.dest.Value() < 0x20)
|
|
|
|
? &state.registers.temporary[instr.common.dest.Value().GetIndex()][0]
|
|
|
|
: dummy_vec4_float24;
|
2014-12-12 18:31:37 +01:00
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
debug_data.max_opdesc_id =
|
|
|
|
std::max<u32>(debug_data.max_opdesc_id, 1 + instr.common.operand_desc_id);
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
switch (instr.opcode.Value().EffectiveOpCode()) {
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::ADD: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = src1[i] + src2[i];
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::MUL: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = src1[i] * src2[i];
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-07 00:37:12 +02:00
|
|
|
case OpCode::Id::FLR:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-05-07 00:37:12 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = float24::FromFloat32(std::floor(src1[i].ToFloat32()));
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-05-07 00:37:12 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::MAX:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2014-12-13 21:22:55 +01:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
2015-08-24 06:46:58 +02:00
|
|
|
// NOTE: Exact form required to match NaN semantics to hardware:
|
|
|
|
// max(0, NaN) -> NaN
|
|
|
|
// max(NaN, 0) -> 0
|
|
|
|
dest[i] = (src1[i] > src2[i]) ? src1[i] : src2[i];
|
2014-12-13 21:22:55 +01:00
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-12-13 21:22:55 +01:00
|
|
|
break;
|
|
|
|
|
2015-05-23 05:13:09 +02:00
|
|
|
case OpCode::Id::MIN:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-05-23 05:13:09 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
2015-08-24 06:46:58 +02:00
|
|
|
// NOTE: Exact form required to match NaN semantics to hardware:
|
|
|
|
// min(0, NaN) -> NaN
|
|
|
|
// min(NaN, 0) -> 0
|
|
|
|
dest[i] = (src1[i] < src2[i]) ? src1[i] : src2[i];
|
2015-05-23 05:13:09 +02:00
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-05-23 05:13:09 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::DP3:
|
|
|
|
case OpCode::Id::DP4:
|
2015-08-21 10:51:41 +02:00
|
|
|
case OpCode::Id::DPH:
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::DPHI: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-08-21 10:51:41 +02:00
|
|
|
|
|
|
|
OpCode::Id opcode = instr.opcode.Value().EffectiveOpCode();
|
|
|
|
if (opcode == OpCode::Id::DPH || opcode == OpCode::Id::DPHI)
|
|
|
|
src1[3] = float24::FromFloat32(1.0f);
|
|
|
|
|
|
|
|
int num_components = (opcode == OpCode::Id::DP3) ? 3 : 4;
|
2016-09-18 02:38:01 +02:00
|
|
|
float24 dot = std::inner_product(src1, src1 + num_components, src2,
|
|
|
|
float24::FromFloat32(0.f));
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2015-07-20 00:01:59 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2014-07-26 19:17:09 +02:00
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = dot;
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reciprocal
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::RCP: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-08-23 15:13:36 +02:00
|
|
|
float24 rcp_res = float24::FromFloat32(1.0f / src1[0].ToFloat32());
|
2014-07-26 19:17:09 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
2015-08-23 15:13:36 +02:00
|
|
|
dest[i] = rcp_res;
|
2014-07-26 19:17:09 +02:00
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reciprocal Square Root
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::RSQ: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-08-23 22:03:07 +02:00
|
|
|
float24 rsq_res = float24::FromFloat32(1.0f / std::sqrt(src1[0].ToFloat32()));
|
2014-07-26 19:17:09 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
2015-08-23 15:13:36 +02:00
|
|
|
dest[i] = rsq_res;
|
2014-07-26 19:17:09 +02:00
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::MOVA: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
2014-12-12 22:50:09 +01:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// TODO: Figure out how the rounding is done on hardware
|
|
|
|
state.address_registers[i] = static_cast<s32>(src1[i].ToFloat32());
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::ADDR_REG_OUT>(debug_data, iteration,
|
2016-09-18 02:38:01 +02:00
|
|
|
state.address_registers);
|
2014-12-12 22:50:09 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::MOV: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = src1[i];
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-19 13:57:01 +02:00
|
|
|
case OpCode::Id::SGE:
|
|
|
|
case OpCode::Id::SGEI:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-08-19 13:57:01 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
dest[i] = (src1[i] >= src2[i]) ? float24::FromFloat32(1.0f)
|
|
|
|
: float24::FromFloat32(0.0f);
|
2015-08-19 13:57:01 +02:00
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-08-19 13:57:01 +02:00
|
|
|
break;
|
|
|
|
|
2015-05-23 05:40:43 +02:00
|
|
|
case OpCode::Id::SLT:
|
|
|
|
case OpCode::Id::SLTI:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-05-23 05:40:43 +02:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
dest[i] = (src1[i] < src2[i]) ? float24::FromFloat32(1.0f)
|
|
|
|
: float24::FromFloat32(0.0f);
|
2015-05-23 05:40:43 +02:00
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-05-23 05:40:43 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::CMP:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
2014-12-12 22:50:09 +01:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
// TODO: Can you restrict to one compare via dest masking?
|
|
|
|
|
|
|
|
auto compare_op = instr.common.compare_op;
|
|
|
|
auto op = (i == 0) ? compare_op.x.Value() : compare_op.y.Value();
|
|
|
|
|
|
|
|
switch (op) {
|
2016-09-18 02:38:01 +02:00
|
|
|
case Instruction::Common::CompareOpType::Equal:
|
|
|
|
state.conditional_code[i] = (src1[i] == src2[i]);
|
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case Instruction::Common::CompareOpType::NotEqual:
|
|
|
|
state.conditional_code[i] = (src1[i] != src2[i]);
|
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case Instruction::Common::CompareOpType::LessThan:
|
|
|
|
state.conditional_code[i] = (src1[i] < src2[i]);
|
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case Instruction::Common::CompareOpType::LessEqual:
|
|
|
|
state.conditional_code[i] = (src1[i] <= src2[i]);
|
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case Instruction::Common::CompareOpType::GreaterThan:
|
|
|
|
state.conditional_code[i] = (src1[i] > src2[i]);
|
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case Instruction::Common::CompareOpType::GreaterEqual:
|
|
|
|
state.conditional_code[i] = (src1[i] >= src2[i]);
|
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
default:
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(HW_GPU, "Unknown compare mode {:x}", static_cast<int>(op));
|
2016-09-18 02:38:01 +02:00
|
|
|
break;
|
2014-12-12 22:50:09 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::CMP_RESULT>(debug_data, iteration, state.conditional_code);
|
2014-12-12 22:50:09 +01:00
|
|
|
break;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::EX2: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-08-16 11:51:21 +02:00
|
|
|
|
|
|
|
// EX2 only takes first component exp2 and writes it to all dest components
|
|
|
|
float24 ex2_res = float24::FromFloat32(std::exp2(src1[0].ToFloat32()));
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = ex2_res;
|
|
|
|
}
|
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-08-16 11:51:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::LG2: {
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-08-16 11:51:21 +02:00
|
|
|
|
|
|
|
// LG2 only takes the first component log2 and writes it to all dest components
|
|
|
|
float24 lg2_res = float24::FromFloat32(std::log2(src1[0].ToFloat32()));
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = lg2_res;
|
|
|
|
}
|
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-08-16 11:51:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-12 18:31:37 +01:00
|
|
|
default:
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(HW_GPU, "Unhandled arithmetic instruction: 0x{:02x} ({}): 0x{:08x}",
|
2018-06-28 23:13:30 +02:00
|
|
|
(int)instr.opcode.Value().EffectiveOpCode(),
|
|
|
|
instr.opcode.Value().GetInfo().name, instr.hex);
|
2015-01-21 02:16:47 +01:00
|
|
|
DEBUG_ASSERT(false);
|
2014-12-12 18:31:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-01-03 13:29:44 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Type::MultiplyAdd: {
|
2015-05-25 20:34:09 +02:00
|
|
|
if ((instr.opcode.Value().EffectiveOpCode() == OpCode::Id::MAD) ||
|
2015-05-06 04:06:46 +02:00
|
|
|
(instr.opcode.Value().EffectiveOpCode() == OpCode::Id::MADI)) {
|
2016-09-18 02:38:01 +02:00
|
|
|
const SwizzlePattern& swizzle = *reinterpret_cast<const SwizzlePattern*>(
|
|
|
|
&swizzle_data[instr.mad.operand_desc_id]);
|
2015-01-03 13:29:44 +01:00
|
|
|
|
2015-05-06 04:06:46 +02:00
|
|
|
bool is_inverted = (instr.opcode.Value().EffectiveOpCode() == OpCode::Id::MADI);
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
const int address_offset =
|
|
|
|
(instr.mad.address_register_index == 0)
|
|
|
|
? 0
|
|
|
|
: state.address_registers[instr.mad.address_register_index - 1];
|
2016-03-09 14:48:45 +01:00
|
|
|
|
2015-05-06 04:06:46 +02:00
|
|
|
const float24* src1_ = LookupSourceRegister(instr.mad.GetSrc1(is_inverted));
|
2016-09-18 02:38:01 +02:00
|
|
|
const float24* src2_ = LookupSourceRegister(instr.mad.GetSrc2(is_inverted) +
|
|
|
|
(!is_inverted * address_offset));
|
|
|
|
const float24* src3_ = LookupSourceRegister(instr.mad.GetSrc3(is_inverted) +
|
|
|
|
(is_inverted * address_offset));
|
2015-01-03 13:29:44 +01:00
|
|
|
|
|
|
|
const bool negate_src1 = ((bool)swizzle.negate_src1 != false);
|
|
|
|
const bool negate_src2 = ((bool)swizzle.negate_src2 != false);
|
|
|
|
const bool negate_src3 = ((bool)swizzle.negate_src3 != false);
|
|
|
|
|
|
|
|
float24 src1[4] = {
|
2016-09-16 08:18:58 +02:00
|
|
|
src1_[(int)swizzle.src1_selector_0.Value()],
|
|
|
|
src1_[(int)swizzle.src1_selector_1.Value()],
|
|
|
|
src1_[(int)swizzle.src1_selector_2.Value()],
|
|
|
|
src1_[(int)swizzle.src1_selector_3.Value()],
|
2015-01-03 13:29:44 +01:00
|
|
|
};
|
|
|
|
if (negate_src1) {
|
2016-09-16 08:18:58 +02:00
|
|
|
src1[0] = -src1[0];
|
|
|
|
src1[1] = -src1[1];
|
|
|
|
src1[2] = -src1[2];
|
|
|
|
src1[3] = -src1[3];
|
2015-01-03 13:29:44 +01:00
|
|
|
}
|
|
|
|
float24 src2[4] = {
|
2016-09-16 08:18:58 +02:00
|
|
|
src2_[(int)swizzle.src2_selector_0.Value()],
|
|
|
|
src2_[(int)swizzle.src2_selector_1.Value()],
|
|
|
|
src2_[(int)swizzle.src2_selector_2.Value()],
|
|
|
|
src2_[(int)swizzle.src2_selector_3.Value()],
|
2015-01-03 13:29:44 +01:00
|
|
|
};
|
|
|
|
if (negate_src2) {
|
2016-09-16 08:18:58 +02:00
|
|
|
src2[0] = -src2[0];
|
|
|
|
src2[1] = -src2[1];
|
|
|
|
src2[2] = -src2[2];
|
|
|
|
src2[3] = -src2[3];
|
2015-01-03 13:29:44 +01:00
|
|
|
}
|
|
|
|
float24 src3[4] = {
|
2016-09-16 08:18:58 +02:00
|
|
|
src3_[(int)swizzle.src3_selector_0.Value()],
|
|
|
|
src3_[(int)swizzle.src3_selector_1.Value()],
|
|
|
|
src3_[(int)swizzle.src3_selector_2.Value()],
|
|
|
|
src3_[(int)swizzle.src3_selector_3.Value()],
|
2015-01-03 13:29:44 +01:00
|
|
|
};
|
|
|
|
if (negate_src3) {
|
2016-09-16 08:18:58 +02:00
|
|
|
src3[0] = -src3[0];
|
|
|
|
src3[1] = -src3[1];
|
|
|
|
src3[2] = -src3[2];
|
|
|
|
src3[3] = -src3[3];
|
2015-01-03 13:29:44 +01:00
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
float24* dest =
|
|
|
|
(instr.mad.dest.Value() < 0x10)
|
2016-12-17 23:38:03 +01:00
|
|
|
? &state.registers.output[instr.mad.dest.Value().GetIndex()][0]
|
2016-09-18 02:38:01 +02:00
|
|
|
: (instr.mad.dest.Value() < 0x20)
|
|
|
|
? &state.registers.temporary[instr.mad.dest.Value().GetIndex()][0]
|
|
|
|
: dummy_vec4_float24;
|
2015-01-03 13:29:44 +01:00
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::SRC1>(debug_data, iteration, src1);
|
|
|
|
Record<DebugDataRecord::SRC2>(debug_data, iteration, src2);
|
|
|
|
Record<DebugDataRecord::SRC3>(debug_data, iteration, src3);
|
|
|
|
Record<DebugDataRecord::DEST_IN>(debug_data, iteration, dest);
|
2015-01-03 13:29:44 +01:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!swizzle.DestComponentEnabled(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dest[i] = src1[i] * src2[i] + src3[i];
|
|
|
|
}
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::DEST_OUT>(debug_data, iteration, dest);
|
2015-01-03 13:29:44 +01:00
|
|
|
} else {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(HW_GPU, "Unhandled multiply-add instruction: 0x{:02x} ({}): 0x{:08x}",
|
2018-06-28 23:13:30 +02:00
|
|
|
(int)instr.opcode.Value().EffectiveOpCode(),
|
|
|
|
instr.opcode.Value().GetInfo().name, instr.hex);
|
2015-01-03 13:29:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
default: {
|
2014-12-12 22:50:09 +01:00
|
|
|
// Handle each instruction on its own
|
2015-03-08 21:52:38 +01:00
|
|
|
switch (instr.opcode.Value()) {
|
|
|
|
case OpCode::Id::END:
|
2014-12-13 21:30:13 +01:00
|
|
|
exit_loop = true;
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::JMPC:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::COND_CMP_IN>(debug_data, iteration, state.conditional_code);
|
2016-12-16 08:47:42 +01:00
|
|
|
if (evaluate_condition(instr.flow_control)) {
|
2016-05-12 10:25:38 +02:00
|
|
|
program_counter = instr.flow_control.dest_offset - 1;
|
2015-01-02 21:40:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::JMPU:
|
2016-09-18 02:38:01 +02:00
|
|
|
Record<DebugDataRecord::COND_BOOL_IN>(
|
2016-12-16 08:57:10 +01:00
|
|
|
debug_data, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
2016-01-25 05:20:39 +01:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
if (uniforms.b[instr.flow_control.bool_uniform_id] ==
|
|
|
|
!(instr.flow_control.num_instructions & 1)) {
|
2016-05-12 10:25:38 +02:00
|
|
|
program_counter = instr.flow_control.dest_offset - 1;
|
2015-01-02 21:40:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::CALL:
|
2016-12-16 08:04:44 +01:00
|
|
|
call(instr.flow_control.dest_offset, instr.flow_control.num_instructions,
|
2016-05-12 10:25:38 +02:00
|
|
|
program_counter + 1, 0, 0);
|
2014-12-13 21:30:13 +01:00
|
|
|
break;
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::CALLU:
|
2016-09-18 02:38:01 +02:00
|
|
|
Record<DebugDataRecord::COND_BOOL_IN>(
|
2016-12-16 08:57:10 +01:00
|
|
|
debug_data, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
2015-05-14 05:29:27 +02:00
|
|
|
if (uniforms.b[instr.flow_control.bool_uniform_id]) {
|
2016-12-16 08:04:44 +01:00
|
|
|
call(instr.flow_control.dest_offset, instr.flow_control.num_instructions,
|
2016-09-18 02:38:01 +02:00
|
|
|
program_counter + 1, 0, 0);
|
2015-01-02 21:40:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::CALLC:
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::COND_CMP_IN>(debug_data, iteration, state.conditional_code);
|
2016-12-16 08:47:42 +01:00
|
|
|
if (evaluate_condition(instr.flow_control)) {
|
2016-12-16 08:04:44 +01:00
|
|
|
call(instr.flow_control.dest_offset, instr.flow_control.num_instructions,
|
2016-09-18 02:38:01 +02:00
|
|
|
program_counter + 1, 0, 0);
|
2015-01-02 21:40:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::NOP:
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-08 21:52:38 +01:00
|
|
|
case OpCode::Id::IFU:
|
2016-09-18 02:38:01 +02:00
|
|
|
Record<DebugDataRecord::COND_BOOL_IN>(
|
2016-12-16 08:57:10 +01:00
|
|
|
debug_data, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
2015-05-14 05:29:27 +02:00
|
|
|
if (uniforms.b[instr.flow_control.bool_uniform_id]) {
|
2016-12-16 08:04:44 +01:00
|
|
|
call(program_counter + 1, instr.flow_control.dest_offset - program_counter - 1,
|
2016-09-18 02:38:01 +02:00
|
|
|
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0,
|
|
|
|
0);
|
2014-12-13 21:30:13 +01:00
|
|
|
} else {
|
2016-12-16 08:04:44 +01:00
|
|
|
call(instr.flow_control.dest_offset, instr.flow_control.num_instructions,
|
2016-09-18 02:38:01 +02:00
|
|
|
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0,
|
|
|
|
0);
|
2014-12-13 21:30:13 +01:00
|
|
|
}
|
|
|
|
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::IFC: {
|
2014-12-12 22:50:09 +01:00
|
|
|
// TODO: Do we need to consider swizzlers here?
|
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::COND_CMP_IN>(debug_data, iteration, state.conditional_code);
|
2016-12-16 08:47:42 +01:00
|
|
|
if (evaluate_condition(instr.flow_control)) {
|
2016-12-16 08:04:44 +01:00
|
|
|
call(program_counter + 1, instr.flow_control.dest_offset - program_counter - 1,
|
2016-09-18 02:38:01 +02:00
|
|
|
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0,
|
|
|
|
0);
|
2014-12-12 22:50:09 +01:00
|
|
|
} else {
|
2016-12-16 08:04:44 +01:00
|
|
|
call(instr.flow_control.dest_offset, instr.flow_control.num_instructions,
|
2016-09-18 02:38:01 +02:00
|
|
|
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0,
|
|
|
|
0);
|
2014-12-12 22:50:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
case OpCode::Id::LOOP: {
|
2015-07-12 01:57:59 +02:00
|
|
|
Math::Vec4<u8> loop_param(uniforms.i[instr.flow_control.int_uniform_id].x,
|
|
|
|
uniforms.i[instr.flow_control.int_uniform_id].y,
|
|
|
|
uniforms.i[instr.flow_control.int_uniform_id].z,
|
|
|
|
uniforms.i[instr.flow_control.int_uniform_id].w);
|
|
|
|
state.address_registers[2] = loop_param.y;
|
2014-12-21 03:01:35 +01:00
|
|
|
|
2016-12-16 08:57:10 +01:00
|
|
|
Record<DebugDataRecord::LOOP_INT_IN>(debug_data, iteration, loop_param);
|
2017-07-27 12:48:27 +02:00
|
|
|
call(program_counter + 1, instr.flow_control.dest_offset - program_counter,
|
2016-09-18 02:38:01 +02:00
|
|
|
instr.flow_control.dest_offset + 1, loop_param.x, loop_param.z);
|
2014-12-21 03:01:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:43:25 +02:00
|
|
|
case OpCode::Id::EMIT: {
|
|
|
|
GSEmitter* emitter = state.emitter_ptr;
|
|
|
|
ASSERT_MSG(emitter, "Execute EMIT on VS");
|
|
|
|
emitter->Emit(state.registers.output);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OpCode::Id::SETEMIT: {
|
|
|
|
GSEmitter* emitter = state.emitter_ptr;
|
|
|
|
ASSERT_MSG(emitter, "Execute SETEMIT on VS");
|
|
|
|
emitter->vertex_id = instr.setemit.vertex_id;
|
|
|
|
emitter->prim_emit = instr.setemit.prim_emit != 0;
|
|
|
|
emitter->winding = instr.setemit.winding != 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-26 19:17:09 +02:00
|
|
|
default:
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(HW_GPU, "Unhandled instruction: 0x{:02x} ({}): 0x{:08x}",
|
2018-06-28 23:13:30 +02:00
|
|
|
(int)instr.opcode.Value().EffectiveOpCode(),
|
|
|
|
instr.opcode.Value().GetInfo().name, instr.hex);
|
2014-07-26 19:17:09 +02:00
|
|
|
break;
|
2014-12-12 18:31:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2014-07-26 19:17:09 +02:00
|
|
|
}
|
2015-01-02 21:40:09 +01:00
|
|
|
}
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2016-05-12 10:25:38 +02:00
|
|
|
++program_counter;
|
2015-07-12 01:57:59 +02:00
|
|
|
++iteration;
|
2014-07-26 19:17:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-18 01:16:02 +01:00
|
|
|
void InterpreterEngine::SetupBatch(ShaderSetup& setup, unsigned int entry_point) {
|
2017-05-08 23:37:38 +02:00
|
|
|
ASSERT(entry_point < MAX_PROGRAM_CODE_LENGTH);
|
2016-12-18 01:16:02 +01:00
|
|
|
setup.engine_data.entry_point = entry_point;
|
|
|
|
}
|
2016-12-17 10:21:16 +01:00
|
|
|
|
|
|
|
MICROPROFILE_DECLARE(GPU_Shader);
|
|
|
|
|
2016-12-18 01:16:02 +01:00
|
|
|
void InterpreterEngine::Run(const ShaderSetup& setup, UnitState& state) const {
|
2016-12-17 10:21:16 +01:00
|
|
|
|
|
|
|
MICROPROFILE_SCOPE(GPU_Shader);
|
|
|
|
|
|
|
|
DebugData<false> dummy_debug_data;
|
2016-12-18 01:16:02 +01:00
|
|
|
RunInterpreter(setup, state, dummy_debug_data, setup.engine_data.entry_point);
|
2016-12-17 10:21:16 +01:00
|
|
|
}
|
|
|
|
|
2016-12-18 01:06:04 +01:00
|
|
|
DebugData<true> InterpreterEngine::ProduceDebugInfo(const ShaderSetup& setup,
|
2016-12-19 01:42:19 +01:00
|
|
|
const AttributeBuffer& input,
|
2017-01-28 22:03:13 +01:00
|
|
|
const ShaderRegs& config) const {
|
2016-12-17 10:21:16 +01:00
|
|
|
UnitState state;
|
|
|
|
DebugData<true> debug_data;
|
|
|
|
|
|
|
|
// Setup input register table
|
|
|
|
boost::fill(state.registers.input, Math::Vec4<float24>::AssignToAll(float24::Zero()));
|
2016-12-19 02:25:03 +01:00
|
|
|
state.LoadInput(config, input);
|
2016-12-18 01:16:02 +01:00
|
|
|
RunInterpreter(setup, state, debug_data, setup.engine_data.entry_point);
|
2016-12-17 10:21:16 +01:00
|
|
|
return debug_data;
|
|
|
|
}
|
2015-07-12 01:57:59 +02:00
|
|
|
|
2018-03-09 18:54:43 +01:00
|
|
|
} // namespace Shader
|
2014-07-26 19:17:09 +02:00
|
|
|
|
2018-03-09 18:54:43 +01:00
|
|
|
} // namespace Pica
|