Compare commits

..

1 Commits

Author SHA1 Message Date
b94374009e code: Add texture sampling option
* This replaces the nearest neighbour filter that shouldn't have existed in the first place
2023-11-23 01:22:47 +02:00
21 changed files with 474 additions and 277 deletions

View File

@ -184,11 +184,6 @@
<string>Bicubic</string>
</property>
</item>
<item>
<property name="text">
<string>Nearest Neighbor</string>
</property>
</item>
<item>
<property name="text">
<string>ScaleForce</string>
@ -199,11 +194,11 @@
<string>xBRZ</string>
</property>
</item>
<item>
<property name="text">
<string>MMPX</string>
</property>
</item>
<item>
<property name="text">
<string>MMPX</string>
</property>
</item>
</widget>
</item>
</layout>

View File

@ -71,11 +71,17 @@ void ConfigureGraphics::SetConfiguration() {
!Settings::values.physical_device.UsingGlobal());
ConfigurationShared::SetPerGameSetting(ui->physical_device_combo,
&Settings::values.physical_device);
ConfigurationShared::SetPerGameSetting(ui->texture_sampling_combobox,
&Settings::values.texture_sampling);
ConfigurationShared::SetHighlight(ui->widget_texture_sampling,
!Settings::values.texture_sampling.UsingGlobal());
} else {
ui->graphics_api_combo->setCurrentIndex(
static_cast<int>(Settings::values.graphics_api.GetValue()));
ui->physical_device_combo->setCurrentIndex(
static_cast<int>(Settings::values.physical_device.GetValue()));
ui->texture_sampling_combobox->setCurrentIndex(
static_cast<int>(Settings::values.texture_sampling.GetValue()));
}
ui->toggle_hw_shader->setChecked(Settings::values.use_hw_shader.GetValue());
@ -106,6 +112,8 @@ void ConfigureGraphics::ApplyConfiguration() {
use_hw_shader);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.shaders_accurate_mul,
ui->toggle_accurate_mul, shaders_accurate_mul);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.texture_sampling,
ui->texture_sampling_combobox);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache,
ui->toggle_disk_shader_cache, use_disk_shader_cache);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync_new, ui->toggle_vsync_new,
@ -132,6 +140,7 @@ void ConfigureGraphics::SetupPerGameUI() {
Settings::values.use_vsync_new.UsingGlobal());
ui->toggle_async_shaders->setEnabled(
Settings::values.async_shader_compilation.UsingGlobal());
ui->widget_texture_sampling->setEnabled(Settings::values.texture_sampling.UsingGlobal());
ui->toggle_async_present->setEnabled(Settings::values.async_presentation.UsingGlobal());
ui->graphics_api_combo->setEnabled(Settings::values.graphics_api.UsingGlobal());
ui->physical_device_combo->setEnabled(Settings::values.physical_device.UsingGlobal());
@ -148,6 +157,10 @@ void ConfigureGraphics::SetupPerGameUI() {
ui->physical_device_combo, ui->physical_device_group,
static_cast<u32>(Settings::values.physical_device.GetValue(true)));
ConfigurationShared::SetColoredComboBox(
ui->texture_sampling_combobox, ui->widget_texture_sampling,
static_cast<int>(Settings::values.texture_sampling.GetValue(true)));
ConfigurationShared::SetColoredTristate(ui->toggle_hw_shader, Settings::values.use_hw_shader,
use_hw_shader);
ConfigurationShared::SetColoredTristate(

View File

@ -212,6 +212,53 @@
<string>Advanced</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget_texture_sampling" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="texture_sampling_label">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Overrides the sampling filter used by games. This can be useful in certain cases with poorly behaved games when upscaling. If unsure set this to Game Controlled&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Texture Sampling</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="texture_sampling_combobox">
<item>
<property name="text">
<string>Game Controlled</string>
</property>
</item>
<item>
<property name="text">
<string>Nearest Neighbor</string>
</property>
</item>
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="toggle_disk_shader_cache">
<property name="toolTip">

View File

@ -46,8 +46,6 @@ std::string_view GetTextureFilterName(TextureFilter filter) {
return "Anime4K";
case TextureFilter::Bicubic:
return "Bicubic";
case TextureFilter::NearestNeighbor:
return "NearestNeighbor";
case TextureFilter::ScaleForce:
return "ScaleForce";
case TextureFilter::xBRZ:
@ -59,6 +57,19 @@ std::string_view GetTextureFilterName(TextureFilter filter) {
}
}
std::string_view GetTextureSamplingName(TextureSampling sampling) {
switch (sampling) {
case TextureSampling::GameControlled:
return "GameControlled";
case TextureSampling::NearestNeighbor:
return "NearestNeighbor";
case TextureSampling::Linear:
return "Linear";
default:
return "Invalid";
}
}
} // Anonymous namespace
Values values = {};
@ -87,6 +98,8 @@ void LogSettings() {
log_setting("Renderer_PostProcessingShader", values.pp_shader_name.GetValue());
log_setting("Renderer_FilterMode", values.filter_mode.GetValue());
log_setting("Renderer_TextureFilter", GetTextureFilterName(values.texture_filter.GetValue()));
log_setting("Renderer_TextureSampling",
GetTextureSamplingName(values.texture_sampling.GetValue()));
log_setting("Stereoscopy_Render3d", values.render_3d.GetValue());
log_setting("Stereoscopy_Factor3d", values.factor_3d.GetValue());
log_setting("Stereoscopy_MonoRenderOption", values.mono_render_option.GetValue());
@ -175,6 +188,7 @@ void RestoreGlobalState(bool is_powered_on) {
values.resolution_factor.SetGlobal(true);
values.frame_limit.SetGlobal(true);
values.texture_filter.SetGlobal(true);
values.texture_sampling.SetGlobal(true);
values.layout_option.SetGlobal(true);
values.swap_screen.SetGlobal(true);
values.upright_screen.SetGlobal(true);

View File

@ -72,10 +72,15 @@ enum class TextureFilter : u32 {
None = 0,
Anime4K = 1,
Bicubic = 2,
NearestNeighbor = 3,
ScaleForce = 4,
xBRZ = 5,
MMPX = 6
ScaleForce = 3,
xBRZ = 4,
MMPX = 5,
};
enum class TextureSampling : u32 {
GameControlled = 0,
NearestNeighbor = 1,
Linear = 2,
};
namespace NativeButton {
@ -451,6 +456,8 @@ struct Values {
SwitchableSetting<u32, true> resolution_factor{1, 0, 10, "resolution_factor"};
SwitchableSetting<u16, true> frame_limit{100, 0, 1000, "frame_limit"};
SwitchableSetting<TextureFilter> texture_filter{TextureFilter::None, "texture_filter"};
SwitchableSetting<TextureSampling> texture_sampling{TextureSampling::GameControlled,
"texture_sampling"};
SwitchableSetting<LayoutOption> layout_option{LayoutOption::Default, "layout_option"};
SwitchableSetting<bool> swap_screen{false, "swap_screen"};

View File

@ -7,7 +7,6 @@ set(SHADER_FILES
format_reinterpreter/rgba4_to_rgb5a1.frag
format_reinterpreter/vulkan_d24s8_to_rgba8.comp
texture_filtering/bicubic.frag
texture_filtering/nearest_neighbor.frag
texture_filtering/refine.frag
texture_filtering/scale_force.frag
texture_filtering/xbrz_freescale.frag

View File

@ -1,15 +0,0 @@
// Copyright 2023 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
//? #version 430 core
precision mediump float;
layout(location = 0) in vec2 tex_coord;
layout(location = 0) out vec4 frag_color;
layout(binding = 2) uniform sampler2D input_texture;
void main() {
frag_color = texture(input_texture, tex_coord);
}

View File

@ -361,10 +361,25 @@ typename T::Sampler& RasterizerCache<T>::GetSampler(SamplerId sampler_id) {
template <class T>
typename T::Sampler& RasterizerCache<T>::GetSampler(
const Pica::TexturingRegs::TextureConfig& config) {
using TextureFilter = Pica::TexturingRegs::TextureConfig::TextureFilter;
const auto get_filter = [](TextureFilter filter) {
switch (Settings::values.texture_sampling.GetValue()) {
case Settings::TextureSampling::GameControlled:
return filter;
case Settings::TextureSampling::NearestNeighbor:
return TextureFilter::Nearest;
case Settings::TextureSampling::Linear:
return TextureFilter::Linear;
default:
return filter;
}
};
const SamplerParams params = {
.mag_filter = config.mag_filter,
.min_filter = config.min_filter,
.mip_filter = config.mip_filter,
.mag_filter = get_filter(config.mag_filter),
.min_filter = get_filter(config.min_filter),
.mip_filter = get_filter(config.mip_filter),
.wrap_s = config.wrap_s,
.wrap_t = config.wrap_t,
.border_color = config.border_color.raw,

View File

@ -15,7 +15,6 @@
#include "video_core/host_shaders/full_screen_triangle_vert.h"
#include "video_core/host_shaders/texture_filtering/bicubic_frag.h"
#include "video_core/host_shaders/texture_filtering/mmpx_frag.h"
#include "video_core/host_shaders/texture_filtering/nearest_neighbor_frag.h"
#include "video_core/host_shaders/texture_filtering/refine_frag.h"
#include "video_core/host_shaders/texture_filtering/scale_force_frag.h"
#include "video_core/host_shaders/texture_filtering/x_gradient_frag.h"
@ -58,7 +57,6 @@ BlitHelper::BlitHelper(const Driver& driver_)
: driver{driver_}, linear_sampler{CreateSampler(GL_LINEAR)},
nearest_sampler{CreateSampler(GL_NEAREST)}, bicubic_program{CreateProgram(
HostShaders::BICUBIC_FRAG)},
nearest_program{CreateProgram(HostShaders::NEAREST_NEIGHBOR_FRAG)},
scale_force_program{CreateProgram(HostShaders::SCALE_FORCE_FRAG)},
xbrz_program{CreateProgram(HostShaders::XBRZ_FREESCALE_FRAG)},
mmpx_program{CreateProgram(HostShaders::MMPX_FRAG)}, gradient_x_program{CreateProgram(
@ -175,9 +173,6 @@ bool BlitHelper::Filter(Surface& surface, const VideoCore::TextureBlit& blit) {
case TextureFilter::Bicubic:
FilterBicubic(surface, blit);
break;
case TextureFilter::NearestNeighbor:
FilterNearest(surface, blit);
break;
case TextureFilter::ScaleForce:
FilterScaleForce(surface, blit);
break;
@ -257,14 +252,6 @@ void BlitHelper::FilterBicubic(Surface& surface, const VideoCore::TextureBlit& b
Draw(bicubic_program, surface.Handle(), draw_fbo.handle, blit.dst_level, blit.dst_rect);
}
void BlitHelper::FilterNearest(Surface& surface, const VideoCore::TextureBlit& blit) {
const OpenGLState prev_state = OpenGLState::GetCurState();
SCOPE_EXIT({ prev_state.Apply(); });
state.texture_units[2].texture_2d = surface.Handle(0);
SetParams(nearest_program, surface.RealExtent(false), blit.src_rect);
Draw(nearest_program, surface.Handle(), draw_fbo.handle, blit.dst_level, blit.dst_rect);
}
void BlitHelper::FilterScaleForce(Surface& surface, const VideoCore::TextureBlit& blit) {
const OpenGLState prev_state = OpenGLState::GetCurState();
SCOPE_EXIT({ prev_state.Apply(); });

View File

@ -33,20 +33,13 @@ public:
private:
void FilterAnime4K(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterBicubic(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterNearest(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterScaleForce(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterXbrz(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterMMPX(Surface& surface, const VideoCore::TextureBlit& blit);
void SetParams(OGLProgram& program, const VideoCore::Extent& src_extent,
Common::Rectangle<u32> src_rect);
void Draw(OGLProgram& program, GLuint dst_tex, GLuint dst_fbo, u32 dst_level,
Common::Rectangle<u32> dst_rect);
@ -59,7 +52,6 @@ private:
OGLSampler nearest_sampler;
OGLProgram bicubic_program;
OGLProgram nearest_program;
OGLProgram scale_force_program;
OGLProgram xbrz_program;
OGLProgram mmpx_program;

View File

@ -78,8 +78,8 @@ RasterizerOpenGL::RasterizerOpenGL(Memory::MemorySystem& memory,
VideoCore::CustomTexManager& custom_tex_manager,
VideoCore::RendererBase& renderer, Driver& driver_)
: VideoCore::RasterizerAccelerated{memory}, driver{driver_},
shader_manager{renderer.GetRenderWindow(), driver}, runtime{driver, renderer},
res_cache{memory, custom_tex_manager, runtime, regs, renderer},
shader_manager{renderer.GetRenderWindow(), driver, !driver.IsOpenGLES()},
runtime{driver, renderer}, res_cache{memory, custom_tex_manager, runtime, regs, renderer},
texture_buffer_size{TextureBufferSize()}, vertex_buffer{driver, GL_ARRAY_BUFFER,
VERTEX_BUFFER_SIZE},
uniform_buffer{driver, GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE},

View File

@ -2,10 +2,14 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/microprofile.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_util.h"
#include "video_core/renderer_opengl/gl_state.h"
MICROPROFILE_DEFINE(OpenGL_ResourceCreation, "OpenGL", "Resource Creation", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(OpenGL_ResourceDeletion, "OpenGL", "Resource Deletion", MP_RGB(128, 128, 192));
namespace OpenGL {
void OGLRenderbuffer::Create() {
@ -13,6 +17,7 @@ void OGLRenderbuffer::Create() {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenRenderbuffers(1, &handle);
}
@ -21,6 +26,7 @@ void OGLRenderbuffer::Release() {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteRenderbuffers(1, &handle);
OpenGLState::GetCurState().ResetRenderbuffer(handle).Apply();
handle = 0;
@ -31,6 +37,7 @@ void OGLTexture::Create() {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenTextures(1, &handle);
}
@ -39,6 +46,7 @@ void OGLTexture::Release() {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteTextures(1, &handle);
OpenGLState::GetCurState().ResetTexture(handle).Apply();
handle = 0;
@ -80,6 +88,7 @@ void OGLSampler::Create() {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenSamplers(1, &handle);
}
@ -88,41 +97,37 @@ void OGLSampler::Release() {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteSamplers(1, &handle);
OpenGLState::GetCurState().ResetSampler(handle).Apply();
handle = 0;
}
void OGLShader::Create(std::string_view source, GLenum type) {
if (handle != 0) {
if (handle != 0)
return;
}
if (source.empty()) {
if (source.empty())
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
handle = LoadShader(source, type);
}
void OGLShader::Release() {
if (handle == 0) {
if (handle == 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteShader(handle);
handle = 0;
}
void OGLProgram::Create(std::string_view source, GLenum type) {
if (handle != 0) {
void OGLProgram::Create(bool separable_program, std::span<const GLuint> shaders) {
if (handle != 0)
return;
}
if (source.empty()) {
return;
}
const std::array sources{GetPreamble().data(), source.data()};
handle = glCreateShaderProgramv(type, 2, sources.data());
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
handle = LoadProgram(separable_program, shaders);
}
void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shader) {
@ -130,87 +135,88 @@ void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shad
vert.Create(vert_shader, GL_VERTEX_SHADER);
frag.Create(frag_shader, GL_FRAGMENT_SHADER);
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
const std::array shaders{vert.handle, frag.handle};
handle = LoadProgram(shaders);
Create(false, shaders);
}
void OGLProgram::Release() {
if (handle == 0) {
if (handle == 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteProgram(handle);
OpenGLState::GetCurState().ResetProgram(handle).Apply();
handle = 0;
}
void OGLPipeline::Create() {
if (handle != 0) {
if (handle != 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenProgramPipelines(1, &handle);
}
void OGLPipeline::Release() {
if (handle == 0) {
if (handle == 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteProgramPipelines(1, &handle);
OpenGLState::GetCurState().ResetPipeline(handle).Apply();
handle = 0;
}
void OGLBuffer::Create() {
if (handle != 0) {
if (handle != 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenBuffers(1, &handle);
}
void OGLBuffer::Release() {
if (handle == 0) {
if (handle == 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteBuffers(1, &handle);
OpenGLState::GetCurState().ResetBuffer(handle).Apply();
handle = 0;
}
void OGLVertexArray::Create() {
if (handle != 0) {
if (handle != 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenVertexArrays(1, &handle);
}
void OGLVertexArray::Release() {
if (handle == 0) {
if (handle == 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteVertexArrays(1, &handle);
OpenGLState::GetCurState().ResetVertexArray(handle).Apply();
handle = 0;
}
void OGLFramebuffer::Create() {
if (handle != 0) {
if (handle != 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenFramebuffers(1, &handle);
}
void OGLFramebuffer::Release() {
if (handle == 0) {
if (handle == 0)
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteFramebuffers(1, &handle);
OpenGLState::GetCurState().ResetFramebuffer(handle).Apply();
handle = 0;

View File

@ -130,7 +130,7 @@ public:
}
/// Creates a new program from given shader objects
void Create(std::string_view source, GLenum type);
void Create(bool separable_program, std::span<const GLuint> shaders);
/// Creates a new program from given shader soruce code
void Create(std::string_view vert_shader, std::string_view frag_shader);

View File

@ -103,8 +103,10 @@ bool ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const {
return true;
}
ShaderDiskCache::ShaderDiskCache()
: transferable_file(AppendTransferableFile()), precompiled_file(AppendPrecompiledFile()) {}
ShaderDiskCache::ShaderDiskCache(bool separable)
: separable{separable}, transferable_file(AppendTransferableFile()),
// seperable shaders use the virtual precompile file, that already has a header.
precompiled_file(AppendPrecompiledFile(!separable)) {}
std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() {
const bool has_title_id = GetProgramID() != 0;
@ -175,7 +177,7 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
}
std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>
ShaderDiskCache::LoadPrecompiled() {
ShaderDiskCache::LoadPrecompiled(bool compressed) {
if (!IsUsable())
return {};
@ -185,7 +187,7 @@ ShaderDiskCache::LoadPrecompiled() {
return {};
}
const auto result = LoadPrecompiledFile(precompiled_file);
const auto result = LoadPrecompiledFile(precompiled_file, compressed);
if (!result) {
LOG_INFO(Render_OpenGL,
"Failed to load precompiled cache for game with title id={} - removing",
@ -197,16 +199,22 @@ ShaderDiskCache::LoadPrecompiled() {
}
std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>>
ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file) {
ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file, bool compressed) {
// Read compressed file from disk and decompress to virtual precompiled cache file
std::vector<u8> precompiled_file(file.GetSize());
file.ReadBytes(precompiled_file.data(), precompiled_file.size());
const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(precompiled_file);
if (decompressed.empty()) {
LOG_ERROR(Render_OpenGL, "Could not decompress precompiled shader cache.");
return std::nullopt;
if (compressed) {
const std::vector<u8> decompressed =
Common::Compression::DecompressDataZSTD(precompiled_file);
if (decompressed.empty()) {
LOG_ERROR(Render_OpenGL, "Could not decompress precompiled shader cache.");
return std::nullopt;
}
SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
} else {
SaveArrayToPrecompiled(precompiled_file.data(), precompiled_file.size());
}
SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
decompressed_precompiled_cache_offset = 0;
ShaderCacheVersionHash file_hash{};
@ -345,7 +353,7 @@ void ShaderDiskCache::InvalidatePrecompiled() {
if (!FileUtil::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
}
precompiled_file = AppendPrecompiledFile();
precompiled_file = AppendPrecompiledFile(!separable);
}
void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) {
@ -463,11 +471,12 @@ FileUtil::IOFile ShaderDiskCache::AppendTransferableFile() {
return file;
}
FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile() {
FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile(bool write_header) {
if (!EnsureDirectories())
return {};
const auto precompiled_path{GetPrecompiledPath()};
const bool existed = FileUtil::Exists(precompiled_path);
FileUtil::IOFile file(precompiled_path, "ab+");
if (!file.IsOpen()) {
@ -475,6 +484,15 @@ FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile() {
return {};
}
// If the file didn't exist, write its version
if (write_header && (!existed || file.GetSize() == 0)) {
const auto hash{GetShaderCacheVersionHash()};
if (file.WriteArray(hash.data(), hash.size()) != hash.size()) {
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
precompiled_path);
return {};
}
}
return file;
}
@ -498,7 +516,7 @@ void ShaderDiskCache::SaveVirtualPrecompiledFile() {
if (!FileUtil::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
}
precompiled_file = AppendPrecompiledFile();
precompiled_file = AppendPrecompiledFile(!separable);
if (precompiled_file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) {
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
@ -540,7 +558,10 @@ std::string ShaderDiskCache::GetPrecompiledDir() const {
}
std::string ShaderDiskCache::GetPrecompiledShaderDir() const {
return GetPrecompiledDir() + DIR_SEP "separable";
if (separable) {
return GetPrecompiledDir() + DIR_SEP "separable";
}
return GetPrecompiledDir() + DIR_SEP "conventional";
}
std::string ShaderDiskCache::GetBaseDir() const {

View File

@ -16,8 +16,11 @@
#include <glad/glad.h>
#include "common/assert.h"
#include "common/common_types.h"
#include "common/file_util.h"
#include "video_core/shader/generator/shader_gen.h"
#include "video_core/regs.h"
#include "video_core/shader/generator/glsl_shader_gen.h"
namespace Core {
class System;
@ -87,14 +90,14 @@ struct ShaderDiskCacheDump {
class ShaderDiskCache {
public:
explicit ShaderDiskCache();
explicit ShaderDiskCache(bool separable);
~ShaderDiskCache() = default;
/// Loads transferable cache. If file has a old version or on failure, it deletes the file.
std::optional<std::vector<ShaderDiskCacheRaw>> LoadTransferable();
/// Loads current game's precompiled cache. Invalidates on failure.
std::pair<ShaderDecompiledMap, ShaderDumpsMap> LoadPrecompiled();
std::pair<ShaderDecompiledMap, ShaderDumpsMap> LoadPrecompiled(bool compressed);
/// Removes the transferable (and precompiled) cache file.
void InvalidateAll();
@ -120,7 +123,7 @@ public:
private:
/// Loads the transferable cache. Returns empty on failure.
std::optional<std::pair<ShaderDecompiledMap, ShaderDumpsMap>> LoadPrecompiledFile(
FileUtil::IOFile& file);
FileUtil::IOFile& file, bool compressed);
/// Loads a decompiled cache entry from m_precompiled_cache_virtual_file. Returns empty on
/// failure.
@ -140,7 +143,7 @@ private:
FileUtil::IOFile AppendTransferableFile();
/// Opens current game's precompiled file and write it's header if it doesn't exist
FileUtil::IOFile AppendPrecompiledFile();
FileUtil::IOFile AppendPrecompiledFile(bool write_header);
/// Save precompiled header to precompiled_cache_in_memory
void SavePrecompiledHeaderToVirtualPrecompiledCache();
@ -216,6 +219,8 @@ private:
// The cache has been loaded at boot
bool tried_to_load{};
bool separable{};
u64 program_id{};
std::string title_id;

View File

@ -14,7 +14,7 @@
#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
#include "video_core/renderer_opengl/gl_shader_manager.h"
#include "video_core/renderer_opengl/gl_state.h"
#include "video_core/shader/generator/glsl_shader_gen.h"
#include "video_core/shader/generator/shader_uniforms.h"
#include "video_core/video_core.h"
using namespace Pica::Shader::Generator;
@ -35,16 +35,19 @@ static u64 GetUniqueIdentifier(const Pica::Regs& regs, const ProgramCode& code)
}
static OGLProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump,
const std::set<GLenum>& supported_formats) {
const std::set<GLenum>& supported_formats,
bool separable) {
if (supported_formats.find(dump.binary_format) == supported_formats.end()) {
LOG_INFO(Render_OpenGL, "Precompiled cache entry with unsupported format - removing");
return {};
}
OGLProgram shader{};
auto shader = OGLProgram();
shader.handle = glCreateProgram();
glProgramParameteri(shader.handle, GL_PROGRAM_SEPARABLE, GL_TRUE);
if (separable) {
glProgramParameteri(shader.handle, GL_PROGRAM_SEPARABLE, GL_TRUE);
}
glProgramBinary(shader.handle, dump.binary_format, dump.binary.data(),
static_cast<GLsizei>(dump.binary.size()));
@ -87,42 +90,91 @@ static std::tuple<PicaVSConfig, Pica::Shader::ShaderSetup> BuildVSConfigFromRaw(
setup};
}
class TrivialVertexShader {
/**
* An object representing a shader program staging. It can be either a shader object or a program
* object, depending on whether separable program is used.
*/
class OGLShaderStage {
public:
explicit TrivialVertexShader(const Driver& driver) {
const auto code = GLSL::GenerateTrivialVertexShader(driver.HasClipCullDistance(), true);
program.Create(code, GL_VERTEX_SHADER);
explicit OGLShaderStage(bool separable) {
if (separable) {
shader_or_program = OGLProgram();
} else {
shader_or_program = OGLShader();
}
}
GLuint Get() const {
return program.handle;
void Create(const char* source, GLenum type) {
if (shader_or_program.index() == 0) {
std::get<OGLShader>(shader_or_program).Create(source, type);
} else {
OGLShader shader;
shader.Create(source, type);
OGLProgram& program = std::get<OGLProgram>(shader_or_program);
program.Create(true, std::array{shader.handle});
}
}
GLuint GetHandle() const {
if (shader_or_program.index() == 0) {
return std::get<OGLShader>(shader_or_program).handle;
} else {
return std::get<OGLProgram>(shader_or_program).handle;
}
}
void Inject(OGLProgram&& program) {
shader_or_program = std::move(program);
}
private:
OGLProgram program;
std::variant<OGLShader, OGLProgram> shader_or_program;
};
template <typename KeyConfigType, auto CodeGenerator, GLenum ShaderType>
class ShaderCache {
class TrivialVertexShader {
public:
explicit ShaderCache() = default;
std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& config) {
auto [iter, new_shader] = shaders.try_emplace(config);
OGLProgram& cached_shader = iter->second;
std::optional<std::string> result{};
if (new_shader) {
result = CodeGenerator(config, true);
cached_shader.Create(result.value(), ShaderType);
}
return {cached_shader.handle, std::move(result)};
explicit TrivialVertexShader(const Driver& driver, bool separable) : program(separable) {
const auto code =
GLSL::GenerateTrivialVertexShader(driver.HasClipCullDistance(), separable);
program.Create(code.c_str(), GL_VERTEX_SHADER);
}
GLuint Get() const {
return program.GetHandle();
}
void Inject(const KeyConfigType& key, OGLProgram&& stage) {
private:
OGLShaderStage program;
};
template <typename KeyConfigType, std::string (*CodeGenerator)(const KeyConfigType&, bool),
GLenum ShaderType>
class ShaderCache {
public:
explicit ShaderCache(bool separable) : separable(separable) {}
std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& config) {
auto [iter, new_shader] = shaders.emplace(config, OGLShaderStage{separable});
OGLShaderStage& cached_shader = iter->second;
std::optional<std::string> result{};
if (new_shader) {
result = CodeGenerator(config, separable);
cached_shader.Create(result->c_str(), ShaderType);
}
return {cached_shader.GetHandle(), std::move(result)};
}
void Inject(const KeyConfigType& key, OGLProgram&& program) {
OGLShaderStage stage{separable};
stage.Inject(std::move(program));
shaders.emplace(key, std::move(stage));
}
void Inject(const KeyConfigType& key, OGLShaderStage&& stage) {
shaders.emplace(key, std::move(stage));
}
private:
std::unordered_map<KeyConfigType, OGLProgram> shaders;
bool separable;
std::unordered_map<KeyConfigType, OGLShaderStage> shaders;
};
// This is a cache designed for shaders translated from PICA shaders. The first cache matches the
@ -130,48 +182,59 @@ private:
// GLSL code. The configuration is like this because there might be leftover code in the PICA shader
// program buffer from the previous shader, which is hashed into the config, resulting several
// different config values from the same shader program.
template <typename KeyConfigType, auto CodeGenerator, GLenum ShaderType>
template <typename KeyConfigType,
std::string (*CodeGenerator)(const Pica::Shader::ShaderSetup&, const KeyConfigType&,
bool),
GLenum ShaderType>
class ShaderDoubleCache {
public:
explicit ShaderDoubleCache() = default;
explicit ShaderDoubleCache(bool separable) : separable(separable) {}
std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& key,
const Pica::Shader::ShaderSetup& setup) {
std::optional<std::string> result{};
auto map_it = shader_map.find(key);
if (map_it == shader_map.end()) {
const auto program = CodeGenerator(setup, key, separable);
auto program = CodeGenerator(setup, key, separable);
if (program.empty()) {
shader_map[key] = nullptr;
return {0, std::nullopt};
}
const auto [iter, new_shader] = shader_cache.try_emplace(program);
OGLProgram& cached_shader = iter->second;
auto [iter, new_shader] = shader_cache.emplace(program, OGLShaderStage{separable});
OGLShaderStage& cached_shader = iter->second;
if (new_shader) {
result = program;
cached_shader.Create(program, ShaderType);
cached_shader.Create(program.c_str(), ShaderType);
}
shader_map[key] = &cached_shader;
return {cached_shader.handle, std::move(result)};
return {cached_shader.GetHandle(), std::move(result)};
}
if (map_it->second == nullptr) {
return {0, std::nullopt};
}
return {map_it->second->handle, std::nullopt};
return {map_it->second->GetHandle(), std::nullopt};
}
void Inject(const KeyConfigType& key, std::string decomp, OGLProgram&& program) {
const auto iter = shader_cache.emplace(std::move(decomp), std::move(program)).first;
shader_map.insert_or_assign(key, &iter->second);
OGLShaderStage stage{separable};
stage.Inject(std::move(program));
const auto iter = shader_cache.emplace(std::move(decomp), std::move(stage)).first;
OGLShaderStage& cached_shader = iter->second;
shader_map.insert_or_assign(key, &cached_shader);
}
void Inject(const KeyConfigType& key, std::string decomp, OGLShaderStage&& stage) {
const auto iter = shader_cache.emplace(std::move(decomp), std::move(stage)).first;
OGLShaderStage& cached_shader = iter->second;
shader_map.insert_or_assign(key, &cached_shader);
}
private:
bool separable;
std::unordered_map<KeyConfigType, OGLProgram*> shader_map;
std::unordered_map<std::string, OGLProgram> shader_cache;
std::unordered_map<KeyConfigType, OGLShaderStage*> shader_map;
std::unordered_map<std::string, OGLShaderStage> shader_cache;
};
using ProgrammableVertexShaders =
@ -185,8 +248,12 @@ using FragmentShaders =
class ShaderProgramManager::Impl {
public:
explicit Impl(const Driver& driver) : trivial_vertex_shader(driver) {
pipeline.Create();
explicit Impl(const Driver& driver, bool separable)
: separable(separable), programmable_vertex_shaders(separable),
trivial_vertex_shader(driver, separable), fixed_geometry_shaders(separable),
fragment_shaders(separable), disk_cache(separable) {
if (separable)
pipeline.Create();
}
struct ShaderTuple {
@ -215,6 +282,8 @@ public:
static_assert(offsetof(ShaderTuple, fs_hash) == sizeof(std::size_t) * 2,
"ShaderTuple layout changed!");
bool separable;
ShaderTuple current;
ProgrammableVertexShaders programmable_vertex_shaders;
@ -228,10 +297,11 @@ public:
ShaderDiskCache disk_cache;
};
ShaderProgramManager::ShaderProgramManager(Frontend::EmuWindow& emu_window_, const Driver& driver_)
ShaderProgramManager::ShaderProgramManager(Frontend::EmuWindow& emu_window_, const Driver& driver_,
bool separable)
: emu_window{emu_window_}, driver{driver_},
strict_context_required{emu_window.StrictContextRequired()}, impl{std::make_unique<Impl>(
driver_)} {}
driver_, separable)} {}
ShaderProgramManager::~ShaderProgramManager() = default;
@ -293,18 +363,30 @@ void ShaderProgramManager::UseFragmentShader(const Pica::Regs& regs, bool use_no
}
void ShaderProgramManager::ApplyTo(OpenGLState& state) {
if (driver.HasBug(DriverBug::ShaderStageChangeFreeze)) {
glUseProgramStages(impl->pipeline.handle,
GL_VERTEX_SHADER_BIT | GL_GEOMETRY_SHADER_BIT | GL_FRAGMENT_SHADER_BIT,
0);
if (impl->separable) {
if (driver.HasBug(DriverBug::ShaderStageChangeFreeze)) {
glUseProgramStages(
impl->pipeline.handle,
GL_VERTEX_SHADER_BIT | GL_GEOMETRY_SHADER_BIT | GL_FRAGMENT_SHADER_BIT, 0);
}
glUseProgramStages(impl->pipeline.handle, GL_VERTEX_SHADER_BIT, impl->current.vs);
glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs);
glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs);
state.draw.shader_program = 0;
state.draw.program_pipeline = impl->pipeline.handle;
} else {
const u64 unique_identifier = impl->current.GetConfigHash();
OGLProgram& cached_program = impl->program_cache[unique_identifier];
if (cached_program.handle == 0) {
cached_program.Create(false,
std::array{impl->current.vs, impl->current.gs, impl->current.fs});
auto& disk_cache = impl->disk_cache;
disk_cache.SaveDumpToFile(unique_identifier, cached_program.handle,
VideoCore::g_hw_shader_accurate_mul);
}
state.draw.shader_program = cached_program.handle;
}
glUseProgramStages(impl->pipeline.handle, GL_VERTEX_SHADER_BIT, impl->current.vs);
glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs);
glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs);
state.draw.shader_program = 0;
state.draw.program_pipeline = impl->pipeline.handle;
}
void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
@ -318,7 +400,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
// Load uncompressed precompiled file for non-separable shaders.
// Precompiled file for separable shaders is compressed.
auto [decompiled, dumps] = disk_cache.LoadPrecompiled();
auto [decompiled, dumps] = disk_cache.LoadPrecompiled(impl->separable);
if (stop_loading) {
return;
@ -336,81 +418,117 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
callback(VideoCore::LoadCallbackStage::Decompile, 0, raws.size());
}
std::vector<std::size_t> load_raws_index;
// Loads both decompiled and precompiled shaders from the cache. If either one is missing for
const auto LoadPrecompiledShader =
[&](std::size_t begin, std::size_t end, std::span<const ShaderDiskCacheRaw> raw_cache,
const ShaderDecompiledMap& decompiled_map, const ShaderDumpsMap& dump_map) {
for (std::size_t i = begin; i < end; ++i) {
if (stop_loading || compilation_failed) {
return;
}
const auto& raw{raw_cache[i]};
const u64 unique_identifier{raw.GetUniqueIdentifier()};
const u64 calculated_hash =
GetUniqueIdentifier(raw.GetRawShaderConfig(), raw.GetProgramCode());
if (unique_identifier != calculated_hash) {
LOG_ERROR(Render_OpenGL,
"Invalid hash in entry={:016x} (obtained hash={:016x}) - removing "
"shader cache",
raw.GetUniqueIdentifier(), calculated_hash);
disk_cache.InvalidateAll();
return;
}
const auto dump{dump_map.find(unique_identifier)};
const auto decomp{decompiled_map.find(unique_identifier)};
OGLProgram shader;
if (dump != dump_map.end() && decomp != decompiled_map.end()) {
// Only load the vertex shader if its sanitize_mul setting matches
if (raw.GetProgramType() == ProgramType::VS &&
decomp->second.sanitize_mul != VideoCore::g_hw_shader_accurate_mul) {
continue;
}
// If the shader is dumped, attempt to load it
shader = GeneratePrecompiledProgram(dump->second, supported_formats);
if (shader.handle == 0) {
// If any shader failed, stop trying to compile, delete the cache, and start
// loading from raws.
compilation_failed = true;
return;
}
// We have both the binary shader and the decompiled, so inject it into the
// cache.
if (raw.GetProgramType() == ProgramType::VS) {
auto [conf, setup] = BuildVSConfigFromRaw(raw, driver);
std::scoped_lock lock(mutex);
impl->programmable_vertex_shaders.Inject(conf, decomp->second.code,
std::move(shader));
} else if (raw.GetProgramType() == ProgramType::FS) {
PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(),
false, driver.HasBlendMinMaxFactor());
std::scoped_lock lock(mutex);
impl->fragment_shaders.Inject(conf, std::move(shader));
} else {
// Unsupported shader type got stored somehow so nuke the cache
LOG_CRITICAL(Frontend, "failed to load raw ProgramType {}",
raw.GetProgramType());
compilation_failed = true;
return;
}
} else {
// Since precompiled didn't have the dump, we'll load them in the next phase
std::scoped_lock lock(mutex);
load_raws_index.push_back(i);
}
if (callback) {
callback(VideoCore::LoadCallbackStage::Decompile, i, raw_cache.size());
}
const auto LoadPrecompiledShader = [&](std::size_t begin, std::size_t end,
std::span<const ShaderDiskCacheRaw> raw_cache,
const ShaderDecompiledMap& decompiled_map,
const ShaderDumpsMap& dump_map) {
for (std::size_t i = begin; i < end; ++i) {
if (stop_loading || compilation_failed) {
return;
}
};
const auto& raw{raw_cache[i]};
const u64 unique_identifier{raw.GetUniqueIdentifier()};
LoadPrecompiledShader(0, raws.size(), raws, decompiled, dumps);
const u64 calculated_hash =
GetUniqueIdentifier(raw.GetRawShaderConfig(), raw.GetProgramCode());
if (unique_identifier != calculated_hash) {
LOG_ERROR(Render_OpenGL,
"Invalid hash in entry={:016x} (obtained hash={:016x}) - removing "
"shader cache",
raw.GetUniqueIdentifier(), calculated_hash);
disk_cache.InvalidateAll();
return;
}
const auto dump{dump_map.find(unique_identifier)};
const auto decomp{decompiled_map.find(unique_identifier)};
OGLProgram shader;
if (dump != dump_map.end() && decomp != decompiled_map.end()) {
// Only load the vertex shader if its sanitize_mul setting matches
if (raw.GetProgramType() == ProgramType::VS &&
decomp->second.sanitize_mul != VideoCore::g_hw_shader_accurate_mul) {
continue;
}
// If the shader is dumped, attempt to load it
shader =
GeneratePrecompiledProgram(dump->second, supported_formats, impl->separable);
if (shader.handle == 0) {
// If any shader failed, stop trying to compile, delete the cache, and start
// loading from raws
compilation_failed = true;
return;
}
// we have both the binary shader and the decompiled, so inject it into the
// cache
if (raw.GetProgramType() == ProgramType::VS) {
auto [conf, setup] = BuildVSConfigFromRaw(raw, driver);
std::scoped_lock lock(mutex);
impl->programmable_vertex_shaders.Inject(conf, decomp->second.code,
std::move(shader));
} else if (raw.GetProgramType() == ProgramType::FS) {
PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(), false,
driver.HasBlendMinMaxFactor());
std::scoped_lock lock(mutex);
impl->fragment_shaders.Inject(conf, std::move(shader));
} else {
// Unsupported shader type got stored somehow so nuke the cache
LOG_CRITICAL(Frontend, "failed to load raw ProgramType {}",
raw.GetProgramType());
compilation_failed = true;
return;
}
} else {
// Since precompiled didn't have the dump, we'll load them in the next phase
std::scoped_lock lock(mutex);
load_raws_index.push_back(i);
}
if (callback) {
callback(VideoCore::LoadCallbackStage::Decompile, i, raw_cache.size());
}
}
};
const auto LoadPrecompiledProgram = [&](const ShaderDecompiledMap& decompiled_map,
const ShaderDumpsMap& dump_map) {
std::size_t i{0};
for (const auto& dump : dump_map) {
if (stop_loading) {
break;
}
const u64 unique_identifier{dump.first};
const auto decomp{decompiled_map.find(unique_identifier)};
// Only load the program if its sanitize_mul setting matches
if (decomp->second.sanitize_mul != VideoCore::g_hw_shader_accurate_mul) {
continue;
}
// If the shader program is dumped, attempt to load it
OGLProgram shader =
GeneratePrecompiledProgram(dump.second, supported_formats, impl->separable);
if (shader.handle != 0) {
impl->program_cache.emplace(unique_identifier, std::move(shader));
} else {
LOG_ERROR(Frontend, "Failed to link Precompiled program!");
compilation_failed = true;
break;
}
if (callback) {
callback(VideoCore::LoadCallbackStage::Decompile, ++i, dump_map.size());
}
}
};
if (impl->separable) {
LoadPrecompiledShader(0, raws.size(), raws, decompiled, dumps);
} else {
LoadPrecompiledProgram(decompiled, dumps);
}
bool load_all_raws = false;
if (compilation_failed) {
@ -421,6 +539,11 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
precompiled_cache_altered = true;
load_all_raws = true;
}
// TODO(SachinV): Skip loading raws until we implement a proper way to link non-seperable
// shaders.
if (!impl->separable) {
return;
}
const std::size_t load_raws_size = load_all_raws ? raws.size() : load_raws_index.size();
@ -447,25 +570,25 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
GLuint handle{0};
std::string code;
// Otherwise decompile and build the shader at boot and save the result to the
// precompiled file.
// precompiled file
if (raw.GetProgramType() == ProgramType::VS) {
const auto [conf, setup] = BuildVSConfigFromRaw(raw, driver);
code = GLSL::GenerateVertexShader(setup, conf, true);
OGLProgram program{};
program.Create(code, GL_VERTEX_SHADER);
handle = program.handle;
auto [conf, setup] = BuildVSConfigFromRaw(raw, driver);
code = GLSL::GenerateVertexShader(setup, conf, impl->separable);
OGLShaderStage stage{impl->separable};
stage.Create(code.c_str(), GL_VERTEX_SHADER);
handle = stage.GetHandle();
sanitize_mul = conf.state.sanitize_mul;
std::scoped_lock lock(mutex);
impl->programmable_vertex_shaders.Inject(conf, code, std::move(program));
impl->programmable_vertex_shaders.Inject(conf, code, std::move(stage));
} else if (raw.GetProgramType() == ProgramType::FS) {
PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(), false,
driver.HasBlendMinMaxFactor());
code = GLSL::GenerateFragmentShader(conf, true);
OGLProgram program{};
program.Create(code, GL_FRAGMENT_SHADER);
handle = program.handle;
code = GLSL::GenerateFragmentShader(conf, impl->separable);
OGLShaderStage stage{impl->separable};
stage.Create(code.c_str(), GL_FRAGMENT_SHADER);
handle = stage.GetHandle();
std::scoped_lock lock(mutex);
impl->fragment_shaders.Inject(conf, std::move(program));
impl->fragment_shaders.Inject(conf, std::move(stage));
} else {
// Unsupported shader type got stored somehow so nuke the cache
LOG_ERROR(Frontend, "failed to load raw ProgramType {}", raw.GetProgramType());

View File

@ -33,29 +33,22 @@ enum UniformBindings {
/// A class that manage different shader stages and configures them with given config data.
class ShaderProgramManager {
public:
explicit ShaderProgramManager(Frontend::EmuWindow& emu_window, const Driver& driver);
ShaderProgramManager(Frontend::EmuWindow& emu_window, const Driver& driver, bool separable);
~ShaderProgramManager();
/// Loads the pipeline cache stored to disk.
void LoadDiskCache(const std::atomic_bool& stop_loading,
const VideoCore::DiskResourceLoadCallback& callback);
/// Binds a PICA decompiled vertex shader.
bool UseProgrammableVertexShader(const Pica::Regs& config, Pica::Shader::ShaderSetup& setup);
/// Binds a passthrough vertex shader.
void UseTrivialVertexShader();
/// Binds a passthrough geometry shader.
void UseFixedGeometryShader(const Pica::Regs& regs);
/// Binds no geometry shader.
void UseTrivialGeometryShader();
/// Binds a fragment shader generated from PICA state.
void UseFragmentShader(const Pica::Regs& config, bool use_normal);
/// Binds current shader state to provided OpenGLState.
void ApplyTo(OpenGLState& state);
private:

View File

@ -13,9 +13,10 @@
namespace OpenGL {
std::string_view GetPreamble() {
GLuint LoadShader(std::string_view source, GLenum type) {
std::string preamble;
if (GLES) {
return R"(#version 320 es
preamble = R"(#version 320 es
#if defined(GL_ANDROID_extension_pack_es31a)
#extension GL_ANDROID_extension_pack_es31a : enable
@ -25,12 +26,9 @@ std::string_view GetPreamble() {
#extension GL_EXT_clip_cull_distance : enable
#endif // defined(GL_EXT_clip_cull_distance)
)";
} else {
preamble = "#version 430 core\n";
}
return "#version 430 core\n";
}
GLuint LoadShader(std::string_view source, GLenum type) {
const auto preamble = GetPreamble();
std::string_view debug_type;
switch (type) {
@ -74,9 +72,11 @@ GLuint LoadShader(std::string_view source, GLenum type) {
return shader_id;
}
GLuint LoadProgram(std::span<const GLuint> shaders) {
GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders) {
// Link the program
LOG_DEBUG(Render_OpenGL, "Linking program...");
const GLuint program_id = glCreateProgram();
GLuint program_id = glCreateProgram();
for (GLuint shader : shaders) {
if (shader != 0) {
@ -84,6 +84,10 @@ GLuint LoadProgram(std::span<const GLuint> shaders) {
}
}
if (separable_program) {
glProgramParameteri(program_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
}
glProgramParameteri(program_id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
glLinkProgram(program_id);

View File

@ -9,11 +9,6 @@
namespace OpenGL {
/**
* Utility function to retrieve the preamble to compile an OpenGL GLSL shader
*/
std::string_view GetPreamble();
/**
* Utility function to create and compile an OpenGL GLSL shader
* @param source String of the GLSL shader program
@ -27,6 +22,6 @@ GLuint LoadShader(std::string_view source, GLenum type);
* @param shaders ID of shaders to attach to the program
* @returns Handle of the newly created OpenGL program object
*/
GLuint LoadProgram(std::span<const GLuint> shaders);
GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders);
} // namespace OpenGL

View File

@ -59,7 +59,6 @@ OpenGLState::OpenGLState() {
texture_buffer_lut_lf.texture_buffer = 0;
texture_buffer_lut_rg.texture_buffer = 0;
texture_buffer_lut_rgba.texture_buffer = 0;
color_buffer.texture_2d = 0;
image_shadow_buffer = 0;
image_shadow_texture_px = 0;

View File

@ -35,10 +35,7 @@ public:
const VideoCore::BufferTextureCopy& copy);
private:
/// Creates compute pipelines used for blit
vk::Pipeline MakeComputePipeline(vk::ShaderModule shader, vk::PipelineLayout layout);
/// Creates graphics pipelines used for blit
vk::Pipeline MakeDepthStencilBlitPipeline();
private: