2018-12-20 22:09:21 +00:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
2018-12-27 19:50:36 +00:00
|
|
|
#include "common/logging/log.h"
|
2018-12-20 22:09:21 +00:00
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2019-06-05 01:44:06 +00:00
|
|
|
#include "video_core/shader/node_helper.h"
|
2018-12-20 22:09:21 +00:00
|
|
|
#include "video_core/shader/shader_ir.h"
|
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
|
|
|
using Tegra::Shader::Attribute;
|
|
|
|
using Tegra::Shader::Instruction;
|
|
|
|
using Tegra::Shader::IpaMode;
|
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
using Tegra::Shader::PredCondition;
|
|
|
|
using Tegra::Shader::PredOperation;
|
|
|
|
using Tegra::Shader::Register;
|
|
|
|
|
2019-06-25 11:57:32 +00:00
|
|
|
ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset, const std::size_t size)
|
2019-06-29 02:59:43 +00:00
|
|
|
: program_code{program_code}, main_offset{main_offset}, program_size{size}, program_manager{} {
|
2019-05-19 08:01:59 +00:00
|
|
|
Decode();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIR::~ShaderIR() = default;
|
|
|
|
|
2018-12-21 01:41:31 +00:00
|
|
|
Node ShaderIR::GetRegister(Register reg) {
|
|
|
|
if (reg != Register::ZeroIndex) {
|
|
|
|
used_registers.insert(static_cast<u32>(reg));
|
|
|
|
}
|
2019-06-05 01:44:06 +00:00
|
|
|
return MakeNode<GprNode>(reg);
|
2018-12-21 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 01:36:17 +00:00
|
|
|
Node ShaderIR::GetImmediate19(Instruction instr) {
|
|
|
|
return Immediate(instr.alu.GetImm20_19());
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetImmediate32(Instruction instr) {
|
|
|
|
return Immediate(instr.alu.GetImm20_32());
|
|
|
|
}
|
|
|
|
|
2018-12-21 01:42:47 +00:00
|
|
|
Node ShaderIR::GetConstBuffer(u64 index_, u64 offset_) {
|
|
|
|
const auto index = static_cast<u32>(index_);
|
|
|
|
const auto offset = static_cast<u32>(offset_);
|
|
|
|
|
|
|
|
const auto [entry, is_new] = used_cbufs.try_emplace(index);
|
|
|
|
entry->second.MarkAsUsed(offset);
|
|
|
|
|
2019-06-05 01:44:06 +00:00
|
|
|
return MakeNode<CbufNode>(index, Immediate(offset));
|
2018-12-21 01:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetConstBufferIndirect(u64 index_, u64 offset_, Node node) {
|
|
|
|
const auto index = static_cast<u32>(index_);
|
|
|
|
const auto offset = static_cast<u32>(offset_);
|
|
|
|
|
|
|
|
const auto [entry, is_new] = used_cbufs.try_emplace(index);
|
|
|
|
entry->second.MarkAsUsedIndirect();
|
|
|
|
|
2019-07-16 14:37:11 +00:00
|
|
|
Node final_offset = [&] {
|
2019-05-31 22:14:34 +00:00
|
|
|
// Attempt to inline constant buffer without a variable offset. This is done to allow
|
|
|
|
// tracking LDC calls.
|
|
|
|
if (const auto gpr = std::get_if<GprNode>(&*node)) {
|
|
|
|
if (gpr->GetIndex() == Register::ZeroIndex) {
|
|
|
|
return Immediate(offset);
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(OperationCode::UAdd, NO_PRECISE, std::move(node), Immediate(offset));
|
2019-05-31 22:14:34 +00:00
|
|
|
}();
|
2019-07-16 14:37:11 +00:00
|
|
|
return MakeNode<CbufNode>(index, std::move(final_offset));
|
2018-12-21 01:42:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 22:09:21 +00:00
|
|
|
Node ShaderIR::GetPredicate(u64 pred_, bool negated) {
|
|
|
|
const auto pred = static_cast<Pred>(pred_);
|
|
|
|
if (pred != Pred::UnusedIndex && pred != Pred::NeverExecute) {
|
|
|
|
used_predicates.insert(pred);
|
|
|
|
}
|
|
|
|
|
2019-06-05 01:44:06 +00:00
|
|
|
return MakeNode<PredicateNode>(pred, negated);
|
2018-12-20 22:09:21 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 01:36:17 +00:00
|
|
|
Node ShaderIR::GetPredicate(bool immediate) {
|
|
|
|
return GetPredicate(static_cast<u64>(immediate ? Pred::UnusedIndex : Pred::NeverExecute));
|
|
|
|
}
|
|
|
|
|
2019-04-30 02:37:09 +00:00
|
|
|
Node ShaderIR::GetInputAttribute(Attribute::Index index, u64 element, Node buffer) {
|
|
|
|
used_input_attributes.emplace(index);
|
2019-07-16 14:37:11 +00:00
|
|
|
return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer));
|
2018-12-21 01:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 21:12:30 +00:00
|
|
|
Node ShaderIR::GetPhysicalInputAttribute(Tegra::Shader::Register physical_address, Node buffer) {
|
2019-04-30 22:46:49 +00:00
|
|
|
uses_physical_attributes = true;
|
2019-06-05 01:44:06 +00:00
|
|
|
return MakeNode<AbufNode>(GetRegister(physical_address), buffer);
|
2018-12-21 01:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetOutputAttribute(Attribute::Index index, u64 element, Node buffer) {
|
2019-07-07 23:36:42 +00:00
|
|
|
if (index == Attribute::Index::LayerViewportPointSize) {
|
|
|
|
switch (element) {
|
|
|
|
case 0:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
uses_layer = true;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
uses_viewport_index = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
uses_point_size = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-15 18:25:07 +00:00
|
|
|
if (index == Attribute::Index::TessCoordInstanceIDVertexID) {
|
|
|
|
switch (element) {
|
|
|
|
case 2:
|
|
|
|
uses_instance_id = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
uses_vertex_id = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 01:45:34 +00:00
|
|
|
if (index == Attribute::Index::ClipDistances0123 ||
|
|
|
|
index == Attribute::Index::ClipDistances4567) {
|
|
|
|
const auto clip_index =
|
|
|
|
static_cast<u32>((index == Attribute::Index::ClipDistances4567 ? 1 : 0) + element);
|
|
|
|
used_clip_distances.at(clip_index) = true;
|
|
|
|
}
|
|
|
|
used_output_attributes.insert(index);
|
|
|
|
|
2019-07-16 14:37:11 +00:00
|
|
|
return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer));
|
2018-12-21 01:45:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 01:49:59 +00:00
|
|
|
Node ShaderIR::GetInternalFlag(InternalFlag flag, bool negated) {
|
2019-06-05 01:44:06 +00:00
|
|
|
const Node node = MakeNode<InternalFlagNode>(flag);
|
2018-12-21 01:49:59 +00:00
|
|
|
if (negated) {
|
|
|
|
return Operation(OperationCode::LogicalNegate, node);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2018-12-21 01:51:38 +00:00
|
|
|
Node ShaderIR::GetLocalMemory(Node address) {
|
2019-07-16 14:37:11 +00:00
|
|
|
return MakeNode<LmemNode>(std::move(address));
|
2018-12-21 01:51:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 03:21:46 +00:00
|
|
|
Node ShaderIR::GetSharedMemory(Node address) {
|
|
|
|
return MakeNode<SmemNode>(std::move(address));
|
|
|
|
}
|
|
|
|
|
2019-07-16 14:31:17 +00:00
|
|
|
Node ShaderIR::GetTemporary(u32 id) {
|
2018-12-27 04:50:22 +00:00
|
|
|
return GetRegister(Register::ZeroIndex + 1 + id);
|
|
|
|
}
|
|
|
|
|
2018-12-21 01:56:08 +00:00
|
|
|
Node ShaderIR::GetOperandAbsNegFloat(Node value, bool absolute, bool negate) {
|
|
|
|
if (absolute) {
|
2019-07-16 14:37:11 +00:00
|
|
|
value = Operation(OperationCode::FAbsolute, NO_PRECISE, std::move(value));
|
2018-12-21 01:56:08 +00:00
|
|
|
}
|
|
|
|
if (negate) {
|
2019-07-16 14:37:11 +00:00
|
|
|
value = Operation(OperationCode::FNegate, NO_PRECISE, std::move(value));
|
2018-12-21 01:56:08 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetSaturatedFloat(Node value, bool saturate) {
|
|
|
|
if (!saturate) {
|
|
|
|
return value;
|
|
|
|
}
|
2019-07-16 14:37:11 +00:00
|
|
|
|
|
|
|
Node positive_zero = Immediate(std::copysignf(0, 1));
|
|
|
|
Node positive_one = Immediate(1.0f);
|
|
|
|
return Operation(OperationCode::FClamp, NO_PRECISE, std::move(value), std::move(positive_zero),
|
|
|
|
std::move(positive_one));
|
2018-12-21 01:56:08 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 14:37:11 +00:00
|
|
|
Node ShaderIR::ConvertIntegerSize(Node value, Register::Size size, bool is_signed) {
|
2018-12-21 01:57:16 +00:00
|
|
|
switch (size) {
|
|
|
|
case Register::Size::Byte:
|
2019-07-16 14:37:11 +00:00
|
|
|
value = SignedOperation(OperationCode::ILogicalShiftLeft, is_signed, NO_PRECISE,
|
|
|
|
std::move(value), Immediate(24));
|
|
|
|
value = SignedOperation(OperationCode::IArithmeticShiftRight, is_signed, NO_PRECISE,
|
|
|
|
std::move(value), Immediate(24));
|
2018-12-21 01:57:16 +00:00
|
|
|
return value;
|
|
|
|
case Register::Size::Short:
|
2019-07-16 14:37:11 +00:00
|
|
|
value = SignedOperation(OperationCode::ILogicalShiftLeft, is_signed, NO_PRECISE,
|
|
|
|
std::move(value), Immediate(16));
|
|
|
|
value = SignedOperation(OperationCode::IArithmeticShiftRight, is_signed, NO_PRECISE,
|
|
|
|
std::move(value), Immediate(16));
|
2018-12-21 01:57:16 +00:00
|
|
|
case Register::Size::Word:
|
|
|
|
// Default - do nothing
|
|
|
|
return value;
|
|
|
|
default:
|
|
|
|
UNREACHABLE_MSG("Unimplemented conversion size: {}", static_cast<u32>(size));
|
2018-12-21 21:47:22 +00:00
|
|
|
return value;
|
2018-12-21 01:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetOperandAbsNegInteger(Node value, bool absolute, bool negate, bool is_signed) {
|
|
|
|
if (!is_signed) {
|
|
|
|
// Absolute or negate on an unsigned is pointless
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
if (absolute) {
|
2019-07-16 14:37:11 +00:00
|
|
|
value = Operation(OperationCode::IAbsolute, NO_PRECISE, std::move(value));
|
2018-12-21 01:57:16 +00:00
|
|
|
}
|
|
|
|
if (negate) {
|
2019-07-16 14:37:11 +00:00
|
|
|
value = Operation(OperationCode::INegate, NO_PRECISE, std::move(value));
|
2018-12-21 01:57:16 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-12-21 01:58:33 +00:00
|
|
|
Node ShaderIR::UnpackHalfImmediate(Instruction instr, bool has_negation) {
|
2019-07-16 14:37:11 +00:00
|
|
|
Node value = Immediate(instr.half_imm.PackImmediates());
|
2018-12-21 01:58:33 +00:00
|
|
|
if (!has_negation) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-07-16 14:37:11 +00:00
|
|
|
Node first_negate = GetPredicate(instr.half_imm.first_negate != 0);
|
|
|
|
Node second_negate = GetPredicate(instr.half_imm.second_negate != 0);
|
|
|
|
|
|
|
|
return Operation(OperationCode::HNegate, NO_PRECISE, std::move(value), std::move(first_negate),
|
|
|
|
std::move(second_negate));
|
2019-04-15 22:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::UnpackHalfFloat(Node value, Tegra::Shader::HalfType type) {
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(OperationCode::HUnpack, type, std::move(value));
|
2018-12-21 01:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::HalfMerge(Node dest, Node src, Tegra::Shader::HalfMerge merge) {
|
|
|
|
switch (merge) {
|
|
|
|
case Tegra::Shader::HalfMerge::H0_H1:
|
|
|
|
return src;
|
|
|
|
case Tegra::Shader::HalfMerge::F32:
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(OperationCode::HMergeF32, std::move(src));
|
2018-12-21 01:58:33 +00:00
|
|
|
case Tegra::Shader::HalfMerge::Mrg_H0:
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(OperationCode::HMergeH0, std::move(dest), std::move(src));
|
2018-12-21 01:58:33 +00:00
|
|
|
case Tegra::Shader::HalfMerge::Mrg_H1:
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(OperationCode::HMergeH1, std::move(dest), std::move(src));
|
2018-12-21 01:58:33 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetOperandAbsNegHalf(Node value, bool absolute, bool negate) {
|
|
|
|
if (absolute) {
|
2019-07-16 14:37:11 +00:00
|
|
|
value = Operation(OperationCode::HAbsolute, NO_PRECISE, std::move(value));
|
2018-12-21 01:58:33 +00:00
|
|
|
}
|
|
|
|
if (negate) {
|
2019-07-16 14:37:11 +00:00
|
|
|
value = Operation(OperationCode::HNegate, NO_PRECISE, std::move(value), GetPredicate(true),
|
2018-12-21 01:58:33 +00:00
|
|
|
GetPredicate(true));
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-04-09 21:41:41 +00:00
|
|
|
Node ShaderIR::GetSaturatedHalfFloat(Node value, bool saturate) {
|
|
|
|
if (!saturate) {
|
|
|
|
return value;
|
|
|
|
}
|
2019-07-16 14:37:11 +00:00
|
|
|
|
|
|
|
Node positive_zero = Immediate(std::copysignf(0, 1));
|
|
|
|
Node positive_one = Immediate(1.0f);
|
|
|
|
return Operation(OperationCode::HClamp, NO_PRECISE, std::move(value), std::move(positive_zero),
|
|
|
|
std::move(positive_one));
|
2019-04-09 21:41:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 02:01:03 +00:00
|
|
|
Node ShaderIR::GetPredicateComparisonFloat(PredCondition condition, Node op_a, Node op_b) {
|
2019-04-09 20:08:07 +00:00
|
|
|
const std::unordered_map<PredCondition, OperationCode> PredicateComparisonTable = {
|
2018-12-21 02:01:03 +00:00
|
|
|
{PredCondition::LessThan, OperationCode::LogicalFLessThan},
|
|
|
|
{PredCondition::Equal, OperationCode::LogicalFEqual},
|
|
|
|
{PredCondition::LessEqual, OperationCode::LogicalFLessEqual},
|
|
|
|
{PredCondition::GreaterThan, OperationCode::LogicalFGreaterThan},
|
|
|
|
{PredCondition::NotEqual, OperationCode::LogicalFNotEqual},
|
|
|
|
{PredCondition::GreaterEqual, OperationCode::LogicalFGreaterEqual},
|
|
|
|
{PredCondition::LessThanWithNan, OperationCode::LogicalFLessThan},
|
|
|
|
{PredCondition::NotEqualWithNan, OperationCode::LogicalFNotEqual},
|
|
|
|
{PredCondition::LessEqualWithNan, OperationCode::LogicalFLessEqual},
|
|
|
|
{PredCondition::GreaterThanWithNan, OperationCode::LogicalFGreaterThan},
|
|
|
|
{PredCondition::GreaterEqualWithNan, OperationCode::LogicalFGreaterEqual}};
|
|
|
|
|
|
|
|
const auto comparison{PredicateComparisonTable.find(condition)};
|
|
|
|
UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonTable.end(),
|
|
|
|
"Unknown predicate comparison operation");
|
|
|
|
|
|
|
|
Node predicate = Operation(comparison->second, NO_PRECISE, op_a, op_b);
|
|
|
|
|
|
|
|
if (condition == PredCondition::LessThanWithNan ||
|
|
|
|
condition == PredCondition::NotEqualWithNan ||
|
|
|
|
condition == PredCondition::LessEqualWithNan ||
|
|
|
|
condition == PredCondition::GreaterThanWithNan ||
|
|
|
|
condition == PredCondition::GreaterEqualWithNan) {
|
|
|
|
predicate = Operation(OperationCode::LogicalOr, predicate,
|
|
|
|
Operation(OperationCode::LogicalFIsNan, op_a));
|
|
|
|
predicate = Operation(OperationCode::LogicalOr, predicate,
|
|
|
|
Operation(OperationCode::LogicalFIsNan, op_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
return predicate;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetPredicateComparisonInteger(PredCondition condition, bool is_signed, Node op_a,
|
|
|
|
Node op_b) {
|
2019-04-09 20:08:07 +00:00
|
|
|
const std::unordered_map<PredCondition, OperationCode> PredicateComparisonTable = {
|
2018-12-21 02:01:03 +00:00
|
|
|
{PredCondition::LessThan, OperationCode::LogicalILessThan},
|
|
|
|
{PredCondition::Equal, OperationCode::LogicalIEqual},
|
|
|
|
{PredCondition::LessEqual, OperationCode::LogicalILessEqual},
|
|
|
|
{PredCondition::GreaterThan, OperationCode::LogicalIGreaterThan},
|
|
|
|
{PredCondition::NotEqual, OperationCode::LogicalINotEqual},
|
|
|
|
{PredCondition::GreaterEqual, OperationCode::LogicalIGreaterEqual},
|
|
|
|
{PredCondition::LessThanWithNan, OperationCode::LogicalILessThan},
|
|
|
|
{PredCondition::NotEqualWithNan, OperationCode::LogicalINotEqual},
|
|
|
|
{PredCondition::LessEqualWithNan, OperationCode::LogicalILessEqual},
|
|
|
|
{PredCondition::GreaterThanWithNan, OperationCode::LogicalIGreaterThan},
|
|
|
|
{PredCondition::GreaterEqualWithNan, OperationCode::LogicalIGreaterEqual}};
|
|
|
|
|
|
|
|
const auto comparison{PredicateComparisonTable.find(condition)};
|
|
|
|
UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonTable.end(),
|
|
|
|
"Unknown predicate comparison operation");
|
|
|
|
|
2019-07-16 14:37:11 +00:00
|
|
|
Node predicate = SignedOperation(comparison->second, is_signed, NO_PRECISE, std::move(op_a),
|
|
|
|
std::move(op_b));
|
2018-12-21 02:01:03 +00:00
|
|
|
|
|
|
|
UNIMPLEMENTED_IF_MSG(condition == PredCondition::LessThanWithNan ||
|
|
|
|
condition == PredCondition::NotEqualWithNan ||
|
|
|
|
condition == PredCondition::LessEqualWithNan ||
|
|
|
|
condition == PredCondition::GreaterThanWithNan ||
|
|
|
|
condition == PredCondition::GreaterEqualWithNan,
|
|
|
|
"NaN comparisons for integers are not implemented");
|
|
|
|
return predicate;
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:48:11 +00:00
|
|
|
Node ShaderIR::GetPredicateComparisonHalf(Tegra::Shader::PredCondition condition, Node op_a,
|
|
|
|
Node op_b) {
|
2019-04-09 20:08:07 +00:00
|
|
|
const std::unordered_map<PredCondition, OperationCode> PredicateComparisonTable = {
|
2018-12-23 23:59:49 +00:00
|
|
|
{PredCondition::LessThan, OperationCode::Logical2HLessThan},
|
|
|
|
{PredCondition::Equal, OperationCode::Logical2HEqual},
|
|
|
|
{PredCondition::LessEqual, OperationCode::Logical2HLessEqual},
|
|
|
|
{PredCondition::GreaterThan, OperationCode::Logical2HGreaterThan},
|
|
|
|
{PredCondition::NotEqual, OperationCode::Logical2HNotEqual},
|
|
|
|
{PredCondition::GreaterEqual, OperationCode::Logical2HGreaterEqual},
|
2019-04-09 20:33:48 +00:00
|
|
|
{PredCondition::LessThanWithNan, OperationCode::Logical2HLessThanWithNan},
|
|
|
|
{PredCondition::NotEqualWithNan, OperationCode::Logical2HNotEqualWithNan},
|
|
|
|
{PredCondition::LessEqualWithNan, OperationCode::Logical2HLessEqualWithNan},
|
|
|
|
{PredCondition::GreaterThanWithNan, OperationCode::Logical2HGreaterThanWithNan},
|
|
|
|
{PredCondition::GreaterEqualWithNan, OperationCode::Logical2HGreaterEqualWithNan}};
|
2018-12-21 02:01:03 +00:00
|
|
|
|
|
|
|
const auto comparison{PredicateComparisonTable.find(condition)};
|
|
|
|
UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonTable.end(),
|
|
|
|
"Unknown predicate comparison operation");
|
|
|
|
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(comparison->second, NO_PRECISE, std::move(op_a), std::move(op_b));
|
2018-12-21 02:01:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 02:40:54 +00:00
|
|
|
OperationCode ShaderIR::GetPredicateCombiner(PredOperation operation) {
|
2019-04-09 20:08:07 +00:00
|
|
|
const std::unordered_map<PredOperation, OperationCode> PredicateOperationTable = {
|
2018-12-21 02:40:54 +00:00
|
|
|
{PredOperation::And, OperationCode::LogicalAnd},
|
|
|
|
{PredOperation::Or, OperationCode::LogicalOr},
|
|
|
|
{PredOperation::Xor, OperationCode::LogicalXor},
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto op = PredicateOperationTable.find(operation);
|
|
|
|
UNIMPLEMENTED_IF_MSG(op == PredicateOperationTable.end(), "Unknown predicate operation");
|
|
|
|
return op->second;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:42:02 +00:00
|
|
|
Node ShaderIR::GetConditionCode(Tegra::Shader::ConditionCode cc) {
|
|
|
|
switch (cc) {
|
|
|
|
case Tegra::Shader::ConditionCode::NEU:
|
|
|
|
return GetInternalFlag(InternalFlag::Zero, true);
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_MSG("Unimplemented condition code: {}", static_cast<u32>(cc));
|
|
|
|
return GetPredicate(static_cast<u64>(Pred::NeverExecute));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 05:09:40 +00:00
|
|
|
void ShaderIR::SetRegister(NodeBlock& bb, Register dest, Node src) {
|
2019-07-16 14:37:11 +00:00
|
|
|
bb.push_back(Operation(OperationCode::Assign, GetRegister(dest), std::move(src)));
|
2018-12-21 01:53:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 05:09:40 +00:00
|
|
|
void ShaderIR::SetPredicate(NodeBlock& bb, u64 dest, Node src) {
|
2019-07-16 14:37:11 +00:00
|
|
|
bb.push_back(Operation(OperationCode::LogicalAssign, GetPredicate(dest), std::move(src)));
|
2018-12-21 01:53:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 05:09:40 +00:00
|
|
|
void ShaderIR::SetInternalFlag(NodeBlock& bb, InternalFlag flag, Node value) {
|
2019-07-16 14:37:11 +00:00
|
|
|
bb.push_back(Operation(OperationCode::LogicalAssign, GetInternalFlag(flag), std::move(value)));
|
2018-12-21 01:53:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 05:09:40 +00:00
|
|
|
void ShaderIR::SetLocalMemory(NodeBlock& bb, Node address, Node value) {
|
2019-07-16 14:37:11 +00:00
|
|
|
bb.push_back(
|
|
|
|
Operation(OperationCode::Assign, GetLocalMemory(std::move(address)), std::move(value)));
|
2018-12-21 01:53:43 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 03:21:46 +00:00
|
|
|
void ShaderIR::SetSharedMemory(NodeBlock& bb, Node address, Node value) {
|
|
|
|
bb.push_back(
|
|
|
|
Operation(OperationCode::Assign, GetSharedMemory(std::move(address)), std::move(value)));
|
|
|
|
}
|
|
|
|
|
2019-07-16 14:31:17 +00:00
|
|
|
void ShaderIR::SetTemporary(NodeBlock& bb, u32 id, Node value) {
|
2019-07-16 14:37:11 +00:00
|
|
|
SetRegister(bb, Register::ZeroIndex + 1 + id, std::move(value));
|
2018-12-27 04:50:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 05:09:40 +00:00
|
|
|
void ShaderIR::SetInternalFlagsFromFloat(NodeBlock& bb, Node value, bool sets_cc) {
|
2018-12-27 19:50:36 +00:00
|
|
|
if (!sets_cc) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-16 14:37:11 +00:00
|
|
|
Node zerop = Operation(OperationCode::LogicalFEqual, std::move(value), Immediate(0.0f));
|
|
|
|
SetInternalFlag(bb, InternalFlag::Zero, std::move(zerop));
|
2018-12-27 19:50:36 +00:00
|
|
|
LOG_WARNING(HW_GPU, "Condition codes implementation is incomplete");
|
|
|
|
}
|
|
|
|
|
2019-01-30 05:09:40 +00:00
|
|
|
void ShaderIR::SetInternalFlagsFromInteger(NodeBlock& bb, Node value, bool sets_cc) {
|
2018-12-27 19:50:36 +00:00
|
|
|
if (!sets_cc) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-16 14:37:11 +00:00
|
|
|
Node zerop = Operation(OperationCode::LogicalIEqual, std::move(value), Immediate(0));
|
|
|
|
SetInternalFlag(bb, InternalFlag::Zero, std::move(zerop));
|
2018-12-27 19:50:36 +00:00
|
|
|
LOG_WARNING(HW_GPU, "Condition codes implementation is incomplete");
|
|
|
|
}
|
|
|
|
|
2018-12-26 05:58:47 +00:00
|
|
|
Node ShaderIR::BitfieldExtract(Node value, u32 offset, u32 bits) {
|
2019-07-16 14:37:11 +00:00
|
|
|
return Operation(OperationCode::UBitfieldExtract, NO_PRECISE, std::move(value),
|
|
|
|
Immediate(offset), Immediate(bits));
|
2018-12-26 05:58:47 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 00:14:44 +00:00
|
|
|
Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) {
|
|
|
|
return Operation(OperationCode::UBitfieldInsert, NO_PRECISE, base, insert, Immediate(offset),
|
|
|
|
Immediate(bits));
|
|
|
|
}
|
|
|
|
|
2019-04-03 07:33:36 +00:00
|
|
|
} // namespace VideoCommon::Shader
|