st/nine: Track bindings for buffers
authorAxel Davy <axel.davy@ens.fr>
Thu, 3 Nov 2016 20:53:53 +0000 (21:53 +0100)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:23 +0000 (23:44 +0100)
Similar code than for textures.

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

index df368b67070b8e792d20d761b470d36882ff8a57..0dd2fc64c0ee8391b056152e80600173ade969b7 100644 (file)
@@ -43,6 +43,8 @@ struct NineBuffer9
     int nmaps, maxmaps;
     UINT size;
 
+    int16_t bind_count; /* to Device9->state.stream */
+
     /* Specific to managed buffers */
     struct {
         void *data;
@@ -95,6 +97,22 @@ NineBuffer9_Upload( struct NineBuffer9 *This )
     This->managed.dirty = FALSE;
 }
 
+static void inline
+NineBindBufferToDevice( struct NineDevice9 *device,
+                        struct NineBuffer9 **slot,
+                        struct NineBuffer9 *buf )
+{
+    struct NineBuffer9 *old = *slot;
+
+    (void)device;
+    if (buf)
+        buf->bind_count++;
+    if (old)
+        old->bind_count--;
+
+    nine_bind(slot, buf);
+}
+
 void
 NineBuffer9_SetDirty( struct NineBuffer9 *This );
 
index 101761f081638277dc20dd113db235fd679a2a9a..2b60280c4ddd87a29b1cfe097d9252c5a72fe99c 100644 (file)
@@ -3471,7 +3471,9 @@ NineDevice9_SetStreamSource( struct NineDevice9 *This,
     state->vtxbuf[i].stride = Stride;
     state->vtxbuf[i].buffer_offset = OffsetInBytes;
 
-    nine_bind(&state->stream[i], pStreamData);
+    NineBindBufferToDevice(This,
+                           (struct NineBuffer9 **)&state->stream[i],
+                           (struct NineBuffer9 *)pVBuf9);
 
     nine_context_set_stream_source(This,
                                    StreamNumber,
@@ -3564,7 +3566,10 @@ NineDevice9_SetIndices( struct NineDevice9 *This,
 
     if (state->idxbuf == idxbuf)
         return D3D_OK;
-    nine_bind(&state->idxbuf, idxbuf);
+
+    NineBindBufferToDevice(This,
+                           (struct NineBuffer9 **)&state->idxbuf,
+                           (struct NineBuffer9 *)idxbuf);
 
     nine_context_set_indices(This, idxbuf);
 
index 02ffa8ce0baff5194039e4510ae26dd6335f6330..4b7166f0da85119429a1cc69baece49569681ad9 100644 (file)
@@ -25,6 +25,8 @@
 #include "basetexture9.h"
 #include "nine_helpers.h"
 #include "vertexdeclaration9.h"
+#include "vertexbuffer9.h"
+#include "indexbuffer9.h"
 
 #define DBG_CHANNEL DBG_STATEBLOCK
 
@@ -93,6 +95,18 @@ NineStateBlock9_dtor( struct NineStateBlock9 *This )
     NineUnknown_dtor(&This->base);
 }
 
+static void
+NineStateBlock9_BindBuffer( struct NineDevice9 *device,
+                            boolean applyToDevice,
+                            struct NineBuffer9 **slot,
+                            struct NineBuffer9 *buf )
+{
+    if (applyToDevice)
+        NineBindBufferToDevice(device, slot, buf);
+    else
+        nine_bind(slot, buf);
+}
+
 static void
 NineStateBlock9_BindTexture( struct NineDevice9 *device,
                              boolean applyToDevice,
@@ -233,7 +247,10 @@ nine_state_copy_common(struct NineDevice9 *device,
 
     /* Index buffer. */
     if (mask->changed.group & NINE_STATE_IDXBUF)
-        nine_bind(&dst->idxbuf, src->idxbuf);
+        NineStateBlock9_BindBuffer(device,
+                                   apply,
+                                   (struct NineBuffer9 **)&dst->idxbuf,
+                                   (struct NineBuffer9 *)src->idxbuf);
 
     /* Vertex streams. */
     if (mask->changed.vtxbuf | mask->changed.stream_freq) {
@@ -241,7 +258,10 @@ nine_state_copy_common(struct NineDevice9 *device,
         uint32_t m = mask->changed.vtxbuf | mask->changed.stream_freq;
         for (i = 0; m; ++i, m >>= 1) {
             if (mask->changed.vtxbuf & (1 << i)) {
-                nine_bind(&dst->stream[i], src->stream[i]);
+                NineStateBlock9_BindBuffer(device,
+                                           apply,
+                                           (struct NineBuffer9 **)&dst->stream[i],
+                                           (struct NineBuffer9 *)src->stream[i]);
                 if (src->stream[i]) {
                     dst->vtxbuf[i].buffer_offset = src->vtxbuf[i].buffer_offset;
                     dst->vtxbuf[i].stride = src->vtxbuf[i].stride;
@@ -408,12 +428,18 @@ nine_state_copy_common_all(struct NineDevice9 *device,
                src->changed.sampler, sizeof(dst->changed.sampler));
 
     /* Index buffer. */
-    nine_bind(&dst->idxbuf, src->idxbuf);
+    NineStateBlock9_BindBuffer(device,
+                               apply,
+                               (struct NineBuffer9 **)&dst->idxbuf,
+                               (struct NineBuffer9 *)src->idxbuf);
 
     /* Vertex streams. */
     if (1) {
         for (i = 0; i < ARRAY_SIZE(dst->stream); ++i) {
-            nine_bind(&dst->stream[i], src->stream[i]);
+            NineStateBlock9_BindBuffer(device,
+                                       apply,
+                                       (struct NineBuffer9 **)&dst->stream[i],
+                                       (struct NineBuffer9 *)src->stream[i]);
             if (src->stream[i]) {
                 dst->vtxbuf[i].buffer_offset = src->vtxbuf[i].buffer_offset;
                 dst->vtxbuf[i].stride = src->vtxbuf[i].stride;