[Mesa-dev] [PATCH 11/84] st/nine: Back vs to nine_context

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


And move programmable_vs storage and computation.
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    | 26 +++++------
 src/gallium/state_trackers/nine/nine_ff.c    |  8 ++--
 src/gallium/state_trackers/nine/nine_ff.h    |  2 +-
 src/gallium/state_trackers/nine/nine_state.c | 68 +++++++++++++++++++---------
 src/gallium/state_trackers/nine/nine_state.h |  8 +++-
 5 files changed, 71 insertions(+), 41 deletions(-)

diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c
index b0465e4..347ccc2 100644
--- a/src/gallium/state_trackers/nine/device9.c
+++ b/src/gallium/state_trackers/nine/device9.c
@@ -2923,6 +2923,7 @@ NineDevice9_ProcessVertices( struct NineDevice9 *This,
     struct pipe_stream_output_target *target;
     struct pipe_draw_info draw;
     struct pipe_box box;
+    bool programmable_vs = This->state.vs && !(This->state.vdecl && This->state.vdecl->position_t);
     unsigned offsets[1] = {0};
     HRESULT hr;
     unsigned buffer_size;
@@ -2939,7 +2940,7 @@ NineDevice9_ProcessVertices( struct NineDevice9 *This,
     }
 
 
-    vs = This->state.programmable_vs ? This->state.vs : This->ff.vs;
+    vs = programmable_vs ? This->state.vs : This->ff.vs;
     /* Note: version is 0 for ff */
     user_assert(vdecl || (vs->byte_code.version < 0x30 && dst->desc.FVF),
                 D3DERR_INVALIDCALL);
@@ -2961,7 +2962,7 @@ NineDevice9_ProcessVertices( struct NineDevice9 *This,
      * if not set, everything from src will be used, and dst
      * must match exactly the ff vs outputs.
      * TODO: Handle all the checks, etc for ff */
-    user_assert(vdecl->position_t || This->state.programmable_vs,
+    user_assert(vdecl->position_t || programmable_vs,
                 D3DERR_INVALIDCALL);
 
     /* TODO: Support vs < 3 and ff */
@@ -3149,23 +3150,22 @@ NineDevice9_SetVertexShader( struct NineDevice9 *This,
                              IDirect3DVertexShader9 *pShader )
 {
     struct nine_state *state = This->update;
-    struct nine_context *context = &This->context;
-    BOOL was_programmable_vs = This->state.programmable_vs;
+    struct NineVertexShader9 *vs_shader = (struct NineVertexShader9*)pShader;
 
     DBG("This=%p pShader=%p\n", This, pShader);
 
-    if (!This->is_recording && state->vs == (struct NineVertexShader9*)pShader)
-      return D3D_OK;
-
-    nine_bind(&state->vs, pShader);
+    if (unlikely(This->is_recording)) {
+        nine_bind(&state->vs, vs_shader);
+        state->changed.group |= NINE_STATE_VS;
+        return D3D_OK;
+    }
 
-    This->state.programmable_vs = This->state.vs && !(This->context.vdecl && This->context.vdecl->position_t);
+    if (state->vs == vs_shader)
+      return D3D_OK;
 
-    /* ff -> non-ff: commit back non-ff constants */
-    if (!was_programmable_vs && This->state.programmable_vs)
-        context->commit |= NINE_STATE_COMMIT_CONST_VS;
+    nine_bind(&state->vs, vs_shader);
 
-    state->changed.group |= NINE_STATE_VS;
+    nine_context_set_vertex_shader(This, vs_shader);
 
     return D3D_OK;
 }
diff --git a/src/gallium/state_trackers/nine/nine_ff.c b/src/gallium/state_trackers/nine/nine_ff.c
index 2c45963..8a550cb 100644
--- a/src/gallium/state_trackers/nine/nine_ff.c
+++ b/src/gallium/state_trackers/nine/nine_ff.c
@@ -1832,7 +1832,7 @@ nine_ff_get_ps(struct NineDevice9 *device)
      * Tests on Win 10 seem to indicate _34
      * and _33 are checked against 0, 1. */
     if (key.fog_mode && key.fog)
-        key.fog_source = !state->programmable_vs &&
+        key.fog_source = !context->programmable_vs &&
             !(projection_matrix->_34 == 0.0f &&
               projection_matrix->_44 == 1.0f);
 
@@ -2042,10 +2042,10 @@ nine_ff_update(struct NineDevice9 *device)
     struct nine_context *context = &device->context;
     struct pipe_constant_buffer cb;
 
-    DBG("vs=%p ps=%p\n", device->state.vs, device->state.ps);
+    DBG("vs=%p ps=%p\n", context->vs, device->state.ps);
 
     /* NOTE: the only reference belongs to the hash table */
-    if (!state->programmable_vs) {
+    if (!context->programmable_vs) {
         device->ff.vs = nine_ff_get_vs(device);
         device->state.changed.group |= NINE_STATE_VS;
     }
@@ -2054,7 +2054,7 @@ nine_ff_update(struct NineDevice9 *device)
         device->state.changed.group |= NINE_STATE_PS;
     }
 
-    if (!state->programmable_vs) {
+    if (!context->programmable_vs) {
         nine_ff_load_vs_transforms(device);
         nine_ff_load_tex_matrices(device);
         nine_ff_load_lights(device);
diff --git a/src/gallium/state_trackers/nine/nine_ff.h b/src/gallium/state_trackers/nine/nine_ff.h
index b1e3b9a..ec79959 100644
--- a/src/gallium/state_trackers/nine/nine_ff.h
+++ b/src/gallium/state_trackers/nine/nine_ff.h
@@ -85,7 +85,7 @@ nine_ff_get_projected_key(struct nine_state *state, struct nine_context *context
         unsigned dim = state->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & 0x7;
         unsigned proj = !!(state->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED);
 
-        if (!state->vs) {
+        if (!context->vs) {
             if (dim > 4)
                 dim = input_texture_coord[s];
 
diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c
index ea61a37..e332b62 100644
--- a/src/gallium/state_trackers/nine/nine_state.c
+++ b/src/gallium/state_trackers/nine/nine_state.c
@@ -95,8 +95,8 @@ prepare_vs_constants_userbuf_swvp(struct NineDevice9 *device)
         cb.buffer_size = 4096 * sizeof(float[4]);
         cb.user_buffer = state->vs_const_f_swvp;
 
-        if (state->vs->lconstf.ranges) {
-            const struct nine_lconstf *lconstf =  &device->state.vs->lconstf;
+        if (context->vs->lconstf.ranges) {
+            const struct nine_lconstf *lconstf = &(context->vs->lconstf);
             const struct nine_range *r = lconstf->ranges;
             unsigned n = 0;
             float *dst = device->state.vs_lconstf_temp;
@@ -234,7 +234,7 @@ prepare_vs_constants_userbuf(struct NineDevice9 *device)
     struct pipe_constant_buffer cb;
     cb.buffer = NULL;
     cb.buffer_offset = 0;
-    cb.buffer_size = device->state.vs->const_used_size;
+    cb.buffer_size = context->vs->const_used_size;
     cb.user_buffer = device->state.vs_const_f;
 
     if (device->swvp) {
@@ -274,9 +274,9 @@ prepare_vs_constants_userbuf(struct NineDevice9 *device)
     if (!cb.buffer_size)
         return;
 
-    if (device->state.vs->lconstf.ranges) {
+    if (context->vs->lconstf.ranges) {
         /* TODO: Can we make it so that we don't have to copy everything ? */
-        const struct nine_lconstf *lconstf =  &device->state.vs->lconstf;
+        const struct nine_lconstf *lconstf =  &(context->vs->lconstf);
         const struct nine_range *r = lconstf->ranges;
         unsigned n = 0;
         float *dst = device->state.vs_lconstf_temp;
@@ -400,20 +400,19 @@ prepare_ps_constants_userbuf(struct NineDevice9 *device)
 static inline uint32_t
 prepare_vs(struct NineDevice9 *device, uint8_t shader_changed)
 {
-    struct nine_state *state = &device->state;
     struct nine_context *context = &device->context;
-    struct NineVertexShader9 *vs = state->vs;
+    struct NineVertexShader9 *vs = context->vs;
     uint32_t changed_group = 0;
     int has_key_changed = 0;
 
-    if (likely(state->programmable_vs))
+    if (likely(context->programmable_vs))
         has_key_changed = NineVertexShader9_UpdateKey(vs, device);
 
     if (!shader_changed && !has_key_changed)
         return 0;
 
     /* likely because we dislike FF */
-    if (likely(state->programmable_vs)) {
+    if (likely(context->programmable_vs)) {
         context->cso.vs = NineVertexShader9_GetVariant(vs);
     } else {
         vs = device->ff.vs;
@@ -610,7 +609,7 @@ update_vertex_elements(struct NineDevice9 *device)
     context->stream_usage_mask = 0;
     memset(vdecl_index_map, -1, 16);
     memset(used_streams, 0, device->caps.MaxStreams);
-    vs = state->programmable_vs ? device->state.vs : device->ff.vs;
+    vs = context->programmable_vs ? context->vs : device->ff.vs;
 
     if (vdecl) {
         for (n = 0; n < vs->num_inputs; ++n) {
@@ -810,7 +809,7 @@ update_textures_and_samplers(struct NineDevice9 *device)
         cso_single_sampler_done(device->cso, PIPE_SHADER_FRAGMENT);
 
     commit_samplers = FALSE;
-    sampler_mask = state->programmable_vs ? state->vs->sampler_mask : 0;
+    sampler_mask = context->programmable_vs ? context->vs->sampler_mask : 0;
     context->bound_samplers_mask_vs = 0;
     for (num_textures = 0, i = 0; i < NINE_MAX_SAMPLERS_VS; ++i) {
         const unsigned s = NINE_SAMPLER_VS(i);
@@ -901,7 +900,7 @@ commit_vs_constants(struct NineDevice9 *device)
 {
     struct pipe_context *pipe = device->pipe;
 
-    if (unlikely(!device->state.programmable_vs))
+    if (unlikely(!device->context.programmable_vs))
         pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &device->context.pipe.cb_vs_ff);
     else {
         if (device->swvp) {
@@ -1022,7 +1021,7 @@ nine_update_state(struct NineDevice9 *device)
     update_managed_buffers(device);
 
     /* ff_update may change VS/PS dirty bits */
-    if (unlikely(!state->programmable_vs || !state->ps))
+    if (unlikely(!context->programmable_vs || !state->ps))
         nine_ff_update(device);
     group = state->changed.group;
 
@@ -1055,7 +1054,7 @@ nine_update_state(struct NineDevice9 *device)
             prepare_rasterizer(device);
         if (group & (NINE_STATE_TEXTURE | NINE_STATE_SAMPLER))
             update_textures_and_samplers(device);
-        if ((group & (NINE_STATE_VS_CONST | NINE_STATE_VS | NINE_STATE_SWVP)) && state->programmable_vs)
+        if ((group & (NINE_STATE_VS_CONST | NINE_STATE_VS | NINE_STATE_SWVP)) && context->programmable_vs)
             prepare_vs_constants_userbuf(device);
         if ((group & (NINE_STATE_PS_CONST | NINE_STATE_PS)) && state->ps)
             prepare_ps_constants_userbuf(device);
@@ -1282,12 +1281,12 @@ nine_context_set_vertex_declaration(struct NineDevice9 *device,
 {
     struct nine_state *state = &device->state;
     struct nine_context *context = &device->context;
-    BOOL was_programmable_vs = device->state.programmable_vs;
+    BOOL was_programmable_vs = context->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->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
+    if (was_programmable_vs != context->programmable_vs) {
         context->commit |= NINE_STATE_COMMIT_CONST_VS;
         state->changed.group |= NINE_STATE_VS;
     }
@@ -1296,6 +1295,25 @@ nine_context_set_vertex_declaration(struct NineDevice9 *device,
 }
 
 void
+nine_context_set_vertex_shader(struct NineDevice9 *device,
+                               struct NineVertexShader9 *pShader)
+{
+    struct nine_state *state = &device->state;
+    struct nine_context *context = &device->context;
+    BOOL was_programmable_vs = context->programmable_vs;
+
+    nine_bind(&context->vs, pShader);
+
+    context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
+
+    /* ff -> non-ff: commit back non-ff constants */
+    if (!was_programmable_vs && context->programmable_vs)
+        context->commit |= NINE_STATE_COMMIT_CONST_VS;
+
+    state->changed.group |= NINE_STATE_VS;
+}
+
+void
 nine_context_apply_stateblock(struct NineDevice9 *device,
                               const struct nine_state *src)
 {
@@ -1355,7 +1373,11 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
     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);
+    /* Vertex shader */
+    if (src->changed.group & NINE_STATE_VS)
+        nine_bind(&context->vs, src->vs);
+
+    context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
 }
 
 static void
@@ -1887,6 +1909,7 @@ nine_context_clear(struct nine_context *context)
 {
     unsigned i;
 
+    nine_bind(&context->vs, NULL);
     nine_bind(&context->vdecl, NULL);
     for (i = 0; i < PIPE_MAX_ATTRIBS; ++i)
         pipe_resource_reference(&context->vtxbuf[i].buffer, NULL);
@@ -1937,10 +1960,11 @@ update_vertex_elements_sw(struct NineDevice9 *device)
     int dummy_vbo_stream = -1;
     BOOL need_dummy_vbo = FALSE;
     struct pipe_vertex_element ve[PIPE_MAX_ATTRIBS];
+    bool programmable_vs = state->vs && !(state->vdecl && state->vdecl->position_t);
 
     memset(vdecl_index_map, -1, 16);
     memset(used_streams, 0, device->caps.MaxStreams);
-    vs = state->programmable_vs ? device->state.vs : device->ff.vs;
+    vs = programmable_vs ? device->state.vs : device->ff.vs;
 
     if (vdecl) {
         for (n = 0; n < vs->num_inputs; ++n) {
@@ -2207,10 +2231,10 @@ nine_state_prepare_draw_sw(struct NineDevice9 *device, struct NineVertexDeclarat
                            int start_vertice, int num_vertices, struct pipe_stream_output_info *so)
 {
     struct nine_state *state = &device->state;
+    bool programmable_vs = state->vs && !(state->vdecl && state->vdecl->position_t);
+    struct NineVertexShader9 *vs = programmable_vs ? device->state.vs : device->ff.vs;
 
-    struct NineVertexShader9 *vs = state->programmable_vs ? device->state.vs : device->ff.vs;
-
-    assert(state->programmable_vs);
+    assert(programmable_vs);
 
     DBG("Preparing draw\n");
     cso_set_vertex_shader_handle(device->cso_sw,
diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h
index 523c93d..c648c0d 100644
--- a/src/gallium/state_trackers/nine/nine_state.h
+++ b/src/gallium/state_trackers/nine/nine_state.h
@@ -166,7 +166,6 @@ struct nine_state
     int   *vs_const_i;
     BOOL  *vs_const_b;
     float *vs_lconstf_temp;
-    BOOL programmable_vs;
 
     struct NinePixelShader9 *ps;
     float *ps_const_f;
@@ -227,6 +226,9 @@ struct nine_context {
 
     uint8_t rt_mask;
 
+    struct NineVertexShader9 *vs;
+    BOOL programmable_vs;
+
     struct NineVertexDeclaration9 *vdecl;
 
     struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
@@ -305,6 +307,10 @@ nine_context_set_vertex_declaration(struct NineDevice9 *device,
                                     struct NineVertexDeclaration9 *vdecl);
 
 void
+nine_context_set_vertex_shader(struct NineDevice9 *device,
+                               struct NineVertexShader9 *pShader);
+
+void
 nine_context_apply_stateblock(struct NineDevice9 *device,
                               const struct nine_state *src);
 
-- 
2.10.2



More information about the mesa-dev mailing list