st/nine: Encapsulate variables for MANAGED resource
authorAxel Davy <axel.davy@ens.fr>
Thu, 19 Feb 2015 15:18:00 +0000 (16:18 +0100)
committerAxel Davy <axel.davy@ens.fr>
Wed, 29 Apr 2015 06:28:11 +0000 (08:28 +0200)
Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/basetexture9.c
src/gallium/state_trackers/nine/basetexture9.h
src/gallium/state_trackers/nine/cubetexture9.c
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/nine_state.c
src/gallium/state_trackers/nine/stateblock9.c
src/gallium/state_trackers/nine/surface9.c
src/gallium/state_trackers/nine/texture9.c
src/gallium/state_trackers/nine/volume9.c
src/gallium/state_trackers/nine/volumetexture9.c

index f2ca35b02053e18db6b8939c29613e700abaacb1..75a305f099a7d50bb7a1df4b3c8015a31c58f96f 100644 (file)
@@ -67,8 +67,8 @@ NineBaseTexture9_ctor( struct NineBaseTexture9 *This,
     This->pipe = pParams->device->pipe;
     This->mipfilter = (Usage & D3DUSAGE_AUTOGENMIPMAP) ?
         D3DTEXF_LINEAR : D3DTEXF_NONE;
-    This->lod = 0;
-    This->lod_resident = -1;
+    This->managed.lod = 0;
+    This->managed.lod_resident = -1;
     /* When a depth buffer is sampled, it is for shadow mapping, except for
      * D3DFMT_INTZ, D3DFMT_DF16 and D3DFMT_DF24.
      * In addition D3DFMT_INTZ can be used for both texturing and depth buffering
@@ -103,15 +103,15 @@ DWORD WINAPI
 NineBaseTexture9_SetLOD( struct NineBaseTexture9 *This,
                          DWORD LODNew )
 {
-    DWORD old = This->lod;
+    DWORD old = This->managed.lod;
 
     DBG("This=%p LODNew=%d\n", This, LODNew);
 
     user_assert(This->base.pool == D3DPOOL_MANAGED, 0);
 
-    This->lod = MIN2(LODNew, This->base.info.last_level);
+    This->managed.lod = MIN2(LODNew, This->base.info.last_level);
 
-    if (This->lod != old && This->bind_count && LIST_IS_EMPTY(&This->list))
+    if (This->managed.lod != old && This->bind_count && LIST_IS_EMPTY(&This->list))
        list_add(&This->list, &This->base.base.device->update_textures);
 
     return old;
@@ -122,7 +122,7 @@ NineBaseTexture9_GetLOD( struct NineBaseTexture9 *This )
 {
     DBG("This=%p\n", This);
 
-    return This->lod;
+    return This->managed.lod;
 }
 
 DWORD WINAPI
@@ -165,7 +165,7 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
     unsigned last_level = This->base.info.last_level;
     unsigned l;
 
-    DBG("This=%p dirty=%i type=%s\n", This, This->dirty,
+    DBG("This=%p dirty=%i type=%s\n", This, This->managed.dirty,
         nine_D3DRTYPE_to_str(This->base.type));
 
     assert(This->base.pool == D3DPOOL_MANAGED);
@@ -173,10 +173,10 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
     if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
         last_level = 0; /* TODO: What if level 0 is not resident ? */
 
-    if (This->lod_resident != This->lod) {
+    if (This->managed.lod_resident != This->managed.lod) {
         struct pipe_resource *res;
 
-        DBG("updating LOD from %u to %u ...\n", This->lod_resident, This->lod);
+        DBG("updating LOD from %u to %u ...\n", This->managed.lod_resident, This->managed.lod);
 
         pipe_sampler_view_reference(&This->view[0], NULL);
         pipe_sampler_view_reference(&This->view[1], NULL);
@@ -192,13 +192,13 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
                 state->changed.group |= NINE_STATE_TEXTURE;
         }
 
-        hr = NineBaseTexture9_CreatePipeResource(This, This->lod_resident != -1);
+        hr = NineBaseTexture9_CreatePipeResource(This, This->managed.lod_resident != -1);
         if (FAILED(hr))
             return hr;
         res = This->base.resource;
 
-        if (This->lod_resident == -1) /* no levels were resident */
-            This->lod_resident = This->base.info.last_level + 1;
+        if (This->managed.lod_resident == -1) /* no levels were resident */
+            This->managed.lod_resident = This->base.info.last_level + 1;
 
         if (This->base.type == D3DRTYPE_TEXTURE) {
             struct NineTexture9 *tex = NineTexture9(This);
@@ -207,15 +207,15 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
             /* Mark uninitialized levels as dirty. */
             box.x = box.y = box.z = 0;
             box.depth = 1;
-            for (l = This->lod; l < This->lod_resident; ++l) {
+            for (l = This->managed.lod; l < This->managed.lod_resident; ++l) {
                 box.width = u_minify(This->base.info.width0, l);
                 box.height = u_minify(This->base.info.height0, l);
                 NineSurface9_AddDirtyRect(tex->surfaces[l], &box);
             }
-            for (l = 0; l < This->lod; ++l)
+            for (l = 0; l < This->managed.lod; ++l)
                 NineSurface9_SetResource(tex->surfaces[l], NULL, -1);
             for (; l <= This->base.info.last_level; ++l)
-                NineSurface9_SetResource(tex->surfaces[l], res, l - This->lod);
+                NineSurface9_SetResource(tex->surfaces[l], res, l - This->managed.lod);
         } else
         if (This->base.type == D3DRTYPE_CUBETEXTURE) {
             struct NineCubeTexture9 *tex = NineCubeTexture9(This);
@@ -225,13 +225,13 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
             /* Mark uninitialized levels as dirty. */
             box.x = box.y = box.z = 0;
             box.depth = 1;
-            for (l = This->lod; l < This->lod_resident; ++l) {
+            for (l = This->managed.lod; l < This->managed.lod_resident; ++l) {
                 box.width = u_minify(This->base.info.width0, l);
                 box.height = u_minify(This->base.info.height0, l);
                 for (z = 0; z < 6; ++z)
                     NineSurface9_AddDirtyRect(tex->surfaces[l * 6 + z], &box);
             }
-            for (l = 0; l < This->lod; ++l) {
+            for (l = 0; l < This->managed.lod; ++l) {
                 for (z = 0; z < 6; ++z)
                     NineSurface9_SetResource(tex->surfaces[l * 6 + z],
                                              NULL, -1);
@@ -239,7 +239,7 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
             for (; l <= This->base.info.last_level; ++l) {
                 for (z = 0; z < 6; ++z)
                     NineSurface9_SetResource(tex->surfaces[l * 6 + z],
-                                             res, l - This->lod);
+                                             res, l - This->managed.lod);
             }
         } else
         if (This->base.type == D3DRTYPE_VOLUMETEXTURE) {
@@ -248,25 +248,25 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
 
             /* Mark uninitialized levels as dirty. */
             box.x = box.y = box.z = 0;
-            for (l = This->lod; l < This->lod_resident; ++l) {
+            for (l = This->managed.lod; l < This->managed.lod_resident; ++l) {
                 box.width = u_minify(This->base.info.width0, l);
                 box.height = u_minify(This->base.info.height0, l);
                 box.depth = u_minify(This->base.info.depth0, l);
                 NineVolume9_AddDirtyRegion(tex->volumes[l], &box);
             }
-            for (l = 0; l < This->lod; ++l)
+            for (l = 0; l < This->managed.lod; ++l)
                 NineVolume9_SetResource(tex->volumes[l], NULL, -1);
             for (; l <= This->base.info.last_level; ++l)
-                NineVolume9_SetResource(tex->volumes[l], res, l - This->lod);
+                NineVolume9_SetResource(tex->volumes[l], res, l - This->managed.lod);
         } else {
             assert(!"invalid texture type");
         }
 
-        if (This->lod < This->lod_resident)
-            This->dirty = TRUE;
-        This->lod_resident = This->lod;
+        if (This->managed.lod < This->managed.lod_resident)
+            This->managed.dirty = TRUE;
+        This->managed.lod_resident = This->managed.lod;
     }
-    if (!This->dirty)
+    if (!This->managed.dirty)
         return D3D_OK;
 
     if (This->base.type == D3DRTYPE_TEXTURE) {
@@ -287,7 +287,7 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
             memset(&tex->dirty_rect, 0, sizeof(tex->dirty_rect));
             tex->dirty_rect.depth = 1;
         }
-        for (l = This->lod; l <= last_level; ++l)
+        for (l = This->managed.lod; l <= last_level; ++l)
             NineSurface9_UploadSelf(tex->surfaces[l]);
     } else
     if (This->base.type == D3DRTYPE_CUBETEXTURE) {
@@ -310,7 +310,7 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
                 memset(&tex->dirty_rect[z], 0, sizeof(tex->dirty_rect[z]));
                 tex->dirty_rect[z].depth = 1;
             }
-            for (l = This->lod; l <= last_level; ++l)
+            for (l = This->managed.lod; l <= last_level; ++l)
                 NineSurface9_UploadSelf(tex->surfaces[l * 6 + z]);
         }
     } else
@@ -329,12 +329,12 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
             }
             memset(&tex->dirty_box, 0, sizeof(tex->dirty_box));
         }
-        for (l = This->lod; l <= last_level; ++l)
+        for (l = This->managed.lod; l <= last_level; ++l)
             NineVolume9_UploadSelf(tex->volumes[l]);
     } else {
         assert(!"invalid texture type");
     }
-    This->dirty = FALSE;
+    This->managed.dirty = FALSE;
 
     if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
         This->dirty_mip = TRUE;
@@ -350,7 +350,7 @@ NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This )
     struct pipe_resource *resource = This->base.resource;
 
     unsigned base_level = 0;
-    unsigned last_level = This->base.info.last_level - This->lod;
+    unsigned last_level = This->base.info.last_level - This->managed.lod;
     unsigned first_layer = 0;
     unsigned last_layer;
     unsigned filter = This->mipfilter == D3DTEXF_POINT ? PIPE_TEX_FILTER_NEAREST
@@ -361,7 +361,7 @@ NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This )
         NineBaseTexture9_UploadSelf(This);
     if (!This->dirty_mip)
         return;
-    if (This->lod) {
+    if (This->managed.lod) {
         ERR("AUTOGENMIPMAP if level 0 is not resident not supported yet !\n");
         return;
     }
@@ -392,18 +392,18 @@ NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
     struct pipe_resource *old = This->base.resource;
 
     DBG("This=%p lod=%u last_level=%u\n", This,
-        This->lod, This->base.info.last_level);
+        This->managed.lod, This->base.info.last_level);
 
     assert(This->base.pool == D3DPOOL_MANAGED);
 
     templ = This->base.info;
 
-    if (This->lod) {
-        templ.width0 = u_minify(templ.width0, This->lod);
-        templ.height0 = u_minify(templ.height0, This->lod);
-        templ.depth0 = u_minify(templ.depth0, This->lod);
+    if (This->managed.lod) {
+        templ.width0 = u_minify(templ.width0, This->managed.lod);
+        templ.height0 = u_minify(templ.height0, This->managed.lod);
+        templ.depth0 = u_minify(templ.depth0, This->managed.lod);
     }
-    templ.last_level = This->base.info.last_level - This->lod;
+    templ.last_level = This->base.info.last_level - This->managed.lod;
 
     if (old) {
         /* LOD might have changed. */
@@ -424,8 +424,8 @@ NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
         box.y = 0;
         box.z = 0;
 
-        l = (This->lod < This->lod_resident) ? This->lod_resident - This->lod : 0;
-        m = (This->lod < This->lod_resident) ? 0 : This->lod - This->lod_resident;
+        l = (This->managed.lod < This->managed.lod_resident) ? This->managed.lod_resident - This->managed.lod : 0;
+        m = (This->managed.lod < This->managed.lod_resident) ? 0 : This->managed.lod - This->managed.lod_resident;
 
         box.width = u_minify(templ.width0, l);
         box.height = u_minify(templ.height0, l);
@@ -545,7 +545,7 @@ NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This )
 {
     DBG("This=%p\n", This);
 
-    if (This->dirty && This->base.pool == D3DPOOL_MANAGED)
+    if (This->managed.dirty && This->base.pool == D3DPOOL_MANAGED)
         NineBaseTexture9_UploadSelf(This);
 }
 
@@ -562,6 +562,6 @@ NineBaseTexture9_Dump( struct NineBaseTexture9 *This )
         d3dformat_to_string(This->format),
         This->base.info.width0, This->base.info.height0, This->base.info.depth0,
         This->base.info.array_size, This->base.info.last_level,
-        This->lod, This->lod_resident);
+        This->managed.lod, This->managed.lod_resident);
 }
 #endif /* DEBUG */
index 006277104a069d020fd1b348ad875e82ac5d33de..7a091bf2578c42e082da1a3d07551b8fd65f0dcb 100644 (file)
@@ -38,17 +38,20 @@ struct NineBaseTexture9
 
     D3DFORMAT format;
 
-    D3DTEXTUREFILTERTYPE mipfilter;
-    DWORD lod;
-    DWORD lod_resident;
-
     int16_t bind_count; /* to Device9->state.texture */
 
     boolean shadow;
     uint8_t pstype; /* 0: 2D, 1: 1D, 2: CUBE, 3: 3D */
 
-    boolean dirty;
     boolean dirty_mip;
+    D3DTEXTUREFILTERTYPE mipfilter;
+
+    /* Specific to managed textures */
+    struct {
+        boolean dirty;
+        DWORD lod;
+        DWORD lod_resident;
+    } managed;
 };
 static INLINE struct NineBaseTexture9 *
 NineBaseTexture9( void *data )
@@ -108,9 +111,9 @@ static INLINE void
 NineBaseTexture9_Validate( struct NineBaseTexture9 *This )
 {
     DBG_FLAG(DBG_BASETEXTURE, "This=%p dirty=%i dirty_mip=%i lod=%u/%u\n",
-             This, This->dirty, This->dirty_mip, This->lod, This->lod_resident);
+             This, This->managed.dirty, This->dirty_mip, This->managed.lod, This->managed.lod_resident);
     if ((This->base.pool == D3DPOOL_MANAGED) &&
-        (This->dirty || This->lod != This->lod_resident))
+        (This->managed.dirty || This->managed.lod != This->managed.lod_resident))
         NineBaseTexture9_UploadSelf(This);
     if (This->dirty_mip)
         NineBaseTexture9_GenerateMipSubLevels(This);
@@ -133,7 +136,7 @@ NineBaseTexture9_Dump( struct NineBaseTexture9 *This ) { }
 #endif
 
 #define BASETEX_REGISTER_UPDATE(t) do { \
-    if (((t)->dirty | ((t)->dirty_mip)) && (t)->base.base.bind) \
+    if (((t)->managed.dirty | ((t)->dirty_mip)) && (t)->base.base.bind) \
         if (LIST_IS_EMPTY(&(t)->list)) \
             list_add(&(t)->list, &(t)->base.base.device->update_textures); \
     } while(0)
index f64764c6733f872afd2032aa37818373bfd629a1..98fe887072ccd47ad18853924ed3344fd98635f9 100644 (file)
@@ -263,7 +263,7 @@ NineCubeTexture9_AddDirtyRect( struct NineCubeTexture9 *This,
             This->base.dirty_mip = TRUE;
         return D3D_OK;
     }
-    This->base.dirty = TRUE;
+    This->base.managed.dirty = TRUE;
 
     BASETEX_REGISTER_UPDATE(&This->base);
 
index 7ffede57c7319619c23ef86270fb5321829ff1c1..ce2ea7696409070c1671cb88e6409658db9d4f30 100644 (file)
@@ -2457,7 +2457,7 @@ NineDevice9_SetTexture( struct NineDevice9 *This,
         if (tex) {
             state->samplers_shadow |= tex->shadow << Stage;
 
-            if ((tex->dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
+            if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
                 list_add(&tex->list, &This->update_textures);
 
             tex->bind_count++;
index 034e666d84c61c91ec73ca272943b416c7a87d50..435118bc93f5844b6d4f9837184b17188d3c495e 100644 (file)
@@ -688,7 +688,7 @@ update_sampler_derived(struct nine_state *state, unsigned s)
     }
 
     if (state->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
-        int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - state->texture[s]->lod;
+        int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - state->texture[s]->managed.lod;
         if (lod < 0)
             lod = 0;
         if (state->samp[s][NINED3DSAMP_MINLOD] != lod) {
index 13217ae45470d4a80ce5979ba858259d8729f708..032b9ffcbf0862161c4af16b1f66e8c1184e49b7 100644 (file)
@@ -501,7 +501,7 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This )
                 continue;
             if (tex) {
                 tex->bind_count++;
-                if ((tex->dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
+                if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
                     list_add(&tex->list, &This->base.device->update_textures);
                 dst->samplers_shadow |= tex->shadow << s;
             }
index e202f8707209affad0fa44ac63cb3a149b06a363..3a0b4d0c9483c5b44ebe26be0bd49774afe5c059 100644 (file)
@@ -240,7 +240,7 @@ NineSurface9_MarkContainerDirty( struct NineSurface9 *This )
         assert(This->texture == D3DRTYPE_TEXTURE ||
                This->texture == D3DRTYPE_CUBETEXTURE);
         if (This->base.pool == D3DPOOL_MANAGED)
-            tex->dirty = TRUE;
+            tex->managed.dirty = TRUE;
         else
         if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
             tex->dirty_mip = TRUE;
index 536d631af4c0da45421b8873c936c2b887818906..5b5fd551a801ecce1580f00443d403027ae343a2 100644 (file)
@@ -299,7 +299,7 @@ NineTexture9_AddDirtyRect( struct NineTexture9 *This,
             This->base.dirty_mip = TRUE;
         return D3D_OK;
     }
-    This->base.dirty = TRUE;
+    This->base.managed.dirty = TRUE;
 
     BASETEX_REGISTER_UPDATE(&This->base);
 
index fce89396204918fe50528d62debd5200d363e1e6..24d5d53f01d0efec4b56916ba1889855ca747c2f 100644 (file)
@@ -168,7 +168,7 @@ NineVolume9_MarkContainerDirty( struct NineVolume9 *This )
     tex = NineBaseTexture9(This->base.container);
     assert(tex);
     if (This->desc.Pool == D3DPOOL_MANAGED)
-        tex->dirty = TRUE;
+        tex->managed.dirty = TRUE;
     else
     if (This->desc.Usage & D3DUSAGE_AUTOGENMIPMAP)
         tex->dirty_mip = TRUE;
index 08fdd3d29cf5ad06b17989e1ed8c2e8a5816a5f7..b56617317644711f875936739765f402c70e1efa 100644 (file)
@@ -208,7 +208,7 @@ NineVolumeTexture9_AddDirtyBox( struct NineVolumeTexture9 *This,
             This->base.dirty_mip = TRUE;
         return D3D_OK;
     }
-    This->base.dirty = TRUE;
+    This->base.managed.dirty = TRUE;
 
     BASETEX_REGISTER_UPDATE(&This->base);