Skip to content

Commit

Permalink
GPU/HW: Slight re-shuffling of field offsets
Browse files Browse the repository at this point in the history
Free up some bits in the middle.
  • Loading branch information
stenzek committed Jan 7, 2025
1 parent 0030bc2 commit 670dc46
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/core/gpu_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ class GPUBackend
void DestroyDeinterlaceTextures();
bool ApplyChromaSmoothing();

GSVector4i m_clamped_drawing_area = {};

s32 m_display_width = 0;
s32 m_display_height = 0;

GSVector4i m_clamped_drawing_area = {};

s32 m_display_origin_left = 0;
s32 m_display_origin_top = 0;
s32 m_display_vram_width = 0;
Expand Down
23 changes: 11 additions & 12 deletions src/core/gpu_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,10 +3050,9 @@ ALWAYS_INLINE_RELEASE void GPU_HW::CheckForTexPageOverlap(const GPUBackendDrawCo
if (m_texpage_dirty & TEXPAGE_DIRTY_PAGE_RECT)
{
DebugAssert(!(m_texpage_dirty & (TEXPAGE_DIRTY_DRAWN_RECT | TEXPAGE_DIRTY_WRITTEN_RECT)));
DebugAssert(m_batch.texture_mode == BatchTextureMode::PageTexture &&
m_batch.texture_cache_key.page < NUM_VRAM_PAGES);
DebugAssert(m_batch.texture_mode == BatchTextureMode::PageTexture && m_texture_cache_key.page < NUM_VRAM_PAGES);

if (GPUTextureCache::AreSourcePagesDrawn(m_batch.texture_cache_key, m_current_uv_rect))
if (GPUTextureCache::AreSourcePagesDrawn(m_texture_cache_key, m_current_uv_rect))
{
// UVs intersect with drawn area, can't use TC
if (m_batch_index_count > 0)
Expand All @@ -3063,7 +3062,7 @@ ALWAYS_INLINE_RELEASE void GPU_HW::CheckForTexPageOverlap(const GPUBackendDrawCo
}

// We need to swap the dirty tracking over to drawn/written.
const GSVector4i page_rect = GetTextureRect(m_batch.texture_cache_key.page, m_batch.texture_cache_key.mode);
const GSVector4i page_rect = GetTextureRect(m_texture_cache_key.page, m_texture_cache_key.mode);
m_texpage_dirty = (m_vram_dirty_draw_rect.rintersects(page_rect) ? TEXPAGE_DIRTY_DRAWN_RECT : 0) |
(m_vram_dirty_write_rect.rintersects(page_rect) ? TEXPAGE_DIRTY_WRITTEN_RECT : 0);
m_compute_uv_range = (ShouldCheckForTexPageOverlap() || m_clamp_uvs);
Expand Down Expand Up @@ -3572,7 +3571,7 @@ void GPU_HW::PrepareDraw(const GPUBackendDrawCommand* cmd)
{
// TODO: avoid all this for vertex loading, only do when the type of draw changes
BatchTextureMode texture_mode = cmd->texture_enable ? m_batch.texture_mode : BatchTextureMode::Disabled;
GPUTextureCache::SourceKey texture_cache_key = m_batch.texture_cache_key;
GPUTextureCache::SourceKey texture_cache_key = m_texture_cache_key;
if (cmd->texture_enable)
{
// texture page changed - check that the new page doesn't intersect the drawing area
Expand Down Expand Up @@ -3680,9 +3679,9 @@ void GPU_HW::PrepareDraw(const GPUBackendDrawCommand* cmd)
{
if (texture_mode != m_batch.texture_mode || transparency_mode != m_batch.transparency_mode ||
(transparency_mode == GPUTransparencyMode::BackgroundMinusForeground && !m_allow_shader_blend) ||
dithering_enable != m_batch.dithering || m_batch_ubo_data.u_texture_window_bits != cmd->window ||
dithering_enable != m_batch.dithering || m_texture_window_bits != cmd->window ||
m_batch_ubo_data.u_set_mask_while_drawing != BoolToUInt32(cmd->set_mask_while_drawing) ||
(texture_mode == BatchTextureMode::PageTexture && m_batch.texture_cache_key != texture_cache_key))
(texture_mode == BatchTextureMode::PageTexture && m_texture_cache_key != texture_cache_key))
{
FlushRender();
}
Expand Down Expand Up @@ -3729,13 +3728,13 @@ void GPU_HW::PrepareDraw(const GPUBackendDrawCommand* cmd)
m_batch.texture_mode = texture_mode;
m_batch.transparency_mode = transparency_mode;
m_batch.dithering = dithering_enable;
m_batch.texture_cache_key = texture_cache_key;
m_texture_cache_key = texture_cache_key;

if (m_batch_ubo_data.u_texture_window_bits != cmd->window)
if (m_texture_window_bits != cmd->window)
{
m_batch_ubo_data.u_texture_window_bits = cmd->window;
m_texture_window_bits = cmd->window;
m_texture_window_active = (cmd->window != GPUTextureWindow{{0xFF, 0xFF, 0x00, 0x00}});
GSVector4i::store<true>(&m_batch_ubo_data.u_texture_window[0], GSVector4i::load32(&cmd->window).u8to32());
GSVector4i::store<false>(&m_batch_ubo_data.u_texture_window[0], GSVector4i::load32(&cmd->window).u8to32());
m_batch_ubo_dirty = true;
}

Expand Down Expand Up @@ -3779,7 +3778,7 @@ void GPU_HW::FlushRender()
const GPUTextureCache::Source* texture = nullptr;
if (m_batch.texture_mode == BatchTextureMode::PageTexture)
{
texture = LookupSource(m_batch.texture_cache_key, m_current_uv_rect,
texture = LookupSource(m_texture_cache_key, m_current_uv_rect,
m_batch.transparency_mode != GPUTransparencyMode::Disabled ?
GPUTextureCache::PaletteRecordFlags::HasSemiTransparentDraws :
GPUTextureCache::PaletteRecordFlags::None);
Expand Down
16 changes: 5 additions & 11 deletions src/core/gpu_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
#include <tuple>
#include <utility>

class Error;

class GPU_SW_Backend;
struct GPUBackendCommand;
struct GPUBackendDrawCommand;

// TODO: Move to cpp
// TODO: Rename to GPUHWBackend, preserved to avoid conflicts.
class GPU_HW final : public GPUBackend
Expand Down Expand Up @@ -139,7 +133,7 @@ class GPU_HW final : public GPUBackend
void SetUVLimits(u32 min_u, u32 max_u, u32 min_v, u32 max_v);
};

struct alignas(4) BatchConfig
struct BatchConfig
{
BatchTextureMode texture_mode = BatchTextureMode::Disabled;
GPUTransparencyMode transparency_mode = GPUTransparencyMode::Disabled;
Expand All @@ -150,13 +144,11 @@ class GPU_HW final : public GPUBackend
bool use_depth_buffer = false;
bool sprite_mode = false;

GPUTextureCache::SourceKey texture_cache_key = {};

// Returns the render mode for this batch.
BatchRenderMode GetRenderMode() const;
};

struct alignas(VECTOR_ALIGNMENT) BatchUBOData
struct BatchUBOData
{
u32 u_texture_window[4]; // and_x, and_y, or_x, or_y
float u_src_alpha_factor;
Expand All @@ -166,7 +158,6 @@ class GPU_HW final : public GPUBackend
float u_resolution_scale;
float u_rcp_resolution_scale;
float u_resolution_scale_minus_one;
GPUTextureWindow u_texture_window_bits; // not actually used on GPU
};

struct RendererStats
Expand Down Expand Up @@ -327,6 +318,7 @@ class GPU_HW final : public GPUBackend
bool m_batch_ubo_dirty = true;
bool m_drawing_area_changed = true;
BatchConfig m_batch;
GPUTextureCache::SourceKey m_texture_cache_key = {};

// Changed state
BatchUBOData m_batch_ubo_data = {};
Expand All @@ -350,6 +342,8 @@ class GPU_HW final : public GPUBackend
u32 bits = INVALID_DRAW_MODE_BITS;
} m_draw_mode = {};

GPUTextureWindow m_texture_window_bits;

std::unique_ptr<GPUPipeline> m_wireframe_pipeline;

// [wrapped][interlaced]
Expand Down

0 comments on commit 670dc46

Please sign in to comment.