freedreno: fence_server_sync() fixes
[mesa.git] / src / gallium / drivers / freedreno / freedreno_state.c
index a748bfec82cd53a2e83a091c7d8947299673ac2b..9e1c1a1776c431db6c3e65e3f45db89a509e4924 100644 (file)
@@ -104,7 +104,7 @@ fd_set_constant_buffer(struct pipe_context *pctx,
 
        util_copy_constant_buffer(&so->cb[index], cb);
 
-       /* Note that the state tracker can unbind constant buffers by
+       /* Note that gallium frontends can unbind constant buffers by
         * passing NULL here.
         */
        if (unlikely(!cb)) {
@@ -115,6 +115,8 @@ fd_set_constant_buffer(struct pipe_context *pctx,
        so->enabled_mask |= 1 << index;
        ctx->dirty_shader[shader] |= FD_DIRTY_SHADER_CONST;
        ctx->dirty |= FD_DIRTY_CONST;
+
+       fd_resource_set_usage(cb->buffer, FD_DIRTY_CONST);
 }
 
 static void
@@ -146,6 +148,8 @@ fd_set_shader_buffers(struct pipe_context *pctx,
                        buf->buffer_size = buffers[i].buffer_size;
                        pipe_resource_reference(&buf->buffer, buffers[i].buffer);
 
+                       fd_resource_set_usage(buffers[i].buffer, FD_DIRTY_SSBO);
+
                        so->enabled_mask |= BIT(n);
                } else {
                        pipe_resource_reference(&buf->buffer, NULL);
@@ -153,6 +157,7 @@ fd_set_shader_buffers(struct pipe_context *pctx,
        }
 
        ctx->dirty_shader[shader] |= FD_DIRTY_SHADER_SSBO;
+       ctx->dirty |= FD_DIRTY_SSBO;
 }
 
 void
@@ -180,10 +185,12 @@ fd_set_shader_images(struct pipe_context *pctx,
                        mask |= BIT(n);
                        util_copy_image_view(buf, &images[i]);
 
-                       if (buf->resource)
+                       if (buf->resource) {
+                               fd_resource_set_usage(buf->resource, FD_DIRTY_IMAGE);
                                so->enabled_mask |= BIT(n);
-                       else
+                       } else {
                                so->enabled_mask &= ~BIT(n);
+                       }
                }
        } else {
                mask = (BIT(count) - 1) << start;
@@ -199,6 +206,7 @@ fd_set_shader_images(struct pipe_context *pctx,
        }
 
        ctx->dirty_shader[shader] |= FD_DIRTY_SHADER_IMAGE;
+       ctx->dirty |= FD_DIRTY_IMAGE;
 }
 
 static void
@@ -212,6 +220,8 @@ fd_set_framebuffer_state(struct pipe_context *pctx,
                framebuffer->width, framebuffer->height,
                framebuffer->layers, framebuffer->samples);
 
+       fd_context_switch_from(ctx);
+
        cso = &ctx->framebuffer;
 
        if (util_framebuffer_state_equal(cso, framebuffer))
@@ -348,7 +358,15 @@ fd_set_vertex_buffers(struct pipe_context *pctx,
        util_set_vertex_buffers_mask(so->vb, &so->enabled_mask, vb, start_slot, count);
        so->count = util_last_bit(so->enabled_mask);
 
+       if (!vb)
+               return;
+
        ctx->dirty |= FD_DIRTY_VTXBUF;
+
+       for (unsigned i = 0; i < count; i++) {
+               assert(!vb[i].is_user_buffer);
+               fd_resource_set_usage(vb[i].buffer.resource, FD_DIRTY_VTXBUF);
+       }
 }
 
 static void
@@ -379,10 +397,17 @@ fd_rasterizer_state_bind(struct pipe_context *pctx, void *hwcso)
 {
        struct fd_context *ctx = fd_context(pctx);
        struct pipe_scissor_state *old_scissor = fd_context_get_scissor(ctx);
+       bool discard = ctx->rasterizer && ctx->rasterizer->rasterizer_discard;
 
        ctx->rasterizer = hwcso;
        ctx->dirty |= FD_DIRTY_RASTERIZER;
 
+       if (ctx->rasterizer && ctx->rasterizer->scissor) {
+               ctx->current_scissor = &ctx->scissor;
+       } else {
+               ctx->current_scissor = &ctx->disabled_scissor;
+       }
+
        /* if scissor enable bit changed we need to mark scissor
         * state as dirty as well:
         * NOTE: we can do a shallow compare, since we only care
@@ -390,6 +415,9 @@ fd_rasterizer_state_bind(struct pipe_context *pctx, void *hwcso)
         */
        if (old_scissor != fd_context_get_scissor(ctx))
                ctx->dirty |= FD_DIRTY_SCISSOR;
+
+       if (ctx->rasterizer && (discard != ctx->rasterizer->rasterizer_discard))
+               ctx->dirty |= FD_DIRTY_RASTERIZER_DISCARD;
 }
 
 static void
@@ -562,10 +590,6 @@ fd_set_global_binding(struct pipe_context *pctx,
 
                for (unsigned i = 0; i < count; i++) {
                        unsigned n = i + first;
-                       if (so->buf[n]) {
-                               struct fd_resource *rsc = fd_resource(so->buf[n]);
-                               fd_bo_put_iova(rsc->bo);
-                       }
                        pipe_resource_reference(&so->buf[n], NULL);
                }
 
@@ -601,7 +625,8 @@ fd_state_init(struct pipe_context *pctx)
        pctx->bind_depth_stencil_alpha_state = fd_zsa_state_bind;
        pctx->delete_depth_stencil_alpha_state = fd_zsa_state_delete;
 
-       pctx->create_vertex_elements_state = fd_vertex_state_create;
+       if (!pctx->create_vertex_elements_state)
+               pctx->create_vertex_elements_state = fd_vertex_state_create;
        pctx->delete_vertex_elements_state = fd_vertex_state_delete;
        pctx->bind_vertex_elements_state = fd_vertex_state_bind;