<div dir="auto">Possibly worth noting as another point for reference is that zink also uses variables.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 11, 2020, 11:08 AM Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">First off, I should point out that the AMD NIR -> LLVM translator is,<br>
as far as I know, the only NIR back-end that consumes variables at<br>
all.  Most back-ends assume that all variable access is completely<br>
lowered away before the back-end ever sees it.  How this is done<br>
depends on the variable mode.<br>
<br>
For nir_var_shader_temp, these are typically converted to<br>
nir_var_function_temp by nir_lower_global_vars_to_local after function<br>
inlining has completed.  For nir_var_function_temp, it's some<br>
combination of nir_lower_vars_to_ssa, nir_lower_indirect_derefs, and<br>
nir_lower_locals_to_regs.  If the back-end wants to be able to handle<br>
indirect access (such as with a non-constant array index) directly, it<br>
will typically use nir_lower_locals_to_regs.  If the back-end doesn't<br>
want to handle indirects, it will use nir_lower_indirect_derefs to get<br>
rid of any indirects at which point nir_lower_vars_to_ssa will get rid<br>
of all access to nir_var_function_temp variables assuming complete<br>
deref chains.  (Incomplete deref chains can happen with OpenCL kernel<br>
so they require a different approach.)<br>
<br>
Next, we have driver-internal I/O for things like vertex attributes,<br>
varyings, and uniforms, i.e. nir_var_shader_in, nir_var_shader_out,<br>
and nir_var_uniform.  This is typically handled by nir_lower_io.  This<br>
call takes a type_size callback function which it ses to lay out the<br>
I/O data in some sort of index space.  For nir_var_uniform, this is<br>
often bytes (but doesn't have to be).  For nir_var_shader_in and<br>
nir_var_shader_out, it's typically in units of vec4 locations.  The<br>
result of this lowering is a bunch of load/store_input/output<br>
intrinsics.  For FS inputs, nir_lower_io can optionally produce<br>
interpolation intrinsics instead.<br>
<br>
The final major category is external I/O.  For this, we use<br>
nir_lower_explicit_io and friends.  One difference between<br>
nir_lower_io and nir_lower_explicit_io is that nir_lower_explicit_io<br>
expects types to have explicit layout information (which is always in<br>
units of bytes) rather than taking it from a callback.  Another<br>
difference is that nir_lower_explicit_io is capable of handling<br>
incomplete deref chains where pointer casts, pointer arithmetic, and<br>
other weirdness may exist while nir_lower_io assumes full deref chains<br>
all the time.  For Vulkan, we need explicit type layout information<br>
because that's what we get from SPIR-V and we need partial deref<br>
chains because of extensions like VK_KHR_variable_pointers.  For<br>
OpenGL, we have neither of those things but we use<br>
nir_lower_explicit_io anyway because we want the consistency and<br>
because the std140/430 layouts are a little too complex to describe<br>
with the callback used by nir_lower_io.<br>
<br>
Lastly, we have nir_var_system_value which is lowered by<br>
nir_lower_system_values and nir_lower_cs_system_values.<br>
<br>
I hope that helps.  I should really turn this into a blog post or,<br>
better yet, real documentation....<br>
<br>
--Jason<br>
<br>
On Sun, Oct 11, 2020 at 6:27 AM vivek pandya <<a href="mailto:vivekvpandya@gmail.com" target="_blank" rel="noreferrer">vivekvpandya@gmail.com</a>> wrote:<br>
><br>
> I see that<br>
> visit_load_var() in ~/mesa/src/amd/llvm/ac_nir_to_llvm.c<br>
><br>
> assumes that nir_variable used in this intrinsic can have few specific mods only.<br>
><br>
> For example variable can not have nir_var_mem_shared , if such mod encountered it will execute unreachable() code.<br>
><br>
> Is there any nir pass that needs to be run before nir_to_llvm translation?<br>
><br>
> Sincerely,<br>
> Vivek<br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank" rel="noreferrer">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank" rel="noreferrer">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>