<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 23, 2018 at 1:35 PM, Karol Herbst <span dir="ltr"><<a href="mailto:kherbst@redhat.com" target="_blank">kherbst@redhat.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 Fri, Mar 23, 2018 at 9:18 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> On Fri, Mar 23, 2018 at 12:33 PM, Karol Herbst <<a href="mailto:kherbst@redhat.com">kherbst@redhat.com</a>> wrote:<br>
>><br>
>> From: Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>><br>
>><br>
>> If local_size is not known at compile time, which is the case with<br>
>> clover, use the load_local_group_size intrinsic instead.<br>
>><br>
>> Signed-off-by: Karol Herbst <<a href="mailto:kherbst@redhat.com">kherbst@redhat.com</a>><br>
>> ---<br>
>>  src/compiler/nir/nir_lower_<wbr>system_values.c | 25 +++++++++++++++++--------<br>
>>  1 file changed, 17 insertions(+), 8 deletions(-)<br>
>><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 d507c28f421..ff4e09c8e61 100644<br>
>> --- a/src/compiler/nir/nir_lower_<wbr>system_values.c<br>
>> +++ b/src/compiler/nir/nir_lower_<wbr>system_values.c<br>
>> @@ -57,19 +57,28 @@ convert_block(nir_block *block, nir_builder *b)<br>
>>            *    "The value of gl_GlobalInvocationID is equal to<br>
>>            *    gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID"<br>
>>            */<br>
>> +         nir_ssa_def *local_size_def;<br>
>><br>
>> -         nir_const_value local_size;<br>
>> -         memset(&local_size, 0, sizeof(local_size));<br>
>> -         local_size.u64[0] = b->shader->info.cs.local_size[<wbr>0];<br>
>> -         local_size.u64[1] = b->shader->info.cs.local_size[<wbr>1];<br>
>> -         local_size.u64[2] = b->shader->info.cs.local_size[<wbr>2];<br>
>> +         /* if local_size[] is already known, use that, otherwise use<br>
>> +          * load_local_group_size intrinsic:<br>
>> +          */<br>
>> +         if (b->shader->info.cs.local_<wbr>size[0]) {<br>
>> +            nir_const_value local_size;<br>
>> +            memset(&local_size, 0, sizeof(local_size));<br>
>> +            local_size.u64[0] = b->shader->info.cs.local_size[<wbr>0];<br>
>> +            local_size.u64[1] = b->shader->info.cs.local_size[<wbr>1];<br>
>> +            local_size.u64[2] = b->shader->info.cs.local_size[<wbr>2];<br>
>> +<br>
>> +            local_size_def = nir_build_imm(b, 3, bit_size, local_size);<br>
>><br>
>> +         } else {<br>
>> +            local_size_def = nir_load_local_group_size(b, bit_size);<br>
>> +         }<br>
><br>
><br>
> I commented on an earlier patch about how the approach to building the<br>
> 32/64-bit immediates is wrong.<br>
><br>
<br>
</div></div>oh right, I totally forgot about that.<br>
<span class=""><br>
> Setting that aside, this patch looks fine to me in principal.  There's a<br>
> part of me that doesn't like using cs.local_size[0] being the trigger but I<br>
> think it's probably ok.  Maybe we should assert that cs_local_size is either<br>
> all zero (second case) or all not zero (first case) just to be safe.<br>
><br>
<br>
</span>I think the main problem here is, that even with OpenCL kernels you<br>
can specify it, but then overwrite it at runtime again. So yes I<br>
agree, that we need something better here.<br><div class="HOEnZb"><div class="h5"></div></div></blockquote><div><br></div><div>Oh, that's tricky then.  We could make nir_lower_system_values take a flag or OpenCL callers could just whack it all to 0 after spirv_to_nir.c.  Or you could do recompiles or something.<br><br></div><div>I think this looks good for now and we can let OpenCL users of NIR whack it to 0.  It's a fairly obvious behavior of "if you don't have it, load it" and we can let the CL driver sort out how they want to handle recompiles.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
>><br>
>><br>
>>           nir_ssa_def *group_id = nir_load_work_group_id(b, bit_size);<br>
>>           nir_ssa_def *local_id = nir_load_local_invocation_id(<wbr>b,<br>
>> bit_size);<br>
>><br>
>> -         sysval = nir_iadd(b, nir_imul(b, group_id,<br>
>> -                                       nir_build_imm(b, 3, bit_size,<br>
>> local_size)),<br>
>> -                              local_id);<br>
>> +         sysval = nir_iadd(b, nir_imul(b, group_id, local_size_def),<br>
>> +                           local_id);<br>
>>           break;<br>
>>        }<br>
>><br>
>> --<br>
>> 2.14.3<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://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
><br>
><br>
</div></div></blockquote></div><br></div></div>