st/nine: Move Managed Pool handling out of nine_context
authorAxel Davy <axel.davy@ens.fr>
Sun, 30 Oct 2016 14:00:48 +0000 (15:00 +0100)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:22 +0000 (23:44 +0100)
Part of the refactor to move all gallium calls to
nine_state.c, and have all internal states required
for those calls in nine_context.

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

index c106ab12c8f8ea555a7a6e9e3385ac0be7185dab..73b5888e4eceada914faec887c3bebfd651701c0 100644 (file)
@@ -2706,6 +2706,55 @@ NineDevice9_GetNPatchMode( struct NineDevice9 *This )
     STUB(0);
 }
 
+/* TODO: only go through dirty textures */
+static void
+validate_textures(struct NineDevice9 *device)
+{
+    struct NineBaseTexture9 *tex, *ptr;
+    LIST_FOR_EACH_ENTRY_SAFE(tex, ptr, &device->update_textures, list) {
+        list_delinit(&tex->list);
+        NineBaseTexture9_Validate(tex);
+    }
+}
+
+static void
+update_managed_buffers(struct NineDevice9 *device)
+{
+    struct NineBuffer9 *buf, *ptr;
+    LIST_FOR_EACH_ENTRY_SAFE(buf, ptr, &device->update_buffers, managed.list) {
+        list_delinit(&buf->managed.list);
+        NineBuffer9_Upload(buf);
+    }
+}
+
+static void
+NineBeforeDraw( struct NineDevice9 *This )
+{
+    /* Upload Managed dirty content */
+    validate_textures(This); /* may clobber state */
+    update_managed_buffers(This);
+}
+
+static void
+NineAfterDraw( struct NineDevice9 *This )
+{
+    unsigned i;
+    struct nine_state *state = &This->state;
+    unsigned ps_mask = state->ps ? state->ps->rt_mask : 1;
+
+    /* Flag render-targets with autogenmipmap for mipmap regeneration */
+    for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
+        struct NineSurface9 *rt = state->rt[i];
+
+        if (rt && rt->desc.Format != D3DFMT_NULL && (ps_mask & (1 << i)) &&
+            rt->desc.Usage & D3DUSAGE_AUTOGENMIPMAP) {
+            assert(rt->texture == D3DRTYPE_TEXTURE ||
+                   rt->texture == D3DRTYPE_CUBETEXTURE);
+            NineBaseTexture9(rt->base.base.container)->dirty_mip = TRUE;
+        }
+    }
+}
+
 HRESULT NINE_WINAPI
 NineDevice9_DrawPrimitive( struct NineDevice9 *This,
                            D3DPRIMITIVETYPE PrimitiveType,
@@ -2715,7 +2764,9 @@ NineDevice9_DrawPrimitive( struct NineDevice9 *This,
     DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
         This, PrimitiveType, StartVertex, PrimitiveCount);
 
+    NineBeforeDraw(This);
     nine_context_draw_primitive(This, PrimitiveType, StartVertex, PrimitiveCount);
+    NineAfterDraw(This);
 
     return D3D_OK;
 }
@@ -2737,9 +2788,11 @@ NineDevice9_DrawIndexedPrimitive( struct NineDevice9 *This,
     user_assert(This->state.idxbuf, D3DERR_INVALIDCALL);
     user_assert(This->state.vdecl, D3DERR_INVALIDCALL);
 
+    NineBeforeDraw(This);
     nine_context_draw_indexed_primitive(This, PrimitiveType, BaseVertexIndex,
                                         MinVertexIndex, NumVertices, StartIndex,
                                         PrimitiveCount);
+    NineAfterDraw(This);
 
     return D3D_OK;
 }
@@ -2778,7 +2831,9 @@ NineDevice9_DrawPrimitiveUP( struct NineDevice9 *This,
         vtxbuf.user_buffer = NULL;
     }
 
+    NineBeforeDraw(This);
     nine_context_draw_primitive_from_vtxbuf(This, PrimitiveType, PrimitiveCount, &vtxbuf);
+    NineAfterDraw(This);
 
     pipe_resource_reference(&vtxbuf.buffer, NULL);
 
@@ -2852,12 +2907,14 @@ NineDevice9_DrawIndexedPrimitiveUP( struct NineDevice9 *This,
         ibuf.user_buffer = NULL;
     }
 
+    NineBeforeDraw(This);
     nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This, PrimitiveType,
                                                            MinVertexIndex,
                                                            NumVertices,
                                                            PrimitiveCount,
                                                            &vbuf,
                                                            &ibuf);
+    NineAfterDraw(This);
 
     pipe_resource_reference(&vbuf.buffer, NULL);
     pipe_resource_reference(&ibuf.buffer, NULL);
index e692dd3f4c6e081e1fa7c9a2b4f86101fac57169..226946031d617c04b1466c69f49b724a38b3d7d3 100644 (file)
@@ -455,12 +455,6 @@ update_framebuffer(struct NineDevice9 *device, bool is_clear)
             fb->cbufs[i] = NineSurface9_GetSurface(rt, sRGB);
             context->rt_mask |= 1 << i;
             fb->nr_cbufs = i + 1;
-
-            if (unlikely(rt->desc.Usage & D3DUSAGE_AUTOGENMIPMAP)) {
-                assert(rt->texture == D3DRTYPE_TEXTURE ||
-                       rt->texture == D3DRTYPE_CUBETEXTURE);
-                NineBaseTexture9(rt->base.base.container)->dirty_mip = TRUE;
-            }
         } else {
             /* Color outputs must match RT slot,
              * drivers will have to handle NULL entries for GL, too.
@@ -931,28 +925,6 @@ commit_ps(struct NineDevice9 *device)
     NINE_STATE_STENCIL_REF | \
     NINE_STATE_SAMPLE_MASK)
 
-
-/* TODO: only go through dirty textures */
-static void
-validate_textures(struct NineDevice9 *device)
-{
-    struct NineBaseTexture9 *tex, *ptr;
-    LIST_FOR_EACH_ENTRY_SAFE(tex, ptr, &device->update_textures, list) {
-        list_delinit(&tex->list);
-        NineBaseTexture9_Validate(tex);
-    }
-}
-
-static void
-update_managed_buffers(struct NineDevice9 *device)
-{
-    struct NineBuffer9 *buf, *ptr;
-    LIST_FOR_EACH_ENTRY_SAFE(buf, ptr, &device->update_buffers, managed.list) {
-        list_delinit(&buf->managed.list);
-        NineBuffer9_Upload(buf);
-    }
-}
-
 static void
 nine_update_state(struct NineDevice9 *device)
 {
@@ -968,8 +940,6 @@ nine_update_state(struct NineDevice9 *device)
      * into update_textures. Except, we also need to re-validate textures that
      * may be dirty anyway, even if no texture bindings changed.
      */
-    validate_textures(device); /* may clobber state */
-    update_managed_buffers(device);
 
     /* ff_update may change VS/PS dirty bits */
     if (unlikely(!context->programmable_vs || !context->ps))
@@ -1842,8 +1812,6 @@ nine_update_state_framebuffer_clear(struct NineDevice9 *device)
 {
     struct nine_context *context = &device->context;
 
-    validate_textures(device);
-
     if (context->changed.group & NINE_STATE_FB)
         update_framebuffer(device, TRUE);
 }