mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-30 10:42:47 +01:00
Implement Bindless Samplers and TEX_B in the IR.
This commit is contained in:
parent
c4ac05c82c
commit
e28fd3d0a5
4 changed files with 77 additions and 16 deletions
|
@ -1309,6 +1309,7 @@ public:
|
||||||
LDG, // Load from global memory
|
LDG, // Load from global memory
|
||||||
STG, // Store in global memory
|
STG, // Store in global memory
|
||||||
TEX,
|
TEX,
|
||||||
|
TEX_B, // Texture Load Bindless
|
||||||
TXQ, // Texture Query
|
TXQ, // Texture Query
|
||||||
TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
|
TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
|
||||||
TLDS, // Texture Load with scalar/non-vec4 source/destinations
|
TLDS, // Texture Load with scalar/non-vec4 source/destinations
|
||||||
|
@ -1577,6 +1578,7 @@ private:
|
||||||
INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
|
INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
|
||||||
INST("1110111011011---", Id::STG, Type::Memory, "STG"),
|
INST("1110111011011---", Id::STG, Type::Memory, "STG"),
|
||||||
INST("110000----111---", Id::TEX, Type::Texture, "TEX"),
|
INST("110000----111---", Id::TEX, Type::Texture, "TEX"),
|
||||||
|
INST("1101111010111---", Id::TEX_B, Type::Texture, "TEX_B"),
|
||||||
INST("1101111101001---", Id::TXQ, Type::Texture, "TXQ"),
|
INST("1101111101001---", Id::TXQ, Type::Texture, "TXQ"),
|
||||||
INST("1101-00---------", Id::TEXS, Type::Texture, "TEXS"),
|
INST("1101-00---------", Id::TEXS, Type::Texture, "TEXS"),
|
||||||
INST("1101101---------", Id::TLDS, Type::Texture, "TLDS"),
|
INST("1101101---------", Id::TLDS, Type::Texture, "TLDS"),
|
||||||
|
|
|
@ -328,7 +328,7 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
|
||||||
}
|
}
|
||||||
entry.entries.samplers.emplace_back(
|
entry.entries.samplers.emplace_back(
|
||||||
static_cast<std::size_t>(offset), static_cast<std::size_t>(index),
|
static_cast<std::size_t>(offset), static_cast<std::size_t>(index),
|
||||||
static_cast<Tegra::Shader::TextureType>(type), is_array != 0, is_shadow != 0);
|
static_cast<Tegra::Shader::TextureType>(type), is_array != 0, is_shadow != 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 global_memory_count{};
|
u32 global_memory_count{};
|
||||||
|
|
|
@ -57,6 +57,23 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
|
||||||
GetTexCode(instr, texture_type, process_mode, depth_compare, is_array, is_aoffi));
|
GetTexCode(instr, texture_type, process_mode, depth_compare, is_array, is_aoffi));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case OpCode::Id::TEX_B: {
|
||||||
|
UNIMPLEMENTED_IF_MSG(instr.tex.UsesMiscMode(TextureMiscMode::AOFFI),
|
||||||
|
"AOFFI is not implemented");
|
||||||
|
|
||||||
|
if (instr.tex.UsesMiscMode(TextureMiscMode::NODEP)) {
|
||||||
|
LOG_WARNING(HW_GPU, "TEX.NODEP implementation is incomplete");
|
||||||
|
}
|
||||||
|
|
||||||
|
const TextureType texture_type{instr.tex.texture_type};
|
||||||
|
const bool is_array = instr.tex.array != 0;
|
||||||
|
const bool depth_compare = instr.tex.UsesMiscMode(TextureMiscMode::DC);
|
||||||
|
const auto process_mode = instr.tex.GetTextureProcessMode();
|
||||||
|
WriteTexInstructionFloat(bb, instr,
|
||||||
|
GetTexCode(instr, texture_type, process_mode, depth_compare,
|
||||||
|
is_array, true, instr.gpr20));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case OpCode::Id::TEXS: {
|
case OpCode::Id::TEXS: {
|
||||||
const TextureType texture_type{instr.texs.GetTextureType()};
|
const TextureType texture_type{instr.texs.GetTextureType()};
|
||||||
const bool is_array{instr.texs.IsArrayTexture()};
|
const bool is_array{instr.texs.IsArrayTexture()};
|
||||||
|
@ -250,10 +267,36 @@ const Sampler& ShaderIR::GetSampler(const Tegra::Shader::Sampler& sampler, Textu
|
||||||
|
|
||||||
// Otherwise create a new mapping for this sampler
|
// Otherwise create a new mapping for this sampler
|
||||||
const std::size_t next_index = used_samplers.size();
|
const std::size_t next_index = used_samplers.size();
|
||||||
const Sampler entry{offset, next_index, type, is_array, is_shadow};
|
const Sampler entry{offset, next_index, type, is_array, is_shadow, false};
|
||||||
return *used_samplers.emplace(entry).first;
|
return *used_samplers.emplace(entry).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Sampler& ShaderIR::GetBindlessSampler(const Tegra::Shader::Register& reg,
|
||||||
|
TextureType type, bool is_array, bool is_shadow) {
|
||||||
|
|
||||||
|
const Node sampler_register = GetRegister(reg);
|
||||||
|
const Node base_sampler = TrackCbuf(sampler_register, global_code, static_cast<s64>(global_code.size()));
|
||||||
|
const auto cbuf = std::get_if<CbufNode>(base_sampler);
|
||||||
|
const auto cbuf_offset_imm = std::get_if<ImmediateNode>(cbuf->GetOffset());
|
||||||
|
ASSERT(cbuf_offset_imm != nullptr);
|
||||||
|
const auto cbuf_offset = cbuf_offset_imm->GetValue();
|
||||||
|
const auto cbuf_index = cbuf->GetIndex();
|
||||||
|
const std::pair<u32, u32> cbuf_pair = {cbuf_index, cbuf_offset};
|
||||||
|
|
||||||
|
// If this sampler has already been used, return the existing mapping.
|
||||||
|
if (used_bindless_samplers.count(cbuf_pair) > 0) {
|
||||||
|
const auto& sampler = used_bindless_samplers[cbuf_pair];
|
||||||
|
ASSERT(sampler.GetType() == type && sampler.IsArray() == is_array &&
|
||||||
|
sampler.IsShadow() == is_shadow);
|
||||||
|
return sampler;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise create a new mapping for this sampler
|
||||||
|
const std::size_t next_index = used_bindless_samplers.size();
|
||||||
|
const Sampler entry{0, next_index, type, is_array, is_shadow, true};
|
||||||
|
return (*used_bindless_samplers.emplace(std::make_pair(cbuf_pair, entry)).first).second;
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderIR::WriteTexInstructionFloat(NodeBlock& bb, Instruction instr, const Node4& components) {
|
void ShaderIR::WriteTexInstructionFloat(NodeBlock& bb, Instruction instr, const Node4& components) {
|
||||||
u32 dest_elem = 0;
|
u32 dest_elem = 0;
|
||||||
for (u32 elem = 0; elem < 4; ++elem) {
|
for (u32 elem = 0; elem < 4; ++elem) {
|
||||||
|
@ -325,8 +368,8 @@ void ShaderIR::WriteTexsInstructionHalfFloat(NodeBlock& bb, Instruction instr,
|
||||||
|
|
||||||
Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
|
Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
|
||||||
TextureProcessMode process_mode, std::vector<Node> coords,
|
TextureProcessMode process_mode, std::vector<Node> coords,
|
||||||
Node array, Node depth_compare, u32 bias_offset,
|
Node array, Node depth_compare, u32 bias_offset, std::vector<Node> aoffi, bool is_bindless,
|
||||||
std::vector<Node> aoffi) {
|
Register bindless_reg) {
|
||||||
const bool is_array = array;
|
const bool is_array = array;
|
||||||
const bool is_shadow = depth_compare;
|
const bool is_shadow = depth_compare;
|
||||||
|
|
||||||
|
@ -334,7 +377,9 @@ Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
|
||||||
(texture_type == TextureType::TextureCube && is_array && is_shadow),
|
(texture_type == TextureType::TextureCube && is_array && is_shadow),
|
||||||
"This method is not supported.");
|
"This method is not supported.");
|
||||||
|
|
||||||
const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, is_shadow);
|
const auto& sampler = !is_bindless
|
||||||
|
? GetSampler(instr.sampler, texture_type, is_array, is_shadow)
|
||||||
|
: GetBindlessSampler(bindless_reg, texture_type, is_array, is_shadow);
|
||||||
|
|
||||||
const bool lod_needed = process_mode == TextureProcessMode::LZ ||
|
const bool lod_needed = process_mode == TextureProcessMode::LZ ||
|
||||||
process_mode == TextureProcessMode::LL ||
|
process_mode == TextureProcessMode::LL ||
|
||||||
|
@ -384,7 +429,7 @@ Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
|
||||||
|
|
||||||
Node4 ShaderIR::GetTexCode(Instruction instr, TextureType texture_type,
|
Node4 ShaderIR::GetTexCode(Instruction instr, TextureType texture_type,
|
||||||
TextureProcessMode process_mode, bool depth_compare, bool is_array,
|
TextureProcessMode process_mode, bool depth_compare, bool is_array,
|
||||||
bool is_aoffi) {
|
bool is_aoffi, bool is_bindless, Register bindless_reg) {
|
||||||
const bool lod_bias_enabled{
|
const bool lod_bias_enabled{
|
||||||
(process_mode != TextureProcessMode::None && process_mode != TextureProcessMode::LZ)};
|
(process_mode != TextureProcessMode::None && process_mode != TextureProcessMode::LZ)};
|
||||||
|
|
||||||
|
@ -423,7 +468,8 @@ Node4 ShaderIR::GetTexCode(Instruction instr, TextureType texture_type,
|
||||||
dc = GetRegister(parameter_register++);
|
dc = GetRegister(parameter_register++);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetTextureCode(instr, texture_type, process_mode, coords, array, dc, 0, aoffi);
|
return GetTextureCode(instr, texture_type, process_mode, coords, array, dc, 0, aoffi, is_bindless,
|
||||||
|
bindless_reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node4 ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type,
|
Node4 ShaderIR::GetTexsCode(Instruction instr, TextureType texture_type,
|
||||||
|
|
|
@ -196,9 +196,12 @@ enum class ExitMethod {
|
||||||
|
|
||||||
class Sampler {
|
class Sampler {
|
||||||
public:
|
public:
|
||||||
|
Sampler() = default;
|
||||||
explicit Sampler(std::size_t offset, std::size_t index, Tegra::Shader::TextureType type,
|
explicit Sampler(std::size_t offset, std::size_t index, Tegra::Shader::TextureType type,
|
||||||
bool is_array, bool is_shadow)
|
bool is_array, bool is_shadow, bool is_bindless)
|
||||||
: offset{offset}, index{index}, type{type}, is_array{is_array}, is_shadow{is_shadow} {}
|
: offset{offset}, index{index}, type{type}, is_array{is_array}, is_shadow{is_shadow}, is_bindless{is_bindless} {}
|
||||||
|
|
||||||
|
~Sampler() = default;
|
||||||
|
|
||||||
std::size_t GetOffset() const {
|
std::size_t GetOffset() const {
|
||||||
return offset;
|
return offset;
|
||||||
|
@ -233,6 +236,7 @@ private:
|
||||||
Tegra::Shader::TextureType type{}; ///< The type used to sample this texture (Texture2D, etc)
|
Tegra::Shader::TextureType type{}; ///< The type used to sample this texture (Texture2D, etc)
|
||||||
bool is_array{}; ///< Whether the texture is being sampled as an array texture or not.
|
bool is_array{}; ///< Whether the texture is being sampled as an array texture or not.
|
||||||
bool is_shadow{}; ///< Whether the texture is being sampled as a depth texture or not.
|
bool is_shadow{}; ///< Whether the texture is being sampled as a depth texture or not.
|
||||||
|
bool is_bindless{}; ///< Whether this sampler belongs to a bindless texture or not.
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConstBuffer {
|
class ConstBuffer {
|
||||||
|
@ -730,6 +734,10 @@ private:
|
||||||
const Sampler& GetSampler(const Tegra::Shader::Sampler& sampler,
|
const Sampler& GetSampler(const Tegra::Shader::Sampler& sampler,
|
||||||
Tegra::Shader::TextureType type, bool is_array, bool is_shadow);
|
Tegra::Shader::TextureType type, bool is_array, bool is_shadow);
|
||||||
|
|
||||||
|
// Accesses a texture sampler for a bindless texture.
|
||||||
|
const Sampler& GetBindlessSampler(const Tegra::Shader::Register& reg, Tegra::Shader::TextureType type,
|
||||||
|
bool is_array, bool is_shadow);
|
||||||
|
|
||||||
/// Extracts a sequence of bits from a node
|
/// Extracts a sequence of bits from a node
|
||||||
Node BitfieldExtract(Node value, u32 offset, u32 bits);
|
Node BitfieldExtract(Node value, u32 offset, u32 bits);
|
||||||
|
|
||||||
|
@ -741,9 +749,11 @@ private:
|
||||||
void WriteTexsInstructionHalfFloat(NodeBlock& bb, Tegra::Shader::Instruction instr,
|
void WriteTexsInstructionHalfFloat(NodeBlock& bb, Tegra::Shader::Instruction instr,
|
||||||
const Node4& components);
|
const Node4& components);
|
||||||
|
|
||||||
Node4 GetTexCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
Node4 GetTexCode(
|
||||||
Tegra::Shader::TextureProcessMode process_mode, bool depth_compare,
|
Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
||||||
bool is_array, bool is_aoffi);
|
Tegra::Shader::TextureProcessMode process_mode, bool depth_compare, bool is_array,
|
||||||
|
bool is_aoffi, bool is_bindless = false,
|
||||||
|
Tegra::Shader::Register bindless_reg = static_cast<Tegra::Shader::Register>(0));
|
||||||
|
|
||||||
Node4 GetTexsCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
Node4 GetTexsCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
||||||
Tegra::Shader::TextureProcessMode process_mode, bool depth_compare,
|
Tegra::Shader::TextureProcessMode process_mode, bool depth_compare,
|
||||||
|
@ -761,9 +771,11 @@ private:
|
||||||
|
|
||||||
std::vector<Node> GetAoffiCoordinates(Node aoffi_reg, std::size_t coord_count, bool is_tld4);
|
std::vector<Node> GetAoffiCoordinates(Node aoffi_reg, std::size_t coord_count, bool is_tld4);
|
||||||
|
|
||||||
Node4 GetTextureCode(Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
Node4 GetTextureCode(
|
||||||
Tegra::Shader::TextureProcessMode process_mode, std::vector<Node> coords,
|
Tegra::Shader::Instruction instr, Tegra::Shader::TextureType texture_type,
|
||||||
Node array, Node depth_compare, u32 bias_offset, std::vector<Node> aoffi);
|
Tegra::Shader::TextureProcessMode process_mode, std::vector<Node> coords, Node array,
|
||||||
|
Node depth_compare, u32 bias_offset, std::vector<Node> aoffi, bool is_bindless = false,
|
||||||
|
Tegra::Shader::Register bindless_reg = static_cast<Tegra::Shader::Register>(0));
|
||||||
|
|
||||||
Node GetVideoOperand(Node op, bool is_chunk, bool is_signed, Tegra::Shader::VideoType type,
|
Node GetVideoOperand(Node op, bool is_chunk, bool is_signed, Tegra::Shader::VideoType type,
|
||||||
u64 byte_height);
|
u64 byte_height);
|
||||||
|
@ -833,6 +845,7 @@ private:
|
||||||
std::set<Tegra::Shader::Attribute::Index> used_output_attributes;
|
std::set<Tegra::Shader::Attribute::Index> used_output_attributes;
|
||||||
std::map<u32, ConstBuffer> used_cbufs;
|
std::map<u32, ConstBuffer> used_cbufs;
|
||||||
std::set<Sampler> used_samplers;
|
std::set<Sampler> used_samplers;
|
||||||
|
std::map<std::pair<u32, u32>, Sampler> used_bindless_samplers;
|
||||||
std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances> used_clip_distances{};
|
std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances> used_clip_distances{};
|
||||||
std::set<GlobalMemoryBase> used_global_memory_bases;
|
std::set<GlobalMemoryBase> used_global_memory_bases;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue