st/nine: Move texture setting to nine_context_*
authorAxel Davy <axel.davy@ens.fr>
Sun, 16 Oct 2016 13:56:14 +0000 (15:56 +0200)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:21 +0000 (23:44 +0100)
And move samplers_shadow to nine_context.
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/pixelshader9.h
src/gallium/state_trackers/nine/stateblock9.c
src/gallium/state_trackers/nine/vertexshader9.h

index 7519eaaa789c1390920f43606a986fb14ae5e7f1..9923c894dd28951d859e19b34d417c889d3c14dc 100644 (file)
@@ -2450,6 +2450,7 @@ NineDevice9_SetTexture( struct NineDevice9 *This,
 {
     struct nine_state *state = This->update;
     struct NineBaseTexture9 *tex = NineBaseTexture9(pTexture);
+    struct NineBaseTexture9 *old;
 
     DBG("This=%p Stage=%u pTexture=%p\n", This, Stage, pTexture);
 
@@ -2463,28 +2464,29 @@ NineDevice9_SetTexture( struct NineDevice9 *This,
     if (Stage >= D3DDMAPSAMPLER)
         Stage = Stage - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
 
-    if (!This->is_recording) {
-        struct NineBaseTexture9 *old = state->texture[Stage];
-        if (old == tex)
-            return D3D_OK;
+    if (This->is_recording) {
+        state->changed.texture |= 1 << Stage;
+        state->changed.group |= NINE_STATE_TEXTURE;
+        nine_bind(&state->texture[Stage], pTexture);
+        return D3D_OK;
+    }
 
-        state->samplers_shadow &= ~(1 << Stage);
-        if (tex) {
-            state->samplers_shadow |= tex->shadow << Stage;
+    old = state->texture[Stage];
+    if (old == tex)
+        return D3D_OK;
 
-            if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
-                list_add(&tex->list, &This->update_textures);
+    if (tex) {
+        if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
+            list_add(&tex->list, &This->update_textures);
 
-            tex->bind_count++;
-        }
-        if (old)
-            old->bind_count--;
+        tex->bind_count++;
     }
-    nine_bind(&state->texture[Stage], pTexture);
+    if (old)
+        old->bind_count--;
 
-    if (This->is_recording)
-        state->changed.texture |= 1 << Stage;
-    state->changed.group |= NINE_STATE_TEXTURE;
+    nine_context_set_texture(This, Stage, tex);
+
+    nine_bind(&state->texture[Stage], pTexture);
 
     return D3D_OK;
 }
index 49e36a0ab5cb90597b7af7c3c8b668e59de03647..b309af53fd1cd672874415a2ed2e6377ed97d09e 100644 (file)
@@ -1223,9 +1223,25 @@ nine_context_set_render_state(struct NineDevice9 *device,
 }
 
 void
-nine_context_apply_stateblock(struct nine_context *dst,
+nine_context_set_texture(struct NineDevice9 *device,
+                         DWORD Stage,
+                         struct NineBaseTexture9 *tex)
+{
+    struct nine_context *context = &device->context;
+    struct nine_state *state = &device->state;
+
+    context->samplers_shadow &= ~(1 << Stage);
+    if (tex)
+        context->samplers_shadow |= tex->shadow << Stage;
+
+    state->changed.group |= NINE_STATE_TEXTURE;
+}
+
+void
+nine_context_apply_stateblock(struct NineDevice9 *device,
                               const struct nine_state *src)
 {
+    struct nine_context *context = &device->context;
     int i;
 
     for (i = 0; i < ARRAY_SIZE(src->changed.rs); ++i) {
@@ -1233,7 +1249,24 @@ nine_context_apply_stateblock(struct nine_context *dst,
         while (m) {
             const int r = ffs(m) - 1;
             m &= ~(1 << r);
-            dst->rs[i * 32 + r] = nine_fix_render_state_value(i * 32 + r, src->rs_advertised[i * 32 + r]);
+            context->rs[i * 32 + r] = nine_fix_render_state_value(i * 32 + r, src->rs_advertised[i * 32 + r]);
+        }
+    }
+
+    /* Textures */
+    if (src->changed.texture) {
+        uint32_t m = src->changed.texture;
+        unsigned s;
+
+        context->samplers_shadow &= ~m;
+
+        for (s = 0; m; ++s, m >>= 1) {
+            struct NineBaseTexture9 *tex = src->texture[s];
+            if (!(m & 1))
+                continue;
+            if (tex)
+                context->samplers_shadow |= tex->shadow << s;
+            /* nine_bind(&state->texture[s], src->texture[s]); Already bound by NineStateBlock9_Apply */
         }
     }
 }
index 99b0a3835bd61e83ca5528fa524f310020e0bfca..686f40175fe9729f35dc79dea8ef1abfbf17691b 100644 (file)
@@ -174,8 +174,6 @@ struct nine_state
     BOOL   ps_const_b[NINE_MAX_CONST_B];
     float *ps_lconstf_temp;
 
-    uint32_t samplers_shadow;
-
     struct NineVertexDeclaration9 *vdecl;
 
     struct NineIndexBuffer9   *idxbuf;
@@ -229,6 +227,8 @@ struct nine_context {
 
     DWORD rs[NINED3DRS_COUNT];
 
+    uint32_t samplers_shadow;
+
     uint8_t bound_samplers_mask_vs;
     uint16_t bound_samplers_mask_ps;
 
@@ -272,6 +272,15 @@ nine_context_set_render_state(struct NineDevice9 *device,
                               D3DRENDERSTATETYPE State,
                               DWORD Value);
 
+void
+nine_context_set_texture(struct NineDevice9 *device,
+                         DWORD Stage,
+                         struct NineBaseTexture9 *tex);
+
+void
+nine_context_apply_stateblock(struct NineDevice9 *device,
+                              const struct nine_state *src);
+
 void
 nine_context_clear_fb(struct NineDevice9 *device, DWORD Count,
                       const D3DRECT *pRects, DWORD Flags,
index bc52cc70ec2e084398d10b55e14398c0d1e72796..98d0b0360f506042ec83d175e0a01d7a84dc2b27 100644 (file)
@@ -85,7 +85,7 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
         }
         key = samplers_ps1_types;
     } else {
-        samplers_shadow = (uint16_t)((state->samplers_shadow & NINE_PS_SAMPLERS_MASK) >> NINE_SAMPLER_PS(0));
+        samplers_shadow = (uint16_t)((context->samplers_shadow & NINE_PS_SAMPLERS_MASK) >> NINE_SAMPLER_PS(0));
         key = samplers_shadow & ps->sampler_mask;
     }
 
index d04ac8f7bfebd820c6bb7329c986f043f26b6fe5..4f5e9d7b8d3cd1fe3709648e9ca34c8ecfd5f4ec 100644 (file)
@@ -570,7 +570,7 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This )
     else
         nine_state_copy_common(device, dst, src, src, TRUE, pool);
 
-    nine_context_apply_stateblock(&device->context, src);
+    nine_context_apply_stateblock(device, src);
 
     if ((src->changed.group & NINE_STATE_VDECL) && src->vdecl)
         NineDevice9_SetVertexDeclaration(This->base.device, (IDirect3DVertexDeclaration9 *)src->vdecl);
@@ -582,8 +582,6 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This )
     if (src->changed.texture) {
         uint32_t m = src->changed.texture;
 
-        dst->samplers_shadow &= ~m;
-
         for (s = 0; m; ++s, m >>= 1) {
             struct NineBaseTexture9 *tex = src->texture[s];
             if (!(m & 1))
@@ -592,7 +590,6 @@ NineStateBlock9_Apply( struct NineStateBlock9 *This )
                 tex->bind_count++;
                 if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
                     list_add(&tex->list, &This->base.device->update_textures);
-                dst->samplers_shadow |= tex->shadow << s;
             }
             if (src->texture[s])
                 src->texture[s]->bind_count--;
index f1d8ec1e0d4a1197e94bbebf16a497402cacda5a..a912d4628b4fd316b52528d5a7a17973ad762d12 100644 (file)
@@ -80,13 +80,12 @@ static inline BOOL
 NineVertexShader9_UpdateKey( struct NineVertexShader9 *vs,
                              struct NineDevice9 *device )
 {
-    struct nine_state *state = &(device->state);
     struct nine_context *context = &(device->context);
     uint8_t samplers_shadow;
     uint64_t key;
     BOOL res;
 
-    samplers_shadow = (uint8_t)((state->samplers_shadow & NINE_VS_SAMPLERS_MASK) >> NINE_SAMPLER_VS(0));
+    samplers_shadow = (uint8_t)((context->samplers_shadow & NINE_VS_SAMPLERS_MASK) >> NINE_SAMPLER_VS(0));
     samplers_shadow &= vs->sampler_mask;
     key = samplers_shadow;