GPU/HW/OpenGLES: Use shader cache

This commit is contained in:
Connor McLaughlin 2020-04-04 00:11:27 +10:00
parent d0be5618ec
commit bb3c0a2ccc
2 changed files with 38 additions and 39 deletions

View File

@ -29,6 +29,8 @@ bool GPU_HW_OpenGL_ES::Initialize(HostDisplay* host_display, System* system, DMA
SetCapabilities(host_display); SetCapabilities(host_display);
m_shader_cache.Open(true, system->GetHostInterface()->GetUserDirectoryRelativePath("cache"));
if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers)) if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers))
return false; return false;
@ -201,31 +203,29 @@ bool GPU_HW_OpenGL_ES::CompilePrograms()
static_cast<TextureMode>(texture_mode), static_cast<TextureMode>(texture_mode),
ConvertToBoolUnchecked(dithering)); ConvertToBoolUnchecked(dithering));
GL::Program& prog = m_render_programs[render_mode][texture_mode][dithering]; std::optional<GL::Program> prog = m_shader_cache.GetProgram(vs, fs, [this, textured](GL::Program& prog) {
if (!prog.Compile(vs, fs)) prog.BindAttribute(0, "a_pos");
prog.BindAttribute(1, "a_col0");
if (textured)
{
prog.BindAttribute(2, "a_texcoord");
prog.BindAttribute(3, "a_texpage");
}
});
if (!prog)
return false; return false;
prog.BindAttribute(0, "a_pos"); prog->Bind();
prog.BindAttribute(1, "a_col0"); prog->RegisterUniform("u_texture_window_mask");
if (textured) prog->RegisterUniform("u_texture_window_offset");
{ prog->RegisterUniform("u_src_alpha_factor");
prog.BindAttribute(2, "a_texcoord"); prog->RegisterUniform("u_dst_alpha_factor");
prog.BindAttribute(3, "a_texpage"); prog->RegisterUniform("u_set_mask_while_drawing");
}
if (!prog.Link())
return false;
prog.Bind();
prog.RegisterUniform("u_texture_window_mask");
prog.RegisterUniform("u_texture_window_offset");
prog.RegisterUniform("u_src_alpha_factor");
prog.RegisterUniform("u_dst_alpha_factor");
prog.RegisterUniform("u_set_mask_while_drawing");
if (textured) if (textured)
prog.Uniform1i("samp0", 0); prog->Uniform1i("samp0", 0);
m_render_programs[render_mode][texture_mode][dithering] = std::move(*prog);
} }
} }
} }
@ -234,35 +234,31 @@ bool GPU_HW_OpenGL_ES::CompilePrograms()
{ {
for (u8 interlaced = 0; interlaced < 2; interlaced++) for (u8 interlaced = 0; interlaced < 2; interlaced++)
{ {
GL::Program& prog = m_display_programs[depth_24bit][interlaced];
const std::string vs = shadergen.GenerateScreenQuadVertexShader(); const std::string vs = shadergen.GenerateScreenQuadVertexShader();
const std::string fs = shadergen.GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit), const std::string fs = shadergen.GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit),
ConvertToBoolUnchecked(interlaced)); ConvertToBoolUnchecked(interlaced));
if (!prog.Compile(vs, fs)) std::optional<GL::Program> prog = m_shader_cache.GetProgram(vs, fs);
if (!prog)
return false; return false;
if (!prog.Link()) prog->Bind();
return false; prog->RegisterUniform("u_base_coords");
prog->Uniform1i("samp0", 0);
prog.Bind(); m_display_programs[depth_24bit][interlaced] = std::move(*prog);
prog.RegisterUniform("u_base_coords");
prog.Uniform1i("samp0", 0);
} }
} }
if (!m_vram_read_program.Compile(shadergen.GenerateScreenQuadVertexShader(), std::optional<GL::Program> prog =
shadergen.GenerateVRAMReadFragmentShader())) m_shader_cache.GetProgram(shadergen.GenerateScreenQuadVertexShader(), shadergen.GenerateVRAMReadFragmentShader());
{ if (!prog)
return false;
}
if (!m_vram_read_program.Link())
return false; return false;
m_vram_read_program.Bind(); prog->Bind();
m_vram_read_program.RegisterUniform("u_base_coords"); prog->RegisterUniform("u_base_coords");
m_vram_read_program.RegisterUniform("u_size"); prog->RegisterUniform("u_size");
m_vram_read_program.Uniform1i("samp0", 0); prog->Uniform1i("samp0", 0);
m_vram_read_program = std::move(*prog);
return true; return true;
} }

View File

@ -2,6 +2,7 @@
#include "common/gl/program.h" #include "common/gl/program.h"
#include "common/gl/stream_buffer.h" #include "common/gl/stream_buffer.h"
#include "common/gl/texture.h" #include "common/gl/texture.h"
#include "common/gl/shader_cache.h"
#include "glad.h" #include "glad.h"
#include "gpu_hw.h" #include "gpu_hw.h"
#include <array> #include <array>
@ -53,6 +54,8 @@ private:
void SetDrawState(BatchRenderMode render_mode); void SetDrawState(BatchRenderMode render_mode);
void SetScissorFromDrawingArea(); void SetScissorFromDrawingArea();
GL::ShaderCache m_shader_cache;
// downsample texture - used for readbacks at >1xIR. // downsample texture - used for readbacks at >1xIR.
GL::Texture m_vram_texture; GL::Texture m_vram_texture;
GL::Texture m_vram_read_texture; GL::Texture m_vram_read_texture;