From 804b28cdc461043bba18f1b2b914ef61b9773192 Mon Sep 17 00:00:00 2001 From: Axel Davy Date: Sun, 6 Nov 2016 12:05:50 +0100 Subject: [PATCH] st/nine: Simplify the logic to bind textures This makes the code more readable. Signed-off-by: Axel Davy --- .../state_trackers/nine/basetexture9.h | 20 +++++++ src/gallium/state_trackers/nine/device9.c | 11 +--- src/gallium/state_trackers/nine/stateblock9.c | 55 +++++++++---------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/gallium/state_trackers/nine/basetexture9.h b/src/gallium/state_trackers/nine/basetexture9.h index 0f604f0e37f..35cfbff3756 100644 --- a/src/gallium/state_trackers/nine/basetexture9.h +++ b/src/gallium/state_trackers/nine/basetexture9.h @@ -23,6 +23,7 @@ #ifndef _NINE_BASETEXTURE9_H_ #define _NINE_BASETEXTURE9_H_ +#include "device9.h" #include "resource9.h" #include "util/u_inlines.h" #include "util/list.h" @@ -130,6 +131,25 @@ NineBaseTexture9_GetSamplerView( struct NineBaseTexture9 *This, const int sRGB ) return This->view[sRGB]; } +static void inline +NineBindTextureToDevice( struct NineDevice9 *device, + struct NineBaseTexture9 **slot, + struct NineBaseTexture9 *tex ) +{ + struct NineBaseTexture9 *old = *slot; + + if (tex) { + if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list)) + list_add(&tex->list, &device->update_textures); + + tex->bind_count++; + } + if (old) + old->bind_count--; + + nine_bind(slot, tex); +} + #ifdef DEBUG void NineBaseTexture9_Dump( struct NineBaseTexture9 *This ); diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c index 5b720cc06dd..101761f0816 100644 --- a/src/gallium/state_trackers/nine/device9.c +++ b/src/gallium/state_trackers/nine/device9.c @@ -2486,19 +2486,10 @@ NineDevice9_SetTexture( struct NineDevice9 *This, if (old == tex) return D3D_OK; - if (tex) { - if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list)) - list_add(&tex->list, &This->update_textures); - - tex->bind_count++; - } - if (old) - old->bind_count--; + NineBindTextureToDevice(This, &state->texture[Stage], tex); nine_context_set_texture(This, Stage, tex); - nine_bind(&state->texture[Stage], pTexture); - return D3D_OK; } diff --git a/src/gallium/state_trackers/nine/stateblock9.c b/src/gallium/state_trackers/nine/stateblock9.c index cc802d4af28..02ffa8ce0ba 100644 --- a/src/gallium/state_trackers/nine/stateblock9.c +++ b/src/gallium/state_trackers/nine/stateblock9.c @@ -93,6 +93,18 @@ NineStateBlock9_dtor( struct NineStateBlock9 *This ) NineUnknown_dtor(&This->base); } +static void +NineStateBlock9_BindTexture( struct NineDevice9 *device, + boolean applyToDevice, + struct NineBaseTexture9 **slot, + struct NineBaseTexture9 *tex ) +{ + if (applyToDevice) + NineBindTextureToDevice(device, slot, tex); + else + nine_bind(slot, tex); +} + /* Copy state marked changed in @mask from @src to @dst. * If @apply is false, updating dst->changed can be omitted. * TODO: compare ? @@ -244,6 +256,14 @@ nine_state_copy_common(struct NineDevice9 *device, } } + /* Textures */ + if (mask->changed.texture) { + uint32_t m = mask->changed.texture; + for (s = 0; m; ++s, m >>= 1) + if (m & 1) + NineStateBlock9_BindTexture(device, apply, &dst->texture[s], src->texture[s]); + } + if (!(mask->changed.group & NINE_STATE_FF)) return; WARN_ONCE("Fixed function state not handled properly by StateBlocks.\n"); @@ -406,6 +426,12 @@ nine_state_copy_common_all(struct NineDevice9 *device, } } + /* Textures */ + if (1) { + for (i = 0; i < device->caps.MaxSimultaneousTextures; i++) + NineStateBlock9_BindTexture(device, apply, &dst->texture[i], src->texture[i]); + } + /* keep this check in case we want to disable FF */ if (!(help->changed.group & NINE_STATE_FF)) return; @@ -460,7 +486,6 @@ NineStateBlock9_Capture( struct NineStateBlock9 *This ) struct nine_state *dst = &This->state; struct nine_state *src = &device->state; const int MaxStreams = device->caps.MaxStreams; - unsigned s; DBG("This=%p\n", This); @@ -472,14 +497,6 @@ NineStateBlock9_Capture( struct NineStateBlock9 *This ) if (dst->changed.group & NINE_STATE_VDECL) nine_bind(&dst->vdecl, src->vdecl); - /* Textures */ - if (dst->changed.texture) { - uint32_t m = dst->changed.texture; - for (s = 0; m; ++s, m >>= 1) - if (m & 1) - nine_bind(&dst->texture[s], src->texture[s]); - } - return D3D_OK; } @@ -492,7 +509,6 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This ) struct nine_state *src = &This->state; struct nine_range_pool *pool = &device->range_pool; const int MaxStreams = device->caps.MaxStreams; - unsigned s; DBG("This=%p\n", This); @@ -506,25 +522,6 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This ) if ((src->changed.group & NINE_STATE_VDECL) && src->vdecl) nine_bind(&dst->vdecl, src->vdecl); - /* Textures */ - if (src->changed.texture) { - uint32_t m = src->changed.texture; - - for (s = 0; m; ++s, m >>= 1) { - struct NineBaseTexture9 *tex = src->texture[s]; - if (!(m & 1)) - continue; - if (tex) { - tex->bind_count++; - if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list)) - list_add(&tex->list, &This->base.device->update_textures); - } - if (src->texture[s]) - src->texture[s]->bind_count--; - nine_bind(&dst->texture[s], src->texture[s]); - } - } - return D3D_OK; } -- 2.30.2