2 # Copyright (C) 2018 Red Hat
3 # Copyright (C) 2014 Intel Corporation
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:
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
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
25 # This file defines all the available intrinsics in one place.
27 # The Intrinsic class corresponds one-to-one with nir_intrinsic_info
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.
34 def __init__(self
, name
, src_components
, dest_components
,
35 indices
, flags
, sysval
):
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 - indices: list of constant indicies
46 - flags: list of semantic flags
47 - sysval: is this a system-value intrinsic
49 assert isinstance(name
, str)
50 assert isinstance(src_components
, list)
52 assert isinstance(src_components
[0], int)
53 assert isinstance(dest_components
, int)
54 assert isinstance(indices
, list)
56 assert isinstance(indices
[0], str)
57 assert isinstance(flags
, list)
59 assert isinstance(flags
[0], str)
60 assert isinstance(sysval
, bool)
63 self
.num_srcs
= len(src_components
)
64 self
.src_components
= src_components
65 self
.has_dest
= (dest_components
>= 0)
66 self
.dest_components
= dest_components
67 self
.num_indices
= len(indices
)
68 self
.indices
= indices
76 # A constant 'base' value that is added to an offset src:
77 BASE
= "NIR_INTRINSIC_BASE"
78 # For store instructions, a writemask:
79 WRMASK
= "NIR_INTRINSIC_WRMASK"
80 # The stream-id for GS emit_vertex/end_primitive intrinsics:
81 STREAM_ID
= "NIR_INTRINSIC_STREAM_ID"
82 # The clip-plane id for load_user_clip_plane intrinsics:
83 UCP_ID
= "NIR_INTRINSIC_UCP_ID"
84 # The amount of data, starting from BASE, that this instruction
85 # may access. This is used to provide bounds if the offset is
87 RANGE
= "NIR_INTRINSIC_RANGE"
88 # The vulkan descriptor set binding for vulkan_resource_index
90 DESC_SET
= "NIR_INTRINSIC_DESC_SET"
91 # The vulkan descriptor set binding for vulkan_resource_index
93 BINDING
= "NIR_INTRINSIC_BINDING"
95 COMPONENT
= "NIR_INTRINSIC_COMPONENT"
96 # Interpolation mode (only meaningful for FS inputs)
97 INTERP_MODE
= "NIR_INTRINSIC_INTERP_MODE"
98 # A binary nir_op to use when performing a reduction or scan operation
99 REDUCTION_OP
= "NIR_INTRINSIC_REDUCTION_OP"
100 # Cluster size for reduction operations
101 CLUSTER_SIZE
= "NIR_INTRINSIC_CLUSTER_SIZE"
102 # Parameter index for a load_param intrinsic
103 PARAM_IDX
= "NIR_INTRINSIC_PARAM_IDX"
104 # Image dimensionality for image intrinsics
105 IMAGE_DIM
= "NIR_INTRINSIC_IMAGE_DIM"
106 # Non-zero if we are accessing an array image
107 IMAGE_ARRAY
= "NIR_INTRINSIC_IMAGE_ARRAY"
108 # Access qualifiers for image and memory access intrinsics
109 ACCESS
= "NIR_INTRINSIC_ACCESS"
110 # Image format for image intrinsics
111 FORMAT
= "NIR_INTRINSIC_FORMAT"
112 # Offset or address alignment
113 ALIGN_MUL
= "NIR_INTRINSIC_ALIGN_MUL"
114 ALIGN_OFFSET
= "NIR_INTRINSIC_ALIGN_OFFSET"
115 # The vulkan descriptor type for vulkan_resource_index
116 DESC_TYPE
= "NIR_INTRINSIC_DESC_TYPE"
122 CAN_ELIMINATE
= "NIR_INTRINSIC_CAN_ELIMINATE"
123 CAN_REORDER
= "NIR_INTRINSIC_CAN_REORDER"
127 def intrinsic(name
, src_comp
=[], dest_comp
=-1, indices
=[],
128 flags
=[], sysval
=False):
129 assert name
not in INTR_OPCODES
130 INTR_OPCODES
[name
] = Intrinsic(name
, src_comp
, dest_comp
,
131 indices
, flags
, sysval
)
133 intrinsic("nop", flags
=[CAN_ELIMINATE
])
135 intrinsic("load_param", dest_comp
=0, indices
=[PARAM_IDX
], flags
=[CAN_ELIMINATE
])
137 intrinsic("load_deref", dest_comp
=0, src_comp
=[-1],
138 indices
=[ACCESS
], flags
=[CAN_ELIMINATE
])
139 intrinsic("store_deref", src_comp
=[-1, 0], indices
=[WRMASK
, ACCESS
])
140 intrinsic("copy_deref", src_comp
=[-1, -1])
142 # Interpolation of input. The interp_deref_at* intrinsics are similar to the
143 # load_var intrinsic acting on a shader input except that they interpolate the
144 # input differently. The at_sample and at_offset intrinsics take an
145 # additional source that is an integer sample id or a vec2 position offset
148 intrinsic("interp_deref_at_centroid", dest_comp
=0, src_comp
=[1],
149 flags
=[ CAN_ELIMINATE
, CAN_REORDER
])
150 intrinsic("interp_deref_at_sample", src_comp
=[1, 1], dest_comp
=0,
151 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
152 intrinsic("interp_deref_at_offset", src_comp
=[1, 2], dest_comp
=0,
153 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
155 # Ask the driver for the size of a given buffer. It takes the buffer index
157 intrinsic("get_buffer_size", src_comp
=[1], dest_comp
=1,
158 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
160 # a barrier is an intrinsic with no inputs/outputs but which can't be moved
161 # around/optimized in general
168 # Memory barrier with semantics analogous to the memoryBarrier() GLSL
170 barrier("memory_barrier")
172 # Shader clock intrinsic with semantics analogous to the clock2x32ARB()
174 # The latter can be used as code motion barrier, which is currently not
176 intrinsic("shader_clock", dest_comp
=2, flags
=[CAN_ELIMINATE
])
178 # Shader ballot intrinsics with semantics analogous to the
181 # readInvocationARB()
182 # readFirstInvocationARB()
184 # GLSL functions from ARB_shader_ballot.
185 intrinsic("ballot", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
186 intrinsic("read_invocation", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
187 intrinsic("read_first_invocation", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
189 # Additional SPIR-V ballot intrinsics
191 # These correspond to the SPIR-V opcodes
193 # OpGroupUniformElect
194 # OpSubgroupFirstInvocationKHR
195 intrinsic("elect", dest_comp
=1, flags
=[CAN_ELIMINATE
])
196 intrinsic("first_invocation", dest_comp
=1, flags
=[CAN_ELIMINATE
])
198 # Memory barrier with semantics analogous to the compute shader
199 # groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
200 # memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
201 barrier("group_memory_barrier")
202 barrier("memory_barrier_atomic_counter")
203 barrier("memory_barrier_buffer")
204 barrier("memory_barrier_image")
205 barrier("memory_barrier_shared")
206 barrier("begin_invocation_interlock")
207 barrier("end_invocation_interlock")
209 # A conditional discard, with a single boolean source.
210 intrinsic("discard_if", src_comp
=[1])
212 # ARB_shader_group_vote intrinsics
213 intrinsic("vote_any", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
214 intrinsic("vote_all", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
215 intrinsic("vote_feq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
216 intrinsic("vote_ieq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
218 # Ballot ALU operations from SPIR-V.
220 # These operations work like their ALU counterparts except that the operate
221 # on a uvec4 which is treated as a 128bit integer. Also, they are, in
222 # general, free to ignore any bits which are above the subgroup size.
223 intrinsic("ballot_bitfield_extract", src_comp
=[4, 1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
224 intrinsic("ballot_bit_count_reduce", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
225 intrinsic("ballot_bit_count_inclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
226 intrinsic("ballot_bit_count_exclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
227 intrinsic("ballot_find_lsb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
228 intrinsic("ballot_find_msb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
230 # Shuffle operations from SPIR-V.
231 intrinsic("shuffle", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
232 intrinsic("shuffle_xor", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
233 intrinsic("shuffle_up", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
234 intrinsic("shuffle_down", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
236 # Quad operations from SPIR-V.
237 intrinsic("quad_broadcast", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
238 intrinsic("quad_swap_horizontal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
239 intrinsic("quad_swap_vertical", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
240 intrinsic("quad_swap_diagonal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
242 intrinsic("reduce", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
, CLUSTER_SIZE
],
243 flags
=[CAN_ELIMINATE
])
244 intrinsic("inclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
245 flags
=[CAN_ELIMINATE
])
246 intrinsic("exclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
247 flags
=[CAN_ELIMINATE
])
249 # Basic Geometry Shader intrinsics.
251 # emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
252 # index, which is the stream ID to write to.
254 # end_primitive implements GLSL's EndPrimitive() built-in.
255 intrinsic("emit_vertex", indices
=[STREAM_ID
])
256 intrinsic("end_primitive", indices
=[STREAM_ID
])
258 # Geometry Shader intrinsics with a vertex count.
260 # Alternatively, drivers may implement these intrinsics, and use
261 # nir_lower_gs_intrinsics() to convert from the basic intrinsics.
263 # These maintain a count of the number of vertices emitted, as an additional
264 # unsigned integer source.
265 intrinsic("emit_vertex_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
266 intrinsic("end_primitive_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
267 intrinsic("set_vertex_count", src_comp
=[1])
271 # The *_var variants take an atomic_uint nir_variable, while the other,
272 # lowered, variants take a constant buffer index and register offset.
274 def atomic(name
, flags
=[]):
275 intrinsic(name
+ "_deref", src_comp
=[-1], dest_comp
=1, flags
=flags
)
276 intrinsic(name
, src_comp
=[1], dest_comp
=1, indices
=[BASE
], flags
=flags
)
279 intrinsic(name
+ "_deref", src_comp
=[-1, 1], dest_comp
=1)
280 intrinsic(name
, src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
283 intrinsic(name
+ "_deref", src_comp
=[-1, 1, 1], dest_comp
=1)
284 intrinsic(name
, src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
286 atomic("atomic_counter_inc")
287 atomic("atomic_counter_pre_dec")
288 atomic("atomic_counter_post_dec")
289 atomic("atomic_counter_read", flags
=[CAN_ELIMINATE
])
290 atomic2("atomic_counter_add")
291 atomic2("atomic_counter_min")
292 atomic2("atomic_counter_max")
293 atomic2("atomic_counter_and")
294 atomic2("atomic_counter_or")
295 atomic2("atomic_counter_xor")
296 atomic2("atomic_counter_exchange")
297 atomic3("atomic_counter_comp_swap")
299 # Image load, store and atomic intrinsics.
301 # All image intrinsics come in two versions. One which take an image target
302 # passed as a deref chain as the first source and one which takes an index or
303 # handle as the first source. In the first version, the image variable
304 # contains the memory and layout qualifiers that influence the semantics of
305 # the intrinsic. In the second, the image format and access qualifiers are
306 # provided as constant indices.
308 # All image intrinsics take a four-coordinate vector and a sample index as
309 # 2nd and 3rd sources, determining the location within the image that will be
310 # accessed by the intrinsic. Components not applicable to the image target
311 # in use are undefined. Image store takes an additional four-component
312 # argument with the value to be written, and image atomic operations take
313 # either one or two additional scalar arguments with the same meaning as in
314 # the ARB_shader_image_load_store specification.
315 def image(name
, src_comp
=[], **kwargs
):
316 intrinsic("image_deref_" + name
, src_comp
=[1] + src_comp
, **kwargs
)
317 intrinsic("image_" + name
, src_comp
=[1] + src_comp
,
318 indices
=[IMAGE_DIM
, IMAGE_ARRAY
, FORMAT
, ACCESS
], **kwargs
)
320 image("load", src_comp
=[4, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
321 image("store", src_comp
=[4, 1, 0])
322 image("atomic_add", src_comp
=[4, 1, 1], dest_comp
=1)
323 image("atomic_min", src_comp
=[4, 1, 1], dest_comp
=1)
324 image("atomic_max", src_comp
=[4, 1, 1], dest_comp
=1)
325 image("atomic_and", src_comp
=[4, 1, 1], dest_comp
=1)
326 image("atomic_or", src_comp
=[4, 1, 1], dest_comp
=1)
327 image("atomic_xor", src_comp
=[4, 1, 1], dest_comp
=1)
328 image("atomic_exchange", src_comp
=[4, 1, 1], dest_comp
=1)
329 image("atomic_comp_swap", src_comp
=[4, 1, 1, 1], dest_comp
=1)
330 image("atomic_fadd", src_comp
=[1, 4, 1, 1], dest_comp
=1)
331 image("size", dest_comp
=0, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
332 image("samples", dest_comp
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
334 # Intel-specific query for loading from the brw_image_param struct passed
335 # into the shader as a uniform. The variable is a deref to the image
336 # variable. The const index specifies which of the six parameters to load.
337 intrinsic("image_deref_load_param_intel", src_comp
=[1], dest_comp
=0,
338 indices
=[BASE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
339 image("load_raw_intel", src_comp
=[1], dest_comp
=0,
340 flags
=[CAN_ELIMINATE
])
341 image("store_raw_intel", src_comp
=[1, 0])
343 # Vulkan descriptor set intrinsics
345 # The Vulkan API uses a different binding model from GL. In the Vulkan
346 # API, all external resources are represented by a tuple:
348 # (descriptor set, binding, array index)
350 # where the array index is the only thing allowed to be indirect. The
351 # vulkan_surface_index intrinsic takes the descriptor set and binding as
352 # its first two indices and the array index as its source. The third
353 # index is a nir_variable_mode in case that's useful to the backend.
355 # The intended usage is that the shader will call vulkan_surface_index to
356 # get an index and then pass that as the buffer index ubo/ssbo calls.
358 # The vulkan_resource_reindex intrinsic takes a resource index in src0
359 # (the result of a vulkan_resource_index or vulkan_resource_reindex) which
360 # corresponds to the tuple (set, binding, index) and computes an index
361 # corresponding to tuple (set, binding, idx + src1).
362 intrinsic("vulkan_resource_index", src_comp
=[1], dest_comp
=1,
363 indices
=[DESC_SET
, BINDING
, DESC_TYPE
],
364 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
365 intrinsic("vulkan_resource_reindex", src_comp
=[1, 1], dest_comp
=1,
366 indices
=[DESC_TYPE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
368 # variable atomic intrinsics
370 # All of these variable atomic memory operations read a value from memory,
371 # compute a new value using one of the operations below, write the new value
372 # to memory, and return the original value read.
374 # All operations take 2 sources except CompSwap that takes 3. These sources
377 # 0: A deref to the memory on which to perform the atomic
378 # 1: The data parameter to the atomic function (i.e. the value to add
379 # in shared_atomic_add, etc).
380 # 2: For CompSwap only: the second data parameter.
381 intrinsic("deref_atomic_add", src_comp
=[-1, 1], dest_comp
=1)
382 intrinsic("deref_atomic_imin", src_comp
=[-1, 1], dest_comp
=1)
383 intrinsic("deref_atomic_umin", src_comp
=[-1, 1], dest_comp
=1)
384 intrinsic("deref_atomic_imax", src_comp
=[-1, 1], dest_comp
=1)
385 intrinsic("deref_atomic_umax", src_comp
=[-1, 1], dest_comp
=1)
386 intrinsic("deref_atomic_and", src_comp
=[-1, 1], dest_comp
=1)
387 intrinsic("deref_atomic_or", src_comp
=[-1, 1], dest_comp
=1)
388 intrinsic("deref_atomic_xor", src_comp
=[-1, 1], dest_comp
=1)
389 intrinsic("deref_atomic_exchange", src_comp
=[-1, 1], dest_comp
=1)
390 intrinsic("deref_atomic_comp_swap", src_comp
=[-1, 1, 1], dest_comp
=1)
391 intrinsic("deref_atomic_fadd", src_comp
=[-1, 1], dest_comp
=1)
392 intrinsic("deref_atomic_fmin", src_comp
=[-1, 1], dest_comp
=1)
393 intrinsic("deref_atomic_fmax", src_comp
=[-1, 1], dest_comp
=1)
394 intrinsic("deref_atomic_fcomp_swap", src_comp
=[-1, 1, 1], dest_comp
=1)
396 # SSBO atomic intrinsics
398 # All of the SSBO atomic memory operations read a value from memory,
399 # compute a new value using one of the operations below, write the new
400 # value to memory, and return the original value read.
402 # All operations take 3 sources except CompSwap that takes 4. These
405 # 0: The SSBO buffer index.
406 # 1: The offset into the SSBO buffer of the variable that the atomic
407 # operation will operate on.
408 # 2: The data parameter to the atomic function (i.e. the value to add
409 # in ssbo_atomic_add, etc).
410 # 3: For CompSwap only: the second data parameter.
411 intrinsic("ssbo_atomic_add", src_comp
=[1, 1, 1], dest_comp
=1)
412 intrinsic("ssbo_atomic_imin", src_comp
=[1, 1, 1], dest_comp
=1)
413 intrinsic("ssbo_atomic_umin", src_comp
=[1, 1, 1], dest_comp
=1)
414 intrinsic("ssbo_atomic_imax", src_comp
=[1, 1, 1], dest_comp
=1)
415 intrinsic("ssbo_atomic_umax", src_comp
=[1, 1, 1], dest_comp
=1)
416 intrinsic("ssbo_atomic_and", src_comp
=[1, 1, 1], dest_comp
=1)
417 intrinsic("ssbo_atomic_or", src_comp
=[1, 1, 1], dest_comp
=1)
418 intrinsic("ssbo_atomic_xor", src_comp
=[1, 1, 1], dest_comp
=1)
419 intrinsic("ssbo_atomic_exchange", src_comp
=[1, 1, 1], dest_comp
=1)
420 intrinsic("ssbo_atomic_comp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
421 intrinsic("ssbo_atomic_fadd", src_comp
=[1, 1, 1], dest_comp
=1)
422 intrinsic("ssbo_atomic_fmin", src_comp
=[1, 1, 1], dest_comp
=1)
423 intrinsic("ssbo_atomic_fmax", src_comp
=[1, 1, 1], dest_comp
=1)
424 intrinsic("ssbo_atomic_fcomp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
426 # CS shared variable atomic intrinsics
428 # All of the shared variable atomic memory operations read a value from
429 # memory, compute a new value using one of the operations below, write the
430 # new value to memory, and return the original value read.
432 # All operations take 2 sources except CompSwap that takes 3. These
435 # 0: The offset into the shared variable storage region that the atomic
436 # operation will operate on.
437 # 1: The data parameter to the atomic function (i.e. the value to add
438 # in shared_atomic_add, etc).
439 # 2: For CompSwap only: the second data parameter.
440 intrinsic("shared_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
441 intrinsic("shared_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
442 intrinsic("shared_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
443 intrinsic("shared_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
444 intrinsic("shared_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
445 intrinsic("shared_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
446 intrinsic("shared_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
447 intrinsic("shared_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
448 intrinsic("shared_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
449 intrinsic("shared_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
450 intrinsic("shared_atomic_fadd", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
451 intrinsic("shared_atomic_fmin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
452 intrinsic("shared_atomic_fmax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
453 intrinsic("shared_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
455 def system_value(name
, dest_comp
, indices
=[]):
456 intrinsic("load_" + name
, [], dest_comp
, indices
,
457 flags
=[CAN_ELIMINATE
, CAN_REORDER
], sysval
=True)
459 system_value("frag_coord", 4)
460 system_value("front_face", 1)
461 system_value("vertex_id", 1)
462 system_value("vertex_id_zero_base", 1)
463 system_value("first_vertex", 1)
464 system_value("is_indexed_draw", 1)
465 system_value("base_vertex", 1)
466 system_value("instance_id", 1)
467 system_value("base_instance", 1)
468 system_value("draw_id", 1)
469 system_value("sample_id", 1)
470 # sample_id_no_per_sample is like sample_id but does not imply per-
471 # sample shading. See the lower_helper_invocation option.
472 system_value("sample_id_no_per_sample", 1)
473 system_value("sample_pos", 2)
474 system_value("sample_mask_in", 1)
475 system_value("primitive_id", 1)
476 system_value("invocation_id", 1)
477 system_value("tess_coord", 3)
478 system_value("tess_level_outer", 4)
479 system_value("tess_level_inner", 2)
480 system_value("patch_vertices_in", 1)
481 system_value("local_invocation_id", 3)
482 system_value("local_invocation_index", 1)
483 system_value("work_group_id", 3)
484 system_value("user_clip_plane", 4, indices
=[UCP_ID
])
485 system_value("num_work_groups", 3)
486 system_value("helper_invocation", 1)
487 system_value("alpha_ref_float", 1)
488 system_value("layer_id", 1)
489 system_value("view_index", 1)
490 system_value("subgroup_size", 1)
491 system_value("subgroup_invocation", 1)
492 system_value("subgroup_eq_mask", 0)
493 system_value("subgroup_ge_mask", 0)
494 system_value("subgroup_gt_mask", 0)
495 system_value("subgroup_le_mask", 0)
496 system_value("subgroup_lt_mask", 0)
497 system_value("num_subgroups", 1)
498 system_value("subgroup_id", 1)
499 system_value("local_group_size", 3)
500 system_value("global_invocation_id", 3)
501 system_value("work_dim", 1)
503 # Blend constant color values. Float values are clamped.#
504 system_value("blend_const_color_r_float", 1)
505 system_value("blend_const_color_g_float", 1)
506 system_value("blend_const_color_b_float", 1)
507 system_value("blend_const_color_a_float", 1)
508 system_value("blend_const_color_rgba8888_unorm", 1)
509 system_value("blend_const_color_aaaa8888_unorm", 1)
511 # Barycentric coordinate intrinsics.
513 # These set up the barycentric coordinates for a particular interpolation.
514 # The first three are for the simple cases: pixel, centroid, or per-sample
515 # (at gl_SampleID). The next two handle interpolating at a specified
516 # sample location, or interpolating with a vec2 offset,
518 # The interp_mode index should be either the INTERP_MODE_SMOOTH or
519 # INTERP_MODE_NOPERSPECTIVE enum values.
521 # The vec2 value produced by these intrinsics is intended for use as the
522 # barycoord source of a load_interpolated_input intrinsic.
524 def barycentric(name
, src_comp
=[]):
525 intrinsic("load_barycentric_" + name
, src_comp
=src_comp
, dest_comp
=2,
526 indices
=[INTERP_MODE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
528 # no sources. const_index[] = { interp_mode }
530 barycentric("centroid")
531 barycentric("sample")
532 # src[] = { sample_id }. const_index[] = { interp_mode }
533 barycentric("at_sample", [1])
534 # src[] = { offset.xy }. const_index[] = { interp_mode }
535 barycentric("at_offset", [2])
537 # Load operations pull data from some piece of GPU memory. All load
538 # operations operate in terms of offsets into some piece of theoretical
539 # memory. Loads from externally visible memory (UBO and SSBO) simply take a
540 # byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
541 # take a base+offset pair where the base (const_index[0]) gives the location
542 # of the start of the variable being loaded and and the offset source is a
543 # offset into that variable.
545 # Uniform load operations have a second "range" index that specifies the
546 # range (starting at base) of the data from which we are loading. If
547 # const_index[1] == 0, then the range is unknown.
549 # Some load operations such as UBO/SSBO load and per_vertex loads take an
550 # additional source to specify which UBO/SSBO/vertex to load from.
552 # The exact address type depends on the lowering pass that generates the
553 # load/store intrinsics. Typically, this is vec4 units for things such as
554 # varying slots and float units for fragment shader inputs. UBO and SSBO
555 # offsets are always in bytes.
557 def load(name
, num_srcs
, indices
=[], flags
=[]):
558 intrinsic("load_" + name
, [1] * num_srcs
, dest_comp
=0, indices
=indices
,
561 # src[] = { offset }. const_index[] = { base, range }
562 load("uniform", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
563 # src[] = { buffer_index, offset }. const_index[] = { align_mul, align_offset }
564 load("ubo", 2, [ALIGN_MUL
, ALIGN_OFFSET
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
565 # src[] = { offset }. const_index[] = { base, component }
566 load("input", 1, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
567 # src[] = { vertex, offset }. const_index[] = { base, component }
568 load("per_vertex_input", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
569 # src[] = { barycoord, offset }. const_index[] = { base, component }
570 intrinsic("load_interpolated_input", src_comp
=[2, 1], dest_comp
=0,
571 indices
=[BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
573 # src[] = { buffer_index, offset }.
574 # const_index[] = { access, align_mul, align_offset }
575 load("ssbo", 2, [ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
576 # src[] = { offset }. const_index[] = { base, component }
577 load("output", 1, [BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
])
578 # src[] = { vertex, offset }. const_index[] = { base }
579 load("per_vertex_output", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
])
580 # src[] = { offset }. const_index[] = { base, align_mul, align_offset }
581 load("shared", 1, [BASE
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
582 # src[] = { offset }. const_index[] = { base, range }
583 load("push_constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
584 # src[] = { offset }. const_index[] = { base, range }
585 load("constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
587 # Stores work the same way as loads, except now the first source is the value
588 # to store and the second (and possibly third) source specify where to store
589 # the value. SSBO and shared memory stores also have a write mask as
592 def store(name
, num_srcs
, indices
=[], flags
=[]):
593 intrinsic("store_" + name
, [0] + ([1] * (num_srcs
- 1)), indices
=indices
, flags
=flags
)
595 # src[] = { value, offset }. const_index[] = { base, write_mask, component }
596 store("output", 2, [BASE
, WRMASK
, COMPONENT
])
597 # src[] = { value, vertex, offset }.
598 # const_index[] = { base, write_mask, component }
599 store("per_vertex_output", 3, [BASE
, WRMASK
, COMPONENT
])
600 # src[] = { value, block_index, offset }
601 # const_index[] = { write_mask, access, align_mul, align_offset }
602 store("ssbo", 3, [WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
603 # src[] = { value, offset }.
604 # const_index[] = { base, write_mask, align_mul, align_offset }
605 store("shared", 2, [BASE
, WRMASK
, ALIGN_MUL
, ALIGN_OFFSET
])