summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2018-03-15 18:42:44 -0400
committerRob Clark <[email protected]>2018-03-27 08:36:37 -0400
commit76dfed8ae2d5c6c509eb2661389be3c6a25077df (patch)
treee811d58f7f277c7844c3421eab1203e7d55607a2 /src/compiler
parentcc3a88e81dbceb12b79eb4ebe7a4ce5ba97fc291 (diff)
nir: mako all the intrinsics
I threatened to do this a long time ago.. I probably *should* have done it a long time ago when there where many fewer intrinsics. But the system of macro/#include magic for dealing with intrinsics is a bit annoying, and python has the nice property of optional fxn params, making it possible to define new intrinsics while ignoring parameters that are not applicable (and naming optional params). And not having to specify various array lengths explicitly is nice too. I think the end result makes it easier to add new intrinsics. v2: couple small fixes found with a test program to compare the old and new tables v3: misc comments, don't rely on capture=true for meson.build, get rid of system_values table to avoid return value of intrinsic() and *mostly* remove side-effects, add autotools build support v4: scons build Signed-off-by: Rob Clark <[email protected]> Acked-by: Dylan Baker <[email protected]> Acked-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/Makefile.nir.am13
-rw-r--r--src/compiler/Makefile.sources4
-rw-r--r--src/compiler/SConscript.nir16
-rw-r--r--src/compiler/nir/meson.build24
-rw-r--r--src/compiler/nir/nir.h9
-rw-r--r--src/compiler/nir/nir_builder.h27
-rw-r--r--src/compiler/nir/nir_builder_opcodes_h.py24
-rw-r--r--src/compiler/nir/nir_intrinsics.h540
-rw-r--r--src/compiler/nir/nir_intrinsics.py546
-rw-r--r--src/compiler/nir/nir_intrinsics_c.py68
-rw-r--r--src/compiler/nir/nir_intrinsics_h.py (renamed from src/compiler/nir/nir_intrinsics.c)75
11 files changed, 727 insertions, 619 deletions
diff --git a/src/compiler/Makefile.nir.am b/src/compiler/Makefile.nir.am
index 28033256762..d805f573d51 100644
--- a/src/compiler/Makefile.nir.am
+++ b/src/compiler/Makefile.nir.am
@@ -32,7 +32,7 @@ nir_libnir_la_SOURCES = \
$(SPIRV_GENERATED_FILES) \
$(NIR_GENERATED_FILES)
-nir/nir_builder_opcodes.h: nir/nir_opcodes.py nir/nir_builder_opcodes_h.py
+nir/nir_builder_opcodes.h: nir/nir_opcodes.py nir/nir_builder_opcodes_h.py nir/nir_intrinsics.py
$(MKDIR_GEN)
$(PYTHON_GEN) $(srcdir)/nir/nir_builder_opcodes_h.py > $@ || ($(RM) $@; false)
@@ -40,6 +40,14 @@ nir/nir_constant_expressions.c: nir/nir_opcodes.py nir/nir_constant_expressions.
$(MKDIR_GEN)
$(PYTHON_GEN) $(srcdir)/nir/nir_constant_expressions.py > $@ || ($(RM) $@; false)
+nir/nir_intrinsics.h: nir/nir_intrinsics.py nir/nir_intrinsics_h.py
+ $(MKDIR_GEN)
+ $(PYTHON_GEN) $(srcdir)/nir/nir_intrinsics_h.py --outdir nir || ($(RM) $@; false)
+
+nir/nir_intrinsics.c: nir/nir_intrinsics.py nir/nir_intrinsics_c.py
+ $(MKDIR_GEN)
+ $(PYTHON_GEN) $(srcdir)/nir/nir_intrinsics_c.py --outdir nir || ($(RM) $@; false)
+
nir/nir_opcodes.h: nir/nir_opcodes.py nir/nir_opcodes_h.py
$(MKDIR_GEN)
$(PYTHON_GEN) $(srcdir)/nir/nir_opcodes_h.py > $@ || ($(RM) $@; false)
@@ -112,6 +120,9 @@ EXTRA_DIST += \
nir/nir_algebraic.py \
nir/nir_builder_opcodes_h.py \
nir/nir_constant_expressions.py \
+ nir/nir_intrinsics.py \
+ nir/nir_intrinsics_c.py \
+ nir/nir_intrinsics_h.py \
nir/nir_opcodes.py \
nir/nir_opcodes_c.py \
nir/nir_opcodes_h.py \
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 2dc48365507..273ce4cde49 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -182,6 +182,8 @@ LIBGLCPP_GENERATED_FILES = \
NIR_GENERATED_FILES = \
nir/nir_builder_opcodes.h \
nir/nir_constant_expressions.c \
+ nir/nir_intrinsics.c \
+ nir/nir_intrinsics.h \
nir/nir_opcodes.c \
nir/nir_opcodes.h \
nir/nir_opt_algebraic.c
@@ -202,8 +204,6 @@ NIR_FILES = \
nir/nir_inline_functions.c \
nir/nir_instr_set.c \
nir/nir_instr_set.h \
- nir/nir_intrinsics.c \
- nir/nir_intrinsics.h \
nir/nir_linking_helpers.c \
nir/nir_liveness.c \
nir/nir_loop_analyze.c \
diff --git a/src/compiler/SConscript.nir b/src/compiler/SConscript.nir
index 3c685a2dc5f..41c67941f51 100644
--- a/src/compiler/SConscript.nir
+++ b/src/compiler/SConscript.nir
@@ -59,6 +59,22 @@ env.CodeGenerate(
command = python_cmd + ' $SCRIPT > $TARGET'
)
+bldroot = Dir('.').abspath
+
+env.CodeGenerate(
+ target = 'nir/nir_intrinsics.h',
+ script = 'nir/nir_intrinsics_h.py',
+ source = [],
+ command = python_cmd + ' $SCRIPT --outdir ' + bldroot + '/nir'
+)
+
+env.CodeGenerate(
+ target = 'nir/nir_intrinsics.c',
+ script = 'nir/nir_intrinsics_c.py',
+ source = [],
+ command = python_cmd + ' $SCRIPT --outdir ' + bldroot + '/nir'
+)
+
# parse Makefile.sources
source_lists = env.ParseSourceList('Makefile.sources')
diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
index 887035d7595..cbee73256ef 100644
--- a/src/compiler/nir/meson.build
+++ b/src/compiler/nir/meson.build
@@ -65,6 +65,24 @@ nir_opt_algebraic_c = custom_target(
depend_files : files('nir_algebraic.py'),
)
+nir_intrinsics_h = custom_target(
+ 'nir_intrinsics.h',
+ input : 'nir_intrinsics_h.py',
+ output : 'nir_intrinsics.h',
+ command : [prog_python2, '@INPUT@', '--outdir', meson.current_build_dir()],
+ capture : false,
+ depend_files : files('nir_intrinsics.py'),
+)
+
+nir_intrinsics_c = custom_target(
+ 'nir_intrinsic.c',
+ input : 'nir_intrinsics_c.py',
+ output : 'nir_intrinsics.c',
+ command : [prog_python2, '@INPUT@', '--outdir', meson.current_build_dir()],
+ capture: false,
+ depend_files : files('nir_intrinsics.py'),
+)
+
spirv_info_c = custom_target(
'spirv_info.c',
input : files('../spirv/spirv_info_c.py', '../spirv/spirv.core.grammar.json'),
@@ -96,8 +114,6 @@ files_libnir = files(
'nir_inline_functions.c',
'nir_instr_set.c',
'nir_instr_set.h',
- 'nir_intrinsics.c',
- 'nir_intrinsics.h',
'nir_linking_helpers.c',
'nir_liveness.c',
'nir_loop_analyze.c',
@@ -202,7 +218,7 @@ libnir = static_library(
'nir',
[files_libnir, spirv_info_c, nir_opt_algebraic_c, nir_opcodes_c,
nir_opcodes_h, nir_constant_expressions_c, nir_builder_opcodes_h,
- vtn_gather_types_c],
+ vtn_gather_types_c, nir_intrinsics_c, nir_intrinsics_h],
include_directories : [inc_common, inc_compiler, include_directories('../spirv')],
c_args : [c_vis_args, c_msvc_compat_args, no_override_init_args],
link_with : libcompiler,
@@ -211,7 +227,7 @@ libnir = static_library(
# Headers-only dependency
idep_nir_headers = declare_dependency(
- sources : [nir_opcodes_h, nir_builder_opcodes_h],
+ sources : [nir_opcodes_h, nir_builder_opcodes_h, nir_intrinsics_h],
include_directories : include_directories('.'),
)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 0d207d0ea54..b474567be1c 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -945,16 +945,7 @@ typedef struct {
struct nir_function *callee;
} nir_call_instr;
-#define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
- num_variables, num_indices, idx0, idx1, idx2, flags) \
- nir_intrinsic_##name,
-
-#define LAST_INTRINSIC(name) nir_last_intrinsic = nir_intrinsic_##name,
-
-typedef enum {
#include "nir_intrinsics.h"
- nir_num_intrinsics = nir_last_intrinsic + 1
-} nir_intrinsic_op;
#define NIR_INTRINSIC_MAX_CONST_INDEX 3
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 36e0ae3ac63..8f7ddf1483c 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -610,32 +610,7 @@ nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src)
nir_builder_instr_insert(build, &copy->instr);
}
-/* Generic builder for system values. */
-static inline nir_ssa_def *
-nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index)
-{
- nir_intrinsic_instr *load = nir_intrinsic_instr_create(build->shader, op);
- load->num_components = nir_intrinsic_infos[op].dest_components;
- load->const_index[0] = index;
- nir_ssa_dest_init(&load->instr, &load->dest,
- nir_intrinsic_infos[op].dest_components, 32, NULL);
- nir_builder_instr_insert(build, &load->instr);
- return &load->dest.ssa;
-}
-
-/* Generate custom builders for system values. */
-#define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
- num_variables, num_indices, idx0, idx1, idx2, flags)
-#define LAST_INTRINSIC(name)
-
-#define DEFINE_SYSTEM_VALUE(name) \
- static inline nir_ssa_def * \
- nir_load_##name(nir_builder *build) \
- { \
- return nir_load_system_value(build, nir_intrinsic_load_##name, 0); \
- }
-
-#include "nir_intrinsics.h"
+#include "nir_builder_opcodes.h"
static inline nir_ssa_def *
nir_load_barycentric(nir_builder *build, nir_intrinsic_op op,
diff --git a/src/compiler/nir/nir_builder_opcodes_h.py b/src/compiler/nir/nir_builder_opcodes_h.py
index bdabe578ce2..4a41e6079ed 100644
--- a/src/compiler/nir/nir_builder_opcodes_h.py
+++ b/src/compiler/nir/nir_builder_opcodes_h.py
@@ -41,9 +41,31 @@ nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
}
% endfor
+/* Generic builder for system values. */
+static inline nir_ssa_def *
+nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index)
+{
+ nir_intrinsic_instr *load = nir_intrinsic_instr_create(build->shader, op);
+ load->num_components = nir_intrinsic_infos[op].dest_components;
+ load->const_index[0] = index;
+ nir_ssa_dest_init(&load->instr, &load->dest,
+ nir_intrinsic_infos[op].dest_components, 32, NULL);
+ nir_builder_instr_insert(build, &load->instr);
+ return &load->dest.ssa;
+}
+
+% for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.iteritems())):
+static inline nir_ssa_def *
+nir_${name}(nir_builder *build)
+{
+ return nir_load_system_value(build, nir_intrinsic_${name}, 0);
+}
+% endfor
+
#endif /* _NIR_BUILDER_OPCODES_ */"""
from nir_opcodes import opcodes
+from nir_intrinsics import INTR_OPCODES
from mako.template import Template
-print Template(template).render(opcodes=opcodes)
+print Template(template).render(opcodes=opcodes, INTR_OPCODES=INTR_OPCODES)
diff --git a/src/compiler/nir/nir_intrinsics.h b/src/compiler/nir/nir_intrinsics.h
deleted file mode 100644
index df2790869ba..00000000000
--- a/src/compiler/nir/nir_intrinsics.h
+++ /dev/null
@@ -1,540 +0,0 @@
-/*
- * Copyright © 2014 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- * Connor Abbott ([email protected])
- *
- */
-
-/**
- * This header file defines all the available intrinsics in one place. It
- * expands to a list of macros of the form:
- *
- * INTRINSIC(name, num_srcs, src_components, has_dest, dest_components,
- * num_variables, num_indices, idx0, idx1, idx2, flags)
- *
- * Which should correspond one-to-one with the nir_intrinsic_info structure. It
- * is included in both ir.h to create the nir_intrinsic enum (with members of
- * the form nir_intrinsic_(name)) and and in opcodes.c to create
- * nir_intrinsic_infos, which is a const array of nir_intrinsic_info structures
- * for each intrinsic.
- */
-
-#define ARR(...) { __VA_ARGS__ }
-
-INTRINSIC(nop, 0, ARR(0), false, 0, 0, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE)
-
-INTRINSIC(load_var, 0, ARR(0), true, 0, 1, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(store_var, 1, ARR(0), false, 0, 1, 1, WRMASK, xx, xx, 0)
-INTRINSIC(copy_var, 0, ARR(0), false, 0, 2, 0, xx, xx, xx, 0)
-
-/*
- * Interpolation of input. The interp_var_at* intrinsics are similar to the
- * load_var intrinsic acting on a shader input except that they interpolate
- * the input differently. The at_sample and at_offset intrinsics take an
- * additional source that is an integer sample id or a vec2 position offset
- * respectively.
- */
-
-INTRINSIC(interp_var_at_centroid, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-INTRINSIC(interp_var_at_sample, 1, ARR(1), true, 0, 1, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-INTRINSIC(interp_var_at_offset, 1, ARR(2), true, 0, 1, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/*
- * Ask the driver for the size of a given buffer. It takes the buffer index
- * as source.
- */
-INTRINSIC(get_buffer_size, 1, ARR(1), true, 1, 0, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/*
- * a barrier is an intrinsic with no inputs/outputs but which can't be moved
- * around/optimized in general
- */
-#define BARRIER(name) INTRINSIC(name, 0, ARR(0), false, 0, 0, 0, xx, xx, xx, 0)
-
-BARRIER(barrier)
-BARRIER(discard)
-
-/*
- * Memory barrier with semantics analogous to the memoryBarrier() GLSL
- * intrinsic.
- */
-BARRIER(memory_barrier)
-
-/*
- * Shader clock intrinsic with semantics analogous to the clock2x32ARB()
- * GLSL intrinsic.
- * The latter can be used as code motion barrier, which is currently not
- * feasible with NIR.
- */
-INTRINSIC(shader_clock, 0, ARR(0), true, 2, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-/*
- * Shader ballot intrinsics with semantics analogous to the
- *
- * ballotARB()
- * readInvocationARB()
- * readFirstInvocationARB()
- *
- * GLSL functions from ARB_shader_ballot.
- */
-INTRINSIC(ballot, 1, ARR(1), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(read_invocation, 2, ARR(0, 1), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(read_first_invocation, 1, ARR(0), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-/** Additional SPIR-V ballot intrinsics
- *
- * These correspond to the SPIR-V opcodes
- *
- * OpGroupUniformElect
- * OpSubgroupFirstInvocationKHR
- */
-INTRINSIC(elect, 0, ARR(0), true, 1, 0, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(first_invocation, 0, ARR(0), true, 1, 0, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE)
-
-/*
- * Memory barrier with semantics analogous to the compute shader
- * groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
- * memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
- */
-BARRIER(group_memory_barrier)
-BARRIER(memory_barrier_atomic_counter)
-BARRIER(memory_barrier_buffer)
-BARRIER(memory_barrier_image)
-BARRIER(memory_barrier_shared)
-
-/** A conditional discard, with a single boolean source. */
-INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)
-
-/** ARB_shader_group_vote intrinsics */
-INTRINSIC(vote_any, 1, ARR(1), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(vote_all, 1, ARR(1), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(vote_feq, 1, ARR(0), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(vote_ieq, 1, ARR(0), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-/** Ballot ALU operations from SPIR-V.
- *
- * These operations work like their ALU counterparts except that the operate
- * on a uvec4 which is treated as a 128bit integer. Also, they are, in
- * general, free to ignore any bits which are above the subgroup size.
- */
-INTRINSIC(ballot_bitfield_extract, 2, ARR(4, 1), true, 1, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(ballot_bit_count_reduce, 1, ARR(4), true, 1, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(ballot_bit_count_inclusive, 1, ARR(4), true, 1, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(ballot_bit_count_exclusive, 1, ARR(4), true, 1, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(ballot_find_lsb, 1, ARR(4), true, 1, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(ballot_find_msb, 1, ARR(4), true, 1, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-/** Shuffle operations from SPIR-V. */
-INTRINSIC(shuffle, 2, ARR(0, 1), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(shuffle_xor, 2, ARR(0, 1), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(shuffle_up, 2, ARR(0, 1), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(shuffle_down, 2, ARR(0, 1), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-/** Quad operations from SPIR-V. */
-INTRINSIC(quad_broadcast, 2, ARR(0, 1), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(quad_swap_horizontal, 1, ARR(0), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(quad_swap_vertical, 1, ARR(0), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(quad_swap_diagonal, 1, ARR(0), true, 0, 0,
- 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-INTRINSIC(reduce, 1, ARR(0), true, 0, 0,
- 2, REDUCTION_OP, CLUSTER_SIZE, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(inclusive_scan, 1, ARR(0), true, 0, 0,
- 1, REDUCTION_OP, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(exclusive_scan, 1, ARR(0), true, 0, 0,
- 1, REDUCTION_OP, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-
-/**
- * Basic Geometry Shader intrinsics.
- *
- * emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
- * index, which is the stream ID to write to.
- *
- * end_primitive implements GLSL's EndPrimitive() built-in.
- */
-INTRINSIC(emit_vertex, 0, ARR(0), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
-INTRINSIC(end_primitive, 0, ARR(0), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
-
-/**
- * Geometry Shader intrinsics with a vertex count.
- *
- * Alternatively, drivers may implement these intrinsics, and use
- * nir_lower_gs_intrinsics() to convert from the basic intrinsics.
- *
- * These maintain a count of the number of vertices emitted, as an additional
- * unsigned integer source.
- */
-INTRINSIC(emit_vertex_with_counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
-INTRINSIC(end_primitive_with_counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
-INTRINSIC(set_vertex_count, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)
-
-/*
- * Atomic counters
- *
- * The *_var variants take an atomic_uint nir_variable, while the other,
- * lowered, variants take a constant buffer index and register offset.
- */
-
-#define ATOMIC(name, flags) \
- INTRINSIC(name##_var, 0, ARR(0), true, 1, 1, 0, xx, xx, xx, flags) \
- INTRINSIC(name, 1, ARR(1), true, 1, 0, 1, BASE, xx, xx, flags)
-#define ATOMIC2(name) \
- INTRINSIC(name##_var, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0) \
- INTRINSIC(name, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-#define ATOMIC3(name) \
- INTRINSIC(name##_var, 2, ARR(1, 1), true, 1, 1, 0, xx, xx, xx, 0) \
- INTRINSIC(name, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-
-ATOMIC(atomic_counter_inc, 0)
-ATOMIC(atomic_counter_dec, 0)
-ATOMIC(atomic_counter_read, NIR_INTRINSIC_CAN_ELIMINATE)
-ATOMIC2(atomic_counter_add)
-ATOMIC2(atomic_counter_min)
-ATOMIC2(atomic_counter_max)
-ATOMIC2(atomic_counter_and)
-ATOMIC2(atomic_counter_or)
-ATOMIC2(atomic_counter_xor)
-ATOMIC2(atomic_counter_exchange)
-ATOMIC3(atomic_counter_comp_swap)
-
-/*
- * Image load, store and atomic intrinsics.
- *
- * All image intrinsics take an image target passed as a nir_variable. Image
- * variables contain a number of memory and layout qualifiers that influence
- * the semantics of the intrinsic.
- *
- * All image intrinsics take a four-coordinate vector and a sample index as
- * first two sources, determining the location within the image that will be
- * accessed by the intrinsic. Components not applicable to the image target
- * in use are undefined. Image store takes an additional four-component
- * argument with the value to be written, and image atomic operations take
- * either one or two additional scalar arguments with the same meaning as in
- * the ARB_shader_image_load_store specification.
- */
-INTRINSIC(image_var_load, 2, ARR(4, 1), true, 4, 1, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE)
-INTRINSIC(image_var_store, 3, ARR(4, 1, 4), false, 0, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_add, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_min, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_max, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_and, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_or, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_xor, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_exchange, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_atomic_comp_swap, 4, ARR(4, 1, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(image_var_size, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-INTRINSIC(image_var_samples, 0, ARR(0), true, 1, 1, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/*
- * Vulkan descriptor set intrinsics
- *
- * The Vulkan API uses a different binding model from GL. In the Vulkan
- * API, all external resources are represented by a tuple:
- *
- * (descriptor set, binding, array index)
- *
- * where the array index is the only thing allowed to be indirect. The
- * vulkan_surface_index intrinsic takes the descriptor set and binding as
- * its first two indices and the array index as its source. The third
- * index is a nir_variable_mode in case that's useful to the backend.
- *
- * The intended usage is that the shader will call vulkan_surface_index to
- * get an index and then pass that as the buffer index ubo/ssbo calls.
- *
- * The vulkan_resource_reindex intrinsic takes a resource index in src0
- * (the result of a vulkan_resource_index or vulkan_resource_reindex) which
- * corresponds to the tuple (set, binding, index) and computes an index
- * corresponding to tuple (set, binding, idx + src1).
- */
-INTRINSIC(vulkan_resource_index, 1, ARR(1), true, 1, 0, 2,
- DESC_SET, BINDING, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-INTRINSIC(vulkan_resource_reindex, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/*
- * variable atomic intrinsics
- *
- * All of these variable atomic memory operations read a value from memory,
- * compute a new value using one of the operations below, write the new value
- * to memory, and return the original value read.
- *
- * All operations take 1 source except CompSwap that takes 2. These sources
- * represent:
- *
- * 0: The data parameter to the atomic function (i.e. the value to add
- * in shared_atomic_add, etc).
- * 1: For CompSwap only: the second data parameter.
- *
- * All operations take 1 variable deref.
- */
-INTRINSIC(var_atomic_add, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_imin, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_umin, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_imax, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_umax, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_and, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_or, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_xor, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_exchange, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
-INTRINSIC(var_atomic_comp_swap, 2, ARR(1, 1), true, 1, 1, 0, xx, xx, xx, 0)
-
-/*
- * SSBO atomic intrinsics
- *
- * All of the SSBO atomic memory operations read a value from memory,
- * compute a new value using one of the operations below, write the new
- * value to memory, and return the original value read.
- *
- * All operations take 3 sources except CompSwap that takes 4. These
- * sources represent:
- *
- * 0: The SSBO buffer index.
- * 1: The offset into the SSBO buffer of the variable that the atomic
- * operation will operate on.
- * 2: The data parameter to the atomic function (i.e. the value to add
- * in ssbo_atomic_add, etc).
- * 3: For CompSwap only: the second data parameter.
- */
-INTRINSIC(ssbo_atomic_add, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_imin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_umin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_imax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_umax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_and, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_or, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_xor, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_exchange, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-INTRINSIC(ssbo_atomic_comp_swap, 4, ARR(1, 1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
-
-/*
- * CS shared variable atomic intrinsics
- *
- * All of the shared variable atomic memory operations read a value from
- * memory, compute a new value using one of the operations below, write the
- * new value to memory, and return the original value read.
- *
- * All operations take 2 sources except CompSwap that takes 3. These
- * sources represent:
- *
- * 0: The offset into the shared variable storage region that the atomic
- * operation will operate on.
- * 1: The data parameter to the atomic function (i.e. the value to add
- * in shared_atomic_add, etc).
- * 2: For CompSwap only: the second data parameter.
- */
-INTRINSIC(shared_atomic_add, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_imin, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_umin, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_imax, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_umax, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_and, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_or, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_xor, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_exchange, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-INTRINSIC(shared_atomic_comp_swap, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
-
-/* Used by nir_builder.h to generate loader helpers for the system values. */
-#ifndef DEFINE_SYSTEM_VALUE
-#define DEFINE_SYSTEM_VALUE(name)
-#endif
-
-#define SYSTEM_VALUE(name, components, num_indices, idx0, idx1, idx2) \
- DEFINE_SYSTEM_VALUE(name) \
- INTRINSIC(load_##name, 0, ARR(0), true, components, 0, num_indices, \
- idx0, idx1, idx2, \
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-SYSTEM_VALUE(frag_coord, 4, 0, xx, xx, xx)
-SYSTEM_VALUE(front_face, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(vertex_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(vertex_id_zero_base, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(base_vertex, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(instance_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(base_instance, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(draw_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(sample_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(sample_pos, 2, 0, xx, xx, xx)
-SYSTEM_VALUE(sample_mask_in, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(primitive_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(invocation_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(tess_coord, 3, 0, xx, xx, xx)
-SYSTEM_VALUE(tess_level_outer, 4, 0, xx, xx, xx)
-SYSTEM_VALUE(tess_level_inner, 2, 0, xx, xx, xx)
-SYSTEM_VALUE(patch_vertices_in, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(local_invocation_id, 3, 0, xx, xx, xx)
-SYSTEM_VALUE(local_invocation_index, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(work_group_id, 3, 0, xx, xx, xx)
-SYSTEM_VALUE(user_clip_plane, 4, 1, UCP_ID, xx, xx)
-SYSTEM_VALUE(num_work_groups, 3, 0, xx, xx, xx)
-SYSTEM_VALUE(helper_invocation, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(alpha_ref_float, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(layer_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(view_index, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_size, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_invocation, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_eq_mask, 0, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_ge_mask, 0, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_gt_mask, 0, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_le_mask, 0, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_lt_mask, 0, 0, xx, xx, xx)
-SYSTEM_VALUE(num_subgroups, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(subgroup_id, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(local_group_size, 3, 0, xx, xx, xx)
-
-/* Blend constant color values. Float values are clamped. */
-SYSTEM_VALUE(blend_const_color_r_float, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(blend_const_color_g_float, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(blend_const_color_b_float, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(blend_const_color_a_float, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(blend_const_color_rgba8888_unorm, 1, 0, xx, xx, xx)
-SYSTEM_VALUE(blend_const_color_aaaa8888_unorm, 1, 0, xx, xx, xx)
-
-/**
- * Barycentric coordinate intrinsics.
- *
- * These set up the barycentric coordinates for a particular interpolation.
- * The first three are for the simple cases: pixel, centroid, or per-sample
- * (at gl_SampleID). The next two handle interpolating at a specified
- * sample location, or interpolating with a vec2 offset,
- *
- * The interp_mode index should be either the INTERP_MODE_SMOOTH or
- * INTERP_MODE_NOPERSPECTIVE enum values.
- *
- * The vec2 value produced by these intrinsics is intended for use as the
- * barycoord source of a load_interpolated_input intrinsic.
- */
-
-#define BARYCENTRIC(name, sources, source_components) \
- INTRINSIC(load_barycentric_##name, sources, ARR(source_components), \
- true, 2, 0, 1, INTERP_MODE, xx, xx, \
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/* no sources. const_index[] = { interp_mode } */
-BARYCENTRIC(pixel, 0, 0)
-BARYCENTRIC(centroid, 0, 0)
-BARYCENTRIC(sample, 0, 0)
-/* src[] = { sample_id }. const_index[] = { interp_mode } */
-BARYCENTRIC(at_sample, 1, 1)
-/* src[] = { offset.xy }. const_index[] = { interp_mode } */
-BARYCENTRIC(at_offset, 1, 2)
-
-/*
- * Load operations pull data from some piece of GPU memory. All load
- * operations operate in terms of offsets into some piece of theoretical
- * memory. Loads from externally visible memory (UBO and SSBO) simply take a
- * byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
- * take a base+offset pair where the base (const_index[0]) gives the location
- * of the start of the variable being loaded and and the offset source is a
- * offset into that variable.
- *
- * Uniform load operations have a second "range" index that specifies the
- * range (starting at base) of the data from which we are loading. If
- * const_index[1] == 0, then the range is unknown.
- *
- * Some load operations such as UBO/SSBO load and per_vertex loads take an
- * additional source to specify which UBO/SSBO/vertex to load from.
- *
- * The exact address type depends on the lowering pass that generates the
- * load/store intrinsics. Typically, this is vec4 units for things such as
- * varying slots and float units for fragment shader inputs. UBO and SSBO
- * offsets are always in bytes.
- */
-
-#define LOAD(name, srcs, num_indices, idx0, idx1, idx2, flags) \
- INTRINSIC(load_##name, srcs, ARR(1, 1, 1, 1), true, 0, 0, num_indices, idx0, idx1, idx2, flags)
-
-/* src[] = { offset }. const_index[] = { base, range } */
-LOAD(uniform, 1, 2, BASE, RANGE, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-/* src[] = { buffer_index, offset }. No const_index */
-LOAD(ubo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-/* src[] = { offset }. const_index[] = { base, component } */
-LOAD(input, 1, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-/* src[] = { vertex, offset }. const_index[] = { base, component } */
-LOAD(per_vertex_input, 2, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-/* src[] = { barycoord, offset }. const_index[] = { base, component } */
-INTRINSIC(load_interpolated_input, 2, ARR(2, 1), true, 0, 0,
- 2, BASE, COMPONENT, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/* src[] = { buffer_index, offset }. No const_index */
-LOAD(ssbo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-/* src[] = { offset }. const_index[] = { base, component } */
-LOAD(output, 1, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-/* src[] = { vertex, offset }. const_index[] = { base, component } */
-LOAD(per_vertex_output, 2, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-/* src[] = { offset }. const_index[] = { base } */
-LOAD(shared, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
-/* src[] = { offset }. const_index[] = { base, range } */
-LOAD(push_constant, 1, 2, BASE, RANGE, xx,
- NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
-
-/*
- * Stores work the same way as loads, except now the first source is the value
- * to store and the second (and possibly third) source specify where to store
- * the value. SSBO and shared memory stores also have a write mask as
- * const_index[0].
- */
-
-#define STORE(name, srcs, num_indices, idx0, idx1, idx2, flags) \
- INTRINSIC(store_##name, srcs, ARR(0, 1, 1, 1), false, 0, 0, num_indices, idx0, idx1, idx2, flags)
-
-/* src[] = { value, offset }. const_index[] = { base, write_mask, component } */
-STORE(output, 2, 3, BASE, WRMASK, COMPONENT, 0)
-/* src[] = { value, vertex, offset }.
- * const_index[] = { base, write_mask, component }
- */
-STORE(per_vertex_output, 3, 3, BASE, WRMASK, COMPONENT, 0)
-/* src[] = { value, block_index, offset }. const_index[] = { write_mask } */
-STORE(ssbo, 3, 1, WRMASK, xx, xx, 0)
-/* src[] = { value, offset }. const_index[] = { base, write_mask } */
-STORE(shared, 2, 2, BASE, WRMASK, xx, 0)
-
-LAST_INTRINSIC(store_shared)
-
-#undef DEFINE_SYSTEM_VALUE
-#undef INTRINSIC
-#undef LAST_INTRINSIC
diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py
new file mode 100644
index 00000000000..1bc99552cd7
--- /dev/null
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -0,0 +1,546 @@
+#
+# Copyright (C) 2018 Red Hat
+# Copyright (C) 2014 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+#
+
+# This file defines all the available intrinsics in one place.
+#
+# The Intrinsic class corresponds one-to-one with nir_intrinsic_info
+# structure.
+
+class Intrinsic(object):
+ """Class that represents all the information about an intrinsic opcode.
+ NOTE: this must be kept in sync with nir_intrinsic_info.
+ """
+ def __init__(self, name, src_components, dest_components, num_variables,
+ indices, flags, sysval):
+ """Parameters:
+
+ - name: the intrinsic name
+ - src_components: list of the number of components per src, 0 means
+ vectorized instruction with number of components given in the
+ num_components field in nir_intrinsic_instr.
+ - dest_components: number of destination components, -1 means no
+ dest, 0 means number of components given in num_components field
+ in nir_intrinsic_instr.
+ - num_variables: the number of variables
+ - indices: list of constant indicies
+ - flags: list of semantic flags
+ - sysval: is this a system-value intrinsic
+ """
+ assert isinstance(name, str)
+ assert isinstance(src_components, list)
+ if src_components:
+ assert isinstance(src_components[0], int)
+ assert isinstance(dest_components, int)
+ assert isinstance(num_variables, int)
+ assert isinstance(indices, list)
+ if indices:
+ assert isinstance(indices[0], str)
+ assert isinstance(flags, list)
+ if flags:
+ assert isinstance(flags[0], str)
+ assert isinstance(sysval, bool)
+
+ self.name = name
+ self.num_srcs = len(src_components)
+ self.src_components = src_components
+ self.has_dest = (dest_components >= 0)
+ self.dest_components = dest_components
+ self.num_variables = num_variables
+ self.num_indices = len(indices)
+ self.indices = indices
+ self.flags = flags
+ self.sysval = sysval
+
+#
+# Possible indices:
+#
+
+# A constant 'base' value that is added to an offset src:
+BASE = "NIR_INTRINSIC_BASE"
+# For store instructions, a writemask:
+WRMASK = "NIR_INTRINSIC_WRMASK"
+# The stream-id for GS emit_vertex/end_primitive intrinsics:
+STREAM_ID = "NIR_INTRINSIC_STREAM_ID"
+# The clip-plane id for load_user_clip_plane intrinsics:
+UCP_ID = "NIR_INTRINSIC_UCP_ID"
+# The amount of data, starting from BASE, that this instruction
+# may access. This is used to provide bounds if the offset is
+# not constant.
+RANGE = "NIR_INTRINSIC_RANGE"
+# The vulkan descriptor set binding for vulkan_resource_index
+# intrinsic
+DESC_SET = "NIR_INTRINSIC_DESC_SET"
+# The vulkan descriptor set binding for vulkan_resource_index
+# intrinsic
+BINDING = "NIR_INTRINSIC_BINDING"
+# Component offset
+COMPONENT = "NIR_INTRINSIC_COMPONENT"
+# Interpolation mode (only meaningful for FS inputs)
+INTERP_MODE = "NIR_INTRINSIC_INTERP_MODE"
+# A binary nir_op to use when performing a reduction or scan operation
+REDUCTION_OP = "NIR_INTRINSIC_REDUCTION_OP"
+# Cluster size for reduction operations
+CLUSTER_SIZE = "NIR_INTRINSIC_CLUSTER_SIZE"
+
+#
+# Possible flags:
+#
+
+CAN_ELIMINATE = "NIR_INTRINSIC_CAN_ELIMINATE"
+CAN_REORDER = "NIR_INTRINSIC_CAN_REORDER"
+
+INTR_OPCODES = {}
+
+def intrinsic(name, src_comp=[], dest_comp=-1, num_vars=0, indices=[],
+ flags=[], sysval=False):
+ assert name not in INTR_OPCODES
+ INTR_OPCODES[name] = Intrinsic(name, src_comp, dest_comp, num_vars,
+ indices, flags, sysval)
+
+intrinsic("nop", flags=[CAN_ELIMINATE])
+
+intrinsic("load_var", dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE])
+intrinsic("store_var", src_comp=[0], num_vars=1, indices=[WRMASK])
+intrinsic("copy_var", num_vars=2)
+
+# Interpolation of input. The interp_var_at* intrinsics are similar to the
+# load_var intrinsic acting on a shader input except that they interpolate
+# the input differently. The at_sample and at_offset intrinsics take an
+# additional source that is an integer sample id or a vec2 position offset
+# respectively.
+
+intrinsic("interp_var_at_centroid", dest_comp=0, num_vars=1,
+ flags=[ CAN_ELIMINATE, CAN_REORDER])
+intrinsic("interp_var_at_sample", src_comp=[1], dest_comp=0, num_vars=1,
+ flags=[CAN_ELIMINATE, CAN_REORDER])
+intrinsic("interp_var_at_offset", src_comp=[2], dest_comp=0, num_vars=1,
+ flags=[CAN_ELIMINATE, CAN_REORDER])
+
+# Ask the driver for the size of a given buffer. It takes the buffer index
+# as source.
+intrinsic("get_buffer_size", src_comp=[1], dest_comp=1,
+ flags=[CAN_ELIMINATE, CAN_REORDER])
+
+# a barrier is an intrinsic with no inputs/outputs but which can't be moved
+# around/optimized in general
+def barrier(name):
+ intrinsic(name)
+
+barrier("barrier")
+barrier("discard")
+
+# Memory barrier with semantics analogous to the memoryBarrier() GLSL
+# intrinsic.
+barrier("memory_barrier")
+
+# Shader clock intrinsic with semantics analogous to the clock2x32ARB()
+# GLSL intrinsic.
+# The latter can be used as code motion barrier, which is currently not
+# feasible with NIR.
+intrinsic("shader_clock", dest_comp=2, flags=[CAN_ELIMINATE])
+
+# Shader ballot intrinsics with semantics analogous to the
+#
+# ballotARB()
+# readInvocationARB()
+# readFirstInvocationARB()
+#
+# GLSL functions from ARB_shader_ballot.
+intrinsic("ballot", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("read_invocation", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("read_first_invocation", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
+
+# Additional SPIR-V ballot intrinsics
+#
+# These correspond to the SPIR-V opcodes
+#
+# OpGroupUniformElect
+# OpSubgroupFirstInvocationKHR
+intrinsic("elect", dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("first_invocation", dest_comp=1, flags=[CAN_ELIMINATE])
+
+# Memory barrier with semantics analogous to the compute shader
+# groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
+# memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
+barrier("group_memory_barrier")
+barrier("memory_barrier_atomic_counter")
+barrier("memory_barrier_buffer")
+barrier("memory_barrier_image")
+barrier("memory_barrier_shared")
+
+# A conditional discard, with a single boolean source.
+intrinsic("discard_if", src_comp=[1])
+
+# ARB_shader_group_vote intrinsics
+intrinsic("vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("vote_feq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("vote_ieq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
+
+# Ballot ALU operations from SPIR-V.
+#
+# These operations work like their ALU counterparts except that the operate
+# on a uvec4 which is treated as a 128bit integer. Also, they are, in
+# general, free to ignore any bits which are above the subgroup size.
+intrinsic("ballot_bitfield_extract", src_comp=[4, 1], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("ballot_bit_count_reduce", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("ballot_bit_count_inclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("ballot_bit_count_exclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("ballot_find_lsb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
+intrinsic("ballot_find_msb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
+
+# Shuffle operations from SPIR-V.
+intrinsic("shuffle", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("shuffle_xor", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("shuffle_up", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("shuffle_down", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
+
+# Quad operations from SPIR-V.
+intrinsic("quad_broadcast", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("quad_swap_horizontal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("quad_swap_vertical", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
+intrinsic("quad_swap_diagonal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
+
+intrinsic("reduce", src_comp=[0], dest_comp=0, indices=[REDUCTION_OP, CLUSTER_SIZE],
+ flags=[CAN_ELIMINATE])
+intrinsic("inclusive_scan", src_comp=[0], dest_comp=0, indices=[REDUCTION_OP],
+ flags=[CAN_ELIMINATE])
+intrinsic("exclusive_scan", src_comp=[0], dest_comp=0, indices=[REDUCTION_OP],
+ flags=[CAN_ELIMINATE])
+
+# Basic Geometry Shader intrinsics.
+#
+# emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
+# index, which is the stream ID to write to.
+#
+# end_primitive implements GLSL's EndPrimitive() built-in.
+intrinsic("emit_vertex", indices=[STREAM_ID])
+intrinsic("end_primitive", indices=[STREAM_ID])
+
+# Geometry Shader intrinsics with a vertex count.
+#
+# Alternatively, drivers may implement these intrinsics, and use
+# nir_lower_gs_intrinsics() to convert from the basic intrinsics.
+#
+# These maintain a count of the number of vertices emitted, as an additional
+# unsigned integer source.
+intrinsic("emit_vertex_with_counter", src_comp=[1], indices=[STREAM_ID])
+intrinsic("end_primitive_with_counter", src_comp=[1], indices=[STREAM_ID])
+intrinsic("set_vertex_count", src_comp=[1])
+
+# Atomic counters
+#
+# The *_var variants take an atomic_uint nir_variable, while the other,
+# lowered, variants take a constant buffer index and register offset.
+
+def atomic(name, flags=[]):
+ intrinsic(name + "_var", dest_comp=1, num_vars=1, flags=flags)
+ intrinsic(name, src_comp=[1], dest_comp=1, indices=[BASE], flags=flags)
+
+def atomic2(name):
+ intrinsic(name + "_var", src_comp=[1], dest_comp=1, num_vars=1)
+ intrinsic(name, src_comp=[1, 1], dest_comp=1, indices=[BASE])
+
+def atomic3(name):
+ intrinsic(name + "_var", src_comp=[1, 1], dest_comp=1, num_vars=1)
+ intrinsic(name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
+
+atomic("atomic_counter_inc")
+atomic("atomic_counter_dec")
+atomic("atomic_counter_read", flags=[CAN_ELIMINATE])
+atomic2("atomic_counter_add")
+atomic2("atomic_counter_min")
+atomic2("atomic_counter_max")
+atomic2("atomic_counter_and")
+atomic2("atomic_counter_or")
+atomic2("atomic_counter_xor")
+atomic2("atomic_counter_exchange")
+atomic3("atomic_counter_comp_swap")
+
+# Image load, store and atomic intrinsics.
+#
+# All image intrinsics take an image target passed as a nir_variable. Image
+# variables contain a number of memory and layout qualifiers that influence
+# the semantics of the intrinsic.
+#
+# All image intrinsics take a four-coordinate vector and a sample index as
+# first two sources, determining the location within the image that will be
+# accessed by the intrinsic. Components not applicable to the image target
+# in use are undefined. Image store takes an additional four-component
+# argument with the value to be written, and image atomic operations take
+# either one or two additional scalar arguments with the same meaning as in
+# the ARB_shader_image_load_store specification.
+intrinsic("image_var_load", src_comp=[4, 1], dest_comp=4, num_vars=1,
+ flags=[CAN_ELIMINATE])
+intrinsic("image_var_store", src_comp=[4, 1, 4], num_vars=1)
+intrinsic("image_var_atomic_add", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_min", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_max", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_and", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_or", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_xor", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_exchange", src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_comp_swap", src_comp=[4, 1, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_size", dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE, CAN_REORDER])
+intrinsic("image_var_samples", dest_comp=1, num_vars=1, flags=[CAN_ELIMINATE, CAN_REORDER])
+
+# Vulkan descriptor set intrinsics
+#
+# The Vulkan API uses a different binding model from GL. In the Vulkan
+# API, all external resources are represented by a tuple:
+#
+# (descriptor set, binding, array index)
+#
+# where the array index is the only thing allowed to be indirect. The
+# vulkan_surface_index intrinsic takes the descriptor set and binding as
+# its first two indices and the array index as its source. The third
+# index is a nir_variable_mode in case that's useful to the backend.
+#
+# The intended usage is that the shader will call vulkan_surface_index to
+# get an index and then pass that as the buffer index ubo/ssbo calls.
+#
+# The vulkan_resource_reindex intrinsic takes a resource index in src0
+# (the result of a vulkan_resource_index or vulkan_resource_reindex) which
+# corresponds to the tuple (set, binding, index) and computes an index
+# corresponding to tuple (set, binding, idx + src1).
+intrinsic("vulkan_resource_index", src_comp=[1], dest_comp=1,
+ indices=[DESC_SET, BINDING], flags=[CAN_ELIMINATE, CAN_REORDER])
+intrinsic("vulkan_resource_reindex", src_comp=[1, 1], dest_comp=1,
+ flags=[CAN_ELIMINATE, CAN_REORDER])
+
+# variable atomic intrinsics
+#
+# All of these variable atomic memory operations read a value from memory,
+# compute a new value using one of the operations below, write the new value
+# to memory, and return the original value read.
+#
+# All operations take 1 source except CompSwap that takes 2. These sources
+# represent:
+#
+# 0: The data parameter to the atomic function (i.e. the value to add
+# in shared_atomic_add, etc).
+# 1: For CompSwap only: the second data parameter.
+#
+# All operations take 1 variable deref.
+intrinsic("var_atomic_add", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_imin", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_umin", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_imax", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_umax", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_and", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_or", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_xor", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_exchange", src_comp=[1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_comp_swap", src_comp=[1, 1], dest_comp=1, num_vars=1)
+
+# SSBO atomic intrinsics
+#
+# All of the SSBO atomic memory operations read a value from memory,
+# compute a new value using one of the operations below, write the new
+# value to memory, and return the original value read.
+#
+# All operations take 3 sources except CompSwap that takes 4. These
+# sources represent:
+#
+# 0: The SSBO buffer index.
+# 1: The offset into the SSBO buffer of the variable that the atomic
+# operation will operate on.
+# 2: The data parameter to the atomic function (i.e. the value to add
+# in ssbo_atomic_add, etc).
+# 3: For CompSwap only: the second data parameter.
+intrinsic("ssbo_atomic_add", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_imin", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_umin", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_imax", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_umax", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_and", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_or", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_xor", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_exchange", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_comp_swap", src_comp=[1, 1, 1, 1], dest_comp=1)
+
+# CS shared variable atomic intrinsics
+#
+# All of the shared variable atomic memory operations read a value from
+# memory, compute a new value using one of the operations below, write the
+# new value to memory, and return the original value read.
+#
+# All operations take 2 sources except CompSwap that takes 3. These
+# sources represent:
+#
+# 0: The offset into the shared variable storage region that the atomic
+# operation will operate on.
+# 1: The data parameter to the atomic function (i.e. the value to add
+# in shared_atomic_add, etc).
+# 2: For CompSwap only: the second data parameter.
+intrinsic("shared_atomic_add", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_imin", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_umin", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_imax", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_umax", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_and", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_or", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_xor", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_exchange", src_comp=[1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_comp_swap", src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
+
+def system_value(name, dest_comp, indices=[]):
+ intrinsic("load_" + name, [], dest_comp, 0, indices,
+ flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True)
+
+system_value("frag_coord", 4)
+system_value("front_face", 1)
+system_value("vertex_id", 1)
+system_value("vertex_id_zero_base", 1)
+system_value("base_vertex", 1)
+system_value("instance_id", 1)
+system_value("base_instance", 1)
+system_value("draw_id", 1)
+system_value("sample_id", 1)
+system_value("sample_pos", 2)
+system_value("sample_mask_in", 1)
+system_value("primitive_id", 1)
+system_value("invocation_id", 1)
+system_value("tess_coord", 3)
+system_value("tess_level_outer", 4)
+system_value("tess_level_inner", 2)
+system_value("patch_vertices_in", 1)
+system_value("local_invocation_id", 3)
+system_value("local_invocation_index", 1)
+system_value("work_group_id", 3)
+system_value("user_clip_plane", 4, indices=[UCP_ID])
+system_value("num_work_groups", 3)
+system_value("helper_invocation", 1)
+system_value("alpha_ref_float", 1)
+system_value("layer_id", 1)
+system_value("view_index", 1)
+system_value("subgroup_size", 1)
+system_value("subgroup_invocation", 1)
+system_value("subgroup_eq_mask", 0)
+system_value("subgroup_ge_mask", 0)
+system_value("subgroup_gt_mask", 0)
+system_value("subgroup_le_mask", 0)
+system_value("subgroup_lt_mask", 0)
+system_value("num_subgroups", 1)
+system_value("subgroup_id", 1)
+system_value("local_group_size", 3)
+
+# Blend constant color values. Float values are clamped.#
+system_value("blend_const_color_r_float", 1)
+system_value("blend_const_color_g_float", 1)
+system_value("blend_const_color_b_float", 1)
+system_value("blend_const_color_a_float", 1)
+system_value("blend_const_color_rgba8888_unorm", 1)
+system_value("blend_const_color_aaaa8888_unorm", 1)
+
+# Barycentric coordinate intrinsics.
+#
+# These set up the barycentric coordinates for a particular interpolation.
+# The first three are for the simple cases: pixel, centroid, or per-sample
+# (at gl_SampleID). The next two handle interpolating at a specified
+# sample location, or interpolating with a vec2 offset,
+#
+# The interp_mode index should be either the INTERP_MODE_SMOOTH or
+# INTERP_MODE_NOPERSPECTIVE enum values.
+#
+# The vec2 value produced by these intrinsics is intended for use as the
+# barycoord source of a load_interpolated_input intrinsic.
+
+def barycentric(name, src_comp=[]):
+ intrinsic("load_barycentric_" + name, src_comp=src_comp, dest_comp=2,
+ indices=[INTERP_MODE], flags=[CAN_ELIMINATE, CAN_REORDER])
+
+# no sources. const_index[] = { interp_mode }
+barycentric("pixel")
+barycentric("centroid")
+barycentric("sample")
+# src[] = { sample_id }. const_index[] = { interp_mode }
+barycentric("at_sample", [1])
+# src[] = { offset.xy }. const_index[] = { interp_mode }
+barycentric("at_offset", [2])
+
+# Load operations pull data from some piece of GPU memory. All load
+# operations operate in terms of offsets into some piece of theoretical
+# memory. Loads from externally visible memory (UBO and SSBO) simply take a
+# byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
+# take a base+offset pair where the base (const_index[0]) gives the location
+# of the start of the variable being loaded and and the offset source is a
+# offset into that variable.
+#
+# Uniform load operations have a second "range" index that specifies the
+# range (starting at base) of the data from which we are loading. If
+# const_index[1] == 0, then the range is unknown.
+#
+# Some load operations such as UBO/SSBO load and per_vertex loads take an
+# additional source to specify which UBO/SSBO/vertex to load from.
+#
+# The exact address type depends on the lowering pass that generates the
+# load/store intrinsics. Typically, this is vec4 units for things such as
+# varying slots and float units for fragment shader inputs. UBO and SSBO
+# offsets are always in bytes.
+
+def load(name, num_srcs, indices=[], flags=[]):
+ intrinsic("load_" + name, [1] * num_srcs, dest_comp=0, indices=indices,
+ flags=flags)
+
+# src[] = { offset }. const_index[] = { base, range }
+load("uniform", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
+# src[] = { buffer_index, offset }. No const_index
+load("ubo", 2, flags=[CAN_ELIMINATE, CAN_REORDER])
+# src[] = { offset }. const_index[] = { base, component }
+load("input", 1, [BASE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER])
+# src[] = { vertex, offset }. const_index[] = { base, component }
+load("per_vertex_input", 2, [BASE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER])
+# src[] = { barycoord, offset }. const_index[] = { base, component }
+intrinsic("load_interpolated_input", src_comp=[2, 1], dest_comp=0,
+ indices=[BASE, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER])
+
+# src[] = { buffer_index, offset }. No const_index
+load("ssbo", 2, flags=[CAN_ELIMINATE])
+# src[] = { offset }. const_index[] = { base, component }
+load("output", 1, [BASE, COMPONENT], flags=[CAN_ELIMINATE])
+# src[] = { vertex, offset }. const_index[] = { base }
+load("per_vertex_output", 2, [BASE, COMPONENT], [CAN_ELIMINATE])
+# src[] = { offset }. const_index[] = { base }
+load("shared", 1, [BASE], [CAN_ELIMINATE])
+# src[] = { offset }. const_index[] = { base, range }
+load("push_constant", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
+
+# Stores work the same way as loads, except now the first source is the value
+# to store and the second (and possibly third) source specify where to store
+# the value. SSBO and shared memory stores also have a write mask as
+# const_index[0].
+
+def store(name, num_srcs, indices=[], flags=[]):
+ intrinsic("store_" + name, [0] + ([1] * (num_srcs - 1)), indices=indices, flags=flags)
+
+# src[] = { value, offset }. const_index[] = { base, write_mask, component }
+store("output", 2, [BASE, WRMASK, COMPONENT])
+# src[] = { value, vertex, offset }.
+# const_index[] = { base, write_mask, component }
+store("per_vertex_output", 3, [BASE, WRMASK, COMPONENT])
+# src[] = { value, block_index, offset }. const_index[] = { write_mask }
+store("ssbo", 3, [WRMASK])
+# src[] = { value, offset }. const_index[] = { base, write_mask }
+store("shared", 2, [BASE, WRMASK])
diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py
new file mode 100644
index 00000000000..556db785c2b
--- /dev/null
+++ b/src/compiler/nir/nir_intrinsics_c.py
@@ -0,0 +1,68 @@
+
+template = """\
+/* Copyright (C) 2018 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "nir.h"
+
+const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = {
+% for name, opcode in sorted(INTR_OPCODES.iteritems()):
+{
+ .name = "${name}",
+ .num_srcs = ${opcode.num_srcs},
+ .src_components = {
+ ${", ".join(str(comp) for comp in opcode.src_components)}
+ },
+ .has_dest = ${"true" if opcode.has_dest else "false"},
+ .dest_components = ${opcode.dest_components},
+ .num_variables = ${opcode.num_variables},
+ .num_indices = ${opcode.num_indices},
+ .index_map = {
+% for i in range(len(opcode.indices)):
+ [${opcode.indices[i]}] = ${i + 1},
+% endfor
+ },
+ .flags = ${"0" if len(opcode.flags) == 0 else " | ".join(opcode.flags)},
+},
+% endfor
+};
+"""
+
+from nir_intrinsics import INTR_OPCODES
+from mako.template import Template
+import argparse
+import os
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--outdir', required=True,
+ help='Directory to put the generated files in')
+
+ args = parser.parse_args()
+
+ path = os.path.join(args.outdir, 'nir_intrinsics.c')
+ with open(path, 'wb') as f:
+ f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES))
+
+if __name__ == '__main__':
+ main()
+
diff --git a/src/compiler/nir/nir_intrinsics.c b/src/compiler/nir/nir_intrinsics_h.py
index 0257b19b348..8a4f0d501e6 100644
--- a/src/compiler/nir/nir_intrinsics.c
+++ b/src/compiler/nir/nir_intrinsics_h.py
@@ -1,5 +1,6 @@
-/*
- * Copyright © 2014 Intel Corporation
+
+template = """\
+/* Copyright (C) 2018 Red Hat
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -19,39 +20,41 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
- *
- * Authors:
- * Connor Abbott ([email protected])
- *
*/
-#include "nir.h"
-
-#define OPCODE(name) nir_intrinsic_##name
-
-#define INTRINSIC(_name, _num_srcs, _src_components, _has_dest, \
- _dest_components, _num_variables, _num_indices, \
- idx0, idx1, idx2, _flags) \
-{ \
- .name = #_name, \
- .num_srcs = _num_srcs, \
- .src_components = _src_components, \
- .has_dest = _has_dest, \
- .dest_components = _dest_components, \
- .num_variables = _num_variables, \
- .num_indices = _num_indices, \
- .index_map = { \
- [NIR_INTRINSIC_ ## idx0] = 1, \
- [NIR_INTRINSIC_ ## idx1] = 2, \
- [NIR_INTRINSIC_ ## idx2] = 3, \
- }, \
- .flags = _flags \
-},
-
-#define NIR_INTRINSIC_xx 0
-
-#define LAST_INTRINSIC(name)
-
-const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = {
-#include "nir_intrinsics.h"
-}; \ No newline at end of file
+#ifndef _NIR_INTRINSICS_
+#define _NIR_INTRINSICS_
+
+<% opcode_names = sorted(INTR_OPCODES) %>
+
+typedef enum {
+% for name in opcode_names:
+ nir_intrinsic_${name},
+% endfor
+
+ nir_last_intrinsic = nir_intrinsic_${opcode_names[-1]},
+ nir_num_intrinsics = nir_last_intrinsic + 1
+} nir_intrinsic_op;
+
+#endif /* _NIR_INTRINSICS_ */"""
+
+from nir_intrinsics import INTR_OPCODES
+from mako.template import Template
+import argparse
+import os
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--outdir', required=True,
+ help='Directory to put the generated files in')
+
+ args = parser.parse_args()
+
+ path = os.path.join(args.outdir, 'nir_intrinsics.h')
+ with open(path, 'wb') as f:
+ f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES))
+
+if __name__ == '__main__':
+ main()
+