st/nine: Back sampler states to nine_context
authorAxel Davy <axel.davy@ens.fr>
Tue, 18 Oct 2016 18:48:54 +0000 (20:48 +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
src/gallium/state_trackers/nine/stateblock9.c

index 3b6820657091ba24f14f2a3831ab2fdcfe10bac4..3bfff86f56b838aa6848a30949f17ff7844c820f 100644 (file)
@@ -2600,15 +2600,19 @@ NineDevice9_SetSamplerState( struct NineDevice9 *This,
     if (Sampler >= D3DDMAPSAMPLER)
         Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
 
-    if (state->samp_advertised[Sampler][Type] != Value || unlikely(This->is_recording)) {
-        /* Contrary to render states, old value is kept if new value is wrong (except intel + Value == 0) */
-        if (likely(nine_check_sampler_state_value(Type, Value)))
-            state->samp[Sampler][Type] = Value;
+    if (unlikely(This->is_recording)) {
         state->samp_advertised[Sampler][Type] = Value;
         state->changed.group |= NINE_STATE_SAMPLER;
         state->changed.sampler[Sampler] |= 1 << Type;
+        return D3D_OK;
     }
 
+    if (state->samp_advertised[Sampler][Type] == Value)
+        return D3D_OK;
+
+    state->samp_advertised[Sampler][Type] = Value;
+    nine_context_set_sampler_state(This, Sampler, Type, Value);
+
     return D3D_OK;
 }
 
@@ -2622,9 +2626,9 @@ NineDevice9_ValidateDevice( struct NineDevice9 *This,
 
     DBG("This=%p pNumPasses=%p\n", This, pNumPasses);
 
-    for (i = 0; i < ARRAY_SIZE(state->samp); ++i) {
-        if (state->samp[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
-            state->samp[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
+    for (i = 0; i < ARRAY_SIZE(state->samp_advertised); ++i) {
+        if (state->samp_advertised[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
+            state->samp_advertised[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
             return D3DERR_UNSUPPORTEDTEXTUREFILTER;
     }
 
index a560b897e60ed70a97f4a03e72066bc91b63401f..17a6934740ea1133524c2c65225dd806ac052d9d 100644 (file)
@@ -715,32 +715,32 @@ update_vertex_buffers(struct NineDevice9 *device)
 }
 
 static inline boolean
-update_sampler_derived(struct nine_state *state, struct nine_context *context, unsigned s)
+update_sampler_derived(struct nine_context *context, unsigned s)
 {
     boolean changed = FALSE;
 
-    if (state->samp[s][NINED3DSAMP_SHADOW] != context->texture[s]->shadow) {
+    if (context->samp[s][NINED3DSAMP_SHADOW] != context->texture[s]->shadow) {
         changed = TRUE;
-        state->samp[s][NINED3DSAMP_SHADOW] = context->texture[s]->shadow;
+        context->samp[s][NINED3DSAMP_SHADOW] = context->texture[s]->shadow;
     }
 
-    if (state->samp[s][NINED3DSAMP_CUBETEX] !=
+    if (context->samp[s][NINED3DSAMP_CUBETEX] !=
         (NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE)) {
         changed = TRUE;
-        state->samp[s][NINED3DSAMP_CUBETEX] =
+        context->samp[s][NINED3DSAMP_CUBETEX] =
                 NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE;
     }
 
-    if (state->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
-        int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s]->managed.lod;
+    if (context->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
+        int lod = context->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s]->managed.lod;
         if (lod < 0)
             lod = 0;
-        if (state->samp[s][NINED3DSAMP_MINLOD] != lod) {
+        if (context->samp[s][NINED3DSAMP_MINLOD] != lod) {
             changed = TRUE;
-            state->samp[s][NINED3DSAMP_MINLOD] = lod;
+            context->samp[s][NINED3DSAMP_MINLOD] = lod;
         }
     } else {
-        state->changed.sampler[s] &= ~0x300; /* lod changes irrelevant */
+        context->changed.sampler[s] &= ~0x300; /* lod changes irrelevant */
     }
 
     return changed;
@@ -773,15 +773,15 @@ update_textures_and_samplers(struct NineDevice9 *device)
         }
 
         if (context->texture[s]) {
-            sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
+            sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
 
             view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB);
             num_textures = i + 1;
 
-            if (update_sampler_derived(state, context, s) || (state->changed.sampler[s] & 0x05fe)) {
-                state->changed.sampler[s] = 0;
+            if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
+                context->changed.sampler[s] = 0;
                 commit_samplers = TRUE;
-                nine_convert_sampler_state(device->cso, s, state->samp[s]);
+                nine_convert_sampler_state(device->cso, s, context->samp[s]);
             }
         } else {
             /* Bind dummy sampler. We do not bind dummy sampler when
@@ -797,7 +797,7 @@ update_textures_and_samplers(struct NineDevice9 *device)
                                s - NINE_SAMPLER_PS(0), &device->dummy_sampler_state);
 
             commit_samplers = TRUE;
-            state->changed.sampler[s] = ~0;
+            context->changed.sampler[s] = ~0;
         }
 
         context->bound_samplers_mask_ps |= (1 << s);
@@ -821,15 +821,15 @@ update_textures_and_samplers(struct NineDevice9 *device)
         }
 
         if (context->texture[s]) {
-            sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
+            sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
 
             view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB);
             num_textures = i + 1;
 
-            if (update_sampler_derived(state, context, s) || (state->changed.sampler[s] & 0x05fe)) {
-                state->changed.sampler[s] = 0;
+            if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
+                context->changed.sampler[s] = 0;
                 commit_samplers = TRUE;
-                nine_convert_sampler_state(device->cso, s, state->samp[s]);
+                nine_convert_sampler_state(device->cso, s, context->samp[s]);
             }
         } else {
             /* Bind dummy sampler. We do not bind dummy sampler when
@@ -845,7 +845,7 @@ update_textures_and_samplers(struct NineDevice9 *device)
                                s - NINE_SAMPLER_VS(0), &device->dummy_sampler_state);
 
             commit_samplers = TRUE;
-            state->changed.sampler[s] = ~0;
+            context->changed.sampler[s] = ~0;
         }
 
         context->bound_samplers_mask_vs |= (1 << s);
@@ -1236,6 +1236,23 @@ nine_context_set_texture(struct NineDevice9 *device,
     state->changed.group |= NINE_STATE_TEXTURE;
 }
 
+void
+nine_context_set_sampler_state(struct NineDevice9 *device,
+                               DWORD Sampler,
+                               D3DSAMPLERSTATETYPE Type,
+                               DWORD Value)
+{
+    struct nine_state *state = &device->state;
+    struct nine_context *context = &device->context;
+
+    if (unlikely(!nine_check_sampler_state_value(Type, Value)))
+        return;
+
+    context->samp[Sampler][Type] = Value;
+    state->changed.group |= NINE_STATE_SAMPLER;
+    context->changed.sampler[Sampler] |= 1 << Type;
+}
+
 void
 nine_context_set_stream_source(struct NineDevice9 *device,
                                UINT StreamNumber,
@@ -1346,6 +1363,22 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
         }
     }
 
+    /* Sampler state */
+    if (src->changed.group & NINE_STATE_SAMPLER) {
+        unsigned s;
+
+        for (s = 0; s < NINE_MAX_SAMPLERS; ++s) {
+            uint32_t m = src->changed.sampler[s];
+            while (m) {
+                const int i = ffs(m) - 1;
+                m &= ~(1 << i);
+                if (nine_check_sampler_state_value(i, src->samp_advertised[s][i]))
+                    context->samp[s][i] = src->samp_advertised[s][i];
+            }
+            context->changed.sampler[s] |= src->changed.sampler[s];
+        }
+    }
+
     /* Vertex buffers */
     if (src->changed.vtxbuf | src->changed.stream_freq) {
         uint32_t m = src->changed.vtxbuf | src->changed.stream_freq;
@@ -1834,9 +1867,9 @@ nine_state_set_defaults(struct NineDevice9 *device, const D3DCAPS9 *caps,
     state->ff.tex_stage[0][D3DTSS_ALPHAOP] = D3DTOP_SELECTARG1;
     memset(&context->bumpmap_vars, 0, sizeof(context->bumpmap_vars));
 
-    for (s = 0; s < ARRAY_SIZE(state->samp); ++s) {
-        memcpy(&state->samp[s], nine_samp_state_defaults,
-               sizeof(state->samp[s]));
+    for (s = 0; s < NINE_MAX_SAMPLERS; ++s) {
+        memcpy(&context->samp[s], nine_samp_state_defaults,
+               sizeof(context->samp[s]));
         memcpy(&state->samp_advertised[s], nine_samp_state_defaults,
                sizeof(state->samp_advertised[s]));
     }
@@ -1866,8 +1899,8 @@ nine_state_set_defaults(struct NineDevice9 *device, const D3DCAPS9 *caps,
         state->viewport.MaxZ = 1.0f;
     }
 
-    for (s = 0; s < ARRAY_SIZE(state->changed.sampler); ++s)
-        state->changed.sampler[s] = ~0;
+    for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
+        context->changed.sampler[s] = ~0;
 
     if (!is_reset) {
         context->dummy_vbo_bound_at = -1;
index c648c0dce1af81154d81ea61c1c5ef7e5703da4f..b6b8d76833d9b933caae2767cd33eddae3d7cf2d 100644 (file)
 #define NINED3DRS_MULTISAMPLE  (D3DRS_BLENDOPALPHA + 4)
 
 #define D3DRS_LAST       D3DRS_BLENDOPALPHA
+#define D3DSAMP_LAST     D3DSAMP_DMAPOFFSET
 #define NINED3DRS_LAST   NINED3DRS_MULTISAMPLE /* 214 */
 #define NINED3DSAMP_LAST NINED3DSAMP_CUBETEX /* 16 */
 #define NINED3DTSS_LAST  D3DTSS_CONSTANT
 #define NINED3DTS_LAST   D3DTS_WORLDMATRIX(255)
 
 #define D3DRS_COUNT       (D3DRS_LAST + 1)
+#define D3DSAMP_COUNT     (D3DSAMP_LAST + 1)
 #define NINED3DRS_COUNT   (NINED3DRS_LAST + 1)
 #define NINED3DSAMP_COUNT (NINED3DSAMP_LAST + 1)
 #define NINED3DTSS_COUNT  (NINED3DTSS_LAST + 1)
@@ -139,7 +141,7 @@ struct nine_state
         uint32_t vtxbuf; /* stateblocks only */
         uint32_t stream_freq; /* stateblocks only */
         uint32_t texture; /* stateblocks only */
-        uint16_t sampler[NINE_MAX_SAMPLERS];
+        uint16_t sampler[NINE_MAX_SAMPLERS]; /* stateblocks only */
         struct nine_range *vs_const_f;
         struct nine_range *ps_const_f;
         struct nine_range *vs_const_i;
@@ -186,8 +188,7 @@ struct nine_state
 
     struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; /* PS, DMAP, VS */
 
-    DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
-    DWORD samp_advertised[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
+    DWORD samp_advertised[NINE_MAX_SAMPLERS][D3DSAMP_COUNT];
 
     struct {
         struct {
@@ -214,6 +215,7 @@ struct nine_state
 
 struct nine_context {
     struct {
+        uint16_t sampler[NINE_MAX_SAMPLERS];
         uint32_t vtxbuf;
     } changed;
 
@@ -240,6 +242,8 @@ struct nine_context {
 
     struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS];
 
+    DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
+
     uint32_t samplers_shadow;
 
     uint8_t bound_samplers_mask_vs;
@@ -290,6 +294,12 @@ nine_context_set_texture(struct NineDevice9 *device,
                          DWORD Stage,
                          struct NineBaseTexture9 *tex);
 
+void
+nine_context_set_sampler_state(struct NineDevice9 *device,
+                               DWORD Sampler,
+                               D3DSAMPLERSTATETYPE Type,
+                               DWORD Value);
+
 void
 nine_context_set_stream_source(struct NineDevice9 *device,
                                UINT StreamNumber,
index 1ed251af623177b4283b7f8f525252de4925b909..0c19703e64bc1d08007d88f7013d2bc741094619 100644 (file)
@@ -246,7 +246,6 @@ nine_state_copy_common(struct NineDevice9 *device,
     if (mask->changed.group & NINE_STATE_SAMPLER) {
         for (s = 0; s < NINE_MAX_SAMPLERS; ++s) {
             if (mask->changed.sampler[s] == 0x3ffe) {
-                memcpy(&dst->samp[s], &src->samp[s], sizeof(dst->samp[s]));
                 memcpy(&dst->samp_advertised[s], &src->samp_advertised[s], sizeof(dst->samp_advertised[s]));
             } else {
                 uint32_t m = mask->changed.sampler[s];
@@ -254,7 +253,6 @@ nine_state_copy_common(struct NineDevice9 *device,
                 while (m) {
                     const int i = ffs(m) - 1;
                     m &= ~(1 << i);
-                    dst->samp[s][i] = src->samp[s][i];
                     dst->samp_advertised[s][i] = src->samp_advertised[s][i];
                 }
             }
@@ -444,7 +442,6 @@ nine_state_copy_common_all(struct NineDevice9 *device,
         dst->changed.ucp = src->changed.ucp;
 
     /* Sampler state. */
-    memcpy(dst->samp, src->samp, sizeof(dst->samp));
     memcpy(dst->samp_advertised, src->samp_advertised, sizeof(dst->samp_advertised));
     if (apply)
         memcpy(dst->changed.sampler,