From d987419d8a4c2233beec19ea00bee9533f826ea1 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 6 Jan 2022 11:03:36 +0200 Subject: [PATCH] anv: limit compiler valid color outputs using NIR variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a test from the vkd3d-proton test_dual_source_blending_dxbc test which asserts in the backend with : brw_fs_visitor.cpp:716: void fs_visitor::emit_fb_writes(): Assertion `!prog_data->dual_src_blend || key->nr_color_regions == 1' failed. This is because there is 2 color attachments provided by the renderpass so we initially set nr_color_regions = 2. But once we've parsed the shader, we can see it's only using one output (with dual source color blending). This change looks at the output variables to update the valid output variables. Signed-off-by: Lionel Landwerlin Reviewed-by: Tapani Pälli Cc: mesa-stable Part-of: (cherry picked from commit 07bc6b7ed9e27ddfee558b3a5216d7a044dd3abe) --- .pick_status.json | 2 +- src/intel/vulkan/anv_pipeline.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index ab2009b83be..c580ee9a4b3 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1057,7 +1057,7 @@ "description": "anv: limit compiler valid color outputs using NIR variables", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 1b5a53544e5..f86ce8ec034 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -1157,6 +1157,24 @@ anv_pipeline_link_fs(const struct brw_compiler *compiler, if (deleted_output) nir_fixup_deref_modes(stage->nir); + /* Initially the valid outputs value is based off the renderpass color + * attachments (see populate_wm_prog_key()), now that we've potentially + * deleted variables that map to unused attachments, we need to update the + * valid outputs for the backend compiler based on what output variables + * are actually used. */ + stage->key.wm.color_outputs_valid = 0; + nir_foreach_shader_out_variable_safe(var, stage->nir) { + if (var->data.location < FRAG_RESULT_DATA0) + continue; + + const unsigned rt = var->data.location - FRAG_RESULT_DATA0; + const unsigned array_len = + glsl_type_is_array(var->type) ? glsl_get_length(var->type) : 1; + assert(rt + array_len <= MAX_RTS); + + stage->key.wm.color_outputs_valid |= BITFIELD_RANGE(rt, array_len); + } + /* We stored the number of subpass color attachments in nr_color_regions * when calculating the key for caching. Now that we've computed the bind * map, we can reduce this to the actual max before we go into the back-end