diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-02-29 00:53:10 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-03-09 22:40:06 +0100 |
commit | e8efd5a90100a86899e31a4de0137e915e0e0366 (patch) | |
tree | 586964f8bf2036517d7fb40c2f93b9e7e1bb058b /src/video_core/shader/registry.h | |
parent | gl_shader_cache: Rework shader cache and remove post-specializations (diff) | |
download | yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.tar yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.tar.gz yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.tar.bz2 yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.tar.lz yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.tar.xz yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.tar.zst yuzu-e8efd5a90100a86899e31a4de0137e915e0e0366.zip |
Diffstat (limited to 'src/video_core/shader/registry.h')
-rw-r--r-- | src/video_core/shader/registry.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/video_core/shader/registry.h b/src/video_core/shader/registry.h new file mode 100644 index 000000000..a5487e1d7 --- /dev/null +++ b/src/video_core/shader/registry.h @@ -0,0 +1,102 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <optional> +#include <unordered_map> +#include "common/common_types.h" +#include "common/hash.h" +#include "video_core/engines/const_buffer_engine_interface.h" +#include "video_core/engines/shader_type.h" +#include "video_core/guest_driver.h" + +namespace VideoCommon::Shader { + +using KeyMap = std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>; +using BoundSamplerMap = std::unordered_map<u32, Tegra::Engines::SamplerDescriptor>; +using BindlessSamplerMap = + std::unordered_map<std::pair<u32, u32>, Tegra::Engines::SamplerDescriptor, Common::PairHash>; + +/** + * The Registry is a class use to interface the 3D and compute engines with the shader compiler. + * With it, the shader can obtain required data from GPU state and store it for disk shader + * compilation. + */ +class Registry { +public: + explicit Registry(Tegra::Engines::ShaderType shader_stage, + VideoCore::GuestDriverProfile stored_guest_driver_profile); + + explicit Registry(Tegra::Engines::ShaderType shader_stage, + Tegra::Engines::ConstBufferEngineInterface& engine); + + ~Registry(); + + /// 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. + std::optional<u32> ObtainKey(u32 buffer, u32 offset); + + std::optional<Tegra::Engines::SamplerDescriptor> ObtainBoundSampler(u32 offset); + + std::optional<Tegra::Engines::SamplerDescriptor> ObtainBindlessSampler(u32 buffer, u32 offset); + + std::optional<u32> ObtainBoundBuffer(); + + /// Inserts a key. + void InsertKey(u32 buffer, u32 offset, u32 value); + + /// Inserts a bound sampler key. + void InsertBoundSampler(u32 offset, Tegra::Engines::SamplerDescriptor sampler); + + /// Inserts a bindless sampler key. + void InsertBindlessSampler(u32 buffer, u32 offset, Tegra::Engines::SamplerDescriptor sampler); + + /// Set the bound buffer for this registry. + void SetBoundBuffer(u32 buffer); + + /// Checks keys and samplers against engine's current const buffers. + /// Returns true if they are the same value, false otherwise. + bool IsConsistent() const; + + /// Returns true if the keys are equal to the other ones in the registry. + bool HasEqualKeys(const Registry& rhs) const; + + /// Gives an getter to the const buffer keys in the database. + const KeyMap& GetKeys() const { + return keys; + } + + /// Gets samplers database. + const BoundSamplerMap& GetBoundSamplers() const { + return bound_samplers; + } + + /// Gets bindless samplers database. + const BindlessSamplerMap& GetBindlessSamplers() const { + return bindless_samplers; + } + + /// Gets bound buffer used on this shader + u32 GetBoundBuffer() const { + return bound_buffer; + } + + /// Obtains access to the guest driver's profile. + VideoCore::GuestDriverProfile& AccessGuestDriverProfile() { + return engine ? engine->AccessGuestDriverProfile() : stored_guest_driver_profile; + } + +private: + const Tegra::Engines::ShaderType stage; + VideoCore::GuestDriverProfile stored_guest_driver_profile; + Tegra::Engines::ConstBufferEngineInterface* engine = nullptr; + KeyMap keys; + BoundSamplerMap bound_samplers; + BindlessSamplerMap bindless_samplers; + bool bound_buffer_saved{}; + u32 bound_buffer{}; +}; + +} // namespace VideoCommon::Shader |