st/nine: Back textures into nine_context
authorAxel Davy <axel.davy@ens.fr>
Sun, 16 Oct 2016 14:09:51 +0000 (16:09 +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/basetexture9.c
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/device9ex.c
src/gallium/state_trackers/nine/nine_ff.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

index e7b049c431180a477318e7ede8d0040f69cece63..633fa23287734a4fe2007b76c6706230e84b1456 100644 (file)
@@ -209,6 +209,7 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
             struct nine_state *state = &This->base.base.device->state;
             unsigned s;
             for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
+                /* Dirty tracking is done in device9 state, not nine_context. */
                 if (state->texture[s] == This)
                     state->changed.group |= NINE_STATE_TEXTURE;
         }
index 9923c894dd28951d859e19b34d417c889d3c14dc..ce30d264f3519df9ba9437650e9e449113fc7fbe 100644 (file)
@@ -486,6 +486,7 @@ NineDevice9_dtor( struct NineDevice9 *This )
     nine_ff_fini(This);
     nine_state_destroy_sw(This);
     nine_state_clear(&This->state, TRUE);
+    nine_context_clear(&This->context);
 
     if (This->vertex_uploader)
         u_upload_destroy(This->vertex_uploader);
@@ -856,6 +857,7 @@ NineDevice9_Reset( struct NineDevice9 *This,
 
     nine_pipe_context_clear(This);
     nine_state_clear(&This->state, TRUE);
+    nine_context_clear(&This->context);
 
     NineDevice9_SetDefaultState(This, TRUE);
     NineDevice9_SetRenderTarget(
index fd4272468cba7f72d30a25acb5d637a852b9a5c4..77a364a31a760ec6b4276396744d20716f0ee74a 100644 (file)
@@ -259,6 +259,7 @@ NineDevice9Ex_Reset( struct NineDevice9Ex *This,
 
     nine_pipe_context_clear((struct NineDevice9 *)This);
     nine_state_clear(&This->base.state, TRUE);
+    nine_context_clear(&This->base.context);
 
     NineDevice9_SetDefaultState((struct NineDevice9 *)This, TRUE);
     NineDevice9_SetRenderTarget(
index c01db01ce204c44ded60314521eb384a715d7fe8..c0f15d84c8f2f88d6e1333b37fc081faf0c13e2b 100644 (file)
@@ -1739,7 +1739,7 @@ nine_ff_get_ps(struct NineDevice9 *device)
             break;
         }
 
-        if (!state->texture[s] &&
+        if (!context->texture[s] &&
             ((state->ff.tex_stage[s][D3DTSS_COLORARG0] == D3DTA_TEXTURE &&
               used_c & 0x1) ||
              (state->ff.tex_stage[s][D3DTSS_COLORARG1] == D3DTA_TEXTURE &&
@@ -1784,8 +1784,8 @@ nine_ff_get_ps(struct NineDevice9 *device)
         }
         key.ts[s].resultarg = state->ff.tex_stage[s][D3DTSS_RESULTARG] == D3DTA_TEMP;
 
-        if (state->texture[s]) {
-            switch (state->texture[s]->base.type) {
+        if (context->texture[s]) {
+            switch (context->texture[s]->base.type) {
             case D3DRTYPE_TEXTURE:       key.ts[s].textarget = 1; break;
             case D3DRTYPE_VOLUMETEXTURE: key.ts[s].textarget = 2; break;
             case D3DRTYPE_CUBETEXTURE:   key.ts[s].textarget = 3; break;
index b309af53fd1cd672874415a2ed2e6377ed97d09e..a4d84a071f3028c1fcc11eb454aa874dd4d7b7fb 100644 (file)
@@ -719,24 +719,24 @@ update_vertex_buffers(struct NineDevice9 *device)
 }
 
 static inline boolean
-update_sampler_derived(struct nine_state *state, unsigned s)
+update_sampler_derived(struct nine_state *state, struct nine_context *context, unsigned s)
 {
     boolean changed = FALSE;
 
-    if (state->samp[s][NINED3DSAMP_SHADOW] != state->texture[s]->shadow) {
+    if (state->samp[s][NINED3DSAMP_SHADOW] != context->texture[s]->shadow) {
         changed = TRUE;
-        state->samp[s][NINED3DSAMP_SHADOW] = state->texture[s]->shadow;
+        state->samp[s][NINED3DSAMP_SHADOW] = context->texture[s]->shadow;
     }
 
     if (state->samp[s][NINED3DSAMP_CUBETEX] !=
-        (NineResource9(state->texture[s])->type == D3DRTYPE_CUBETEXTURE)) {
+        (NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE)) {
         changed = TRUE;
         state->samp[s][NINED3DSAMP_CUBETEX] =
-                NineResource9(state->texture[s])->type == D3DRTYPE_CUBETEXTURE;
+                NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE;
     }
 
     if (state->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
-        int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - state->texture[s]->managed.lod;
+        int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s]->managed.lod;
         if (lod < 0)
             lod = 0;
         if (state->samp[s][NINED3DSAMP_MINLOD] != lod) {
@@ -771,18 +771,18 @@ update_textures_and_samplers(struct NineDevice9 *device)
         const unsigned s = NINE_SAMPLER_PS(i);
         int sRGB;
 
-        if (!state->texture[s] && !(sampler_mask & (1 << i))) {
+        if (!context->texture[s] && !(sampler_mask & (1 << i))) {
             view[i] = NULL;
             continue;
         }
 
-        if (state->texture[s]) {
+        if (context->texture[s]) {
             sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
 
-            view[i] = NineBaseTexture9_GetSamplerView(state->texture[s], sRGB);
+            view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB);
             num_textures = i + 1;
 
-            if (update_sampler_derived(state, s) || (state->changed.sampler[s] & 0x05fe)) {
+            if (update_sampler_derived(state, context, s) || (state->changed.sampler[s] & 0x05fe)) {
                 state->changed.sampler[s] = 0;
                 commit_samplers = TRUE;
                 nine_convert_sampler_state(device->cso, s, state->samp[s]);
@@ -819,18 +819,18 @@ update_textures_and_samplers(struct NineDevice9 *device)
         const unsigned s = NINE_SAMPLER_VS(i);
         int sRGB;
 
-        if (!state->texture[s] && !(sampler_mask & (1 << i))) {
+        if (!context->texture[s] && !(sampler_mask & (1 << i))) {
             view[i] = NULL;
             continue;
         }
 
-        if (state->texture[s]) {
+        if (context->texture[s]) {
             sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
 
-            view[i] = NineBaseTexture9_GetSamplerView(state->texture[s], sRGB);
+            view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB);
             num_textures = i + 1;
 
-            if (update_sampler_derived(state, s) || (state->changed.sampler[s] & 0x05fe)) {
+            if (update_sampler_derived(state, context, s) || (state->changed.sampler[s] & 0x05fe)) {
                 state->changed.sampler[s] = 0;
                 commit_samplers = TRUE;
                 nine_convert_sampler_state(device->cso, s, state->samp[s]);
@@ -1124,9 +1124,10 @@ static void
 NineDevice9_ResolveZ( struct NineDevice9 *device )
 {
     struct nine_state *state = &device->state;
+    struct nine_context *context = &device->context;
     const struct util_format_description *desc;
     struct NineSurface9 *source = state->ds;
-    struct NineBaseTexture9 *destination = state->texture[0];
+    struct NineBaseTexture9 *destination = context->texture[0];
     struct pipe_resource *src, *dst;
     struct pipe_blit_info blit;
 
@@ -1234,6 +1235,8 @@ nine_context_set_texture(struct NineDevice9 *device,
     if (tex)
         context->samplers_shadow |= tex->shadow << Stage;
 
+    nine_bind(&context->texture[Stage], tex);
+
     state->changed.group |= NINE_STATE_TEXTURE;
 }
 
@@ -1266,7 +1269,7 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
                 continue;
             if (tex)
                 context->samplers_shadow |= tex->shadow << s;
-            /* nine_bind(&state->texture[s], src->texture[s]); Already bound by NineStateBlock9_Apply */
+            nine_bind(&context->texture[s], src->texture[s]);
         }
     }
 }
@@ -1791,6 +1794,15 @@ nine_state_clear(struct nine_state *state, const boolean device)
     }
 }
 
+void
+nine_context_clear(struct nine_context *context)
+{
+    unsigned i;
+
+    for (i = 0; i < NINE_MAX_SAMPLERS; ++i)
+        nine_bind(&context->texture[i], NULL);
+}
+
 void
 nine_state_init_sw(struct NineDevice9 *device)
 {
index 686f40175fe9729f35dc79dea8ef1abfbf17691b..71a5293e2bc43a48208fad8c44aa3b79780fd34a 100644 (file)
@@ -227,6 +227,8 @@ struct nine_context {
 
     DWORD rs[NINED3DRS_COUNT];
 
+    struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS];
+
     uint32_t samplers_shadow;
 
     uint8_t bound_samplers_mask_vs;
@@ -320,6 +322,7 @@ void nine_state_restore_non_cso(struct NineDevice9 *device);
 void nine_state_set_defaults(struct NineDevice9 *, const D3DCAPS9 *,
                              boolean is_reset);
 void nine_state_clear(struct nine_state *, const boolean device);
+void nine_context_clear(struct nine_context *);
 
 void nine_state_init_sw(struct NineDevice9 *device);
 void nine_state_prepare_draw_sw(struct NineDevice9 *device,
index 98d0b0360f506042ec83d175e0a01d7a84dc2b27..4c0b537b1bd4066128b4fc6578976f51bc28c61d 100644 (file)
@@ -81,7 +81,7 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
         while (m) {
             int s = ffs(m) - 1;
             m &= ~(1 << s);
-            samplers_ps1_types |= (state->texture[s] ? state->texture[s]->pstype : 1) << (s * 2);
+            samplers_ps1_types |= (context->texture[s] ? context->texture[s]->pstype : 1) << (s * 2);
         }
         key = samplers_ps1_types;
     } else {
index 4f5e9d7b8d3cd1fe3709648e9ca34c8ecfd5f4ec..d0063ed774a808b9b404a3d6710d8cc37e6ad047 100644 (file)
@@ -73,7 +73,7 @@ NineStateBlock9_dtor( struct NineStateBlock9 *This )
     struct nine_range *r;
     struct nine_range_pool *pool = &This->base.device->range_pool;
 
-    nine_state_clear(state, FALSE);
+    nine_state_clear(state, false);
 
     FREE(state->vs_const_f);
     FREE(state->ps_const_f);