From 831d4f9aeb291b64f29b2198d3756af183ebf9d6 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Sat, 19 May 2018 15:38:48 +0200 Subject: [PATCH] gl_rasterizer: Use the shared texture buffer for the proctex lut. --- .../renderer_opengl/gl_rasterizer.cpp | 43 ++++++------------- .../renderer_opengl/gl_rasterizer.h | 6 --- .../renderer_opengl/gl_shader_gen.cpp | 9 ++-- .../renderer_opengl/gl_shader_manager.cpp | 2 - src/video_core/renderer_opengl/gl_state.cpp | 19 -------- src/video_core/renderer_opengl/gl_state.h | 10 ----- 6 files changed, 17 insertions(+), 72 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 82426dcf1..1c613df8e 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -135,26 +135,6 @@ RasterizerOpenGL::RasterizerOpenGL() glActiveTexture(TextureUnits::TextureBufferLUT_RGBA.Enum()); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, texture_buffer.GetHandle()); - // Setup the LUT for proctex - proctex_lut.Create(); - state.proctex_lut.texture_buffer = proctex_lut.handle; - state.Apply(); - proctex_lut_buffer.Create(); - glBindBuffer(GL_TEXTURE_BUFFER, proctex_lut_buffer.handle); - glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 4 * 256, nullptr, GL_DYNAMIC_DRAW); - glActiveTexture(TextureUnits::ProcTexLUT.Enum()); - glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, proctex_lut_buffer.handle); - - // Setup the difference LUT for proctex - proctex_diff_lut.Create(); - state.proctex_diff_lut.texture_buffer = proctex_diff_lut.handle; - state.Apply(); - proctex_diff_lut_buffer.Create(); - glBindBuffer(GL_TEXTURE_BUFFER, proctex_diff_lut_buffer.handle); - glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 4 * 256, nullptr, GL_DYNAMIC_DRAW); - glActiveTexture(TextureUnits::ProcTexDiffLUT.Enum()); - glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, proctex_diff_lut_buffer.handle); - // Bind index buffer for hardware shader path state.draw.vertex_array = hw_vao.handle; state.Apply(); @@ -1996,7 +1976,7 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { } // Sync the proctex lut - if (uniform_block_data.proctex_lut_dirty) { + if (uniform_block_data.proctex_lut_dirty || invalidate) { std::array new_data; std::transform(Pica::g_state.proctex.color_table.begin(), @@ -2006,17 +1986,18 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { return GLvec4{rgba.r(), rgba.g(), rgba.b(), rgba.a()}; }); - if (new_data != proctex_lut_data) { + if (new_data != proctex_lut_data || invalidate) { proctex_lut_data = new_data; - glBindBuffer(GL_TEXTURE_BUFFER, proctex_lut_buffer.handle); - glBufferSubData(GL_TEXTURE_BUFFER, 0, new_data.size() * sizeof(GLvec4), - new_data.data()); + std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec4)); + uniform_block_data.data.proctex_lut_offset = (offset + bytes_used) / sizeof(GLvec4); + uniform_block_data.dirty = true; + bytes_used += new_data.size() * sizeof(GLvec4); } uniform_block_data.proctex_lut_dirty = false; } // Sync the proctex difference lut - if (uniform_block_data.proctex_diff_lut_dirty) { + if (uniform_block_data.proctex_diff_lut_dirty || invalidate) { std::array new_data; std::transform(Pica::g_state.proctex.color_diff_table.begin(), @@ -2026,11 +2007,13 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { return GLvec4{rgba.r(), rgba.g(), rgba.b(), rgba.a()}; }); - if (new_data != proctex_diff_lut_data) { + if (new_data != proctex_diff_lut_data || invalidate) { proctex_diff_lut_data = new_data; - glBindBuffer(GL_TEXTURE_BUFFER, proctex_diff_lut_buffer.handle); - glBufferSubData(GL_TEXTURE_BUFFER, 0, new_data.size() * sizeof(GLvec4), - new_data.data()); + std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec4)); + uniform_block_data.data.proctex_diff_lut_offset = + (offset + bytes_used) / sizeof(GLvec4); + uniform_block_data.dirty = true; + bytes_used += new_data.size() * sizeof(GLvec4); } uniform_block_data.proctex_diff_lut_dirty = false; } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index d2fc8ead1..2753ddb79 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -294,13 +294,7 @@ private: std::array proctex_noise_lut_data{}; std::array proctex_color_map_data{}; std::array proctex_alpha_map_data{}; - - OGLBuffer proctex_lut_buffer; - OGLTexture proctex_lut; std::array proctex_lut_data{}; - - OGLBuffer proctex_diff_lut_buffer; - OGLTexture proctex_diff_lut; std::array proctex_diff_lut_data{}; bool allow_shadow; diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 063bf9d70..1d1ce9758 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -1171,15 +1171,16 @@ float ProcTexNoiseCoef(vec2 x) { out += "int lut_index_i = int(lut_coord) + " + std::to_string(config.state.proctex.lut_offset) + ";\n"; out += "float lut_index_f = fract(lut_coord);\n"; - out += "vec4 final_color = texelFetch(proctex_lut, lut_index_i + proctex_lut_offset) + " + out += "vec4 final_color = texelFetch(texture_buffer_lut_rgba, lut_index_i + " + "proctex_lut_offset) + " "lut_index_f * " - "texelFetch(proctex_diff_lut, lut_index_i + proctex_diff_lut_offset);\n"; + "texelFetch(texture_buffer_lut_rgba, lut_index_i + proctex_diff_lut_offset);\n"; break; case ProcTexFilter::Nearest: case ProcTexFilter::NearestMipmapLinear: case ProcTexFilter::NearestMipmapNearest: out += "lut_coord += " + std::to_string(config.state.proctex.lut_offset) + ";\n"; - out += "vec4 final_color = texelFetch(proctex_lut, int(round(lut_coord)) + " + out += "vec4 final_color = texelFetch(texture_buffer_lut_rgba, int(round(lut_coord)) + " "proctex_lut_offset);\n"; break; } @@ -1224,8 +1225,6 @@ uniform sampler2D tex2; uniform samplerCube tex_cube; uniform samplerBuffer texture_buffer_lut_rg; uniform samplerBuffer texture_buffer_lut_rgba; -uniform samplerBuffer proctex_lut; -uniform samplerBuffer proctex_diff_lut; #if ALLOW_SHADOW layout(r32ui) uniform readonly uimage2D shadow_texture_px; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index 19e163804..3b3faea9a 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -57,8 +57,6 @@ static void SetShaderSamplerBindings(GLuint shader) { // Set the texture samplers to correspond to different lookup table texture units SetShaderSamplerBinding(shader, "texture_buffer_lut_rg", TextureUnits::TextureBufferLUT_RG); SetShaderSamplerBinding(shader, "texture_buffer_lut_rgba", TextureUnits::TextureBufferLUT_RGBA); - SetShaderSamplerBinding(shader, "proctex_lut", TextureUnits::ProcTexLUT); - SetShaderSamplerBinding(shader, "proctex_diff_lut", TextureUnits::ProcTexDiffLUT); SetShaderImageBinding(shader, "shadow_buffer", ImageUnits::ShadowBuffer); SetShaderImageBinding(shader, "shadow_texture_px", ImageUnits::ShadowTexturePX); diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index dd019b8f1..0d41242ee 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -58,9 +58,6 @@ OpenGLState::OpenGLState() { texture_buffer_lut_rg.texture_buffer = 0; texture_buffer_lut_rgba.texture_buffer = 0; - proctex_lut.texture_buffer = 0; - proctex_diff_lut.texture_buffer = 0; - image_shadow_buffer = 0; image_shadow_texture_px = 0; image_shadow_texture_nx = 0; @@ -230,18 +227,6 @@ void OpenGLState::Apply() const { glBindTexture(GL_TEXTURE_BUFFER, texture_buffer_lut_rgba.texture_buffer); } - // ProcTex LUT - if (proctex_lut.texture_buffer != cur_state.proctex_lut.texture_buffer) { - glActiveTexture(TextureUnits::ProcTexLUT.Enum()); - glBindTexture(GL_TEXTURE_BUFFER, proctex_lut.texture_buffer); - } - - // ProcTex Diff LUT - if (proctex_diff_lut.texture_buffer != cur_state.proctex_diff_lut.texture_buffer) { - glActiveTexture(TextureUnits::ProcTexDiffLUT.Enum()); - glBindTexture(GL_TEXTURE_BUFFER, proctex_diff_lut.texture_buffer); - } - // Shadow Images if (image_shadow_buffer != cur_state.image_shadow_buffer) { glBindImageTexture(ImageUnits::ShadowBuffer, image_shadow_buffer, 0, GL_FALSE, 0, @@ -357,10 +342,6 @@ OpenGLState& OpenGLState::ResetTexture(GLuint handle) { texture_buffer_lut_rg.texture_buffer = 0; if (texture_buffer_lut_rgba.texture_buffer == handle) texture_buffer_lut_rgba.texture_buffer = 0; - if (proctex_lut.texture_buffer == handle) - proctex_lut.texture_buffer = 0; - if (proctex_diff_lut.texture_buffer == handle) - proctex_diff_lut.texture_buffer = 0; if (image_shadow_buffer == handle) image_shadow_buffer = 0; if (image_shadow_texture_px == handle) diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 4f939be31..4408506c3 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -20,8 +20,6 @@ constexpr TextureUnit PicaTexture(int unit) { return TextureUnit{unit}; } -constexpr TextureUnit ProcTexLUT{8}; -constexpr TextureUnit ProcTexDiffLUT{9}; constexpr TextureUnit TextureCube{10}; constexpr TextureUnit TextureBufferLUT_RG{11}; constexpr TextureUnit TextureBufferLUT_RGBA{12}; @@ -108,14 +106,6 @@ public: GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER } texture_buffer_lut_rgba; - struct { - GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER - } proctex_lut; - - struct { - GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER - } proctex_diff_lut; - // GL_IMAGE_BINDING_NAME GLuint image_shadow_buffer; GLuint image_shadow_texture_px;