nv2a/vk: Move overlapping surface download logic to function

This commit is contained in:
Matt Borgerson 2024-07-26 17:21:02 -07:00 committed by mborgerson
parent da1e72a39a
commit ad0aec9adb
3 changed files with 20 additions and 9 deletions

View File

@ -447,6 +447,7 @@ void pgraph_vk_surface_download_if_dirty(NV2AState *d, SurfaceBinding *surface);
SurfaceBinding *pgraph_vk_surface_get_within(NV2AState *d, hwaddr addr);
void pgraph_vk_wait_for_surface_download(SurfaceBinding *e);
void pgraph_vk_download_dirty_surfaces(NV2AState *d);
void pgraph_vk_download_surfaces_in_range_if_dirty(PGRAPHState *pg, hwaddr start, hwaddr size);
void pgraph_vk_upload_surface_data(NV2AState *d, SurfaceBinding *surface,
bool force);
void pgraph_vk_surface_update(NV2AState *d, bool upload, bool color_write,

View File

@ -122,6 +122,23 @@ static void memcpy_image(void *dst, void const *src, int dst_stride,
}
}
void pgraph_vk_download_surfaces_in_range_if_dirty(PGRAPHState *pg, hwaddr start, hwaddr size)
{
PGRAPHVkState *r = pg->vk_renderer_state;
SurfaceBinding *surface;
hwaddr end = start + size - 1;
QTAILQ_FOREACH(surface, &r->surfaces, entry) {
hwaddr surf_end = surface->vram_addr + surface->size - 1;
bool overlapping = !(surface->vram_addr >= end || start >= surf_end);
if (overlapping) {
pgraph_vk_surface_download_if_dirty(
container_of(pg, NV2AState, pgraph), surface);
}
}
}
static void download_surface_to_buffer(NV2AState *d, SurfaceBinding *surface,
uint8_t *pixels)
{

View File

@ -1066,15 +1066,8 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
// FIXME: Restructure to support rendering surfaces to cubemap faces
// Writeback any surfaces which this texture may index
hwaddr tex_vram_end = texture_vram_offset + texture_length - 1;
QTAILQ_FOREACH(surface, &r->surfaces, entry) {
hwaddr surf_vram_end = surface->vram_addr + surface->size - 1;
bool overlapping = !(surface->vram_addr >= tex_vram_end
|| texture_vram_offset >= surf_vram_end);
if (overlapping) {
pgraph_vk_surface_download_if_dirty(d, surface);
}
}
pgraph_vk_download_surfaces_in_range_if_dirty(
pg, texture_vram_offset, texture_length);
}
if (surface_to_texture && pg->surface_scale_factor > 1) {