2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-08-23 23:30:27 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-05-26 01:39:55 +02:00
|
|
|
#include <filesystem>
|
2019-02-03 01:14:36 +01:00
|
|
|
#include <unordered_map>
|
2019-01-05 05:00:06 +01:00
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "common/common_types.h"
|
2021-06-06 05:35:57 +02:00
|
|
|
#include "common/thread_worker.h"
|
2021-06-16 08:03:08 +02:00
|
|
|
#include "shader_recompiler/host_translate_info.h"
|
2021-06-16 08:22:56 +02:00
|
|
|
#include "shader_recompiler/profile.h"
|
2021-05-25 23:58:28 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_compute_pipeline.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_graphics_pipeline.h"
|
2021-06-15 03:06:29 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_context.h"
|
2020-05-23 01:55:38 +02:00
|
|
|
#include "video_core/shader_cache.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
namespace Tegra {
|
|
|
|
class MemoryManager;
|
2019-04-06 22:59:56 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2019-04-10 23:03:52 +02:00
|
|
|
class Device;
|
2021-05-23 09:28:34 +02:00
|
|
|
class ProgramManager;
|
2018-11-08 12:08:00 +01:00
|
|
|
class RasterizerOpenGL;
|
2021-06-15 03:06:29 +02:00
|
|
|
using ShaderWorker = Common::StatefulThreadWorker<ShaderContext::Context>;
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2021-04-26 08:53:26 +02:00
|
|
|
class ShaderCache : public VideoCommon::ShaderCache {
|
2018-08-23 23:30:27 +02:00
|
|
|
public:
|
2021-04-26 08:53:26 +02:00
|
|
|
explicit ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindow& emu_window_,
|
2021-11-05 15:52:31 +01:00
|
|
|
const Device& device_, TextureCache& texture_cache_,
|
|
|
|
BufferCache& buffer_cache_, ProgramManager& program_manager_,
|
|
|
|
StateTracker& state_tracker_, VideoCore::ShaderNotify& shader_notify_);
|
2021-04-26 08:53:26 +02:00
|
|
|
~ShaderCache();
|
2018-11-08 12:08:00 +01:00
|
|
|
|
2021-05-26 01:39:55 +02:00
|
|
|
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
|
|
|
const VideoCore::DiskResourceLoadCallback& callback);
|
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
[[nodiscard]] GraphicsPipeline* CurrentGraphicsPipeline();
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
[[nodiscard]] ComputePipeline* CurrentComputePipeline();
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2019-01-06 07:58:43 +01:00
|
|
|
private:
|
2021-06-20 07:23:50 +02:00
|
|
|
GraphicsPipeline* CurrentGraphicsPipelineSlowPath();
|
|
|
|
|
2021-07-02 02:32:30 +02:00
|
|
|
[[nodiscard]] GraphicsPipeline* BuiltPipeline(GraphicsPipeline* pipeline) const noexcept;
|
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline();
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline(
|
2021-06-15 03:06:29 +02:00
|
|
|
ShaderContext::ShaderPools& pools, const GraphicsPipelineKey& key,
|
2023-01-30 02:26:49 +01:00
|
|
|
std::span<Shader::Environment* const> envs, bool use_shader_workers,
|
|
|
|
bool force_context_flush = false);
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
std::unique_ptr<ComputePipeline> CreateComputePipeline(const ComputePipelineKey& key,
|
|
|
|
const VideoCommon::ShaderInfo* shader);
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-06-15 03:06:29 +02:00
|
|
|
std::unique_ptr<ComputePipeline> CreateComputePipeline(ShaderContext::ShaderPools& pools,
|
2021-05-25 23:58:28 +02:00
|
|
|
const ComputePipelineKey& key,
|
2023-01-30 03:04:46 +01:00
|
|
|
Shader::Environment& env,
|
|
|
|
bool force_context_flush = false);
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-06-15 03:06:29 +02:00
|
|
|
std::unique_ptr<ShaderWorker> CreateWorkers() const;
|
2021-06-06 05:35:57 +02:00
|
|
|
|
2019-04-06 22:59:56 +02:00
|
|
|
Core::Frontend::EmuWindow& emu_window;
|
2019-04-10 23:03:52 +02:00
|
|
|
const Device& device;
|
2021-05-23 09:28:34 +02:00
|
|
|
TextureCache& texture_cache;
|
|
|
|
BufferCache& buffer_cache;
|
|
|
|
ProgramManager& program_manager;
|
|
|
|
StateTracker& state_tracker;
|
2021-06-15 03:06:29 +02:00
|
|
|
VideoCore::ShaderNotify& shader_notify;
|
2021-06-20 07:23:50 +02:00
|
|
|
const bool use_asynchronous_shaders;
|
2022-12-13 18:30:15 +01:00
|
|
|
const bool strict_context_required;
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
GraphicsPipelineKey graphics_key{};
|
2021-06-20 07:23:50 +02:00
|
|
|
GraphicsPipeline* current_pipeline{};
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-06-15 03:06:29 +02:00
|
|
|
ShaderContext::ShaderPools main_pools;
|
2021-05-25 23:58:28 +02:00
|
|
|
std::unordered_map<GraphicsPipelineKey, std::unique_ptr<GraphicsPipeline>> graphics_cache;
|
|
|
|
std::unordered_map<ComputePipelineKey, std::unique_ptr<ComputePipeline>> compute_cache;
|
2021-05-22 01:46:40 +02:00
|
|
|
|
|
|
|
Shader::Profile profile;
|
2021-06-16 08:03:08 +02:00
|
|
|
Shader::HostTranslateInfo host_info;
|
|
|
|
|
2021-05-26 01:39:55 +02:00
|
|
|
std::filesystem::path shader_cache_filename;
|
2021-06-15 03:06:29 +02:00
|
|
|
std::unique_ptr<ShaderWorker> workers;
|
2018-08-23 23:30:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenGL
|