2018-08-23 23:30:27 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-01-06 07:58:43 +01:00
|
|
|
#include <array>
|
2019-02-03 01:14:36 +01:00
|
|
|
#include <unordered_map>
|
2019-01-05 05:00:06 +01:00
|
|
|
|
|
|
|
#include <glad/glad.h>
|
2018-08-23 23:30:27 +02:00
|
|
|
|
|
|
|
#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"
|
2019-11-18 22:35:21 +01:00
|
|
|
#include "video_core/engines/shader_type.h"
|
2021-05-23 09:28:34 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_compute_program.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_graphics_program.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
|
|
|
}
|
|
|
|
|
|
|
|
namespace Core::Frontend {
|
|
|
|
class EmuWindow;
|
|
|
|
}
|
2019-01-15 20:28:42 +01: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-05-23 09:28:34 +02:00
|
|
|
struct ShaderPools {
|
|
|
|
void ReleaseContents() {
|
|
|
|
flow_block.ReleaseContents();
|
|
|
|
block.ReleaseContents();
|
|
|
|
inst.ReleaseContents();
|
2021-04-26 08:53:26 +02:00
|
|
|
}
|
|
|
|
|
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;
|
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-05-23 09:28:34 +02:00
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d_,
|
2021-04-26 08:53:26 +02:00
|
|
|
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_);
|
2021-04-26 08:53:26 +02:00
|
|
|
~ShaderCache();
|
2018-11-08 12:08:00 +01:00
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
[[nodiscard]] GraphicsProgram* CurrentGraphicsProgram();
|
|
|
|
|
|
|
|
[[nodiscard]] ComputeProgram* CurrentComputeProgram();
|
|
|
|
|
2019-01-06 07:58:43 +01:00
|
|
|
private:
|
2021-05-23 09:28:34 +02:00
|
|
|
std::unique_ptr<GraphicsProgram> CreateGraphicsProgram();
|
|
|
|
|
|
|
|
std::unique_ptr<GraphicsProgram> CreateGraphicsProgram(
|
|
|
|
ShaderPools& pools, const GraphicsProgramKey& key,
|
|
|
|
std::span<Shader::Environment* const> envs, bool build_in_parallel);
|
|
|
|
|
|
|
|
std::unique_ptr<ComputeProgram> CreateComputeProgram(const ComputeProgramKey& key,
|
|
|
|
const VideoCommon::ShaderInfo* shader);
|
|
|
|
|
|
|
|
std::unique_ptr<ComputeProgram> CreateComputeProgram(ShaderPools& pools,
|
|
|
|
const ComputeProgramKey& key,
|
|
|
|
Shader::Environment& env,
|
|
|
|
bool build_in_parallel);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
GraphicsProgramKey graphics_key{};
|
|
|
|
|
|
|
|
ShaderPools main_pools;
|
|
|
|
std::unordered_map<GraphicsProgramKey, std::unique_ptr<GraphicsProgram>> graphics_cache;
|
|
|
|
std::unordered_map<ComputeProgramKey, std::unique_ptr<ComputeProgram>> compute_cache;
|
2021-05-22 01:46:40 +02:00
|
|
|
|
|
|
|
Shader::Profile profile;
|
2018-08-23 23:30:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenGL
|