v3d: Don't forget to flush writes to UBOs.
authorEric Anholt <eric@anholt.net>
Thu, 6 Dec 2018 01:10:15 +0000 (17:10 -0800)
committerEric Anholt <eric@anholt.net>
Sat, 8 Dec 2018 00:48:23 +0000 (16:48 -0800)
If someone did TF into a UBO, we might have left the TF job un-flushed at
the point of reading.

src/gallium/drivers/v3d/v3d_context.h
src/gallium/drivers/v3d/v3dx_draw.c

index d62dd229ef270379000570210e86e95a25b0f3ea..4db422b5755750d4902432e1db9c1d5c23757fe2 100644 (file)
@@ -459,6 +459,9 @@ struct v3d_blend_state {
                 fprintf(stderr, __VA_ARGS__);           \
 } while (0)
 
+#define foreach_bit(b, mask)                                            \
+        for (uint32_t _m = (mask), b; _m && ({(b) = u_bit_scan(&_m); 1;});)
+
 static inline struct v3d_context *
 v3d_context(struct pipe_context *pcontext)
 {
index 519aa9157d5718fdc2a6648de604704790d69268..ca0a1ab39c2f8f28298fe0c2f9d979565079c85d 100644 (file)
@@ -119,18 +119,26 @@ v3d_start_draw(struct v3d_context *v3d)
 }
 
 static void
-v3d_predraw_check_textures(struct pipe_context *pctx,
-                           struct v3d_texture_stateobj *stage_tex)
+v3d_predraw_check_stage_inputs(struct pipe_context *pctx,
+                               enum pipe_shader_type s)
 {
         struct v3d_context *v3d = v3d_context(pctx);
 
-        for (int i = 0; i < stage_tex->num_textures; i++) {
-                struct pipe_sampler_view *view = stage_tex->textures[i];
+        /* Flush writes to textures we're sampling. */
+        for (int i = 0; i < v3d->tex[s].num_textures; i++) {
+                struct pipe_sampler_view *view = v3d->tex[s].textures[i];
                 if (!view)
                         continue;
 
                 v3d_flush_jobs_writing_resource(v3d, view->texture);
         }
+
+        /* Flush writes to UBOs. */
+        foreach_bit(i, v3d->constbuf[s].enabled_mask) {
+                struct pipe_constant_buffer *cb = &v3d->constbuf[s].cb[i];
+                if (cb->buffer)
+                        v3d_flush_jobs_writing_resource(v3d, cb->buffer);
+        }
 }
 
 static void
@@ -436,7 +444,7 @@ v3d_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
          * that we read from.
          */
         for (int s = 0; s < PIPE_SHADER_TYPES; s++)
-                v3d_predraw_check_textures(pctx, &v3d->tex[s]);
+                v3d_predraw_check_stage_inputs(pctx, s);
 
         struct v3d_job *job = v3d_get_job_for_fbo(v3d);