From 974ea68cf912cf531b097ae39748ccdd0442b690 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 23 Feb 2016 18:36:31 +0300 Subject: [PATCH] Always bind null for unused shader inputs Properly rename index offsets to improve readability Handle indexed and other array cases --- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 50 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 1a359e7b03..e2286e33ec 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -386,11 +386,6 @@ void GLGSRender::end() //setup textures for (int i = 0; i < rsx::limits::textures_count; ++i) { - if (!textures[i].enabled()) - { - continue; - } - int location; if (m_program->uniforms.has_location("tex" + std::to_string(i), &location)) { @@ -398,6 +393,14 @@ void GLGSRender::end() if (textures[i].format() & CELL_GCM_TEXTURE_UN) target = GL_TEXTURE_RECTANGLE; + if (!textures[i].enabled()) + { + glActiveTexture(GL_TEXTURE0 + i); + glBindTexture(target, NULL); + glProgramUniform1i(m_program->id(), location, i); + continue; + } + m_gl_textures[i].set_target(target); __glcheck m_gl_texture_cache.upload_texture(i, textures[i], m_gl_textures[i]); @@ -469,13 +472,18 @@ void GLGSRender::end() { auto &vertex_info = vertex_arrays_info[index]; - if (!vertex_info.size) // disabled - continue; - int location; if (!m_program->uniforms.has_location(reg_table[index] + "_buffer", &location)) continue; + if (!vertex_info.size) // disabled, bind a null sampler + { + glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count); + glBindTexture(GL_TEXTURE_BUFFER, NULL); + glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count); + continue; + } + const u32 element_size = rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.size); u32 data_size = element_size * vertex_draw_count; u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size); @@ -536,7 +544,7 @@ void GLGSRender::end() texture->copy_from(*buffer, gl_type); //Link texture to uniform - m_program->uniforms.texture(location, index + rsx::limits::vertex_count, *texture); + m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture); } } @@ -552,14 +560,19 @@ void GLGSRender::end() { for (int index = 0; index < rsx::limits::vertex_count; ++index) { - bool enabled = !!(input_mask & (1 << index)); - if (!enabled) - continue; - int location; if (!m_program->uniforms.has_location(reg_table[index]+"_buffer", &location)) continue; + bool enabled = !!(input_mask & (1 << index)); + if (!enabled) + { + glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count); + glBindTexture(GL_TEXTURE_BUFFER, NULL); + glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count); + continue; + } + if (vertex_arrays_info[index].size > 0) { auto &vertex_info = vertex_arrays_info[index]; @@ -637,7 +650,7 @@ void GLGSRender::end() texture->copy_from(*buffer, gl_type); //Link texture to uniform - m_program->uniforms.texture(location, index + rsx::limits::vertex_count, *texture); + m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture); } else if (register_vertex_info[index].size > 0) { @@ -663,7 +676,7 @@ void GLGSRender::end() texture->copy_from(*buffer, gl_type); //Link texture to uniform - m_program->uniforms.texture(location, index + rsx::limits::vertex_count, *texture); + m_program->uniforms.texture(location, index + rsx::limits::textures_count, *texture); break; } default: @@ -671,6 +684,13 @@ void GLGSRender::end() break; } } + else + { + glActiveTexture(GL_TEXTURE0 + index + rsx::limits::textures_count); + glBindTexture(GL_TEXTURE_BUFFER, NULL); + glProgramUniform1i(m_program->id(), location, index + rsx::limits::textures_count); + continue; + } } }