<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 2, 2019 at 5:46 AM Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>><br>
<br>
There tests in CTS for for alpha to coverage without a color attachment.<br>
First the test draws a primitive with alpha 0 and a subpass with only<br>
a depth buffer. No writes to a depth buffer are expected. Then a<br>
second draw with a color buffer and the same depth buffer is done to<br>
verify the depth buffer still has the original clear values.<br>
<br>
This behavior is not explicitly forbidden by the Vulkan spec, so<br>
it seems it is allowed.<br>
<br>
When there is no color attachment for a given output, we discard it<br>
so at the end we have an FS assembly like:<br>
<br>
Native code for unnamed fragment shader (null)<br>
SIMD16 shader: 1 instructions. 0 loops. 4 cycles. 0:0 spills:fills.<br>
Promoted 0 constants. Compacted 16 to 16 bytes (0%)<br>
  START B0 (4 cycles)<br>
sendc(16)       null<1>UW       g120<0,1,0>F    0x90031000<br>
<br>
render MsgDesc: RT write SIMD16 LastRT Surface = 0 mlen 8 rlen 0 {<br>
align1 1H EOT };<br>
<br>
As g120 is not initialized, we see random writes to the depth buffer<br>
due to the alphaToCoverage enablement. This patch fixes that by<br>
keeping the output in that case.<br>
<br>
v2:<br>
 - No need to create a null render target, the driver is already<br>
   doing that (Jason)<br>
 - Simplified code a bit (Iago)<br>
<br>
Fixes the following CTS tests:<br>
dEQP-VK.pipeline.multisample.alpha_to_coverage_no_color_attachment.*<br>
<br>
Signed-off-by: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>><br>
Signed-off-by: Iago Toral Quiroga <<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>><br>
---<br>
 src/intel/vulkan/anv_pipeline.c | 25 ++++++++++++++++++-------<br>
 1 file changed, 18 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c<br>
index b9c9bfd7598..07f1a939e43 100644<br>
--- a/src/intel/vulkan/anv_pipeline.c<br>
+++ b/src/intel/vulkan/anv_pipeline.c<br>
@@ -808,7 +808,9 @@ anv_pipeline_compile_gs(const struct brw_compiler *compiler,<br>
<br>
 static void<br>
 anv_pipeline_link_fs(const struct brw_compiler *compiler,<br>
-                     struct anv_pipeline_stage *stage)<br>
+                     struct anv_pipeline_stage *stage,<br>
+                     bool has_depth_stencil_att,<br>
+                     bool has_alpha_to_coverage)<br>
 {<br>
    unsigned num_rts = 0;<br>
    const int max_rt = FRAG_RESULT_DATA7 - FRAG_RESULT_DATA0 + 1;<br>
@@ -859,11 +861,17 @@ anv_pipeline_link_fs(const struct brw_compiler *compiler,<br>
       const unsigned rt = var->data.location - FRAG_RESULT_DATA0;<br>
       if (rt >= MAX_RTS ||<br>
           !(stage->key.wm.color_outputs_valid & (1 << rt))) {<br>
-         /* Unused or out-of-bounds, throw it away */<br>
-         deleted_output = true;<br>
-         var->data.mode = nir_var_function_temp;<br>
-         exec_node_remove(&var->node);<br>
-         exec_list_push_tail(&impl->locals, &var->node);<br>
+         /* Unused or out-of-bounds, throw it away. The exception is depth-only<br>
+          * rendering with alphaToCoverage, as in this case we need to keep the<br>
+          * fragment output in location 0, which we will bind later to a null<br>
+          * render target.<br>
+          */<br>
+         if (rt != 0 || !has_alpha_to_coverage || !has_depth_stencil_att) {<br>
+            deleted_output = true;<br>
+            var->data.mode = nir_var_function_temp;<br>
+            exec_node_remove(&var->node);<br>
+            exec_list_push_tail(&impl->locals, &var->node);<br>
+         }<br>
          continue;<br>
       }<br>
<br>
@@ -1120,7 +1128,10 @@ anv_pipeline_compile_graphics(struct anv_pipeline *pipeline,<br>
          anv_pipeline_link_gs(compiler, &stages[s], next_stage);<br>
          break;<br>
       case MESA_SHADER_FRAGMENT:<br>
-         anv_pipeline_link_fs(compiler, &stages[s]);<br>
+         anv_pipeline_link_fs(compiler, &stages[s],<br>
+                              pipeline->subpass->depth_stencil_attachment,<br>
+                              info->pMultisampleState &&<br>
+                              info->pMultisampleState->alphaToCoverageEnable);<br></blockquote><div><br></div><div>You don't need to pass alphaToCoverageEnable through because it's already in the key.  For pipeline->subpass->depth_stencil_attachment, I'm inclined to just not have that in the calculation.  It's not in the key, so we'd have to add it, and the calculation should be correct regardless of whether we take depth stencil attachments into account.  If they have no attachments whatsoever, then why are they setting alphaToCoverage?  Also, I think you could similar issues if someone had no attacyment to rt 0 but did have an attachment at rt 1 which they wrote with a color value.</div><div><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          break;<br>
       default:<br>
          unreachable("Invalid graphics shader stage");<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div>