yuzu/src/video_core/renderer_opengl/gl_shader_cache.h

89 lines
3.2 KiB
C
Raw Normal View History

2022-04-23 22:49:07 +04:00
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-12-28 19:15:37 +04:00
#pragma once
2021-07-10 01:54:15 +04:00
#include <filesystem>
#include <stop_token>
2020-12-28 19:15:37 +04:00
#include <unordered_map>
#include "common/common_types.h"
2021-07-10 01:54:15 +04:00
#include "common/thread_worker.h"
#include "shader_recompiler/host_translate_info.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"
2020-12-28 19:15:37 +04:00
#include "video_core/shader_cache.h"
namespace Tegra {
class MemoryManager;
}
namespace OpenGL {
class Device;
2021-07-10 01:54:15 +04:00
class ProgramManager;
2020-12-28 19:15:37 +04:00
class RasterizerOpenGL;
2021-07-10 01:54:15 +04:00
using ShaderWorker = Common::StatefulThreadWorker<ShaderContext::Context>;
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
class ShaderCache : public VideoCommon::ShaderCache {
2020-12-28 19:15:37 +04:00
public:
2021-07-10 01:54:15 +04:00
explicit ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindow& emu_window_,
2022-06-16 05:46:18 +04:00
const Device& device_, TextureCache& texture_cache_,
BufferCache& buffer_cache_, ProgramManager& program_manager_,
StateTracker& state_tracker_, VideoCore::ShaderNotify& shader_notify_);
2021-07-10 01:54:15 +04:00
~ShaderCache();
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
const VideoCore::DiskResourceLoadCallback& callback);
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
[[nodiscard]] GraphicsPipeline* CurrentGraphicsPipeline();
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
[[nodiscard]] ComputePipeline* CurrentComputePipeline();
2020-12-28 19:15:37 +04:00
private:
2021-07-10 01:54:15 +04:00
GraphicsPipeline* CurrentGraphicsPipelineSlowPath();
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
[[nodiscard]] GraphicsPipeline* BuiltPipeline(GraphicsPipeline* pipeline) const noexcept;
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline();
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline(
ShaderContext::ShaderPools& pools, const GraphicsPipelineKey& key,
std::span<Shader::Environment* const> envs, bool build_in_parallel);
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
std::unique_ptr<ComputePipeline> CreateComputePipeline(const ComputePipelineKey& key,
const VideoCommon::ShaderInfo* shader);
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
std::unique_ptr<ComputePipeline> CreateComputePipeline(ShaderContext::ShaderPools& pools,
const ComputePipelineKey& key,
Shader::Environment& env);
std::unique_ptr<ShaderWorker> CreateWorkers() const;
2020-12-28 19:15:37 +04:00
Core::Frontend::EmuWindow& emu_window;
const Device& device;
2021-07-10 01:54:15 +04:00
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{};
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
ShaderContext::ShaderPools main_pools;
std::unordered_map<GraphicsPipelineKey, std::unique_ptr<GraphicsPipeline>> graphics_cache;
std::unordered_map<ComputePipelineKey, std::unique_ptr<ComputePipeline>> compute_cache;
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
Shader::Profile profile;
Shader::HostTranslateInfo host_info;
2020-12-28 19:15:37 +04:00
2021-07-10 01:54:15 +04:00
std::filesystem::path shader_cache_filename;
std::unique_ptr<ShaderWorker> workers;
2020-12-28 19:15:37 +04:00
};
} // namespace OpenGL