<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 12, 2018 at 10:49 AM, Rob Clark <span dir="ltr"><<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Jun 11, 2018 at 10:59 PM, Roland Scheidegger <<a href="mailto:sroland@vmware.com">sroland@vmware.com</a>> wrote:<br>
> Am 12.06.2018 um 01:17 schrieb Rob Clark:<br>
>> On Mon, Jun 11, 2018 at 6:59 PM, Roland Scheidegger <<a href="mailto:sroland@vmware.com">sroland@vmware.com</a>> wrote:<br>
>>> Am 12.06.2018 um 00:32 schrieb Jason Ekstrand:<br>
>>>> On Wed, Jun 6, 2018 at 7:43 AM, Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a><br>
>>>> <mailto:<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>>> wrote:<br>
>>>><br>
>>>>     Signed-off-by: Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a><br>
>>>>     <mailto:<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>>><br>
>>>>     ---<br>
>>>>     I can't say for sure that this will work on all drivers, but it is<br>
>>>>     what the blob driver does, and it seems to make deqp happy.  I could<br>
>>>>     move this to it's own pass inside ir3, but that seemed like overkill<br>
>>>><br>
>>>>      src/compiler/nir/nir.h                      | 10 ++++++++++<br>
>>>>      src/compiler/nir/nir_lower_<wbr>system_values.c  | 17 +++++++++++++++++<br>
>>>>      src/gallium/drivers/freedreno/<wbr>ir3/ir3_nir.c |  1 +<br>
>>>>      3 files changed, 28 insertions(+)<br>
>>>><br>
>>>>     diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
>>>>     index 073ab4e82ea..de3d55d83af 100644<br>
>>>>     --- a/src/compiler/nir/nir.h<br>
>>>>     +++ b/src/compiler/nir/nir.h<br>
>>>>     @@ -1963,6 +1963,16 @@ typedef struct nir_shader_compiler_options {<br>
>>>>          */<br>
>>>>         bool lower_base_vertex;<br>
>>>><br>
>>>>     +   /**<br>
>>>>     +    * If enabled, gl_HelperInvocation will be lowered as:<br>
>>>>     +    *<br>
>>>>     +    *   !((1 << gl_SampleID) & gl_SampleMaskIN[0]))<br>
>>>><br>
>>>><br>
>>>> This only works for multi-sampling.  What about the single-sampled case?<br>
>>> It doesn't make sense to me for msaa neither.<br>
>>> gl_SampleID forces per-sample execution, which clearly isn't what you<br>
>>> want.<br>
>><br>
>> open to suggestions about how to try and force blob to do something<br>
>> different.. I tried a few things and the blob popped out shader code<br>
>> that worked the same way in all cases, but ofc I could have missed<br>
>> something.<br>
>><br>
>>> Plus, gl_SampleMaskIN is specified to only contain bits for the<br>
>>> current shader invocation, so for msaa with forced per-sample execution<br>
>>> that would only contain the single bit corresponding to gl_SampleID<br>
>>> anyway (that is my interpretation at least - I know hw sample mask<br>
>>> inputs will probably always contains all the bits from rasterization,<br>
>>> regardless of gl_SampleID), so the "1 << gl_SampleID &" part will do<br>
>>> nothing at all. So I think that part is more about lowering the hw<br>
>>> rasterization sample mask to gl_SampleMaskIN rather than lowering to<br>
>>> gl_HelperInvocation.<br>
>>> But yes, !gl_SampleMaskIN should give gl_HelperInvocation - I think all<br>
>>> hw can give you raster sample mask even without msaa but I'm not<br>
>>> entirely sure if it's guaranteed to work in GL with single sampling<br>
>>> (similar for sample id, which should just be stuck at 0). But using the<br>
>>> gl names here looks very, very fishy to me here.<br>
>><br>
>> I *guess* this is relying on behaviour that gl does not guarantee, but<br>
>> also doesn't prohibit, but the hw happens work that way and it works<br>
>> out..<br>
>><br>
>> Maybe the answer is to simply better document the assumptions that<br>
>> this lowering depends on?<br>
> Well I think if you have a nir shader which uses sample id but is<br>
> supposed to not be run per-sample that is quite confusing (I'd just<br>
> assume that adrenos will use sample id 0 just like in single sampled<br>
> case). Hopefully noone will deduce shader frequency from the nir shader...<br>
> I'm definitely no NIR expert but there's quite a lot of hacky<br>
> assumptions in there:<br>
> - sample id in nir doesn't cause per-sample execution (and needs to be 0<br>
> in case of msaa but no per-sample execution)<br>
> - sampleMaskIn is available in single-sampled<br>
> - sampleMaskIn doesn't actually have gl semantics but hw ones (so simply<br>
> the mask from rasterization, not taking into account the sample id<br>
> already if there's per-sample execution (for legitimate reasons),<br>
> although as mentioned I think there's still some debate about this and<br>
> not all drivers may actually agree what the semantics of it are in case<br>
> of per-sample execution)<br>
><br>
> As such I'm not sure it really makes sense to do that as a generic<br>
> lowering pass? Albeit you're quite right that it might work for a lot of<br>
> hw... But some comments would at the very least imho definitely be required.<br>
><br>
<br>
</div></div>so I reworded the comment about the enable flag a bit:<br>
<br>
   /**<br>
<span class="">    * If enabled, gl_HelperInvocation will be lowered as:<br>
</span>    *<br>
    *   !((1 << sample_id) & sample_mask_in))<br>
    *<br>
    * This depends on some possibly hw implementation details, which may<br>
    * not be true for all hw.  In particular that the FS is only executed<br>
    * for covered samples or for helper invocations.  So, do not blindly<br>
    * enable this option.<br>
    */<br>
   bool lower_helper_invocation;<br>
<br>
But I guess I probably do need to introduce a new intrinsic to access<br>
sample_id without necessarily triggering per-sample mode.. hmm..<br></blockquote><div><br></div><div>Interesting side-note:  Issue 22 of the ARB_shader_image_load_store spec explicitly calls out gl_SampleMaskIn[0] as a mechanism for detecting helper pixels.  So, apart from the whole implicitly causing per-sample shading, this does appear to be valid if you're willing to take an issue in an extension as spec text. :-)</div><div><br></div><div>--Jason</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
BR,<br>
-R<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> Roland<br>
><br>
><br>
><br>
>><br>
>> BR,<br>
>> -R<br>
>><br>
>>><br>
>>> Roland<br>
>>><br>
>>><br>
>>><br>
>>><br>
>>>><br>
>>>> --Jason<br>
>>>><br>
>>>><br>
>>>><br>
>>>>     +    *<br>
>>>>     +    * TODO any hw w/ more than 32 samples?  For them (if they<br>
>>>>     +    * used this option), a bit more math would be involved.<br>
>>>>     +    */<br>
>>>>     +   bool lower_helper_invocation;<br>
>>>>     +<br>
>>>>         bool lower_cs_local_index_from_id;<br>
>>>><br>
>>>>         bool lower_device_index_to_zero;<br>
>>>>     diff --git a/src/compiler/nir/nir_lower_<wbr>system_values.c<br>
>>>>     b/src/compiler/nir/nir_lower_<wbr>system_values.c<br>
>>>>     index 487da042620..6668cbb5dcd 100644<br>
>>>>     --- a/src/compiler/nir/nir_lower_<wbr>system_values.c<br>
>>>>     +++ b/src/compiler/nir/nir_lower_<wbr>system_values.c<br>
>>>>     @@ -136,6 +136,23 @@ convert_block(nir_block *block, nir_builder *b)<br>
>>>>                                    nir_load_first_vertex(b));<br>
>>>>               break;<br>
>>>><br>
>>>>     +      case SYSTEM_VALUE_HELPER_<wbr>INVOCATION:<br>
>>>>     +         if (b->shader->options->lower_<wbr>helper_invocation) {<br>
>>>>     +            nir_ssa_def *tmp;<br>
>>>>     +<br>
>>>>     +            tmp = nir_ushr(b,<br>
>>>>     +                           nir_imm_int(b, 1),<br>
>>>>     +                           nir_load_sample_id(b));<br>
>>>>     +<br>
>>>>     +            tmp = nir_iand(b,<br>
>>>>     +                           nir_load_sample_mask_in(b),<br>
>>>>     +                           tmp);<br>
>>>>     +<br>
>>>>     +            sysval = nir_inot(b, nir_i2b(b, tmp));<br>
>>>>     +         }<br>
>>>>     +<br>
>>>>     +         break;<br>
>>>>     +<br>
>>>>            case SYSTEM_VALUE_INSTANCE_INDEX:<br>
>>>>               sysval = nir_iadd(b,<br>
>>>>                                 nir_load_instance_id(b),<br>
>>>>     diff --git a/src/gallium/drivers/<wbr>freedreno/ir3/ir3_nir.c<br>
>>>>     b/src/gallium/drivers/<wbr>freedreno/ir3/ir3_nir.c<br>
>>>>     index cd1f9c526f2..341d990b269 100644<br>
>>>>     --- a/src/gallium/drivers/<wbr>freedreno/ir3/ir3_nir.c<br>
>>>>     +++ b/src/gallium/drivers/<wbr>freedreno/ir3/ir3_nir.c<br>
>>>>     @@ -51,6 +51,7 @@ static const nir_shader_compiler_options options = {<br>
>>>>                     .lower_extract_byte = true,<br>
>>>>                     .lower_extract_word = true,<br>
>>>>                     .lower_all_io_to_temps = true,<br>
>>>>     +               .lower_helper_invocation = true,<br>
>>>>      };<br>
>>>><br>
>>>>      struct nir_shader *<br>
>>>>     --<br>
>>>>     2.17.0<br>
>>>><br>
>>>>     ______________________________<wbr>_________________<br>
>>>>     mesa-dev mailing list<br>
>>>>     <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.<wbr>freedesktop.org</a>><br>
>>>>     <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7C3de626b5c92844260bfb08d5cff17c34%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636643558433673773&sdata=rA8s3IuEmEOR6NKdxwa5eTIwAOOhbAQWNAxW6FmiUOU%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>https%3A%2F%2Flists.<wbr>freedesktop.org%2Fmailman%<wbr>2Flistinfo%2Fmesa-dev&data=02%<wbr>7C01%7Csroland%40vmware.com%<wbr>7C3de626b5c92844260bfb08d5cff1<wbr>7c34%<wbr>7Cb39138ca3cee4b4aa4d6cd83d9dd<wbr>62f0%7C1%7C0%<wbr>7C636643558433673773&sdata=<wbr>rA8s3IuEmEOR6NKdxwa5eTIwAOOhbA<wbr>QWNAxW6FmiUOU%3D&reserved=0</a><br>
>>>>     <<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Cc50ea7f234a34e635ac308d5cfeb432a%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636643531719133589&sdata=k8EjcVGoBZyrmPfu5s5yUFZ7OerpIrUi3W3bK7qVz5o%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>https%3A%2F%2Flists.<wbr>freedesktop.org%2Fmailman%<wbr>2Flistinfo%2Fmesa-dev&data=02%<wbr>7C01%7Csroland%40vmware.com%<wbr>7Cc50ea7f234a34e635ac308d5cfeb<wbr>432a%<wbr>7Cb39138ca3cee4b4aa4d6cd83d9dd<wbr>62f0%7C1%7C0%<wbr>7C636643531719133589&sdata=<wbr>k8EjcVGoBZyrmPfu5s5yUFZ7OerpIr<wbr>Ui3W3bK7qVz5o%3D&reserved=0</a>><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> ______________________________<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://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Cc50ea7f234a34e635ac308d5cfeb432a%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636643531719133589&sdata=k8EjcVGoBZyrmPfu5s5yUFZ7OerpIrUi3W3bK7qVz5o%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.<wbr>protection.outlook.com/?url=<wbr>https%3A%2F%2Flists.<wbr>freedesktop.org%2Fmailman%<wbr>2Flistinfo%2Fmesa-dev&data=02%<wbr>7C01%7Csroland%40vmware.com%<wbr>7Cc50ea7f234a34e635ac308d5cfeb<wbr>432a%<wbr>7Cb39138ca3cee4b4aa4d6cd83d9dd<wbr>62f0%7C1%7C0%<wbr>7C636643531719133589&sdata=<wbr>k8EjcVGoBZyrmPfu5s5yUFZ7OerpIr<wbr>Ui3W3bK7qVz5o%3D&reserved=0</a><br>
>>>><br>
>>><br>
><br>
</div></div></blockquote></div><br></div></div>