st/nine: Do not use NineBaseTexture9 in nine_context
authorAxel Davy <axel.davy@ens.fr>
Mon, 31 Oct 2016 16:04:29 +0000 (17:04 +0100)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:22 +0000 (23:44 +0100)
Some fields are subject to modification outside of nine_context
(SetLod, etc).

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/basetexture9.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

index 6bcd0c9f2dff45637241f394c50e592d158f9dfb..f37dbb1d121e3d88865169b684bf712abc9c6ffe 100644 (file)
@@ -203,17 +203,6 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
         pipe_sampler_view_reference(&This->view[0], NULL);
         pipe_sampler_view_reference(&This->view[1], NULL);
 
-        if (This->bind_count) {
-            /* mark state dirty */
-            struct nine_state *state = &This->base.base.device->state;
-            struct nine_context *context = &This->base.base.device->context;
-            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)
-                    context->changed.group |= NINE_STATE_TEXTURE;
-        }
-
         /* Allocate a new resource */
         hr = NineBaseTexture9_CreatePipeResource(This, This->managed.lod_resident != -1);
         if (FAILED(hr))
@@ -378,6 +367,16 @@ NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
     if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
         This->dirty_mip = TRUE;
 
+    /* Set again the textures currently bound to update the texture data */
+    if (This->bind_count) {
+        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)
+                nine_context_set_texture(This->base.base.device, s, This);
+    }
+
     DBG("DONE, generate mip maps = %i\n", This->dirty_mip);
     return D3D_OK;
 }
index b18b00e4471cf366fffabccb5acb95e8f2cab5d5..a0a33cdc74a80a7f8ffc67271b1dabc8c8ce98e1 100644 (file)
@@ -1737,7 +1737,7 @@ nine_ff_get_ps(struct NineDevice9 *device)
             break;
         }
 
-        if (!context->texture[s] &&
+        if (!context->texture[s].enabled &&
             ((context->ff.tex_stage[s][D3DTSS_COLORARG0] == D3DTA_TEXTURE &&
               used_c & 0x1) ||
              (context->ff.tex_stage[s][D3DTSS_COLORARG1] == D3DTA_TEXTURE &&
@@ -1782,8 +1782,8 @@ nine_ff_get_ps(struct NineDevice9 *device)
         }
         key.ts[s].resultarg = context->ff.tex_stage[s][D3DTSS_RESULTARG] == D3DTA_TEMP;
 
-        if (context->texture[s]) {
-            switch (context->texture[s]->base.type) {
+        if (context->texture[s].enabled) {
+            switch (context->texture[s].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 226946031d617c04b1466c69f49b724a38b3d7d3..928d82050c92a56807b0f11430452b25528af607 100644 (file)
@@ -656,20 +656,20 @@ update_sampler_derived(struct nine_context *context, unsigned s)
 {
     boolean changed = FALSE;
 
-    if (context->samp[s][NINED3DSAMP_SHADOW] != context->texture[s]->shadow) {
+    if (context->samp[s][NINED3DSAMP_SHADOW] != context->texture[s].shadow) {
         changed = TRUE;
-        context->samp[s][NINED3DSAMP_SHADOW] = context->texture[s]->shadow;
+        context->samp[s][NINED3DSAMP_SHADOW] = context->texture[s].shadow;
     }
 
     if (context->samp[s][NINED3DSAMP_CUBETEX] !=
-        (NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE)) {
+        (context->texture[s].type == D3DRTYPE_CUBETEXTURE)) {
         changed = TRUE;
         context->samp[s][NINED3DSAMP_CUBETEX] =
-                NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE;
+                context->texture[s].type == D3DRTYPE_CUBETEXTURE;
     }
 
     if (context->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
-        int lod = context->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s]->managed.lod;
+        int lod = context->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s].lod;
         if (lod < 0)
             lod = 0;
         if (context->samp[s][NINED3DSAMP_MINLOD] != lod) {
@@ -703,15 +703,15 @@ update_textures_and_samplers(struct NineDevice9 *device)
         const unsigned s = NINE_SAMPLER_PS(i);
         int sRGB;
 
-        if (!context->texture[s] && !(sampler_mask & (1 << i))) {
+        if (!context->texture[s].enabled && !(sampler_mask & (1 << i))) {
             view[i] = NULL;
             continue;
         }
 
-        if (context->texture[s]) {
+        if (context->texture[s].enabled) {
             sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
 
-            view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB);
+            view[i] = context->texture[s].view[sRGB];
             num_textures = i + 1;
 
             if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
@@ -751,15 +751,15 @@ update_textures_and_samplers(struct NineDevice9 *device)
         const unsigned s = NINE_SAMPLER_VS(i);
         int sRGB;
 
-        if (!context->texture[s] && !(sampler_mask & (1 << i))) {
+        if (!context->texture[s].enabled && !(sampler_mask & (1 << i))) {
             view[i] = NULL;
             continue;
         }
 
-        if (context->texture[s]) {
+        if (context->texture[s].enabled) {
             sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
 
-            view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB);
+            view[i] = context->texture[s].view[sRGB];
             num_textures = i + 1;
 
             if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
@@ -1043,18 +1043,17 @@ NineDevice9_ResolveZ( struct NineDevice9 *device )
     struct nine_context *context = &device->context;
     const struct util_format_description *desc;
     struct NineSurface9 *source = context->ds;
-    struct NineBaseTexture9 *destination = context->texture[0];
     struct pipe_resource *src, *dst;
     struct pipe_blit_info blit;
 
     DBG("RESZ resolve\n");
 
-    if (!source || !destination ||
-        destination->base.type != D3DRTYPE_TEXTURE)
+    if (!source || !context->texture[0].enabled ||
+        context->texture[0].type != D3DRTYPE_TEXTURE)
         return;
 
     src = source->base.resource;
-    dst = destination->base.resource;
+    dst = context->texture[0].resource;
 
     if (!src || !dst)
         return;
@@ -1146,10 +1145,31 @@ nine_context_set_texture(struct NineDevice9 *device,
     struct nine_context *context = &device->context;
 
     context->samplers_shadow &= ~(1 << Stage);
-    if (tex)
+    /* For managed pool, the data can be initially incomplete.
+     * In that case, the texture is rebound later
+     * (in NineBaseTexture9_Validate/NineBaseTexture9_UploadSelf). */
+    if (tex && tex->base.resource) {
         context->samplers_shadow |= tex->shadow << Stage;
-
-    nine_bind(&context->texture[Stage], tex);
+        context->texture[Stage].enabled = TRUE;
+        context->texture[Stage].shadow = tex->shadow;
+        context->texture[Stage].lod = tex->managed.lod;
+        context->texture[Stage].type = tex->base.type;
+        context->texture[Stage].pstype = tex->pstype;
+        pipe_resource_reference(&context->texture[Stage].resource,
+                                tex->base.resource);
+        pipe_sampler_view_reference(&context->texture[Stage].view[0],
+                                    NineBaseTexture9_GetSamplerView(tex, 0));
+        pipe_sampler_view_reference(&context->texture[Stage].view[1],
+                                    NineBaseTexture9_GetSamplerView(tex, 1));
+    } else {
+        context->texture[Stage].enabled = FALSE;
+        pipe_resource_reference(&context->texture[Stage].resource,
+                                NULL);
+        pipe_sampler_view_reference(&context->texture[Stage].view[0],
+                                    NULL);
+        pipe_sampler_view_reference(&context->texture[Stage].view[1],
+                                    NULL);
+    }
 
     context->changed.group |= NINE_STATE_TEXTURE;
 }
@@ -1601,15 +1621,11 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
         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(&context->texture[s], src->texture[s]);
+            nine_context_set_texture(device, s, tex);
         }
     }
 
@@ -2424,8 +2440,15 @@ nine_context_clear(struct NineDevice9 *device)
         pipe_resource_reference(&context->vtxbuf[i].buffer, NULL);
     pipe_resource_reference(&context->idxbuf.buffer, NULL);
 
-    for (i = 0; i < NINE_MAX_SAMPLERS; ++i)
-        nine_bind(&context->texture[i], NULL);
+    for (i = 0; i < NINE_MAX_SAMPLERS; ++i) {
+        context->texture[i].enabled = FALSE;
+        pipe_resource_reference(&context->texture[i].resource,
+                                NULL);
+        pipe_sampler_view_reference(&context->texture[i].view[0],
+                                    NULL);
+        pipe_sampler_view_reference(&context->texture[i].view[1],
+                                    NULL);
+    }
 }
 
 void
index 11a213e3066da6b4a190a9a6bcaa7938d9505dfe..42d45d959b95f75ffab0ca789eb3b967841fe6d6 100644 (file)
@@ -277,7 +277,15 @@ struct nine_context {
 
     DWORD rs[NINED3DRS_COUNT];
 
-    struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS];
+    struct {
+        BOOL enabled;
+        BOOL shadow;
+        DWORD lod;
+        D3DRESOURCETYPE type;
+        struct pipe_resource *resource;
+        struct pipe_sampler_view *view[2];
+        uint8_t pstype;
+    } texture[NINE_MAX_SAMPLERS];
 
     DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
 
index 67a18f20c42eb0bcb03ff12455534a08e4b87a6e..accd00a6a8c3ec24f9df3367f69e341f1c9fc88c 100644 (file)
@@ -80,7 +80,7 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
         while (m) {
             int s = ffs(m) - 1;
             m &= ~(1 << s);
-            samplers_ps1_types |= (context->texture[s] ? context->texture[s]->pstype : 1) << (s * 2);
+            samplers_ps1_types |= (context->texture[s].enabled ? context->texture[s].pstype : 1) << (s * 2);
         }
         key = samplers_ps1_types;
     } else {