st/nine: Simplify the logic to bind textures
authorAxel Davy <axel.davy@ens.fr>
Sun, 6 Nov 2016 11:05:50 +0000 (12:05 +0100)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:23 +0000 (23:44 +0100)
This makes the code more readable.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/basetexture9.h
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/stateblock9.c

index 0f604f0e37f0e5892ffbb556f26ed9b29ca78b1c..35cfbff3756ed7ea285a619ef4cfe72eb2ebb8d3 100644 (file)
@@ -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 );
index 5b720cc06dd567f53b3cbf1fd2557bafdc2f37a7..101761f081638277dc20dd113db235fd679a2a9a 100644 (file)
@@ -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;
 }
 
index cc802d4af2805509356a1226c37b161e1e13def1..02ffa8ce0baff5194039e4510ae26dd6335f6330 100644 (file)
@@ -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;
 }