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.
|
|
|
|
|
2019-10-24 05:44:30 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
2018-12-20 23:09:21 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
2018-12-27 20:50:36 +01:00
|
|
|
#include "common/logging/log.h"
|
2018-12-20 23:09:21 +01:00
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2020-05-09 09:55:15 +02:00
|
|
|
#include "video_core/shader/node.h"
|
2019-06-05 03:44:06 +02:00
|
|
|
#include "video_core/shader/node_helper.h"
|
2020-02-29 00:53:10 +01:00
|
|
|
#include "video_core/shader/registry.h"
|
2018-12-20 23:09:21 +01: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-09-25 04:34:18 +02:00
|
|
|
ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset, CompilerSettings settings,
|
2020-02-29 00:53:10 +01:00
|
|
|
Registry& registry)
|
|
|
|
: program_code{program_code}, main_offset{main_offset}, settings{settings}, registry{registry} {
|
2019-05-19 10:01:59 +02:00
|
|
|
Decode();
|
2020-01-03 21:16:29 +01:00
|
|
|
PostDecode();
|
2019-05-19 10:01:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderIR::~ShaderIR() = default;
|
|
|
|
|
2018-12-21 02:41:31 +01:00
|
|
|
Node ShaderIR::GetRegister(Register reg) {
|
|
|
|
if (reg != Register::ZeroIndex) {
|
|
|
|
used_registers.insert(static_cast<u32>(reg));
|
|
|
|
}
|
2019-06-05 03:44:06 +02:00
|
|
|
return MakeNode<GprNode>(reg);
|
2018-12-21 02:41:31 +01:00
|
|
|
}
|
|
|
|
|
2020-01-07 19:53:46 +01:00
|
|
|
Node ShaderIR::GetCustomVariable(u32 id) {
|
|
|
|
return MakeNode<CustomVarNode>(id);
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:36:17 +01: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 02:42:47 +01:00
|
|
|
Node ShaderIR::GetConstBuffer(u64 index_, u64 offset_) {
|
|
|
|
const auto index = static_cast<u32>(index_);
|
|
|
|
const auto offset = static_cast<u32>(offset_);
|
|
|
|
|
2020-04-15 21:59:23 +02:00
|
|
|
used_cbufs.try_emplace(index).first->second.MarkAsUsed(offset);
|
2018-12-21 02:42:47 +01:00
|
|
|
|
2019-06-05 03:44:06 +02:00
|
|
|
return MakeNode<CbufNode>(index, Immediate(offset));
|
2018-12-21 02:42:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetConstBufferIndirect(u64 index_, u64 offset_, Node node) {
|
|
|
|
const auto index = static_cast<u32>(index_);
|
|
|
|
const auto offset = static_cast<u32>(offset_);
|
|
|
|
|
2020-04-15 21:59:23 +02:00
|
|
|
used_cbufs.try_emplace(index).first->second.MarkAsUsedIndirect();
|
2018-12-21 02:42:47 +01:00
|
|
|
|
2019-07-16 16:37:11 +02:00
|
|
|
Node final_offset = [&] {
|
2019-06-01 00:14:34 +02: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 16:37:11 +02:00
|
|
|
return Operation(OperationCode::UAdd, NO_PRECISE, std::move(node), Immediate(offset));
|
2019-06-01 00:14:34 +02:00
|
|
|
}();
|
2019-07-16 16:37:11 +02:00
|
|
|
return MakeNode<CbufNode>(index, std::move(final_offset));
|
2018-12-21 02:42:47 +01:00
|
|
|
}
|
|
|
|
|
2018-12-20 23:09:21 +01: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 03:44:06 +02:00
|
|
|
return MakeNode<PredicateNode>(pred, negated);
|
2018-12-20 23:09:21 +01:00
|
|
|
}
|
|
|
|
|
2018-12-21 02:36:17 +01:00
|
|
|
Node ShaderIR::GetPredicate(bool immediate) {
|
|
|
|
return GetPredicate(static_cast<u64>(immediate ? Pred::UnusedIndex : Pred::NeverExecute));
|
|
|
|
}
|
|
|
|
|
2019-04-30 04:37:09 +02:00
|
|
|
Node ShaderIR::GetInputAttribute(Attribute::Index index, u64 element, Node buffer) {
|
2020-03-16 01:00:51 +01:00
|
|
|
MarkAttributeUsage(index, element);
|
2019-04-30 04:37:09 +02:00
|
|
|
used_input_attributes.emplace(index);
|
2019-07-16 16:37:11 +02:00
|
|
|
return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer));
|
2018-12-21 02:45:34 +01:00
|
|
|
}
|
|
|
|
|
2019-04-30 23:12:30 +02:00
|
|
|
Node ShaderIR::GetPhysicalInputAttribute(Tegra::Shader::Register physical_address, Node buffer) {
|
2019-05-01 00:46:49 +02:00
|
|
|
uses_physical_attributes = true;
|
2019-06-05 03:44:06 +02:00
|
|
|
return MakeNode<AbufNode>(GetRegister(physical_address), buffer);
|
2018-12-21 02:45:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetOutputAttribute(Attribute::Index index, u64 element, Node buffer) {
|
2020-03-16 01:00:51 +01:00
|
|
|
MarkAttributeUsage(index, element);
|
2018-12-21 02:45:34 +01:00
|
|
|
used_output_attributes.insert(index);
|
2019-07-16 16:37:11 +02:00
|
|
|
return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer));
|
2018-12-21 02:45:34 +01:00
|
|
|
}
|
|
|
|
|
2019-06-29 07:44:07 +02:00
|
|
|
Node ShaderIR::GetInternalFlag(InternalFlag flag, bool negated) const {
|
2020-07-21 06:29:23 +02:00
|
|
|
Node node = MakeNode<InternalFlagNode>(flag);
|
2018-12-21 02:49:59 +01:00
|
|
|
if (negated) {
|
2020-07-21 06:29:23 +02:00
|
|
|
return Operation(OperationCode::LogicalNegate, std::move(node));
|
2018-12-21 02:49:59 +01:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:51:38 +01:00
|
|
|
Node ShaderIR::GetLocalMemory(Node address) {
|
2019-07-16 16:37:11 +02:00
|
|
|
return MakeNode<LmemNode>(std::move(address));
|
2018-12-21 02:51:38 +01:00
|
|
|
}
|
|
|
|
|
2019-07-30 05:21:46 +02:00
|
|
|
Node ShaderIR::GetSharedMemory(Node address) {
|
|
|
|
return MakeNode<SmemNode>(std::move(address));
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:31:17 +02:00
|
|
|
Node ShaderIR::GetTemporary(u32 id) {
|
2018-12-27 05:50:22 +01:00
|
|
|
return GetRegister(Register::ZeroIndex + 1 + id);
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:56:08 +01:00
|
|
|
Node ShaderIR::GetOperandAbsNegFloat(Node value, bool absolute, bool negate) {
|
|
|
|
if (absolute) {
|
2019-07-16 16:37:11 +02:00
|
|
|
value = Operation(OperationCode::FAbsolute, NO_PRECISE, std::move(value));
|
2018-12-21 02:56:08 +01:00
|
|
|
}
|
|
|
|
if (negate) {
|
2019-07-16 16:37:11 +02:00
|
|
|
value = Operation(OperationCode::FNegate, NO_PRECISE, std::move(value));
|
2018-12-21 02:56:08 +01:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetSaturatedFloat(Node value, bool saturate) {
|
|
|
|
if (!saturate) {
|
|
|
|
return value;
|
|
|
|
}
|
2019-07-16 16:37:11 +02: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 02:56:08 +01:00
|
|
|
}
|
|
|
|
|
2019-07-16 16:37:11 +02:00
|
|
|
Node ShaderIR::ConvertIntegerSize(Node value, Register::Size size, bool is_signed) {
|
2018-12-21 02:57:16 +01:00
|
|
|
switch (size) {
|
|
|
|
case Register::Size::Byte:
|
2019-07-16 16:37:11 +02: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 02:57:16 +01:00
|
|
|
return value;
|
|
|
|
case Register::Size::Short:
|
2019-07-16 16:37:11 +02: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));
|
2020-04-15 21:59:23 +02:00
|
|
|
return value;
|
2018-12-21 02:57:16 +01:00
|
|
|
case Register::Size::Word:
|
|
|
|
// Default - do nothing
|
|
|
|
return value;
|
|
|
|
default:
|
|
|
|
UNREACHABLE_MSG("Unimplemented conversion size: {}", static_cast<u32>(size));
|
2018-12-21 22:47:22 +01:00
|
|
|
return value;
|
2018-12-21 02:57:16 +01: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 16:37:11 +02:00
|
|
|
value = Operation(OperationCode::IAbsolute, NO_PRECISE, std::move(value));
|
2018-12-21 02:57:16 +01:00
|
|
|
}
|
|
|
|
if (negate) {
|
2019-07-16 16:37:11 +02:00
|
|
|
value = Operation(OperationCode::INegate, NO_PRECISE, std::move(value));
|
2018-12-21 02:57:16 +01:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-12-21 02:58:33 +01:00
|
|
|
Node ShaderIR::UnpackHalfImmediate(Instruction instr, bool has_negation) {
|
2019-07-16 16:37:11 +02:00
|
|
|
Node value = Immediate(instr.half_imm.PackImmediates());
|
2018-12-21 02:58:33 +01:00
|
|
|
if (!has_negation) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:37:11 +02: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-16 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::UnpackHalfFloat(Node value, Tegra::Shader::HalfType type) {
|
2019-07-16 16:37:11 +02:00
|
|
|
return Operation(OperationCode::HUnpack, type, std::move(value));
|
2018-12-21 02:58:33 +01: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 16:37:11 +02:00
|
|
|
return Operation(OperationCode::HMergeF32, std::move(src));
|
2018-12-21 02:58:33 +01:00
|
|
|
case Tegra::Shader::HalfMerge::Mrg_H0:
|
2019-07-16 16:37:11 +02:00
|
|
|
return Operation(OperationCode::HMergeH0, std::move(dest), std::move(src));
|
2018-12-21 02:58:33 +01:00
|
|
|
case Tegra::Shader::HalfMerge::Mrg_H1:
|
2019-07-16 16:37:11 +02:00
|
|
|
return Operation(OperationCode::HMergeH1, std::move(dest), std::move(src));
|
2018-12-21 02:58:33 +01:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetOperandAbsNegHalf(Node value, bool absolute, bool negate) {
|
|
|
|
if (absolute) {
|
2019-07-16 16:37:11 +02:00
|
|
|
value = Operation(OperationCode::HAbsolute, NO_PRECISE, std::move(value));
|
2018-12-21 02:58:33 +01:00
|
|
|
}
|
|
|
|
if (negate) {
|
2019-07-16 16:37:11 +02:00
|
|
|
value = Operation(OperationCode::HNegate, NO_PRECISE, std::move(value), GetPredicate(true),
|
2018-12-21 02:58:33 +01:00
|
|
|
GetPredicate(true));
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-04-09 23:41:41 +02:00
|
|
|
Node ShaderIR::GetSaturatedHalfFloat(Node value, bool saturate) {
|
|
|
|
if (!saturate) {
|
|
|
|
return value;
|
|
|
|
}
|
2019-07-16 16:37:11 +02: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 23:41:41 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 03:01:03 +01:00
|
|
|
Node ShaderIR::GetPredicateComparisonFloat(PredCondition condition, Node op_a, Node op_b) {
|
2020-05-09 09:55:15 +02:00
|
|
|
if (condition == PredCondition::T) {
|
|
|
|
return GetPredicate(true);
|
|
|
|
} else if (condition == PredCondition::F) {
|
|
|
|
return GetPredicate(false);
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:44:30 +02:00
|
|
|
static constexpr std::array comparison_table{
|
2020-05-09 09:55:15 +02:00
|
|
|
OperationCode(0),
|
|
|
|
OperationCode::LogicalFOrdLessThan, // LT
|
|
|
|
OperationCode::LogicalFOrdEqual, // EQ
|
|
|
|
OperationCode::LogicalFOrdLessEqual, // LE
|
|
|
|
OperationCode::LogicalFOrdGreaterThan, // GT
|
|
|
|
OperationCode::LogicalFOrdNotEqual, // NE
|
|
|
|
OperationCode::LogicalFOrdGreaterEqual, // GE
|
|
|
|
OperationCode::LogicalFOrdered, // NUM
|
|
|
|
OperationCode::LogicalFUnordered, // NAN
|
|
|
|
OperationCode::LogicalFUnordLessThan, // LTU
|
|
|
|
OperationCode::LogicalFUnordEqual, // EQU
|
|
|
|
OperationCode::LogicalFUnordLessEqual, // LEU
|
|
|
|
OperationCode::LogicalFUnordGreaterThan, // GTU
|
|
|
|
OperationCode::LogicalFUnordNotEqual, // NEU
|
|
|
|
OperationCode::LogicalFUnordGreaterEqual, // GEU
|
2019-10-24 05:44:30 +02:00
|
|
|
};
|
2020-05-09 09:55:15 +02:00
|
|
|
const std::size_t index = static_cast<std::size_t>(condition);
|
|
|
|
ASSERT_MSG(index < std::size(comparison_table), "Invalid condition={}", index);
|
2019-10-24 05:44:30 +02:00
|
|
|
|
2020-05-09 09:55:15 +02:00
|
|
|
return Operation(comparison_table[index], op_a, op_b);
|
2018-12-21 03:01:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Node ShaderIR::GetPredicateComparisonInteger(PredCondition condition, bool is_signed, Node op_a,
|
|
|
|
Node op_b) {
|
2019-10-24 05:44:30 +02:00
|
|
|
static constexpr std::array comparison_table{
|
2020-05-09 09:55:15 +02:00
|
|
|
std::pair{PredCondition::LT, OperationCode::LogicalILessThan},
|
|
|
|
std::pair{PredCondition::EQ, OperationCode::LogicalIEqual},
|
|
|
|
std::pair{PredCondition::LE, OperationCode::LogicalILessEqual},
|
|
|
|
std::pair{PredCondition::GT, OperationCode::LogicalIGreaterThan},
|
|
|
|
std::pair{PredCondition::NE, OperationCode::LogicalINotEqual},
|
|
|
|
std::pair{PredCondition::GE, OperationCode::LogicalIGreaterEqual},
|
2019-10-24 05:44:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto comparison =
|
|
|
|
std::find_if(comparison_table.cbegin(), comparison_table.cend(),
|
|
|
|
[condition](const auto entry) { return condition == entry.first; });
|
|
|
|
UNIMPLEMENTED_IF_MSG(comparison == comparison_table.cend(),
|
2018-12-21 03:01:03 +01:00
|
|
|
"Unknown predicate comparison operation");
|
|
|
|
|
2020-05-09 09:55:15 +02:00
|
|
|
return SignedOperation(comparison->second, is_signed, NO_PRECISE, std::move(op_a),
|
|
|
|
std::move(op_b));
|
2018-12-21 03:01:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:48:11 +02:00
|
|
|
Node ShaderIR::GetPredicateComparisonHalf(Tegra::Shader::PredCondition condition, Node op_a,
|
|
|
|
Node op_b) {
|
2019-10-24 05:44:30 +02:00
|
|
|
static constexpr std::array comparison_table{
|
2020-05-09 09:55:15 +02:00
|
|
|
std::pair{PredCondition::LT, OperationCode::Logical2HLessThan},
|
|
|
|
std::pair{PredCondition::EQ, OperationCode::Logical2HEqual},
|
|
|
|
std::pair{PredCondition::LE, OperationCode::Logical2HLessEqual},
|
|
|
|
std::pair{PredCondition::GT, OperationCode::Logical2HGreaterThan},
|
|
|
|
std::pair{PredCondition::NE, OperationCode::Logical2HNotEqual},
|
|
|
|
std::pair{PredCondition::GE, OperationCode::Logical2HGreaterEqual},
|
|
|
|
std::pair{PredCondition::LTU, OperationCode::Logical2HLessThanWithNan},
|
|
|
|
std::pair{PredCondition::LEU, OperationCode::Logical2HLessEqualWithNan},
|
|
|
|
std::pair{PredCondition::GTU, OperationCode::Logical2HGreaterThanWithNan},
|
|
|
|
std::pair{PredCondition::NEU, OperationCode::Logical2HNotEqualWithNan},
|
|
|
|
std::pair{PredCondition::GEU, OperationCode::Logical2HGreaterEqualWithNan},
|
2019-10-24 05:44:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto comparison =
|
|
|
|
std::find_if(comparison_table.cbegin(), comparison_table.cend(),
|
|
|
|
[condition](const auto entry) { return condition == entry.first; });
|
|
|
|
UNIMPLEMENTED_IF_MSG(comparison == comparison_table.cend(),
|
2018-12-21 03:01:03 +01:00
|
|
|
"Unknown predicate comparison operation");
|
|
|
|
|
2019-07-16 16:37:11 +02:00
|
|
|
return Operation(comparison->second, NO_PRECISE, std::move(op_a), std::move(op_b));
|
2018-12-21 03:01:03 +01:00
|
|
|
}
|
|
|
|
|
2018-12-21 03:40:54 +01:00
|
|
|
OperationCode ShaderIR::GetPredicateCombiner(PredOperation operation) {
|
2019-10-24 05:44:30 +02:00
|
|
|
static constexpr std::array operation_table{
|
|
|
|
OperationCode::LogicalAnd,
|
|
|
|
OperationCode::LogicalOr,
|
|
|
|
OperationCode::LogicalXor,
|
2018-12-21 03:40:54 +01:00
|
|
|
};
|
|
|
|
|
2019-10-24 05:44:30 +02:00
|
|
|
const auto index = static_cast<std::size_t>(operation);
|
|
|
|
if (index >= operation_table.size()) {
|
|
|
|
UNIMPLEMENTED_MSG("Unknown predicate operation.");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return operation_table[index];
|
2018-12-21 03:40:54 +01:00
|
|
|
}
|
|
|
|
|
2019-06-29 07:44:07 +02:00
|
|
|
Node ShaderIR::GetConditionCode(Tegra::Shader::ConditionCode cc) const {
|
2018-12-21 03:42:02 +01:00
|
|
|
switch (cc) {
|
|
|
|
case Tegra::Shader::ConditionCode::NEU:
|
|
|
|
return GetInternalFlag(InternalFlag::Zero, true);
|
2020-04-04 08:34:08 +02:00
|
|
|
case Tegra::Shader::ConditionCode::FCSM_TR:
|
|
|
|
UNIMPLEMENTED_MSG("EXIT.FCSM_TR is not implemented");
|
|
|
|
return MakeNode<PredicateNode>(Pred::NeverExecute, false);
|
2018-12-21 03:42:02 +01:00
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_MSG("Unimplemented condition code: {}", static_cast<u32>(cc));
|
2019-06-29 07:44:07 +02:00
|
|
|
return MakeNode<PredicateNode>(Pred::NeverExecute, false);
|
2018-12-21 03:42:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
void ShaderIR::SetRegister(NodeBlock& bb, Register dest, Node src) {
|
2019-07-16 16:37:11 +02:00
|
|
|
bb.push_back(Operation(OperationCode::Assign, GetRegister(dest), std::move(src)));
|
2018-12-21 02:53:43 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
void ShaderIR::SetPredicate(NodeBlock& bb, u64 dest, Node src) {
|
2019-07-16 16:37:11 +02:00
|
|
|
bb.push_back(Operation(OperationCode::LogicalAssign, GetPredicate(dest), std::move(src)));
|
2018-12-21 02:53:43 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
void ShaderIR::SetInternalFlag(NodeBlock& bb, InternalFlag flag, Node value) {
|
2019-07-16 16:37:11 +02:00
|
|
|
bb.push_back(Operation(OperationCode::LogicalAssign, GetInternalFlag(flag), std::move(value)));
|
2018-12-21 02:53:43 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
void ShaderIR::SetLocalMemory(NodeBlock& bb, Node address, Node value) {
|
2019-07-16 16:37:11 +02:00
|
|
|
bb.push_back(
|
|
|
|
Operation(OperationCode::Assign, GetLocalMemory(std::move(address)), std::move(value)));
|
2018-12-21 02:53:43 +01:00
|
|
|
}
|
|
|
|
|
2019-07-30 05:21:46 +02: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 16:31:17 +02:00
|
|
|
void ShaderIR::SetTemporary(NodeBlock& bb, u32 id, Node value) {
|
2019-07-16 16:37:11 +02:00
|
|
|
SetRegister(bb, Register::ZeroIndex + 1 + id, std::move(value));
|
2018-12-27 05:50:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
void ShaderIR::SetInternalFlagsFromFloat(NodeBlock& bb, Node value, bool sets_cc) {
|
2018-12-27 20:50:36 +01:00
|
|
|
if (!sets_cc) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-09 09:55:15 +02:00
|
|
|
Node zerop = Operation(OperationCode::LogicalFOrdEqual, std::move(value), Immediate(0.0f));
|
2019-07-16 16:37:11 +02:00
|
|
|
SetInternalFlag(bb, InternalFlag::Zero, std::move(zerop));
|
2018-12-27 20:50:36 +01:00
|
|
|
LOG_WARNING(HW_GPU, "Condition codes implementation is incomplete");
|
|
|
|
}
|
|
|
|
|
2019-01-30 06:09:40 +01:00
|
|
|
void ShaderIR::SetInternalFlagsFromInteger(NodeBlock& bb, Node value, bool sets_cc) {
|
2018-12-27 20:50:36 +01:00
|
|
|
if (!sets_cc) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-25 00:40:06 +02:00
|
|
|
switch (value->index()) {
|
|
|
|
case 0:
|
|
|
|
Iterop(bb, value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (const auto gpr = std::get_if<GprNode>(value.get())) {
|
|
|
|
LOG_WARNING(HW_GPU, "GprNode: index={}", gpr->GetIndex());
|
|
|
|
Node zerop = Operation(OperationCode::LogicalIEqual, std::move(value),
|
|
|
|
Immediate(gpr->GetIndex()));
|
|
|
|
SetInternalFlag(bb, InternalFlag::Zero, std::move(zerop));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Node zerop = Operation(OperationCode::LogicalIEqual, std::move(value), Immediate(0));
|
|
|
|
SetInternalFlag(bb, InternalFlag::Zero, std::move(zerop));
|
|
|
|
LOG_WARNING(HW_GPU, "Node Type: {}", value->index());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderIR::Iterop(NodeBlock& nb, Node var) {
|
|
|
|
if (const auto op = std::get_if<OperationNode>(var.get())) {
|
|
|
|
if (op->GetOperandsCount() > 0) {
|
|
|
|
for (auto& opss : op->GetOperands()) {
|
|
|
|
switch (opss->index()) {
|
|
|
|
case 0:
|
|
|
|
return Iterop(nb, opss);
|
|
|
|
case 2:
|
|
|
|
if (const auto gpr = std::get_if<GprNode>(opss.get())) {
|
|
|
|
LOG_WARNING(HW_GPU, "Child GprNode: index={}", gpr->GetIndex());
|
|
|
|
Node zerop = Operation(OperationCode::LogicalIEqual, std::move(opss),
|
|
|
|
Immediate(gpr->GetIndex()));
|
|
|
|
SetInternalFlag(nb, InternalFlag::Zero, std::move(zerop));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_WARNING(HW_GPU, "Child Node Type: {}", opss->index());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-27 20:50:36 +01:00
|
|
|
}
|
|
|
|
|
2018-12-26 06:58:47 +01:00
|
|
|
Node ShaderIR::BitfieldExtract(Node value, u32 offset, u32 bits) {
|
2019-07-16 16:37:11 +02:00
|
|
|
return Operation(OperationCode::UBitfieldExtract, NO_PRECISE, std::move(value),
|
|
|
|
Immediate(offset), Immediate(bits));
|
2018-12-26 06:58:47 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 02:14:44 +02:00
|
|
|
Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) {
|
|
|
|
return Operation(OperationCode::UBitfieldInsert, NO_PRECISE, base, insert, Immediate(offset),
|
|
|
|
Immediate(bits));
|
|
|
|
}
|
|
|
|
|
2020-03-16 01:00:51 +01:00
|
|
|
void ShaderIR::MarkAttributeUsage(Attribute::Index index, u64 element) {
|
|
|
|
switch (index) {
|
|
|
|
case 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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Attribute::Index::TessCoordInstanceIDVertexID:
|
|
|
|
switch (element) {
|
|
|
|
case 2:
|
|
|
|
uses_instance_id = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
uses_vertex_id = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Attribute::Index::ClipDistances0123:
|
|
|
|
case Attribute::Index::ClipDistances4567: {
|
|
|
|
const u64 clip_index = (index == Attribute::Index::ClipDistances4567 ? 4 : 0) + element;
|
|
|
|
used_clip_distances.at(clip_index) = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Attribute::Index::FrontColor:
|
|
|
|
case Attribute::Index::FrontSecondaryColor:
|
|
|
|
case Attribute::Index::BackColor:
|
|
|
|
case Attribute::Index::BackSecondaryColor:
|
|
|
|
uses_legacy_varyings = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (index >= Attribute::Index::TexCoord_0 && index <= Attribute::Index::TexCoord_7) {
|
|
|
|
uses_legacy_varyings = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-04 19:40:57 +01:00
|
|
|
std::size_t ShaderIR::DeclareAmend(Node new_amend) {
|
|
|
|
const std::size_t id = amend_code.size();
|
2019-12-30 18:54:53 +01:00
|
|
|
amend_code.push_back(new_amend);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2020-01-07 19:53:46 +01:00
|
|
|
u32 ShaderIR::NewCustomVariable() {
|
2020-01-24 15:44:34 +01:00
|
|
|
return num_custom_variables++;
|
2020-01-07 19:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 09:33:36 +02:00
|
|
|
} // namespace VideoCommon::Shader
|