gl: Despaghettify texture handling
This commit is contained in:
+57
-32
@@ -299,26 +299,44 @@ void GLGSRender::load_texture_env()
|
||||
for (u32 textures_ref = current_fp_metadata.referenced_textures_mask, i = 0; textures_ref; textures_ref >>= 1, ++i)
|
||||
{
|
||||
if (!(textures_ref & 1))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fs_sampler_state[i])
|
||||
{
|
||||
fs_sampler_state[i] = std::make_unique<gl::texture_cache::sampled_image_descriptor>();
|
||||
}
|
||||
|
||||
auto sampler_state = static_cast<gl::texture_cache::sampled_image_descriptor*>(fs_sampler_state[i].get());
|
||||
const auto& tex = rsx::method_registers.fragment_textures[i];
|
||||
const auto previous_format_class = sampler_state->format_class;
|
||||
|
||||
if (m_samplers_dirty || m_textures_dirty[i] || m_gl_texture_cache.test_if_descriptor_expired(cmd, m_rtts, sampler_state, tex))
|
||||
if (!m_samplers_dirty &&
|
||||
!m_textures_dirty[i] &&
|
||||
!m_gl_texture_cache.test_if_descriptor_expired(cmd, m_rtts, sampler_state, tex))
|
||||
{
|
||||
if (tex.enabled())
|
||||
{
|
||||
*sampler_state = m_gl_texture_cache.upload_texture(cmd, tex, m_rtts);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sampler_state->validate())
|
||||
const bool is_sampler_dirty = m_textures_dirty[i];
|
||||
m_textures_dirty[i] = false;
|
||||
|
||||
if (!tex.enabled())
|
||||
{
|
||||
*sampler_state = {};
|
||||
continue;
|
||||
}
|
||||
|
||||
*sampler_state = m_gl_texture_cache.upload_texture(cmd, tex, m_rtts);
|
||||
if (!sampler_state->validate())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sampler_state->format_ex = tex.format_ex();
|
||||
|
||||
if (m_textures_dirty[i])
|
||||
if (is_sampler_dirty)
|
||||
{
|
||||
m_fs_sampler_states[i].apply(tex, fs_sampler_state[i].get());
|
||||
}
|
||||
@@ -342,36 +360,46 @@ void GLGSRender::load_texture_env()
|
||||
m_fs_sampler_states[i].set_parameteri(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*sampler_state = {};
|
||||
}
|
||||
|
||||
m_textures_dirty[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 textures_ref = current_vp_metadata.referenced_textures_mask, i = 0; textures_ref; textures_ref >>= 1, ++i)
|
||||
{
|
||||
if (!(textures_ref & 1))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!vs_sampler_state[i])
|
||||
{
|
||||
vs_sampler_state[i] = std::make_unique<gl::texture_cache::sampled_image_descriptor>();
|
||||
}
|
||||
|
||||
auto sampler_state = static_cast<gl::texture_cache::sampled_image_descriptor*>(vs_sampler_state[i].get());
|
||||
const auto& tex = rsx::method_registers.vertex_textures[i];
|
||||
const auto previous_format_class = sampler_state->format_class;
|
||||
|
||||
if (m_samplers_dirty || m_vertex_textures_dirty[i] || m_gl_texture_cache.test_if_descriptor_expired(cmd, m_rtts, sampler_state, tex))
|
||||
if (!m_samplers_dirty &&
|
||||
!m_vertex_textures_dirty[i] &&
|
||||
!m_gl_texture_cache.test_if_descriptor_expired(cmd, m_rtts, sampler_state, tex))
|
||||
{
|
||||
if (rsx::method_registers.vertex_textures[i].enabled())
|
||||
continue;
|
||||
}
|
||||
|
||||
const bool is_sampler_dirty = m_vertex_textures_dirty[i];
|
||||
m_vertex_textures_dirty[i] = false;
|
||||
|
||||
if (!tex.enabled())
|
||||
{
|
||||
*sampler_state = {};
|
||||
continue;
|
||||
}
|
||||
|
||||
*sampler_state = m_gl_texture_cache.upload_texture(cmd, rsx::method_registers.vertex_textures[i], m_rtts);
|
||||
|
||||
if (sampler_state->validate())
|
||||
if (!sampler_state->validate())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_vertex_textures_dirty[i])
|
||||
{
|
||||
m_vs_sampler_states[i].apply(tex, vs_sampler_state[i].get());
|
||||
@@ -381,15 +409,6 @@ void GLGSRender::load_texture_env()
|
||||
m_graphics_state |= rsx::vertex_program_state_dirty;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*sampler_state = {};
|
||||
}
|
||||
|
||||
m_vertex_textures_dirty[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
m_samplers_dirty.store(false);
|
||||
}
|
||||
@@ -402,7 +421,9 @@ void GLGSRender::bind_texture_env()
|
||||
for (u32 textures_ref = current_fp_metadata.referenced_textures_mask, i = 0; textures_ref; textures_ref >>= 1, ++i)
|
||||
{
|
||||
if (!(textures_ref & 1))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
gl::texture_view* view = nullptr;
|
||||
auto sampler_state = static_cast<gl::texture_cache::sampled_image_descriptor*>(fs_sampler_state[i].get());
|
||||
@@ -442,21 +463,25 @@ void GLGSRender::bind_texture_env()
|
||||
for (u32 textures_ref = current_vp_metadata.referenced_textures_mask, i = 0; textures_ref; textures_ref >>= 1, ++i)
|
||||
{
|
||||
if (!(textures_ref & 1))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto sampler_state = static_cast<gl::texture_cache::sampled_image_descriptor*>(vs_sampler_state[i].get());
|
||||
gl::texture_view* view = nullptr;
|
||||
|
||||
if (rsx::method_registers.vertex_textures[i].enabled() &&
|
||||
sampler_state->validate())
|
||||
{
|
||||
if (sampler_state->image_handle) [[likely]]
|
||||
if (view = sampler_state->image_handle; !view)
|
||||
{
|
||||
sampler_state->image_handle->bind(cmd, GL_VERTEX_TEXTURES_START + i);
|
||||
view = m_gl_texture_cache.create_temporary_subresource(cmd, sampler_state->external_subresource_desc);
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
if (view) [[likely]]
|
||||
{
|
||||
m_gl_texture_cache.create_temporary_subresource(cmd, sampler_state->external_subresource_desc)->bind(cmd, GL_VERTEX_TEXTURES_START + i);
|
||||
}
|
||||
view->bind(cmd, GL_VERTEX_TEXTURES_START + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user