radeonsi: use a compiler queue with a low priority for optimized shaders
[mesa.git] / src / gallium / drivers / vc4 / vc4_blit.c
index 16dcece1ea186a0f700a1a90383dbc5000839dee..1e056568acb6bc2edd6ad4841447b2fb20a4499c 100644 (file)
@@ -51,11 +51,8 @@ static bool
 vc4_tile_blit(struct pipe_context *pctx, const struct pipe_blit_info *info)
 {
         struct vc4_context *vc4 = vc4_context(pctx);
-        bool old_msaa = vc4->msaa;
-        int old_tile_width = vc4->tile_width;
-        int old_tile_height = vc4->tile_height;
-        bool msaa = (info->src.resource->nr_samples ||
-                     info->dst.resource->nr_samples);
+        bool msaa = (info->src.resource->nr_samples > 1 ||
+                     info->dst.resource->nr_samples > 1);
         int tile_width = msaa ? 32 : 64;
         int tile_height = msaa ? 32 : 64;
 
@@ -88,10 +85,31 @@ vc4_tile_blit(struct pipe_context *pctx, const struct pipe_blit_info *info)
                 return false;
         }
 
-        if (info->dst.resource->format != info->src.resource->format)
+        /* VC4_PACKET_LOAD_TILE_BUFFER_GENERAL uses the
+         * VC4_PACKET_TILE_RENDERING_MODE_CONFIG's width (determined by our
+         * destination surface) to determine the stride.  This may be wrong
+         * when reading from texture miplevels > 0, which are stored in
+         * POT-sized areas.  For MSAA, the tile addresses are computed
+         * explicitly by the RCL, but still use the destination width to
+         * determine the stride (which could be fixed by explicitly supplying
+         * it in the ABI).
+         */
+        struct vc4_resource *rsc = vc4_resource(info->src.resource);
+
+        uint32_t stride;
+
+        if (info->src.resource->nr_samples > 1)
+                stride = align(dst_surface_width, 32) * 4 * rsc->cpp;
+        else if (rsc->slices[info->src.level].tiling == VC4_TILING_FORMAT_T)
+                stride = align(dst_surface_width * rsc->cpp, 128);
+        else
+                stride = align(dst_surface_width * rsc->cpp, 16);
+
+        if (stride != rsc->slices[info->src.level].stride)
                 return false;
 
-        vc4_flush(pctx);
+        if (info->dst.resource->format != info->src.resource->format)
+                return false;
 
         if (false) {
                 fprintf(stderr, "RCL blit from %d,%d to %d,%d (%d,%d)\n",
@@ -108,32 +126,34 @@ vc4_tile_blit(struct pipe_context *pctx, const struct pipe_blit_info *info)
         struct pipe_surface *src_surf =
                 vc4_get_blit_surface(pctx, info->src.resource, info->src.level);
 
-        pipe_surface_reference(&vc4->color_read, src_surf);
-        pipe_surface_reference(&vc4->color_write,
-                               dst_surf->texture->nr_samples ? NULL : dst_surf);
-        pipe_surface_reference(&vc4->msaa_color_write,
-                               dst_surf->texture->nr_samples ? dst_surf : NULL);
-        pipe_surface_reference(&vc4->zs_read, NULL);
-        pipe_surface_reference(&vc4->zs_write, NULL);
-        pipe_surface_reference(&vc4->msaa_zs_write, NULL);
-
-        vc4->draw_min_x = info->dst.box.x;
-        vc4->draw_min_y = info->dst.box.y;
-        vc4->draw_max_x = info->dst.box.x + info->dst.box.width;
-        vc4->draw_max_y = info->dst.box.y + info->dst.box.height;
-        vc4->draw_width = dst_surf->width;
-        vc4->draw_height = dst_surf->height;
-
-        vc4->tile_width = tile_width;
-        vc4->tile_height = tile_height;
-        vc4->msaa = msaa;
-        vc4->needs_flush = true;
-
-        vc4_job_submit(vc4);
-
-        vc4->msaa = old_msaa;
-        vc4->tile_width = old_tile_width;
-        vc4->tile_height = old_tile_height;
+        vc4_flush_jobs_reading_resource(vc4, info->src.resource);
+
+        struct vc4_job *job = vc4_get_job(vc4, dst_surf, NULL);
+        pipe_surface_reference(&job->color_read, src_surf);
+
+        /* If we're resolving from MSAA to single sample, we still need to run
+         * the engine in MSAA mode for the load.
+         */
+        if (!job->msaa && info->src.resource->nr_samples > 1) {
+                job->msaa = true;
+                job->tile_width = 32;
+                job->tile_height = 32;
+        }
+
+        job->draw_min_x = info->dst.box.x;
+        job->draw_min_y = info->dst.box.y;
+        job->draw_max_x = info->dst.box.x + info->dst.box.width;
+        job->draw_max_y = info->dst.box.y + info->dst.box.height;
+        job->draw_width = dst_surf->width;
+        job->draw_height = dst_surf->height;
+
+        job->tile_width = tile_width;
+        job->tile_height = tile_height;
+        job->msaa = msaa;
+        job->needs_flush = true;
+        job->resolve |= PIPE_CLEAR_COLOR;
+
+        vc4_job_submit(vc4, job);
 
         pipe_surface_reference(&dst_surf, NULL);
         pipe_surface_reference(&src_surf, NULL);
@@ -141,18 +161,9 @@ vc4_tile_blit(struct pipe_context *pctx, const struct pipe_blit_info *info)
         return true;
 }
 
-static bool
-vc4_render_blit(struct pipe_context *ctx, struct pipe_blit_info *info)
+void
+vc4_blitter_save(struct vc4_context *vc4)
 {
-        struct vc4_context *vc4 = vc4_context(ctx);
-
-        if (!util_blitter_is_blit_supported(vc4->blitter, info)) {
-                fprintf(stderr, "blit unsupported %s -> %s\n",
-                    util_format_short_name(info->src.resource->format),
-                    util_format_short_name(info->dst.resource->format));
-                return false;
-        }
-
         util_blitter_save_vertex_buffer_slot(vc4->blitter, vc4->vertexbuf.vb);
         util_blitter_save_vertex_elements(vc4->blitter, vc4->vtx);
         util_blitter_save_vertex_shader(vc4->blitter, vc4->prog.bind_vs);
@@ -170,7 +181,21 @@ vc4_render_blit(struct pipe_context *ctx, struct pipe_blit_info *info)
                         (void **)vc4->fragtex.samplers);
         util_blitter_save_fragment_sampler_views(vc4->blitter,
                         vc4->fragtex.num_textures, vc4->fragtex.textures);
+}
+
+static bool
+vc4_render_blit(struct pipe_context *ctx, struct pipe_blit_info *info)
+{
+        struct vc4_context *vc4 = vc4_context(ctx);
+
+        if (!util_blitter_is_blit_supported(vc4->blitter, info)) {
+                fprintf(stderr, "blit unsupported %s -> %s\n",
+                    util_format_short_name(info->src.resource->format),
+                    util_format_short_name(info->dst.resource->format));
+                return false;
+        }
 
+        vc4_blitter_save(vc4);
         util_blitter_blit(vc4->blitter, info);
 
         return true;