diff options
author | bunnei <bunneidev@gmail.com> | 2021-07-25 20:39:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-25 20:39:04 +0200 |
commit | 98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f (patch) | |
tree | 816faa96c2c4d291825063433331a8ea4b3d08f1 /src/video_core/renderer_opengl/gl_shader_cache.h | |
parent | Merge pull request #6699 from lat9nq/common-threads (diff) | |
parent | shader: Support out of bound local memory reads and immediate writes (diff) | |
download | yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.gz yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.bz2 yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.lz yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.xz yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.zst yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.zip |
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_cache.h')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.h | 172 |
1 files changed, 54 insertions, 118 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h index b30308b6f..a34110b37 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_cache.h @@ -5,157 +5,93 @@ #pragma once #include <array> -#include <atomic> -#include <bitset> -#include <memory> -#include <string> -#include <tuple> +#include <filesystem> +#include <stop_token> #include <unordered_map> -#include <unordered_set> -#include <vector> #include <glad/glad.h> #include "common/common_types.h" -#include "video_core/engines/shader_type.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_disk_cache.h" -#include "video_core/shader/registry.h" -#include "video_core/shader/shader_ir.h" +#include "common/thread_worker.h" +#include "shader_recompiler/frontend/ir/value.h" +#include "shader_recompiler/host_translate_info.h" +#include "shader_recompiler/object_pool.h" +#include "shader_recompiler/profile.h" +#include "video_core/renderer_opengl/gl_compute_pipeline.h" +#include "video_core/renderer_opengl/gl_graphics_pipeline.h" +#include "video_core/renderer_opengl/gl_shader_context.h" #include "video_core/shader_cache.h" namespace Tegra { class MemoryManager; } -namespace Core::Frontend { -class EmuWindow; -} - -namespace VideoCommon::Shader { -class AsyncShaders; -} - namespace OpenGL { class Device; +class ProgramManager; class RasterizerOpenGL; +using ShaderWorker = Common::StatefulThreadWorker<ShaderContext::Context>; -using Maxwell = Tegra::Engines::Maxwell3D::Regs; - -struct ProgramHandle { - OGLProgram source_program; - OGLAssemblyProgram assembly_program; -}; -using ProgramSharedPtr = std::shared_ptr<ProgramHandle>; - -struct PrecompiledShader { - ProgramSharedPtr program; - std::shared_ptr<VideoCommon::Shader::Registry> registry; - ShaderEntries entries; -}; - -struct ShaderParameters { - Tegra::GPU& gpu; - Tegra::Engines::ConstBufferEngineInterface& engine; - ShaderDiskCacheOpenGL& disk_cache; - const Device& device; - VAddr cpu_addr; - const u8* host_ptr; - u64 unique_identifier; -}; - -ProgramSharedPtr BuildShader(const Device& device, Tegra::Engines::ShaderType shader_type, - u64 unique_identifier, const VideoCommon::Shader::ShaderIR& ir, - const VideoCommon::Shader::Registry& registry, - bool hint_retrievable = false); - -class Shader final { +class ShaderCache : public VideoCommon::ShaderCache { public: - ~Shader(); - - /// Gets the GL program handle for the shader - GLuint GetHandle() const; - - bool IsBuilt() const; - - /// Gets the shader entries for the shader - const ShaderEntries& GetEntries() const { - return entries; - } - - const VideoCommon::Shader::Registry& GetRegistry() const { - return *registry; - } - - /// Mark a OpenGL shader as built - void AsyncOpenGLBuilt(OGLProgram new_program); + explicit ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindow& emu_window_, + Tegra::Engines::Maxwell3D& maxwell3d_, + Tegra::Engines::KeplerCompute& kepler_compute_, + Tegra::MemoryManager& gpu_memory_, const Device& device_, + TextureCache& texture_cache_, BufferCache& buffer_cache_, + ProgramManager& program_manager_, StateTracker& state_tracker_, + VideoCore::ShaderNotify& shader_notify_); + ~ShaderCache(); - /// Mark a GLASM shader as built - void AsyncGLASMBuilt(OGLAssemblyProgram new_program); + void LoadDiskResources(u64 title_id, std::stop_token stop_loading, + const VideoCore::DiskResourceLoadCallback& callback); - static std::unique_ptr<Shader> CreateStageFromMemory( - const ShaderParameters& params, Maxwell::ShaderProgram program_type, - ProgramCode program_code, ProgramCode program_code_b, - VideoCommon::Shader::AsyncShaders& async_shaders, VAddr cpu_addr); + [[nodiscard]] GraphicsPipeline* CurrentGraphicsPipeline(); - static std::unique_ptr<Shader> CreateKernelFromMemory(const ShaderParameters& params, - ProgramCode code); - - static std::unique_ptr<Shader> CreateFromCache(const ShaderParameters& params, - const PrecompiledShader& precompiled_shader); + [[nodiscard]] ComputePipeline* CurrentComputePipeline(); private: - explicit Shader(std::shared_ptr<VideoCommon::Shader::Registry> registry, ShaderEntries entries, - ProgramSharedPtr program, bool is_built_ = true); - - std::shared_ptr<VideoCommon::Shader::Registry> registry; - ShaderEntries entries; - ProgramSharedPtr program; - GLuint handle = 0; - bool is_built{}; -}; + GraphicsPipeline* CurrentGraphicsPipelineSlowPath(); -class ShaderCacheOpenGL final : public VideoCommon::ShaderCache<Shader> { -public: - explicit ShaderCacheOpenGL(RasterizerOpenGL& rasterizer_, - Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu, - Tegra::Engines::Maxwell3D& maxwell3d_, - Tegra::Engines::KeplerCompute& kepler_compute_, - Tegra::MemoryManager& gpu_memory_, const Device& device_); - ~ShaderCacheOpenGL() override; + [[nodiscard]] GraphicsPipeline* BuiltPipeline(GraphicsPipeline* pipeline) const noexcept; - /// Loads disk cache for the current game - void LoadDiskCache(u64 title_id, std::stop_token stop_loading, - const VideoCore::DiskResourceLoadCallback& callback); + std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline(); - /// Gets the current specified shader stage program - Shader* GetStageProgram(Maxwell::ShaderProgram program, - VideoCommon::Shader::AsyncShaders& async_shaders); + std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline( + ShaderContext::ShaderPools& pools, const GraphicsPipelineKey& key, + std::span<Shader::Environment* const> envs, bool build_in_parallel); - /// Gets a compute kernel in the passed address - Shader* GetComputeKernel(GPUVAddr code_addr); + std::unique_ptr<ComputePipeline> CreateComputePipeline(const ComputePipelineKey& key, + const VideoCommon::ShaderInfo* shader); -private: - ProgramSharedPtr GeneratePrecompiledProgram( - const ShaderDiskCacheEntry& entry, const ShaderDiskCachePrecompiled& precompiled_entry, - const std::unordered_set<GLenum>& supported_formats); + std::unique_ptr<ComputePipeline> CreateComputePipeline(ShaderContext::ShaderPools& pools, + const ComputePipelineKey& key, + Shader::Environment& env); + + std::unique_ptr<ShaderWorker> CreateWorkers() const; Core::Frontend::EmuWindow& emu_window; - Tegra::GPU& gpu; - Tegra::MemoryManager& gpu_memory; - Tegra::Engines::Maxwell3D& maxwell3d; - Tegra::Engines::KeplerCompute& kepler_compute; const Device& device; + TextureCache& texture_cache; + BufferCache& buffer_cache; + ProgramManager& program_manager; + StateTracker& state_tracker; + VideoCore::ShaderNotify& shader_notify; + const bool use_asynchronous_shaders; + + GraphicsPipelineKey graphics_key{}; + GraphicsPipeline* current_pipeline{}; - ShaderDiskCacheOpenGL disk_cache; - std::unordered_map<u64, PrecompiledShader> runtime_cache; + ShaderContext::ShaderPools main_pools; + std::unordered_map<GraphicsPipelineKey, std::unique_ptr<GraphicsPipeline>> graphics_cache; + std::unordered_map<ComputePipelineKey, std::unique_ptr<ComputePipeline>> compute_cache; - std::unique_ptr<Shader> null_shader; - std::unique_ptr<Shader> null_kernel; + Shader::Profile profile; + Shader::HostTranslateInfo host_info; - std::array<Shader*, Maxwell::MaxShaderProgram> last_shaders{}; + std::filesystem::path shader_cache_filename; + std::unique_ptr<ShaderWorker> workers; }; } // namespace OpenGL |