Skip to content

Commit

Permalink
nv2a: Fix stale texture in surface input and output case
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire authored and mborgerson committed May 18, 2022
1 parent f375a0c commit b0f20c9
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions hw/xbox/nv2a/pgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,14 @@ DEF_METHOD(NV097, SET_BEGIN_END)
glEndQuery(GL_SAMPLES_PASSED);
}

pg->draw_time++;
if (pg->color_binding && pgraph_color_write_enabled(pg)) {
pg->color_binding->draw_time = pg->draw_time;
}
if (pg->zeta_binding && pgraph_zeta_write_enabled(pg)) {
pg->zeta_binding->draw_time = pg->draw_time;
}

NV2A_GL_DGROUP_END();
} else {
NV2A_GL_DGROUP_BEGIN("NV097_SET_BEGIN_END: 0x%x", parameter);
Expand Down Expand Up @@ -6160,7 +6168,32 @@ static void pgraph_bind_textures(NV2AState *d)

nv2a_profile_inc_counter(NV2A_PROF_TEX_BIND);

if (!pg->texture_dirty[i] && pg->texture_binding[i]) {
hwaddr dma_len;
uint8_t *texture_data;
if (dma_select) {
texture_data = (uint8_t*)nv_dma_map(d, pg->dma_b, &dma_len);
} else {
texture_data = (uint8_t*)nv_dma_map(d, pg->dma_a, &dma_len);
}
assert(offset < dma_len);
texture_data += offset;
hwaddr texture_vram_offset = texture_data - d->vram_ptr;

hwaddr palette_dma_len;
uint8_t *palette_data;
if (palette_dma_select) {
palette_data = (uint8_t*)nv_dma_map(d, pg->dma_b, &palette_dma_len);
} else {
palette_data = (uint8_t*)nv_dma_map(d, pg->dma_a, &palette_dma_len);
}
assert(palette_offset < palette_dma_len);
palette_data += palette_offset;
hwaddr palette_vram_offset = palette_data - d->vram_ptr;

SurfaceBinding *surface = pgraph_surface_get(d, texture_vram_offset);
TextureBinding *tbind = pg->texture_binding[i];
if (!pg->texture_dirty[i] && tbind &&
(!surface || tbind->draw_time == surface->draw_time)) {
glBindTexture(pg->texture_binding[i]->gl_target,
pg->texture_binding[i]->gl_texture);
continue;
Expand Down Expand Up @@ -6243,28 +6276,6 @@ static void pgraph_bind_textures(NV2AState *d)
assert(levels > 0);
}

hwaddr dma_len;
uint8_t *texture_data;
if (dma_select) {
texture_data = (uint8_t*)nv_dma_map(d, pg->dma_b, &dma_len);
} else {
texture_data = (uint8_t*)nv_dma_map(d, pg->dma_a, &dma_len);
}
assert(offset < dma_len);
texture_data += offset;
hwaddr texture_vram_offset = texture_data - d->vram_ptr;

hwaddr palette_dma_len;
uint8_t *palette_data;
if (palette_dma_select) {
palette_data = (uint8_t*)nv_dma_map(d, pg->dma_b, &palette_dma_len);
} else {
palette_data = (uint8_t*)nv_dma_map(d, pg->dma_a, &palette_dma_len);
}
assert(palette_offset < palette_dma_len);
palette_data += palette_offset;
hwaddr palette_vram_offset = palette_data - d->vram_ptr;

size_t length = 0;
if (f.linear) {
assert(cubemap == false);
Expand Down Expand Up @@ -6329,7 +6340,6 @@ static void pgraph_bind_textures(NV2AState *d)
* Check active surfaces to see if this texture was a render target
*/
bool surf_to_tex = false;
SurfaceBinding *surface = pgraph_surface_get(d, texture_vram_offset);
if (surface != NULL) {
surf_to_tex = pgraph_check_surface_to_texture_compatibility(
surface, &state);
Expand Down Expand Up @@ -6424,7 +6434,8 @@ static void pgraph_bind_textures(NV2AState *d)
TextureBinding *binding = key_out->binding;
binding->refcnt++;

if (surf_to_tex && (binding->draw_time < surface->draw_time)) {
if (surf_to_tex && binding->draw_time < surface->draw_time) {

NV2A_XPRINTF(DBG_SURFACES,
"Rendering surface @ %" HWADDR_PRIx " to texture (%dx%d)\n",
surface->vram_addr, surface->width, surface->height);
Expand Down

0 comments on commit b0f20c9

Please sign in to comment.