2018-12-20 14:09:21 -08:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-12-26 20:50:22 -08:00
|
|
|
#include <array>
|
2019-10-27 22:31:05 -07:00
|
|
|
#include <list>
|
2018-12-20 14:09:21 -08:00
|
|
|
#include <map>
|
2019-03-29 14:36:07 -07:00
|
|
|
#include <optional>
|
2018-12-20 14:09:21 -08:00
|
|
|
#include <set>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
|
|
|
#include "video_core/engines/shader_header.h"
|
2019-06-28 19:59:43 -07:00
|
|
|
#include "video_core/shader/ast.h"
|
2019-08-16 13:25:02 -07:00
|
|
|
#include "video_core/shader/compiler_settings.h"
|
2020-04-23 21:44:14 -07:00
|
|
|
#include "video_core/shader/memory_util.h"
|
2019-06-28 22:44:07 -07:00
|
|
|
#include "video_core/shader/node.h"
|
2020-02-28 15:53:10 -08:00
|
|
|
#include "video_core/shader/registry.h"
|
2018-12-20 14:09:21 -08:00
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
2019-06-25 08:10:45 -07:00
|
|
|
struct ShaderBlock;
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
constexpr u32 MAX_PROGRAM_LENGTH = 0x1000;
|
|
|
|
|
2020-04-15 21:34:45 -07:00
|
|
|
struct ConstBuffer {
|
|
|
|
constexpr explicit ConstBuffer(u32 max_offset, bool is_indirect)
|
2019-01-14 20:07:57 -08:00
|
|
|
: max_offset{max_offset}, is_indirect{is_indirect} {}
|
|
|
|
|
2020-04-15 21:34:45 -07:00
|
|
|
constexpr ConstBuffer() = default;
|
2019-01-14 20:07:57 -08:00
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
void MarkAsUsed(u64 offset) {
|
|
|
|
max_offset = std::max(max_offset, static_cast<u32>(offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsUsedIndirect() {
|
|
|
|
is_indirect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsIndirect() const {
|
|
|
|
return is_indirect;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetSize() const {
|
2019-11-08 12:08:07 -08:00
|
|
|
return max_offset + static_cast<u32>(sizeof(float));
|
2018-12-20 14:09:21 -08:00
|
|
|
}
|
|
|
|
|
2019-01-14 20:07:57 -08:00
|
|
|
u32 GetMaxOffset() const {
|
|
|
|
return max_offset;
|
|
|
|
}
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
private:
|
2020-04-15 21:34:45 -07:00
|
|
|
u32 max_offset = 0;
|
|
|
|
bool is_indirect = false;
|
2018-12-20 14:09:21 -08:00
|
|
|
};
|
|
|
|
|
2019-02-06 19:05:41 -08:00
|
|
|
struct GlobalMemoryUsage {
|
|
|
|
bool is_read{};
|
|
|
|
bool is_written{};
|
|
|
|
};
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
class ShaderIR final {
|
|
|
|
public:
|
2020-04-05 23:09:19 -07:00
|
|
|
explicit ShaderIR(const ProgramCode& program_code, u32 main_offset, CompilerSettings settings,
|
|
|
|
Registry& registry);
|
2019-05-19 01:01:59 -07:00
|
|
|
~ShaderIR();
|
2018-12-20 14:09:21 -08:00
|
|
|
|
2019-01-29 21:09:40 -08:00
|
|
|
const std::map<u32, NodeBlock>& GetBasicBlocks() const {
|
2018-12-20 14:09:21 -08:00
|
|
|
return basic_blocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::set<u32>& GetRegisters() const {
|
|
|
|
return used_registers;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::set<Tegra::Shader::Pred>& GetPredicates() const {
|
|
|
|
return used_predicates;
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:37:09 -07:00
|
|
|
const std::set<Tegra::Shader::Attribute::Index>& GetInputAttributes() const {
|
2018-12-20 14:09:21 -08:00
|
|
|
return used_input_attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::set<Tegra::Shader::Attribute::Index>& GetOutputAttributes() const {
|
|
|
|
return used_output_attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::map<u32, ConstBuffer>& GetConstantBuffers() const {
|
|
|
|
return used_cbufs;
|
|
|
|
}
|
|
|
|
|
2019-10-27 22:31:05 -07:00
|
|
|
const std::list<Sampler>& GetSamplers() const {
|
2018-12-20 14:09:21 -08:00
|
|
|
return used_samplers;
|
|
|
|
}
|
|
|
|
|
2019-10-27 22:31:05 -07:00
|
|
|
const std::list<Image>& GetImages() const {
|
2019-04-26 22:07:18 -07:00
|
|
|
return used_images;
|
|
|
|
}
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
const std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances>& GetClipDistances()
|
|
|
|
const {
|
|
|
|
return used_clip_distances;
|
|
|
|
}
|
|
|
|
|
2019-02-06 19:05:41 -08:00
|
|
|
const std::map<GlobalMemoryBase, GlobalMemoryUsage>& GetGlobalMemory() const {
|
|
|
|
return used_global_memory;
|
2018-12-28 21:44:54 -08:00
|
|
|
}
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
std::size_t GetLength() const {
|
|
|
|
return static_cast<std::size_t>(coverage_end * sizeof(u64));
|
|
|
|
}
|
|
|
|
|
2019-07-07 16:36:42 -07:00
|
|
|
bool UsesLayer() const {
|
|
|
|
return uses_layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UsesViewportIndex() const {
|
|
|
|
return uses_viewport_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UsesPointSize() const {
|
|
|
|
return uses_point_size;
|
|
|
|
}
|
|
|
|
|
2019-09-15 11:25:07 -07:00
|
|
|
bool UsesInstanceId() const {
|
|
|
|
return uses_instance_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UsesVertexId() const {
|
|
|
|
return uses_vertex_id;
|
|
|
|
}
|
|
|
|
|
2020-03-15 17:00:51 -07:00
|
|
|
bool UsesLegacyVaryings() const {
|
|
|
|
return uses_legacy_varyings;
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:40:32 -08:00
|
|
|
bool UsesWarps() const {
|
|
|
|
return uses_warps;
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:28:28 -07:00
|
|
|
bool HasPhysicalAttributes() const {
|
2019-04-30 15:46:49 -07:00
|
|
|
return uses_physical_attributes;
|
2019-04-29 19:28:28 -07:00
|
|
|
}
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
const Tegra::Shader::Header& GetHeader() const {
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2019-08-16 13:25:02 -07:00
|
|
|
bool IsFlowStackDisabled() const {
|
|
|
|
return disable_flow_stack;
|
|
|
|
}
|
|
|
|
|
2019-06-28 22:44:07 -07:00
|
|
|
bool IsDecompiled() const {
|
|
|
|
return decompiled;
|
|
|
|
}
|
|
|
|
|
2019-08-25 12:32:00 -07:00
|
|
|
const ASTManager& GetASTManager() const {
|
|
|
|
return program_manager;
|
|
|
|
}
|
|
|
|
|
2019-06-28 22:44:07 -07:00
|
|
|
ASTNode GetASTProgram() const {
|
|
|
|
return program_manager.GetProgram();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetASTNumVariables() const {
|
|
|
|
return program_manager.GetVariables();
|
2019-06-25 10:03:51 -07:00
|
|
|
}
|
|
|
|
|
2019-11-08 12:08:07 -08:00
|
|
|
u32 ConvertAddressToNvidiaSpace(u32 address) const {
|
|
|
|
return (address - main_offset) * static_cast<u32>(sizeof(Tegra::Shader::Instruction));
|
2019-07-05 11:13:14 -07:00
|
|
|
}
|
|
|
|
|
2019-06-28 22:44:07 -07:00
|
|
|
/// Returns a condition code evaluated from internal flags
|
|
|
|
Node GetConditionCode(Tegra::Shader::ConditionCode cc) const;
|
|
|
|
|
2020-01-04 10:40:57 -08:00
|
|
|
const Node& GetAmendNode(std::size_t index) const {
|
2019-12-30 09:54:53 -08:00
|
|
|
return amend_code[index];
|
|
|
|
}
|
|
|
|
|
2020-01-24 06:44:34 -08:00
|
|
|
u32 GetNumCustomVariables() const {
|
2020-01-07 10:53:46 -08:00
|
|
|
return num_custom_variables;
|
|
|
|
}
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
private:
|
2019-06-28 22:44:07 -07:00
|
|
|
friend class ASTDecoder;
|
2019-09-25 06:53:18 -07:00
|
|
|
|
|
|
|
struct SamplerInfo {
|
2020-04-15 22:07:42 -07:00
|
|
|
std::optional<Tegra::Shader::TextureType> type;
|
|
|
|
std::optional<bool> is_array;
|
|
|
|
std::optional<bool> is_shadow;
|
|
|
|
std::optional<bool> is_buffer;
|
|
|
|
|
|
|
|
constexpr bool IsComplete() const noexcept {
|
|
|
|
return type && is_array && is_shadow && is_buffer;
|
|
|
|
}
|
2019-09-25 06:53:18 -07:00
|
|
|
};
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
void Decode();
|
2020-01-03 12:16:29 -08:00
|
|
|
void PostDecode();
|
2018-12-20 14:09:21 -08:00
|
|
|
|
2019-01-29 21:09:40 -08:00
|
|
|
NodeBlock DecodeRange(u32 begin, u32 end);
|
2019-06-25 10:03:51 -07:00
|
|
|
void DecodeRangeInner(NodeBlock& bb, u32 begin, u32 end);
|
2019-06-25 08:10:45 -07:00
|
|
|
void InsertControlFlow(NodeBlock& bb, const ShaderBlock& block);
|
2018-12-20 14:09:21 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes a single instruction from Tegra to IR.
|
|
|
|
* @param bb Basic block where the nodes will be written to.
|
|
|
|
* @param pc Program counter. Offset to decode.
|
|
|
|
* @return Next address to decode.
|
|
|
|
*/
|
2019-01-29 21:09:40 -08:00
|
|
|
u32 DecodeInstr(NodeBlock& bb, u32 pc);
|
|
|
|
|
|
|
|
u32 DecodeArithmetic(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeArithmeticImmediate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeBfe(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeBfi(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeShift(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeArithmeticInteger(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeArithmeticIntegerImmediate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeArithmeticHalf(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeArithmeticHalfImmediate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeFfma(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeHfma2(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeConversion(NodeBlock& bb, u32 pc);
|
2019-08-09 19:50:21 -07:00
|
|
|
u32 DecodeWarp(NodeBlock& bb, u32 pc);
|
2019-01-29 21:09:40 -08:00
|
|
|
u32 DecodeMemory(NodeBlock& bb, u32 pc);
|
2019-02-21 21:19:45 -08:00
|
|
|
u32 DecodeTexture(NodeBlock& bb, u32 pc);
|
2019-04-26 22:07:18 -07:00
|
|
|
u32 DecodeImage(NodeBlock& bb, u32 pc);
|
2019-01-29 21:09:40 -08:00
|
|
|
u32 DecodeFloatSetPredicate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeIntegerSetPredicate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeHalfSetPredicate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodePredicateSetRegister(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodePredicateSetPredicate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeRegisterSetPredicate(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeFloatSet(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeIntegerSet(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeHalfSet(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeVideo(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeXmad(NodeBlock& bb, u32 pc);
|
|
|
|
u32 DecodeOther(NodeBlock& bb, u32 pc);
|
2018-12-20 14:09:21 -08:00
|
|
|
|
2018-12-20 17:41:31 -08:00
|
|
|
/// Generates a node for a passed register.
|
|
|
|
Node GetRegister(Tegra::Shader::Register reg);
|
2020-01-07 10:53:46 -08:00
|
|
|
/// Generates a node for a custom variable
|
|
|
|
Node GetCustomVariable(u32 id);
|
2018-12-20 17:36:17 -08:00
|
|
|
/// Generates a node representing a 19-bit immediate value
|
|
|
|
Node GetImmediate19(Tegra::Shader::Instruction instr);
|
|
|
|
/// Generates a node representing a 32-bit immediate value
|
|
|
|
Node GetImmediate32(Tegra::Shader::Instruction instr);
|
2018-12-20 17:42:47 -08:00
|
|
|
/// Generates a node representing a constant buffer
|
|
|
|
Node GetConstBuffer(u64 index, u64 offset);
|
|
|
|
/// Generates a node representing a constant buffer with a variadic offset
|
|
|
|
Node GetConstBufferIndirect(u64 index, u64 offset, Node node);
|
2018-12-20 14:09:21 -08:00
|
|
|
/// Generates a node for a passed predicate. It can be optionally negated
|
|
|
|
Node GetPredicate(u64 pred, bool negated = false);
|
2018-12-20 17:36:17 -08:00
|
|
|
/// Generates a predicate node for an immediate true or false value
|
|
|
|
Node GetPredicate(bool immediate);
|
2019-01-28 04:52:02 -08:00
|
|
|
/// Generates a node representing an input attribute. Keeps track of used attributes.
|
2019-04-29 19:37:09 -07:00
|
|
|
Node GetInputAttribute(Tegra::Shader::Attribute::Index index, u64 element, Node buffer = {});
|
2019-04-30 14:12:30 -07:00
|
|
|
/// Generates a node representing a physical input attribute.
|
|
|
|
Node GetPhysicalInputAttribute(Tegra::Shader::Register physical_address, Node buffer = {});
|
2019-01-28 04:52:02 -08:00
|
|
|
/// Generates a node representing an output attribute. Keeps track of used attributes.
|
2018-12-20 17:45:34 -08:00
|
|
|
Node GetOutputAttribute(Tegra::Shader::Attribute::Index index, u64 element, Node buffer);
|
2018-12-20 17:49:59 -08:00
|
|
|
/// Generates a node representing an internal flag
|
2019-06-28 22:44:07 -07:00
|
|
|
Node GetInternalFlag(InternalFlag flag, bool negated = false) const;
|
2018-12-20 17:51:38 -08:00
|
|
|
/// Generates a node representing a local memory address
|
|
|
|
Node GetLocalMemory(Node address);
|
2019-07-29 20:21:46 -07:00
|
|
|
/// Generates a node representing a shared memory address
|
|
|
|
Node GetSharedMemory(Node address);
|
2019-07-16 07:31:17 -07:00
|
|
|
/// Generates a temporary, internally it uses a post-RZ register
|
|
|
|
Node GetTemporary(u32 id);
|
2018-12-20 17:51:38 -08:00
|
|
|
|
2018-12-20 17:53:43 -08:00
|
|
|
/// Sets a register. src value must be a number-evaluated node.
|
2019-01-29 21:09:40 -08:00
|
|
|
void SetRegister(NodeBlock& bb, Tegra::Shader::Register dest, Node src);
|
2018-12-20 17:53:43 -08:00
|
|
|
/// Sets a predicate. src value must be a bool-evaluated node
|
2019-01-29 21:09:40 -08:00
|
|
|
void SetPredicate(NodeBlock& bb, u64 dest, Node src);
|
2018-12-20 17:53:43 -08:00
|
|
|
/// Sets an internal flag. src value must be a bool-evaluated node
|
2019-01-29 21:09:40 -08:00
|
|
|
void SetInternalFlag(NodeBlock& bb, InternalFlag flag, Node value);
|
2019-07-29 20:21:46 -07:00
|
|
|
/// Sets a local memory address with a value.
|
2019-01-29 21:09:40 -08:00
|
|
|
void SetLocalMemory(NodeBlock& bb, Node address, Node value);
|
2019-07-29 20:21:46 -07:00
|
|
|
/// Sets a shared memory address with a value.
|
|
|
|
void SetSharedMemory(NodeBlock& bb, Node address, Node value);
|
2019-07-16 07:31:17 -07:00
|
|
|
/// Sets a temporary. Internally it uses a post-RZ register
|
|
|
|
void SetTemporary(NodeBlock& bb, u32 id, Node value);
|
2018-12-20 14:09:21 -08:00
|
|
|
|
2018-12-27 11:50:36 -08:00
|
|
|
/// Sets internal flags from a float
|
2019-01-29 21:09:40 -08:00
|
|
|
void SetInternalFlagsFromFloat(NodeBlock& bb, Node value, bool sets_cc = true);
|
2018-12-27 11:50:36 -08:00
|
|
|
/// Sets internal flags from an integer
|
2019-01-29 21:09:40 -08:00
|
|
|
void SetInternalFlagsFromInteger(NodeBlock& bb, Node value, bool sets_cc = true);
|
2018-12-27 11:50:36 -08:00
|
|
|
|
2018-12-20 17:56:08 -08:00
|
|
|
/// Conditionally absolute/negated float. Absolute is applied first
|
|
|
|
Node GetOperandAbsNegFloat(Node value, bool absolute, bool negate);
|
|
|
|
/// Conditionally saturates a float
|
|
|
|
Node GetSaturatedFloat(Node value, bool saturate = true);
|
|
|
|
|
2018-12-20 17:57:16 -08:00
|
|
|
/// Converts an integer to different sizes.
|
|
|
|
Node ConvertIntegerSize(Node value, Tegra::Shader::Register::Size size, bool is_signed);
|
|
|
|
/// Conditionally absolute/negated integer. Absolute is applied first
|
|
|
|
Node GetOperandAbsNegInteger(Node value, bool absolute, bool negate, bool is_signed);
|
|
|
|
|
2018-12-20 17:58:33 -08:00
|
|
|
/// Unpacks a half immediate from an instruction
|
|
|
|
Node UnpackHalfImmediate(Tegra::Shader::Instruction instr, bool has_negation);
|
2019-04-15 15:48:11 -07:00
|
|
|
/// Unpacks a binary value into a half float pair with a type format
|
|
|
|
Node UnpackHalfFloat(Node value, Tegra::Shader::HalfType type);
|
2018-12-20 17:58:33 -08:00
|
|
|
/// Merges a half pair into another value
|
|
|
|
Node HalfMerge(Node dest, Node src, Tegra::Shader::HalfMerge merge);
|
|
|
|
/// Conditionally absolute/negated half float pair. Absolute is applied first
|
|
|
|
Node GetOperandAbsNegHalf(Node value, bool absolute, bool negate);
|
2019-04-09 14:41:41 -07:00
|
|
|
/// Conditionally saturates a half float pair
|
|
|
|
Node GetSaturatedHalfFloat(Node value, bool saturate = true);
|
2018-12-20 17:58:33 -08:00
|
|
|
|
2020-04-05 23:09:19 -07:00
|
|
|
/// Get image component value by type and size
|
2020-04-05 23:46:55 -07:00
|
|
|
std::pair<Node, bool> GetComponentValue(Tegra::Texture::ComponentType component_type,
|
|
|
|
u32 component_size, Node original_value);
|
2020-04-05 23:09:19 -07:00
|
|
|
|
2018-12-20 18:01:03 -08:00
|
|
|
/// Returns a predicate comparing two floats
|
|
|
|
Node GetPredicateComparisonFloat(Tegra::Shader::PredCondition condition, Node op_a, Node op_b);
|
|
|
|
/// Returns a predicate comparing two integers
|
|
|
|
Node GetPredicateComparisonInteger(Tegra::Shader::PredCondition condition, bool is_signed,
|
|
|
|
Node op_a, Node op_b);
|
|
|
|
/// Returns a predicate comparing two half floats. meta consumes how both pairs will be compared
|
2019-04-15 15:48:11 -07:00
|
|
|
Node GetPredicateComparisonHalf(Tegra::Shader::PredCondition condition, Node op_a, Node op_b);
|
2018-12-20 18:01:03 -08:00
|
|
|
|
2018-12-20 18:40:54 -08:00
|
|
|
/// Returns a predicate combiner operation
|
|
|
|
OperationCode GetPredicateCombiner(Tegra::Shader::PredOperation operation);
|
|
|
|
|
2019-11-05 23:32:43 -08:00
|
|
|
/// Queries the missing sampler info from the execution context.
|
2020-06-04 19:03:49 -07:00
|
|
|
SamplerInfo GetSamplerInfo(SamplerInfo info,
|
|
|
|
std::optional<Tegra::Engines::SamplerDescriptor> sampler);
|
2019-11-05 23:32:43 -08:00
|
|
|
|
2020-04-15 22:07:42 -07:00
|
|
|
/// Accesses a texture sampler.
|
|
|
|
std::optional<Sampler> GetSampler(Tegra::Shader::Sampler sampler, SamplerInfo info);
|
2018-12-20 20:27:47 -08:00
|
|
|
|
2019-11-05 23:32:43 -08:00
|
|
|
/// Accesses a texture sampler for a bindless texture.
|
2020-04-15 22:07:42 -07:00
|
|
|
std::optional<Sampler> GetBindlessSampler(Tegra::Shader::Register reg, SamplerInfo info,
|
|
|
|
Node& index_var);
|
2019-03-26 14:05:23 -07:00
|
|
|
|
2019-04-26 22:07:18 -07:00
|
|
|
/// Accesses an image.
|
2019-09-17 21:50:40 -07:00
|
|
|
Image& GetImage(Tegra::Shader::Image image, Tegra::Shader::ImageType type);
|
2019-04-26 22:07:18 -07:00
|
|
|
|
2019-04-26 23:04:13 -07:00
|
|
|
/// Access a bindless image sampler.
|
2019-09-17 21:50:40 -07:00
|
|
|
Image& GetBindlessImage(Tegra::Shader::Register reg, Tegra::Shader::ImageType type);
|
2019-07-17 17:03:53 -07:00
|
|
|
|
2018-12-25 21:58:47 -08:00
|
|
|
/// Extracts a sequence of bits from a node
|
|
|
|
Node BitfieldExtract(Node value, u32 offset, u32 bits);
|
|
|
|
|
2019-07-11 17:14:44 -07:00
|
|
|
/// Inserts a sequence of bits from a node
|
|
|
|
Node BitfieldInsert(Node base, Node insert, u32 offset, u32 bits);
|
|
|
|
|
2020-03-15 17:00:51 -07:00
|
|
|
/// Marks the usage of a input or output attribute.
|
|
|
|
void MarkAttributeUsage(Tegra::Shader::Attribute::Index index, u64 element);
|
|
|
|
|
2020-03-28 14:49:50 -07:00
|
|
|
/// Decodes VMNMX instruction and inserts its code into the passed basic block.
|
|
|
|
void DecodeVMNMX(NodeBlock& bb, Tegra::Shader::Instruction instr);
|
|
|
|
|
2019-01-29 21:09:40 -08:00
|
|
|
void WriteTexInstructionFloat(NodeBlock& bb, Tegra::Shader::Instruction instr,
|
2019-10-30 18:14:57 -07:00
|
|
|
const Node4& components);
|
2018-12-20 20:27:47 -08:00
|
|
|
|
2019-01-29 21:09:40 -08:00
|
|
|
void WriteTexsInstructionFloat(NodeBlock& bb, Tegra::Shader::Instruction instr,
|
2019-10-22 07:59:07 -07:00
|
|
|
const Node4& components, bool ignore_mask = false);
|
2019-01-29 21:09:40 -08:00
|
|
|
void WriteTexsInstructionHalfFloat(NodeBlock& bb, Tegra::Shader::Instruction instr,
|
2019-12-11 14:12:29 -08:00
|
|
|
const Node4& components, bool ignore_mask = false);
|
2018-12-13 11:59:28 -08:00
|
|
|
|
2018-12-26 20:50:22 -08:00
|
|
|
Node4 GetTexCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
2018-12-20 20:27:47 -08:00
|
|
|
Tegra::Shader::TextureProcessMode process_mode, bool depth_compare,
|
2019-03-27 04:11:50 -07:00
|
|
|
bool is_array, bool is_aoffi,
|
|
|
|
std::optional<Tegra::Shader::Register> bindless_reg);
|
2018-12-20 20:27:47 -08:00
|
|
|
|
2018-12-26 20:50:22 -08:00
|
|
|
Node4 GetTexsCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
|
|
|
Tegra::Shader::TextureProcessMode process_mode, bool depth_compare,
|
|
|
|
bool is_array);
|
2018-12-22 19:38:01 -08:00
|
|
|
|
2018-12-26 20:50:22 -08:00
|
|
|
Node4 GetTld4Code(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
2019-12-15 23:09:24 -08:00
|
|
|
bool depth_compare, bool is_array, bool is_aoffi, bool is_ptp,
|
|
|
|
bool is_bindless);
|
2018-12-26 20:50:22 -08:00
|
|
|
|
2019-04-27 16:50:35 -07:00
|
|
|
Node4 GetTldCode(Tegra::Shader::Instruction instr);
|
|
|
|
|
2018-12-26 20:50:22 -08:00
|
|
|
Node4 GetTldsCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
|
|
|
bool is_array);
|
2018-12-22 20:18:33 -08:00
|
|
|
|
2018-12-20 20:27:47 -08:00
|
|
|
std::tuple<std::size_t, std::size_t> ValidateAndGetCoordinateElement(
|
|
|
|
Tegra::Shader::TextureType texture_type, bool depth_compare, bool is_array,
|
|
|
|
bool lod_bias_enabled, std::size_t max_coords, std::size_t max_inputs);
|
|
|
|
|
2019-03-29 14:36:54 -07:00
|
|
|
std::vector<Node> GetAoffiCoordinates(Node aoffi_reg, std::size_t coord_count, bool is_tld4);
|
|
|
|
|
2019-12-15 23:09:24 -08:00
|
|
|
std::vector<Node> GetPtpCoordinates(std::array<Node, 2> ptp_regs);
|
|
|
|
|
2018-12-26 20:50:22 -08:00
|
|
|
Node4 GetTextureCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
2019-01-28 23:31:40 -08:00
|
|
|
Tegra::Shader::TextureProcessMode process_mode, std::vector<Node> coords,
|
2019-03-27 04:11:50 -07:00
|
|
|
Node array, Node depth_compare, u32 bias_offset, std::vector<Node> aoffi,
|
|
|
|
std::optional<Tegra::Shader::Register> bindless_reg);
|
2018-12-20 20:27:47 -08:00
|
|
|
|
2018-12-23 20:23:00 -08:00
|
|
|
Node GetVideoOperand(Node op, bool is_chunk, bool is_signed, Tegra::Shader::VideoType type,
|
|
|
|
u64 byte_height);
|
|
|
|
|
2019-01-29 21:09:40 -08:00
|
|
|
void WriteLogicOperation(NodeBlock& bb, Tegra::Shader::Register dest,
|
2018-12-20 21:02:15 -08:00
|
|
|
Tegra::Shader::LogicOperation logic_op, Node op_a, Node op_b,
|
|
|
|
Tegra::Shader::PredicateResultMode predicate_mode,
|
2018-12-27 11:50:36 -08:00
|
|
|
Tegra::Shader::Pred predicate, bool sets_cc);
|
2019-01-29 21:09:40 -08:00
|
|
|
void WriteLop3Instruction(NodeBlock& bb, Tegra::Shader::Register dest, Node op_a, Node op_b,
|
2018-12-27 11:50:36 -08:00
|
|
|
Node op_c, Node imm_lut, bool sets_cc);
|
2018-12-20 21:02:15 -08:00
|
|
|
|
2019-05-31 15:14:34 -07:00
|
|
|
std::tuple<Node, u32, u32> TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) const;
|
2018-12-28 21:44:54 -08:00
|
|
|
|
2020-06-04 19:02:55 -07:00
|
|
|
std::pair<Node, TrackSampler> TrackBindlessSampler(Node tracked, const NodeBlock& code,
|
|
|
|
s64 cursor);
|
|
|
|
|
|
|
|
std::pair<Node, TrackSampler> HandleBindlessIndirectRead(const CbufNode& cbuf,
|
|
|
|
const OperationNode& operation,
|
|
|
|
Node gpr, Node base_offset,
|
|
|
|
Node tracked, const NodeBlock& code,
|
|
|
|
s64 cursor);
|
2020-01-05 11:23:24 -08:00
|
|
|
|
2019-05-19 01:10:32 -07:00
|
|
|
std::optional<u32> TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) const;
|
2019-03-29 14:36:07 -07:00
|
|
|
|
2019-05-19 01:10:32 -07:00
|
|
|
std::pair<Node, s64> TrackRegister(const GprNode* tracked, const NodeBlock& code,
|
|
|
|
s64 cursor) const;
|
2018-12-28 21:44:54 -08:00
|
|
|
|
2019-10-17 21:23:10 -07:00
|
|
|
std::tuple<Node, Node, GlobalMemoryBase> TrackGlobalMemory(NodeBlock& bb,
|
|
|
|
Tegra::Shader::Instruction instr,
|
2020-01-08 20:08:55 -08:00
|
|
|
bool is_read, bool is_write);
|
2019-02-06 19:05:41 -08:00
|
|
|
|
2020-01-04 10:40:57 -08:00
|
|
|
/// Register new amending code and obtain the reference id.
|
|
|
|
std::size_t DeclareAmend(Node new_amend);
|
2019-12-30 09:54:53 -08:00
|
|
|
|
2020-01-07 10:53:46 -08:00
|
|
|
u32 NewCustomVariable();
|
|
|
|
|
2018-12-20 14:09:21 -08:00
|
|
|
const ProgramCode& program_code;
|
|
|
|
const u32 main_offset;
|
2019-09-24 19:34:18 -07:00
|
|
|
const CompilerSettings settings;
|
2020-02-28 15:53:10 -08:00
|
|
|
Registry& registry;
|
2019-09-24 19:34:18 -07:00
|
|
|
|
2019-06-28 22:44:07 -07:00
|
|
|
bool decompiled{};
|
2019-08-16 13:25:02 -07:00
|
|
|
bool disable_flow_stack{};
|
2018-12-20 14:09:21 -08:00
|
|
|
|
|
|
|
u32 coverage_begin{};
|
|
|
|
u32 coverage_end{};
|
|
|
|
|
2019-01-29 21:09:40 -08:00
|
|
|
std::map<u32, NodeBlock> basic_blocks;
|
|
|
|
NodeBlock global_code;
|
2019-09-24 19:34:18 -07:00
|
|
|
ASTManager program_manager{true, true};
|
2020-01-04 10:40:57 -08:00
|
|
|
std::vector<Node> amend_code;
|
2020-01-07 10:53:46 -08:00
|
|
|
u32 num_custom_variables{};
|
2018-12-20 14:09:21 -08:00
|
|
|
|
|
|
|
std::set<u32> used_registers;
|
|
|
|
std::set<Tegra::Shader::Pred> used_predicates;
|
2019-04-29 19:37:09 -07:00
|
|
|
std::set<Tegra::Shader::Attribute::Index> used_input_attributes;
|
2018-12-20 14:09:21 -08:00
|
|
|
std::set<Tegra::Shader::Attribute::Index> used_output_attributes;
|
|
|
|
std::map<u32, ConstBuffer> used_cbufs;
|
2019-10-27 22:31:05 -07:00
|
|
|
std::list<Sampler> used_samplers;
|
|
|
|
std::list<Image> used_images;
|
2018-12-20 14:09:21 -08:00
|
|
|
std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances> used_clip_distances{};
|
2019-02-06 19:05:41 -08:00
|
|
|
std::map<GlobalMemoryBase, GlobalMemoryUsage> used_global_memory;
|
2019-07-07 16:36:42 -07:00
|
|
|
bool uses_layer{};
|
|
|
|
bool uses_viewport_index{};
|
|
|
|
bool uses_point_size{};
|
2019-04-30 15:46:49 -07:00
|
|
|
bool uses_physical_attributes{}; // Shader uses AL2P or physical attribute read/writes
|
2019-09-15 11:25:07 -07:00
|
|
|
bool uses_instance_id{};
|
|
|
|
bool uses_vertex_id{};
|
2020-03-15 17:00:51 -07:00
|
|
|
bool uses_legacy_varyings{};
|
2019-12-09 18:40:32 -08:00
|
|
|
bool uses_warps{};
|
2020-01-05 14:36:21 -08:00
|
|
|
bool uses_indexed_samplers{};
|
2018-12-20 14:09:21 -08:00
|
|
|
|
|
|
|
Tegra::Shader::Header header;
|
|
|
|
};
|
|
|
|
|
2018-12-20 22:22:26 -08:00
|
|
|
} // namespace VideoCommon::Shader
|