pan/mdg: Do per-sample framebuffer loads
authorIcecream95 <ixn@keemail.me>
Thu, 16 Jul 2020 02:16:11 +0000 (14:16 +1200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 17 Jul 2020 14:34:47 +0000 (14:34 +0000)
EXT_shader_framebuffer_fetch requires the fetched value to be per-sample, so we
need to load the sample id when in a fragment shader.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5930>

src/compiler/nir/nir_intrinsics.py
src/panfrost/midgard/midgard_compile.c
src/panfrost/util/pan_lower_framebuffer.c

index a7d9d73369ed41e10fb787c1822857d252fb12c7..2b7614ea353dd7b85dc1a65d433a750ec01ce82b 100644 (file)
@@ -866,7 +866,7 @@ intrinsic("bindless_resource_ir3", [1], dest_comp=1, indices=[DESC_SET], flags=[
 # src[] = { value }
 store("raw_output_pan", [], [])
 store("combined_output_pan", [1, 1, 1], [BASE, COMPONENT])
-load("raw_output_pan", [], [BASE], [CAN_ELIMINATE, CAN_REORDER])
+load("raw_output_pan", [1], [BASE], [CAN_ELIMINATE, CAN_REORDER])
 
 # Loads the sampler paramaters <min_lod, max_lod, lod_bias>
 # src[] = { sampler_index }
index 085edc5d0d4d5acff99b09aa754cf43f410c82b8..5a7afec40088d94c185ba2222d3128ae4d0e76bc 100644 (file)
@@ -1822,6 +1822,14 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 
                 ld.load_store.arg_2 = output_load_rt_addr(ctx->nir, instr);
 
+                if (nir_src_is_const(instr->src[0])) {
+                        ld.load_store.arg_1 = nir_src_as_uint(instr->src[0]);
+                } else {
+                        ld.load_store.varying_parameters = 2;
+                        ld.src[1] = nir_src_index(ctx, &instr->src[0]);
+                        ld.src_types[1] = nir_type_int32;
+                }
+
                 if (ctx->quirks & MIDGARD_OLD_BLEND) {
                         ld.load_store.op = midgard_op_ld_color_buffer_32u_old;
                         ld.load_store.address = 16;
index 08f56ce658964916e5a6c628a269c5b4b1a2e59c..1b733687b33c4dc6da6180d3e496c3a4b01cf991 100644 (file)
@@ -660,16 +660,23 @@ pan_lower_fb_store(nir_shader *shader,
         nir_builder_instr_insert(b, &new->instr);
 }
 
+static nir_ssa_def *
+pan_sample_id(nir_builder *b, int sample)
+{
+        return (sample >= 0) ? nir_imm_int(b, sample) : nir_load_sample_id(b);
+}
+
 static void
 pan_lower_fb_load(nir_shader *shader,
                 nir_builder *b,
                 nir_intrinsic_instr *intr,
                 const struct util_format_description *desc,
-                unsigned base, unsigned quirks)
+                unsigned base, int sample, unsigned quirks)
 {
         nir_intrinsic_instr *new = nir_intrinsic_instr_create(shader,
                        nir_intrinsic_load_raw_output_pan);
         new->num_components = 4;
+        new->src[0] = nir_src_for_ssa(pan_sample_id(b, sample));
 
         nir_intrinsic_set_base(new, base);
 
@@ -765,6 +772,12 @@ pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
                                 if (fmt_class == PAN_FORMAT_NATIVE)
                                         continue;
 
+                                /* EXT_shader_framebuffer_fetch requires
+                                 * per-sample loads.
+                                 * MSAA blend shaders are not yet handled, so
+                                 * for now always load sample 0. */
+                                int sample = is_blend ? 0 : -1;
+
                                 nir_builder b;
                                 nir_builder_init(&b, func->impl);
 
@@ -773,7 +786,7 @@ pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
                                         pan_lower_fb_store(shader, &b, intr, desc, quirks);
                                 } else {
                                         b.cursor = nir_after_instr(instr);
-                                        pan_lower_fb_load(shader, &b, intr, desc, base, quirks);
+                                        pan_lower_fb_load(shader, &b, intr, desc, base, sample, quirks);
                                 }
 
                                 nir_instr_remove(instr);