st/nine: Back vdecl to nine_context
authorAxel Davy <axel.davy@ens.fr>
Mon, 17 Oct 2016 19:18:42 +0000 (21:18 +0200)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:21 +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_ff.c
src/gallium/state_trackers/nine/nine_ff.h
src/gallium/state_trackers/nine/nine_state.c
src/gallium/state_trackers/nine/nine_state.h
src/gallium/state_trackers/nine/pixelshader9.h
src/gallium/state_trackers/nine/stateblock9.c

index d11f3d1903cc872e71c1c37bb5c75f7830079fad..8b47d3eaf84564528ba8a0164e5bacd08e7f7cb0 100644 (file)
@@ -3068,23 +3068,22 @@ NineDevice9_SetVertexDeclaration( struct NineDevice9 *This,
                                   IDirect3DVertexDeclaration9 *pDecl )
 {
     struct nine_state *state = This->update;
-    struct nine_context *context = &This->context;
-    BOOL was_programmable_vs = This->state.programmable_vs;
+    struct NineVertexDeclaration9 *vdecl = NineVertexDeclaration9(pDecl);
 
     DBG("This=%p pDecl=%p\n", This, pDecl);
 
-    if (likely(!This->is_recording) && state->vdecl == NineVertexDeclaration9(pDecl))
+    if (unlikely(This->is_recording)) {
+        nine_bind(&state->vdecl, vdecl);
+        state->changed.group |= NINE_STATE_VDECL;
         return D3D_OK;
+    }
 
-    nine_bind(&state->vdecl, pDecl);
+    if (state->vdecl == vdecl)
+        return D3D_OK;
 
-    This->state.programmable_vs = This->state.vs && !(This->state.vdecl && This->state.vdecl->position_t);
-    if (likely(!This->is_recording) && was_programmable_vs != This->state.programmable_vs) {
-        context->commit |= NINE_STATE_COMMIT_CONST_VS;
-        state->changed.group |= NINE_STATE_VS;
-    }
+    nine_bind(&state->vdecl, vdecl);
 
-    state->changed.group |= NINE_STATE_VDECL;
+    nine_context_set_vertex_declaration(This, vdecl);
 
     return D3D_OK;
 }
@@ -3165,7 +3164,7 @@ NineDevice9_SetVertexShader( struct NineDevice9 *This,
 
     nine_bind(&state->vs, pShader);
 
-    This->state.programmable_vs = This->state.vs && !(This->state.vdecl && This->state.vdecl->position_t);
+    This->state.programmable_vs = This->state.vs && !(This->context.vdecl && This->context.vdecl->position_t);
 
     /* ff -> non-ff: commit back non-ff constants */
     if (!was_programmable_vs && This->state.programmable_vs)
index c0f15d84c8f2f88d6e1333b37fc081faf0c13e2b..2c459636e84910ff0a078421e3431ea8ab3dd22b 100644 (file)
@@ -1578,11 +1578,11 @@ nine_ff_get_vs(struct NineDevice9 *device)
     bld.key = &key;
 
     /* FIXME: this shouldn't be NULL, but it is on init */
-    if (state->vdecl) {
+    if (context->vdecl) {
         key.color0in_one = 1;
         key.color1in_zero = 1;
-        for (i = 0; i < state->vdecl->nelems; i++) {
-            uint16_t usage = state->vdecl->usage_map[i];
+        for (i = 0; i < context->vdecl->nelems; i++) {
+            uint16_t usage = context->vdecl->usage_map[i];
             if (usage == NINE_DECLUSAGE_POSITIONT)
                 key.position_t = 1;
             else if (usage == NINE_DECLUSAGE_i(COLOR, 0))
@@ -1603,7 +1603,7 @@ nine_ff_get_vs(struct NineDevice9 *device)
             else if (usage % NINE_DECLUSAGE_COUNT == NINE_DECLUSAGE_TEXCOORD) {
                 s = usage / NINE_DECLUSAGE_COUNT;
                 if (s < 8)
-                    input_texture_coord[s] = nine_decltype_get_dim(state->vdecl->decls[i].Type);
+                    input_texture_coord[s] = nine_decltype_get_dim(context->vdecl->decls[i].Type);
                 else
                     DBG("FF given texture coordinate >= 8. Ignoring\n");
             } else if (usage < NINE_DECLUSAGE_NONE)
@@ -1818,7 +1818,7 @@ nine_ff_get_ps(struct NineDevice9 *device)
     if (s >= 1)
         key.ts[s-1].resultarg = 0;
 
-    key.projected = nine_ff_get_projected_key(state);
+    key.projected = nine_ff_get_projected_key(state, context);
     key.specular = !!context->rs[D3DRS_SPECULARENABLE];
 
     for (; s < 8; ++s)
index 6c32dba5902f996271b572db820c5cb7be8d22fc..b1e3b9ac4a973e56f7c2b2ef6004c07bdb2e6f69 100644 (file)
@@ -62,20 +62,20 @@ nine_decltype_get_dim(BYTE type)
 }
 
 static inline uint16_t
-nine_ff_get_projected_key(struct nine_state *state)
+nine_ff_get_projected_key(struct nine_state *state, struct nine_context *context)
 {
     unsigned s, i;
     uint16_t projected = 0;
     char input_texture_coord[8];
     memset(&input_texture_coord, 0, sizeof(input_texture_coord));
 
-    if (state->vdecl) {
-        for (i = 0; i < state->vdecl->nelems; i++) {
-            uint16_t usage = state->vdecl->usage_map[i];
+    if (context->vdecl) {
+        for (i = 0; i < context->vdecl->nelems; i++) {
+            uint16_t usage = context->vdecl->usage_map[i];
             if (usage % NINE_DECLUSAGE_COUNT == NINE_DECLUSAGE_TEXCOORD) {
                 s = usage / NINE_DECLUSAGE_COUNT;
                 if (s < 8)
-                    input_texture_coord[s] = nine_decltype_get_dim(state->vdecl->decls[i].Type);
+                    input_texture_coord[s] = nine_decltype_get_dim(context->vdecl->decls[i].Type);
             }
         }
     }
index cde38ee662264db601b393d14416ae86d338221a..07a57ba8f94ae71cc9503c67c127f5921901719d 100644 (file)
@@ -597,7 +597,7 @@ update_vertex_elements(struct NineDevice9 *device)
 {
     struct nine_state *state = &device->state;
     struct nine_context *context = &device->context;
-    const struct NineVertexDeclaration9 *vdecl = device->state.vdecl;
+    const struct NineVertexDeclaration9 *vdecl = device->context.vdecl;
     const struct NineVertexShader9 *vs;
     unsigned n, b, i;
     int index;
@@ -1276,6 +1276,25 @@ nine_context_set_stream_source_freq(struct NineDevice9 *device,
         state->changed.group |= NINE_STATE_STREAMFREQ;
 }
 
+void
+nine_context_set_vertex_declaration(struct NineDevice9 *device,
+                                    struct NineVertexDeclaration9 *vdecl)
+{
+    struct nine_state *state = &device->state;
+    struct nine_context *context = &device->context;
+    BOOL was_programmable_vs = device->state.programmable_vs;
+
+    nine_bind(&context->vdecl, vdecl);
+
+    device->state.programmable_vs = device->state.vs && !(device->context.vdecl && device->context.vdecl->position_t);
+    if (was_programmable_vs != device->state.programmable_vs) {
+        context->commit |= NINE_STATE_COMMIT_CONST_VS;
+        state->changed.group |= NINE_STATE_VS;
+    }
+
+    state->changed.group |= NINE_STATE_VDECL;
+}
+
 void
 nine_context_apply_stateblock(struct NineDevice9 *device,
                               const struct nine_state *src)
@@ -1331,6 +1350,12 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
         }
         context->changed.vtxbuf |= src->changed.vtxbuf;
     }
+
+    /* Vertex declaration */
+    if ((src->changed.group & NINE_STATE_VDECL) && src->vdecl)
+        nine_context_set_vertex_declaration(device, src->vdecl);
+
+    device->state.programmable_vs = device->state.vs && !(context->vdecl && context->vdecl->position_t);
 }
 
 static void
@@ -1857,6 +1882,7 @@ nine_context_clear(struct nine_context *context)
 {
     unsigned i;
 
+    nine_bind(&context->vdecl, NULL);
     for (i = 0; i < PIPE_MAX_ATTRIBS; ++i)
         pipe_resource_reference(&context->vtxbuf[i].buffer, NULL);
 
index 5bc9f70702389be5f821fae268d84dad974f21f5..523c93d68e9184363de650ccea99a8eff099d9ab 100644 (file)
@@ -227,6 +227,8 @@ struct nine_context {
 
     uint8_t rt_mask;
 
+    struct NineVertexDeclaration9 *vdecl;
+
     struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
     UINT stream_freq[PIPE_MAX_ATTRIBS];
     uint32_t stream_instancedata_mask; /* derived from stream_freq */
@@ -298,6 +300,10 @@ nine_context_set_stream_source_freq(struct NineDevice9 *device,
                                     UINT StreamNumber,
                                     UINT Setting);
 
+void
+nine_context_set_vertex_declaration(struct NineDevice9 *device,
+                                    struct NineVertexDeclaration9 *vdecl);
+
 void
 nine_context_apply_stateblock(struct NineDevice9 *device,
                               const struct nine_state *src);
index 4c0b537b1bd4066128b4fc6578976f51bc28c61d..d9f55b4e5fac3ba113d1618ea1f1b5de2bd14593 100644 (file)
@@ -99,7 +99,7 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
         key |= ((uint64_t)1) << 34;
 
     if (unlikely(ps->byte_code.version < 0x14)) {
-        projected = nine_ff_get_projected_key(state);
+        projected = nine_ff_get_projected_key(state, context);
         key |= ((uint64_t) projected) << 48;
     }
 
index 4af370ec94db96fbf4ba3bf196e1030d08b8b67c..1ed251af623177b4283b7f8f525252de4925b909 100644 (file)
@@ -567,10 +567,7 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This )
     nine_context_apply_stateblock(device, src);
 
     if ((src->changed.group & NINE_STATE_VDECL) && src->vdecl)
-        NineDevice9_SetVertexDeclaration(This->base.device, (IDirect3DVertexDeclaration9 *)src->vdecl);
-
-    /* Recomputing it is needed if we changed vs but not vdecl */
-    dst->programmable_vs = dst->vs && !(dst->vdecl && dst->vdecl->position_t);
+        nine_bind(&dst->vdecl, src->vdecl);
 
     /* Textures */
     if (src->changed.texture) {