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
, num_variables
,
35 indices
, flags
, sysval
):
38 - name: the intrinsic name
39 - src_components: list of the number of components per src, 0 means
40 vectorized instruction with number of components given in the
41 num_components field in nir_intrinsic_instr.
42 - dest_components: number of destination components, -1 means no
43 dest, 0 means number of components given in num_components field
44 in nir_intrinsic_instr.
45 - num_variables: the number of variables
46 - indices: list of constant indicies
47 - flags: list of semantic flags
48 - sysval: is this a system-value intrinsic
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(num_variables
, int)
56 assert isinstance(indices
, list)
58 assert isinstance(indices
[0], str)
59 assert isinstance(flags
, list)
61 assert isinstance(flags
[0], str)
62 assert isinstance(sysval
, bool)
65 self
.num_srcs
= len(src_components
)
66 self
.src_components
= src_components
67 self
.has_dest
= (dest_components
>= 0)
68 self
.dest_components
= dest_components
69 self
.num_variables
= num_variables
70 self
.num_indices
= len(indices
)
71 self
.indices
= indices
79 # A constant 'base' value that is added to an offset src:
80 BASE
= "NIR_INTRINSIC_BASE"
81 # For store instructions, a writemask:
82 WRMASK
= "NIR_INTRINSIC_WRMASK"
83 # The stream-id for GS emit_vertex/end_primitive intrinsics:
84 STREAM_ID
= "NIR_INTRINSIC_STREAM_ID"
85 # The clip-plane id for load_user_clip_plane intrinsics:
86 UCP_ID
= "NIR_INTRINSIC_UCP_ID"
87 # The amount of data, starting from BASE, that this instruction
88 # may access. This is used to provide bounds if the offset is
90 RANGE
= "NIR_INTRINSIC_RANGE"
91 # The vulkan descriptor set binding for vulkan_resource_index
93 DESC_SET
= "NIR_INTRINSIC_DESC_SET"
94 # The vulkan descriptor set binding for vulkan_resource_index
96 BINDING
= "NIR_INTRINSIC_BINDING"
98 COMPONENT
= "NIR_INTRINSIC_COMPONENT"
99 # Interpolation mode (only meaningful for FS inputs)
100 INTERP_MODE
= "NIR_INTRINSIC_INTERP_MODE"
101 # A binary nir_op to use when performing a reduction or scan operation
102 REDUCTION_OP
= "NIR_INTRINSIC_REDUCTION_OP"
103 # Cluster size for reduction operations
104 CLUSTER_SIZE
= "NIR_INTRINSIC_CLUSTER_SIZE"
105 # Parameter index for a load_param intrinsic
106 PARAM_IDX
= "NIR_INTRINSIC_PARAM_IDX"
112 CAN_ELIMINATE
= "NIR_INTRINSIC_CAN_ELIMINATE"
113 CAN_REORDER
= "NIR_INTRINSIC_CAN_REORDER"
117 def intrinsic(name
, src_comp
=[], dest_comp
=-1, num_vars
=0, indices
=[],
118 flags
=[], sysval
=False):
119 assert name
not in INTR_OPCODES
120 INTR_OPCODES
[name
] = Intrinsic(name
, src_comp
, dest_comp
, num_vars
,
121 indices
, flags
, sysval
)
123 intrinsic("nop", flags
=[CAN_ELIMINATE
])
125 intrinsic("load_param", dest_comp
=0, indices
=[PARAM_IDX
], flags
=[CAN_ELIMINATE
])
127 intrinsic("load_var", dest_comp
=0, num_vars
=1, flags
=[CAN_ELIMINATE
])
128 intrinsic("store_var", src_comp
=[0], num_vars
=1, indices
=[WRMASK
])
129 intrinsic("copy_var", num_vars
=2)
131 intrinsic("load_deref", dest_comp
=0, src_comp
=[1], flags
=[CAN_ELIMINATE
])
132 intrinsic("store_deref", src_comp
=[1, 0], indices
=[WRMASK
])
133 intrinsic("copy_deref", src_comp
=[1, 1])
135 # Interpolation of input. The interp_var_at* intrinsics are similar to the
136 # load_var intrinsic acting on a shader input except that they interpolate
137 # the input differently. The at_sample and at_offset intrinsics take an
138 # additional source that is an integer sample id or a vec2 position offset
141 intrinsic("interp_var_at_centroid", dest_comp
=0, num_vars
=1,
142 flags
=[ CAN_ELIMINATE
, CAN_REORDER
])
143 intrinsic("interp_var_at_sample", src_comp
=[1], dest_comp
=0, num_vars
=1,
144 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
145 intrinsic("interp_var_at_offset", src_comp
=[2], dest_comp
=0, num_vars
=1,
146 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
148 # Interpolation of input. The interp_deref_at* intrinsics are similar to the
149 # load_var intrinsic acting on a shader input except that they interpolate the
150 # input differently. The at_sample and at_offset intrinsics take an
151 # additional source that is an integer sample id or a vec2 position offset
154 intrinsic("interp_deref_at_centroid", dest_comp
=0, src_comp
=[1],
155 flags
=[ CAN_ELIMINATE
, CAN_REORDER
])
156 intrinsic("interp_deref_at_sample", src_comp
=[1, 1], dest_comp
=0,
157 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
158 intrinsic("interp_deref_at_offset", src_comp
=[1, 2], dest_comp
=0,
159 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
161 # Ask the driver for the size of a given buffer. It takes the buffer index
163 intrinsic("get_buffer_size", src_comp
=[1], dest_comp
=1,
164 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
166 # a barrier is an intrinsic with no inputs/outputs but which can't be moved
167 # around/optimized in general
174 # Memory barrier with semantics analogous to the memoryBarrier() GLSL
176 barrier("memory_barrier")
178 # Shader clock intrinsic with semantics analogous to the clock2x32ARB()
180 # The latter can be used as code motion barrier, which is currently not
182 intrinsic("shader_clock", dest_comp
=2, flags
=[CAN_ELIMINATE
])
184 # Shader ballot intrinsics with semantics analogous to the
187 # readInvocationARB()
188 # readFirstInvocationARB()
190 # GLSL functions from ARB_shader_ballot.
191 intrinsic("ballot", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
192 intrinsic("read_invocation", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
193 intrinsic("read_first_invocation", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
195 # Additional SPIR-V ballot intrinsics
197 # These correspond to the SPIR-V opcodes
199 # OpGroupUniformElect
200 # OpSubgroupFirstInvocationKHR
201 intrinsic("elect", dest_comp
=1, flags
=[CAN_ELIMINATE
])
202 intrinsic("first_invocation", dest_comp
=1, flags
=[CAN_ELIMINATE
])
204 # Memory barrier with semantics analogous to the compute shader
205 # groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
206 # memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
207 barrier("group_memory_barrier")
208 barrier("memory_barrier_atomic_counter")
209 barrier("memory_barrier_buffer")
210 barrier("memory_barrier_image")
211 barrier("memory_barrier_shared")
212 barrier("begin_invocation_interlock")
213 barrier("end_invocation_interlock")
215 # A conditional discard, with a single boolean source.
216 intrinsic("discard_if", src_comp
=[1])
218 # ARB_shader_group_vote intrinsics
219 intrinsic("vote_any", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
220 intrinsic("vote_all", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
221 intrinsic("vote_feq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
222 intrinsic("vote_ieq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
224 # Ballot ALU operations from SPIR-V.
226 # These operations work like their ALU counterparts except that the operate
227 # on a uvec4 which is treated as a 128bit integer. Also, they are, in
228 # general, free to ignore any bits which are above the subgroup size.
229 intrinsic("ballot_bitfield_extract", src_comp
=[4, 1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
230 intrinsic("ballot_bit_count_reduce", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
231 intrinsic("ballot_bit_count_inclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
232 intrinsic("ballot_bit_count_exclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
233 intrinsic("ballot_find_lsb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
234 intrinsic("ballot_find_msb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
236 # Shuffle operations from SPIR-V.
237 intrinsic("shuffle", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
238 intrinsic("shuffle_xor", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
239 intrinsic("shuffle_up", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
240 intrinsic("shuffle_down", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
242 # Quad operations from SPIR-V.
243 intrinsic("quad_broadcast", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
244 intrinsic("quad_swap_horizontal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
245 intrinsic("quad_swap_vertical", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
246 intrinsic("quad_swap_diagonal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
248 intrinsic("reduce", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
, CLUSTER_SIZE
],
249 flags
=[CAN_ELIMINATE
])
250 intrinsic("inclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
251 flags
=[CAN_ELIMINATE
])
252 intrinsic("exclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
253 flags
=[CAN_ELIMINATE
])
255 # Basic Geometry Shader intrinsics.
257 # emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
258 # index, which is the stream ID to write to.
260 # end_primitive implements GLSL's EndPrimitive() built-in.
261 intrinsic("emit_vertex", indices
=[STREAM_ID
])
262 intrinsic("end_primitive", indices
=[STREAM_ID
])
264 # Geometry Shader intrinsics with a vertex count.
266 # Alternatively, drivers may implement these intrinsics, and use
267 # nir_lower_gs_intrinsics() to convert from the basic intrinsics.
269 # These maintain a count of the number of vertices emitted, as an additional
270 # unsigned integer source.
271 intrinsic("emit_vertex_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
272 intrinsic("end_primitive_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
273 intrinsic("set_vertex_count", src_comp
=[1])
277 # The *_var variants take an atomic_uint nir_variable, while the other,
278 # lowered, variants take a constant buffer index and register offset.
280 def atomic(name
, flags
=[]):
281 intrinsic(name
+ "_var", dest_comp
=1, num_vars
=1, flags
=flags
)
282 intrinsic(name
+ "_deref", src_comp
=[1], dest_comp
=1, flags
=flags
)
283 intrinsic(name
, src_comp
=[1], dest_comp
=1, indices
=[BASE
], flags
=flags
)
286 intrinsic(name
+ "_var", src_comp
=[1], dest_comp
=1, num_vars
=1)
287 intrinsic(name
+ "_deref", src_comp
=[1, 1], dest_comp
=1)
288 intrinsic(name
, src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
291 intrinsic(name
+ "_var", src_comp
=[1, 1], dest_comp
=1, num_vars
=1)
292 intrinsic(name
+ "_deref", src_comp
=[1, 1, 1], dest_comp
=1)
293 intrinsic(name
, src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
295 atomic("atomic_counter_inc")
296 atomic("atomic_counter_dec")
297 atomic("atomic_counter_read", flags
=[CAN_ELIMINATE
])
298 atomic2("atomic_counter_add")
299 atomic2("atomic_counter_min")
300 atomic2("atomic_counter_max")
301 atomic2("atomic_counter_and")
302 atomic2("atomic_counter_or")
303 atomic2("atomic_counter_xor")
304 atomic2("atomic_counter_exchange")
305 atomic3("atomic_counter_comp_swap")
307 # Image load, store and atomic intrinsics.
309 # All image intrinsics take an image target passed as a nir_variable. Image
310 # variables contain a number of memory and layout qualifiers that influence
311 # the semantics of the intrinsic.
313 # All image intrinsics take a four-coordinate vector and a sample index as
314 # first two sources, determining the location within the image that will be
315 # accessed by the intrinsic. Components not applicable to the image target
316 # in use are undefined. Image store takes an additional four-component
317 # argument with the value to be written, and image atomic operations take
318 # either one or two additional scalar arguments with the same meaning as in
319 # the ARB_shader_image_load_store specification.
320 intrinsic("image_var_load", src_comp
=[4, 1], dest_comp
=4, num_vars
=1,
321 flags
=[CAN_ELIMINATE
])
322 intrinsic("image_var_store", src_comp
=[4, 1, 4], num_vars
=1)
323 intrinsic("image_var_atomic_add", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
324 intrinsic("image_var_atomic_min", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
325 intrinsic("image_var_atomic_max", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
326 intrinsic("image_var_atomic_and", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
327 intrinsic("image_var_atomic_or", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
328 intrinsic("image_var_atomic_xor", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
329 intrinsic("image_var_atomic_exchange", src_comp
=[4, 1, 1], dest_comp
=1, num_vars
=1)
330 intrinsic("image_var_atomic_comp_swap", src_comp
=[4, 1, 1, 1], dest_comp
=1, num_vars
=1)
331 intrinsic("image_var_size", dest_comp
=0, num_vars
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
332 intrinsic("image_var_samples", dest_comp
=1, num_vars
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
334 # Image load, store and atomic intrinsics.
336 # All image intrinsics take an image target passed as a nir_variable. The
337 # variable is passed in using a chain of nir_deref_instr with as the first
338 # source of the image intrinsic. Image variables contain a number of memory
339 # and layout qualifiers that influence the semantics of the intrinsic.
341 # All image intrinsics take a four-coordinate vector and a sample index as
342 # first two sources, determining the location within the image that will be
343 # accessed by the intrinsic. Components not applicable to the image target
344 # in use are undefined. Image store takes an additional four-component
345 # argument with the value to be written, and image atomic operations take
346 # either one or two additional scalar arguments with the same meaning as in
347 # the ARB_shader_image_load_store specification.
348 intrinsic("image_deref_load", src_comp
=[1, 4, 1], dest_comp
=4,
349 flags
=[CAN_ELIMINATE
])
350 intrinsic("image_deref_store", src_comp
=[1, 4, 1, 4])
351 intrinsic("image_deref_atomic_add", src_comp
=[1, 4, 1, 1], dest_comp
=1)
352 intrinsic("image_deref_atomic_min", src_comp
=[1, 4, 1, 1], dest_comp
=1)
353 intrinsic("image_deref_atomic_max", src_comp
=[1, 4, 1, 1], dest_comp
=1)
354 intrinsic("image_deref_atomic_and", src_comp
=[1, 4, 1, 1], dest_comp
=1)
355 intrinsic("image_deref_atomic_or", src_comp
=[1, 4, 1, 1], dest_comp
=1)
356 intrinsic("image_deref_atomic_xor", src_comp
=[1, 4, 1, 1], dest_comp
=1)
357 intrinsic("image_deref_atomic_exchange", src_comp
=[1, 4, 1, 1], dest_comp
=1)
358 intrinsic("image_deref_atomic_comp_swap", src_comp
=[1, 4, 1, 1, 1], dest_comp
=1)
359 intrinsic("image_deref_size", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
360 intrinsic("image_deref_samples", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
362 # Vulkan descriptor set intrinsics
364 # The Vulkan API uses a different binding model from GL. In the Vulkan
365 # API, all external resources are represented by a tuple:
367 # (descriptor set, binding, array index)
369 # where the array index is the only thing allowed to be indirect. The
370 # vulkan_surface_index intrinsic takes the descriptor set and binding as
371 # its first two indices and the array index as its source. The third
372 # index is a nir_variable_mode in case that's useful to the backend.
374 # The intended usage is that the shader will call vulkan_surface_index to
375 # get an index and then pass that as the buffer index ubo/ssbo calls.
377 # The vulkan_resource_reindex intrinsic takes a resource index in src0
378 # (the result of a vulkan_resource_index or vulkan_resource_reindex) which
379 # corresponds to the tuple (set, binding, index) and computes an index
380 # corresponding to tuple (set, binding, idx + src1).
381 intrinsic("vulkan_resource_index", src_comp
=[1], dest_comp
=1,
382 indices
=[DESC_SET
, BINDING
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
383 intrinsic("vulkan_resource_reindex", src_comp
=[1, 1], dest_comp
=1,
384 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
386 # variable atomic intrinsics
388 # All of these variable atomic memory operations read a value from memory,
389 # compute a new value using one of the operations below, write the new value
390 # to memory, and return the original value read.
392 # All operations take 1 source except CompSwap that takes 2. These sources
395 # 0: The data parameter to the atomic function (i.e. the value to add
396 # in shared_atomic_add, etc).
397 # 1: For CompSwap only: the second data parameter.
399 # All operations take 1 variable deref.
400 intrinsic("var_atomic_add", src_comp
=[1], dest_comp
=1, num_vars
=1)
401 intrinsic("var_atomic_imin", src_comp
=[1], dest_comp
=1, num_vars
=1)
402 intrinsic("var_atomic_umin", src_comp
=[1], dest_comp
=1, num_vars
=1)
403 intrinsic("var_atomic_imax", src_comp
=[1], dest_comp
=1, num_vars
=1)
404 intrinsic("var_atomic_umax", src_comp
=[1], dest_comp
=1, num_vars
=1)
405 intrinsic("var_atomic_and", src_comp
=[1], dest_comp
=1, num_vars
=1)
406 intrinsic("var_atomic_or", src_comp
=[1], dest_comp
=1, num_vars
=1)
407 intrinsic("var_atomic_xor", src_comp
=[1], dest_comp
=1, num_vars
=1)
408 intrinsic("var_atomic_exchange", src_comp
=[1], dest_comp
=1, num_vars
=1)
409 intrinsic("var_atomic_comp_swap", src_comp
=[1, 1], dest_comp
=1, num_vars
=1)
411 # variable atomic intrinsics
413 # All of these variable atomic memory operations read a value from memory,
414 # compute a new value using one of the operations below, write the new value
415 # to memory, and return the original value read.
417 # All operations take 2 sources except CompSwap that takes 3. These sources
420 # 0: A deref to the memory on which to perform the atomic
421 # 1: The data parameter to the atomic function (i.e. the value to add
422 # in shared_atomic_add, etc).
423 # 2: For CompSwap only: the second data parameter.
424 intrinsic("deref_atomic_add", src_comp
=[1, 1], dest_comp
=1)
425 intrinsic("deref_atomic_imin", src_comp
=[1, 1], dest_comp
=1)
426 intrinsic("deref_atomic_umin", src_comp
=[1, 1], dest_comp
=1)
427 intrinsic("deref_atomic_imax", src_comp
=[1, 1], dest_comp
=1)
428 intrinsic("deref_atomic_umax", src_comp
=[1, 1], dest_comp
=1)
429 intrinsic("deref_atomic_and", src_comp
=[1, 1], dest_comp
=1)
430 intrinsic("deref_atomic_or", src_comp
=[1, 1], dest_comp
=1)
431 intrinsic("deref_atomic_xor", src_comp
=[1, 1], dest_comp
=1)
432 intrinsic("deref_atomic_exchange", src_comp
=[1, 1], dest_comp
=1)
433 intrinsic("deref_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1)
435 # SSBO atomic intrinsics
437 # All of the SSBO atomic memory operations read a value from memory,
438 # compute a new value using one of the operations below, write the new
439 # value to memory, and return the original value read.
441 # All operations take 3 sources except CompSwap that takes 4. These
444 # 0: The SSBO buffer index.
445 # 1: The offset into the SSBO buffer of the variable that the atomic
446 # operation will operate on.
447 # 2: The data parameter to the atomic function (i.e. the value to add
448 # in ssbo_atomic_add, etc).
449 # 3: For CompSwap only: the second data parameter.
450 intrinsic("ssbo_atomic_add", src_comp
=[1, 1, 1], dest_comp
=1)
451 intrinsic("ssbo_atomic_imin", src_comp
=[1, 1, 1], dest_comp
=1)
452 intrinsic("ssbo_atomic_umin", src_comp
=[1, 1, 1], dest_comp
=1)
453 intrinsic("ssbo_atomic_imax", src_comp
=[1, 1, 1], dest_comp
=1)
454 intrinsic("ssbo_atomic_umax", src_comp
=[1, 1, 1], dest_comp
=1)
455 intrinsic("ssbo_atomic_and", src_comp
=[1, 1, 1], dest_comp
=1)
456 intrinsic("ssbo_atomic_or", src_comp
=[1, 1, 1], dest_comp
=1)
457 intrinsic("ssbo_atomic_xor", src_comp
=[1, 1, 1], dest_comp
=1)
458 intrinsic("ssbo_atomic_exchange", src_comp
=[1, 1, 1], dest_comp
=1)
459 intrinsic("ssbo_atomic_comp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
461 # CS shared variable 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 offset into the shared variable storage region that the atomic
471 # operation will operate on.
472 # 1: The data parameter to the atomic function (i.e. the value to add
473 # in shared_atomic_add, etc).
474 # 2: For CompSwap only: the second data parameter.
475 intrinsic("shared_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
476 intrinsic("shared_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
477 intrinsic("shared_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
478 intrinsic("shared_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
479 intrinsic("shared_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
480 intrinsic("shared_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
481 intrinsic("shared_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
482 intrinsic("shared_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
483 intrinsic("shared_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
484 intrinsic("shared_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
486 def system_value(name
, dest_comp
, indices
=[]):
487 intrinsic("load_" + name
, [], dest_comp
, 0, indices
,
488 flags
=[CAN_ELIMINATE
, CAN_REORDER
], sysval
=True)
490 system_value("frag_coord", 4)
491 system_value("front_face", 1)
492 system_value("vertex_id", 1)
493 system_value("vertex_id_zero_base", 1)
494 system_value("first_vertex", 1)
495 system_value("is_indexed_draw", 1)
496 system_value("base_vertex", 1)
497 system_value("instance_id", 1)
498 system_value("base_instance", 1)
499 system_value("draw_id", 1)
500 system_value("sample_id", 1)
501 system_value("sample_pos", 2)
502 system_value("sample_mask_in", 1)
503 system_value("primitive_id", 1)
504 system_value("invocation_id", 1)
505 system_value("tess_coord", 3)
506 system_value("tess_level_outer", 4)
507 system_value("tess_level_inner", 2)
508 system_value("patch_vertices_in", 1)
509 system_value("local_invocation_id", 3)
510 system_value("local_invocation_index", 1)
511 system_value("work_group_id", 3)
512 system_value("user_clip_plane", 4, indices
=[UCP_ID
])
513 system_value("num_work_groups", 3)
514 system_value("helper_invocation", 1)
515 system_value("alpha_ref_float", 1)
516 system_value("layer_id", 1)
517 system_value("view_index", 1)
518 system_value("subgroup_size", 1)
519 system_value("subgroup_invocation", 1)
520 system_value("subgroup_eq_mask", 0)
521 system_value("subgroup_ge_mask", 0)
522 system_value("subgroup_gt_mask", 0)
523 system_value("subgroup_le_mask", 0)
524 system_value("subgroup_lt_mask", 0)
525 system_value("num_subgroups", 1)
526 system_value("subgroup_id", 1)
527 system_value("local_group_size", 3)
528 system_value("global_invocation_id", 3)
530 # Blend constant color values. Float values are clamped.#
531 system_value("blend_const_color_r_float", 1)
532 system_value("blend_const_color_g_float", 1)
533 system_value("blend_const_color_b_float", 1)
534 system_value("blend_const_color_a_float", 1)
535 system_value("blend_const_color_rgba8888_unorm", 1)
536 system_value("blend_const_color_aaaa8888_unorm", 1)
538 # Barycentric coordinate intrinsics.
540 # These set up the barycentric coordinates for a particular interpolation.
541 # The first three are for the simple cases: pixel, centroid, or per-sample
542 # (at gl_SampleID). The next two handle interpolating at a specified
543 # sample location, or interpolating with a vec2 offset,
545 # The interp_mode index should be either the INTERP_MODE_SMOOTH or
546 # INTERP_MODE_NOPERSPECTIVE enum values.
548 # The vec2 value produced by these intrinsics is intended for use as the
549 # barycoord source of a load_interpolated_input intrinsic.
551 def barycentric(name
, src_comp
=[]):
552 intrinsic("load_barycentric_" + name
, src_comp
=src_comp
, dest_comp
=2,
553 indices
=[INTERP_MODE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
555 # no sources. const_index[] = { interp_mode }
557 barycentric("centroid")
558 barycentric("sample")
559 # src[] = { sample_id }. const_index[] = { interp_mode }
560 barycentric("at_sample", [1])
561 # src[] = { offset.xy }. const_index[] = { interp_mode }
562 barycentric("at_offset", [2])
564 # Load operations pull data from some piece of GPU memory. All load
565 # operations operate in terms of offsets into some piece of theoretical
566 # memory. Loads from externally visible memory (UBO and SSBO) simply take a
567 # byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
568 # take a base+offset pair where the base (const_index[0]) gives the location
569 # of the start of the variable being loaded and and the offset source is a
570 # offset into that variable.
572 # Uniform load operations have a second "range" index that specifies the
573 # range (starting at base) of the data from which we are loading. If
574 # const_index[1] == 0, then the range is unknown.
576 # Some load operations such as UBO/SSBO load and per_vertex loads take an
577 # additional source to specify which UBO/SSBO/vertex to load from.
579 # The exact address type depends on the lowering pass that generates the
580 # load/store intrinsics. Typically, this is vec4 units for things such as
581 # varying slots and float units for fragment shader inputs. UBO and SSBO
582 # offsets are always in bytes.
584 def load(name
, num_srcs
, indices
=[], flags
=[]):
585 intrinsic("load_" + name
, [1] * num_srcs
, dest_comp
=0, indices
=indices
,
588 # src[] = { offset }. const_index[] = { base, range }
589 load("uniform", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
590 # src[] = { buffer_index, offset }. No const_index
591 load("ubo", 2, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
592 # src[] = { offset }. const_index[] = { base, component }
593 load("input", 1, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
594 # src[] = { vertex, offset }. const_index[] = { base, component }
595 load("per_vertex_input", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
596 # src[] = { barycoord, offset }. const_index[] = { base, component }
597 intrinsic("load_interpolated_input", src_comp
=[2, 1], dest_comp
=0,
598 indices
=[BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
600 # src[] = { buffer_index, offset }. No const_index
601 load("ssbo", 2, flags
=[CAN_ELIMINATE
])
602 # src[] = { offset }. const_index[] = { base, component }
603 load("output", 1, [BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
])
604 # src[] = { vertex, offset }. const_index[] = { base }
605 load("per_vertex_output", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
])
606 # src[] = { offset }. const_index[] = { base }
607 load("shared", 1, [BASE
], [CAN_ELIMINATE
])
608 # src[] = { offset }. const_index[] = { base, range }
609 load("push_constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
611 # Stores work the same way as loads, except now the first source is the value
612 # to store and the second (and possibly third) source specify where to store
613 # the value. SSBO and shared memory stores also have a write mask as
616 def store(name
, num_srcs
, indices
=[], flags
=[]):
617 intrinsic("store_" + name
, [0] + ([1] * (num_srcs
- 1)), indices
=indices
, flags
=flags
)
619 # src[] = { value, offset }. const_index[] = { base, write_mask, component }
620 store("output", 2, [BASE
, WRMASK
, COMPONENT
])
621 # src[] = { value, vertex, offset }.
622 # const_index[] = { base, write_mask, component }
623 store("per_vertex_output", 3, [BASE
, WRMASK
, COMPONENT
])
624 # src[] = { value, block_index, offset }. const_index[] = { write_mask }
625 store("ssbo", 3, [WRMASK
])
626 # src[] = { value, offset }. const_index[] = { base, write_mask }
627 store("shared", 2, [BASE
, WRMASK
])