Always bind null for unused shader inputs

Properly rename index offsets to improve readability
Handle indexed and other array cases
This commit is contained in:
kd-11 2016-02-23 18:36:31 +03:00
parent 0f0de47c83
commit 974ea68cf9

View File

@ -386,11 +386,6 @@ void GLGSRender::end()
//setup textures //setup textures
for (int i = 0; i < rsx::limits::textures_count; ++i) for (int i = 0; i < rsx::limits::textures_count; ++i)
{ {
if (!textures[i].enabled())
{
continue;
}
int location; int location;
if (m_program->uniforms.has_location("tex" + std::to_string(i), &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) if (textures[i].format() & CELL_GCM_TEXTURE_UN)
target = GL_TEXTURE_RECTANGLE; 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); m_gl_textures[i].set_target(target);
__glcheck m_gl_texture_cache.upload_texture(i, textures[i], m_gl_textures[i]); __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]; auto &vertex_info = vertex_arrays_info[index];
if (!vertex_info.size) // disabled
continue;
int location; int location;
if (!m_program->uniforms.has_location(reg_table[index] + "_buffer", &location)) if (!m_program->uniforms.has_location(reg_table[index] + "_buffer", &location))
continue; 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); 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 data_size = element_size * vertex_draw_count;
u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size); 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); texture->copy_from(*buffer, gl_type);
//Link texture to uniform //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) for (int index = 0; index < rsx::limits::vertex_count; ++index)
{ {
bool enabled = !!(input_mask & (1 << index));
if (!enabled)
continue;
int location; int location;
if (!m_program->uniforms.has_location(reg_table[index]+"_buffer", &location)) if (!m_program->uniforms.has_location(reg_table[index]+"_buffer", &location))
continue; 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) if (vertex_arrays_info[index].size > 0)
{ {
auto &vertex_info = vertex_arrays_info[index]; auto &vertex_info = vertex_arrays_info[index];
@ -637,7 +650,7 @@ void GLGSRender::end()
texture->copy_from(*buffer, gl_type); texture->copy_from(*buffer, gl_type);
//Link texture to uniform //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) else if (register_vertex_info[index].size > 0)
{ {
@ -663,7 +676,7 @@ void GLGSRender::end()
texture->copy_from(*buffer, gl_type); texture->copy_from(*buffer, gl_type);
//Link texture to uniform //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; break;
} }
default: default:
@ -671,6 +684,13 @@ void GLGSRender::end()
break; 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;
}
} }
} }