2018-03-19 23:51:43 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-04-05 03:44:35 +02:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2018-03-19 23:51:43 +01:00
|
|
|
#include <string>
|
2018-04-20 02:10:40 +02:00
|
|
|
#include <string_view>
|
2018-03-19 23:51:43 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
2018-04-05 03:44:35 +02:00
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2018-03-19 23:51:43 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
namespace GLShader {
|
2018-03-19 23:51:43 +01:00
|
|
|
namespace Decompiler {
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
using Tegra::Shader::Attribute;
|
|
|
|
using Tegra::Shader::Instruction;
|
|
|
|
using Tegra::Shader::OpCode;
|
|
|
|
using Tegra::Shader::Register;
|
2018-04-10 07:26:15 +02:00
|
|
|
using Tegra::Shader::Sampler;
|
2018-04-10 05:39:44 +02:00
|
|
|
using Tegra::Shader::SubOp;
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-03-19 23:51:43 +01:00
|
|
|
constexpr u32 PROGRAM_END = MAX_PROGRAM_CODE_LENGTH;
|
|
|
|
|
2018-04-05 03:44:35 +02:00
|
|
|
class DecompileFail : public std::runtime_error {
|
2018-03-19 23:51:43 +01:00
|
|
|
public:
|
2018-04-05 03:44:35 +02:00
|
|
|
using std::runtime_error::runtime_error;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Describes the behaviour of code path of a given entry point and a return point.
|
|
|
|
enum class ExitMethod {
|
|
|
|
Undetermined, ///< Internal value. Only occur when analyzing JMP loop.
|
|
|
|
AlwaysReturn, ///< All code paths reach the return point.
|
|
|
|
Conditional, ///< Code path reaches the return point or an END instruction conditionally.
|
|
|
|
AlwaysEnd, ///< All code paths reach a END instruction.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A subroutine is a range of code refereced by a CALL, IF or LOOP instruction.
|
|
|
|
struct Subroutine {
|
|
|
|
/// Generates a name suitable for GLSL source code.
|
|
|
|
std::string GetName() const {
|
2018-04-27 04:48:06 +02:00
|
|
|
return "sub_" + std::to_string(begin) + '_' + std::to_string(end);
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 begin; ///< Entry point of the subroutine.
|
|
|
|
u32 end; ///< Return point of the subroutine.
|
|
|
|
ExitMethod exit_method; ///< Exit method of the subroutine.
|
|
|
|
std::set<u32> labels; ///< Addresses refereced by JMP instructions.
|
|
|
|
|
|
|
|
bool operator<(const Subroutine& rhs) const {
|
|
|
|
return std::tie(begin, end) < std::tie(rhs.begin, rhs.end);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Analyzes shader code and produces a set of subroutines.
|
|
|
|
class ControlFlowAnalyzer {
|
|
|
|
public:
|
|
|
|
ControlFlowAnalyzer(const ProgramCode& program_code, u32 main_offset)
|
|
|
|
: program_code(program_code) {
|
|
|
|
|
|
|
|
// Recursively finds all subroutines.
|
|
|
|
const Subroutine& program_main = AddSubroutine(main_offset, PROGRAM_END);
|
|
|
|
if (program_main.exit_method != ExitMethod::AlwaysEnd)
|
|
|
|
throw DecompileFail("Program does not always end");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<Subroutine> GetSubroutines() {
|
|
|
|
return std::move(subroutines);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ProgramCode& program_code;
|
|
|
|
std::set<Subroutine> subroutines;
|
|
|
|
std::map<std::pair<u32, u32>, ExitMethod> exit_method_map;
|
|
|
|
|
|
|
|
/// Adds and analyzes a new subroutine if it is not added yet.
|
|
|
|
const Subroutine& AddSubroutine(u32 begin, u32 end) {
|
|
|
|
auto iter = subroutines.find(Subroutine{begin, end});
|
|
|
|
if (iter != subroutines.end())
|
|
|
|
return *iter;
|
|
|
|
|
|
|
|
Subroutine subroutine{begin, end};
|
|
|
|
subroutine.exit_method = Scan(begin, end, subroutine.labels);
|
|
|
|
if (subroutine.exit_method == ExitMethod::Undetermined)
|
|
|
|
throw DecompileFail("Recursive function detected");
|
|
|
|
return *subroutines.insert(std::move(subroutine)).first;
|
|
|
|
}
|
2018-03-19 23:51:43 +01:00
|
|
|
|
2018-06-02 21:45:50 +02:00
|
|
|
/// Merges exit method of two parallel branches.
|
|
|
|
static ExitMethod ParallelExit(ExitMethod a, ExitMethod b) {
|
|
|
|
if (a == ExitMethod::Undetermined) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
if (b == ExitMethod::Undetermined) {
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
if (a == b) {
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
return ExitMethod::Conditional;
|
|
|
|
}
|
|
|
|
|
2018-04-05 03:44:35 +02:00
|
|
|
/// Scans a range of code for labels and determines the exit method.
|
|
|
|
ExitMethod Scan(u32 begin, u32 end, std::set<u32>& labels) {
|
|
|
|
auto [iter, inserted] =
|
|
|
|
exit_method_map.emplace(std::make_pair(begin, end), ExitMethod::Undetermined);
|
|
|
|
ExitMethod& exit_method = iter->second;
|
|
|
|
if (!inserted)
|
|
|
|
return exit_method;
|
|
|
|
|
|
|
|
for (u32 offset = begin; offset != end && offset != PROGRAM_END; ++offset) {
|
2018-06-02 21:45:50 +02:00
|
|
|
const Instruction instr = {program_code[offset]};
|
|
|
|
if (const auto opcode = OpCode::Decode(instr)) {
|
2018-04-21 02:49:05 +02:00
|
|
|
switch (opcode->GetId()) {
|
|
|
|
case OpCode::Id::EXIT: {
|
2018-06-05 02:14:23 +02:00
|
|
|
// The EXIT instruction can be predicated, which means that the shader can
|
|
|
|
// conditionally end on this instruction. We have to consider the case where the
|
|
|
|
// condition is not met and check the exit method of that other basic block.
|
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
if (instr.pred.pred_index == static_cast<u64>(Pred::UnusedIndex)) {
|
|
|
|
return exit_method = ExitMethod::AlwaysEnd;
|
|
|
|
} else {
|
|
|
|
ExitMethod not_met = Scan(offset + 1, end, labels);
|
|
|
|
return exit_method = ParallelExit(ExitMethod::AlwaysEnd, not_met);
|
|
|
|
}
|
2018-04-21 02:49:05 +02:00
|
|
|
}
|
2018-06-02 21:45:50 +02:00
|
|
|
case OpCode::Id::BRA: {
|
|
|
|
u32 target = offset + instr.bra.GetBranchTarget();
|
|
|
|
labels.insert(target);
|
|
|
|
ExitMethod no_jmp = Scan(offset + 1, end, labels);
|
|
|
|
ExitMethod jmp = Scan(target, end, labels);
|
|
|
|
return exit_method = ParallelExit(no_jmp, jmp);
|
|
|
|
}
|
2018-04-21 02:49:05 +02:00
|
|
|
}
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return exit_method = ExitMethod::AlwaysReturn;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderWriter {
|
|
|
|
public:
|
2018-04-20 02:10:40 +02:00
|
|
|
void AddLine(std::string_view text) {
|
2018-04-05 03:44:35 +02:00
|
|
|
DEBUG_ASSERT(scope >= 0);
|
|
|
|
if (!text.empty()) {
|
2018-04-20 01:59:20 +02:00
|
|
|
AppendIndentation();
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
2018-04-20 02:05:42 +02:00
|
|
|
shader_source += text;
|
|
|
|
AddNewLine();
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 02:02:24 +02:00
|
|
|
void AddLine(char character) {
|
|
|
|
DEBUG_ASSERT(scope >= 0);
|
|
|
|
AppendIndentation();
|
|
|
|
shader_source += character;
|
2018-04-20 02:05:42 +02:00
|
|
|
AddNewLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddNewLine() {
|
|
|
|
DEBUG_ASSERT(scope >= 0);
|
2018-04-20 02:02:24 +02:00
|
|
|
shader_source += '\n';
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetResult() {
|
|
|
|
return std::move(shader_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
int scope = 0;
|
|
|
|
|
|
|
|
private:
|
2018-04-20 01:59:20 +02:00
|
|
|
void AppendIndentation() {
|
|
|
|
shader_source.append(static_cast<size_t>(scope) * 4, ' ');
|
|
|
|
}
|
|
|
|
|
2018-04-05 03:44:35 +02:00
|
|
|
std::string shader_source;
|
|
|
|
};
|
|
|
|
|
2018-04-26 05:55:21 +02:00
|
|
|
/**
|
|
|
|
* Represents an emulated shader register, used to track the state of that register for emulation
|
|
|
|
* with GLSL. At this time, a register can be used as a float or an integer. This class is used for
|
|
|
|
* bookkeeping within the GLSL program.
|
|
|
|
*/
|
|
|
|
class GLSLRegister {
|
|
|
|
public:
|
2018-04-28 04:24:53 +02:00
|
|
|
enum class Type {
|
|
|
|
Float,
|
|
|
|
Integer,
|
2018-04-29 01:59:30 +02:00
|
|
|
UnsignedInteger,
|
2018-04-28 04:24:53 +02:00
|
|
|
};
|
2018-04-26 05:55:21 +02:00
|
|
|
|
2018-04-28 04:24:53 +02:00
|
|
|
GLSLRegister(size_t index, ShaderWriter& shader) : index{index}, shader{shader} {}
|
2018-04-26 05:55:21 +02:00
|
|
|
|
2018-04-29 01:59:30 +02:00
|
|
|
/// Gets the GLSL type string for a register
|
2018-04-28 04:24:53 +02:00
|
|
|
static std::string GetTypeString(Type type) {
|
|
|
|
switch (type) {
|
2018-04-26 05:55:21 +02:00
|
|
|
case Type::Float:
|
2018-04-28 04:24:53 +02:00
|
|
|
return "float";
|
2018-04-29 01:59:30 +02:00
|
|
|
case Type::Integer:
|
|
|
|
return "int";
|
|
|
|
case Type::UnsignedInteger:
|
|
|
|
return "uint";
|
2018-04-26 05:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UNREACHABLE();
|
2018-04-28 04:24:53 +02:00
|
|
|
return {};
|
2018-04-26 05:55:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 01:59:30 +02:00
|
|
|
/// Gets the GLSL register prefix string, used for declarations and referencing
|
2018-04-28 04:24:53 +02:00
|
|
|
static std::string GetPrefixString(Type type) {
|
|
|
|
return "reg_" + GetTypeString(type) + '_';
|
2018-04-26 05:55:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-28 04:24:53 +02:00
|
|
|
/// Returns a GLSL string representing the current state of the register
|
|
|
|
const std::string GetActiveString() {
|
|
|
|
declr_type.insert(active_type);
|
|
|
|
return GetPrefixString(active_type) + std::to_string(index);
|
2018-04-26 05:55:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-28 04:24:53 +02:00
|
|
|
/// Returns true if the active type is a float
|
2018-04-27 04:48:06 +02:00
|
|
|
bool IsFloat() const {
|
|
|
|
return active_type == Type::Float;
|
|
|
|
}
|
|
|
|
|
2018-04-28 04:24:53 +02:00
|
|
|
/// Returns true if the active type is an integer
|
2018-04-27 04:48:06 +02:00
|
|
|
bool IsInteger() const {
|
|
|
|
return active_type == Type::Integer;
|
|
|
|
}
|
|
|
|
|
2018-06-04 18:22:26 +02:00
|
|
|
/// Returns the current active type of the register
|
|
|
|
Type GetActiveType() const {
|
|
|
|
return active_type;
|
|
|
|
}
|
|
|
|
|
2018-04-28 04:24:53 +02:00
|
|
|
/// Returns the index of the register
|
|
|
|
size_t GetIndex() const {
|
|
|
|
return index;
|
|
|
|
}
|
2018-04-26 05:55:21 +02:00
|
|
|
|
2018-04-28 04:24:53 +02:00
|
|
|
/// Returns a set of the declared types of the register
|
|
|
|
const std::set<Type>& DeclaredTypes() const {
|
|
|
|
return declr_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-04-26 05:55:21 +02:00
|
|
|
const size_t index;
|
|
|
|
const std::string float_str;
|
|
|
|
const std::string integer_str;
|
|
|
|
ShaderWriter& shader;
|
|
|
|
Type active_type{Type::Float};
|
|
|
|
std::set<Type> declr_type;
|
|
|
|
};
|
|
|
|
|
2018-04-27 04:48:06 +02:00
|
|
|
/**
|
|
|
|
* Used to manage shader registers that are emulated with GLSL. This class keeps track of the state
|
|
|
|
* of all registers (e.g. whether they are currently being used as Floats or Integers), and
|
|
|
|
* generates the necessary GLSL code to perform conversions as needed. This class is used for
|
|
|
|
* bookkeeping within the GLSL program.
|
|
|
|
*/
|
|
|
|
class GLSLRegisterManager {
|
2018-04-05 03:44:35 +02:00
|
|
|
public:
|
2018-04-27 04:48:06 +02:00
|
|
|
GLSLRegisterManager(ShaderWriter& shader, ShaderWriter& declarations,
|
|
|
|
const Maxwell3D::Regs::ShaderStage& stage)
|
|
|
|
: shader{shader}, declarations{declarations}, stage{stage} {
|
2018-04-26 05:55:21 +02:00
|
|
|
BuildRegisterList();
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 01:59:30 +02:00
|
|
|
/**
|
|
|
|
* Gets a register as an float.
|
|
|
|
* @param reg The register to get.
|
|
|
|
* @param elem The element to use for the operation.
|
|
|
|
* @returns GLSL string corresponding to the register as a float.
|
|
|
|
*/
|
|
|
|
std::string GetRegisterAsFloat(const Register& reg, unsigned elem = 0) {
|
|
|
|
ASSERT(regs[reg].IsFloat());
|
|
|
|
return GetRegister(reg, elem);
|
|
|
|
}
|
2018-04-27 04:48:06 +02:00
|
|
|
|
2018-04-29 01:59:30 +02:00
|
|
|
/**
|
|
|
|
* Gets a register as an integer.
|
|
|
|
* @param reg The register to get.
|
|
|
|
* @param elem The element to use for the operation.
|
|
|
|
* @param is_signed Whether to get the register as a signed (or unsigned) integer.
|
|
|
|
* @returns GLSL string corresponding to the register as an integer.
|
|
|
|
*/
|
|
|
|
std::string GetRegisterAsInteger(const Register& reg, unsigned elem = 0,
|
|
|
|
bool is_signed = true) {
|
|
|
|
const std::string func = GetGLSLConversionFunc(
|
|
|
|
GLSLRegister::Type::Float,
|
|
|
|
is_signed ? GLSLRegister::Type::Integer : GLSLRegister::Type::UnsignedInteger);
|
|
|
|
|
|
|
|
return func + '(' + GetRegister(reg, elem) + ')';
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
|
|
|
|
2018-04-27 04:48:06 +02:00
|
|
|
/**
|
2018-04-29 01:59:30 +02:00
|
|
|
* Writes code that does a register assignment to float value operation.
|
2018-04-27 04:48:06 +02:00
|
|
|
* @param reg The destination register to use.
|
|
|
|
* @param elem The element to use for the operation.
|
|
|
|
* @param value The code representing the value to assign.
|
|
|
|
* @param dest_num_components Number of components in the destination.
|
|
|
|
* @param value_num_components Number of components in the value.
|
|
|
|
* @param is_abs Optional, when True, applies absolute value to output.
|
|
|
|
* @param dest_elem Optional, the destination element to use for the operation.
|
|
|
|
*/
|
|
|
|
void SetRegisterToFloat(const Register& reg, u64 elem, const std::string& value,
|
|
|
|
u64 dest_num_components, u64 value_num_components, bool is_abs = false,
|
|
|
|
u64 dest_elem = 0) {
|
2018-04-29 01:59:30 +02:00
|
|
|
SetRegister(reg, elem, value, dest_num_components, value_num_components, is_abs, dest_elem);
|
|
|
|
}
|
2018-04-27 04:48:06 +02:00
|
|
|
|
2018-04-29 01:59:30 +02:00
|
|
|
/**
|
|
|
|
* Writes code that does a register assignment to integer value operation.
|
|
|
|
* @param reg The destination register to use.
|
|
|
|
* @param elem The element to use for the operation.
|
|
|
|
* @param value The code representing the value to assign.
|
|
|
|
* @param dest_num_components Number of components in the destination.
|
|
|
|
* @param value_num_components Number of components in the value.
|
|
|
|
* @param is_abs Optional, when True, applies absolute value to output.
|
|
|
|
* @param dest_elem Optional, the destination element to use for the operation.
|
|
|
|
*/
|
|
|
|
void SetRegisterToInteger(const Register& reg, bool is_signed, u64 elem,
|
|
|
|
const std::string& value, u64 dest_num_components,
|
|
|
|
u64 value_num_components, bool is_abs = false, u64 dest_elem = 0) {
|
|
|
|
const std::string func = GetGLSLConversionFunc(
|
|
|
|
is_signed ? GLSLRegister::Type::Integer : GLSLRegister::Type::UnsignedInteger,
|
|
|
|
GLSLRegister::Type::Float);
|
2018-04-27 04:48:06 +02:00
|
|
|
|
2018-04-29 01:59:30 +02:00
|
|
|
SetRegister(reg, elem, func + '(' + value + ')', dest_num_components, value_num_components,
|
|
|
|
is_abs, dest_elem);
|
2018-04-27 04:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes code that does a register assignment to input attribute operation. Input attributes
|
|
|
|
* are stored as floats, so this may require conversion.
|
|
|
|
* @param reg The destination register to use.
|
|
|
|
* @param elem The element to use for the operation.
|
2018-05-30 17:58:03 +02:00
|
|
|
* @param attribute The input attribute to use as the source value.
|
2018-04-27 04:48:06 +02:00
|
|
|
*/
|
|
|
|
void SetRegisterToInputAttibute(const Register& reg, u64 elem, Attribute::Index attribute) {
|
2018-04-29 01:59:30 +02:00
|
|
|
std::string dest = GetRegisterAsFloat(reg);
|
2018-04-27 04:48:06 +02:00
|
|
|
std::string src = GetInputAttribute(attribute) + GetSwizzle(elem);
|
|
|
|
|
|
|
|
if (regs[reg].IsFloat()) {
|
|
|
|
shader.AddLine(dest + " = " + src + ';');
|
|
|
|
} else if (regs[reg].IsInteger()) {
|
|
|
|
shader.AddLine(dest + " = floatBitsToInt(" + src + ");");
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes code that does a output attribute assignment to register operation. Output attributes
|
|
|
|
* are stored as floats, so this may require conversion.
|
|
|
|
* @param attribute The destination output attribute.
|
|
|
|
* @param elem The element to use for the operation.
|
|
|
|
* @param reg The register to use as the source value.
|
|
|
|
*/
|
|
|
|
void SetOutputAttributeToRegister(Attribute::Index attribute, u64 elem, const Register& reg) {
|
|
|
|
std::string dest = GetOutputAttribute(attribute) + GetSwizzle(elem);
|
2018-04-29 01:59:30 +02:00
|
|
|
std::string src = GetRegisterAsFloat(reg);
|
2018-04-27 04:48:06 +02:00
|
|
|
ASSERT_MSG(regs[reg].IsFloat(), "Output attributes must be set to a float");
|
|
|
|
shader.AddLine(dest + " = " + src + ';');
|
|
|
|
}
|
|
|
|
|
2018-06-04 18:22:26 +02:00
|
|
|
/// Generates code representing a uniform (C buffer) register, interpreted as the input type.
|
2018-06-06 04:45:22 +02:00
|
|
|
std::string GetUniform(u64 index, u64 offset, GLSLRegister::Type type) {
|
|
|
|
declr_const_buffers[index].MarkAsUsed(index, offset, stage);
|
|
|
|
std::string value = 'c' + std::to_string(index) + '[' + std::to_string(offset) + ']';
|
2018-04-27 04:48:06 +02:00
|
|
|
|
2018-06-04 18:22:26 +02:00
|
|
|
if (type == GLSLRegister::Type::Float) {
|
2018-04-27 04:48:06 +02:00
|
|
|
return value;
|
2018-06-04 18:22:26 +02:00
|
|
|
} else if (type == GLSLRegister::Type::Integer) {
|
2018-04-27 04:48:06 +02:00
|
|
|
return "floatBitsToInt(" + value + ')';
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 05:34:37 +02:00
|
|
|
std::string GetUniformIndirect(u64 index, s64 offset, const Register& index_reg,
|
|
|
|
GLSLRegister::Type type) {
|
|
|
|
declr_const_buffers[index].MarkAsUsedIndirect(index, stage);
|
|
|
|
std::string value = 'c' + std::to_string(index) + "[(floatBitsToInt(" +
|
|
|
|
GetRegister(index_reg, 0) + ") + " + std::to_string(offset) + ") / 4]";
|
|
|
|
|
|
|
|
if (type == GLSLRegister::Type::Float) {
|
|
|
|
return value;
|
|
|
|
} else if (type == GLSLRegister::Type::Integer) {
|
|
|
|
return "floatBitsToInt(" + value + ')';
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:48:06 +02:00
|
|
|
/// Add declarations for registers
|
|
|
|
void GenerateDeclarations() {
|
|
|
|
for (const auto& reg : regs) {
|
2018-04-28 04:24:53 +02:00
|
|
|
for (const auto& type : reg.DeclaredTypes()) {
|
|
|
|
declarations.AddLine(GLSLRegister::GetTypeString(type) + ' ' +
|
|
|
|
GLSLRegister::GetPrefixString(type) +
|
|
|
|
std::to_string(reg.GetIndex()) + " = 0;");
|
2018-04-27 04:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
declarations.AddNewLine();
|
|
|
|
|
|
|
|
for (const auto& index : declr_input_attribute) {
|
|
|
|
// TODO(bunnei): Use proper number of elements for these
|
|
|
|
declarations.AddLine("layout(location = " +
|
|
|
|
std::to_string(static_cast<u32>(index) -
|
|
|
|
static_cast<u32>(Attribute::Index::Attribute_0)) +
|
|
|
|
") in vec4 " + GetInputAttribute(index) + ';');
|
|
|
|
}
|
|
|
|
declarations.AddNewLine();
|
|
|
|
|
|
|
|
for (const auto& index : declr_output_attribute) {
|
|
|
|
// TODO(bunnei): Use proper number of elements for these
|
|
|
|
declarations.AddLine("layout(location = " +
|
|
|
|
std::to_string(static_cast<u32>(index) -
|
|
|
|
static_cast<u32>(Attribute::Index::Attribute_0)) +
|
|
|
|
") out vec4 " + GetOutputAttribute(index) + ';');
|
|
|
|
}
|
|
|
|
declarations.AddNewLine();
|
|
|
|
|
|
|
|
unsigned const_buffer_layout = 0;
|
|
|
|
for (const auto& entry : GetConstBuffersDeclarations()) {
|
|
|
|
declarations.AddLine("layout(std430) buffer " + entry.GetName());
|
|
|
|
declarations.AddLine('{');
|
|
|
|
declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];");
|
|
|
|
declarations.AddLine("};");
|
|
|
|
declarations.AddNewLine();
|
|
|
|
++const_buffer_layout;
|
|
|
|
}
|
|
|
|
declarations.AddNewLine();
|
2018-06-06 19:58:16 +02:00
|
|
|
|
|
|
|
// Append the sampler2D array for the used textures.
|
|
|
|
size_t num_samplers = GetSamplers().size();
|
|
|
|
if (num_samplers > 0) {
|
|
|
|
declarations.AddLine("uniform sampler2D " + SamplerEntry::GetArrayName(stage) + '[' +
|
|
|
|
std::to_string(num_samplers) + "];");
|
|
|
|
declarations.AddNewLine();
|
|
|
|
}
|
2018-04-27 04:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a list of constant buffer declarations
|
|
|
|
std::vector<ConstBufferEntry> GetConstBuffersDeclarations() const {
|
|
|
|
std::vector<ConstBufferEntry> result;
|
|
|
|
std::copy_if(declr_const_buffers.begin(), declr_const_buffers.end(),
|
|
|
|
std::back_inserter(result), [](const auto& entry) { return entry.IsUsed(); });
|
|
|
|
return result;
|
2018-04-15 09:32:12 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 19:58:16 +02:00
|
|
|
/// Returns a list of samplers used in the shader
|
|
|
|
std::vector<SamplerEntry> GetSamplers() const {
|
|
|
|
return used_samplers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the GLSL sampler used for the input shader sampler, and creates a new one if
|
|
|
|
/// necessary.
|
|
|
|
std::string AccessSampler(const Sampler& sampler) {
|
|
|
|
size_t offset = static_cast<size_t>(sampler.index.Value());
|
|
|
|
|
|
|
|
// If this sampler has already been used, return the existing mapping.
|
|
|
|
auto itr =
|
|
|
|
std::find_if(used_samplers.begin(), used_samplers.end(),
|
|
|
|
[&](const SamplerEntry& entry) { return entry.GetOffset() == offset; });
|
|
|
|
|
|
|
|
if (itr != used_samplers.end()) {
|
|
|
|
return itr->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise create a new mapping for this sampler
|
|
|
|
size_t next_index = used_samplers.size();
|
|
|
|
SamplerEntry entry{stage, offset, next_index};
|
|
|
|
used_samplers.emplace_back(entry);
|
|
|
|
return entry.GetName();
|
|
|
|
}
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
private:
|
2018-04-29 01:59:30 +02:00
|
|
|
/// Build GLSL conversion function, e.g. floatBitsToInt, intBitsToFloat, etc.
|
|
|
|
const std::string GetGLSLConversionFunc(GLSLRegister::Type src, GLSLRegister::Type dest) const {
|
|
|
|
const std::string src_type = GLSLRegister::GetTypeString(src);
|
|
|
|
std::string dest_type = GLSLRegister::GetTypeString(dest);
|
|
|
|
dest_type[0] = toupper(dest_type[0]);
|
|
|
|
return src_type + "BitsTo" + dest_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generates code representing a temporary (GPR) register.
|
|
|
|
std::string GetRegister(const Register& reg, unsigned elem) {
|
|
|
|
if (reg == Register::ZeroIndex) {
|
|
|
|
return "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
return regs[reg.GetSwizzledIndex(elem)].GetActiveString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes code that does a register assignment to value operation.
|
|
|
|
* @param reg The destination register to use.
|
|
|
|
* @param elem The element to use for the operation.
|
|
|
|
* @param value The code representing the value to assign.
|
|
|
|
* @param dest_num_components Number of components in the destination.
|
|
|
|
* @param value_num_components Number of components in the value.
|
|
|
|
* @param is_abs Optional, when True, applies absolute value to output.
|
|
|
|
* @param dest_elem Optional, the destination element to use for the operation.
|
|
|
|
*/
|
|
|
|
void SetRegister(const Register& reg, u64 elem, const std::string& value,
|
|
|
|
u64 dest_num_components, u64 value_num_components, bool is_abs,
|
|
|
|
u64 dest_elem) {
|
|
|
|
std::string dest = GetRegister(reg, dest_elem);
|
|
|
|
if (dest_num_components > 1) {
|
|
|
|
dest += GetSwizzle(elem);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string src = '(' + value + ')';
|
|
|
|
if (value_num_components > 1) {
|
|
|
|
src += GetSwizzle(elem);
|
|
|
|
}
|
|
|
|
|
|
|
|
src = is_abs ? "abs(" + src + ')' : src;
|
|
|
|
|
|
|
|
shader.AddLine(dest + " = " + src + ';');
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:48:06 +02:00
|
|
|
/// Build the GLSL register list.
|
2018-04-26 05:55:21 +02:00
|
|
|
void BuildRegisterList() {
|
|
|
|
for (size_t index = 0; index < Register::NumRegisters; ++index) {
|
|
|
|
regs.emplace_back(index, shader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
/// Generates code representing an input attribute register.
|
|
|
|
std::string GetInputAttribute(Attribute::Index attribute) {
|
2018-04-16 02:26:45 +02:00
|
|
|
switch (attribute) {
|
|
|
|
case Attribute::Index::Position:
|
|
|
|
return "position";
|
2018-05-30 17:58:03 +02:00
|
|
|
case Attribute::Index::TessCoordInstanceIDVertexID:
|
|
|
|
// TODO(Subv): Find out what the values are for the first two elements when inside a
|
|
|
|
// vertex shader, and what's the value of the fourth element when inside a Tess Eval
|
|
|
|
// shader.
|
|
|
|
ASSERT(stage == Maxwell3D::Regs::ShaderStage::Vertex);
|
|
|
|
return "vec4(0, 0, gl_InstanceID, gl_VertexID)";
|
2018-04-16 02:26:45 +02:00
|
|
|
default:
|
|
|
|
const u32 index{static_cast<u32>(attribute) -
|
|
|
|
static_cast<u32>(Attribute::Index::Attribute_0)};
|
|
|
|
if (attribute >= Attribute::Index::Attribute_0) {
|
|
|
|
declr_input_attribute.insert(attribute);
|
|
|
|
return "input_attribute_" + std::to_string(index);
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-17 22:28:47 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled input attribute: {}", index);
|
2018-04-16 02:26:45 +02:00
|
|
|
UNREACHABLE();
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generates code representing an output attribute register.
|
|
|
|
std::string GetOutputAttribute(Attribute::Index attribute) {
|
|
|
|
switch (attribute) {
|
|
|
|
case Attribute::Index::Position:
|
2018-04-16 02:26:45 +02:00
|
|
|
return "position";
|
2018-04-08 05:48:38 +02:00
|
|
|
default:
|
|
|
|
const u32 index{static_cast<u32>(attribute) -
|
|
|
|
static_cast<u32>(Attribute::Index::Attribute_0)};
|
|
|
|
if (attribute >= Attribute::Index::Attribute_0) {
|
|
|
|
declr_output_attribute.insert(attribute);
|
|
|
|
return "output_attribute_" + std::to_string(index);
|
|
|
|
}
|
|
|
|
|
2018-04-17 22:28:47 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled output attribute: {}", index);
|
2018-04-08 05:48:38 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:48:06 +02:00
|
|
|
/// Generates code to use for a swizzle operation.
|
|
|
|
static std::string GetSwizzle(u64 elem) {
|
|
|
|
ASSERT(elem <= 3);
|
|
|
|
std::string swizzle = ".";
|
|
|
|
swizzle += "xyzw"[elem];
|
|
|
|
return swizzle;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderWriter& shader;
|
|
|
|
ShaderWriter& declarations;
|
|
|
|
std::vector<GLSLRegister> regs;
|
|
|
|
std::set<Attribute::Index> declr_input_attribute;
|
|
|
|
std::set<Attribute::Index> declr_output_attribute;
|
|
|
|
std::array<ConstBufferEntry, Maxwell3D::Regs::MaxConstBuffers> declr_const_buffers;
|
2018-06-06 19:58:16 +02:00
|
|
|
std::vector<SamplerEntry> used_samplers;
|
2018-04-27 04:48:06 +02:00
|
|
|
const Maxwell3D::Regs::ShaderStage& stage;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GLSLGenerator {
|
|
|
|
public:
|
|
|
|
GLSLGenerator(const std::set<Subroutine>& subroutines, const ProgramCode& program_code,
|
|
|
|
u32 main_offset, Maxwell3D::Regs::ShaderStage stage)
|
|
|
|
: subroutines(subroutines), program_code(program_code), main_offset(main_offset),
|
|
|
|
stage(stage) {
|
|
|
|
|
|
|
|
Generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetShaderCode() {
|
|
|
|
return declarations.GetResult() + shader.GetResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns entries in the shader that are useful for external functions
|
|
|
|
ShaderEntries GetEntries() const {
|
2018-06-06 19:58:16 +02:00
|
|
|
return {regs.GetConstBuffersDeclarations(), regs.GetSamplers()};
|
2018-04-27 04:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Gets the Subroutine object corresponding to the specified address.
|
|
|
|
const Subroutine& GetSubroutine(u32 begin, u32 end) const {
|
|
|
|
auto iter = subroutines.find(Subroutine{begin, end});
|
|
|
|
ASSERT(iter != subroutines.end());
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
|
2018-04-19 20:34:50 +02:00
|
|
|
/// Generates code representing a 19-bit immediate value
|
|
|
|
static std::string GetImmediate19(const Instruction& instr) {
|
|
|
|
return std::to_string(instr.alu.GetImm20_19());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generates code representing a 32-bit immediate value
|
|
|
|
static std::string GetImmediate32(const Instruction& instr) {
|
|
|
|
return std::to_string(instr.alu.GetImm20_32());
|
2018-04-16 02:45:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 07:26:15 +02:00
|
|
|
/// Generates code representing a texture sampler.
|
2018-06-06 19:58:16 +02:00
|
|
|
std::string GetSampler(const Sampler& sampler) {
|
|
|
|
return regs.AccessSampler(sampler);
|
2018-04-10 07:26:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
/**
|
|
|
|
* Adds code that calls a subroutine.
|
|
|
|
* @param subroutine the subroutine to call.
|
|
|
|
*/
|
|
|
|
void CallSubroutine(const Subroutine& subroutine) {
|
|
|
|
if (subroutine.exit_method == ExitMethod::AlwaysEnd) {
|
|
|
|
shader.AddLine(subroutine.GetName() + "();");
|
|
|
|
shader.AddLine("return true;");
|
|
|
|
} else if (subroutine.exit_method == ExitMethod::Conditional) {
|
|
|
|
shader.AddLine("if (" + subroutine.GetName() + "()) { return true; }");
|
|
|
|
} else {
|
|
|
|
shader.AddLine(subroutine.GetName() + "();");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:09:50 +02:00
|
|
|
/*
|
|
|
|
* Writes code that assigns a predicate boolean variable.
|
|
|
|
* @param pred The id of the predicate to write to.
|
|
|
|
* @param value The expression value to assign to the predicate.
|
|
|
|
*/
|
|
|
|
void SetPredicate(u64 pred, const std::string& value) {
|
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
// Can't assign to the constant predicate.
|
|
|
|
ASSERT(pred != static_cast<u64>(Pred::UnusedIndex));
|
|
|
|
|
|
|
|
std::string variable = 'p' + std::to_string(pred);
|
|
|
|
shader.AddLine(variable + " = " + value + ';');
|
|
|
|
declr_predicates.insert(std::move(variable));
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:16:55 +02:00
|
|
|
/*
|
|
|
|
* Returns the condition to use in the 'if' for a predicated instruction.
|
|
|
|
* @param instr Instruction to generate the if condition for.
|
|
|
|
* @returns string containing the predicate condition.
|
|
|
|
*/
|
2018-05-21 00:53:06 +02:00
|
|
|
std::string GetPredicateCondition(u64 index, bool negate) const {
|
2018-04-20 16:16:55 +02:00
|
|
|
using Tegra::Shader::Pred;
|
2018-05-21 00:53:06 +02:00
|
|
|
std::string variable;
|
2018-04-20 16:16:55 +02:00
|
|
|
|
2018-05-21 00:53:06 +02:00
|
|
|
// Index 7 is used as an 'Always True' condition.
|
|
|
|
if (index == static_cast<u64>(Pred::UnusedIndex))
|
|
|
|
variable = "true";
|
|
|
|
else
|
|
|
|
variable = 'p' + std::to_string(index);
|
2018-04-20 16:16:55 +02:00
|
|
|
|
2018-05-21 00:53:06 +02:00
|
|
|
if (negate) {
|
2018-04-20 16:16:55 +02:00
|
|
|
return "!(" + variable + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2018-05-25 00:22:36 +02:00
|
|
|
/**
|
|
|
|
* Returns the comparison string to use to compare two values in the 'set' family of
|
|
|
|
* instructions.
|
|
|
|
* @params condition The condition used in the 'set'-family instruction.
|
|
|
|
* @returns String corresponding to the GLSL operator that matches the desired comparison.
|
|
|
|
*/
|
|
|
|
std::string GetPredicateComparison(Tegra::Shader::PredCondition condition) const {
|
|
|
|
using Tegra::Shader::PredCondition;
|
|
|
|
static const std::unordered_map<PredCondition, const char*> PredicateComparisonStrings = {
|
2018-06-05 02:53:26 +02:00
|
|
|
{PredCondition::LessThan, "<"}, {PredCondition::Equal, "=="},
|
|
|
|
{PredCondition::LessEqual, "<="}, {PredCondition::GreaterThan, ">"},
|
|
|
|
{PredCondition::NotEqual, "!="}, {PredCondition::GreaterEqual, ">="},
|
2018-05-25 00:22:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
auto comparison = PredicateComparisonStrings.find(condition);
|
|
|
|
ASSERT_MSG(comparison != PredicateComparisonStrings.end(),
|
|
|
|
"Unknown predicate comparison operation");
|
|
|
|
return comparison->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the operator string to use to combine two predicates in the 'setp' family of
|
|
|
|
* instructions.
|
|
|
|
* @params operation The operator used in the 'setp'-family instruction.
|
|
|
|
* @returns String corresponding to the GLSL operator that matches the desired operator.
|
|
|
|
*/
|
|
|
|
std::string GetPredicateCombiner(Tegra::Shader::PredOperation operation) const {
|
|
|
|
using Tegra::Shader::PredOperation;
|
|
|
|
static const std::unordered_map<PredOperation, const char*> PredicateOperationStrings = {
|
|
|
|
{PredOperation::And, "&&"},
|
|
|
|
{PredOperation::Or, "||"},
|
2018-05-25 00:28:54 +02:00
|
|
|
{PredOperation::Xor, "^^"},
|
2018-05-25 00:22:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
auto op = PredicateOperationStrings.find(operation);
|
|
|
|
ASSERT_MSG(op != PredicateOperationStrings.end(), "Unknown predicate operation");
|
|
|
|
return op->second;
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:02:28 +02:00
|
|
|
/*
|
|
|
|
* Returns whether the instruction at the specified offset is a 'sched' instruction.
|
|
|
|
* Sched instructions always appear before a sequence of 3 instructions.
|
|
|
|
*/
|
|
|
|
bool IsSchedInstruction(u32 offset) const {
|
|
|
|
// sched instructions appear once every 4 instructions.
|
|
|
|
static constexpr size_t SchedPeriod = 4;
|
|
|
|
u32 absolute_offset = offset - main_offset;
|
|
|
|
|
|
|
|
return (absolute_offset % SchedPeriod) == 0;
|
|
|
|
}
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
/**
|
|
|
|
* Compiles a single instruction from Tegra to GLSL.
|
|
|
|
* @param offset the offset of the Tegra shader instruction.
|
|
|
|
* @return the offset of the next instruction to execute. Usually it is the current offset
|
|
|
|
* + 1. If the current instruction always terminates the program, returns PROGRAM_END.
|
|
|
|
*/
|
|
|
|
u32 CompileInstr(u32 offset) {
|
2018-04-20 16:02:28 +02:00
|
|
|
// Ignore sched instructions when generating code.
|
2018-04-21 02:49:05 +02:00
|
|
|
if (IsSchedInstruction(offset)) {
|
2018-04-20 16:02:28 +02:00
|
|
|
return offset + 1;
|
2018-04-21 02:49:05 +02:00
|
|
|
}
|
2018-04-20 16:02:28 +02:00
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
const Instruction instr = {program_code[offset]};
|
2018-04-21 02:49:05 +02:00
|
|
|
const auto opcode = OpCode::Decode(instr);
|
|
|
|
|
|
|
|
// Decoding failure
|
|
|
|
if (!opcode) {
|
2018-04-21 04:25:29 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled instruction: {0:x}", instr.value);
|
2018-04-21 02:49:05 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-21 02:49:05 +02:00
|
|
|
shader.AddLine("// " + std::to_string(offset) + ": " + opcode->GetName());
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-20 16:16:55 +02:00
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
ASSERT_MSG(instr.pred.full_pred != Pred::NeverExecute,
|
|
|
|
"NeverExecute predicate not implemented");
|
|
|
|
|
|
|
|
if (instr.pred.pred_index != static_cast<u64>(Pred::UnusedIndex)) {
|
2018-05-21 00:53:06 +02:00
|
|
|
shader.AddLine("if (" +
|
|
|
|
GetPredicateCondition(instr.pred.pred_index, instr.negate_pred != 0) +
|
|
|
|
')');
|
2018-04-20 16:16:55 +02:00
|
|
|
shader.AddLine('{');
|
|
|
|
++shader.scope;
|
|
|
|
}
|
|
|
|
|
2018-04-21 02:49:05 +02:00
|
|
|
switch (opcode->GetType()) {
|
2018-04-08 05:48:38 +02:00
|
|
|
case OpCode::Type::Arithmetic: {
|
2018-04-10 05:39:44 +02:00
|
|
|
std::string op_a = instr.alu.negate_a ? "-" : "";
|
2018-04-29 01:59:30 +02:00
|
|
|
op_a += regs.GetRegisterAsFloat(instr.gpr8);
|
2018-04-10 05:39:44 +02:00
|
|
|
if (instr.alu.abs_a) {
|
2018-04-27 04:48:06 +02:00
|
|
|
op_a = "abs(" + op_a + ')';
|
2018-04-10 05:39:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string op_b = instr.alu.negate_b ? "-" : "";
|
2018-04-16 02:45:56 +02:00
|
|
|
|
|
|
|
if (instr.is_b_imm) {
|
2018-04-19 20:34:50 +02:00
|
|
|
op_b += GetImmediate19(instr);
|
2018-04-10 05:39:44 +02:00
|
|
|
} else {
|
2018-04-16 02:45:56 +02:00
|
|
|
if (instr.is_b_gpr) {
|
2018-04-29 01:59:30 +02:00
|
|
|
op_b += regs.GetRegisterAsFloat(instr.gpr20);
|
2018-04-16 02:45:56 +02:00
|
|
|
} else {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Float);
|
2018-04-16 02:45:56 +02:00
|
|
|
}
|
2018-04-10 05:39:44 +02:00
|
|
|
}
|
2018-04-16 02:45:56 +02:00
|
|
|
|
2018-04-10 05:39:44 +02:00
|
|
|
if (instr.alu.abs_b) {
|
2018-04-27 04:48:06 +02:00
|
|
|
op_b = "abs(" + op_b + ')';
|
2018-04-10 05:39:44 +02:00
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-21 02:49:05 +02:00
|
|
|
switch (opcode->GetId()) {
|
2018-04-29 19:50:52 +02:00
|
|
|
case OpCode::Id::MOV_C:
|
|
|
|
case OpCode::Id::MOV_R: {
|
2018-04-29 19:13:13 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_b, 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-27 05:21:17 +02:00
|
|
|
case OpCode::Id::MOV32_IMM: {
|
|
|
|
// mov32i doesn't have abs or neg bits.
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, GetImmediate32(instr), 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-10 05:39:44 +02:00
|
|
|
case OpCode::Id::FMUL_C:
|
2018-04-16 02:45:56 +02:00
|
|
|
case OpCode::Id::FMUL_R:
|
|
|
|
case OpCode::Id::FMUL_IMM: {
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a + " * " + op_b, 1, 1, instr.alu.abs_d);
|
2018-04-10 05:39:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-19 20:34:50 +02:00
|
|
|
case OpCode::Id::FMUL32_IMM: {
|
|
|
|
// fmul32i doesn't have abs or neg bits.
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(
|
2018-04-29 01:59:30 +02:00
|
|
|
instr.gpr0, 0,
|
|
|
|
regs.GetRegisterAsFloat(instr.gpr8) + " * " + GetImmediate32(instr), 1, 1);
|
2018-04-19 20:34:50 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-10 05:39:44 +02:00
|
|
|
case OpCode::Id::FADD_C:
|
2018-04-16 02:45:56 +02:00
|
|
|
case OpCode::Id::FADD_R:
|
|
|
|
case OpCode::Id::FADD_IMM: {
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a + " + " + op_b, 1, 1, instr.alu.abs_d);
|
2018-04-08 05:48:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-10 06:02:12 +02:00
|
|
|
case OpCode::Id::MUFU: {
|
|
|
|
switch (instr.sub_op) {
|
2018-04-16 02:59:37 +02:00
|
|
|
case SubOp::Cos:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "cos(" + op_a + ')', 1, 1,
|
|
|
|
instr.alu.abs_d);
|
2018-04-16 02:59:37 +02:00
|
|
|
break;
|
|
|
|
case SubOp::Sin:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "sin(" + op_a + ')', 1, 1,
|
|
|
|
instr.alu.abs_d);
|
2018-04-16 02:59:37 +02:00
|
|
|
break;
|
|
|
|
case SubOp::Ex2:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "exp2(" + op_a + ')', 1, 1,
|
|
|
|
instr.alu.abs_d);
|
2018-04-16 02:59:37 +02:00
|
|
|
break;
|
|
|
|
case SubOp::Lg2:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "log2(" + op_a + ')', 1, 1,
|
|
|
|
instr.alu.abs_d);
|
2018-04-16 02:59:37 +02:00
|
|
|
break;
|
2018-04-10 06:02:12 +02:00
|
|
|
case SubOp::Rcp:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "1.0 / " + op_a, 1, 1, instr.alu.abs_d);
|
2018-04-16 02:59:37 +02:00
|
|
|
break;
|
|
|
|
case SubOp::Rsq:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "inversesqrt(" + op_a + ')', 1, 1,
|
|
|
|
instr.alu.abs_d);
|
2018-04-16 02:59:37 +02:00
|
|
|
break;
|
|
|
|
case SubOp::Min:
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, "min(" + op_a + "," + op_b + ')', 1, 1,
|
|
|
|
instr.alu.abs_d);
|
2018-04-10 06:02:12 +02:00
|
|
|
break;
|
|
|
|
default:
|
2018-04-21 04:25:29 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled MUFU sub op: {0:x}",
|
2018-04-17 22:28:47 +02:00
|
|
|
static_cast<unsigned>(instr.sub_op.Value()));
|
|
|
|
UNREACHABLE();
|
2018-04-10 06:02:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-05-25 01:37:18 +02:00
|
|
|
case OpCode::Id::FMNMX_C:
|
|
|
|
case OpCode::Id::FMNMX_R:
|
|
|
|
case OpCode::Id::FMNMX_IMM: {
|
2018-05-21 00:53:06 +02:00
|
|
|
std::string condition =
|
|
|
|
GetPredicateCondition(instr.alu.fmnmx.pred, instr.alu.fmnmx.negate_pred != 0);
|
|
|
|
std::string parameters = op_a + ',' + op_b;
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0,
|
|
|
|
'(' + condition + ") ? min(" + parameters + ") : max(" +
|
|
|
|
parameters + ')',
|
|
|
|
1, 1);
|
|
|
|
break;
|
|
|
|
}
|
2018-06-01 06:03:23 +02:00
|
|
|
case OpCode::Id::RRO_C:
|
|
|
|
case OpCode::Id::RRO_R:
|
|
|
|
case OpCode::Id::RRO_IMM: {
|
|
|
|
// Currently RRO is only implemented as a register move.
|
|
|
|
// Usage of `abs_b` and `negate_b` here should also be correct.
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_b, 1, 1);
|
|
|
|
NGLOG_WARNING(HW_GPU, "RRO instruction is incomplete");
|
2018-04-21 04:27:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-10 05:39:44 +02:00
|
|
|
default: {
|
2018-04-21 04:25:29 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled arithmetic instruction: {}", opcode->GetName());
|
2018-04-17 22:28:47 +02:00
|
|
|
UNREACHABLE();
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
2018-04-10 05:39:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-06-04 20:24:31 +02:00
|
|
|
case OpCode::Type::Logic: {
|
|
|
|
std::string op_a = regs.GetRegisterAsInteger(instr.gpr8, 0, false);
|
|
|
|
|
|
|
|
if (instr.alu.lop.invert_a)
|
|
|
|
op_a = "~(" + op_a + ')';
|
|
|
|
|
|
|
|
switch (opcode->GetId()) {
|
|
|
|
case OpCode::Id::LOP32I: {
|
|
|
|
u32 imm = static_cast<u32>(instr.alu.imm20_32.Value());
|
|
|
|
|
|
|
|
if (instr.alu.lop.invert_b)
|
|
|
|
imm = ~imm;
|
|
|
|
|
|
|
|
switch (instr.alu.lop.operation) {
|
|
|
|
case Tegra::Shader::LogicOperation::And: {
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, false, 0,
|
|
|
|
'(' + op_a + " & " + std::to_string(imm) + ')', 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Tegra::Shader::LogicOperation::Or: {
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, false, 0,
|
|
|
|
'(' + op_a + " | " + std::to_string(imm) + ')', 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Tegra::Shader::LogicOperation::Xor: {
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, false, 0,
|
|
|
|
'(' + op_a + " ^ " + std::to_string(imm) + ')', 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unimplemented lop32i operation: {}",
|
|
|
|
static_cast<u32>(instr.alu.lop.operation.Value()));
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled logic instruction: {}", opcode->GetName());
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-06-05 04:15:19 +02:00
|
|
|
|
|
|
|
case OpCode::Type::Shift: {
|
2018-06-06 00:38:25 +02:00
|
|
|
std::string op_a = regs.GetRegisterAsInteger(instr.gpr8, 0, true);
|
2018-06-05 04:15:19 +02:00
|
|
|
std::string op_b;
|
|
|
|
|
|
|
|
if (instr.is_b_imm) {
|
|
|
|
op_b += '(' + std::to_string(instr.alu.GetSignedImm20_20()) + ')';
|
|
|
|
} else {
|
|
|
|
if (instr.is_b_gpr) {
|
|
|
|
op_b += regs.GetRegisterAsInteger(instr.gpr20);
|
|
|
|
} else {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Integer);
|
2018-06-05 04:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (opcode->GetId()) {
|
|
|
|
case OpCode::Id::SHL_C:
|
|
|
|
case OpCode::Id::SHL_R:
|
|
|
|
case OpCode::Id::SHL_IMM:
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, true, 0, op_a + " << " + op_b, 1, 1);
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled shift instruction: {}", opcode->GetName());
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-05 02:03:47 +02:00
|
|
|
case OpCode::Type::ScaledAdd: {
|
|
|
|
std::string op_a = regs.GetRegisterAsInteger(instr.gpr8);
|
|
|
|
|
|
|
|
if (instr.iscadd.negate_a)
|
|
|
|
op_a = '-' + op_a;
|
|
|
|
|
|
|
|
std::string op_b = instr.iscadd.negate_b ? "-" : "";
|
|
|
|
|
|
|
|
if (instr.is_b_imm) {
|
2018-06-05 04:15:19 +02:00
|
|
|
op_b += '(' + std::to_string(instr.alu.GetSignedImm20_20()) + ')';
|
2018-06-05 02:03:47 +02:00
|
|
|
} else {
|
|
|
|
if (instr.is_b_gpr) {
|
|
|
|
op_b += regs.GetRegisterAsInteger(instr.gpr20);
|
|
|
|
} else {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Integer);
|
2018-06-05 02:03:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string shift = std::to_string(instr.iscadd.shift_amount.Value());
|
|
|
|
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, true, 0,
|
|
|
|
"((" + op_a + " << " + shift + ") + " + op_b + ')', 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-10 05:39:44 +02:00
|
|
|
case OpCode::Type::Ffma: {
|
2018-04-29 01:59:30 +02:00
|
|
|
std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
|
2018-04-10 05:39:44 +02:00
|
|
|
std::string op_b = instr.ffma.negate_b ? "-" : "";
|
|
|
|
std::string op_c = instr.ffma.negate_c ? "-" : "";
|
|
|
|
|
2018-04-21 02:49:05 +02:00
|
|
|
switch (opcode->GetId()) {
|
2018-04-08 05:48:38 +02:00
|
|
|
case OpCode::Id::FFMA_CR: {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Float);
|
2018-04-29 01:59:30 +02:00
|
|
|
op_c += regs.GetRegisterAsFloat(instr.gpr39);
|
2018-04-16 02:45:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpCode::Id::FFMA_RR: {
|
2018-04-29 01:59:30 +02:00
|
|
|
op_b += regs.GetRegisterAsFloat(instr.gpr20);
|
|
|
|
op_c += regs.GetRegisterAsFloat(instr.gpr39);
|
2018-04-16 02:45:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpCode::Id::FFMA_RC: {
|
2018-04-29 01:59:30 +02:00
|
|
|
op_b += regs.GetRegisterAsFloat(instr.gpr39);
|
2018-06-06 04:45:22 +02:00
|
|
|
op_c += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Float);
|
2018-04-16 02:45:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpCode::Id::FFMA_IMM: {
|
2018-04-19 20:34:50 +02:00
|
|
|
op_b += GetImmediate19(instr);
|
2018-04-29 01:59:30 +02:00
|
|
|
op_c += regs.GetRegisterAsFloat(instr.gpr39);
|
2018-04-08 05:48:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2018-04-21 04:25:29 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled FFMA instruction: {}", opcode->GetName());
|
2018-04-17 22:28:47 +02:00
|
|
|
UNREACHABLE();
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-16 02:45:56 +02:00
|
|
|
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a + " * " + op_b + " + " + op_c, 1, 1);
|
2018-04-08 05:48:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-29 02:01:36 +02:00
|
|
|
case OpCode::Type::Conversion: {
|
|
|
|
ASSERT_MSG(instr.conversion.size == Register::Size::Word, "Unimplemented");
|
|
|
|
ASSERT_MSG(!instr.conversion.negate_a, "Unimplemented");
|
|
|
|
ASSERT_MSG(!instr.conversion.saturate_a, "Unimplemented");
|
|
|
|
|
|
|
|
switch (opcode->GetId()) {
|
2018-06-04 18:57:47 +02:00
|
|
|
case OpCode::Id::I2I_R: {
|
2018-05-30 05:10:44 +02:00
|
|
|
ASSERT_MSG(!instr.conversion.selector, "Unimplemented");
|
|
|
|
|
2018-04-29 02:01:36 +02:00
|
|
|
std::string op_a =
|
2018-06-05 01:05:12 +02:00
|
|
|
regs.GetRegisterAsInteger(instr.gpr20, 0, instr.conversion.is_input_signed);
|
2018-04-29 02:01:36 +02:00
|
|
|
|
|
|
|
if (instr.conversion.abs_a) {
|
|
|
|
op_a = "abs(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:05:12 +02:00
|
|
|
regs.SetRegisterToInteger(instr.gpr0, instr.conversion.is_output_signed, 0, op_a, 1,
|
|
|
|
1);
|
2018-04-29 02:01:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-04 18:57:47 +02:00
|
|
|
case OpCode::Id::I2F_R: {
|
2018-06-05 01:05:12 +02:00
|
|
|
ASSERT_MSG(!instr.conversion.selector, "Unimplemented");
|
2018-06-04 18:57:47 +02:00
|
|
|
std::string op_a =
|
2018-06-05 01:05:12 +02:00
|
|
|
regs.GetRegisterAsInteger(instr.gpr20, 0, instr.conversion.is_input_signed);
|
2018-06-04 18:57:47 +02:00
|
|
|
|
|
|
|
if (instr.conversion.abs_a) {
|
|
|
|
op_a = "abs(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a, 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
2018-05-30 05:10:44 +02:00
|
|
|
case OpCode::Id::F2F_R: {
|
2018-06-05 01:05:12 +02:00
|
|
|
// TODO(Subv): Implement rounding operations.
|
|
|
|
ASSERT_MSG(instr.conversion.f2f.rounding == 0, "Unimplemented rounding operation");
|
2018-05-30 05:52:54 +02:00
|
|
|
std::string op_a = regs.GetRegisterAsFloat(instr.gpr20);
|
|
|
|
|
|
|
|
if (instr.conversion.abs_a) {
|
|
|
|
op_a = "abs(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a, 1, 1);
|
2018-05-30 05:10:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-05 01:05:12 +02:00
|
|
|
case OpCode::Id::F2I_R: {
|
|
|
|
std::string op_a = regs.GetRegisterAsFloat(instr.gpr20);
|
|
|
|
|
|
|
|
if (instr.conversion.abs_a) {
|
|
|
|
op_a = "abs(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
using Tegra::Shader::FloatRoundingOp;
|
|
|
|
switch (instr.conversion.f2i.rounding) {
|
|
|
|
case FloatRoundingOp::None:
|
|
|
|
break;
|
|
|
|
case FloatRoundingOp::Floor:
|
|
|
|
op_a = "floor(" + op_a + ')';
|
|
|
|
break;
|
|
|
|
case FloatRoundingOp::Ceil:
|
|
|
|
op_a = "ceil(" + op_a + ')';
|
|
|
|
break;
|
|
|
|
case FloatRoundingOp::Trunc:
|
|
|
|
op_a = "trunc(" + op_a + ')';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unimplemented f2i rounding mode {}",
|
|
|
|
static_cast<u32>(instr.conversion.f2i.rounding.Value()));
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (instr.conversion.is_output_signed) {
|
|
|
|
op_a = "int(" + op_a + ')';
|
|
|
|
} else {
|
|
|
|
op_a = "uint(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, instr.conversion.is_output_signed, 0, op_a, 1,
|
|
|
|
1);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-29 02:01:36 +02:00
|
|
|
default: {
|
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled conversion instruction: {}", opcode->GetName());
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
case OpCode::Type::Memory: {
|
2018-04-10 05:39:44 +02:00
|
|
|
const Attribute::Index attribute = instr.attribute.fmt20.index;
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-21 02:49:05 +02:00
|
|
|
switch (opcode->GetId()) {
|
2018-04-08 05:48:38 +02:00
|
|
|
case OpCode::Id::LD_A: {
|
2018-04-10 07:26:15 +02:00
|
|
|
ASSERT_MSG(instr.attribute.fmt20.size == 0, "untested");
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToInputAttibute(instr.gpr0, instr.attribute.fmt20.element,
|
|
|
|
attribute);
|
2018-04-08 05:48:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-06 05:46:23 +02:00
|
|
|
case OpCode::Id::LD_C: {
|
|
|
|
ASSERT_MSG(instr.ld_c.unknown == 0, "Unimplemented");
|
|
|
|
|
|
|
|
std::string op_a =
|
|
|
|
regs.GetUniformIndirect(instr.cbuf36.index, instr.cbuf36.offset + 0, instr.gpr8,
|
|
|
|
GLSLRegister::Type::Float);
|
|
|
|
std::string op_b =
|
|
|
|
regs.GetUniformIndirect(instr.cbuf36.index, instr.cbuf36.offset + 4, instr.gpr8,
|
|
|
|
GLSLRegister::Type::Float);
|
|
|
|
|
|
|
|
switch (instr.ld_c.type.Value()) {
|
|
|
|
case Tegra::Shader::UniformType::Single:
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a, 1, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tegra::Shader::UniformType::Double:
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, op_a, 1, 1);
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0.Value() + 1, 0, op_b, 1, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled type: {}",
|
|
|
|
static_cast<unsigned>(instr.ld_c.type.Value()));
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
case OpCode::Id::ST_A: {
|
2018-04-10 07:26:15 +02:00
|
|
|
ASSERT_MSG(instr.attribute.fmt20.size == 0, "untested");
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetOutputAttributeToRegister(attribute, instr.attribute.fmt20.element,
|
|
|
|
instr.gpr0);
|
2018-04-08 05:48:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-01 05:22:21 +02:00
|
|
|
case OpCode::Id::TEX: {
|
|
|
|
ASSERT_MSG(instr.attribute.fmt20.size == 4, "untested");
|
|
|
|
const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
|
|
|
|
const std::string op_b = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
|
|
|
|
const std::string sampler = GetSampler(instr.sampler);
|
|
|
|
const std::string coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");";
|
|
|
|
// Add an extra scope and declare the texture coords inside to prevent overwriting
|
|
|
|
// them in case they are used as outputs of the texs instruction.
|
|
|
|
shader.AddLine("{");
|
|
|
|
++shader.scope;
|
|
|
|
shader.AddLine(coord);
|
|
|
|
const std::string texture = "texture(" + sampler + ", coords)";
|
|
|
|
|
|
|
|
size_t dest_elem{};
|
|
|
|
for (size_t elem = 0; elem < instr.attribute.fmt20.size; ++elem) {
|
|
|
|
if (!instr.tex.IsComponentEnabled(elem)) {
|
|
|
|
// Skip disabled components
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, elem, texture, 1, 4, false, dest_elem);
|
|
|
|
++dest_elem;
|
|
|
|
}
|
|
|
|
--shader.scope;
|
|
|
|
shader.AddLine("}");
|
|
|
|
break;
|
|
|
|
}
|
2018-04-10 07:26:15 +02:00
|
|
|
case OpCode::Id::TEXS: {
|
|
|
|
ASSERT_MSG(instr.attribute.fmt20.size == 4, "untested");
|
2018-04-29 01:59:30 +02:00
|
|
|
const std::string op_a = regs.GetRegisterAsFloat(instr.gpr8);
|
|
|
|
const std::string op_b = regs.GetRegisterAsFloat(instr.gpr20);
|
2018-04-10 07:26:15 +02:00
|
|
|
const std::string sampler = GetSampler(instr.sampler);
|
2018-04-19 20:33:17 +02:00
|
|
|
const std::string coord = "vec2 coords = vec2(" + op_a + ", " + op_b + ");";
|
2018-06-01 06:03:23 +02:00
|
|
|
// Add an extra scope and declare the texture coords inside to prevent
|
|
|
|
// overwriting them in case they are used as outputs of the texs instruction.
|
2018-04-19 20:33:17 +02:00
|
|
|
shader.AddLine("{");
|
|
|
|
++shader.scope;
|
|
|
|
shader.AddLine(coord);
|
|
|
|
const std::string texture = "texture(" + sampler + ", coords)";
|
2018-06-01 04:57:32 +02:00
|
|
|
|
|
|
|
// TEXS has two destination registers. RG goes into gpr0+0 and gpr0+1, and BA goes
|
|
|
|
// into gpr28+0 and gpr28+1
|
|
|
|
size_t offset{};
|
2018-06-03 18:08:17 +02:00
|
|
|
|
2018-06-01 04:57:32 +02:00
|
|
|
for (const auto& dest : {instr.gpr0.Value(), instr.gpr28.Value()}) {
|
|
|
|
for (unsigned elem = 0; elem < 2; ++elem) {
|
2018-06-03 18:08:17 +02:00
|
|
|
if (!instr.texs.IsComponentEnabled(elem)) {
|
|
|
|
// Skip disabled components
|
|
|
|
continue;
|
2018-06-01 04:57:32 +02:00
|
|
|
}
|
|
|
|
regs.SetRegisterToFloat(dest, elem + offset, texture, 1, 4, false, elem);
|
|
|
|
}
|
2018-06-03 18:08:17 +02:00
|
|
|
|
|
|
|
if (!instr.texs.HasTwoDestinations()) {
|
|
|
|
// Skip the second destination
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-01 04:57:32 +02:00
|
|
|
offset += 2;
|
2018-04-10 07:26:15 +02:00
|
|
|
}
|
2018-04-19 20:33:17 +02:00
|
|
|
--shader.scope;
|
|
|
|
shader.AddLine("}");
|
2018-04-10 07:26:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
default: {
|
2018-04-21 04:25:29 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled memory instruction: {}", opcode->GetName());
|
2018-04-17 22:28:47 +02:00
|
|
|
UNREACHABLE();
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-25 05:42:54 +02:00
|
|
|
case OpCode::Type::FloatSetPredicate: {
|
2018-04-20 16:09:50 +02:00
|
|
|
std::string op_a = instr.fsetp.neg_a ? "-" : "";
|
2018-04-29 01:59:30 +02:00
|
|
|
op_a += regs.GetRegisterAsFloat(instr.gpr8);
|
2018-04-20 16:09:50 +02:00
|
|
|
|
|
|
|
if (instr.fsetp.abs_a) {
|
|
|
|
op_a = "abs(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string op_b{};
|
|
|
|
|
|
|
|
if (instr.is_b_imm) {
|
|
|
|
if (instr.fsetp.neg_b) {
|
|
|
|
// Only the immediate version of fsetp has a neg_b bit.
|
|
|
|
op_b += '-';
|
|
|
|
}
|
|
|
|
op_b += '(' + GetImmediate19(instr) + ')';
|
|
|
|
} else {
|
|
|
|
if (instr.is_b_gpr) {
|
2018-04-29 01:59:30 +02:00
|
|
|
op_b += regs.GetRegisterAsFloat(instr.gpr20);
|
2018-04-20 16:09:50 +02:00
|
|
|
} else {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Float);
|
2018-04-20 16:09:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (instr.fsetp.abs_b) {
|
|
|
|
op_b = "abs(" + op_b + ')';
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-20 16:09:50 +02:00
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
// We can't use the constant predicate as destination.
|
|
|
|
ASSERT(instr.fsetp.pred3 != static_cast<u64>(Pred::UnusedIndex));
|
|
|
|
|
2018-05-25 00:22:36 +02:00
|
|
|
std::string second_pred =
|
|
|
|
GetPredicateCondition(instr.fsetp.pred39, instr.fsetp.neg_pred != 0);
|
|
|
|
|
|
|
|
std::string comparator = GetPredicateComparison(instr.fsetp.cond);
|
|
|
|
std::string combiner = GetPredicateCombiner(instr.fsetp.op);
|
|
|
|
|
|
|
|
std::string predicate = '(' + op_a + ") " + comparator + " (" + op_b + ')';
|
|
|
|
// Set the primary predicate to the result of Predicate OP SecondPredicate
|
|
|
|
SetPredicate(instr.fsetp.pred3,
|
|
|
|
'(' + predicate + ") " + combiner + " (" + second_pred + ')');
|
|
|
|
|
|
|
|
if (instr.fsetp.pred0 != static_cast<u64>(Pred::UnusedIndex)) {
|
2018-06-01 06:03:23 +02:00
|
|
|
// Set the secondary predicate to the result of !Predicate OP SecondPredicate,
|
|
|
|
// if enabled
|
2018-05-25 00:22:36 +02:00
|
|
|
SetPredicate(instr.fsetp.pred0,
|
|
|
|
"!(" + predicate + ") " + combiner + " (" + second_pred + ')');
|
2018-04-20 16:09:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-06-04 18:12:03 +02:00
|
|
|
case OpCode::Type::IntegerSetPredicate: {
|
|
|
|
std::string op_a = regs.GetRegisterAsInteger(instr.gpr8, 0, instr.isetp.is_signed);
|
|
|
|
|
|
|
|
std::string op_b{};
|
|
|
|
|
|
|
|
ASSERT_MSG(!instr.is_b_imm, "ISETP_IMM not implemented");
|
|
|
|
|
|
|
|
if (instr.is_b_gpr) {
|
|
|
|
op_b += regs.GetRegisterAsInteger(instr.gpr20, 0, instr.isetp.is_signed);
|
|
|
|
} else {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Integer);
|
2018-06-04 18:12:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
using Tegra::Shader::Pred;
|
|
|
|
// We can't use the constant predicate as destination.
|
|
|
|
ASSERT(instr.isetp.pred3 != static_cast<u64>(Pred::UnusedIndex));
|
|
|
|
|
|
|
|
std::string second_pred =
|
|
|
|
GetPredicateCondition(instr.isetp.pred39, instr.isetp.neg_pred != 0);
|
|
|
|
|
|
|
|
std::string comparator = GetPredicateComparison(instr.isetp.cond);
|
|
|
|
std::string combiner = GetPredicateCombiner(instr.isetp.op);
|
|
|
|
|
|
|
|
std::string predicate = '(' + op_a + ") " + comparator + " (" + op_b + ')';
|
|
|
|
// Set the primary predicate to the result of Predicate OP SecondPredicate
|
|
|
|
SetPredicate(instr.isetp.pred3,
|
|
|
|
'(' + predicate + ") " + combiner + " (" + second_pred + ')');
|
|
|
|
|
|
|
|
if (instr.isetp.pred0 != static_cast<u64>(Pred::UnusedIndex)) {
|
|
|
|
// Set the secondary predicate to the result of !Predicate OP SecondPredicate,
|
|
|
|
// if enabled
|
|
|
|
SetPredicate(instr.isetp.pred0,
|
|
|
|
"!(" + predicate + ") " + combiner + " (" + second_pred + ')');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-25 18:17:38 +02:00
|
|
|
case OpCode::Type::FloatSet: {
|
|
|
|
std::string op_a = instr.fset.neg_a ? "-" : "";
|
2018-04-29 01:59:30 +02:00
|
|
|
op_a += regs.GetRegisterAsFloat(instr.gpr8);
|
2018-04-25 18:17:38 +02:00
|
|
|
|
|
|
|
if (instr.fset.abs_a) {
|
|
|
|
op_a = "abs(" + op_a + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string op_b = instr.fset.neg_b ? "-" : "";
|
|
|
|
|
|
|
|
if (instr.is_b_imm) {
|
|
|
|
std::string imm = GetImmediate19(instr);
|
|
|
|
if (instr.fset.neg_imm)
|
|
|
|
op_b += "(-" + imm + ')';
|
|
|
|
else
|
|
|
|
op_b += imm;
|
|
|
|
} else {
|
|
|
|
if (instr.is_b_gpr) {
|
2018-04-29 01:59:30 +02:00
|
|
|
op_b += regs.GetRegisterAsFloat(instr.gpr20);
|
2018-04-25 18:17:38 +02:00
|
|
|
} else {
|
2018-06-06 04:45:22 +02:00
|
|
|
op_b += regs.GetUniform(instr.cbuf34.index, instr.cbuf34.offset,
|
|
|
|
GLSLRegister::Type::Float);
|
2018-04-25 18:17:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (instr.fset.abs_b) {
|
2018-04-27 04:48:06 +02:00
|
|
|
op_b = "abs(" + op_b + ')';
|
2018-04-25 18:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The fset instruction sets a register to 1.0 if the condition is true, and to 0
|
|
|
|
// otherwise.
|
2018-05-25 00:28:54 +02:00
|
|
|
std::string second_pred =
|
|
|
|
GetPredicateCondition(instr.fset.pred39, instr.fset.neg_pred != 0);
|
|
|
|
|
|
|
|
std::string comparator = GetPredicateComparison(instr.fset.cond);
|
|
|
|
std::string combiner = GetPredicateCombiner(instr.fset.op);
|
|
|
|
|
|
|
|
std::string predicate = "(((" + op_a + ") " + comparator + " (" + op_b + ")) " +
|
|
|
|
combiner + " (" + second_pred + "))";
|
|
|
|
|
2018-06-04 18:58:29 +02:00
|
|
|
if (instr.fset.bf) {
|
|
|
|
regs.SetRegisterToFloat(instr.gpr0, 0, predicate + " ? 1.0 : 0.0", 1, 1);
|
|
|
|
} else {
|
|
|
|
regs.SetRegisterToInteger(instr.gpr0, false, 0, predicate + " ? 0xFFFFFFFF : 0", 1,
|
|
|
|
1);
|
|
|
|
}
|
2018-04-25 18:17:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
default: {
|
2018-04-21 02:49:05 +02:00
|
|
|
switch (opcode->GetId()) {
|
2018-04-08 05:48:38 +02:00
|
|
|
case OpCode::Id::EXIT: {
|
2018-04-26 05:10:41 +02:00
|
|
|
// Final color output is currently hardcoded to GPR0-3 for fragment shaders
|
|
|
|
if (stage == Maxwell3D::Regs::ShaderStage::Fragment) {
|
2018-04-29 01:59:30 +02:00
|
|
|
shader.AddLine("color.r = " + regs.GetRegisterAsFloat(0) + ';');
|
|
|
|
shader.AddLine("color.g = " + regs.GetRegisterAsFloat(1) + ';');
|
|
|
|
shader.AddLine("color.b = " + regs.GetRegisterAsFloat(2) + ';');
|
|
|
|
shader.AddLine("color.a = " + regs.GetRegisterAsFloat(3) + ';');
|
2018-04-26 05:10:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
shader.AddLine("return true;");
|
2018-06-05 02:18:11 +02:00
|
|
|
if (instr.pred.pred_index == static_cast<u64>(Pred::UnusedIndex)) {
|
|
|
|
// If this is an unconditional exit then just end processing here, otherwise we
|
|
|
|
// have to account for the possibility of the condition not being met, so
|
|
|
|
// continue processing the next instruction.
|
|
|
|
offset = PROGRAM_END - 1;
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-20 16:17:39 +02:00
|
|
|
case OpCode::Id::KIL: {
|
|
|
|
shader.AddLine("discard;");
|
|
|
|
break;
|
|
|
|
}
|
2018-06-02 21:45:50 +02:00
|
|
|
case OpCode::Id::BRA: {
|
|
|
|
ASSERT_MSG(instr.bra.constant_buffer == 0,
|
|
|
|
"BRA with constant buffers are not implemented");
|
|
|
|
u32 target = offset + instr.bra.GetBranchTarget();
|
|
|
|
shader.AddLine("{ jmp_to = " + std::to_string(target) + "u; break; }");
|
|
|
|
break;
|
|
|
|
}
|
2018-04-11 03:37:49 +02:00
|
|
|
case OpCode::Id::IPA: {
|
|
|
|
const auto& attribute = instr.attribute.fmt28;
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.SetRegisterToInputAttibute(instr.gpr0, attribute.element, attribute.index);
|
2018-04-11 03:37:49 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-04-08 05:48:38 +02:00
|
|
|
default: {
|
2018-04-21 04:25:29 +02:00
|
|
|
NGLOG_CRITICAL(HW_GPU, "Unhandled instruction: {}", opcode->GetName());
|
2018-04-17 22:28:47 +02:00
|
|
|
UNREACHABLE();
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:16:55 +02:00
|
|
|
// Close the predicate condition scope.
|
2018-04-20 16:17:39 +02:00
|
|
|
if (instr.pred.pred_index != static_cast<u64>(Pred::UnusedIndex)) {
|
2018-04-20 16:16:55 +02:00
|
|
|
--shader.scope;
|
|
|
|
shader.AddLine('}');
|
|
|
|
}
|
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
return offset + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compiles a range of instructions from Tegra to GLSL.
|
|
|
|
* @param begin the offset of the starting instruction.
|
|
|
|
* @param end the offset where the compilation should stop (exclusive).
|
|
|
|
* @return the offset of the next instruction to compile. PROGRAM_END if the program
|
|
|
|
* terminates.
|
|
|
|
*/
|
|
|
|
u32 CompileRange(u32 begin, u32 end) {
|
|
|
|
u32 program_counter;
|
|
|
|
for (program_counter = begin; program_counter < (begin > end ? PROGRAM_END : end);) {
|
|
|
|
program_counter = CompileInstr(program_counter);
|
|
|
|
}
|
|
|
|
return program_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Generate() {
|
|
|
|
// Add declarations for all subroutines
|
|
|
|
for (const auto& subroutine : subroutines) {
|
|
|
|
shader.AddLine("bool " + subroutine.GetName() + "();");
|
|
|
|
}
|
2018-04-20 02:05:42 +02:00
|
|
|
shader.AddNewLine();
|
2018-04-08 05:48:38 +02:00
|
|
|
|
|
|
|
// Add the main entry point
|
|
|
|
shader.AddLine("bool exec_shader() {");
|
|
|
|
++shader.scope;
|
|
|
|
CallSubroutine(GetSubroutine(main_offset, PROGRAM_END));
|
|
|
|
--shader.scope;
|
|
|
|
shader.AddLine("}\n");
|
|
|
|
|
|
|
|
// Add definitions for all subroutines
|
|
|
|
for (const auto& subroutine : subroutines) {
|
|
|
|
std::set<u32> labels = subroutine.labels;
|
|
|
|
|
|
|
|
shader.AddLine("bool " + subroutine.GetName() + "() {");
|
|
|
|
++shader.scope;
|
|
|
|
|
|
|
|
if (labels.empty()) {
|
|
|
|
if (CompileRange(subroutine.begin, subroutine.end) != PROGRAM_END) {
|
|
|
|
shader.AddLine("return false;");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
labels.insert(subroutine.begin);
|
|
|
|
shader.AddLine("uint jmp_to = " + std::to_string(subroutine.begin) + "u;");
|
|
|
|
shader.AddLine("while (true) {");
|
|
|
|
++shader.scope;
|
|
|
|
|
|
|
|
shader.AddLine("switch (jmp_to) {");
|
|
|
|
|
|
|
|
for (auto label : labels) {
|
|
|
|
shader.AddLine("case " + std::to_string(label) + "u: {");
|
|
|
|
++shader.scope;
|
|
|
|
|
|
|
|
auto next_it = labels.lower_bound(label + 1);
|
|
|
|
u32 next_label = next_it == labels.end() ? subroutine.end : *next_it;
|
|
|
|
|
|
|
|
u32 compile_end = CompileRange(label, next_label);
|
|
|
|
if (compile_end > next_label && compile_end != PROGRAM_END) {
|
|
|
|
// This happens only when there is a label inside a IF/LOOP block
|
|
|
|
shader.AddLine("{ jmp_to = " + std::to_string(compile_end) + "u; break; }");
|
|
|
|
labels.emplace(compile_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
--shader.scope;
|
2018-04-20 02:02:24 +02:00
|
|
|
shader.AddLine('}');
|
2018-04-08 05:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
shader.AddLine("default: return false;");
|
2018-04-20 02:02:24 +02:00
|
|
|
shader.AddLine('}');
|
2018-04-08 05:48:38 +02:00
|
|
|
|
|
|
|
--shader.scope;
|
2018-04-20 02:02:24 +02:00
|
|
|
shader.AddLine('}');
|
2018-04-08 05:48:38 +02:00
|
|
|
|
|
|
|
shader.AddLine("return false;");
|
|
|
|
}
|
|
|
|
|
|
|
|
--shader.scope;
|
|
|
|
shader.AddLine("}\n");
|
|
|
|
|
|
|
|
DEBUG_ASSERT(shader.scope == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
GenerateDeclarations();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add declarations for registers
|
|
|
|
void GenerateDeclarations() {
|
2018-04-27 04:48:06 +02:00
|
|
|
regs.GenerateDeclarations();
|
2018-04-08 05:48:38 +02:00
|
|
|
|
2018-04-20 16:09:50 +02:00
|
|
|
for (const auto& pred : declr_predicates) {
|
|
|
|
declarations.AddLine("bool " + pred + " = false;");
|
|
|
|
}
|
|
|
|
declarations.AddNewLine();
|
2018-03-19 23:51:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-04-05 03:44:35 +02:00
|
|
|
const std::set<Subroutine>& subroutines;
|
|
|
|
const ProgramCode& program_code;
|
|
|
|
const u32 main_offset;
|
2018-04-10 04:07:30 +02:00
|
|
|
Maxwell3D::Regs::ShaderStage stage;
|
2018-04-05 03:44:35 +02:00
|
|
|
|
|
|
|
ShaderWriter shader;
|
2018-04-08 05:48:38 +02:00
|
|
|
ShaderWriter declarations;
|
2018-04-27 04:48:06 +02:00
|
|
|
GLSLRegisterManager regs{shader, declarations, stage};
|
2018-04-05 03:44:35 +02:00
|
|
|
|
2018-04-08 05:48:38 +02:00
|
|
|
// Declarations
|
2018-04-20 16:09:50 +02:00
|
|
|
std::set<std::string> declr_predicates;
|
2018-04-19 20:34:50 +02:00
|
|
|
}; // namespace Decompiler
|
2018-04-08 05:48:38 +02:00
|
|
|
|
|
|
|
std::string GetCommonDeclarations() {
|
|
|
|
return "bool exec_shader();";
|
|
|
|
}
|
2018-03-19 23:51:43 +01:00
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
boost::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u32 main_offset,
|
|
|
|
Maxwell3D::Regs::ShaderStage stage) {
|
2018-04-05 03:44:35 +02:00
|
|
|
try {
|
|
|
|
auto subroutines = ControlFlowAnalyzer(program_code, main_offset).GetSubroutines();
|
2018-04-10 04:07:30 +02:00
|
|
|
GLSLGenerator generator(subroutines, program_code, main_offset, stage);
|
2018-04-15 09:32:12 +02:00
|
|
|
return ProgramResult{generator.GetShaderCode(), generator.GetEntries()};
|
2018-04-05 03:44:35 +02:00
|
|
|
} catch (const DecompileFail& exception) {
|
2018-04-17 22:28:47 +02:00
|
|
|
NGLOG_ERROR(HW_GPU, "Shader decompilation failed: {}", exception.what());
|
2018-04-05 03:44:35 +02:00
|
|
|
}
|
|
|
|
return boost::none;
|
2018-03-19 23:51:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Decompiler
|
2018-04-08 05:48:38 +02:00
|
|
|
} // namespace GLShader
|