[Mesa-dev] [PATCH 14/84] st/nine: Back current index buffer to nine_context

Axel Davy axel.davy at ens.fr
Wed Dec 7 22:54:47 UTC 2016


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 at ens.fr>
---
 src/gallium/state_trackers/nine/device9.c    | 16 ++++++++++-----
 src/gallium/state_trackers/nine/nine_state.c | 29 ++++++++++++++++++++++++++--
 src/gallium/state_trackers/nine/nine_state.h |  6 ++++++
 3 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c
index 8eeddb2..ed7f97f 100644
--- a/src/gallium/state_trackers/nine/device9.c
+++ b/src/gallium/state_trackers/nine/device9.c
@@ -3521,15 +3521,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;
 }
diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c
index 9217529..bd3f92f 100644
--- a/src/gallium/state_trackers/nine/nine_state.c
+++ b/src/gallium/state_trackers/nine/nine_state.c
@@ -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);
 }
@@ -1241,6 +1241,26 @@ nine_context_set_stream_source_freq(struct NineDevice9 *device,
 }
 
 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);
@@ -2101,6 +2125,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);
diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h
index e8519e9..70a9f10 100644
--- a/src/gallium/state_trackers/nine/nine_state.h
+++ b/src/gallium/state_trackers/nine/nine_state.h
@@ -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];
@@ -331,6 +333,10 @@ nine_context_set_stream_source_freq(struct NineDevice9 *device,
                                     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);
 
-- 
2.10.2



More information about the mesa-dev mailing list