[Mesa-dev] [PATCH 41/71] st/nine: Rework rasterizer states

Axel Davy axel.davy at ens.fr
Sun Aug 16 08:28:05 PDT 2015


Separate state preparation and state commit

Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
 src/gallium/state_trackers/nine/nine_pipe.c  |  8 ++++----
 src/gallium/state_trackers/nine/nine_pipe.h  |  2 +-
 src/gallium/state_trackers/nine/nine_state.c | 23 ++++++++++++++++-------
 src/gallium/state_trackers/nine/nine_state.h |  2 ++
 4 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/gallium/state_trackers/nine/nine_pipe.c b/src/gallium/state_trackers/nine/nine_pipe.c
index 0538957..ff5ec60 100644
--- a/src/gallium/state_trackers/nine/nine_pipe.c
+++ b/src/gallium/state_trackers/nine/nine_pipe.c
@@ -69,13 +69,13 @@ nine_convert_dsa_state(struct pipe_depth_stencil_alpha_state *dsa_state,
     *dsa_state = dsa;
 }
 
-/* TODO: Keep a static copy in device so we don't have to memset every time ? */
 void
-nine_convert_rasterizer_state(struct cso_context *ctx, const DWORD *rs)
+nine_convert_rasterizer_state(struct pipe_rasterizer_state *rast_state, const DWORD *rs)
 {
     struct pipe_rasterizer_state rast;
 
-    memset(&rast, 0, sizeof(rast)); /* memcmp safety */
+    /* Note: we don't have a memset since we use a static copy that was memset once
+     * and we always rewrite all states we change. */
 
     rast.flatshade = rs[D3DRS_SHADEMODE] == D3DSHADE_FLAT;
  /* rast.light_twoside = 0; */
@@ -122,7 +122,7 @@ nine_convert_rasterizer_state(struct cso_context *ctx, const DWORD *rs)
     rast.offset_scale = asfloat(rs[D3DRS_SLOPESCALEDEPTHBIAS]);
  /* rast.offset_clamp = 0.0f; */
 
-    cso_set_rasterizer(ctx, &rast);
+    *rast_state = rast;
 }
 
 static inline void
diff --git a/src/gallium/state_trackers/nine/nine_pipe.h b/src/gallium/state_trackers/nine/nine_pipe.h
index 2f2e9cb..e2680f6 100644
--- a/src/gallium/state_trackers/nine/nine_pipe.h
+++ b/src/gallium/state_trackers/nine/nine_pipe.h
@@ -38,7 +38,7 @@ extern const enum pipe_format nine_d3d9_to_pipe_format_map[120];
 extern const D3DFORMAT nine_pipe_to_d3d9_format_map[PIPE_FORMAT_COUNT];
 
 void nine_convert_dsa_state(struct pipe_depth_stencil_alpha_state *, const DWORD *);
-void nine_convert_rasterizer_state(struct cso_context *, const DWORD *);
+void nine_convert_rasterizer_state(struct pipe_rasterizer_state *, const DWORD *);
 void nine_convert_blend_state(struct cso_context *, const DWORD *);
 void nine_convert_sampler_state(struct cso_context *, int idx, const DWORD *);
 
diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c
index 7875d31..b29556b 100644
--- a/src/gallium/state_trackers/nine/nine_state.c
+++ b/src/gallium/state_trackers/nine/nine_state.c
@@ -46,6 +46,13 @@ prepare_dsa(struct NineDevice9 *device)
     device->state.commit |= NINE_STATE_COMMIT_DSA;
 }
 
+static inline void
+prepare_rasterizer(struct NineDevice9 *device)
+{
+    nine_convert_rasterizer_state(&device->state.pipe.rast, device->state.rs);
+    device->state.commit |= NINE_STATE_COMMIT_RASTERIZER;
+}
+
 /* State preparation incremental */
 
 /* State preparation + State commit */
@@ -195,12 +202,6 @@ update_blend(struct NineDevice9 *device)
     nine_convert_blend_state(device->cso, device->state.rs);
 }
 
-static inline void
-update_rasterizer(struct NineDevice9 *device)
-{
-    nine_convert_rasterizer_state(device->cso, device->state.rs);
-}
-
 /* Loop through VS inputs and pick the vertex elements with the declared
  * usage from the vertex declaration, then insert the instance divisor from
  * the stream source frequency setting.
@@ -859,6 +860,12 @@ commit_scissor(struct NineDevice9 *device)
 }
 
 static inline void
+commit_rasterizer(struct NineDevice9 *device)
+{
+    cso_set_rasterizer(device->cso, &device->state.pipe.rast);
+}
+
+static inline void
 commit_index_buffer(struct NineDevice9 *device)
 {
     struct pipe_context *pipe = device->pipe;
@@ -958,7 +965,7 @@ nine_update_state(struct NineDevice9 *device)
             group |= update_vs(device);
 
         if (group & NINE_STATE_RASTERIZER)
-            update_rasterizer(device);
+            prepare_rasterizer(device);
 
         if (group & NINE_STATE_PS)
             group |= update_ps(device);
@@ -1012,6 +1019,8 @@ nine_update_state(struct NineDevice9 *device)
 
     if (state->commit & NINE_STATE_COMMIT_DSA)
         commit_dsa(device);
+    if (state->commit & NINE_STATE_COMMIT_RASTERIZER)
+        commit_rasterizer(device);
 
     state->commit = 0;
 
diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h
index e833225..bd2ad38 100644
--- a/src/gallium/state_trackers/nine/nine_state.h
+++ b/src/gallium/state_trackers/nine/nine_state.h
@@ -79,6 +79,7 @@
 #define NINE_STATE_UNHANDLED   (1 << 24)
 
 #define NINE_STATE_COMMIT_DSA  (1 << 0)
+#define NINE_STATE_COMMIT_RASTERIZER (1 << 1)
 
 
 #define NINE_MAX_SIMULTANEOUS_RENDERTARGETS 4
@@ -214,6 +215,7 @@ struct nine_state
     uint32_t commit;
     struct {
         struct pipe_depth_stencil_alpha_state dsa;
+        struct pipe_rasterizer_state rast;
     } pipe;
 };
 
-- 
2.1.0



More information about the mesa-dev mailing list