From e9ada4c0a2ebe11a4a8b3bf08fd12a0f76d56c9a Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 5 Jan 2024 10:05:03 +0100 Subject: [PATCH] panfrost: add support for forcing sample-counts This implements a D3D11-style forcing of the sample-counts, which will be used by the line-smoothing code we're about to add. Even though we don't actually use the single-sample mode, I left it in for completeness, as it's documented in the TRM. Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/lib/pan_desc.c | 24 ++++++++++++++++++++++-- src/panfrost/lib/pan_desc.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/panfrost/lib/pan_desc.c b/src/panfrost/lib/pan_desc.c index 575d344cbc9..69fe8e1e30f 100644 --- a/src/panfrost/lib/pan_desc.c +++ b/src/panfrost/lib/pan_desc.c @@ -732,8 +732,28 @@ GENX(pan_emit_fbd)(const struct panfrost_device *dev, cfg.z_clear = fb->zs.clear_value.depth; cfg.s_clear = fb->zs.clear_value.stencil; cfg.color_buffer_allocation = cbuf_allocation; - cfg.sample_count = fb->nr_samples; - cfg.sample_pattern = pan_sample_pattern(fb->nr_samples); + + /* The force_samples setting dictates the sample-count that is used + * for rasterization, and works like D3D11's ForcedSampleCount feature: + * + * - If force_samples == 0: Let nr_samples dictate sample count + * - If force_samples == 1: force single-sampled rasterization + * - If force_samples >= 1: force multi-sampled rasterization + * + * This can be used to read SYSTEM_VALUE_SAMPLE_MASK_IN from the + * fragment shader, even when performing single-sampled rendering. + */ + if (!fb->force_samples) { + cfg.sample_count = fb->nr_samples; + cfg.sample_pattern = pan_sample_pattern(fb->nr_samples); + } else if (fb->force_samples == 1) { + cfg.sample_count = fb->nr_samples; + cfg.sample_pattern = pan_sample_pattern(1); + } else { + cfg.sample_count = 1; + cfg.sample_pattern = pan_sample_pattern(fb->force_samples); + } + cfg.z_write_enable = (fb->zs.view.zs && !fb->zs.discard.z); cfg.s_write_enable = (fb->zs.view.s && !fb->zs.discard.s); cfg.has_zs_crc_extension = has_zs_crc_ext; diff --git a/src/panfrost/lib/pan_desc.h b/src/panfrost/lib/pan_desc.h index 74e793e2f51..5cdb87ce43d 100644 --- a/src/panfrost/lib/pan_desc.h +++ b/src/panfrost/lib/pan_desc.h @@ -111,6 +111,7 @@ struct pan_fb_info { unsigned minx, miny, maxx, maxy; } extent; unsigned nr_samples; + unsigned force_samples; /* samples used for rasterization */ unsigned rt_count; struct pan_fb_color_attachment rts[8]; struct pan_fb_zs_attachment zs;