st/nine: Back current index buffer to nine_context
authorAxel Davy <axel.davy@ens.fr>
Wed, 19 Oct 2016 18:41:40 +0000 (20:41 +0200)
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
src/gallium/state_trackers/nine/nine_state.h

index fb87f2c90708d56c95ef7a5d30bb73f6e9a2fbbd..5fa44c42e35fd95676db77dbe194f8b9fcc0df6b 100644 (file)
@@ -3526,15 +3526,21 @@ NineDevice9_SetIndices( struct NineDevice9 *This,
                         IDirect3DIndexBuffer9 *pIndexData )
 {
     struct nine_state *state = This->update;
+    struct NineIndexBuffer9 *idxbuf = NineIndexBuffer9(pIndexData);
 
     DBG("This=%p pIndexData=%p\n", This, pIndexData);
 
-    if (likely(!This->is_recording))
-        if (state->idxbuf == NineIndexBuffer9(pIndexData))
-            return D3D_OK;
-    nine_bind(&state->idxbuf, pIndexData);
+    if (unlikely(This->is_recording)) {
+        nine_bind(&state->idxbuf, idxbuf);
+        state->changed.group |= NINE_STATE_IDXBUF;
+        return D3D_OK;
+    }
+
+    if (state->idxbuf == idxbuf)
+        return D3D_OK;
+    nine_bind(&state->idxbuf, idxbuf);
 
-    state->changed.group |= NINE_STATE_IDXBUF;
+    nine_context_set_indices(This, idxbuf);
 
     return D3D_OK;
 }
index ef72cdc7ba393829e8df7cb8e949ce3ceebb9562..5aaf5a132dff8d70804f537052015619907939c2 100644 (file)
@@ -837,8 +837,8 @@ static inline void
 commit_index_buffer(struct NineDevice9 *device)
 {
     struct pipe_context *pipe = device->pipe;
-    if (device->state.idxbuf)
-        pipe->set_index_buffer(pipe, &device->state.idxbuf->buffer);
+    if (device->context.idxbuf.buffer)
+        pipe->set_index_buffer(pipe, &device->context.idxbuf);
     else
         pipe->set_index_buffer(pipe, NULL);
 }
@@ -1240,6 +1240,26 @@ nine_context_set_stream_source_freq(struct NineDevice9 *device,
         state->changed.group |= NINE_STATE_STREAMFREQ;
 }
 
+void
+nine_context_set_indices(struct NineDevice9 *device,
+                         struct NineIndexBuffer9 *idxbuf)
+{
+    struct nine_state *state = &device->state;
+    struct nine_context *context = &device->context;
+    const struct pipe_index_buffer *pipe_idxbuf;
+
+    if (idxbuf) {
+        pipe_idxbuf = NineIndexBuffer9_GetBuffer(idxbuf);
+        context->idxbuf.index_size = pipe_idxbuf->index_size;
+        pipe_resource_reference(&context->idxbuf.buffer, pipe_idxbuf->buffer);
+        context->idxbuf.offset = pipe_idxbuf->offset;
+        context->idxbuf.user_buffer = NULL;
+    } else
+        pipe_resource_reference(&context->idxbuf.buffer, NULL);
+
+    state->changed.group |= NINE_STATE_IDXBUF;
+}
+
 void
 nine_context_set_vertex_declaration(struct NineDevice9 *device,
                                     struct NineVertexDeclaration9 *vdecl)
@@ -1483,6 +1503,10 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
         context->changed.vtxbuf |= src->changed.vtxbuf;
     }
 
+    /* Index buffer */
+    if (src->changed.group & NINE_STATE_IDXBUF)
+        nine_context_set_indices(device, src->idxbuf);
+
     /* Vertex declaration */
     if ((src->changed.group & NINE_STATE_VDECL) && src->vdecl)
         nine_context_set_vertex_declaration(device, src->vdecl);
@@ -2096,6 +2120,7 @@ nine_context_clear(struct nine_context *context)
     nine_bind(&context->vdecl, NULL);
     for (i = 0; i < PIPE_MAX_ATTRIBS; ++i)
         pipe_resource_reference(&context->vtxbuf[i].buffer, NULL);
+    pipe_resource_reference(&context->idxbuf.buffer, NULL);
 
     for (i = 0; i < NINE_MAX_SAMPLERS; ++i)
         nine_bind(&context->texture[i], NULL);
index e8519e982c726588df7bcad4390aef903d53ae50..70a9f102b030b6aa011595bf30692c9f2cc5e31f 100644 (file)
@@ -256,6 +256,8 @@ struct nine_context {
     uint32_t stream_instancedata_mask; /* derived from stream_freq */
     uint32_t stream_usage_mask; /* derived from VS and vdecl */
 
+    struct pipe_index_buffer idxbuf;
+
     DWORD rs[NINED3DRS_COUNT];
 
     struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS];
@@ -330,6 +332,10 @@ nine_context_set_stream_source_freq(struct NineDevice9 *device,
                                     UINT StreamNumber,
                                     UINT Setting);
 
+void
+nine_context_set_indices(struct NineDevice9 *device,
+                         struct NineIndexBuffer9 *idxbuf);
+
 void
 nine_context_set_vertex_declaration(struct NineDevice9 *device,
                                     struct NineVertexDeclaration9 *vdecl);