1
mirror of https://github.com/yuzu-emu/yuzu synced 2024-11-06 02:30:37 +01:00

video_core: Rename "const buffer locker" to "registry"

This commit is contained in:
ReinUsesLisp 2020-02-28 20:53:10 -03:00
parent bd8b9bbcee
commit e8efd5a901
17 changed files with 102 additions and 97 deletions

View File

@ -89,8 +89,6 @@ set(HASH_FILES
"${VIDEO_CORE}/shader/ast.h" "${VIDEO_CORE}/shader/ast.h"
"${VIDEO_CORE}/shader/compiler_settings.cpp" "${VIDEO_CORE}/shader/compiler_settings.cpp"
"${VIDEO_CORE}/shader/compiler_settings.h" "${VIDEO_CORE}/shader/compiler_settings.h"
"${VIDEO_CORE}/shader/const_buffer_locker.cpp"
"${VIDEO_CORE}/shader/const_buffer_locker.h"
"${VIDEO_CORE}/shader/control_flow.cpp" "${VIDEO_CORE}/shader/control_flow.cpp"
"${VIDEO_CORE}/shader/control_flow.h" "${VIDEO_CORE}/shader/control_flow.h"
"${VIDEO_CORE}/shader/decode.cpp" "${VIDEO_CORE}/shader/decode.cpp"
@ -99,6 +97,8 @@ set(HASH_FILES
"${VIDEO_CORE}/shader/node.h" "${VIDEO_CORE}/shader/node.h"
"${VIDEO_CORE}/shader/node_helper.cpp" "${VIDEO_CORE}/shader/node_helper.cpp"
"${VIDEO_CORE}/shader/node_helper.h" "${VIDEO_CORE}/shader/node_helper.h"
"${VIDEO_CORE}/shader/registry.cpp"
"${VIDEO_CORE}/shader/registry.h"
"${VIDEO_CORE}/shader/shader_ir.cpp" "${VIDEO_CORE}/shader/shader_ir.cpp"
"${VIDEO_CORE}/shader/shader_ir.h" "${VIDEO_CORE}/shader/shader_ir.h"
"${VIDEO_CORE}/shader/track.cpp" "${VIDEO_CORE}/shader/track.cpp"

View File

@ -70,8 +70,6 @@ add_custom_command(OUTPUT scm_rev.cpp
"${VIDEO_CORE}/shader/ast.h" "${VIDEO_CORE}/shader/ast.h"
"${VIDEO_CORE}/shader/compiler_settings.cpp" "${VIDEO_CORE}/shader/compiler_settings.cpp"
"${VIDEO_CORE}/shader/compiler_settings.h" "${VIDEO_CORE}/shader/compiler_settings.h"
"${VIDEO_CORE}/shader/const_buffer_locker.cpp"
"${VIDEO_CORE}/shader/const_buffer_locker.h"
"${VIDEO_CORE}/shader/control_flow.cpp" "${VIDEO_CORE}/shader/control_flow.cpp"
"${VIDEO_CORE}/shader/control_flow.h" "${VIDEO_CORE}/shader/control_flow.h"
"${VIDEO_CORE}/shader/decode.cpp" "${VIDEO_CORE}/shader/decode.cpp"
@ -80,6 +78,8 @@ add_custom_command(OUTPUT scm_rev.cpp
"${VIDEO_CORE}/shader/node.h" "${VIDEO_CORE}/shader/node.h"
"${VIDEO_CORE}/shader/node_helper.cpp" "${VIDEO_CORE}/shader/node_helper.cpp"
"${VIDEO_CORE}/shader/node_helper.h" "${VIDEO_CORE}/shader/node_helper.h"
"${VIDEO_CORE}/shader/registry.cpp"
"${VIDEO_CORE}/shader/registry.h"
"${VIDEO_CORE}/shader/shader_ir.cpp" "${VIDEO_CORE}/shader/shader_ir.cpp"
"${VIDEO_CORE}/shader/shader_ir.h" "${VIDEO_CORE}/shader/shader_ir.h"
"${VIDEO_CORE}/shader/track.cpp" "${VIDEO_CORE}/shader/track.cpp"

View File

@ -116,8 +116,6 @@ add_library(video_core STATIC
shader/ast.h shader/ast.h
shader/compiler_settings.cpp shader/compiler_settings.cpp
shader/compiler_settings.h shader/compiler_settings.h
shader/const_buffer_locker.cpp
shader/const_buffer_locker.h
shader/control_flow.cpp shader/control_flow.cpp
shader/control_flow.h shader/control_flow.h
shader/decode.cpp shader/decode.cpp
@ -126,6 +124,8 @@ add_library(video_core STATIC
shader/node_helper.cpp shader/node_helper.cpp
shader/node_helper.h shader/node_helper.h
shader/node.h shader/node.h
shader/registry.cpp
shader/registry.h
shader/shader_ir.cpp shader/shader_ir.cpp
shader/shader_ir.h shader/shader_ir.h
shader/track.cpp shader/track.cpp

View File

@ -28,13 +28,14 @@
#include "video_core/renderer_opengl/gl_shader_disk_cache.h" #include "video_core/renderer_opengl/gl_shader_disk_cache.h"
#include "video_core/renderer_opengl/gl_state_tracker.h" #include "video_core/renderer_opengl/gl_state_tracker.h"
#include "video_core/renderer_opengl/utils.h" #include "video_core/renderer_opengl/utils.h"
#include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
namespace OpenGL { namespace OpenGL {
using Tegra::Engines::ShaderType; using Tegra::Engines::ShaderType;
using VideoCommon::Shader::ConstBufferLocker;
using VideoCommon::Shader::ProgramCode; using VideoCommon::Shader::ProgramCode;
using VideoCommon::Shader::Registry;
using VideoCommon::Shader::ShaderIR; using VideoCommon::Shader::ShaderIR;
namespace { namespace {
@ -163,22 +164,22 @@ std::string MakeShaderID(u64 unique_identifier, ShaderType shader_type) {
return fmt::format("{}{:016X}", GetShaderTypeName(shader_type), unique_identifier); return fmt::format("{}{:016X}", GetShaderTypeName(shader_type), unique_identifier);
} }
std::shared_ptr<ConstBufferLocker> MakeLocker(const ShaderDiskCacheEntry& entry) { std::shared_ptr<Registry> MakeRegistry(const ShaderDiskCacheEntry& entry) {
const VideoCore::GuestDriverProfile guest_profile{entry.texture_handler_size}; const VideoCore::GuestDriverProfile guest_profile{entry.texture_handler_size};
auto locker = std::make_shared<ConstBufferLocker>(entry.type, guest_profile); auto registry = std::make_shared<Registry>(entry.type, guest_profile);
locker->SetBoundBuffer(entry.bound_buffer); registry->SetBoundBuffer(entry.bound_buffer);
for (const auto& [address, value] : entry.keys) { for (const auto& [address, value] : entry.keys) {
const auto [buffer, offset] = address; const auto [buffer, offset] = address;
locker->InsertKey(buffer, offset, value); registry->InsertKey(buffer, offset, value);
} }
for (const auto& [offset, sampler] : entry.bound_samplers) { for (const auto& [offset, sampler] : entry.bound_samplers) {
locker->InsertBoundSampler(offset, sampler); registry->InsertBoundSampler(offset, sampler);
} }
for (const auto& [key, sampler] : entry.bindless_samplers) { for (const auto& [key, sampler] : entry.bindless_samplers) {
const auto [buffer, offset] = key; const auto [buffer, offset] = key;
locker->InsertBindlessSampler(buffer, offset, sampler); registry->InsertBindlessSampler(buffer, offset, sampler);
} }
return locker; return registry;
} }
std::shared_ptr<OGLProgram> BuildShader(const Device& device, ShaderType shader_type, std::shared_ptr<OGLProgram> BuildShader(const Device& device, ShaderType shader_type,
@ -211,15 +212,15 @@ std::unordered_set<GLenum> GetSupportedFormats() {
} // Anonymous namespace } // Anonymous namespace
CachedShader::CachedShader(const u8* host_ptr, VAddr cpu_addr, std::size_t size_in_bytes, CachedShader::CachedShader(const u8* host_ptr, VAddr cpu_addr, std::size_t size_in_bytes,
std::shared_ptr<VideoCommon::Shader::ConstBufferLocker> locker, std::shared_ptr<VideoCommon::Shader::Registry> registry,
ShaderEntries entries, std::shared_ptr<OGLProgram> program) ShaderEntries entries, std::shared_ptr<OGLProgram> program)
: RasterizerCacheObject{host_ptr}, locker{std::move(locker)}, entries{std::move(entries)}, : RasterizerCacheObject{host_ptr}, registry{std::move(registry)}, entries{std::move(entries)},
cpu_addr{cpu_addr}, size_in_bytes{size_in_bytes}, program{std::move(program)} {} cpu_addr{cpu_addr}, size_in_bytes{size_in_bytes}, program{std::move(program)} {}
CachedShader::~CachedShader() = default; CachedShader::~CachedShader() = default;
GLuint CachedShader::GetHandle() const { GLuint CachedShader::GetHandle() const {
if (!locker->IsConsistent()) { if (!registry->IsConsistent()) {
std::abort(); std::abort();
} }
return program->handle; return program->handle;
@ -231,8 +232,8 @@ Shader CachedShader::CreateStageFromMemory(const ShaderParameters& params,
const auto shader_type = GetShaderType(program_type); const auto shader_type = GetShaderType(program_type);
const std::size_t size_in_bytes = code.size() * sizeof(u64); const std::size_t size_in_bytes = code.size() * sizeof(u64);
auto locker = std::make_shared<ConstBufferLocker>(shader_type, params.system.GPU().Maxwell3D()); auto registry = std::make_shared<Registry>(shader_type, params.system.GPU().Maxwell3D());
const ShaderIR ir(code, STAGE_MAIN_OFFSET, COMPILER_SETTINGS, *locker); const ShaderIR ir(code, STAGE_MAIN_OFFSET, COMPILER_SETTINGS, *registry);
// TODO(Rodrigo): Handle VertexA shaders // TODO(Rodrigo): Handle VertexA shaders
// std::optional<ShaderIR> ir_b; // std::optional<ShaderIR> ir_b;
// if (!code_b.empty()) { // if (!code_b.empty()) {
@ -245,46 +246,46 @@ Shader CachedShader::CreateStageFromMemory(const ShaderParameters& params,
entry.code = std::move(code); entry.code = std::move(code);
entry.code_b = std::move(code_b); entry.code_b = std::move(code_b);
entry.unique_identifier = params.unique_identifier; entry.unique_identifier = params.unique_identifier;
entry.bound_buffer = locker->GetBoundBuffer(); entry.bound_buffer = registry->GetBoundBuffer();
entry.keys = locker->GetKeys(); entry.keys = registry->GetKeys();
entry.bound_samplers = locker->GetBoundSamplers(); entry.bound_samplers = registry->GetBoundSamplers();
entry.bindless_samplers = locker->GetBindlessSamplers(); entry.bindless_samplers = registry->GetBindlessSamplers();
params.disk_cache.SaveEntry(std::move(entry)); params.disk_cache.SaveEntry(std::move(entry));
return std::shared_ptr<CachedShader>(new CachedShader(params.host_ptr, params.cpu_addr, return std::shared_ptr<CachedShader>(new CachedShader(params.host_ptr, params.cpu_addr,
size_in_bytes, std::move(locker), size_in_bytes, std::move(registry),
MakeEntries(ir), std::move(program))); MakeEntries(ir), std::move(program)));
} }
Shader CachedShader::CreateKernelFromMemory(const ShaderParameters& params, ProgramCode code) { Shader CachedShader::CreateKernelFromMemory(const ShaderParameters& params, ProgramCode code) {
const std::size_t size_in_bytes = code.size() * sizeof(u64); const std::size_t size_in_bytes = code.size() * sizeof(u64);
auto locker = std::make_shared<ConstBufferLocker>(Tegra::Engines::ShaderType::Compute, auto registry =
params.system.GPU().KeplerCompute()); std::make_shared<Registry>(ShaderType::Compute, params.system.GPU().KeplerCompute());
const ShaderIR ir(code, KERNEL_MAIN_OFFSET, COMPILER_SETTINGS, *locker); const ShaderIR ir(code, KERNEL_MAIN_OFFSET, COMPILER_SETTINGS, *registry);
auto program = BuildShader(params.device, ShaderType::Compute, params.unique_identifier, ir); auto program = BuildShader(params.device, ShaderType::Compute, params.unique_identifier, ir);
ShaderDiskCacheEntry entry; ShaderDiskCacheEntry entry;
entry.type = ShaderType::Compute; entry.type = ShaderType::Compute;
entry.code = std::move(code); entry.code = std::move(code);
entry.unique_identifier = params.unique_identifier; entry.unique_identifier = params.unique_identifier;
entry.bound_buffer = locker->GetBoundBuffer(); entry.bound_buffer = registry->GetBoundBuffer();
entry.keys = locker->GetKeys(); entry.keys = registry->GetKeys();
entry.bound_samplers = locker->GetBoundSamplers(); entry.bound_samplers = registry->GetBoundSamplers();
entry.bindless_samplers = locker->GetBindlessSamplers(); entry.bindless_samplers = registry->GetBindlessSamplers();
params.disk_cache.SaveEntry(std::move(entry)); params.disk_cache.SaveEntry(std::move(entry));
return std::shared_ptr<CachedShader>(new CachedShader(params.host_ptr, params.cpu_addr, return std::shared_ptr<CachedShader>(new CachedShader(params.host_ptr, params.cpu_addr,
size_in_bytes, std::move(locker), size_in_bytes, std::move(registry),
MakeEntries(ir), std::move(program))); MakeEntries(ir), std::move(program)));
} }
Shader CachedShader::CreateFromCache(const ShaderParameters& params, Shader CachedShader::CreateFromCache(const ShaderParameters& params,
const PrecompiledShader& precompiled_shader, const PrecompiledShader& precompiled_shader,
std::size_t size_in_bytes) { std::size_t size_in_bytes) {
return std::shared_ptr<CachedShader>( return std::shared_ptr<CachedShader>(new CachedShader(
new CachedShader(params.host_ptr, params.cpu_addr, size_in_bytes, precompiled_shader.locker, params.host_ptr, params.cpu_addr, size_in_bytes, precompiled_shader.registry,
precompiled_shader.entries, precompiled_shader.program)); precompiled_shader.entries, precompiled_shader.program));
} }
ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system, ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system,
@ -336,8 +337,8 @@ void ShaderCacheOpenGL::LoadDiskCache(const std::atomic_bool& stop_loading,
const bool is_compute = entry.type == ShaderType::Compute; const bool is_compute = entry.type == ShaderType::Compute;
const u32 main_offset = is_compute ? KERNEL_MAIN_OFFSET : STAGE_MAIN_OFFSET; const u32 main_offset = is_compute ? KERNEL_MAIN_OFFSET : STAGE_MAIN_OFFSET;
auto locker = MakeLocker(entry); auto registry = MakeRegistry(entry);
const ShaderIR ir(entry.code, main_offset, COMPILER_SETTINGS, *locker); const ShaderIR ir(entry.code, main_offset, COMPILER_SETTINGS, *registry);
std::shared_ptr<OGLProgram> program; std::shared_ptr<OGLProgram> program;
if (precompiled_entry) { if (precompiled_entry) {
@ -354,7 +355,7 @@ void ShaderCacheOpenGL::LoadDiskCache(const std::atomic_bool& stop_loading,
PrecompiledShader shader; PrecompiledShader shader;
shader.program = std::move(program); shader.program = std::move(program);
shader.locker = std::move(locker); shader.registry = std::move(registry);
shader.entries = MakeEntries(ir); shader.entries = MakeEntries(ir);
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};

View File

@ -22,7 +22,7 @@
#include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_disk_cache.h" #include "video_core/renderer_opengl/gl_shader_disk_cache.h"
#include "video_core/shader/const_buffer_locker.h" #include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
namespace Core { namespace Core {
@ -45,7 +45,7 @@ using Maxwell = Tegra::Engines::Maxwell3D::Regs;
struct PrecompiledShader { struct PrecompiledShader {
std::shared_ptr<OGLProgram> program; std::shared_ptr<OGLProgram> program;
std::shared_ptr<VideoCommon::Shader::ConstBufferLocker> locker; std::shared_ptr<VideoCommon::Shader::Registry> registry;
ShaderEntries entries; ShaderEntries entries;
}; };
@ -91,10 +91,10 @@ public:
private: private:
explicit CachedShader(const u8* host_ptr, VAddr cpu_addr, std::size_t size_in_bytes, explicit CachedShader(const u8* host_ptr, VAddr cpu_addr, std::size_t size_in_bytes,
std::shared_ptr<VideoCommon::Shader::ConstBufferLocker> locker, std::shared_ptr<VideoCommon::Shader::Registry> registry,
ShaderEntries entries, std::shared_ptr<OGLProgram> program); ShaderEntries entries, std::shared_ptr<OGLProgram> program);
std::shared_ptr<VideoCommon::Shader::ConstBufferLocker> locker; std::shared_ptr<VideoCommon::Shader::Registry> registry;
ShaderEntries entries; ShaderEntries entries;
VAddr cpu_addr = 0; VAddr cpu_addr = 0;
std::size_t size_in_bytes = 0; std::size_t size_in_bytes = 0;

View File

@ -19,7 +19,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/file_sys/vfs_vector.h" #include "core/file_sys/vfs_vector.h"
#include "video_core/engines/shader_type.h" #include "video_core/engines/shader_type.h"
#include "video_core/shader/const_buffer_locker.h" #include "video_core/shader/registry.h"
namespace Core { namespace Core {
class System; class System;

View File

@ -161,8 +161,8 @@ CachedShader::CachedShader(Core::System& system, Tegra::Engines::ShaderType stag
GPUVAddr gpu_addr, VAddr cpu_addr, u8* host_ptr, GPUVAddr gpu_addr, VAddr cpu_addr, u8* host_ptr,
ProgramCode program_code, u32 main_offset) ProgramCode program_code, u32 main_offset)
: RasterizerCacheObject{host_ptr}, gpu_addr{gpu_addr}, cpu_addr{cpu_addr}, : RasterizerCacheObject{host_ptr}, gpu_addr{gpu_addr}, cpu_addr{cpu_addr},
program_code{std::move(program_code)}, locker{stage, GetEngine(system, stage)}, program_code{std::move(program_code)}, registry{stage, GetEngine(system, stage)},
shader_ir{this->program_code, main_offset, compiler_settings, locker}, shader_ir{this->program_code, main_offset, compiler_settings, registry},
entries{GenerateShaderEntries(shader_ir)} {} entries{GenerateShaderEntries(shader_ir)} {}
CachedShader::~CachedShader() = default; CachedShader::~CachedShader() = default;

View File

@ -25,7 +25,7 @@
#include "video_core/renderer_vulkan/vk_renderpass_cache.h" #include "video_core/renderer_vulkan/vk_renderpass_cache.h"
#include "video_core/renderer_vulkan/vk_resource_manager.h" #include "video_core/renderer_vulkan/vk_resource_manager.h"
#include "video_core/renderer_vulkan/vk_shader_decompiler.h" #include "video_core/renderer_vulkan/vk_shader_decompiler.h"
#include "video_core/shader/const_buffer_locker.h" #include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
#include "video_core/surface.h" #include "video_core/surface.h"
@ -147,7 +147,7 @@ private:
GPUVAddr gpu_addr{}; GPUVAddr gpu_addr{};
VAddr cpu_addr{}; VAddr cpu_addr{};
ProgramCode program_code; ProgramCode program_code;
VideoCommon::Shader::ConstBufferLocker locker; VideoCommon::Shader::Registry registry;
VideoCommon::Shader::ShaderIR shader_ir; VideoCommon::Shader::ShaderIR shader_ir;
ShaderEntries entries; ShaderEntries entries;
}; };

View File

@ -13,6 +13,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/shader/ast.h" #include "video_core/shader/ast.h"
#include "video_core/shader/control_flow.h" #include "video_core/shader/control_flow.h"
#include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
namespace VideoCommon::Shader { namespace VideoCommon::Shader {
@ -64,11 +65,11 @@ struct BlockInfo {
}; };
struct CFGRebuildState { struct CFGRebuildState {
explicit CFGRebuildState(const ProgramCode& program_code, u32 start, ConstBufferLocker& locker) explicit CFGRebuildState(const ProgramCode& program_code, u32 start, Registry& registry)
: program_code{program_code}, locker{locker}, start{start} {} : program_code{program_code}, registry{registry}, start{start} {}
const ProgramCode& program_code; const ProgramCode& program_code;
ConstBufferLocker& locker; Registry& registry;
u32 start{}; u32 start{};
std::vector<BlockInfo> block_info; std::vector<BlockInfo> block_info;
std::list<u32> inspect_queries; std::list<u32> inspect_queries;
@ -438,7 +439,7 @@ std::pair<ParseResult, ParseInfo> ParseCode(CFGRebuildState& state, u32 address)
const s32 pc_target = offset + result.relative_position; const s32 pc_target = offset + result.relative_position;
std::vector<CaseBranch> branches; std::vector<CaseBranch> branches;
for (u32 i = 0; i < result.entries; i++) { for (u32 i = 0; i < result.entries; i++) {
auto key = state.locker.ObtainKey(result.buffer, result.offset + i * 4); auto key = state.registry.ObtainKey(result.buffer, result.offset + i * 4);
if (!key) { if (!key) {
return {ParseResult::AbnormalFlow, parse_info}; return {ParseResult::AbnormalFlow, parse_info};
} }
@ -656,14 +657,14 @@ void DecompileShader(CFGRebuildState& state) {
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 start_address, std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 start_address,
const CompilerSettings& settings, const CompilerSettings& settings,
ConstBufferLocker& locker) { Registry& registry) {
auto result_out = std::make_unique<ShaderCharacteristics>(); auto result_out = std::make_unique<ShaderCharacteristics>();
if (settings.depth == CompileDepth::BruteForce) { if (settings.depth == CompileDepth::BruteForce) {
result_out->settings.depth = CompileDepth::BruteForce; result_out->settings.depth = CompileDepth::BruteForce;
return result_out; return result_out;
} }
CFGRebuildState state{program_code, start_address, locker}; CFGRebuildState state{program_code, start_address, registry};
// Inspect Code and generate blocks // Inspect Code and generate blocks
state.labels.clear(); state.labels.clear();
state.labels.emplace(start_address); state.labels.emplace(start_address);

View File

@ -12,6 +12,7 @@
#include "video_core/engines/shader_bytecode.h" #include "video_core/engines/shader_bytecode.h"
#include "video_core/shader/ast.h" #include "video_core/shader/ast.h"
#include "video_core/shader/compiler_settings.h" #include "video_core/shader/compiler_settings.h"
#include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
namespace VideoCommon::Shader { namespace VideoCommon::Shader {
@ -111,6 +112,6 @@ struct ShaderCharacteristics {
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 start_address, std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code, u32 start_address,
const CompilerSettings& settings, const CompilerSettings& settings,
ConstBufferLocker& locker); Registry& registry);
} // namespace VideoCommon::Shader } // namespace VideoCommon::Shader

View File

@ -141,7 +141,7 @@ void ShaderIR::Decode() {
std::memcpy(&header, program_code.data(), sizeof(Tegra::Shader::Header)); std::memcpy(&header, program_code.data(), sizeof(Tegra::Shader::Header));
decompiled = false; decompiled = false;
auto info = ScanFlow(program_code, main_offset, settings, locker); auto info = ScanFlow(program_code, main_offset, settings, registry);
auto& shader_info = *info; auto& shader_info = *info;
coverage_begin = shader_info.start; coverage_begin = shader_info.start;
coverage_end = shader_info.end; coverage_end = shader_info.end;
@ -356,7 +356,7 @@ u32 ShaderIR::DecodeInstr(NodeBlock& bb, u32 pc) {
void ShaderIR::PostDecode() { void ShaderIR::PostDecode() {
// Deduce texture handler size if needed // Deduce texture handler size if needed
auto gpu_driver = locker.AccessGuestDriverProfile(); auto gpu_driver = registry.AccessGuestDriverProfile();
DeduceTextureHandlerSize(gpu_driver, used_samplers); DeduceTextureHandlerSize(gpu_driver, used_samplers);
// Deduce Indexed Samplers // Deduce Indexed Samplers
if (!uses_indexed_samplers) { if (!uses_indexed_samplers) {

View File

@ -12,6 +12,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "video_core/engines/shader_bytecode.h" #include "video_core/engines/shader_bytecode.h"
#include "video_core/shader/node_helper.h" #include "video_core/shader/node_helper.h"
#include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
namespace VideoCommon::Shader { namespace VideoCommon::Shader {
@ -359,8 +360,8 @@ ShaderIR::SamplerInfo ShaderIR::GetSamplerInfo(std::optional<SamplerInfo> sample
if (sampler_info) { if (sampler_info) {
return *sampler_info; return *sampler_info;
} }
const auto sampler = const auto sampler = buffer ? registry.ObtainBindlessSampler(*buffer, offset)
buffer ? locker.ObtainBindlessSampler(*buffer, offset) : locker.ObtainBoundSampler(offset); : registry.ObtainBoundSampler(offset);
if (!sampler) { if (!sampler) {
LOG_WARNING(HW_GPU, "Unknown sampler info"); LOG_WARNING(HW_GPU, "Unknown sampler info");
return SamplerInfo{TextureType::Texture2D, false, false, false}; return SamplerInfo{TextureType::Texture2D, false, false, false};

View File

@ -8,23 +8,23 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
#include "video_core/engines/shader_type.h" #include "video_core/engines/shader_type.h"
#include "video_core/shader/const_buffer_locker.h" #include "video_core/shader/registry.h"
namespace VideoCommon::Shader { namespace VideoCommon::Shader {
using Tegra::Engines::SamplerDescriptor; using Tegra::Engines::SamplerDescriptor;
ConstBufferLocker::ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, Registry::Registry(Tegra::Engines::ShaderType shader_stage,
VideoCore::GuestDriverProfile stored_guest_driver_profile) VideoCore::GuestDriverProfile stored_guest_driver_profile)
: stage{shader_stage}, stored_guest_driver_profile{stored_guest_driver_profile} {} : stage{shader_stage}, stored_guest_driver_profile{stored_guest_driver_profile} {}
ConstBufferLocker::ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, Registry::Registry(Tegra::Engines::ShaderType shader_stage,
Tegra::Engines::ConstBufferEngineInterface& engine) Tegra::Engines::ConstBufferEngineInterface& engine)
: stage{shader_stage}, engine{&engine} {} : stage{shader_stage}, engine{&engine} {}
ConstBufferLocker::~ConstBufferLocker() = default; Registry::~Registry() = default;
std::optional<u32> ConstBufferLocker::ObtainKey(u32 buffer, u32 offset) { std::optional<u32> Registry::ObtainKey(u32 buffer, u32 offset) {
const std::pair<u32, u32> key = {buffer, offset}; const std::pair<u32, u32> key = {buffer, offset};
const auto iter = keys.find(key); const auto iter = keys.find(key);
if (iter != keys.end()) { if (iter != keys.end()) {
@ -38,7 +38,7 @@ std::optional<u32> ConstBufferLocker::ObtainKey(u32 buffer, u32 offset) {
return value; return value;
} }
std::optional<SamplerDescriptor> ConstBufferLocker::ObtainBoundSampler(u32 offset) { std::optional<SamplerDescriptor> Registry::ObtainBoundSampler(u32 offset) {
const u32 key = offset; const u32 key = offset;
const auto iter = bound_samplers.find(key); const auto iter = bound_samplers.find(key);
if (iter != bound_samplers.end()) { if (iter != bound_samplers.end()) {
@ -52,8 +52,8 @@ std::optional<SamplerDescriptor> ConstBufferLocker::ObtainBoundSampler(u32 offse
return value; return value;
} }
std::optional<Tegra::Engines::SamplerDescriptor> ConstBufferLocker::ObtainBindlessSampler( std::optional<Tegra::Engines::SamplerDescriptor> Registry::ObtainBindlessSampler(u32 buffer,
u32 buffer, u32 offset) { u32 offset) {
const std::pair key = {buffer, offset}; const std::pair key = {buffer, offset};
const auto iter = bindless_samplers.find(key); const auto iter = bindless_samplers.find(key);
if (iter != bindless_samplers.end()) { if (iter != bindless_samplers.end()) {
@ -67,7 +67,7 @@ std::optional<Tegra::Engines::SamplerDescriptor> ConstBufferLocker::ObtainBindle
return value; return value;
} }
std::optional<u32> ConstBufferLocker::ObtainBoundBuffer() { std::optional<u32> Registry::ObtainBoundBuffer() {
if (bound_buffer_saved) { if (bound_buffer_saved) {
return bound_buffer; return bound_buffer;
} }
@ -79,24 +79,24 @@ std::optional<u32> ConstBufferLocker::ObtainBoundBuffer() {
return bound_buffer; return bound_buffer;
} }
void ConstBufferLocker::InsertKey(u32 buffer, u32 offset, u32 value) { void Registry::InsertKey(u32 buffer, u32 offset, u32 value) {
keys.insert_or_assign({buffer, offset}, value); keys.insert_or_assign({buffer, offset}, value);
} }
void ConstBufferLocker::InsertBoundSampler(u32 offset, SamplerDescriptor sampler) { void Registry::InsertBoundSampler(u32 offset, SamplerDescriptor sampler) {
bound_samplers.insert_or_assign(offset, sampler); bound_samplers.insert_or_assign(offset, sampler);
} }
void ConstBufferLocker::InsertBindlessSampler(u32 buffer, u32 offset, SamplerDescriptor sampler) { void Registry::InsertBindlessSampler(u32 buffer, u32 offset, SamplerDescriptor sampler) {
bindless_samplers.insert_or_assign({buffer, offset}, sampler); bindless_samplers.insert_or_assign({buffer, offset}, sampler);
} }
void ConstBufferLocker::SetBoundBuffer(u32 buffer) { void Registry::SetBoundBuffer(u32 buffer) {
bound_buffer_saved = true; bound_buffer_saved = true;
bound_buffer = buffer; bound_buffer = buffer;
} }
bool ConstBufferLocker::IsConsistent() const { bool Registry::IsConsistent() const {
if (!engine) { if (!engine) {
return true; return true;
} }
@ -119,7 +119,7 @@ bool ConstBufferLocker::IsConsistent() const {
}); });
} }
bool ConstBufferLocker::HasEqualKeys(const ConstBufferLocker& rhs) const { bool Registry::HasEqualKeys(const Registry& rhs) const {
return std::tie(keys, bound_samplers, bindless_samplers) == return std::tie(keys, bound_samplers, bindless_samplers) ==
std::tie(rhs.keys, rhs.bound_samplers, rhs.bindless_samplers); std::tie(rhs.keys, rhs.bound_samplers, rhs.bindless_samplers);
} }

View File

@ -20,21 +20,21 @@ using BindlessSamplerMap =
std::unordered_map<std::pair<u32, u32>, Tegra::Engines::SamplerDescriptor, Common::PairHash>; std::unordered_map<std::pair<u32, u32>, Tegra::Engines::SamplerDescriptor, Common::PairHash>;
/** /**
* The ConstBufferLocker is a class use to interface the 3D and compute engines with the shader * The Registry is a class use to interface the 3D and compute engines with the shader compiler.
* compiler. with it, the shader can obtain required data from GPU state and store it for disk * With it, the shader can obtain required data from GPU state and store it for disk shader
* shader compilation. * compilation.
*/ */
class ConstBufferLocker { class Registry {
public: public:
explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, explicit Registry(Tegra::Engines::ShaderType shader_stage,
VideoCore::GuestDriverProfile stored_guest_driver_profile); VideoCore::GuestDriverProfile stored_guest_driver_profile);
explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, explicit Registry(Tegra::Engines::ShaderType shader_stage,
Tegra::Engines::ConstBufferEngineInterface& engine); Tegra::Engines::ConstBufferEngineInterface& engine);
~ConstBufferLocker(); ~Registry();
/// Retrieves a key from the locker, if it's registered, it will give the registered value, if /// Retrieves a key from the registry, if it's registered, it will give the registered value, if
/// not it will obtain it from maxwell3d and register it. /// not it will obtain it from maxwell3d and register it.
std::optional<u32> ObtainKey(u32 buffer, u32 offset); std::optional<u32> ObtainKey(u32 buffer, u32 offset);
@ -53,15 +53,15 @@ public:
/// Inserts a bindless sampler key. /// Inserts a bindless sampler key.
void InsertBindlessSampler(u32 buffer, u32 offset, Tegra::Engines::SamplerDescriptor sampler); void InsertBindlessSampler(u32 buffer, u32 offset, Tegra::Engines::SamplerDescriptor sampler);
/// Set the bound buffer for this locker. /// Set the bound buffer for this registry.
void SetBoundBuffer(u32 buffer); void SetBoundBuffer(u32 buffer);
/// Checks keys and samplers against engine's current const buffers. Returns true if they are /// Checks keys and samplers against engine's current const buffers.
/// the same value, false otherwise; /// Returns true if they are the same value, false otherwise.
bool IsConsistent() const; bool IsConsistent() const;
/// Returns true if the keys are equal to the other ones in the locker. /// Returns true if the keys are equal to the other ones in the registry.
bool HasEqualKeys(const ConstBufferLocker& rhs) const; bool HasEqualKeys(const Registry& rhs) const;
/// Gives an getter to the const buffer keys in the database. /// Gives an getter to the const buffer keys in the database.
const KeyMap& GetKeys() const { const KeyMap& GetKeys() const {

View File

@ -11,6 +11,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "video_core/engines/shader_bytecode.h" #include "video_core/engines/shader_bytecode.h"
#include "video_core/shader/node_helper.h" #include "video_core/shader/node_helper.h"
#include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h" #include "video_core/shader/shader_ir.h"
namespace VideoCommon::Shader { namespace VideoCommon::Shader {
@ -24,8 +25,8 @@ using Tegra::Shader::PredOperation;
using Tegra::Shader::Register; using Tegra::Shader::Register;
ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset, CompilerSettings settings, ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset, CompilerSettings settings,
ConstBufferLocker& locker) Registry& registry)
: program_code{program_code}, main_offset{main_offset}, settings{settings}, locker{locker} { : program_code{program_code}, main_offset{main_offset}, settings{settings}, registry{registry} {
Decode(); Decode();
PostDecode(); PostDecode();
} }

View File

@ -18,8 +18,8 @@
#include "video_core/engines/shader_header.h" #include "video_core/engines/shader_header.h"
#include "video_core/shader/ast.h" #include "video_core/shader/ast.h"
#include "video_core/shader/compiler_settings.h" #include "video_core/shader/compiler_settings.h"
#include "video_core/shader/const_buffer_locker.h"
#include "video_core/shader/node.h" #include "video_core/shader/node.h"
#include "video_core/shader/registry.h"
namespace VideoCommon::Shader { namespace VideoCommon::Shader {
@ -69,7 +69,7 @@ struct GlobalMemoryUsage {
class ShaderIR final { class ShaderIR final {
public: public:
explicit ShaderIR(const ProgramCode& program_code, u32 main_offset, CompilerSettings settings, explicit ShaderIR(const ProgramCode& program_code, u32 main_offset, CompilerSettings settings,
ConstBufferLocker& locker); Registry& registry);
~ShaderIR(); ~ShaderIR();
const std::map<u32, NodeBlock>& GetBasicBlocks() const { const std::map<u32, NodeBlock>& GetBasicBlocks() const {
@ -414,7 +414,7 @@ private:
const ProgramCode& program_code; const ProgramCode& program_code;
const u32 main_offset; const u32 main_offset;
const CompilerSettings settings; const CompilerSettings settings;
ConstBufferLocker& locker; Registry& registry;
bool decompiled{}; bool decompiled{};
bool disable_flow_stack{}; bool disable_flow_stack{};

View File

@ -81,7 +81,7 @@ std::tuple<Node, TrackSampler> ShaderIR::TrackBindlessSampler(Node tracked, cons
MakeTrackSampler<BindlessSamplerNode>(cbuf->GetIndex(), immediate->GetValue()); MakeTrackSampler<BindlessSamplerNode>(cbuf->GetIndex(), immediate->GetValue());
return {tracked, track}; return {tracked, track};
} else if (const auto operation = std::get_if<OperationNode>(&*offset)) { } else if (const auto operation = std::get_if<OperationNode>(&*offset)) {
auto bound_buffer = locker.ObtainBoundBuffer(); const auto bound_buffer = registry.ObtainBoundBuffer();
if (!bound_buffer) { if (!bound_buffer) {
return {}; return {};
} }
@ -94,7 +94,7 @@ std::tuple<Node, TrackSampler> ShaderIR::TrackBindlessSampler(Node tracked, cons
} }
auto [gpr, base_offset] = *pair; auto [gpr, base_offset] = *pair;
const auto offset_inm = std::get_if<ImmediateNode>(&*base_offset); const auto offset_inm = std::get_if<ImmediateNode>(&*base_offset);
const auto& gpu_driver = locker.AccessGuestDriverProfile(); const auto& gpu_driver = registry.AccessGuestDriverProfile();
const u32 bindless_cv = NewCustomVariable(); const u32 bindless_cv = NewCustomVariable();
const Node op = const Node op =
Operation(OperationCode::UDiv, gpr, Immediate(gpu_driver.GetTextureHandlerSize())); Operation(OperationCode::UDiv, gpr, Immediate(gpu_driver.GetTextureHandlerSize()));