2018-12-20 23:09:21 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2019-06-05 03:44:06 +02:00
|
|
|
#include "video_core/shader/node_helper.h"
|
2018-12-20 23:09:21 +01:00
|
|
|
#include "video_core/shader/shader_ir.h"
|
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
|
|
|
using Tegra::Shader::Instruction;
|
|
|
|
using Tegra::Shader::OpCode;
|
2018-12-18 23:54:12 +01:00
|
|
|
using Tegra::Shader::Pred;
|
2018-12-20 23:09:21 +01:00
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
u32 ShaderIR::DecodeHalfSetPredicate(NodeBlock& bb, u32 pc) {
|
2018-12-20 23:09:21 +01:00
|
|
|
const Instruction instr = {program_code[pc]};
|
|
|
|
const auto opcode = OpCode::Decode(instr);
|
|
|
|
|
2019-07-18 14:17:19 +02:00
|
|
|
DEBUG_ASSERT(instr.hsetp2.ftz == 0);
|
2018-12-18 23:54:12 +01:00
|
|
|
|
2019-04-16 00:48:11 +02:00
|
|
|
Node op_a = UnpackHalfFloat(GetRegister(instr.gpr8), instr.hsetp2.type_a);
|
2018-12-18 23:54:12 +01:00
|
|
|
op_a = GetOperandAbsNegHalf(op_a, instr.hsetp2.abs_a, instr.hsetp2.negate_a);
|
|
|
|
|
2019-05-14 22:16:23 +02:00
|
|
|
Tegra::Shader::PredCondition cond{};
|
|
|
|
bool h_and{};
|
|
|
|
Node op_b{};
|
|
|
|
switch (opcode->get().GetId()) {
|
|
|
|
case OpCode::Id::HSETP2_C:
|
|
|
|
cond = instr.hsetp2.cbuf_and_imm.cond;
|
|
|
|
h_and = instr.hsetp2.cbuf_and_imm.h_and;
|
2019-08-04 07:50:55 +02:00
|
|
|
op_b = GetOperandAbsNegHalf(GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset()),
|
2019-05-14 22:16:23 +02:00
|
|
|
instr.hsetp2.cbuf.abs_b, instr.hsetp2.cbuf.negate_b);
|
|
|
|
break;
|
|
|
|
case OpCode::Id::HSETP2_IMM:
|
|
|
|
cond = instr.hsetp2.cbuf_and_imm.cond;
|
|
|
|
h_and = instr.hsetp2.cbuf_and_imm.h_and;
|
|
|
|
op_b = UnpackHalfImmediate(instr, true);
|
|
|
|
break;
|
|
|
|
case OpCode::Id::HSETP2_R:
|
|
|
|
cond = instr.hsetp2.reg.cond;
|
|
|
|
h_and = instr.hsetp2.reg.h_and;
|
|
|
|
op_b =
|
|
|
|
UnpackHalfFloat(GetOperandAbsNegHalf(GetRegister(instr.gpr20), instr.hsetp2.reg.abs_b,
|
|
|
|
instr.hsetp2.reg.negate_b),
|
|
|
|
instr.hsetp2.reg.type_b);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
op_b = Immediate(0);
|
|
|
|
}
|
2018-12-18 23:54:12 +01:00
|
|
|
|
|
|
|
const OperationCode combiner = GetPredicateCombiner(instr.hsetp2.op);
|
2019-07-26 05:12:38 +02:00
|
|
|
const Node combined_pred = GetPredicate(instr.hsetp2.pred3, instr.hsetp2.neg_pred);
|
2018-12-18 23:54:12 +01:00
|
|
|
|
2019-07-20 03:20:34 +02:00
|
|
|
const auto Write = [&](u64 dest, Node src) {
|
2019-07-26 05:12:38 +02:00
|
|
|
SetPredicate(bb, dest, Operation(combiner, std::move(src), combined_pred));
|
2019-07-20 03:20:34 +02:00
|
|
|
};
|
2018-12-18 23:54:12 +01:00
|
|
|
|
2019-07-20 03:20:34 +02:00
|
|
|
const Node comparison = GetPredicateComparisonHalf(cond, op_a, op_b);
|
|
|
|
const u64 first = instr.hsetp2.pred0;
|
2019-07-26 05:12:38 +02:00
|
|
|
const u64 second = instr.hsetp2.pred39;
|
2019-07-20 03:20:34 +02:00
|
|
|
if (h_and) {
|
|
|
|
const Node joined = Operation(OperationCode::LogicalAnd2, comparison);
|
|
|
|
Write(first, joined);
|
|
|
|
Write(second, Operation(OperationCode::LogicalNegate, joined));
|
|
|
|
} else {
|
|
|
|
Write(first, Operation(OperationCode::LogicalPick2, comparison, Immediate(0u)));
|
|
|
|
Write(second, Operation(OperationCode::LogicalPick2, comparison, Immediate(1u)));
|
2018-12-18 23:54:12 +01:00
|
|
|
}
|
2018-12-20 23:09:21 +01:00
|
|
|
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
2019-05-22 23:24:35 +02:00
|
|
|
} // namespace VideoCommon::Shader
|