46f67a908ed0cfe91e6e5aab1e054bf84d296408
[mesa.git] / src / compiler / nir / nir_intrinsics.h
1 /*
2 * Copyright © 2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Connor Abbott (cwabbott0@gmail.com)
25 *
26 */
27
28 /**
29 * This header file defines all the available intrinsics in one place. It
30 * expands to a list of macros of the form:
31 *
32 * INTRINSIC(name, num_srcs, src_components, has_dest, dest_components,
33 * num_variables, num_indices, idx0, idx1, idx2, flags)
34 *
35 * Which should correspond one-to-one with the nir_intrinsic_info structure. It
36 * is included in both ir.h to create the nir_intrinsic enum (with members of
37 * the form nir_intrinsic_(name)) and and in opcodes.c to create
38 * nir_intrinsic_infos, which is a const array of nir_intrinsic_info structures
39 * for each intrinsic.
40 */
41
42 #define ARR(...) { __VA_ARGS__ }
43
44 INTRINSIC(nop, 0, ARR(0), false, 0, 0, 0, xx, xx, xx,
45 NIR_INTRINSIC_CAN_ELIMINATE)
46
47 INTRINSIC(load_var, 0, ARR(0), true, 0, 1, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
48 INTRINSIC(store_var, 1, ARR(0), false, 0, 1, 1, WRMASK, xx, xx, 0)
49 INTRINSIC(copy_var, 0, ARR(0), false, 0, 2, 0, xx, xx, xx, 0)
50
51 /*
52 * Interpolation of input. The interp_var_at* intrinsics are similar to the
53 * load_var intrinsic acting on a shader input except that they interpolate
54 * the input differently. The at_sample and at_offset intrinsics take an
55 * additional source that is an integer sample id or a vec2 position offset
56 * respectively.
57 */
58
59 INTRINSIC(interp_var_at_centroid, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,
60 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
61 INTRINSIC(interp_var_at_sample, 1, ARR(1), true, 0, 1, 0, xx, xx, xx,
62 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
63 INTRINSIC(interp_var_at_offset, 1, ARR(2), true, 0, 1, 0, xx, xx, xx,
64 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
65
66 /*
67 * Ask the driver for the size of a given buffer. It takes the buffer index
68 * as source.
69 */
70 INTRINSIC(get_buffer_size, 1, ARR(1), true, 1, 0, 0, xx, xx, xx,
71 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
72
73 /*
74 * a barrier is an intrinsic with no inputs/outputs but which can't be moved
75 * around/optimized in general
76 */
77 #define BARRIER(name) INTRINSIC(name, 0, ARR(0), false, 0, 0, 0, xx, xx, xx, 0)
78
79 BARRIER(barrier)
80 BARRIER(discard)
81
82 /*
83 * Memory barrier with semantics analogous to the memoryBarrier() GLSL
84 * intrinsic.
85 */
86 BARRIER(memory_barrier)
87
88 /*
89 * Shader clock intrinsic with semantics analogous to the clock2x32ARB()
90 * GLSL intrinsic.
91 * The latter can be used as code motion barrier, which is currently not
92 * feasible with NIR.
93 */
94 INTRINSIC(shader_clock, 0, ARR(0), true, 2, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
95
96 /*
97 * Shader ballot intrinsics with semantics analogous to the
98 *
99 * ballotARB()
100 * readInvocationARB()
101 * readFirstInvocationARB()
102 *
103 * GLSL functions from ARB_shader_ballot.
104 */
105 INTRINSIC(ballot, 1, ARR(1), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
106 INTRINSIC(read_invocation, 2, ARR(0, 1), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
107 INTRINSIC(read_first_invocation, 1, ARR(0), true, 0, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
108
109 /** Additional SPIR-V ballot intrinsics
110 *
111 * These correspond to the SPIR-V opcodes
112 *
113 * OpGroupUniformElect
114 * OpSubgroupFirstInvocationKHR
115 */
116 INTRINSIC(elect, 0, ARR(0), true, 1, 0, 0, xx, xx, xx,
117 NIR_INTRINSIC_CAN_ELIMINATE)
118 INTRINSIC(first_invocation, 0, ARR(0), true, 1, 0, 0, xx, xx, xx,
119 NIR_INTRINSIC_CAN_ELIMINATE)
120
121 /*
122 * Memory barrier with semantics analogous to the compute shader
123 * groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
124 * memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
125 */
126 BARRIER(group_memory_barrier)
127 BARRIER(memory_barrier_atomic_counter)
128 BARRIER(memory_barrier_buffer)
129 BARRIER(memory_barrier_image)
130 BARRIER(memory_barrier_shared)
131
132 /** A conditional discard, with a single boolean source. */
133 INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)
134
135 /** ARB_shader_group_vote intrinsics */
136 INTRINSIC(vote_any, 1, ARR(1), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
137 INTRINSIC(vote_all, 1, ARR(1), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
138 INTRINSIC(vote_eq, 1, ARR(1), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
139
140 /** Ballot ALU operations from SPIR-V.
141 *
142 * These operations work like their ALU counterparts except that the operate
143 * on a uvec4 which is treated as a 128bit integer. Also, they are, in
144 * general, free to ignore any bits which are above the subgroup size.
145 */
146 INTRINSIC(ballot_bitfield_extract, 2, ARR(4, 1), true, 1, 0,
147 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
148 INTRINSIC(ballot_bit_count_reduce, 1, ARR(4), true, 1, 0,
149 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
150 INTRINSIC(ballot_bit_count_inclusive, 1, ARR(4), true, 1, 0,
151 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
152 INTRINSIC(ballot_bit_count_exclusive, 1, ARR(4), true, 1, 0,
153 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
154 INTRINSIC(ballot_find_lsb, 1, ARR(4), true, 1, 0,
155 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
156 INTRINSIC(ballot_find_msb, 1, ARR(4), true, 1, 0,
157 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
158
159 /**
160 * Basic Geometry Shader intrinsics.
161 *
162 * emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
163 * index, which is the stream ID to write to.
164 *
165 * end_primitive implements GLSL's EndPrimitive() built-in.
166 */
167 INTRINSIC(emit_vertex, 0, ARR(0), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
168 INTRINSIC(end_primitive, 0, ARR(0), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
169
170 /**
171 * Geometry Shader intrinsics with a vertex count.
172 *
173 * Alternatively, drivers may implement these intrinsics, and use
174 * nir_lower_gs_intrinsics() to convert from the basic intrinsics.
175 *
176 * These maintain a count of the number of vertices emitted, as an additional
177 * unsigned integer source.
178 */
179 INTRINSIC(emit_vertex_with_counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
180 INTRINSIC(end_primitive_with_counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
181 INTRINSIC(set_vertex_count, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)
182
183 /*
184 * Atomic counters
185 *
186 * The *_var variants take an atomic_uint nir_variable, while the other,
187 * lowered, variants take a constant buffer index and register offset.
188 */
189
190 #define ATOMIC(name, flags) \
191 INTRINSIC(name##_var, 0, ARR(0), true, 1, 1, 0, xx, xx, xx, flags) \
192 INTRINSIC(name, 1, ARR(1), true, 1, 0, 1, BASE, xx, xx, flags)
193 #define ATOMIC2(name) \
194 INTRINSIC(name##_var, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0) \
195 INTRINSIC(name, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
196 #define ATOMIC3(name) \
197 INTRINSIC(name##_var, 2, ARR(1, 1), true, 1, 1, 0, xx, xx, xx, 0) \
198 INTRINSIC(name, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
199
200 ATOMIC(atomic_counter_inc, 0)
201 ATOMIC(atomic_counter_dec, 0)
202 ATOMIC(atomic_counter_read, NIR_INTRINSIC_CAN_ELIMINATE)
203 ATOMIC2(atomic_counter_add)
204 ATOMIC2(atomic_counter_min)
205 ATOMIC2(atomic_counter_max)
206 ATOMIC2(atomic_counter_and)
207 ATOMIC2(atomic_counter_or)
208 ATOMIC2(atomic_counter_xor)
209 ATOMIC2(atomic_counter_exchange)
210 ATOMIC3(atomic_counter_comp_swap)
211
212 /*
213 * Image load, store and atomic intrinsics.
214 *
215 * All image intrinsics take an image target passed as a nir_variable. Image
216 * variables contain a number of memory and layout qualifiers that influence
217 * the semantics of the intrinsic.
218 *
219 * All image intrinsics take a four-coordinate vector and a sample index as
220 * first two sources, determining the location within the image that will be
221 * accessed by the intrinsic. Components not applicable to the image target
222 * in use are undefined. Image store takes an additional four-component
223 * argument with the value to be written, and image atomic operations take
224 * either one or two additional scalar arguments with the same meaning as in
225 * the ARB_shader_image_load_store specification.
226 */
227 INTRINSIC(image_load, 2, ARR(4, 1), true, 4, 1, 0, xx, xx, xx,
228 NIR_INTRINSIC_CAN_ELIMINATE)
229 INTRINSIC(image_store, 3, ARR(4, 1, 4), false, 0, 1, 0, xx, xx, xx, 0)
230 INTRINSIC(image_atomic_add, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
231 INTRINSIC(image_atomic_min, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
232 INTRINSIC(image_atomic_max, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
233 INTRINSIC(image_atomic_and, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
234 INTRINSIC(image_atomic_or, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
235 INTRINSIC(image_atomic_xor, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
236 INTRINSIC(image_atomic_exchange, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
237 INTRINSIC(image_atomic_comp_swap, 4, ARR(4, 1, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
238 INTRINSIC(image_size, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,
239 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
240 INTRINSIC(image_samples, 0, ARR(0), true, 1, 1, 0, xx, xx, xx,
241 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
242
243 /*
244 * Vulkan descriptor set intrinsics
245 *
246 * The Vulkan API uses a different binding model from GL. In the Vulkan
247 * API, all external resources are represented by a tuple:
248 *
249 * (descriptor set, binding, array index)
250 *
251 * where the array index is the only thing allowed to be indirect. The
252 * vulkan_surface_index intrinsic takes the descriptor set and binding as
253 * its first two indices and the array index as its source. The third
254 * index is a nir_variable_mode in case that's useful to the backend.
255 *
256 * The intended usage is that the shader will call vulkan_surface_index to
257 * get an index and then pass that as the buffer index ubo/ssbo calls.
258 *
259 * The vulkan_resource_reindex intrinsic takes a resource index in src0
260 * (the result of a vulkan_resource_index or vulkan_resource_reindex) which
261 * corresponds to the tuple (set, binding, index) and computes an index
262 * corresponding to tuple (set, binding, idx + src1).
263 */
264 INTRINSIC(vulkan_resource_index, 1, ARR(1), true, 1, 0, 2,
265 DESC_SET, BINDING, xx,
266 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
267 INTRINSIC(vulkan_resource_reindex, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx,
268 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
269
270 /*
271 * variable atomic intrinsics
272 *
273 * All of these variable atomic memory operations read a value from memory,
274 * compute a new value using one of the operations below, write the new value
275 * to memory, and return the original value read.
276 *
277 * All operations take 1 source except CompSwap that takes 2. These sources
278 * represent:
279 *
280 * 0: The data parameter to the atomic function (i.e. the value to add
281 * in shared_atomic_add, etc).
282 * 1: For CompSwap only: the second data parameter.
283 *
284 * All operations take 1 variable deref.
285 */
286 INTRINSIC(var_atomic_add, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
287 INTRINSIC(var_atomic_imin, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
288 INTRINSIC(var_atomic_umin, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
289 INTRINSIC(var_atomic_imax, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
290 INTRINSIC(var_atomic_umax, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
291 INTRINSIC(var_atomic_and, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
292 INTRINSIC(var_atomic_or, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
293 INTRINSIC(var_atomic_xor, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
294 INTRINSIC(var_atomic_exchange, 1, ARR(1), true, 1, 1, 0, xx, xx, xx, 0)
295 INTRINSIC(var_atomic_comp_swap, 2, ARR(1, 1), true, 1, 1, 0, xx, xx, xx, 0)
296
297 /*
298 * SSBO atomic intrinsics
299 *
300 * All of the SSBO atomic memory operations read a value from memory,
301 * compute a new value using one of the operations below, write the new
302 * value to memory, and return the original value read.
303 *
304 * All operations take 3 sources except CompSwap that takes 4. These
305 * sources represent:
306 *
307 * 0: The SSBO buffer index.
308 * 1: The offset into the SSBO buffer of the variable that the atomic
309 * operation will operate on.
310 * 2: The data parameter to the atomic function (i.e. the value to add
311 * in ssbo_atomic_add, etc).
312 * 3: For CompSwap only: the second data parameter.
313 */
314 INTRINSIC(ssbo_atomic_add, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
315 INTRINSIC(ssbo_atomic_imin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
316 INTRINSIC(ssbo_atomic_umin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
317 INTRINSIC(ssbo_atomic_imax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
318 INTRINSIC(ssbo_atomic_umax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
319 INTRINSIC(ssbo_atomic_and, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
320 INTRINSIC(ssbo_atomic_or, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
321 INTRINSIC(ssbo_atomic_xor, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
322 INTRINSIC(ssbo_atomic_exchange, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
323 INTRINSIC(ssbo_atomic_comp_swap, 4, ARR(1, 1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
324
325 /*
326 * CS shared variable atomic intrinsics
327 *
328 * All of the shared variable atomic memory operations read a value from
329 * memory, compute a new value using one of the operations below, write the
330 * new value to memory, and return the original value read.
331 *
332 * All operations take 2 sources except CompSwap that takes 3. These
333 * sources represent:
334 *
335 * 0: The offset into the shared variable storage region that the atomic
336 * operation will operate on.
337 * 1: The data parameter to the atomic function (i.e. the value to add
338 * in shared_atomic_add, etc).
339 * 2: For CompSwap only: the second data parameter.
340 */
341 INTRINSIC(shared_atomic_add, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
342 INTRINSIC(shared_atomic_imin, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
343 INTRINSIC(shared_atomic_umin, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
344 INTRINSIC(shared_atomic_imax, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
345 INTRINSIC(shared_atomic_umax, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
346 INTRINSIC(shared_atomic_and, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
347 INTRINSIC(shared_atomic_or, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
348 INTRINSIC(shared_atomic_xor, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
349 INTRINSIC(shared_atomic_exchange, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
350 INTRINSIC(shared_atomic_comp_swap, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
351
352 /* Used by nir_builder.h to generate loader helpers for the system values. */
353 #ifndef DEFINE_SYSTEM_VALUE
354 #define DEFINE_SYSTEM_VALUE(name)
355 #endif
356
357 #define SYSTEM_VALUE(name, components, num_indices, idx0, idx1, idx2) \
358 DEFINE_SYSTEM_VALUE(name) \
359 INTRINSIC(load_##name, 0, ARR(0), true, components, 0, num_indices, \
360 idx0, idx1, idx2, \
361 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
362
363 SYSTEM_VALUE(frag_coord, 4, 0, xx, xx, xx)
364 SYSTEM_VALUE(front_face, 1, 0, xx, xx, xx)
365 SYSTEM_VALUE(vertex_id, 1, 0, xx, xx, xx)
366 SYSTEM_VALUE(vertex_id_zero_base, 1, 0, xx, xx, xx)
367 SYSTEM_VALUE(base_vertex, 1, 0, xx, xx, xx)
368 SYSTEM_VALUE(instance_id, 1, 0, xx, xx, xx)
369 SYSTEM_VALUE(base_instance, 1, 0, xx, xx, xx)
370 SYSTEM_VALUE(draw_id, 1, 0, xx, xx, xx)
371 SYSTEM_VALUE(sample_id, 1, 0, xx, xx, xx)
372 SYSTEM_VALUE(sample_pos, 2, 0, xx, xx, xx)
373 SYSTEM_VALUE(sample_mask_in, 1, 0, xx, xx, xx)
374 SYSTEM_VALUE(primitive_id, 1, 0, xx, xx, xx)
375 SYSTEM_VALUE(invocation_id, 1, 0, xx, xx, xx)
376 SYSTEM_VALUE(tess_coord, 3, 0, xx, xx, xx)
377 SYSTEM_VALUE(tess_level_outer, 4, 0, xx, xx, xx)
378 SYSTEM_VALUE(tess_level_inner, 2, 0, xx, xx, xx)
379 SYSTEM_VALUE(patch_vertices_in, 1, 0, xx, xx, xx)
380 SYSTEM_VALUE(local_invocation_id, 3, 0, xx, xx, xx)
381 SYSTEM_VALUE(local_invocation_index, 1, 0, xx, xx, xx)
382 SYSTEM_VALUE(work_group_id, 3, 0, xx, xx, xx)
383 SYSTEM_VALUE(user_clip_plane, 4, 1, UCP_ID, xx, xx)
384 SYSTEM_VALUE(num_work_groups, 3, 0, xx, xx, xx)
385 SYSTEM_VALUE(helper_invocation, 1, 0, xx, xx, xx)
386 SYSTEM_VALUE(alpha_ref_float, 1, 0, xx, xx, xx)
387 SYSTEM_VALUE(layer_id, 1, 0, xx, xx, xx)
388 SYSTEM_VALUE(view_index, 1, 0, xx, xx, xx)
389 SYSTEM_VALUE(subgroup_size, 1, 0, xx, xx, xx)
390 SYSTEM_VALUE(subgroup_invocation, 1, 0, xx, xx, xx)
391 SYSTEM_VALUE(subgroup_eq_mask, 0, 0, xx, xx, xx)
392 SYSTEM_VALUE(subgroup_ge_mask, 0, 0, xx, xx, xx)
393 SYSTEM_VALUE(subgroup_gt_mask, 0, 0, xx, xx, xx)
394 SYSTEM_VALUE(subgroup_le_mask, 0, 0, xx, xx, xx)
395 SYSTEM_VALUE(subgroup_lt_mask, 0, 0, xx, xx, xx)
396 SYSTEM_VALUE(num_subgroups, 1, 0, xx, xx, xx)
397 SYSTEM_VALUE(subgroup_id, 1, 0, xx, xx, xx)
398 SYSTEM_VALUE(local_group_size, 3, 0, xx, xx, xx)
399
400 /* Blend constant color values. Float values are clamped. */
401 SYSTEM_VALUE(blend_const_color_r_float, 1, 0, xx, xx, xx)
402 SYSTEM_VALUE(blend_const_color_g_float, 1, 0, xx, xx, xx)
403 SYSTEM_VALUE(blend_const_color_b_float, 1, 0, xx, xx, xx)
404 SYSTEM_VALUE(blend_const_color_a_float, 1, 0, xx, xx, xx)
405 SYSTEM_VALUE(blend_const_color_rgba8888_unorm, 1, 0, xx, xx, xx)
406 SYSTEM_VALUE(blend_const_color_aaaa8888_unorm, 1, 0, xx, xx, xx)
407
408 /**
409 * Barycentric coordinate intrinsics.
410 *
411 * These set up the barycentric coordinates for a particular interpolation.
412 * The first three are for the simple cases: pixel, centroid, or per-sample
413 * (at gl_SampleID). The next two handle interpolating at a specified
414 * sample location, or interpolating with a vec2 offset,
415 *
416 * The interp_mode index should be either the INTERP_MODE_SMOOTH or
417 * INTERP_MODE_NOPERSPECTIVE enum values.
418 *
419 * The vec2 value produced by these intrinsics is intended for use as the
420 * barycoord source of a load_interpolated_input intrinsic.
421 */
422
423 #define BARYCENTRIC(name, sources, source_components) \
424 INTRINSIC(load_barycentric_##name, sources, ARR(source_components), \
425 true, 2, 0, 1, INTERP_MODE, xx, xx, \
426 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
427
428 /* no sources. const_index[] = { interp_mode } */
429 BARYCENTRIC(pixel, 0, 0)
430 BARYCENTRIC(centroid, 0, 0)
431 BARYCENTRIC(sample, 0, 0)
432 /* src[] = { sample_id }. const_index[] = { interp_mode } */
433 BARYCENTRIC(at_sample, 1, 1)
434 /* src[] = { offset.xy }. const_index[] = { interp_mode } */
435 BARYCENTRIC(at_offset, 1, 2)
436
437 /*
438 * Load operations pull data from some piece of GPU memory. All load
439 * operations operate in terms of offsets into some piece of theoretical
440 * memory. Loads from externally visible memory (UBO and SSBO) simply take a
441 * byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
442 * take a base+offset pair where the base (const_index[0]) gives the location
443 * of the start of the variable being loaded and and the offset source is a
444 * offset into that variable.
445 *
446 * Uniform load operations have a second "range" index that specifies the
447 * range (starting at base) of the data from which we are loading. If
448 * const_index[1] == 0, then the range is unknown.
449 *
450 * Some load operations such as UBO/SSBO load and per_vertex loads take an
451 * additional source to specify which UBO/SSBO/vertex to load from.
452 *
453 * The exact address type depends on the lowering pass that generates the
454 * load/store intrinsics. Typically, this is vec4 units for things such as
455 * varying slots and float units for fragment shader inputs. UBO and SSBO
456 * offsets are always in bytes.
457 */
458
459 #define LOAD(name, srcs, num_indices, idx0, idx1, idx2, flags) \
460 INTRINSIC(load_##name, srcs, ARR(1, 1, 1, 1), true, 0, 0, num_indices, idx0, idx1, idx2, flags)
461
462 /* src[] = { offset }. const_index[] = { base, range } */
463 LOAD(uniform, 1, 2, BASE, RANGE, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
464 /* src[] = { buffer_index, offset }. No const_index */
465 LOAD(ubo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
466 /* src[] = { offset }. const_index[] = { base, component } */
467 LOAD(input, 1, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
468 /* src[] = { vertex, offset }. const_index[] = { base, component } */
469 LOAD(per_vertex_input, 2, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
470 /* src[] = { barycoord, offset }. const_index[] = { base, component } */
471 INTRINSIC(load_interpolated_input, 2, ARR(2, 1), true, 0, 0,
472 2, BASE, COMPONENT, xx,
473 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
474
475 /* src[] = { buffer_index, offset }. No const_index */
476 LOAD(ssbo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
477 /* src[] = { offset }. const_index[] = { base, component } */
478 LOAD(output, 1, 2, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE)
479 /* src[] = { vertex, offset }. const_index[] = { base, component } */
480 LOAD(per_vertex_output, 2, 1, BASE, COMPONENT, xx, NIR_INTRINSIC_CAN_ELIMINATE)
481 /* src[] = { offset }. const_index[] = { base } */
482 LOAD(shared, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
483 /* src[] = { offset }. const_index[] = { base, range } */
484 LOAD(push_constant, 1, 2, BASE, RANGE, xx,
485 NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
486
487 /*
488 * Stores work the same way as loads, except now the first source is the value
489 * to store and the second (and possibly third) source specify where to store
490 * the value. SSBO and shared memory stores also have a write mask as
491 * const_index[0].
492 */
493
494 #define STORE(name, srcs, num_indices, idx0, idx1, idx2, flags) \
495 INTRINSIC(store_##name, srcs, ARR(0, 1, 1, 1), false, 0, 0, num_indices, idx0, idx1, idx2, flags)
496
497 /* src[] = { value, offset }. const_index[] = { base, write_mask, component } */
498 STORE(output, 2, 3, BASE, WRMASK, COMPONENT, 0)
499 /* src[] = { value, vertex, offset }.
500 * const_index[] = { base, write_mask, component }
501 */
502 STORE(per_vertex_output, 3, 3, BASE, WRMASK, COMPONENT, 0)
503 /* src[] = { value, block_index, offset }. const_index[] = { write_mask } */
504 STORE(ssbo, 3, 1, WRMASK, xx, xx, 0)
505 /* src[] = { value, offset }. const_index[] = { base, write_mask } */
506 STORE(shared, 2, 2, BASE, WRMASK, xx, 0)
507
508 LAST_INTRINSIC(store_shared)
509
510 #undef DEFINE_SYSTEM_VALUE
511 #undef INTRINSIC
512 #undef LAST_INTRINSIC