Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx: Minor refactoring #13290

Merged
merged 2 commits into from Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 67 additions & 0 deletions rpcs3/Emu/RSX/Common/bitfield.hpp
Expand Up @@ -35,6 +35,7 @@ namespace rsx
}

template <typename T, typename bitmask_type = u32>
requires std::is_integral_v<bitmask_type>&& std::is_enum_v<T>
class atomic_bitmask_t
{
private:
Expand Down Expand Up @@ -95,4 +96,70 @@ namespace rsx
return m_data.observe() != 0;
}
};

template <typename T, typename bitmask_type = u32>
requires std::is_integral_v<bitmask_type> && std::is_enum_v<T>
class bitmask_t
{
private:
bitmask_type m_data = 0;

public:
bitmask_t() = default;

bool operator & (bitmask_type mask) const
{
return !!(m_data & mask);
}

bitmask_type operator | (bitmask_type mask) const
{
return m_data | mask;
}

void operator &= (bitmask_type mask)
{
m_data &= mask;
}

void operator |= (bitmask_type mask)
{
m_data |= mask;
}

bool test(T mask)
{
return !!(m_data & static_cast<bitmask_type>(mask));
}

void set(T mask)
{
m_data |= static_cast<bitmask_type>(mask);
}

bool test_and_set(T mask)
{
const auto old = m_data;
m_data |= static_cast<bitmask_type>(mask);
return !!(old & mask);
}

template <typename U>
requires std::is_same_v<T, U> || std::is_same_v<bitmask_type, U>
void clear(U mask)
{
const bitmask_type clear_mask = ~(static_cast<bitmask_type>(mask));
m_data &= clear_mask;
}

void clear()
{
m_data = 0;
}

operator bool() const
{
return !!m_data;
}
};
}
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/GL/GLDraw.cpp
Expand Up @@ -320,7 +320,7 @@ void GLGSRender::update_draw_state()
//NV4097_SET_CLIP_ID_TEST_ENABLE

// For OGL Z range is updated every draw as it is separate from viewport config
m_graphics_state &= ~(rsx::pipeline_state::zclip_config_state_dirty);
m_graphics_state.clear(rsx::pipeline_state::zclip_config_state_dirty);

m_frame_stats.setup_time += m_profiler.duration();
}
Expand Down Expand Up @@ -671,7 +671,7 @@ void GLGSRender::end()
{
m_profiler.start();

if (skip_current_frame || !framebuffer_status_valid || cond_render_ctrl.disable_rendering())
if (skip_current_frame || !m_graphics_state.test(rsx::rtt_config_valid) || cond_render_ctrl.disable_rendering())
{
execute_nop_draw();
rsx::thread::end();
Expand Down
28 changes: 16 additions & 12 deletions rpcs3/Emu/RSX/GL/GLGSRender.cpp
Expand Up @@ -544,7 +544,7 @@ void GLGSRender::clear_surface(u32 arg)

init_buffers(static_cast<rsx::framebuffer_creation_context>(ctx), true);

if (!framebuffer_status_valid) return;
if (!m_graphics_state.test(rsx::rtt_config_valid)) return;

GLbitfield mask = 0;

Expand Down Expand Up @@ -799,13 +799,13 @@ void GLGSRender::load_program_env()

const u32 fragment_constants_size = current_fp_metadata.program_constants_buffer_length;

const bool update_transform_constants = !!(m_graphics_state & rsx::pipeline_state::transform_constants_dirty);
const bool update_fragment_constants = !!(m_graphics_state & rsx::pipeline_state::fragment_constants_dirty) && fragment_constants_size;
const bool update_vertex_env = !!(m_graphics_state & rsx::pipeline_state::vertex_state_dirty);
const bool update_fragment_env = !!(m_graphics_state & rsx::pipeline_state::fragment_state_dirty);
const bool update_fragment_texture_env = !!(m_graphics_state & rsx::pipeline_state::fragment_texture_state_dirty);
const bool update_instruction_buffers = (!!m_interpreter_state && m_shader_interpreter.is_interpreter(m_program));
const bool update_raster_env = (rsx::method_registers.polygon_stipple_enabled() && !!(m_graphics_state & rsx::pipeline_state::polygon_stipple_pattern_dirty));
const bool update_transform_constants = m_graphics_state & rsx::pipeline_state::transform_constants_dirty;
const bool update_fragment_constants = (m_graphics_state & rsx::pipeline_state::fragment_constants_dirty) && fragment_constants_size;
const bool update_vertex_env = m_graphics_state & rsx::pipeline_state::vertex_state_dirty;
const bool update_fragment_env = m_graphics_state & rsx::pipeline_state::fragment_state_dirty;
const bool update_fragment_texture_env = m_graphics_state & rsx::pipeline_state::fragment_texture_state_dirty;
const bool update_instruction_buffers = !!m_interpreter_state && m_shader_interpreter.is_interpreter(m_program);
const bool update_raster_env = rsx::method_registers.polygon_stipple_enabled() && (m_graphics_state & rsx::pipeline_state::polygon_stipple_pattern_dirty);

if (manually_flush_ring_buffers)
{
Expand Down Expand Up @@ -892,7 +892,7 @@ void GLGSRender::load_program_env()
std::memcpy(mapping.first, rsx::method_registers.polygon_stipple_pattern(), 128);
m_raster_env_ring_buffer->bind_range(GL_RASTERIZER_STATE_BIND_SLOT, mapping.second, 128);

m_graphics_state &= ~(rsx::pipeline_state::polygon_stipple_pattern_dirty);
m_graphics_state.clear(rsx::pipeline_state::polygon_stipple_pattern_dirty);
}

if (update_instruction_buffers)
Expand Down Expand Up @@ -954,8 +954,12 @@ void GLGSRender::load_program_env()
}
}

const u32 handled_flags = (rsx::pipeline_state::fragment_state_dirty | rsx::pipeline_state::vertex_state_dirty | rsx::pipeline_state::transform_constants_dirty | rsx::pipeline_state::fragment_constants_dirty | rsx::pipeline_state::fragment_texture_state_dirty);
m_graphics_state &= ~handled_flags;
m_graphics_state.clear(
rsx::pipeline_state::fragment_state_dirty |
rsx::pipeline_state::vertex_state_dirty |
rsx::pipeline_state::transform_constants_dirty |
rsx::pipeline_state::fragment_constants_dirty |
rsx::pipeline_state::fragment_texture_state_dirty);
}

void GLGSRender::update_vertex_env(const gl::vertex_upload_info& upload_info)
Expand Down Expand Up @@ -1065,7 +1069,7 @@ void GLGSRender::do_local_task(rsx::FIFO::state state)
//This will re-engage locks and break the texture cache if another thread is waiting in access violation handler!
//Only call when there are no waiters
m_gl_texture_cache.do_update();
m_graphics_state &= ~rsx::pipeline_state::framebuffer_reads_dirty;
m_graphics_state.clear(rsx::pipeline_state::framebuffer_reads_dirty);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GL/GLGSRender.h
Expand Up @@ -78,7 +78,7 @@ class GLGSRender : public GSRender, public ::rsx::reports::ZCULL_control
const GLFragmentProgram *m_fragment_prog = nullptr;
const GLVertexProgram *m_vertex_prog = nullptr;

u32 m_interpreter_state = 0;
rsx::flags32_t m_interpreter_state = 0;
gl::shader_interpreter m_shader_interpreter;

gl_render_targets m_rtts;
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/GL/GLPresent.cpp
Expand Up @@ -409,11 +409,11 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info)
return false;
});

if (m_draw_fbo && !m_rtts_dirty)
if (m_draw_fbo && !m_graphics_state.test(rsx::rtt_config_dirty))
{
// Always restore the active framebuffer
m_draw_fbo->bind();
set_viewport();
set_scissor(!!(m_graphics_state & rsx::pipeline_state::scissor_setup_clipped));
set_scissor(m_graphics_state & rsx::pipeline_state::scissor_setup_clipped);
}
}
27 changes: 17 additions & 10 deletions rpcs3/Emu/RSX/GL/GLRenderTargets.cpp
Expand Up @@ -103,20 +103,22 @@ u8 rsx::internals::get_pixel_size(rsx::surface_depth_format format)
void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /*skip_reading*/)
{
const bool clipped_scissor = (context == rsx::framebuffer_creation_context::context_draw);
if (m_current_framebuffer_context == context && !m_rtts_dirty && m_draw_fbo)
if (m_current_framebuffer_context == context && !m_graphics_state.test(rsx::rtt_config_dirty) && m_draw_fbo)
{
// Fast path
// Framebuffer usage has not changed, framebuffer exists and config regs have not changed
set_scissor(clipped_scissor);
return;
}

m_rtts_dirty = false;
framebuffer_status_valid = false;
m_framebuffer_state_contested = false;
m_graphics_state.clear(
rsx::rtt_config_dirty |
rsx::rtt_config_contested |
rsx::rtt_config_valid |
rsx::rtt_cache_state_dirty);

get_framebuffer_layout(context, m_framebuffer_layout);
if (!framebuffer_status_valid)
if (!m_graphics_state.test(rsx::rtt_config_valid))
{
return;
}
Expand Down Expand Up @@ -207,7 +209,7 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /*
m_depth_surface_info = {};
}

framebuffer_status_valid = false;
m_graphics_state.clear(rsx::rtt_config_valid);

if (m_draw_fbo)
{
Expand All @@ -225,12 +227,12 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /*
m_draw_fbo->bind();
m_draw_fbo->set_extents({ m_framebuffer_layout.width, m_framebuffer_layout.height });

framebuffer_status_valid = true;
m_graphics_state.set(rsx::rtt_config_valid);
break;
}
}

if (!framebuffer_status_valid)
if (!m_graphics_state.test(rsx::rtt_config_valid))
{
m_framebuffer_cache.emplace_back();
m_framebuffer_cache.back().add_ref();
Expand Down Expand Up @@ -291,8 +293,13 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /*
break;
}

framebuffer_status_valid = m_draw_fbo->check();
if (!framebuffer_status_valid) return;
if (!m_draw_fbo->check())
{
m_graphics_state.clear(rsx::rtt_config_valid);
return;
}

m_graphics_state.set(rsx::rtt_config_valid);

check_zcull_status(true);
set_viewport();
Expand Down