a6c74dc254347c7d6b9bb126e203133e47d989ab
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
=0,
367 indices
=[DESC_SET
, BINDING
, DESC_TYPE
],
368 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
369 intrinsic("vulkan_resource_reindex", src_comp
=[0, 1], dest_comp
=0,
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 # Global atomic intrinsics
463 # All of the shared variable atomic memory operations read a value from
464 # memory, compute a new value using one of the operations below, write the
465 # new value to memory, and return the original value read.
467 # All operations take 2 sources except CompSwap that takes 3. These
470 # 0: The memory address that the atomic operation will operate on.
471 # 1: The data parameter to the atomic function (i.e. the value to add
472 # in shared_atomic_add, etc).
473 # 2: For CompSwap only: the second data parameter.
474 intrinsic("global_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
475 intrinsic("global_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
476 intrinsic("global_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
477 intrinsic("global_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
478 intrinsic("global_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
479 intrinsic("global_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
480 intrinsic("global_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
481 intrinsic("global_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
482 intrinsic("global_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
483 intrinsic("global_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
484 intrinsic("global_atomic_fadd", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
485 intrinsic("global_atomic_fmin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
486 intrinsic("global_atomic_fmax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
487 intrinsic("global_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
489 def system_value(name
, dest_comp
, indices
=[], bit_sizes
=[32]):
490 intrinsic("load_" + name
, [], dest_comp
, indices
,
491 flags
=[CAN_ELIMINATE
, CAN_REORDER
], sysval
=True,
494 system_value("frag_coord", 4)
495 system_value("front_face", 1, bit_sizes
=[1, 32])
496 system_value("vertex_id", 1)
497 system_value("vertex_id_zero_base", 1)
498 system_value("first_vertex", 1)
499 system_value("is_indexed_draw", 1)
500 system_value("base_vertex", 1)
501 system_value("instance_id", 1)
502 system_value("base_instance", 1)
503 system_value("draw_id", 1)
504 system_value("sample_id", 1)
505 # sample_id_no_per_sample is like sample_id but does not imply per-
506 # sample shading. See the lower_helper_invocation option.
507 system_value("sample_id_no_per_sample", 1)
508 system_value("sample_pos", 2)
509 system_value("sample_mask_in", 1)
510 system_value("primitive_id", 1)
511 system_value("invocation_id", 1)
512 system_value("tess_coord", 3)
513 system_value("tess_level_outer", 4)
514 system_value("tess_level_inner", 2)
515 system_value("patch_vertices_in", 1)
516 system_value("local_invocation_id", 3)
517 system_value("local_invocation_index", 1)
518 system_value("work_group_id", 3)
519 system_value("user_clip_plane", 4, indices
=[UCP_ID
])
520 system_value("num_work_groups", 3)
521 system_value("helper_invocation", 1, bit_sizes
=[1, 32])
522 system_value("alpha_ref_float", 1)
523 system_value("layer_id", 1)
524 system_value("view_index", 1)
525 system_value("subgroup_size", 1)
526 system_value("subgroup_invocation", 1)
527 system_value("subgroup_eq_mask", 0, bit_sizes
=[32, 64])
528 system_value("subgroup_ge_mask", 0, bit_sizes
=[32, 64])
529 system_value("subgroup_gt_mask", 0, bit_sizes
=[32, 64])
530 system_value("subgroup_le_mask", 0, bit_sizes
=[32, 64])
531 system_value("subgroup_lt_mask", 0, bit_sizes
=[32, 64])
532 system_value("num_subgroups", 1)
533 system_value("subgroup_id", 1)
534 system_value("local_group_size", 3)
535 system_value("global_invocation_id", 3, bit_sizes
=[32, 64])
536 system_value("global_invocation_index", 1, bit_sizes
=[32, 64])
537 system_value("work_dim", 1)
538 # Driver-specific viewport scale/offset parameters.
540 # VC4 and V3D need to emit a scaled version of the position in the vertex
541 # shaders for binning, and having system values lets us move the math for that
543 system_value("viewport_x_scale", 1)
544 system_value("viewport_y_scale", 1)
545 system_value("viewport_z_scale", 1)
546 system_value("viewport_z_offset", 1)
548 # Blend constant color values. Float values are clamped.#
549 system_value("blend_const_color_r_float", 1)
550 system_value("blend_const_color_g_float", 1)
551 system_value("blend_const_color_b_float", 1)
552 system_value("blend_const_color_a_float", 1)
553 system_value("blend_const_color_rgba8888_unorm", 1)
554 system_value("blend_const_color_aaaa8888_unorm", 1)
556 # Barycentric coordinate intrinsics.
558 # These set up the barycentric coordinates for a particular interpolation.
559 # The first three are for the simple cases: pixel, centroid, or per-sample
560 # (at gl_SampleID). The next two handle interpolating at a specified
561 # sample location, or interpolating with a vec2 offset,
563 # The interp_mode index should be either the INTERP_MODE_SMOOTH or
564 # INTERP_MODE_NOPERSPECTIVE enum values.
566 # The vec2 value produced by these intrinsics is intended for use as the
567 # barycoord source of a load_interpolated_input intrinsic.
569 def barycentric(name
, src_comp
=[]):
570 intrinsic("load_barycentric_" + name
, src_comp
=src_comp
, dest_comp
=2,
571 indices
=[INTERP_MODE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
573 # no sources. const_index[] = { interp_mode }
575 barycentric("centroid")
576 barycentric("sample")
577 # src[] = { sample_id }. const_index[] = { interp_mode }
578 barycentric("at_sample", [1])
579 # src[] = { offset.xy }. const_index[] = { interp_mode }
580 barycentric("at_offset", [2])
582 # Load operations pull data from some piece of GPU memory. All load
583 # operations operate in terms of offsets into some piece of theoretical
584 # memory. Loads from externally visible memory (UBO and SSBO) simply take a
585 # byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
586 # take a base+offset pair where the base (const_index[0]) gives the location
587 # of the start of the variable being loaded and and the offset source is a
588 # offset into that variable.
590 # Uniform load operations have a second "range" index that specifies the
591 # range (starting at base) of the data from which we are loading. If
592 # const_index[1] == 0, then the range is unknown.
594 # Some load operations such as UBO/SSBO load and per_vertex loads take an
595 # additional source to specify which UBO/SSBO/vertex to load from.
597 # The exact address type depends on the lowering pass that generates the
598 # load/store intrinsics. Typically, this is vec4 units for things such as
599 # varying slots and float units for fragment shader inputs. UBO and SSBO
600 # offsets are always in bytes.
602 def load(name
, num_srcs
, indices
=[], flags
=[]):
603 intrinsic("load_" + name
, [1] * num_srcs
, dest_comp
=0, indices
=indices
,
606 # src[] = { offset }. const_index[] = { base, range }
607 load("uniform", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
608 # src[] = { buffer_index, offset }. const_index[] = { align_mul, align_offset }
609 load("ubo", 2, [ALIGN_MUL
, ALIGN_OFFSET
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
610 # src[] = { offset }. const_index[] = { base, component }
611 load("input", 1, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
612 # src[] = { vertex, offset }. const_index[] = { base, component }
613 load("per_vertex_input", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
614 # src[] = { barycoord, offset }. const_index[] = { base, component }
615 intrinsic("load_interpolated_input", src_comp
=[2, 1], dest_comp
=0,
616 indices
=[BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
618 # src[] = { buffer_index, offset }.
619 # const_index[] = { access, align_mul, align_offset }
620 load("ssbo", 2, [ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
621 # src[] = { offset }. const_index[] = { base, component }
622 load("output", 1, [BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
])
623 # src[] = { vertex, offset }. const_index[] = { base }
624 load("per_vertex_output", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
])
625 # src[] = { offset }. const_index[] = { base, align_mul, align_offset }
626 load("shared", 1, [BASE
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
627 # src[] = { offset }. const_index[] = { base, range }
628 load("push_constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
629 # src[] = { offset }. const_index[] = { base, range }
630 load("constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
631 # src[] = { address }.
632 # const_index[] = { access, align_mul, align_offset }
633 load("global", 1, [ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
635 # Stores work the same way as loads, except now the first source is the value
636 # to store and the second (and possibly third) source specify where to store
637 # the value. SSBO and shared memory stores also have a write mask as
640 def store(name
, num_srcs
, indices
=[], flags
=[]):
641 intrinsic("store_" + name
, [0] + ([1] * (num_srcs
- 1)), indices
=indices
, flags
=flags
)
643 # src[] = { value, offset }. const_index[] = { base, write_mask, component }
644 store("output", 2, [BASE
, WRMASK
, COMPONENT
])
645 # src[] = { value, vertex, offset }.
646 # const_index[] = { base, write_mask, component }
647 store("per_vertex_output", 3, [BASE
, WRMASK
, COMPONENT
])
648 # src[] = { value, block_index, offset }
649 # const_index[] = { write_mask, access, align_mul, align_offset }
650 store("ssbo", 3, [WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
651 # src[] = { value, offset }.
652 # const_index[] = { base, write_mask, align_mul, align_offset }
653 store("shared", 2, [BASE
, WRMASK
, ALIGN_MUL
, ALIGN_OFFSET
])
654 # src[] = { value, address }.
655 # const_index[] = { write_mask, align_mul, align_offset }
656 store("global", 2, [WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
659 # IR3-specific version of most SSBO intrinsics. The only different
660 # compare to the originals is that they add an extra source to hold
661 # the dword-offset, which is needed by the backend code apart from
662 # the byte-offset already provided by NIR in one of the sources.
664 # NIR lowering pass 'ir3_nir_lower_io_offset' will replace the
665 # original SSBO intrinsics by these, placing the computed
666 # dword-offset always in the last source.
668 # The float versions are not handled because those are not supported
670 intrinsic("store_ssbo_ir3", src_comp
=[0, 1, 1, 1],
671 indices
=[WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
672 intrinsic("load_ssbo_ir3", src_comp
=[1, 1, 1], dest_comp
=0,
673 indices
=[ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], flags
=[CAN_ELIMINATE
])
674 intrinsic("ssbo_atomic_add_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
675 intrinsic("ssbo_atomic_imin_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
676 intrinsic("ssbo_atomic_umin_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
677 intrinsic("ssbo_atomic_imax_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
678 intrinsic("ssbo_atomic_umax_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
679 intrinsic("ssbo_atomic_and_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
680 intrinsic("ssbo_atomic_or_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
681 intrinsic("ssbo_atomic_xor_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
682 intrinsic("ssbo_atomic_exchange_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
683 intrinsic("ssbo_atomic_comp_swap_ir3", src_comp
=[1, 1, 1, 1, 1], dest_comp
=1)