GPU/HW/OpenGL: Use shader cache

This commit is contained in:
Connor McLaughlin 2020-04-04 00:11:20 +10:00
parent f566ca7a50
commit d0be5618ec
2 changed files with 62 additions and 64 deletions

View file

@ -37,6 +37,8 @@ bool GPU_HW_OpenGL::Initialize(HostDisplay* host_display, System* system, DMA* d
SetCapabilities(host_display); SetCapabilities(host_display);
m_shader_cache.Open(m_is_gles, 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;
@ -306,30 +308,29 @@ bool GPU_HW_OpenGL::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 (!m_is_gles)
prog.BindFragData(0, "o_col0");
});
if (!prog)
return false; return false;
prog.BindAttribute(0, "a_pos"); prog->BindUniformBlock("UBOBlock", 1);
prog.BindAttribute(1, "a_col0");
if (textured) if (textured)
{ {
prog.BindAttribute(2, "a_texcoord"); prog->Bind();
prog.BindAttribute(3, "a_texpage"); prog->Uniform1i("samp0", 0);
} }
if (!m_is_gles) m_render_programs[render_mode][texture_mode][dithering] = std::move(*prog);
prog.BindFragData(0, "o_col0");
if (!prog.Link())
return false;
prog.BindUniformBlock("UBOBlock", 1);
if (textured)
{
prog.Bind();
prog.Uniform1i("samp0", 0);
}
} }
} }
} }
@ -338,71 +339,65 @@ bool GPU_HW_OpenGL::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, [this](GL::Program& prog) {
if (!m_is_gles)
{
if (m_supports_dual_source_blend)
{
prog.BindFragDataIndexed(0, "o_col0");
prog.BindFragDataIndexed(1, "o_col1");
}
else
{
prog.BindFragData(0, "o_col0");
}
}
});
if (!prog)
return false; return false;
if (!m_is_gles) prog->BindUniformBlock("UBOBlock", 1);
{
if (m_supports_dual_source_blend)
{
prog.BindFragDataIndexed(0, "o_col0");
prog.BindFragDataIndexed(1, "o_col1");
}
else
{
prog.BindFragData(0, "o_col0");
}
}
if (!prog.Link()) prog->Bind();
return false; prog->Uniform1i("samp0", 0);
prog.BindUniformBlock("UBOBlock", 1); m_display_programs[depth_24bit][interlaced] = std::move(*prog);
prog.Bind();
prog.Uniform1i("samp0", 0);
} }
} }
if (!m_vram_read_program.Compile(shadergen.GenerateScreenQuadVertexShader(), std::optional<GL::Program> prog = m_shader_cache.GetProgram(
shadergen.GenerateVRAMReadFragmentShader())) shadergen.GenerateScreenQuadVertexShader(), shadergen.GenerateVRAMReadFragmentShader(), [this](GL::Program& prog) {
{ if (!m_is_gles)
return false; prog.BindFragData(0, "o_col0");
} });
if (!prog)
if (!m_is_gles)
m_vram_read_program.BindFragData(0, "o_col0");
if (!m_vram_read_program.Link())
return false; return false;
m_vram_read_program.BindUniformBlock("UBOBlock", 1); prog->BindUniformBlock("UBOBlock", 1);
prog->Bind();
prog->Uniform1i("samp0", 0);
m_vram_read_program.Bind(); m_vram_read_program = std::move(*prog);
m_vram_read_program.Uniform1i("samp0", 0);
if (m_supports_texture_buffer) if (m_supports_texture_buffer)
{ {
if (!m_vram_write_program.Compile(shadergen.GenerateScreenQuadVertexShader(), prog = m_shader_cache.GetProgram(shadergen.GenerateScreenQuadVertexShader(),
shadergen.GenerateVRAMWriteFragmentShader())) shadergen.GenerateVRAMWriteFragmentShader(), [this](GL::Program& prog) {
{ if (!m_is_gles)
return false; prog.BindFragData(0, "o_col0");
} });
if (!prog)
if (!m_is_gles)
m_vram_write_program.BindFragData(0, "o_col0");
if (!m_vram_write_program.Link())
return false; return false;
m_vram_write_program.BindUniformBlock("UBOBlock", 1); prog->BindUniformBlock("UBOBlock", 1);
prog->Bind();
prog->Uniform1i("samp0", 0);
m_vram_write_program.Bind(); m_vram_write_program = std::move(*prog);
m_vram_write_program.Uniform1i("samp0", 0);
} }
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>
@ -58,6 +59,8 @@ private:
void SetScissorFromDrawingArea(); void SetScissorFromDrawingArea();
void UploadUniformBlock(const void* data, u32 data_size); void UploadUniformBlock(const void* data, u32 data_size);
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;