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"
121 # The nir_alu_type of a uniform/input/output
122 TYPE
= "NIR_INTRINSIC_TYPE"
123 # The swizzle mask for quad_swizzle_amd & masked_swizzle_amd
124 SWIZZLE_MASK
= "NIR_INTRINSIC_SWIZZLE_MASK"
130 CAN_ELIMINATE
= "NIR_INTRINSIC_CAN_ELIMINATE"
131 CAN_REORDER
= "NIR_INTRINSIC_CAN_REORDER"
135 # Defines a new NIR intrinsic. By default, the intrinsic will have no sources
136 # and no destination.
138 # You can set dest_comp=n to enable a destination for the intrinsic, in which
139 # case it will have that many components, or =0 for "as many components as the
140 # NIR destination value."
142 # Set src_comp=n to enable sources for the intruction. It can be an array of
143 # component counts, or (for convenience) a scalar component count if there's
144 # only one source. If a component count is 0, it will be as many components as
145 # the intrinsic has based on the dest_comp.
146 def intrinsic(name
, src_comp
=[], dest_comp
=-1, indices
=[],
147 flags
=[], sysval
=False, bit_sizes
=[]):
148 assert name
not in INTR_OPCODES
149 INTR_OPCODES
[name
] = Intrinsic(name
, src_comp
, dest_comp
,
150 indices
, flags
, sysval
, bit_sizes
)
152 intrinsic("nop", flags
=[CAN_ELIMINATE
])
154 intrinsic("load_param", dest_comp
=0, indices
=[PARAM_IDX
], flags
=[CAN_ELIMINATE
])
156 intrinsic("load_deref", dest_comp
=0, src_comp
=[-1],
157 indices
=[ACCESS
], flags
=[CAN_ELIMINATE
])
158 intrinsic("store_deref", src_comp
=[-1, 0], indices
=[WRMASK
, ACCESS
])
159 intrinsic("copy_deref", src_comp
=[-1, -1])
161 # Interpolation of input. The interp_deref_at* intrinsics are similar to the
162 # load_var intrinsic acting on a shader input except that they interpolate the
163 # input differently. The at_sample and at_offset intrinsics take an
164 # additional source that is an integer sample id or a vec2 position offset
167 intrinsic("interp_deref_at_centroid", dest_comp
=0, src_comp
=[1],
168 flags
=[ CAN_ELIMINATE
, CAN_REORDER
])
169 intrinsic("interp_deref_at_sample", src_comp
=[1, 1], dest_comp
=0,
170 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
171 intrinsic("interp_deref_at_offset", src_comp
=[1, 2], dest_comp
=0,
172 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
174 # Gets the length of an unsized array at the end of a buffer
175 intrinsic("deref_buffer_array_length", src_comp
=[-1], dest_comp
=1,
176 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
178 # Ask the driver for the size of a given buffer. It takes the buffer index
180 intrinsic("get_buffer_size", src_comp
=[-1], dest_comp
=1,
181 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
183 # a barrier is an intrinsic with no inputs/outputs but which can't be moved
184 # around/optimized in general
191 # Memory barrier with semantics analogous to the memoryBarrier() GLSL
193 barrier("memory_barrier")
195 # Shader clock intrinsic with semantics analogous to the clock2x32ARB()
197 # The latter can be used as code motion barrier, which is currently not
199 intrinsic("shader_clock", dest_comp
=2, flags
=[CAN_ELIMINATE
])
201 # Shader ballot intrinsics with semantics analogous to the
204 # readInvocationARB()
205 # readFirstInvocationARB()
207 # GLSL functions from ARB_shader_ballot.
208 intrinsic("ballot", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
209 intrinsic("read_invocation", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
210 intrinsic("read_first_invocation", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
212 # Additional SPIR-V ballot intrinsics
214 # These correspond to the SPIR-V opcodes
216 # OpGroupUniformElect
217 # OpSubgroupFirstInvocationKHR
218 intrinsic("elect", dest_comp
=1, flags
=[CAN_ELIMINATE
])
219 intrinsic("first_invocation", dest_comp
=1, flags
=[CAN_ELIMINATE
])
221 # Memory barrier with semantics analogous to the compute shader
222 # groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
223 # memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
224 barrier("group_memory_barrier")
225 barrier("memory_barrier_atomic_counter")
226 barrier("memory_barrier_buffer")
227 barrier("memory_barrier_image")
228 barrier("memory_barrier_shared")
229 barrier("begin_invocation_interlock")
230 barrier("end_invocation_interlock")
232 # A conditional discard, with a single boolean source.
233 intrinsic("discard_if", src_comp
=[1])
235 # ARB_shader_group_vote intrinsics
236 intrinsic("vote_any", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
237 intrinsic("vote_all", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
238 intrinsic("vote_feq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
239 intrinsic("vote_ieq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
241 # Ballot ALU operations from SPIR-V.
243 # These operations work like their ALU counterparts except that the operate
244 # on a uvec4 which is treated as a 128bit integer. Also, they are, in
245 # general, free to ignore any bits which are above the subgroup size.
246 intrinsic("ballot_bitfield_extract", src_comp
=[4, 1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
247 intrinsic("ballot_bit_count_reduce", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
248 intrinsic("ballot_bit_count_inclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
249 intrinsic("ballot_bit_count_exclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
250 intrinsic("ballot_find_lsb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
251 intrinsic("ballot_find_msb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
253 # Shuffle operations from SPIR-V.
254 intrinsic("shuffle", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
255 intrinsic("shuffle_xor", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
256 intrinsic("shuffle_up", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
257 intrinsic("shuffle_down", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
259 # Quad operations from SPIR-V.
260 intrinsic("quad_broadcast", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
261 intrinsic("quad_swap_horizontal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
262 intrinsic("quad_swap_vertical", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
263 intrinsic("quad_swap_diagonal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
265 intrinsic("reduce", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
, CLUSTER_SIZE
],
266 flags
=[CAN_ELIMINATE
])
267 intrinsic("inclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
268 flags
=[CAN_ELIMINATE
])
269 intrinsic("exclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
270 flags
=[CAN_ELIMINATE
])
272 # AMD shader ballot operations
273 intrinsic("quad_swizzle_amd", src_comp
=[0], dest_comp
=0, indices
=[SWIZZLE_MASK
],
274 flags
=[CAN_ELIMINATE
])
275 intrinsic("masked_swizzle_amd", src_comp
=[0], dest_comp
=0, indices
=[SWIZZLE_MASK
],
276 flags
=[CAN_ELIMINATE
])
277 intrinsic("write_invocation_amd", src_comp
=[0, 0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
278 intrinsic("mbcnt_amd", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
280 # Basic Geometry Shader intrinsics.
282 # emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
283 # index, which is the stream ID to write to.
285 # end_primitive implements GLSL's EndPrimitive() built-in.
286 intrinsic("emit_vertex", indices
=[STREAM_ID
])
287 intrinsic("end_primitive", indices
=[STREAM_ID
])
289 # Geometry Shader intrinsics with a vertex count.
291 # Alternatively, drivers may implement these intrinsics, and use
292 # nir_lower_gs_intrinsics() to convert from the basic intrinsics.
294 # These maintain a count of the number of vertices emitted, as an additional
295 # unsigned integer source.
296 intrinsic("emit_vertex_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
297 intrinsic("end_primitive_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
298 intrinsic("set_vertex_count", src_comp
=[1])
302 # The *_var variants take an atomic_uint nir_variable, while the other,
303 # lowered, variants take a constant buffer index and register offset.
305 def atomic(name
, flags
=[]):
306 intrinsic(name
+ "_deref", src_comp
=[-1], dest_comp
=1, flags
=flags
)
307 intrinsic(name
, src_comp
=[1], dest_comp
=1, indices
=[BASE
], flags
=flags
)
310 intrinsic(name
+ "_deref", src_comp
=[-1, 1], dest_comp
=1)
311 intrinsic(name
, src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
314 intrinsic(name
+ "_deref", src_comp
=[-1, 1, 1], dest_comp
=1)
315 intrinsic(name
, src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
317 atomic("atomic_counter_inc")
318 atomic("atomic_counter_pre_dec")
319 atomic("atomic_counter_post_dec")
320 atomic("atomic_counter_read", flags
=[CAN_ELIMINATE
])
321 atomic2("atomic_counter_add")
322 atomic2("atomic_counter_min")
323 atomic2("atomic_counter_max")
324 atomic2("atomic_counter_and")
325 atomic2("atomic_counter_or")
326 atomic2("atomic_counter_xor")
327 atomic2("atomic_counter_exchange")
328 atomic3("atomic_counter_comp_swap")
330 # Image load, store and atomic intrinsics.
332 # All image intrinsics come in three versions. One which take an image target
333 # passed as a deref chain as the first source, one which takes an index as the
334 # first source, and one which takes a bindless handle as the first source.
335 # In the first version, the image variable contains the memory and layout
336 # qualifiers that influence the semantics of the intrinsic. In the second and
337 # third, the image format and access qualifiers are provided as constant
340 # All image intrinsics take a four-coordinate vector and a sample index as
341 # 2nd and 3rd sources, determining the location within the image that will be
342 # accessed by the intrinsic. Components not applicable to the image target
343 # in use are undefined. Image store takes an additional four-component
344 # argument with the value to be written, and image atomic operations take
345 # either one or two additional scalar arguments with the same meaning as in
346 # the ARB_shader_image_load_store specification.
347 def image(name
, src_comp
=[], **kwargs
):
348 intrinsic("image_deref_" + name
, src_comp
=[1] + src_comp
, **kwargs
)
349 intrinsic("image_" + name
, src_comp
=[1] + src_comp
,
350 indices
=[IMAGE_DIM
, IMAGE_ARRAY
, FORMAT
, ACCESS
], **kwargs
)
351 intrinsic("bindless_image_" + name
, src_comp
=[1] + src_comp
,
352 indices
=[IMAGE_DIM
, IMAGE_ARRAY
, FORMAT
, ACCESS
], **kwargs
)
354 image("load", src_comp
=[4, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
355 image("store", src_comp
=[4, 1, 0])
356 image("atomic_add", src_comp
=[4, 1, 1], dest_comp
=1)
357 image("atomic_min", src_comp
=[4, 1, 1], dest_comp
=1)
358 image("atomic_max", src_comp
=[4, 1, 1], dest_comp
=1)
359 image("atomic_and", src_comp
=[4, 1, 1], dest_comp
=1)
360 image("atomic_or", src_comp
=[4, 1, 1], dest_comp
=1)
361 image("atomic_xor", src_comp
=[4, 1, 1], dest_comp
=1)
362 image("atomic_exchange", src_comp
=[4, 1, 1], dest_comp
=1)
363 image("atomic_comp_swap", src_comp
=[4, 1, 1, 1], dest_comp
=1)
364 image("atomic_fadd", src_comp
=[1, 4, 1, 1], dest_comp
=1)
365 image("size", dest_comp
=0, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
366 image("samples", dest_comp
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
368 # Intel-specific query for loading from the brw_image_param struct passed
369 # into the shader as a uniform. The variable is a deref to the image
370 # variable. The const index specifies which of the six parameters to load.
371 intrinsic("image_deref_load_param_intel", src_comp
=[1], dest_comp
=0,
372 indices
=[BASE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
373 image("load_raw_intel", src_comp
=[1], dest_comp
=0,
374 flags
=[CAN_ELIMINATE
])
375 image("store_raw_intel", src_comp
=[1, 0])
377 # Vulkan descriptor set intrinsics
379 # The Vulkan API uses a different binding model from GL. In the Vulkan
380 # API, all external resources are represented by a tuple:
382 # (descriptor set, binding, array index)
384 # where the array index is the only thing allowed to be indirect. The
385 # vulkan_surface_index intrinsic takes the descriptor set and binding as
386 # its first two indices and the array index as its source. The third
387 # index is a nir_variable_mode in case that's useful to the backend.
389 # The intended usage is that the shader will call vulkan_surface_index to
390 # get an index and then pass that as the buffer index ubo/ssbo calls.
392 # The vulkan_resource_reindex intrinsic takes a resource index in src0
393 # (the result of a vulkan_resource_index or vulkan_resource_reindex) which
394 # corresponds to the tuple (set, binding, index) and computes an index
395 # corresponding to tuple (set, binding, idx + src1).
396 intrinsic("vulkan_resource_index", src_comp
=[1], dest_comp
=0,
397 indices
=[DESC_SET
, BINDING
, DESC_TYPE
],
398 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
399 intrinsic("vulkan_resource_reindex", src_comp
=[0, 1], dest_comp
=0,
400 indices
=[DESC_TYPE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
401 intrinsic("load_vulkan_descriptor", src_comp
=[-1], dest_comp
=0,
402 indices
=[DESC_TYPE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
404 # variable atomic intrinsics
406 # All of these variable atomic memory operations read a value from memory,
407 # compute a new value using one of the operations below, write the new value
408 # to memory, and return the original value read.
410 # All operations take 2 sources except CompSwap that takes 3. These sources
413 # 0: A deref to the memory on which to perform the atomic
414 # 1: The data parameter to the atomic function (i.e. the value to add
415 # in shared_atomic_add, etc).
416 # 2: For CompSwap only: the second data parameter.
417 intrinsic("deref_atomic_add", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
418 intrinsic("deref_atomic_imin", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
419 intrinsic("deref_atomic_umin", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
420 intrinsic("deref_atomic_imax", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
421 intrinsic("deref_atomic_umax", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
422 intrinsic("deref_atomic_and", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
423 intrinsic("deref_atomic_or", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
424 intrinsic("deref_atomic_xor", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
425 intrinsic("deref_atomic_exchange", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
426 intrinsic("deref_atomic_comp_swap", src_comp
=[-1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
427 intrinsic("deref_atomic_fadd", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
428 intrinsic("deref_atomic_fmin", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
429 intrinsic("deref_atomic_fmax", src_comp
=[-1, 1], dest_comp
=1, indices
=[ACCESS
])
430 intrinsic("deref_atomic_fcomp_swap", src_comp
=[-1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
432 # SSBO atomic intrinsics
434 # All of the SSBO atomic memory operations read a value from memory,
435 # compute a new value using one of the operations below, write the new
436 # value to memory, and return the original value read.
438 # All operations take 3 sources except CompSwap that takes 4. These
441 # 0: The SSBO buffer index.
442 # 1: The offset into the SSBO buffer of the variable that the atomic
443 # operation will operate on.
444 # 2: The data parameter to the atomic function (i.e. the value to add
445 # in ssbo_atomic_add, etc).
446 # 3: For CompSwap only: the second data parameter.
447 intrinsic("ssbo_atomic_add", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
448 intrinsic("ssbo_atomic_imin", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
449 intrinsic("ssbo_atomic_umin", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
450 intrinsic("ssbo_atomic_imax", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
451 intrinsic("ssbo_atomic_umax", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
452 intrinsic("ssbo_atomic_and", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
453 intrinsic("ssbo_atomic_or", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
454 intrinsic("ssbo_atomic_xor", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
455 intrinsic("ssbo_atomic_exchange", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
456 intrinsic("ssbo_atomic_comp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
457 intrinsic("ssbo_atomic_fadd", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
458 intrinsic("ssbo_atomic_fmin", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
459 intrinsic("ssbo_atomic_fmax", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
460 intrinsic("ssbo_atomic_fcomp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1, indices
=[ACCESS
])
462 # CS shared variable atomic intrinsics
464 # All of the shared variable atomic memory operations read a value from
465 # memory, compute a new value using one of the operations below, write the
466 # new value to memory, and return the original value read.
468 # All operations take 2 sources except CompSwap that takes 3. These
471 # 0: The offset into the shared variable storage region that the atomic
472 # operation will operate on.
473 # 1: The data parameter to the atomic function (i.e. the value to add
474 # in shared_atomic_add, etc).
475 # 2: For CompSwap only: the second data parameter.
476 intrinsic("shared_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
477 intrinsic("shared_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
478 intrinsic("shared_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
479 intrinsic("shared_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
480 intrinsic("shared_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
481 intrinsic("shared_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
482 intrinsic("shared_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
483 intrinsic("shared_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
484 intrinsic("shared_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
485 intrinsic("shared_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
486 intrinsic("shared_atomic_fadd", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
487 intrinsic("shared_atomic_fmin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
488 intrinsic("shared_atomic_fmax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
489 intrinsic("shared_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
491 # Global atomic intrinsics
493 # All of the shared variable atomic memory operations read a value from
494 # memory, compute a new value using one of the operations below, write the
495 # new value to memory, and return the original value read.
497 # All operations take 2 sources except CompSwap that takes 3. These
500 # 0: The memory address that the atomic operation will operate on.
501 # 1: The data parameter to the atomic function (i.e. the value to add
502 # in shared_atomic_add, etc).
503 # 2: For CompSwap only: the second data parameter.
504 intrinsic("global_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
505 intrinsic("global_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
506 intrinsic("global_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
507 intrinsic("global_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
508 intrinsic("global_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
509 intrinsic("global_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
510 intrinsic("global_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
511 intrinsic("global_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
512 intrinsic("global_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
513 intrinsic("global_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
514 intrinsic("global_atomic_fadd", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
515 intrinsic("global_atomic_fmin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
516 intrinsic("global_atomic_fmax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
517 intrinsic("global_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
519 def system_value(name
, dest_comp
, indices
=[], bit_sizes
=[32]):
520 intrinsic("load_" + name
, [], dest_comp
, indices
,
521 flags
=[CAN_ELIMINATE
, CAN_REORDER
], sysval
=True,
524 system_value("frag_coord", 4)
525 system_value("front_face", 1, bit_sizes
=[1, 32])
526 system_value("vertex_id", 1)
527 system_value("vertex_id_zero_base", 1)
528 system_value("first_vertex", 1)
529 system_value("is_indexed_draw", 1)
530 system_value("base_vertex", 1)
531 system_value("instance_id", 1)
532 system_value("base_instance", 1)
533 system_value("draw_id", 1)
534 system_value("sample_id", 1)
535 # sample_id_no_per_sample is like sample_id but does not imply per-
536 # sample shading. See the lower_helper_invocation option.
537 system_value("sample_id_no_per_sample", 1)
538 system_value("sample_pos", 2)
539 system_value("sample_mask_in", 1)
540 system_value("primitive_id", 1)
541 system_value("invocation_id", 1)
542 system_value("tess_coord", 3)
543 system_value("tess_level_outer", 4)
544 system_value("tess_level_inner", 2)
545 system_value("patch_vertices_in", 1)
546 system_value("local_invocation_id", 3)
547 system_value("local_invocation_index", 1)
548 system_value("work_group_id", 3)
549 system_value("user_clip_plane", 4, indices
=[UCP_ID
])
550 system_value("num_work_groups", 3)
551 system_value("helper_invocation", 1, bit_sizes
=[1, 32])
552 system_value("alpha_ref_float", 1)
553 system_value("layer_id", 1)
554 system_value("view_index", 1)
555 system_value("subgroup_size", 1)
556 system_value("subgroup_invocation", 1)
557 system_value("subgroup_eq_mask", 0, bit_sizes
=[32, 64])
558 system_value("subgroup_ge_mask", 0, bit_sizes
=[32, 64])
559 system_value("subgroup_gt_mask", 0, bit_sizes
=[32, 64])
560 system_value("subgroup_le_mask", 0, bit_sizes
=[32, 64])
561 system_value("subgroup_lt_mask", 0, bit_sizes
=[32, 64])
562 system_value("num_subgroups", 1)
563 system_value("subgroup_id", 1)
564 system_value("local_group_size", 3)
565 system_value("global_invocation_id", 3, bit_sizes
=[32, 64])
566 system_value("global_invocation_index", 1, bit_sizes
=[32, 64])
567 system_value("work_dim", 1)
568 # Driver-specific viewport scale/offset parameters.
570 # VC4 and V3D need to emit a scaled version of the position in the vertex
571 # shaders for binning, and having system values lets us move the math for that
574 # Panfrost needs to implement all coordinate transformation in the
575 # vertex shader; system values allow us to share this routine in NIR.
576 system_value("viewport_x_scale", 1)
577 system_value("viewport_y_scale", 1)
578 system_value("viewport_z_scale", 1)
579 system_value("viewport_z_offset", 1)
580 system_value("viewport_scale", 3)
581 system_value("viewport_offset", 3)
583 # Blend constant color values. Float values are clamped. Vectored versions are
584 # provided as well for driver convenience
586 system_value("blend_const_color_r_float", 1)
587 system_value("blend_const_color_g_float", 1)
588 system_value("blend_const_color_b_float", 1)
589 system_value("blend_const_color_a_float", 1)
590 system_value("blend_const_color_rgba", 4)
591 system_value("blend_const_color_rgba8888_unorm", 1)
592 system_value("blend_const_color_aaaa8888_unorm", 1)
594 # Barycentric coordinate intrinsics.
596 # These set up the barycentric coordinates for a particular interpolation.
597 # The first three are for the simple cases: pixel, centroid, or per-sample
598 # (at gl_SampleID). The next two handle interpolating at a specified
599 # sample location, or interpolating with a vec2 offset,
601 # The interp_mode index should be either the INTERP_MODE_SMOOTH or
602 # INTERP_MODE_NOPERSPECTIVE enum values.
604 # The vec2 value produced by these intrinsics is intended for use as the
605 # barycoord source of a load_interpolated_input intrinsic.
607 def barycentric(name
, src_comp
=[]):
608 intrinsic("load_barycentric_" + name
, src_comp
=src_comp
, dest_comp
=2,
609 indices
=[INTERP_MODE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
613 barycentric("centroid")
614 barycentric("sample")
615 # src[] = { sample_id }.
616 barycentric("at_sample", [1])
617 # src[] = { offset.xy }.
618 barycentric("at_offset", [2])
620 # Load sample position:
622 # Takes a sample # and returns a sample position. Used for lowering
623 # interpolateAtSample() to interpolateAtOffset()
624 intrinsic("load_sample_pos_from_id", src_comp
=[1], dest_comp
=2,
625 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
627 # Loads what I believe is the primitive size, for scaling ij to pixel size:
628 intrinsic("load_size_ir3", dest_comp
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
630 # Load operations pull data from some piece of GPU memory. All load
631 # operations operate in terms of offsets into some piece of theoretical
632 # memory. Loads from externally visible memory (UBO and SSBO) simply take a
633 # byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
634 # take a base+offset pair where the nir_intrinsic_base() gives the location
635 # of the start of the variable being loaded and and the offset source is a
636 # offset into that variable.
638 # Uniform load operations have a nir_intrinsic_range() index that specifies the
639 # range (starting at base) of the data from which we are loading. If
640 # range == 0, then the range is unknown.
642 # Some load operations such as UBO/SSBO load and per_vertex loads take an
643 # additional source to specify which UBO/SSBO/vertex to load from.
645 # The exact address type depends on the lowering pass that generates the
646 # load/store intrinsics. Typically, this is vec4 units for things such as
647 # varying slots and float units for fragment shader inputs. UBO and SSBO
648 # offsets are always in bytes.
650 def load(name
, num_srcs
, indices
=[], flags
=[]):
651 intrinsic("load_" + name
, [1] * num_srcs
, dest_comp
=0, indices
=indices
,
654 # src[] = { offset }.
655 load("uniform", 1, [BASE
, RANGE
, TYPE
], [CAN_ELIMINATE
, CAN_REORDER
])
656 # src[] = { buffer_index, offset }.
657 load("ubo", 2, [ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
658 # src[] = { offset }.
659 load("input", 1, [BASE
, COMPONENT
, TYPE
], [CAN_ELIMINATE
, CAN_REORDER
])
660 # src[] = { vertex, offset }.
661 load("per_vertex_input", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
662 # src[] = { barycoord, offset }.
663 intrinsic("load_interpolated_input", src_comp
=[2, 1], dest_comp
=0,
664 indices
=[BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
666 # src[] = { buffer_index, offset }.
667 load("ssbo", 2, [ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
668 # src[] = { offset }.
669 load("output", 1, [BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
])
670 # src[] = { vertex, offset }.
671 load("per_vertex_output", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
])
672 # src[] = { offset }.
673 load("shared", 1, [BASE
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
674 # src[] = { offset }.
675 load("push_constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
676 # src[] = { offset }.
677 load("constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
678 # src[] = { address }.
679 load("global", 1, [ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
680 # src[] = { address }.
681 load("kernel_input", 1, [BASE
, RANGE
, ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
, CAN_REORDER
])
682 # src[] = { offset }.
683 load("scratch", 1, [ALIGN_MUL
, ALIGN_OFFSET
], [CAN_ELIMINATE
])
685 # Stores work the same way as loads, except now the first source is the value
686 # to store and the second (and possibly third) source specify where to store
687 # the value. SSBO and shared memory stores also have a
688 # nir_intrinsic_write_mask()
690 def store(name
, num_srcs
, indices
=[], flags
=[]):
691 intrinsic("store_" + name
, [0] + ([1] * (num_srcs
- 1)), indices
=indices
, flags
=flags
)
693 # src[] = { value, offset }.
694 store("output", 2, [BASE
, WRMASK
, COMPONENT
, TYPE
])
695 # src[] = { value, vertex, offset }.
696 store("per_vertex_output", 3, [BASE
, WRMASK
, COMPONENT
])
697 # src[] = { value, block_index, offset }
698 store("ssbo", 3, [WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
699 # src[] = { value, offset }.
700 store("shared", 2, [BASE
, WRMASK
, ALIGN_MUL
, ALIGN_OFFSET
])
701 # src[] = { value, address }.
702 store("global", 2, [WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
703 # src[] = { value, offset }.
704 store("scratch", 2, [ALIGN_MUL
, ALIGN_OFFSET
, WRMASK
])
706 # IR3-specific version of most SSBO intrinsics. The only different
707 # compare to the originals is that they add an extra source to hold
708 # the dword-offset, which is needed by the backend code apart from
709 # the byte-offset already provided by NIR in one of the sources.
711 # NIR lowering pass 'ir3_nir_lower_io_offset' will replace the
712 # original SSBO intrinsics by these, placing the computed
713 # dword-offset always in the last source.
715 # The float versions are not handled because those are not supported
717 intrinsic("store_ssbo_ir3", src_comp
=[0, 1, 1, 1],
718 indices
=[WRMASK
, ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
])
719 intrinsic("load_ssbo_ir3", src_comp
=[1, 1, 1], dest_comp
=0,
720 indices
=[ACCESS
, ALIGN_MUL
, ALIGN_OFFSET
], flags
=[CAN_ELIMINATE
])
721 intrinsic("ssbo_atomic_add_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
722 intrinsic("ssbo_atomic_imin_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
723 intrinsic("ssbo_atomic_umin_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
724 intrinsic("ssbo_atomic_imax_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
725 intrinsic("ssbo_atomic_umax_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
726 intrinsic("ssbo_atomic_and_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
727 intrinsic("ssbo_atomic_or_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
728 intrinsic("ssbo_atomic_xor_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
729 intrinsic("ssbo_atomic_exchange_ir3", src_comp
=[1, 1, 1, 1], dest_comp
=1)
730 intrinsic("ssbo_atomic_comp_swap_ir3", src_comp
=[1, 1, 1, 1, 1], dest_comp
=1)