<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 23, 2018 at 1:40 AM, Iago Toral <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Thu, 2018-02-22 at 11:22 -0800, Gustavo Lima Chaves wrote:<br>
> v2:<br>
> An attempt to support SpvExecutionModeStencilRefRepl<wbr>acingEXT's<br>
> behavior<br>
> also follows, with the interpretation to said mode being we prevent<br>
> writes to the built-in FragStencilRefEXT variable when the execution<br>
> mode isn't set.<br>
><br>
> v3:<br>
> A more cautious reading of 1db44252d01bf7539452ccc2b5210c<wbr>74b8dcd573<br>
> led<br>
> me to a missing change that would stop (what I later discovered were)<br>
> GPU hangs on the CTS test written to exercize this.<br>
> ---<br>
> src/compiler/shader_info.h | 2 ++<br>
> src/compiler/spirv/spirv_to_<wbr>nir.c | 4 ++++<br>
> src/compiler/spirv/vtn_<wbr>variables.c | 4 ++++<br>
> src/intel/vulkan/anv_<wbr>extensions.py | 2 ++<br>
> src/intel/vulkan/anv_pipeline.<wbr>c | 1 +<br>
> src/intel/vulkan/genX_<wbr>pipeline.c | 1 +<br>
> 6 files changed, 14 insertions(+)<br>
><br>
> diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h<br>
> index 6de707f672..f99cbc27a7 100644<br>
> --- a/src/compiler/shader_info.h<br>
> +++ b/src/compiler/shader_info.h<br>
> @@ -162,6 +162,8 @@ typedef struct shader_info {<br>
><br>
> bool pixel_center_integer;<br>
><br>
> + bool outputs_stencil;<br>
> +<br>
> /** gl_FragDepth layout for ARB_conservative_depth. */<br>
> enum gl_frag_depth_layout depth_layout;<br>
> } fs;<br>
> diff --git a/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> index e00dcafa12..dcb8b31967 100644<br>
> --- a/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> +++ b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> @@ -3395,6 +3395,10 @@ vtn_handle_execution_mode(<wbr>struct vtn_builder<br>
> *b, struct vtn_value *entry_point,<br>
> case SpvExecutionModeContractionOff<wbr>:<br>
> break; /* OpenCL */<br>
><br>
> + case SpvExecutionModeStencilRefRepl<wbr>acingEXT:<br>
> + b->shader->info.fs.outputs_<wbr>stencil = true;<br>
> + break;<br>
> +<br>
> default:<br>
> vtn_fail("Unhandled execution mode");<br>
> }<br>
> diff --git a/src/compiler/spirv/vtn_<wbr>variables.c<br>
> b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> index 36976798e9..42f915d434 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>variables.c<br>
> +++ b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> @@ -1373,6 +1373,10 @@ apply_var_decoration(struct vtn_builder *b,<br>
> nir_variable *nir_var,<br>
> case SpvBuiltInFragCoord:<br>
> nir_var->data.pixel_center_<wbr>integer = b-<br>
> >pixel_center_integer;<br>
> break;<br>
> + case SpvBuiltInFragStencilRefEXT:<br>
> + if (!b->shader->info.fs.outputs_<wbr>stencil)<br>
> + nir_var->data.read_only = true;<br>
> + break;<br>
<br>
</div></div>From the SPIR-V spec:<br>
<br>
FragStencilRefEXT must only decorate output variable whose type is<br>
an arbitrary-sized integer type scalar.<br>
<br>
If it is an output variable, I don't think we should make it read-only<br>
in any case.<br></blockquote><div><br></div><div>Thanks for doing the spec archeology. I suspected that was the case.<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">
More over, from ARB_shader_stencil_export (which is the base GL<br>
extension this is trying to replicate):<br>
<br>
"1) Should gl_FragStencilRefARB be initialized to the current stencil<br>
reference value on input to the fragment shader?<br>
<br>
RESOLVED: No. gl_FragStencilRefARB is write-only. If the current<br>
stencil reference value is required in a shader, the application should<br>
place it in a uniform."<br>
<br>
In other words, this is an output-only variable and it is not expected<br>
to be read. If we see a SpvBuiltInFragStencilRefEXT decoration then my<br>
understanding is that we should also have<br>
SpvExecutionModeStencilRefRepl<wbr>acingEXT, so if we didn't have that I<br>
think we have incorrect SPIR-V, and in that case, instead of marking<br>
the variable as read-only, we should maybe just drop a warning instead.<br><div class="gmail-HOEnZb"><div class="gmail-h5"></div></div></blockquote><div><br></div><div>Thanks for checking. I've filed an issue against the Vulkan spec for this:<br><br><a href="https://gitlab.khronos.org/vulkan/vulkan/issues/1173">https://gitlab.khronos.org/vulkan/vulkan/issues/1173</a><br><br></div>For now, let's proceed under the assumption that the Vulkan extension follows the GL extension and does not require gl_FragStencilRefARB to be initialized with the API stencil reference value.<br><br></div><div class="gmail_quote">--Jason<br></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">
> default:<br>
> break;<br>
> }<br>
> diff --git a/src/intel/vulkan/anv_<wbr>extensions.py<br>
> b/src/intel/vulkan/anv_<wbr>extensions.py<br>
> index 581921e62a..cd90c6ae52 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>extensions.py<br>
> +++ b/src/intel/vulkan/anv_<wbr>extensions.py<br>
> @@ -86,6 +86,8 @@ EXTENSIONS = [<br>
> Extension('VK_KHX_multiview', 1, True),<br>
> Extension('VK_EXT_debug_<wbr>report', 8, True),<br>
> Extension('VK_EXT_external_<wbr>memory_dma_buf', 1, True),<br>
> + Extension('VK_EXT_shader_<wbr>stencil_export', 1,<br>
> + 'device->info.gen >= 9'),<br>
> ]<br>
><br>
> class VkVersion:<br>
> diff --git a/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> index e16a7a1994..ed63fa42cd 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> +++ b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> @@ -143,6 +143,7 @@ anv_shader_compile_to_nir(<wbr>struct anv_pipeline<br>
> *pipeline,<br>
> .multiview = true,<br>
> .variable_pointers = true,<br>
> .storage_16bit = device->instance-><wbr>physicalDevice.info.gen<br>
> >= 8,<br>
> + .stencil_export = device->instance-><wbr>physicalDevice.info.gen<br>
> >= 9,<br>
> },<br>
> };<br>
><br>
> diff --git a/src/intel/vulkan/genX_<wbr>pipeline.c<br>
> b/src/intel/vulkan/genX_<wbr>pipeline.c<br>
> index 89cbe293b8..683a4607e6 100644<br>
> --- a/src/intel/vulkan/genX_<wbr>pipeline.c<br>
> +++ b/src/intel/vulkan/genX_<wbr>pipeline.c<br>
> @@ -1600,6 +1600,7 @@ emit_3dstate_ps_extra(struct anv_pipeline<br>
> *pipeline,<br>
> ps.PixelShaderHasUAV = true;<br>
><br>
> #if GEN_GEN >= 9<br>
> + ps.PixelShaderComputesStencil = wm_prog_data-<br>
> >computed_stencil;<br>
> ps.PixelShaderPullsBary = wm_prog_data->pulls_bary;<br>
> ps.InputCoverageMaskState = wm_prog_data->uses_sample_mask ?<br>
> ICMS_INNER_CONSERVATIVE :<br>
> ICMS_NONE;<br>
</div></div><div class="gmail-HOEnZb"><div class="gmail-h5">______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>