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