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