From 63fb7dcc1bd6afe32529f5891e28b6723caec662 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Sat, 19 May 2018 15:16:49 +0200 Subject: [PATCH] gl_rasterizer: Use the shared texture buffer for the fog lut. --- .../renderer_opengl/gl_rasterizer.cpp | 21 ++++++------------- .../renderer_opengl/gl_rasterizer.h | 3 --- .../renderer_opengl/gl_shader_gen.cpp | 4 ++-- .../renderer_opengl/gl_shader_manager.cpp | 1 - src/video_core/renderer_opengl/gl_state.cpp | 10 --------- src/video_core/renderer_opengl/gl_state.h | 5 ----- 6 files changed, 8 insertions(+), 36 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index a7e8126e3..d1e00efa2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -135,16 +135,6 @@ RasterizerOpenGL::RasterizerOpenGL() glActiveTexture(TextureUnits::TextureBufferLUT_RGBA.Enum()); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, texture_buffer.GetHandle()); - // Setup the LUT for the fog - fog_lut.Create(); - state.fog_lut.texture_buffer = fog_lut.handle; - state.Apply(); - fog_lut_buffer.Create(); - glBindBuffer(GL_TEXTURE_BUFFER, fog_lut_buffer.handle); - glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 2 * 128, nullptr, GL_DYNAMIC_DRAW); - glActiveTexture(TextureUnits::FogLUT.Enum()); - glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, fog_lut_buffer.handle); - // Setup the noise LUT for proctex proctex_noise_lut.Create(); state.proctex_noise_lut.texture_buffer = proctex_noise_lut.handle; @@ -1978,7 +1968,7 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { uniform_block_data.lighting_lut_dirty_any = false; // Sync the fog lut - if (uniform_block_data.fog_lut_dirty) { + if (uniform_block_data.fog_lut_dirty || invalidate) { std::array new_data; std::transform(Pica::g_state.fog.lut.begin(), Pica::g_state.fog.lut.end(), new_data.begin(), @@ -1986,11 +1976,12 @@ void RasterizerOpenGL::SyncAndUploadLUTs() { return GLvec2{entry.ToFloat(), entry.DiffToFloat()}; }); - if (new_data != fog_lut_data) { + if (new_data != fog_lut_data || invalidate) { fog_lut_data = new_data; - glBindBuffer(GL_TEXTURE_BUFFER, fog_lut_buffer.handle); - glBufferSubData(GL_TEXTURE_BUFFER, 0, new_data.size() * sizeof(GLvec2), - new_data.data()); + std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2)); + uniform_block_data.data.fog_lut_offset = (offset + bytes_used) / sizeof(GLvec2); + uniform_block_data.dirty = true; + bytes_used += new_data.size() * sizeof(GLvec2); } uniform_block_data.fog_lut_dirty = false; } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 8eb78a4f9..8e532d907 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -290,9 +290,6 @@ private: OGLTexture texture_buffer_lut_rgba; std::array, Pica::LightingRegs::NumLightingSampler> lighting_lut_data{}; - - OGLBuffer fog_lut_buffer; - OGLTexture fog_lut; std::array fog_lut_data{}; OGLBuffer proctex_noise_lut_buffer; diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 312a41f00..58c83a775 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -1224,7 +1224,6 @@ uniform sampler2D tex2; uniform samplerCube tex_cube; uniform samplerBuffer texture_buffer_lut_rg; uniform samplerBuffer texture_buffer_lut_rgba; -uniform samplerBuffer fog_lut; uniform samplerBuffer proctex_noise_lut; uniform samplerBuffer proctex_color_map; uniform samplerBuffer proctex_alpha_map; @@ -1494,7 +1493,8 @@ vec4 secondary_fragment_color = vec4(0.0); // Generate clamped fog factor from LUT for given fog index out += "float fog_i = clamp(floor(fog_index), 0.0, 127.0);\n"; out += "float fog_f = fog_index - fog_i;\n"; - out += "vec2 fog_lut_entry = texelFetch(fog_lut, int(fog_i) + fog_lut_offset).rg;\n"; + out += "vec2 fog_lut_entry = texelFetch(texture_buffer_lut_rg, int(fog_i) + " + "fog_lut_offset).rg;\n"; out += "float fog_factor = fog_lut_entry.r + fog_lut_entry.g * fog_f;\n"; out += "fog_factor = clamp(fog_factor, 0.0, 1.0);\n"; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index c14744e6b..318037267 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -57,7 +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, "fog_lut", TextureUnits::FogLUT); SetShaderSamplerBinding(shader, "proctex_noise_lut", TextureUnits::ProcTexNoiseLUT); SetShaderSamplerBinding(shader, "proctex_color_map", TextureUnits::ProcTexColorMap); SetShaderSamplerBinding(shader, "proctex_alpha_map", TextureUnits::ProcTexAlphaMap); diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 005523ce3..2b58f673e 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -58,8 +58,6 @@ OpenGLState::OpenGLState() { texture_buffer_lut_rg.texture_buffer = 0; texture_buffer_lut_rgba.texture_buffer = 0; - fog_lut.texture_buffer = 0; - proctex_lut.texture_buffer = 0; proctex_diff_lut.texture_buffer = 0; proctex_color_map.texture_buffer = 0; @@ -235,12 +233,6 @@ void OpenGLState::Apply() const { glBindTexture(GL_TEXTURE_BUFFER, texture_buffer_lut_rgba.texture_buffer); } - // Fog LUT - if (fog_lut.texture_buffer != cur_state.fog_lut.texture_buffer) { - glActiveTexture(TextureUnits::FogLUT.Enum()); - glBindTexture(GL_TEXTURE_BUFFER, fog_lut.texture_buffer); - } - // ProcTex Noise LUT if (proctex_noise_lut.texture_buffer != cur_state.proctex_noise_lut.texture_buffer) { glActiveTexture(TextureUnits::ProcTexNoiseLUT.Enum()); @@ -386,8 +378,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 (fog_lut.texture_buffer == handle) - fog_lut.texture_buffer = 0; if (proctex_noise_lut.texture_buffer == handle) proctex_noise_lut.texture_buffer = 0; if (proctex_color_map.texture_buffer == handle) diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 4a0745720..759b94569 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -20,7 +20,6 @@ constexpr TextureUnit PicaTexture(int unit) { return TextureUnit{unit}; } -constexpr TextureUnit FogLUT{4}; constexpr TextureUnit ProcTexNoiseLUT{5}; constexpr TextureUnit ProcTexColorMap{6}; constexpr TextureUnit ProcTexAlphaMap{7}; @@ -112,10 +111,6 @@ public: GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER } texture_buffer_lut_rgba; - struct { - GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER - } fog_lut; - struct { GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER } proctex_noise_lut;