yuzu/src/video_core/renderer_opengl/gl_shader_cache.h

95 lines
3.2 KiB
C++
Raw Normal View History

// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <array>
2021-05-26 01:39:55 +02:00
#include <filesystem>
#include <stop_token>
#include <unordered_map>
2019-01-05 05:00:06 +01:00
#include <glad/glad.h>
#include "common/common_types.h"
2021-05-23 09:28:34 +02:00
#include "shader_recompiler/frontend/ir/basic_block.h"
#include "shader_recompiler/frontend/ir/value.h"
#include "shader_recompiler/frontend/maxwell/control_flow.h"
#include "shader_recompiler/object_pool.h"
#include "video_core/engines/shader_type.h"
#include "video_core/renderer_opengl/gl_compute_pipeline.h"
#include "video_core/renderer_opengl/gl_graphics_pipeline.h"
#include "video_core/shader_cache.h"
namespace Tegra {
class MemoryManager;
}
namespace OpenGL {
class Device;
2021-05-23 09:28:34 +02:00
class ProgramManager;
class RasterizerOpenGL;
2021-05-23 09:28:34 +02:00
struct ShaderPools {
void ReleaseContents() {
flow_block.ReleaseContents();
block.ReleaseContents();
inst.ReleaseContents();
}
2021-05-23 09:28:34 +02:00
Shader::ObjectPool<Shader::IR::Inst> inst;
Shader::ObjectPool<Shader::IR::Block> block;
Shader::ObjectPool<Shader::Maxwell::Flow::Block> flow_block;
};
class ShaderCache : public VideoCommon::ShaderCache {
public:
explicit ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindow& emu_window_,
2021-05-23 09:28:34 +02:00
Tegra::Engines::Maxwell3D& maxwell3d_,
Tegra::Engines::KeplerCompute& kepler_compute_,
2021-05-23 09:28:34 +02:00
Tegra::MemoryManager& gpu_memory_, const Device& device_,
TextureCache& texture_cache_, BufferCache& buffer_cache_,
ProgramManager& program_manager_, StateTracker& state_tracker_);
~ShaderCache();
2021-05-26 01:39:55 +02:00
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
const VideoCore::DiskResourceLoadCallback& callback);
[[nodiscard]] GraphicsPipeline* CurrentGraphicsPipeline();
2021-05-23 09:28:34 +02:00
[[nodiscard]] ComputePipeline* CurrentComputePipeline();
2021-05-23 09:28:34 +02:00
private:
std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline();
2021-05-23 09:28:34 +02:00
std::unique_ptr<GraphicsPipeline> CreateGraphicsPipeline(
ShaderPools& pools, const GraphicsPipelineKey& key,
2021-05-27 22:51:00 +02:00
std::span<Shader::Environment* const> envs);
2021-05-23 09:28:34 +02:00
std::unique_ptr<ComputePipeline> CreateComputePipeline(const ComputePipelineKey& key,
const VideoCommon::ShaderInfo* shader);
2021-05-23 09:28:34 +02:00
std::unique_ptr<ComputePipeline> CreateComputePipeline(ShaderPools& pools,
const ComputePipelineKey& key,
2021-05-27 22:51:00 +02:00
Shader::Environment& env);
2021-05-23 09:28:34 +02:00
Core::Frontend::EmuWindow& emu_window;
const Device& device;
2021-05-23 09:28:34 +02:00
TextureCache& texture_cache;
BufferCache& buffer_cache;
ProgramManager& program_manager;
StateTracker& state_tracker;
GraphicsPipelineKey graphics_key{};
2021-05-23 09:28:34 +02:00
ShaderPools main_pools;
std::unordered_map<GraphicsPipelineKey, std::unique_ptr<GraphicsPipeline>> graphics_cache;
std::unordered_map<ComputePipelineKey, std::unique_ptr<ComputePipeline>> compute_cache;
Shader::Profile profile;
2021-05-26 01:39:55 +02:00
std::filesystem::path shader_cache_filename;
};
} // namespace OpenGL