2 # Copyright (C) 2018 Red Hat
3 # Copyright (C) 2014 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 # This file defines all the available intrinsics in one place.
27 # The Intrinsic class corresponds one-to-one with nir_intrinsic_info
30 class Intrinsic(object):
31 """Class that represents all the information about an intrinsic opcode.
32 NOTE: this must be kept in sync with nir_intrinsic_info.
34 def __init__(self
, name
, src_components
, dest_components
,
35 indices
, flags
, sysval
):
38 - name: the intrinsic name
39 - src_components: list of the number of components per src, 0 means
40 vectorized instruction with number of components given in the
41 num_components field in nir_intrinsic_instr.
42 - dest_components: number of destination components, -1 means no
43 dest, 0 means number of components given in num_components field
44 in nir_intrinsic_instr.
45 - indices: list of constant indicies
46 - flags: list of semantic flags
47 - sysval: is this a system-value intrinsic
49 assert isinstance(name
, str)
50 assert isinstance(src_components
, list)
52 assert isinstance(src_components
[0], int)
53 assert isinstance(dest_components
, int)
54 assert isinstance(indices
, list)
56 assert isinstance(indices
[0], str)
57 assert isinstance(flags
, list)
59 assert isinstance(flags
[0], str)
60 assert isinstance(sysval
, bool)
63 self
.num_srcs
= len(src_components
)
64 self
.src_components
= src_components
65 self
.has_dest
= (dest_components
>= 0)
66 self
.dest_components
= dest_components
67 self
.num_indices
= len(indices
)
68 self
.indices
= indices
76 # A constant 'base' value that is added to an offset src:
77 BASE
= "NIR_INTRINSIC_BASE"
78 # For store instructions, a writemask:
79 WRMASK
= "NIR_INTRINSIC_WRMASK"
80 # The stream-id for GS emit_vertex/end_primitive intrinsics:
81 STREAM_ID
= "NIR_INTRINSIC_STREAM_ID"
82 # The clip-plane id for load_user_clip_plane intrinsics:
83 UCP_ID
= "NIR_INTRINSIC_UCP_ID"
84 # The amount of data, starting from BASE, that this instruction
85 # may access. This is used to provide bounds if the offset is
87 RANGE
= "NIR_INTRINSIC_RANGE"
88 # The vulkan descriptor set binding for vulkan_resource_index
90 DESC_SET
= "NIR_INTRINSIC_DESC_SET"
91 # The vulkan descriptor set binding for vulkan_resource_index
93 BINDING
= "NIR_INTRINSIC_BINDING"
95 COMPONENT
= "NIR_INTRINSIC_COMPONENT"
96 # Interpolation mode (only meaningful for FS inputs)
97 INTERP_MODE
= "NIR_INTRINSIC_INTERP_MODE"
98 # A binary nir_op to use when performing a reduction or scan operation
99 REDUCTION_OP
= "NIR_INTRINSIC_REDUCTION_OP"
100 # Cluster size for reduction operations
101 CLUSTER_SIZE
= "NIR_INTRINSIC_CLUSTER_SIZE"
102 # Parameter index for a load_param intrinsic
103 PARAM_IDX
= "NIR_INTRINSIC_PARAM_IDX"
104 # Image dimensionality for image intrinsics
105 IMAGE_DIM
= "NIR_INTRINSIC_IMAGE_DIM"
106 # Non-zero if we are accessing an array image
107 IMAGE_ARRAY
= "NIR_INTRINSIC_IMAGE_ARRAY"
108 # Access qualifiers for image intrinsics
109 ACCESS
= "NIR_INTRINSIC_ACCESS"
110 # Image format for image intrinsics
111 FORMAT
= "NIR_INTRINSIC_FORMAT"
117 CAN_ELIMINATE
= "NIR_INTRINSIC_CAN_ELIMINATE"
118 CAN_REORDER
= "NIR_INTRINSIC_CAN_REORDER"
122 def intrinsic(name
, src_comp
=[], dest_comp
=-1, indices
=[],
123 flags
=[], sysval
=False):
124 assert name
not in INTR_OPCODES
125 INTR_OPCODES
[name
] = Intrinsic(name
, src_comp
, dest_comp
,
126 indices
, flags
, sysval
)
128 intrinsic("nop", flags
=[CAN_ELIMINATE
])
130 intrinsic("load_param", dest_comp
=0, indices
=[PARAM_IDX
], flags
=[CAN_ELIMINATE
])
132 intrinsic("load_deref", dest_comp
=0, src_comp
=[1], flags
=[CAN_ELIMINATE
])
133 intrinsic("store_deref", src_comp
=[1, 0], indices
=[WRMASK
])
134 intrinsic("copy_deref", src_comp
=[1, 1])
136 # Interpolation of input. The interp_deref_at* intrinsics are similar to the
137 # load_var intrinsic acting on a shader input except that they interpolate the
138 # input differently. The at_sample and at_offset intrinsics take an
139 # additional source that is an integer sample id or a vec2 position offset
142 intrinsic("interp_deref_at_centroid", dest_comp
=0, src_comp
=[1],
143 flags
=[ CAN_ELIMINATE
, CAN_REORDER
])
144 intrinsic("interp_deref_at_sample", src_comp
=[1, 1], dest_comp
=0,
145 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
146 intrinsic("interp_deref_at_offset", src_comp
=[1, 2], dest_comp
=0,
147 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
149 # Ask the driver for the size of a given buffer. It takes the buffer index
151 intrinsic("get_buffer_size", src_comp
=[1], dest_comp
=1,
152 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
154 # a barrier is an intrinsic with no inputs/outputs but which can't be moved
155 # around/optimized in general
162 # Memory barrier with semantics analogous to the memoryBarrier() GLSL
164 barrier("memory_barrier")
166 # Shader clock intrinsic with semantics analogous to the clock2x32ARB()
168 # The latter can be used as code motion barrier, which is currently not
170 intrinsic("shader_clock", dest_comp
=2, flags
=[CAN_ELIMINATE
])
172 # Shader ballot intrinsics with semantics analogous to the
175 # readInvocationARB()
176 # readFirstInvocationARB()
178 # GLSL functions from ARB_shader_ballot.
179 intrinsic("ballot", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
180 intrinsic("read_invocation", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
181 intrinsic("read_first_invocation", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
183 # Additional SPIR-V ballot intrinsics
185 # These correspond to the SPIR-V opcodes
187 # OpGroupUniformElect
188 # OpSubgroupFirstInvocationKHR
189 intrinsic("elect", dest_comp
=1, flags
=[CAN_ELIMINATE
])
190 intrinsic("first_invocation", dest_comp
=1, flags
=[CAN_ELIMINATE
])
192 # Memory barrier with semantics analogous to the compute shader
193 # groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
194 # memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
195 barrier("group_memory_barrier")
196 barrier("memory_barrier_atomic_counter")
197 barrier("memory_barrier_buffer")
198 barrier("memory_barrier_image")
199 barrier("memory_barrier_shared")
200 barrier("begin_invocation_interlock")
201 barrier("end_invocation_interlock")
202 barrier("begin_fragment_shader_ordering")
204 # A conditional discard, with a single boolean source.
205 intrinsic("discard_if", src_comp
=[1])
207 # ARB_shader_group_vote intrinsics
208 intrinsic("vote_any", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
209 intrinsic("vote_all", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
210 intrinsic("vote_feq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
211 intrinsic("vote_ieq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
213 # Ballot ALU operations from SPIR-V.
215 # These operations work like their ALU counterparts except that the operate
216 # on a uvec4 which is treated as a 128bit integer. Also, they are, in
217 # general, free to ignore any bits which are above the subgroup size.
218 intrinsic("ballot_bitfield_extract", src_comp
=[4, 1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
219 intrinsic("ballot_bit_count_reduce", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
220 intrinsic("ballot_bit_count_inclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
221 intrinsic("ballot_bit_count_exclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
222 intrinsic("ballot_find_lsb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
223 intrinsic("ballot_find_msb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
225 # Shuffle operations from SPIR-V.
226 intrinsic("shuffle", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
227 intrinsic("shuffle_xor", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
228 intrinsic("shuffle_up", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
229 intrinsic("shuffle_down", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
231 # Quad operations from SPIR-V.
232 intrinsic("quad_broadcast", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
233 intrinsic("quad_swap_horizontal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
234 intrinsic("quad_swap_vertical", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
235 intrinsic("quad_swap_diagonal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
237 intrinsic("reduce", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
, CLUSTER_SIZE
],
238 flags
=[CAN_ELIMINATE
])
239 intrinsic("inclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
240 flags
=[CAN_ELIMINATE
])
241 intrinsic("exclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
242 flags
=[CAN_ELIMINATE
])
244 # Basic Geometry Shader intrinsics.
246 # emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
247 # index, which is the stream ID to write to.
249 # end_primitive implements GLSL's EndPrimitive() built-in.
250 intrinsic("emit_vertex", indices
=[STREAM_ID
])
251 intrinsic("end_primitive", indices
=[STREAM_ID
])
253 # Geometry Shader intrinsics with a vertex count.
255 # Alternatively, drivers may implement these intrinsics, and use
256 # nir_lower_gs_intrinsics() to convert from the basic intrinsics.
258 # These maintain a count of the number of vertices emitted, as an additional
259 # unsigned integer source.
260 intrinsic("emit_vertex_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
261 intrinsic("end_primitive_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
262 intrinsic("set_vertex_count", src_comp
=[1])
266 # The *_var variants take an atomic_uint nir_variable, while the other,
267 # lowered, variants take a constant buffer index and register offset.
269 def atomic(name
, flags
=[]):
270 intrinsic(name
+ "_deref", src_comp
=[1], dest_comp
=1, flags
=flags
)
271 intrinsic(name
, src_comp
=[1], dest_comp
=1, indices
=[BASE
], flags
=flags
)
274 intrinsic(name
+ "_deref", src_comp
=[1, 1], dest_comp
=1)
275 intrinsic(name
, src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
278 intrinsic(name
+ "_deref", src_comp
=[1, 1, 1], dest_comp
=1)
279 intrinsic(name
, src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
281 atomic("atomic_counter_inc")
282 atomic("atomic_counter_pre_dec")
283 atomic("atomic_counter_post_dec")
284 atomic("atomic_counter_read", flags
=[CAN_ELIMINATE
])
285 atomic2("atomic_counter_add")
286 atomic2("atomic_counter_min")
287 atomic2("atomic_counter_max")
288 atomic2("atomic_counter_and")
289 atomic2("atomic_counter_or")
290 atomic2("atomic_counter_xor")
291 atomic2("atomic_counter_exchange")
292 atomic3("atomic_counter_comp_swap")
294 # Image load, store and atomic intrinsics.
296 # All image intrinsics come in two versions. One which take an image target
297 # passed as a deref chain as the first source and one which takes an index or
298 # handle as the first source. In the first version, the image variable
299 # contains the memory and layout qualifiers that influence the semantics of
300 # the intrinsic. In the second, the image format and access qualifiers are
301 # provided as constant indices.
303 # All image intrinsics take a four-coordinate vector and a sample index as
304 # 2nd and 3rd sources, determining the location within the image that will be
305 # accessed by the intrinsic. Components not applicable to the image target
306 # in use are undefined. Image store takes an additional four-component
307 # argument with the value to be written, and image atomic operations take
308 # either one or two additional scalar arguments with the same meaning as in
309 # the ARB_shader_image_load_store specification.
310 def image(name
, src_comp
=[], **kwargs
):
311 intrinsic("image_deref_" + name
, src_comp
=[1] + src_comp
, **kwargs
)
312 intrinsic("image_" + name
, src_comp
=[1] + src_comp
,
313 indices
=[IMAGE_DIM
, IMAGE_ARRAY
, FORMAT
, ACCESS
], **kwargs
)
315 image("load", src_comp
=[4, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
316 image("store", src_comp
=[4, 1, 0])
317 image("atomic_add", src_comp
=[4, 1, 1], dest_comp
=1)
318 image("atomic_min", src_comp
=[4, 1, 1], dest_comp
=1)
319 image("atomic_max", src_comp
=[4, 1, 1], dest_comp
=1)
320 image("atomic_and", src_comp
=[4, 1, 1], dest_comp
=1)
321 image("atomic_or", src_comp
=[4, 1, 1], dest_comp
=1)
322 image("atomic_xor", src_comp
=[4, 1, 1], dest_comp
=1)
323 image("atomic_exchange", src_comp
=[4, 1, 1], dest_comp
=1)
324 image("atomic_comp_swap", src_comp
=[4, 1, 1, 1], dest_comp
=1)
325 image("atomic_fadd", src_comp
=[1, 4, 1, 1], dest_comp
=1)
326 image("size", dest_comp
=0, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
327 image("samples", dest_comp
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
329 # Intel-specific query for loading from the brw_image_param struct passed
330 # into the shader as a uniform. The variable is a deref to the image
331 # variable. The const index specifies which of the six parameters to load.
332 intrinsic("image_deref_load_param_intel", src_comp
=[1], dest_comp
=0,
333 indices
=[BASE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
334 image("load_raw_intel", src_comp
=[1], dest_comp
=0,
335 flags
=[CAN_ELIMINATE
])
336 image("store_raw_intel", src_comp
=[1, 0])
338 # Vulkan descriptor set intrinsics
340 # The Vulkan API uses a different binding model from GL. In the Vulkan
341 # API, all external resources are represented by a tuple:
343 # (descriptor set, binding, array index)
345 # where the array index is the only thing allowed to be indirect. The
346 # vulkan_surface_index intrinsic takes the descriptor set and binding as
347 # its first two indices and the array index as its source. The third
348 # index is a nir_variable_mode in case that's useful to the backend.
350 # The intended usage is that the shader will call vulkan_surface_index to
351 # get an index and then pass that as the buffer index ubo/ssbo calls.
353 # The vulkan_resource_reindex intrinsic takes a resource index in src0
354 # (the result of a vulkan_resource_index or vulkan_resource_reindex) which
355 # corresponds to the tuple (set, binding, index) and computes an index
356 # corresponding to tuple (set, binding, idx + src1).
357 intrinsic("vulkan_resource_index", src_comp
=[1], dest_comp
=1,
358 indices
=[DESC_SET
, BINDING
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
359 intrinsic("vulkan_resource_reindex", src_comp
=[1, 1], dest_comp
=1,
360 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
362 # variable atomic intrinsics
364 # All of these variable atomic memory operations read a value from memory,
365 # compute a new value using one of the operations below, write the new value
366 # to memory, and return the original value read.
368 # All operations take 2 sources except CompSwap that takes 3. These sources
371 # 0: A deref to the memory on which to perform the atomic
372 # 1: The data parameter to the atomic function (i.e. the value to add
373 # in shared_atomic_add, etc).
374 # 2: For CompSwap only: the second data parameter.
375 intrinsic("deref_atomic_add", src_comp
=[1, 1], dest_comp
=1)
376 intrinsic("deref_atomic_imin", src_comp
=[1, 1], dest_comp
=1)
377 intrinsic("deref_atomic_umin", src_comp
=[1, 1], dest_comp
=1)
378 intrinsic("deref_atomic_imax", src_comp
=[1, 1], dest_comp
=1)
379 intrinsic("deref_atomic_umax", src_comp
=[1, 1], dest_comp
=1)
380 intrinsic("deref_atomic_and", src_comp
=[1, 1], dest_comp
=1)
381 intrinsic("deref_atomic_or", src_comp
=[1, 1], dest_comp
=1)
382 intrinsic("deref_atomic_xor", src_comp
=[1, 1], dest_comp
=1)
383 intrinsic("deref_atomic_exchange", src_comp
=[1, 1], dest_comp
=1)
384 intrinsic("deref_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1)
385 intrinsic("deref_atomic_fadd", src_comp
=[1, 1], dest_comp
=1)
386 intrinsic("deref_atomic_fmin", src_comp
=[1, 1], dest_comp
=1)
387 intrinsic("deref_atomic_fmax", src_comp
=[1, 1], dest_comp
=1)
388 intrinsic("deref_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1)
390 # SSBO atomic intrinsics
392 # All of the SSBO atomic memory operations read a value from memory,
393 # compute a new value using one of the operations below, write the new
394 # value to memory, and return the original value read.
396 # All operations take 3 sources except CompSwap that takes 4. These
399 # 0: The SSBO buffer index.
400 # 1: The offset into the SSBO buffer of the variable that the atomic
401 # operation will operate on.
402 # 2: The data parameter to the atomic function (i.e. the value to add
403 # in ssbo_atomic_add, etc).
404 # 3: For CompSwap only: the second data parameter.
405 intrinsic("ssbo_atomic_add", src_comp
=[1, 1, 1], dest_comp
=1)
406 intrinsic("ssbo_atomic_imin", src_comp
=[1, 1, 1], dest_comp
=1)
407 intrinsic("ssbo_atomic_umin", src_comp
=[1, 1, 1], dest_comp
=1)
408 intrinsic("ssbo_atomic_imax", src_comp
=[1, 1, 1], dest_comp
=1)
409 intrinsic("ssbo_atomic_umax", src_comp
=[1, 1, 1], dest_comp
=1)
410 intrinsic("ssbo_atomic_and", src_comp
=[1, 1, 1], dest_comp
=1)
411 intrinsic("ssbo_atomic_or", src_comp
=[1, 1, 1], dest_comp
=1)
412 intrinsic("ssbo_atomic_xor", src_comp
=[1, 1, 1], dest_comp
=1)
413 intrinsic("ssbo_atomic_exchange", src_comp
=[1, 1, 1], dest_comp
=1)
414 intrinsic("ssbo_atomic_comp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
415 intrinsic("ssbo_atomic_fadd", src_comp
=[1, 1, 1], dest_comp
=1)
416 intrinsic("ssbo_atomic_fmin", src_comp
=[1, 1, 1], dest_comp
=1)
417 intrinsic("ssbo_atomic_fmax", src_comp
=[1, 1, 1], dest_comp
=1)
418 intrinsic("ssbo_atomic_fcomp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
420 # CS shared variable atomic intrinsics
422 # All of the shared variable atomic memory operations read a value from
423 # memory, compute a new value using one of the operations below, write the
424 # new value to memory, and return the original value read.
426 # All operations take 2 sources except CompSwap that takes 3. These
429 # 0: The offset into the shared variable storage region that the atomic
430 # operation will operate on.
431 # 1: The data parameter to the atomic function (i.e. the value to add
432 # in shared_atomic_add, etc).
433 # 2: For CompSwap only: the second data parameter.
434 intrinsic("shared_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
435 intrinsic("shared_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
436 intrinsic("shared_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
437 intrinsic("shared_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
438 intrinsic("shared_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
439 intrinsic("shared_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
440 intrinsic("shared_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
441 intrinsic("shared_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
442 intrinsic("shared_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
443 intrinsic("shared_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
444 intrinsic("shared_atomic_fadd", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
445 intrinsic("shared_atomic_fmin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
446 intrinsic("shared_atomic_fmax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
447 intrinsic("shared_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
449 def system_value(name
, dest_comp
, indices
=[]):
450 intrinsic("load_" + name
, [], dest_comp
, indices
,
451 flags
=[CAN_ELIMINATE
, CAN_REORDER
], sysval
=True)
453 system_value("frag_coord", 4)
454 system_value("front_face", 1)
455 system_value("vertex_id", 1)
456 system_value("vertex_id_zero_base", 1)
457 system_value("first_vertex", 1)
458 system_value("is_indexed_draw", 1)
459 system_value("base_vertex", 1)
460 system_value("instance_id", 1)
461 system_value("base_instance", 1)
462 system_value("draw_id", 1)
463 system_value("sample_id", 1)
464 # sample_id_no_per_sample is like sample_id but does not imply per-
465 # sample shading. See the lower_helper_invocation option.
466 system_value("sample_id_no_per_sample", 1)
467 system_value("sample_pos", 2)
468 system_value("sample_mask_in", 1)
469 system_value("primitive_id", 1)
470 system_value("invocation_id", 1)
471 system_value("tess_coord", 3)
472 system_value("tess_level_outer", 4)
473 system_value("tess_level_inner", 2)
474 system_value("patch_vertices_in", 1)
475 system_value("local_invocation_id", 3)
476 system_value("local_invocation_index", 1)
477 system_value("work_group_id", 3)
478 system_value("user_clip_plane", 4, indices
=[UCP_ID
])
479 system_value("num_work_groups", 3)
480 system_value("helper_invocation", 1)
481 system_value("alpha_ref_float", 1)
482 system_value("layer_id", 1)
483 system_value("view_index", 1)
484 system_value("subgroup_size", 1)
485 system_value("subgroup_invocation", 1)
486 system_value("subgroup_eq_mask", 0)
487 system_value("subgroup_ge_mask", 0)
488 system_value("subgroup_gt_mask", 0)
489 system_value("subgroup_le_mask", 0)
490 system_value("subgroup_lt_mask", 0)
491 system_value("num_subgroups", 1)
492 system_value("subgroup_id", 1)
493 system_value("local_group_size", 3)
494 system_value("global_invocation_id", 3)
495 system_value("work_dim", 1)
497 # Blend constant color values. Float values are clamped.#
498 system_value("blend_const_color_r_float", 1)
499 system_value("blend_const_color_g_float", 1)
500 system_value("blend_const_color_b_float", 1)
501 system_value("blend_const_color_a_float", 1)
502 system_value("blend_const_color_rgba8888_unorm", 1)
503 system_value("blend_const_color_aaaa8888_unorm", 1)
505 # Barycentric coordinate intrinsics.
507 # These set up the barycentric coordinates for a particular interpolation.
508 # The first three are for the simple cases: pixel, centroid, or per-sample
509 # (at gl_SampleID). The next two handle interpolating at a specified
510 # sample location, or interpolating with a vec2 offset,
512 # The interp_mode index should be either the INTERP_MODE_SMOOTH or
513 # INTERP_MODE_NOPERSPECTIVE enum values.
515 # The vec2 value produced by these intrinsics is intended for use as the
516 # barycoord source of a load_interpolated_input intrinsic.
518 def barycentric(name
, src_comp
=[]):
519 intrinsic("load_barycentric_" + name
, src_comp
=src_comp
, dest_comp
=2,
520 indices
=[INTERP_MODE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
522 # no sources. const_index[] = { interp_mode }
524 barycentric("centroid")
525 barycentric("sample")
526 # src[] = { sample_id }. const_index[] = { interp_mode }
527 barycentric("at_sample", [1])
528 # src[] = { offset.xy }. const_index[] = { interp_mode }
529 barycentric("at_offset", [2])
531 # Load operations pull data from some piece of GPU memory. All load
532 # operations operate in terms of offsets into some piece of theoretical
533 # memory. Loads from externally visible memory (UBO and SSBO) simply take a
534 # byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
535 # take a base+offset pair where the base (const_index[0]) gives the location
536 # of the start of the variable being loaded and and the offset source is a
537 # offset into that variable.
539 # Uniform load operations have a second "range" index that specifies the
540 # range (starting at base) of the data from which we are loading. If
541 # const_index[1] == 0, then the range is unknown.
543 # Some load operations such as UBO/SSBO load and per_vertex loads take an
544 # additional source to specify which UBO/SSBO/vertex to load from.
546 # The exact address type depends on the lowering pass that generates the
547 # load/store intrinsics. Typically, this is vec4 units for things such as
548 # varying slots and float units for fragment shader inputs. UBO and SSBO
549 # offsets are always in bytes.
551 def load(name
, num_srcs
, indices
=[], flags
=[]):
552 intrinsic("load_" + name
, [1] * num_srcs
, dest_comp
=0, indices
=indices
,
555 # src[] = { offset }. const_index[] = { base, range }
556 load("uniform", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
557 # src[] = { buffer_index, offset }. No const_index
558 load("ubo", 2, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
559 # src[] = { offset }. const_index[] = { base, component }
560 load("input", 1, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
561 # src[] = { vertex, offset }. const_index[] = { base, component }
562 load("per_vertex_input", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
563 # src[] = { barycoord, offset }. const_index[] = { base, component }
564 intrinsic("load_interpolated_input", src_comp
=[2, 1], dest_comp
=0,
565 indices
=[BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
567 # src[] = { buffer_index, offset }. No const_index
568 load("ssbo", 2, flags
=[CAN_ELIMINATE
], indices
=[ACCESS
])
569 # src[] = { offset }. const_index[] = { base, component }
570 load("output", 1, [BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
])
571 # src[] = { vertex, offset }. const_index[] = { base }
572 load("per_vertex_output", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
])
573 # src[] = { offset }. const_index[] = { base }
574 load("shared", 1, [BASE
], [CAN_ELIMINATE
])
575 # src[] = { offset }. const_index[] = { base, range }
576 load("push_constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
577 # src[] = { offset }. const_index[] = { base, range }
578 load("constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
580 # Stores work the same way as loads, except now the first source is the value
581 # to store and the second (and possibly third) source specify where to store
582 # the value. SSBO and shared memory stores also have a write mask as
585 def store(name
, num_srcs
, indices
=[], flags
=[]):
586 intrinsic("store_" + name
, [0] + ([1] * (num_srcs
- 1)), indices
=indices
, flags
=flags
)
588 # src[] = { value, offset }. const_index[] = { base, write_mask, component }
589 store("output", 2, [BASE
, WRMASK
, COMPONENT
])
590 # src[] = { value, vertex, offset }.
591 # const_index[] = { base, write_mask, component }
592 store("per_vertex_output", 3, [BASE
, WRMASK
, COMPONENT
])
593 # src[] = { value, block_index, offset }. const_index[] = { write_mask }
594 store("ssbo", 3, [WRMASK
, ACCESS
])
595 # src[] = { value, offset }. const_index[] = { base, write_mask }
596 store("shared", 2, [BASE
, WRMASK
])