From: Icecream95 Date: Thu, 16 Jul 2020 02:16:11 +0000 (+1200) Subject: pan/mdg: Do per-sample framebuffer loads X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c20d166b4ecbde8c5dcf7fbbeb7860c6be859a69;p=mesa.git pan/mdg: Do per-sample framebuffer loads 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 Part-of: --- diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py index a7d9d73369e..2b7614ea353 100644 --- a/src/compiler/nir/nir_intrinsics.py +++ b/src/compiler/nir/nir_intrinsics.py @@ -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 # src[] = { sampler_index } diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 085edc5d0d4..5a7afec4008 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -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; diff --git a/src/panfrost/util/pan_lower_framebuffer.c b/src/panfrost/util/pan_lower_framebuffer.c index 08f56ce6589..1b733687b33 100644 --- a/src/panfrost/util/pan_lower_framebuffer.c +++ b/src/panfrost/util/pan_lower_framebuffer.c @@ -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);