<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 16, 2018 at 5:41 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">Ok, I came up with:<br>
<br>
<a href="https://hastebin.com/bulilojupo.cpp" rel="noreferrer" target="_blank">https://hastebin.com/<wbr>bulilojupo.cpp</a><br>
<br>
if you want to double check my methodology.<br>
<br>
It spotted a couple small mistakes, which I've fixed up locally. Will<br>
resend once I finish autotools build support.. hmm, and I guess there<br>
is scons too.. *sigh*<br>
<br>
Fwiw, one if the bugs was from this confusion about num_indices:<br>
<span class=""><br>
/* src[] = { vertex, offset }. const_index[] = { base, component } */<br>
</span><span class=""> LOAD(per_vertex_output, 2, 1, BASE, COMPONENT, xx,<br>
NIR_INTRINSIC_CAN_ELIMINATE)<br>
<br>
</span>;-)<br>
<br>
I *guess* I should assume the original code was correct, and change this to:<br>
<br>
# src[] = { vertex, offset }. const_index[] = { base }<br>
load("per_vertex_output", 2, [BASE], [CAN_ELIMINATE])<br></blockquote><div><br></div><div>It looks like we set component in nir_lower_io so we should probably keep it. Probably best to have a patch before this one which fixes nir_intrinsics.h. :-/<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
?<br>
<br>
BR,<br>
-R<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Fri, Mar 16, 2018 at 7:08 AM, Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> wrote:<br>
> I haven't done anything to verify yet, but I was thinking along the<br>
> same lines of just hacking up a .c program to compare both sets of<br>
> tables. There are enough intrinsics, that somewhere I probably<br>
> transcribed one wrong and visual inspection of the tables doesn't seem<br>
> sane ;-)<br>
><br>
> BR,<br>
> -R<br>
><br>
> On Fri, Mar 16, 2018 at 1:27 AM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
>> I think I like this in principal. One question would be what have you done<br>
>> to verify everything is the same? When I've done things like this in the<br>
>> past, I've written a bit of C code to compare all the info struct to ensure<br>
>> that the two generate the same thing.<br>
>><br>
>><br>
>><br>
>> On March 15, 2018 18:43:59 Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> wrote:<br>
>><br>
>>> I threatened to do this a long time ago.. I probably *should* have done<br>
>>> it a long time ago when there where many fewer intrinsics. But the<br>
>>> system of macro/#include magic for dealing with intrinsics is a bit<br>
>>> annoying, and python has the nice property of optional fxn params,<br>
>>> making it possible to define new intrinsics while ignoring parameters<br>
>>> that are not applicable (and naming optional params). And not having to<br>
>>> specify various array lengths explicitly is nice too.<br>
>>><br>
>>> I think the end result makes it easier to add new intrinsics.<br>
>>> ---<br>
>>> I still need to update autotools build.. but it's late and my wrist<br>
>>> needs a break so I thought I'd send it out as-is to solicit comments<br>
>>> on the py bits, etc<br>
>>><br>
>>> src/compiler/nir/meson.build | 22 +-<br>
>>> src/compiler/nir/nir.h | 9 -<br>
>>> src/compiler/nir/nir_builder.h | 27 +-<br>
>>> src/compiler/nir/nir_builder_<wbr>opcodes_h.py | 24 +-<br>
>>> src/compiler/nir/nir_<wbr>intrinsics.h | 540<br>
>>> --------------------<br>
>>> src/compiler/nir/nir_<wbr>intrinsics.py | 547<br>
>>> +++++++++++++++++++++<br>
>>> .../nir/{nir_intrinsics.c => nir_intrinsics_c.py} | 56 +--<br>
>>> src/compiler/nir/nir_<wbr>intrinsics_h.py | 44 ++<br>
>>> 8 files changed, 659 insertions(+), 610 deletions(-)<br>
>>> delete mode 100644 src/compiler/nir/nir_<wbr>intrinsics.h<br>
>>> create mode 100644 src/compiler/nir/nir_<wbr>intrinsics.py<br>
>>> rename src/compiler/nir/{nir_<wbr>intrinsics.c => nir_intrinsics_c.py} (59%)<br>
>>> create mode 100644 src/compiler/nir/nir_<wbr>intrinsics_h.py<br>
>>><br>
>>> diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build<br>
>>> index a70c236b958..ca9237e2ba3 100644<br>
>>> --- a/src/compiler/nir/meson.build<br>
>>> +++ b/src/compiler/nir/meson.build<br>
>>> @@ -65,6 +65,24 @@ nir_opt_algebraic_c = custom_target(<br>
>>> depend_files : files('nir_algebraic.py'),<br>
>>> )<br>
>>><br>
>>> +nir_intrinsics_h = custom_target(<br>
>>> + 'nir_intrinsics.h',<br>
>>> + input : 'nir_intrinsics_h.py',<br>
>>> + output : 'nir_intrinsics.h',<br>
>>> + command : [prog_python2, '@INPUT@'],<br>
>>> + capture : true,<br>
>>> + depend_files : files('nir_intrinsics.py'),<br>
>>> +)<br>
>>> +<br>
>>> +nir_intrinsics_c = custom_target(<br>
>>> + 'nir_intrinsic.c',<br>
>>> + input : 'nir_intrinsics_c.py',<br>
>>> + output : 'nir_intrinsics.c',<br>
>>> + command : [prog_python2, '@INPUT@'],<br>
>>> + capture: true,<br>
>>> + depend_files : files('nir_intrinsics.py'),<br>
>>> +)<br>
>>> +<br>
>>> spirv_info_c = custom_target(<br>
>>> 'spirv_info.c',<br>
>>> input : files('../spirv/spirv_info_c.<wbr>py',<br>
>>> '../spirv/spirv.core.grammar.<wbr>json'),<br>
>>> @@ -96,8 +114,6 @@ files_libnir = files(<br>
>>> 'nir_inline_functions.c',<br>
>>> 'nir_instr_set.c',<br>
>>> 'nir_instr_set.h',<br>
>>> - 'nir_intrinsics.c',<br>
>>> - 'nir_intrinsics.h',<br>
>>> 'nir_linking_helpers.c',<br>
>>> 'nir_liveness.c',<br>
>>> 'nir_loop_analyze.c',<br>
>>> @@ -201,7 +217,7 @@ libnir = static_library(<br>
>>> 'nir',<br>
>>> [files_libnir, spirv_info_c, nir_opt_algebraic_c, nir_opcodes_c,<br>
>>> nir_opcodes_h, nir_constant_expressions_c, nir_builder_opcodes_h,<br>
>>> - vtn_gather_types_c],<br>
>>> + vtn_gather_types_c, nir_intrinsics_c, nir_intrinsics_h],<br>
>>> include_directories : [inc_common, inc_compiler,<br>
>>> include_directories('../spirv'<wbr>)],<br>
>>> c_args : [c_vis_args, c_msvc_compat_args, no_override_init_args],<br>
>>> link_with : libcompiler,<br>
>>> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
>>> index 1e2ab459bd6..9bcd24a1305 100644<br>
>>> --- a/src/compiler/nir/nir.h<br>
>>> +++ b/src/compiler/nir/nir.h<br>
>>> @@ -945,16 +945,7 @@ typedef struct {<br>
>>> struct nir_function *callee;<br>
>>> } nir_call_instr;<br>
>>><br>
>>> -#define INTRINSIC(name, num_srcs, src_components, has_dest,<br>
>>> dest_components, \<br>
>>> - num_variables, num_indices, idx0, idx1, idx2, flags) \<br>
>>> - nir_intrinsic_##name,<br>
>>> -<br>
>>> -#define LAST_INTRINSIC(name) nir_last_intrinsic = nir_intrinsic_##name,<br>
>>> -<br>
>>> -typedef enum {<br>
>>> #include "nir_intrinsics.h"<br>
>>> - nir_num_intrinsics = nir_last_intrinsic + 1<br>
>>> -} nir_intrinsic_op;<br>
>>><br>
>>> #define NIR_INTRINSIC_MAX_CONST_INDEX 3<br>
>>><br>
>>> diff --git a/src/compiler/nir/nir_<wbr>builder.h<br>
>>> b/src/compiler/nir/nir_<wbr>builder.h<br>
>>> index 36e0ae3ac63..8f7ddf1483c 100644<br>
>>> --- a/src/compiler/nir/nir_<wbr>builder.h<br>
>>> +++ b/src/compiler/nir/nir_<wbr>builder.h<br>
>>> @@ -610,32 +610,7 @@ nir_copy_var(nir_builder *build, nir_variable *dest,<br>
>>> nir_variable *src)<br>
>>> nir_builder_instr_insert(<wbr>build, ©->instr);<br>
>>> }<br>
>>><br>
>>> -/* Generic builder for system values. */<br>
>>> -static inline nir_ssa_def *<br>
>>> -nir_load_system_value(nir_<wbr>builder *build, nir_intrinsic_op op, int index)<br>
>>> -{<br>
>>> - nir_intrinsic_instr *load = nir_intrinsic_instr_create(<wbr>build->shader,<br>
>>> op);<br>
>>> - load->num_components = nir_intrinsic_infos[op].dest_<wbr>components;<br>
>>> - load->const_index[0] = index;<br>
>>> - nir_ssa_dest_init(&load-><wbr>instr, &load->dest,<br>
>>> - nir_intrinsic_infos[op].dest_<wbr>components, 32, NULL);<br>
>>> - nir_builder_instr_insert(<wbr>build, &load->instr);<br>
>>> - return &load->dest.ssa;<br>
>>> -}<br>
>>> -<br>
>>> -/* Generate custom builders for system values. */<br>
>>> -#define INTRINSIC(name, num_srcs, src_components, has_dest,<br>
>>> dest_components, \<br>
>>> - num_variables, num_indices, idx0, idx1, idx2, flags)<br>
>>> -#define LAST_INTRINSIC(name)<br>
>>> -<br>
>>> -#define DEFINE_SYSTEM_VALUE(name)<br>
>>> \<br>
>>> - static inline nir_ssa_def *<br>
>>> \<br>
>>> - nir_load_##name(nir_builder *build)<br>
>>> \<br>
>>> - {<br>
>>> \<br>
>>> - return nir_load_system_value(build, nir_intrinsic_load_##name, 0);<br>
>>> \<br>
>>> - }<br>
>>> -<br>
>>> -#include "nir_intrinsics.h"<br>
>>> +#include "nir_builder_opcodes.h"<br>
>>><br>
>>> static inline nir_ssa_def *<br>
>>> nir_load_barycentric(nir_<wbr>builder *build, nir_intrinsic_op op,<br>
>>> diff --git a/src/compiler/nir/nir_<wbr>builder_opcodes_h.py<br>
>>> b/src/compiler/nir/nir_<wbr>builder_opcodes_h.py<br>
>>> index bdabe578ce2..590e471a8cd 100644<br>
>>> --- a/src/compiler/nir/nir_<wbr>builder_opcodes_h.py<br>
>>> +++ b/src/compiler/nir/nir_<wbr>builder_opcodes_h.py<br>
>>> @@ -41,9 +41,31 @@ nir_${name}(nir_builder *build,<br>
>>> ${src_decl_list(opcode.num_<wbr>inputs)})<br>
>>> }<br>
>>> % endfor<br>
>>><br>
>>> +/* Generic builder for system values. */<br>
>>> +static inline nir_ssa_def *<br>
>>> +nir_load_system_value(nir_<wbr>builder *build, nir_intrinsic_op op, int index)<br>
>>> +{<br>
>>> + nir_intrinsic_instr *load = nir_intrinsic_instr_create(<wbr>build->shader,<br>
>>> op);<br>
>>> + load->num_components = nir_intrinsic_infos[op].dest_<wbr>components;<br>
>>> + load->const_index[0] = index;<br>
>>> + nir_ssa_dest_init(&load-><wbr>instr, &load->dest,<br>
>>> + nir_intrinsic_infos[op].dest_<wbr>components, 32, NULL);<br>
>>> + nir_builder_instr_insert(<wbr>build, &load->instr);<br>
>>> + return &load->dest.ssa;<br>
>>> +}<br>
>>> +<br>
>>> +% for name in sorted(system_values.iterkeys(<wbr>)):<br>
>>> +static inline nir_ssa_def *<br>
>>> +nir_load_${name}(nir_builder *build)<br>
>>> +{<br>
>>> + return nir_load_system_value(build, nir_intrinsic_load_${name}, 0);<br>
>>> +}<br>
>>> +% endfor<br>
>>> +<br>
>>> #endif /* _NIR_BUILDER_OPCODES_ */"""<br>
>>><br>
>>> from nir_opcodes import opcodes<br>
>>> +from nir_intrinsics import system_values<br>
>>> from mako.template import Template<br>
>>><br>
>>> -print Template(template).render(<wbr>opcodes=opcodes)<br>
>>> +print Template(template).render(<wbr>opcodes=opcodes,<br>
>>> system_values=system_values)<br>
>>> diff --git a/src/compiler/nir/nir_<wbr>intrinsics.h<br>
>>> b/src/compiler/nir/nir_<wbr>intrinsics.h<br>
>>> deleted file mode 100644<br>
>>> index 7b737559d5a..00000000000<br>
>>> --- a/src/compiler/nir/nir_<wbr>intrinsics.h<br>
>>> +++ /dev/null<br>
>>> @@ -1,540 +0,0 @@<br>
>>> -/*<br>
>>> - * Copyright © 2014 Intel Corporation<br>
>>> - *<br>
>>> - * Permission is hereby granted, free of charge, to any person obtaining<br>
>>> a<br>
>>> - * copy of this software and associated documentation files (the<br>
>>> "Software"),<br>
>>> - * to deal in the Software without restriction, including without<br>
>>> limitation<br>
>>> - * the rights to use, copy, modify, merge, publish, distribute,<br>
>>> sublicense,<br>
>>> - * and/or sell copies of the Software, and to permit persons to whom the<br>
>>> - * Software is furnished to do so, subject to the following conditions:<br>
>>> - *<br>
>>> - * The above copyright notice and this permission notice (including the<br>
>>> next<br>
>>> - * paragraph) shall be included in all copies or substantial portions of<br>
>>> the<br>
>>> - * Software.<br>
>>> - *<br>
>>> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
>>> EXPRESS OR<br>
>>> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
>>> MERCHANTABILITY,<br>
>>> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT<br>
>>> SHALL<br>
>>> - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
>>> OTHER<br>
>>> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
>>> ARISING<br>
>>> - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
>>> DEALINGS<br>
>>> - * IN THE SOFTWARE.<br>
>>> - *<br>
>>> - * Authors:<br>
>>> - * Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
>>> - *<br>
>>> - */<br>
>>> -<br>
>>> -/**<br>
>>> - * This header file defines all the available intrinsics in one place. It<br>
>>> - * expands to a list of macros of the form:<br>
>>> - *<br>
>>> - * INTRINSIC(name, num_srcs, src_components, has_dest, dest_components,<br>
>>> - * num_variables, num_indices, idx0, idx1, idx2, flags)<br>
>>> - *<br>
>>> - * Which should correspond one-to-one with the nir_intrinsic_info<br>
>>> structure. It<br>
>>> - * is included in both ir.h to create the nir_intrinsic enum (with<br>
>>> members of<br>
>>> - * the form nir_intrinsic_(name)) and and in opcodes.c to create<br>
>>> - * nir_intrinsic_infos, which is a const array of nir_intrinsic_info<br>
>>> structures<br>
>>> - * for each intrinsic.<br>
>>> - */<br>
>>> -<br>
>>> -#define ARR(...) { __VA_ARGS__ }<br>
>>> -<br>
>>> -INTRINSIC(nop, 0, ARR(0), false, 0, 0, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -INTRINSIC(load_var, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(store_var, 1, ARR(0), false, 0, 1, 1, WRMASK, xx, xx, 0)<br>
>>> -INTRINSIC(copy_var, 0, ARR(0), false, 0, 2, 0, xx, xx, xx, 0)<br>
>>> -<br>
>>> -/*<br>
>>> - * Interpolation of input. The interp_var_at* intrinsics are similar to<br>
>>> the<br>
>>> - * load_var intrinsic acting on a shader input except that they<br>
>>> interpolate<br>
>>> - * the input differently. The at_sample and at_offset intrinsics take an<br>
>>> - * additional source that is an integer sample id or a vec2 position<br>
>>> offset<br>
>>> - * respectively.<br>
>>> - */<br>
>>> -<br>
>>> -INTRINSIC(interp_var_at_<wbr>centroid, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -INTRINSIC(interp_var_at_<wbr>sample, 1, ARR(1), true, 0, 1, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -INTRINSIC(interp_var_at_<wbr>offset, 1, ARR(2), true, 0, 1, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/*<br>
>>> - * Ask the driver for the size of a given buffer. It takes the buffer<br>
>>> index<br>
>>> - * as source.<br>
>>> - */<br>
>>> -INTRINSIC(get_buffer_size, 1, ARR(1), true, 1, 0, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/*<br>
>>> - * a barrier is an intrinsic with no inputs/outputs but which can't be<br>
>>> moved<br>
>>> - * around/optimized in general<br>
>>> - */<br>
>>> -#define BARRIER(name) INTRINSIC(name, 0, ARR(0), false, 0, 0, 0, xx, xx,<br>
>>> xx, 0)<br>
>>> -<br>
>>> -BARRIER(barrier)<br>
>>> -BARRIER(discard)<br>
>>> -<br>
>>> -/*<br>
>>> - * Memory barrier with semantics analogous to the memoryBarrier() GLSL<br>
>>> - * intrinsic.<br>
>>> - */<br>
>>> -BARRIER(memory_barrier)<br>
>>> -<br>
>>> -/*<br>
>>> - * Shader clock intrinsic with semantics analogous to the clock2x32ARB()<br>
>>> - * GLSL intrinsic.<br>
>>> - * The latter can be used as code motion barrier, which is currently not<br>
>>> - * feasible with NIR.<br>
>>> - */<br>
>>> -INTRINSIC(shader_clock, 0, ARR(0), true, 2, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/*<br>
>>> - * Shader ballot intrinsics with semantics analogous to the<br>
>>> - *<br>
>>> - * ballotARB()<br>
>>> - * readInvocationARB()<br>
>>> - * readFirstInvocationARB()<br>
>>> - *<br>
>>> - * GLSL functions from ARB_shader_ballot.<br>
>>> - */<br>
>>> -INTRINSIC(ballot, 1, ARR(1), true, 0, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(read_invocation, 2, ARR(0, 1), true, 0, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(read_first_<wbr>invocation, 1, ARR(0), true, 0, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/** Additional SPIR-V ballot intrinsics<br>
>>> - *<br>
>>> - * These correspond to the SPIR-V opcodes<br>
>>> - *<br>
>>> - * OpGroupUniformElect<br>
>>> - * OpSubgroupFirstInvocationKHR<br>
>>> - */<br>
>>> -INTRINSIC(elect, 0, ARR(0), true, 1, 0, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(first_invocation, 0, ARR(0), true, 1, 0, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/*<br>
>>> - * Memory barrier with semantics analogous to the compute shader<br>
>>> - * groupMemoryBarrier(), memoryBarrierAtomicCounter(),<br>
>>> memoryBarrierBuffer(),<br>
>>> - * memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.<br>
>>> - */<br>
>>> -BARRIER(group_memory_barrier)<br>
>>> -BARRIER(memory_barrier_<wbr>atomic_counter)<br>
>>> -BARRIER(memory_barrier_<wbr>buffer)<br>
>>> -BARRIER(memory_barrier_image)<br>
>>> -BARRIER(memory_barrier_<wbr>shared)<br>
>>> -<br>
>>> -/** A conditional discard, with a single boolean source. */<br>
>>> -INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)<br>
>>> -<br>
>>> -/** ARB_shader_group_vote intrinsics */<br>
>>> -INTRINSIC(vote_any, 1, ARR(1), true, 1, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(vote_all, 1, ARR(1), true, 1, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(vote_feq, 1, ARR(0), true, 1, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(vote_ieq, 1, ARR(0), true, 1, 0, 0, xx, xx, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/** Ballot ALU operations from SPIR-V.<br>
>>> - *<br>
>>> - * These operations work like their ALU counterparts except that the<br>
>>> operate<br>
>>> - * on a uvec4 which is treated as a 128bit integer. Also, they are, in<br>
>>> - * general, free to ignore any bits which are above the subgroup size.<br>
>>> - */<br>
>>> -INTRINSIC(ballot_bitfield_<wbr>extract, 2, ARR(4, 1), true, 1, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(ballot_bit_count_<wbr>reduce, 1, ARR(4), true, 1, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(ballot_bit_count_<wbr>inclusive, 1, ARR(4), true, 1, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(ballot_bit_count_<wbr>exclusive, 1, ARR(4), true, 1, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(ballot_find_lsb, 1, ARR(4), true, 1, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(ballot_find_msb, 1, ARR(4), true, 1, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/** Shuffle operations from SPIR-V. */<br>
>>> -INTRINSIC(shuffle, 2, ARR(0, 1), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(shuffle_xor, 2, ARR(0, 1), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(shuffle_up, 2, ARR(0, 1), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(shuffle_down, 2, ARR(0, 1), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/** Quad operations from SPIR-V. */<br>
>>> -INTRINSIC(quad_broadcast, 2, ARR(0, 1), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(quad_swap_<wbr>horizontal, 1, ARR(0), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(quad_swap_vertical, 1, ARR(0), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(quad_swap_diagonal, 1, ARR(0), true, 0, 0,<br>
>>> - 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -INTRINSIC(reduce, 1, ARR(0), true, 0, 0,<br>
>>> - 2, REDUCTION_OP, CLUSTER_SIZE, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(inclusive_scan, 1, ARR(0), true, 0, 0,<br>
>>> - 1, REDUCTION_OP, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(exclusive_scan, 1, ARR(0), true, 0, 0,<br>
>>> - 1, REDUCTION_OP, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -<br>
>>> -/**<br>
>>> - * Basic Geometry Shader intrinsics.<br>
>>> - *<br>
>>> - * emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a<br>
>>> single<br>
>>> - * index, which is the stream ID to write to.<br>
>>> - *<br>
>>> - * end_primitive implements GLSL's EndPrimitive() built-in.<br>
>>> - */<br>
>>> -INTRINSIC(emit_vertex, 0, ARR(0), false, 0, 0, 1, STREAM_ID, xx, xx, 0)<br>
>>> -INTRINSIC(end_primitive, 0, ARR(0), false, 0, 0, 1, STREAM_ID, xx, xx, 0)<br>
>>> -<br>
>>> -/**<br>
>>> - * Geometry Shader intrinsics with a vertex count.<br>
>>> - *<br>
>>> - * Alternatively, drivers may implement these intrinsics, and use<br>
>>> - * nir_lower_gs_intrinsics() to convert from the basic intrinsics.<br>
>>> - *<br>
>>> - * These maintain a count of the number of vertices emitted, as an<br>
>>> additional<br>
>>> - * unsigned integer source.<br>
>>> - */<br>
>>> -INTRINSIC(emit_vertex_with_<wbr>counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID,<br>
>>> xx, xx, 0)<br>
>>> -INTRINSIC(end_primitive_with_<wbr>counter, 1, ARR(1), false, 0, 0, 1,<br>
>>> STREAM_ID, xx, xx, 0)<br>
>>> -INTRINSIC(set_vertex_count, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)<br>
>>> -<br>
>>> -/*<br>
>>> - * Atomic counters<br>
>>> - *<br>
>>> - * The *_var variants take an atomic_uint nir_variable, while the other,<br>
>>> - * lowered, variants take a constant buffer index and register offset.<br>
>>> - */<br>
>>> -<br>
>>> -#define ATOMIC(name, flags) \<br>
>>> - INTRINSIC(name##_var, 0, ARR(0), true, 1, 1, 0, xx, xx, xx, flags) \<br>
>>> - INTRINSIC(name, 1, ARR(1), true, 1, 0, 1, BASE, xx, xx, flags)<br>
>>> -#define ATOMIC2(name) \<br>
>>> - INTRINSIC(name##_var, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0) \<br>
>>> - INTRINSIC(name, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)<br>
>>> -#define ATOMIC3(name) \<br>
>>> - INTRINSIC(name##_var, 2, ARR(1, 1), true, 1, 1, 0, xx, xx, xx, 0) \<br>
>>> - INTRINSIC(name, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE, xx, xx, 0)<br>
>>> -<br>
>>> -ATOMIC(atomic_counter_inc, 0)<br>
>>> -ATOMIC(atomic_counter_dec, 0)<br>
>>> -ATOMIC(atomic_counter_read, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -ATOMIC2(atomic_counter_add)<br>
>>> -ATOMIC2(atomic_counter_min)<br>
>>> -ATOMIC2(atomic_counter_max)<br>
>>> -ATOMIC2(atomic_counter_and)<br>
>>> -ATOMIC2(atomic_counter_or)<br>
>>> -ATOMIC2(atomic_counter_xor)<br>
>>> -ATOMIC2(atomic_counter_<wbr>exchange)<br>
>>> -ATOMIC3(atomic_counter_comp_<wbr>swap)<br>
>>> -<br>
>>> -/*<br>
>>> - * Image load, store and atomic intrinsics.<br>
>>> - *<br>
>>> - * All image intrinsics take an image target passed as a nir_variable.<br>
>>> Image<br>
>>> - * variables contain a number of memory and layout qualifiers that<br>
>>> influence<br>
>>> - * the semantics of the intrinsic.<br>
>>> - *<br>
>>> - * All image intrinsics take a four-coordinate vector and a sample index<br>
>>> as<br>
>>> - * first two sources, determining the location within the image that will<br>
>>> be<br>
>>> - * accessed by the intrinsic. Components not applicable to the image<br>
>>> target<br>
>>> - * in use are undefined. Image store takes an additional four-component<br>
>>> - * argument with the value to be written, and image atomic operations<br>
>>> take<br>
>>> - * either one or two additional scalar arguments with the same meaning as<br>
>>> in<br>
>>> - * the ARB_shader_image_load_store specification.<br>
>>> - */<br>
>>> -INTRINSIC(image_load, 2, ARR(4, 1), true, 4, 1, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -INTRINSIC(image_store, 3, ARR(4, 1, 4), false, 0, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(image_atomic_add, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(image_atomic_min, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(image_atomic_max, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(image_atomic_and, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(image_atomic_or, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(image_atomic_xor, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(image_atomic_<wbr>exchange, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx,<br>
>>> xx, 0)<br>
>>> -INTRINSIC(image_atomic_comp_<wbr>swap, 4, ARR(4, 1, 1, 1), true, 1, 1, 0, xx,<br>
>>> xx, xx, 0)<br>
>>> -INTRINSIC(image_size, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -INTRINSIC(image_samples, 0, ARR(0), true, 1, 1, 0, xx, xx, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/*<br>
>>> - * Vulkan descriptor set intrinsics<br>
>>> - *<br>
>>> - * The Vulkan API uses a different binding model from GL. In the Vulkan<br>
>>> - * API, all external resources are represented by a tuple:<br>
>>> - *<br>
>>> - * (descriptor set, binding, array index)<br>
>>> - *<br>
>>> - * where the array index is the only thing allowed to be indirect. The<br>
>>> - * vulkan_surface_index intrinsic takes the descriptor set and binding as<br>
>>> - * its first two indices and the array index as its source. The third<br>
>>> - * index is a nir_variable_mode in case that's useful to the backend.<br>
>>> - *<br>
>>> - * The intended usage is that the shader will call vulkan_surface_index<br>
>>> to<br>
>>> - * get an index and then pass that as the buffer index ubo/ssbo calls.<br>
>>> - *<br>
>>> - * The vulkan_resource_reindex intrinsic takes a resource index in src0<br>
>>> - * (the result of a vulkan_resource_index or vulkan_resource_reindex)<br>
>>> which<br>
>>> - * corresponds to the tuple (set, binding, index) and computes an index<br>
>>> - * corresponding to tuple (set, binding, idx + src1).<br>
>>> - */<br>
>>> -INTRINSIC(vulkan_resource_<wbr>index, 1, ARR(1), true, 1, 0, 2,<br>
>>> - DESC_SET, BINDING, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -INTRINSIC(vulkan_resource_<wbr>reindex, 2, ARR(1, 1), true, 1, 0, 0, xx, xx,<br>
>>> xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/*<br>
>>> - * variable atomic intrinsics<br>
>>> - *<br>
>>> - * All of these variable atomic memory operations read a value from<br>
>>> memory,<br>
>>> - * compute a new value using one of the operations below, write the new<br>
>>> value<br>
>>> - * to memory, and return the original value read.<br>
>>> - *<br>
>>> - * All operations take 1 source except CompSwap that takes 2. These<br>
>>> sources<br>
>>> - * represent:<br>
>>> - *<br>
>>> - * 0: The data parameter to the atomic function (i.e. the value to add<br>
>>> - * in shared_atomic_add, etc).<br>
>>> - * 1: For CompSwap only: the second data parameter.<br>
>>> - *<br>
>>> - * All operations take 1 variable deref.<br>
>>> - */<br>
>>> -INTRINSIC(var_atomic_add, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_imin, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_umin, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_imax, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_umax, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_and, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_or, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_xor, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_<wbr>exchange, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(var_atomic_comp_<wbr>swap, 2, ARR(1, 1), true, 1, 1, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -<br>
>>> -/*<br>
>>> - * SSBO atomic intrinsics<br>
>>> - *<br>
>>> - * All of the SSBO atomic memory operations read a value from memory,<br>
>>> - * compute a new value using one of the operations below, write the new<br>
>>> - * value to memory, and return the original value read.<br>
>>> - *<br>
>>> - * All operations take 3 sources except CompSwap that takes 4. These<br>
>>> - * sources represent:<br>
>>> - *<br>
>>> - * 0: The SSBO buffer index.<br>
>>> - * 1: The offset into the SSBO buffer of the variable that the atomic<br>
>>> - * operation will operate on.<br>
>>> - * 2: The data parameter to the atomic function (i.e. the value to add<br>
>>> - * in ssbo_atomic_add, etc).<br>
>>> - * 3: For CompSwap only: the second data parameter.<br>
>>> - */<br>
>>> -INTRINSIC(ssbo_atomic_add, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(ssbo_atomic_imin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(ssbo_atomic_umin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(ssbo_atomic_imax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(ssbo_atomic_umax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(ssbo_atomic_and, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(ssbo_atomic_or, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(ssbo_atomic_xor, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)<br>
>>> -INTRINSIC(ssbo_atomic_<wbr>exchange, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx,<br>
>>> xx, 0)<br>
>>> -INTRINSIC(ssbo_atomic_comp_<wbr>swap, 4, ARR(1, 1, 1, 1), true, 1, 0, 0, xx,<br>
>>> xx, xx, 0)<br>
>>> -<br>
>>> -/*<br>
>>> - * CS shared variable atomic intrinsics<br>
>>> - *<br>
>>> - * All of the shared variable atomic memory operations read a value from<br>
>>> - * memory, compute a new value using one of the operations below, write<br>
>>> the<br>
>>> - * new value to memory, and return the original value read.<br>
>>> - *<br>
>>> - * All operations take 2 sources except CompSwap that takes 3. These<br>
>>> - * sources represent:<br>
>>> - *<br>
>>> - * 0: The offset into the shared variable storage region that the atomic<br>
>>> - * operation will operate on.<br>
>>> - * 1: The data parameter to the atomic function (i.e. the value to add<br>
>>> - * in shared_atomic_add, etc).<br>
>>> - * 2: For CompSwap only: the second data parameter.<br>
>>> - */<br>
>>> -INTRINSIC(shared_atomic_add, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_imin, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_umin, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_imax, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_umax, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_and, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_or, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)<br>
>>> -INTRINSIC(shared_atomic_xor, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx,<br>
>>> 0)<br>
>>> -INTRINSIC(shared_atomic_<wbr>exchange, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx,<br>
>>> xx, 0)<br>
>>> -INTRINSIC(shared_atomic_comp_<wbr>swap, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE,<br>
>>> xx, xx, 0)<br>
>>> -<br>
>>> -/* Used by nir_builder.h to generate loader helpers for the system<br>
>>> values. */<br>
>>> -#ifndef DEFINE_SYSTEM_VALUE<br>
>>> -#define DEFINE_SYSTEM_VALUE(name)<br>
>>> -#endif<br>
>>> -<br>
>>> -#define SYSTEM_VALUE(name, components, num_indices, idx0, idx1, idx2) \<br>
>>> - DEFINE_SYSTEM_VALUE(name) \<br>
>>> - INTRINSIC(load_##name, 0, ARR(0), true, components, 0, num_indices, \<br>
>>> - idx0, idx1, idx2, \<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -SYSTEM_VALUE(frag_coord, 4, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(front_face, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(vertex_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(vertex_id_zero_<wbr>base, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(base_vertex, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(instance_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(base_instance, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(draw_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(sample_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(sample_pos, 2, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(sample_mask_in, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(primitive_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(invocation_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(tess_coord, 3, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(tess_level_<wbr>outer, 4, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(tess_level_<wbr>inner, 2, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(patch_vertices_<wbr>in, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(local_<wbr>invocation_id, 3, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(local_<wbr>invocation_index, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(work_group_id, 3, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(user_clip_plane, 4, 1, UCP_ID, xx, xx)<br>
>>> -SYSTEM_VALUE(num_work_groups, 3, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(helper_<wbr>invocation, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(alpha_ref_float, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(layer_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(view_index, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_size, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_<wbr>invocation, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_eq_<wbr>mask, 0, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_ge_<wbr>mask, 0, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_gt_<wbr>mask, 0, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_le_<wbr>mask, 0, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_lt_<wbr>mask, 0, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(num_subgroups, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(subgroup_id, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(local_group_<wbr>size, 3, 0, xx, xx, xx)<br>
>>> -<br>
>>> -/* Blend constant color values. Float values are clamped. */<br>
>>> -SYSTEM_VALUE(blend_const_<wbr>color_r_float, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(blend_const_<wbr>color_g_float, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(blend_const_<wbr>color_b_float, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(blend_const_<wbr>color_a_float, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(blend_const_<wbr>color_rgba8888_unorm, 1, 0, xx, xx, xx)<br>
>>> -SYSTEM_VALUE(blend_const_<wbr>color_aaaa8888_unorm, 1, 0, xx, xx, xx)<br>
>>> -<br>
>>> -/**<br>
>>> - * Barycentric coordinate intrinsics.<br>
>>> - *<br>
>>> - * These set up the barycentric coordinates for a particular<br>
>>> interpolation.<br>
>>> - * The first three are for the simple cases: pixel, centroid, or<br>
>>> per-sample<br>
>>> - * (at gl_SampleID). The next two handle interpolating at a specified<br>
>>> - * sample location, or interpolating with a vec2 offset,<br>
>>> - *<br>
>>> - * The interp_mode index should be either the INTERP_MODE_SMOOTH or<br>
>>> - * INTERP_MODE_NOPERSPECTIVE enum values.<br>
>>> - *<br>
>>> - * The vec2 value produced by these intrinsics is intended for use as the<br>
>>> - * barycoord source of a load_interpolated_input intrinsic.<br>
>>> - */<br>
>>> -<br>
>>> -#define BARYCENTRIC(name, sources, source_components) \<br>
>>> - INTRINSIC(load_barycentric_##<wbr>name, sources, ARR(source_components), \<br>
>>> - true, 2, 0, 1, INTERP_MODE, xx, xx, \<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/* no sources. const_index[] = { interp_mode } */<br>
>>> -BARYCENTRIC(pixel, 0, 0)<br>
>>> -BARYCENTRIC(centroid, 0, 0)<br>
>>> -BARYCENTRIC(sample, 0, 0)<br>
>>> -/* src[] = { sample_id }. const_index[] = { interp_mode } */<br>
>>> -BARYCENTRIC(at_sample, 1, 1)<br>
>>> -/* src[] = { offset.xy }. const_index[] = { interp_mode } */<br>
>>> -BARYCENTRIC(at_offset, 1, 2)<br>
>>> -<br>
>>> -/*<br>
>>> - * Load operations pull data from some piece of GPU memory. All load<br>
>>> - * operations operate in terms of offsets into some piece of theoretical<br>
>>> - * memory. Loads from externally visible memory (UBO and SSBO) simply<br>
>>> take a<br>
>>> - * byte offset as a source. Loads from opaque memory (uniforms, inputs,<br>
>>> etc.)<br>
>>> - * take a base+offset pair where the base (const_index[0]) gives the<br>
>>> location<br>
>>> - * of the start of the variable being loaded and and the offset source is<br>
>>> a<br>
>>> - * offset into that variable.<br>
>>> - *<br>
>>> - * Uniform load operations have a second "range" index that specifies the<br>
>>> - * range (starting at base) of the data from which we are loading. If<br>
>>> - * const_index[1] == 0, then the range is unknown.<br>
>>> - *<br>
>>> - * Some load operations such as UBO/SSBO load and per_vertex loads take<br>
>>> an<br>
>>> - * additional source to specify which UBO/SSBO/vertex to load from.<br>
>>> - *<br>
>>> - * The exact address type depends on the lowering pass that generates the<br>
>>> - * load/store intrinsics. Typically, this is vec4 units for things such<br>
>>> as<br>
>>> - * varying slots and float units for fragment shader inputs. UBO and<br>
>>> SSBO<br>
>>> - * offsets are always in bytes.<br>
>>> - */<br>
>>> -<br>
>>> -#define LOAD(name, srcs, num_indices, idx0, idx1, idx2, flags) \<br>
>>> - INTRINSIC(load_##name, srcs, ARR(1, 1, 1, 1), true, 0, 0, num_indices,<br>
>>> idx0, idx1, idx2, flags)<br>
>>> -<br>
>>> -/* src[] = { offset }. const_index[] = { base, range } */<br>
>>> -LOAD(uniform, 1, 2, BASE, RANGE, xx, NIR_INTRINSIC_CAN_ELIMINATE |<br>
>>> NIR_INTRINSIC_CAN_REORDER)<br>
>>> -/* src[] = { buffer_index, offset }. No const_index */<br>
>>> -LOAD(ubo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE |<br>
>>> NIR_INTRINSIC_CAN_REORDER)<br>
>>> -/* src[] = { offset }. const_index[] = { base, component } */<br>
>>> -LOAD(input, 1, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE |<br>
>>> NIR_INTRINSIC_CAN_REORDER)<br>
>>> -/* src[] = { vertex, offset }. const_index[] = { base, component } */<br>
>>> -LOAD(per_vertex_input, 2, 2, BASE, COMPONENT, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -/* src[] = { barycoord, offset }. const_index[] = { base, component } */<br>
>>> -INTRINSIC(load_interpolated_<wbr>input, 2, ARR(2, 1), true, 0, 0,<br>
>>> - 2, BASE, COMPONENT, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/* src[] = { buffer_index, offset }. No const_index */<br>
>>> -LOAD(ssbo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -/* src[] = { offset }. const_index[] = { base, component } */<br>
>>> -LOAD(output, 1, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -/* src[] = { vertex, offset }. const_index[] = { base, component } */<br>
>>> -LOAD(per_vertex_output, 2, 1, BASE, COMPONENT, xx,<br>
>>> NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -/* src[] = { offset }. const_index[] = { base } */<br>
>>> -LOAD(shared, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)<br>
>>> -/* src[] = { offset }. const_index[] = { base, range } */<br>
>>> -LOAD(push_constant, 1, 2, BASE, RANGE, xx,<br>
>>> - NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)<br>
>>> -<br>
>>> -/*<br>
>>> - * Stores work the same way as loads, except now the first source is the<br>
>>> value<br>
>>> - * to store and the second (and possibly third) source specify where to<br>
>>> store<br>
>>> - * the value. SSBO and shared memory stores also have a write mask as<br>
>>> - * const_index[0].<br>
>>> - */<br>
>>> -<br>
>>> -#define STORE(name, srcs, num_indices, idx0, idx1, idx2, flags) \<br>
>>> - INTRINSIC(store_##name, srcs, ARR(0, 1, 1, 1), false, 0, 0,<br>
>>> num_indices, idx0, idx1, idx2, flags)<br>
>>> -<br>
>>> -/* src[] = { value, offset }. const_index[] = { base, write_mask,<br>
>>> component } */<br>
>>> -STORE(output, 2, 3, BASE, WRMASK, COMPONENT, 0)<br>
>>> -/* src[] = { value, vertex, offset }.<br>
>>> - * const_index[] = { base, write_mask, component }<br>
>>> - */<br>
>>> -STORE(per_vertex_output, 3, 3, BASE, WRMASK, COMPONENT, 0)<br>
>>> -/* src[] = { value, block_index, offset }. const_index[] = { write_mask }<br>
>>> */<br>
>>> -STORE(ssbo, 3, 1, WRMASK, xx, xx, 0)<br>
>>> -/* src[] = { value, offset }. const_index[] = { base, write_mask } */<br>
>>> -STORE(shared, 2, 2, BASE, WRMASK, xx, 0)<br>
>>> -<br>
>>> -LAST_INTRINSIC(store_shared)<br>
>>> -<br>
>>> -#undef DEFINE_SYSTEM_VALUE<br>
>>> -#undef INTRINSIC<br>
>>> -#undef LAST_INTRINSIC<br>
>>> diff --git a/src/compiler/nir/nir_<wbr>intrinsics.py<br>
>>> b/src/compiler/nir/nir_<wbr>intrinsics.py<br>
>>> new file mode 100644<br>
>>> index 00000000000..6bb6603586e<br>
>>> --- /dev/null<br>
>>> +++ b/src/compiler/nir/nir_<wbr>intrinsics.py<br>
>>> @@ -0,0 +1,547 @@<br>
>>> +#<br>
>>> +# Copyright (C) 2018 Red Hat<br>
>>> +# Copyright (C) 2014 Intel Corporation<br>
>>> +#<br>
>>> +# Permission is hereby granted, free of charge, to any person obtaining a<br>
>>> +# copy of this software and associated documentation files (the<br>
>>> "Software"),<br>
>>> +# to deal in the Software without restriction, including without<br>
>>> limitation<br>
>>> +# the rights to use, copy, modify, merge, publish, distribute,<br>
>>> sublicense,<br>
>>> +# and/or sell copies of the Software, and to permit persons to whom the<br>
>>> +# Software is furnished to do so, subject to the following conditions:<br>
>>> +#<br>
>>> +# The above copyright notice and this permission notice (including the<br>
>>> next<br>
>>> +# paragraph) shall be included in all copies or substantial portions of<br>
>>> the<br>
>>> +# Software.<br>
>>> +#<br>
>>> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
>>> OR<br>
>>> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
>>> MERCHANTABILITY,<br>
>>> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT<br>
>>> SHALL<br>
>>> +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
>>> OTHER<br>
>>> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
>>> +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
>>> DEALINGS<br>
>>> +# IN THE SOFTWARE.<br>
>>> +#<br>
>>> +<br>
>>> +# This file defines all the available intrinsics in one place.<br>
>>> +#<br>
>>> +# The Intrinsic class corresponds one-to-one with nir_intrinsic_info<br>
>>> +# structure.<br>
>>> +<br>
>>> +class Intrinsic(object):<br>
>>> + """Class that represents all the information about an intrinsic<br>
>>> opcode.<br>
>>> + NOTE: this must be kept in sync with nir_intrinsic_info.<br>
>>> + """<br>
>>> + def __init__(self, name, src_components, dest_components,<br>
>>> num_variables,<br>
>>> + indices, flags):<br>
>>> + """Parameters:<br>
>>> +<br>
>>> + - name: the intrinsic name<br>
>>> + - src_components: list of the number of components per src, 0<br>
>>> means<br>
>>> + vectorized instruction with number of components given in the<br>
>>> + num_components field in nir_intrinsic_instr.<br>
>>> + - dest_components: number of destination components, -1 means no<br>
>>> + dest, 0 means number of components given in num_components field<br>
>>> + in nir_intrinsic_instr.<br>
>>> + - num_variables: the number of variables<br>
>>> + - indices: list of constant indicies<br>
>>> + - flags: list of semantic flags<br>
>>> + """<br>
>>> + assert isinstance(name, str)<br>
>>> + assert isinstance(src_components, list)<br>
>>> + if len(src_components) > 0:<br>
>>> + assert isinstance(src_components[0], int)<br>
>>> + assert isinstance(dest_components, int)<br>
>>> + assert isinstance(num_variables, int)<br>
>>> + assert isinstance(indices, list)<br>
>>> + if len(indices) > 0:<br>
>>> + assert isinstance(indices[0], str)<br>
>>> + assert isinstance(flags, list)<br>
>>> + if len(flags) > 0:<br>
>>> + assert isinstance(flags[0], str)<br>
>>> +<br>
>>> + <a href="http://self.name" rel="noreferrer" target="_blank">self.name</a> = name<br>
>>> + self.num_srcs = len(src_components)<br>
>>> + self.src_components = src_components<br>
>>> + self.has_dest = (dest_components >= 0)<br>
>>> + self.dest_components = dest_components<br>
>>> + self.num_variables = num_variables<br>
>>> + self.num_indices = len(indices)<br>
>>> + self.indices = indices<br>
>>> + self.flags = flags<br>
>>> +<br>
>>> +#<br>
>>> +# Possible indices:<br>
>>> +#<br>
>>> +<br>
>>> +# A constant 'base' value that is added to an offset src:<br>
>>> +BASE = "NIR_INTRINSIC_BASE"<br>
>>> +# For store instructions, a writemask:<br>
>>> +WRMASK = "NIR_INTRINSIC_WRMASK"<br>
>>> +# The stream-id for GS emit_vertex/end_primitive intrinsics:<br>
>>> +STREAM_ID = "NIR_INTRINSIC_STREAM_ID"<br>
>>> +# The clip-plane id for load_user_clip_plane intrinsics:<br>
>>> +UCP_ID = "NIR_INTRINSIC_UCP_ID"<br>
>>> +# The amount of data, starting from BASE, that this instruction<br>
>>> +# may access. This is used to provide bounds if the offset is<br>
>>> +# not constant.<br>
>>> +RANGE = "NIR_INTRINSIC_RANGE"<br>
>>> +# The vulkan descriptor set binding for vulkan_resource_index<br>
>>> +# intrinsic<br>
>>> +DESC_SET = "NIR_INTRINSIC_DESC_SET"<br>
>>> +# The vulkan descriptor set binding for vulkan_resource_index<br>
>>> +# intrinsic<br>
>>> +BINDING = "NIR_INTRINSIC_BINDING"<br>
>>> +# Component offset<br>
>>> +COMPONENT = "NIR_INTRINSIC_COMPONENT"<br>
>>> +# Interpolation mode (only meaningful for FS inputs)<br>
>>> +INTERP_MODE = "NIR_INTRINSIC_INTERP_MODE"<br>
>>> +# A binary nir_op to use when performing a reduction or scan operation<br>
>>> +REDUCTION_OP = "NIR_INTRINSIC_REDUCTION_OP"<br>
>>> +# Cluster size for reduction operations<br>
>>> +CLUSTER_SIZE = "NIR_INTRINSIC_CLUSTER_SIZE"<br>
>>> +<br>
>>> +#<br>
>>> +# Possible flags:<br>
>>> +#<br>
>>> +<br>
>>> +CAN_ELIMINATE = "NIR_INTRINSIC_CAN_ELIMINATE"<br>
>>> +CAN_REORDER = "NIR_INTRINSIC_CAN_REORDER"<br>
>>> +<br>
>>> +intr_opcodes = {}<br>
>>> +<br>
>>> +def intrinsic(name, src_comp=[], dest_comp=-1, num_vars=0, indices=[],<br>
>>> flags=[]):<br>
>>> + assert name not in intr_opcodes<br>
>>> + intr = Intrinsic(name, src_comp, dest_comp, num_vars, indices, flags)<br>
>>> + intr_opcodes[name] = intr<br>
>>> + return intr<br>
>>> +<br>
>>> +intrinsic("nop", flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +intrinsic("load_var", dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("store_var", src_comp=[0], num_vars=1, indices=[WRMASK])<br>
>>> +intrinsic("copy_var", num_vars=2)<br>
>>> +<br>
>>> +# Interpolation of input. The interp_var_at* intrinsics are similar to<br>
>>> the<br>
>>> +# load_var intrinsic acting on a shader input except that they<br>
>>> interpolate<br>
>>> +# the input differently. The at_sample and at_offset intrinsics take an<br>
>>> +# additional source that is an integer sample id or a vec2 position<br>
>>> offset<br>
>>> +# respectively.<br>
>>> +<br>
>>> +intrinsic("interp_var_at_<wbr>centroid", dest_comp=0, num_vars=1,<br>
>>> + flags=[ CAN_ELIMINATE, CAN_REORDER])<br>
>>> +intrinsic("interp_var_at_<wbr>sample", src_comp=[1], dest_comp=0,<br>
>>> + flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +intrinsic("interp_var_at_<wbr>offset", src_comp=[2], dest_comp=0, num_vars=1,<br>
>>> + flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +<br>
>>> +# Ask the driver for the size of a given buffer. It takes the buffer<br>
>>> index<br>
>>> +# as source.<br>
>>> +intrinsic("get_buffer_size", src_comp=[1], dest_comp=1,<br>
>>> + flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +<br>
>>> +# a barrier is an intrinsic with no inputs/outputs but which can't be<br>
>>> moved<br>
>>> +# around/optimized in general<br>
>>> +def barrier(name):<br>
>>> + intrinsic(name)<br>
>>> +<br>
>>> +barrier("barrier")<br>
>>> +barrier("discard")<br>
>>> +<br>
>>> +# Memory barrier with semantics analogous to the memoryBarrier() GLSL<br>
>>> +# intrinsic.<br>
>>> +barrier("memory_barrier")<br>
>>> +<br>
>>> +# Shader clock intrinsic with semantics analogous to the clock2x32ARB()<br>
>>> +# GLSL intrinsic.<br>
>>> +# The latter can be used as code motion barrier, which is currently not<br>
>>> +# feasible with NIR.<br>
>>> +intrinsic("shader_clock", dest_comp=2, flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Shader ballot intrinsics with semantics analogous to the<br>
>>> +#<br>
>>> +# ballotARB()<br>
>>> +# readInvocationARB()<br>
>>> +# readFirstInvocationARB()<br>
>>> +#<br>
>>> +# GLSL functions from ARB_shader_ballot.<br>
>>> +intrinsic("ballot", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("read_invocation", src_comp=[0, 1], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("read_first_<wbr>invocation", src_comp=[0], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Additional SPIR-V ballot intrinsics<br>
>>> +#<br>
>>> +# These correspond to the SPIR-V opcodes<br>
>>> +#<br>
>>> +# OpGroupUniformElect<br>
>>> +# OpSubgroupFirstInvocationKHR<br>
>>> +intrinsic("elect", dest_comp=1, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("first_invocation", dest_comp=1, flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Memory barrier with semantics analogous to the compute shader<br>
>>> +# groupMemoryBarrier(), memoryBarrierAtomicCounter(),<br>
>>> memoryBarrierBuffer(),<br>
>>> +# memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.<br>
>>> +barrier("group_memory_<wbr>barrier")<br>
>>> +barrier("memory_barrier_<wbr>atomic_counter")<br>
>>> +barrier("memory_barrier_<wbr>buffer")<br>
>>> +barrier("memory_barrier_<wbr>image")<br>
>>> +barrier("memory_barrier_<wbr>shared")<br>
>>> +<br>
>>> +# A conditional discard, with a single boolean source.<br>
>>> +intrinsic("discard_if", src_comp=[1])<br>
>>> +<br>
>>> +# ARB_shader_group_vote intrinsics<br>
>>> +intrinsic("vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("vote_feq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("vote_ieq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Ballot ALU operations from SPIR-V.<br>
>>> +#<br>
>>> +# These operations work like their ALU counterparts except that the<br>
>>> operate<br>
>>> +# on a uvec4 which is treated as a 128bit integer. Also, they are, in<br>
>>> +# general, free to ignore any bits which are above the subgroup size.<br>
>>> +intrinsic("ballot_bitfield_<wbr>extract", src_comp=[4, 1], dest_comp=1,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("ballot_bit_count_<wbr>reduce", src_comp=[4], dest_comp=1,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("ballot_bit_count_<wbr>inclusive", src_comp=[4], dest_comp=1,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("ballot_bit_count_<wbr>exclusive", src_comp=[4], dest_comp=1,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("ballot_find_lsb", src_comp=[4], dest_comp=1,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("ballot_find_msb", src_comp=[4], dest_comp=1,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Shuffle operations from SPIR-V.<br>
>>> +intrinsic("shuffle", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("shuffle_xor", src_comp=[0, 1], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("shuffle_up", src_comp=[0, 1], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("shuffle_down", src_comp=[0, 1], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Quad operations from SPIR-V.<br>
>>> +intrinsic("quad_broadcast", src_comp=[0, 1], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("quad_swap_<wbr>horizontal", src_comp=[0], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("quad_swap_<wbr>vertical", src_comp=[0], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("quad_swap_<wbr>diagonal", src_comp=[0], dest_comp=0,<br>
>>> flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +intrinsic("reduce", src_comp=[0], dest_comp=0, indices=[REDUCTION_OP,<br>
>>> CLUSTER_SIZE],<br>
>>> + flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("inclusive_scan", src_comp=[0], dest_comp=0,<br>
>>> indices=[REDUCTION_OP],<br>
>>> + flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("exclusive_scan", src_comp=[0], dest_comp=0,<br>
>>> indices=[REDUCTION_OP],<br>
>>> + flags=[CAN_ELIMINATE])<br>
>>> +<br>
>>> +# Basic Geometry Shader intrinsics.<br>
>>> +#<br>
>>> +# emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a<br>
>>> single<br>
>>> +# index, which is the stream ID to write to.<br>
>>> +#<br>
>>> +# end_primitive implements GLSL's EndPrimitive() built-in.<br>
>>> +intrinsic("emit_vertex", indices=[STREAM_ID])<br>
>>> +intrinsic("end_primitive", indices=[STREAM_ID])<br>
>>> +<br>
>>> +# Geometry Shader intrinsics with a vertex count.<br>
>>> +#<br>
>>> +# Alternatively, drivers may implement these intrinsics, and use<br>
>>> +# nir_lower_gs_intrinsics() to convert from the basic intrinsics.<br>
>>> +#<br>
>>> +# These maintain a count of the number of vertices emitted, as an<br>
>>> additional<br>
>>> +# unsigned integer source.<br>
>>> +intrinsic("emit_vertex_with_<wbr>counter", src_comp=[1], indices=[STREAM_ID])<br>
>>> +intrinsic("end_primitive_<wbr>with_counter", src_comp=[1],<br>
>>> indices=[STREAM_ID])<br>
>>> +intrinsic("set_vertex_count", src_comp=[1])<br>
>>> +<br>
>>> +# Atomic counters<br>
>>> +#<br>
>>> +# The *_var variants take an atomic_uint nir_variable, while the other,<br>
>>> +# lowered, variants take a constant buffer index and register offset.<br>
>>> +<br>
>>> +def atomic(name, flags=[]):<br>
>>> + intrinsic(name + "_var", dest_comp=1, num_vars=1, flags=flags)<br>
>>> + intrinsic(name, src_comp=[1], dest_comp=1, indices=[BASE],<br>
>>> flags=flags)<br>
>>> +<br>
>>> +def atomic2(name):<br>
>>> + intrinsic(name + "_var", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> + intrinsic(name, src_comp=[1, 1], dest_comp=1, indices=[BASE])<br>
>>> +<br>
>>> +def atomic3(name):<br>
>>> + intrinsic(name + "_var", src_comp=[1, 1], dest_comp=1, num_vars=1)<br>
>>> + intrinsic(name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])<br>
>>> +<br>
>>> +atomic("atomic_counter_inc")<br>
>>> +atomic("atomic_counter_dec")<br>
>>> +atomic("atomic_counter_read", flags=[CAN_ELIMINATE])<br>
>>> +atomic2("atomic_counter_add")<br>
>>> +atomic2("atomic_counter_min")<br>
>>> +atomic2("atomic_counter_max")<br>
>>> +atomic2("atomic_counter_and")<br>
>>> +atomic2("atomic_counter_or")<br>
>>> +atomic2("atomic_counter_xor")<br>
>>> +atomic2("atomic_counter_<wbr>exchange")<br>
>>> +atomic3("atomic_counter_comp_<wbr>swap")<br>
>>> +<br>
>>> +# Image load, store and atomic intrinsics.<br>
>>> +#<br>
>>> +# All image intrinsics take an image target passed as a nir_variable.<br>
>>> Image<br>
>>> +# variables contain a number of memory and layout qualifiers that<br>
>>> influence<br>
>>> +# the semantics of the intrinsic.<br>
>>> +#<br>
>>> +# All image intrinsics take a four-coordinate vector and a sample index<br>
>>> as<br>
>>> +# first two sources, determining the location within the image that will<br>
>>> be<br>
>>> +# accessed by the intrinsic. Components not applicable to the image<br>
>>> target<br>
>>> +# in use are undefined. Image store takes an additional four-component<br>
>>> +# argument with the value to be written, and image atomic operations take<br>
>>> +# either one or two additional scalar arguments with the same meaning as<br>
>>> in<br>
>>> +# the ARB_shader_image_load_store specification.<br>
>>> +intrinsic("image_load", src_comp=[4, 1], dest_comp=4, num_vars=1,<br>
>>> + flags=[CAN_ELIMINATE])<br>
>>> +intrinsic("image_store", src_comp=[4, 1, 4], num_vars=1)<br>
>>> +intrinsic("image_atomic_add", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_min", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_max", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_and", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_or", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_xor", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_<wbr>exchange", src_comp=[4, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_atomic_comp_<wbr>swap", src_comp=[4, 1, 1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +intrinsic("image_size", dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE,<br>
>>> CAN_REORDER])<br>
>>> +intrinsic("image_samples", dest_comp=1, num_vars=1, flags=[CAN_ELIMINATE,<br>
>>> CAN_REORDER])<br>
>>> +<br>
>>> +# Vulkan descriptor set intrinsics<br>
>>> +#<br>
>>> +# The Vulkan API uses a different binding model from GL. In the Vulkan<br>
>>> +# API, all external resources are represented by a tuple:<br>
>>> +#<br>
>>> +# (descriptor set, binding, array index)<br>
>>> +#<br>
>>> +# where the array index is the only thing allowed to be indirect. The<br>
>>> +# vulkan_surface_index intrinsic takes the descriptor set and binding as<br>
>>> +# its first two indices and the array index as its source. The third<br>
>>> +# index is a nir_variable_mode in case that's useful to the backend.<br>
>>> +#<br>
>>> +# The intended usage is that the shader will call vulkan_surface_index to<br>
>>> +# get an index and then pass that as the buffer index ubo/ssbo calls.<br>
>>> +#<br>
>>> +# The vulkan_resource_reindex intrinsic takes a resource index in src0<br>
>>> +# (the result of a vulkan_resource_index or vulkan_resource_reindex)<br>
>>> which<br>
>>> +# corresponds to the tuple (set, binding, index) and computes an index<br>
>>> +# corresponding to tuple (set, binding, idx + src1).<br>
>>> +intrinsic("vulkan_resource_<wbr>index", src_comp=[1], dest_comp=1,<br>
>>> + indices=[DESC_SET, BINDING], flags=[CAN_ELIMINATE,<br>
>>> CAN_REORDER])<br>
>>> +intrinsic("vulkan_resource_<wbr>reindex", src_comp=[1, 1], dest_comp=1,<br>
>>> + flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +<br>
>>> +# variable atomic intrinsics<br>
>>> +#<br>
>>> +# All of these variable atomic memory operations read a value from<br>
>>> memory,<br>
>>> +# compute a new value using one of the operations below, write the new<br>
>>> value<br>
>>> +# to memory, and return the original value read.<br>
>>> +#<br>
>>> +# All operations take 1 source except CompSwap that takes 2. These<br>
>>> sources<br>
>>> +# represent:<br>
>>> +#<br>
>>> +# 0: The data parameter to the atomic function (i.e. the value to add<br>
>>> +# in shared_atomic_add, etc).<br>
>>> +# 1: For CompSwap only: the second data parameter.<br>
>>> +#<br>
>>> +# All operations take 1 variable deref.<br>
>>> +intrinsic("var_atomic_add", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_imin", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_umin", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_imax", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_umax", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_and", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_or", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_xor", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_<wbr>exchange", src_comp=[1], dest_comp=1, num_vars=1)<br>
>>> +intrinsic("var_atomic_comp_<wbr>swap", src_comp=[1, 1], dest_comp=1,<br>
>>> num_vars=1)<br>
>>> +<br>
>>> +# SSBO atomic intrinsics<br>
>>> +#<br>
>>> +# All of the SSBO atomic memory operations read a value from memory,<br>
>>> +# compute a new value using one of the operations below, write the new<br>
>>> +# value to memory, and return the original value read.<br>
>>> +#<br>
>>> +# All operations take 3 sources except CompSwap that takes 4. These<br>
>>> +# sources represent:<br>
>>> +#<br>
>>> +# 0: The SSBO buffer index.<br>
>>> +# 1: The offset into the SSBO buffer of the variable that the atomic<br>
>>> +# operation will operate on.<br>
>>> +# 2: The data parameter to the atomic function (i.e. the value to add<br>
>>> +# in ssbo_atomic_add, etc).<br>
>>> +# 3: For CompSwap only: the second data parameter.<br>
>>> +intrinsic("ssbo_atomic_add", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_imin", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_umin", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_imax", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_umax", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_and", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_or", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_xor", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_<wbr>exchange", src_comp=[1, 1, 1], dest_comp=1)<br>
>>> +intrinsic("ssbo_atomic_comp_<wbr>swap", src_comp=[1, 1, 1, 1], dest_comp=1)<br>
>>> +<br>
>>> +# CS shared variable atomic intrinsics<br>
>>> +#<br>
>>> +# All of the shared variable atomic memory operations read a value from<br>
>>> +# memory, compute a new value using one of the operations below, write<br>
>>> the<br>
>>> +# new value to memory, and return the original value read.<br>
>>> +#<br>
>>> +# All operations take 2 sources except CompSwap that takes 3. These<br>
>>> +# sources represent:<br>
>>> +#<br>
>>> +# 0: The offset into the shared variable storage region that the atomic<br>
>>> +# operation will operate on.<br>
>>> +# 1: The data parameter to the atomic function (i.e. the value to add<br>
>>> +# in shared_atomic_add, etc).<br>
>>> +# 2: For CompSwap only: the second data parameter.<br>
>>> +intrinsic("shared_atomic_add"<wbr>, src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_<wbr>imin", src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_<wbr>umin", src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_<wbr>imax", src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_<wbr>umax", src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_and"<wbr>, src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_or", src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_xor"<wbr>, src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_<wbr>exchange", src_comp=[1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +intrinsic("shared_atomic_<wbr>comp_swap", src_comp=[1, 1, 1], dest_comp=1,<br>
>>> indices=[BASE])<br>
>>> +<br>
>>> +system_values = {}<br>
>>> +<br>
>>> +def system_value(name, dest_comp, indices=[]):<br>
>>> + assert name not in system_values<br>
>>> + intr = intrinsic("load_" + name, [], dest_comp, 0, indices,<br>
>>> + flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> + system_values[name] = intr<br>
>>> +<br>
>>> +system_value("frag_coord", 4)<br>
>>> +system_value("front_face", 1)<br>
>>> +system_value("vertex_id", 1)<br>
>>> +system_value("vertex_id_zero_<wbr>base", 1)<br>
>>> +system_value("base_vertex", 1)<br>
>>> +system_value("instance_id", 1)<br>
>>> +system_value("base_instance", 1)<br>
>>> +system_value("draw_id", 1)<br>
>>> +system_value("sample_id", 1)<br>
>>> +system_value("sample_pos", 2)<br>
>>> +system_value("sample_mask_in"<wbr>, 1)<br>
>>> +system_value("primitive_id", 1)<br>
>>> +system_value("invocation_id", 1)<br>
>>> +system_value("tess_coord", 3)<br>
>>> +system_value("tess_level_<wbr>outer", 4)<br>
>>> +system_value("tess_level_<wbr>inner", 2)<br>
>>> +system_value("patch_vertices_<wbr>in", 1)<br>
>>> +system_value("local_<wbr>invocation_id", 3)<br>
>>> +system_value("local_<wbr>invocation_index", 1)<br>
>>> +system_value("work_group_id", 3)<br>
>>> +system_value("user_clip_<wbr>plane", 4, indices=[UCP_ID])<br>
>>> +system_value("num_work_<wbr>groups", 3)<br>
>>> +system_value("helper_<wbr>invocation", 1)<br>
>>> +system_value("alpha_ref_<wbr>float", 1)<br>
>>> +system_value("layer_id", 1)<br>
>>> +system_value("view_index", 1)<br>
>>> +system_value("subgroup_size", 1)<br>
>>> +system_value("subgroup_<wbr>invocation", 1)<br>
>>> +system_value("subgroup_eq_<wbr>mask", 0)<br>
>>> +system_value("subgroup_ge_<wbr>mask", 0)<br>
>>> +system_value("subgroup_gt_<wbr>mask", 0)<br>
>>> +system_value("subgroup_le_<wbr>mask", 0)<br>
>>> +system_value("subgroup_lt_<wbr>mask", 0)<br>
>>> +system_value("num_subgroups", 1)<br>
>>> +system_value("subgroup_id", 1)<br>
>>> +system_value("local_group_<wbr>size", 3)<br>
>>> +<br>
>>> +# Blend constant color values. Float values are clamped.#<br>
>>> +system_value("blend_const_<wbr>color_r_float", 1)<br>
>>> +system_value("blend_const_<wbr>color_g_float", 1)<br>
>>> +system_value("blend_const_<wbr>color_b_float", 1)<br>
>>> +system_value("blend_const_<wbr>color_a_float", 1)<br>
>>> +system_value("blend_const_<wbr>color_rgba8888_unorm", 1)<br>
>>> +system_value("blend_const_<wbr>color_aaaa8888_unorm", 1)<br>
>>> +<br>
>>> +# Barycentric coordinate intrinsics.<br>
>>> +#<br>
>>> +# These set up the barycentric coordinates for a particular<br>
>>> interpolation.<br>
>>> +# The first three are for the simple cases: pixel, centroid, or<br>
>>> per-sample<br>
>>> +# (at gl_SampleID). The next two handle interpolating at a specified<br>
>>> +# sample location, or interpolating with a vec2 offset,<br>
>>> +#<br>
>>> +# The interp_mode index should be either the INTERP_MODE_SMOOTH or<br>
>>> +# INTERP_MODE_NOPERSPECTIVE enum values.<br>
>>> +#<br>
>>> +# The vec2 value produced by these intrinsics is intended for use as the<br>
>>> +# barycoord source of a load_interpolated_input intrinsic.<br>
>>> +<br>
>>> +def barycentric(name, src_comp=[]):<br>
>>> + intrinsic("load_barycentric_" + name, src_comp=src_comp, dest_comp=2,<br>
>>> + indices=[INTERP_MODE], flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +<br>
>>> +# no sources. const_index[] = { interp_mode }<br>
>>> +barycentric("pixel")<br>
>>> +barycentric("centroid")<br>
>>> +barycentric("sample")<br>
>>> +# src[] = { sample_id }. const_index[] = { interp_mode }<br>
>>> +barycentric("at_sample", [1])<br>
>>> +# src[] = { offset.xy }. const_index[] = { interp_mode }<br>
>>> +barycentric("at_offset", [2])<br>
>>> +<br>
>>> +# Load operations pull data from some piece of GPU memory. All load<br>
>>> +# operations operate in terms of offsets into some piece of theoretical<br>
>>> +# memory. Loads from externally visible memory (UBO and SSBO) simply<br>
>>> take a<br>
>>> +# byte offset as a source. Loads from opaque memory (uniforms, inputs,<br>
>>> etc.)<br>
>>> +# take a base+offset pair where the base (const_index[0]) gives the<br>
>>> location<br>
>>> +# of the start of the variable being loaded and and the offset source is<br>
>>> a<br>
>>> +# offset into that variable.<br>
>>> +#<br>
>>> +# Uniform load operations have a second "range" index that specifies the<br>
>>> +# range (starting at base) of the data from which we are loading. If<br>
>>> +# const_index[1] == 0, then the range is unknown.<br>
>>> +#<br>
>>> +# Some load operations such as UBO/SSBO load and per_vertex loads take an<br>
>>> +# additional source to specify which UBO/SSBO/vertex to load from.<br>
>>> +#<br>
>>> +# The exact address type depends on the lowering pass that generates the<br>
>>> +# load/store intrinsics. Typically, this is vec4 units for things such<br>
>>> as<br>
>>> +# varying slots and float units for fragment shader inputs. UBO and SSBO<br>
>>> +# offsets are always in bytes.<br>
>>> +<br>
>>> +def load(name, num_srcs, indices=[], flags=[]):<br>
>>> + intrinsic("load_" + name, [1] * num_srcs, dest_comp=0,<br>
>>> indices=indices,<br>
>>> + flags=flags)<br>
>>> +<br>
>>> +# src[] = { offset }. const_index[] = { base, range }<br>
>>> +load("uniform", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])<br>
>>> +# src[] = { buffer_index, offset }. No const_index<br>
>>> +load("ubo", 2, flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +# src[] = { offset }. const_index[] = { base, component }<br>
>>> +load("input", 1, [BASE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER])<br>
>>> +# src[] = { vertex, offset }. const_index[] = { base, component }<br>
>>> +load("per_vertex_input", 2, [BASE, COMPONENT], [CAN_ELIMINATE,<br>
>>> CAN_REORDER])<br>
>>> +# src[] = { barycoord, offset }. const_index[] = { base, component }<br>
>>> +intrinsic("load_interpolated_<wbr>input", src_comp=[2, 1], dest_comp=0,<br>
>>> + indices=[BASE, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER])<br>
>>> +<br>
>>> +# src[] = { buffer_index, offset }. No const_index<br>
>>> +load("ssbo", 2, flags=[CAN_ELIMINATE])<br>
>>> +# src[] = { offset }. const_index[] = { base, component }<br>
>>> +load("output", 1, [BASE, COMPONENT], flags=[CAN_ELIMINATE])<br>
>>> +# src[] = { vertex, offset }. const_index[] = { base, component }<br>
>>> +load("per_vertex_output", 2, [BASE, COMPONENT], [CAN_ELIMINATE])<br>
>>> +# src[] = { offset }. const_index[] = { base }<br>
>>> +load("shared", 1, [BASE], [CAN_ELIMINATE])<br>
>>> +# src[] = { offset }. const_index[] = { base, range }<br>
>>> +load("push_constant", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])<br>
>>> +<br>
>>> +# Stores work the same way as loads, except now the first source is the<br>
>>> value<br>
>>> +# to store and the second (and possibly third) source specify where to<br>
>>> store<br>
>>> +# the value. SSBO and shared memory stores also have a write mask as<br>
>>> +# const_index[0].<br>
>>> +<br>
>>> +def store(name, num_srcs, indices=[], flags=[]):<br>
>>> + intrinsic("store_" + name, [0] + ([1] * (num_srcs - 1)),<br>
>>> indices=indices, flags=flags)<br>
>>> +<br>
>>> +# src[] = { value, offset }. const_index[] = { base, write_mask,<br>
>>> component }<br>
>>> +store("output", 2, [BASE, WRMASK, COMPONENT])<br>
>>> +# src[] = { value, vertex, offset }.<br>
>>> +# const_index[] = { base, write_mask, component }<br>
>>> +store("per_vertex_output", 3, [BASE, WRMASK, COMPONENT])<br>
>>> +# src[] = { value, block_index, offset }. const_index[] = { write_mask }<br>
>>> +store("ssbo", 3, [WRMASK])<br>
>>> +# src[] = { value, offset }. const_index[] = { base, write_mask }<br>
>>> +store("shared", 2, [BASE, WRMASK])<br>
>>> diff --git a/src/compiler/nir/nir_<wbr>intrinsics.c<br>
>>> b/src/compiler/nir/nir_<wbr>intrinsics_c.py<br>
>>> similarity index 59%<br>
>>> rename from src/compiler/nir/nir_<wbr>intrinsics.c<br>
>>> rename to src/compiler/nir/nir_<wbr>intrinsics_c.py<br>
>>> index 0257b19b348..22b5e5823ed 100644<br>
>>> --- a/src/compiler/nir/nir_<wbr>intrinsics.c<br>
>>> +++ b/src/compiler/nir/nir_<wbr>intrinsics_c.py<br>
>>> @@ -1,5 +1,6 @@<br>
>>> -/*<br>
>>> - * Copyright © 2014 Intel Corporation<br>
>>> +<br>
>>> +template = """\<br>
>>> +/* Copyright (C) 2018 Red Hat<br>
>>> *<br>
>>> * Permission is hereby granted, free of charge, to any person obtaining<br>
>>> a<br>
>>> * copy of this software and associated documentation files (the<br>
>>> "Software"),<br>
>>> @@ -19,39 +20,32 @@<br>
>>> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
>>> ARISING<br>
>>> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
>>> DEALINGS<br>
>>> * IN THE SOFTWARE.<br>
>>> - *<br>
>>> - * Authors:<br>
>>> - * Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
>>> - *<br>
>>> */<br>
>>><br>
>>> #include "nir.h"<br>
>>><br>
>>> -#define OPCODE(name) nir_intrinsic_##name<br>
>>> -<br>
>>> -#define INTRINSIC(_name, _num_srcs, _src_components, _has_dest, \<br>
>>> - _dest_components, _num_variables, _num_indices, \<br>
>>> - idx0, idx1, idx2, _flags) \<br>
>>> -{ \<br>
>>> - .name = #_name, \<br>
>>> - .num_srcs = _num_srcs, \<br>
>>> - .src_components = _src_components, \<br>
>>> - .has_dest = _has_dest, \<br>
>>> - .dest_components = _dest_components, \<br>
>>> - .num_variables = _num_variables, \<br>
>>> - .num_indices = _num_indices, \<br>
>>> - .index_map = { \<br>
>>> - [NIR_INTRINSIC_ ## idx0] = 1, \<br>
>>> - [NIR_INTRINSIC_ ## idx1] = 2, \<br>
>>> - [NIR_INTRINSIC_ ## idx2] = 3, \<br>
>>> - }, \<br>
>>> - .flags = _flags \<br>
>>> +const nir_intrinsic_info nir_intrinsic_infos[nir_num_<wbr>intrinsics] = {<br>
>>> +% for name, opcode in sorted(intr_opcodes.iteritems(<wbr>)):<br>
>>> +{<br>
>>> + .name = "${name}",<br>
>>> + .num_srcs = ${opcode.num_srcs},<br>
>>> + .src_components = {<br>
>>> + ${ ", ".join(str(comp) for comp in opcode.src_components) }<br>
>>> + },<br>
>>> + .has_dest = ${ "TRUE" if opcode.has_dest else "FALSE" },<br>
>>> + .dest_components = ${opcode.dest_components},<br>
>>> + .num_variables = ${opcode.num_variables},<br>
>>> + .num_indices = ${opcode.num_indices},<br>
>>> + .index_map = {<br>
>>> + ${ ", ".join(str(idx) for idx in opcode.indices) }<br>
>>> + },<br>
>>> + .flags = ${ "0" if len(opcode.flags) == 0 else " |<br>
>>> ".join(opcode.flags) },<br>
>>> },<br>
>>> +% endfor<br>
>>> +};<br>
>>> +"""<br>
>>><br>
>>> -#define NIR_INTRINSIC_xx 0<br>
>>> -<br>
>>> -#define LAST_INTRINSIC(name)<br>
>>> +from nir_intrinsics import intr_opcodes<br>
>>> +from mako.template import Template<br>
>>><br>
>>> -const nir_intrinsic_info nir_intrinsic_infos[nir_num_<wbr>intrinsics] = {<br>
>>> -#include "nir_intrinsics.h"<br>
>>> -};<br>
>>> \ No newline at end of file<br>
>>> +print Template(template).render(<wbr>intr_opcodes=intr_opcodes)<br>
>>> diff --git a/src/compiler/nir/nir_<wbr>intrinsics_h.py<br>
>>> b/src/compiler/nir/nir_<wbr>intrinsics_h.py<br>
>>> new file mode 100644<br>
>>> index 00000000000..000ed53f25d<br>
>>> --- /dev/null<br>
>>> +++ b/src/compiler/nir/nir_<wbr>intrinsics_h.py<br>
>>> @@ -0,0 +1,44 @@<br>
>>> +<br>
>>> +template = """\<br>
>>> +/* Copyright (C) 2018 Red Hat<br>
>>> + *<br>
>>> + * Permission is hereby granted, free of charge, to any person obtaining<br>
>>> a<br>
>>> + * copy of this software and associated documentation files (the<br>
>>> "Software"),<br>
>>> + * to deal in the Software without restriction, including without<br>
>>> limitation<br>
>>> + * the rights to use, copy, modify, merge, publish, distribute,<br>
>>> sublicense,<br>
>>> + * and/or sell copies of the Software, and to permit persons to whom the<br>
>>> + * Software is furnished to do so, subject to the following conditions:<br>
>>> + *<br>
>>> + * The above copyright notice and this permission notice (including the<br>
>>> next<br>
>>> + * paragraph) shall be included in all copies or substantial portions of<br>
>>> the<br>
>>> + * Software.<br>
>>> + *<br>
>>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
>>> EXPRESS OR<br>
>>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
>>> MERCHANTABILITY,<br>
>>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT<br>
>>> SHALL<br>
>>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
>>> OTHER<br>
>>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
>>> ARISING<br>
>>> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
>>> DEALINGS<br>
>>> + * IN THE SOFTWARE.<br>
>>> + */<br>
>>> +<br>
>>> +#ifndef _NIR_INTRINSICS_<br>
>>> +#define _NIR_INTRINSICS_<br>
>>> +<br>
>>> +<% opcode_names = sorted(intr_opcodes.iterkeys()<wbr>) %><br>
>>> +<br>
>>> +typedef enum {<br>
>>> +% for name in opcode_names:<br>
>>> + nir_intrinsic_${name},<br>
>>> +% endfor<br>
>>> +<br>
>>> + nir_last_intrinsic = nir_intrinsic_${opcode_names[-<wbr>1]},<br>
>>> + nir_num_intrinsics = nir_last_intrinsic + 1<br>
>>> +} nir_intrinsic_op;<br>
>>> +<br>
>>> +#endif /* _NIR_INTRINSICS_ */"""<br>
>>> +<br>
>>> +from nir_intrinsics import intr_opcodes<br>
>>> +from mako.template import Template<br>
>>> +<br>
>>> +print Template(template).render(<wbr>intr_opcodes=intr_opcodes)<br>
>>> --<br>
>>> 2.14.3<br>
>>><br>
>><br>
>><br>
</div></div></blockquote></div><br></div></div>