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"
109 CAN_ELIMINATE
= "NIR_INTRINSIC_CAN_ELIMINATE"
110 CAN_REORDER
= "NIR_INTRINSIC_CAN_REORDER"
114 def intrinsic(name
, src_comp
=[], dest_comp
=-1, indices
=[],
115 flags
=[], sysval
=False):
116 assert name
not in INTR_OPCODES
117 INTR_OPCODES
[name
] = Intrinsic(name
, src_comp
, dest_comp
,
118 indices
, flags
, sysval
)
120 intrinsic("nop", flags
=[CAN_ELIMINATE
])
122 intrinsic("load_param", dest_comp
=0, indices
=[PARAM_IDX
], flags
=[CAN_ELIMINATE
])
124 intrinsic("load_deref", dest_comp
=0, src_comp
=[1], flags
=[CAN_ELIMINATE
])
125 intrinsic("store_deref", src_comp
=[1, 0], indices
=[WRMASK
])
126 intrinsic("copy_deref", src_comp
=[1, 1])
128 # Interpolation of input. The interp_deref_at* intrinsics are similar to the
129 # load_var intrinsic acting on a shader input except that they interpolate the
130 # input differently. The at_sample and at_offset intrinsics take an
131 # additional source that is an integer sample id or a vec2 position offset
134 intrinsic("interp_deref_at_centroid", dest_comp
=0, src_comp
=[1],
135 flags
=[ CAN_ELIMINATE
, CAN_REORDER
])
136 intrinsic("interp_deref_at_sample", src_comp
=[1, 1], dest_comp
=0,
137 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
138 intrinsic("interp_deref_at_offset", src_comp
=[1, 2], dest_comp
=0,
139 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
141 # Ask the driver for the size of a given buffer. It takes the buffer index
143 intrinsic("get_buffer_size", src_comp
=[1], dest_comp
=1,
144 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
146 # a barrier is an intrinsic with no inputs/outputs but which can't be moved
147 # around/optimized in general
154 # Memory barrier with semantics analogous to the memoryBarrier() GLSL
156 barrier("memory_barrier")
158 # Shader clock intrinsic with semantics analogous to the clock2x32ARB()
160 # The latter can be used as code motion barrier, which is currently not
162 intrinsic("shader_clock", dest_comp
=2, flags
=[CAN_ELIMINATE
])
164 # Shader ballot intrinsics with semantics analogous to the
167 # readInvocationARB()
168 # readFirstInvocationARB()
170 # GLSL functions from ARB_shader_ballot.
171 intrinsic("ballot", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
172 intrinsic("read_invocation", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
173 intrinsic("read_first_invocation", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
175 # Additional SPIR-V ballot intrinsics
177 # These correspond to the SPIR-V opcodes
179 # OpGroupUniformElect
180 # OpSubgroupFirstInvocationKHR
181 intrinsic("elect", dest_comp
=1, flags
=[CAN_ELIMINATE
])
182 intrinsic("first_invocation", dest_comp
=1, flags
=[CAN_ELIMINATE
])
184 # Memory barrier with semantics analogous to the compute shader
185 # groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
186 # memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
187 barrier("group_memory_barrier")
188 barrier("memory_barrier_atomic_counter")
189 barrier("memory_barrier_buffer")
190 barrier("memory_barrier_image")
191 barrier("memory_barrier_shared")
192 barrier("begin_invocation_interlock")
193 barrier("end_invocation_interlock")
194 barrier("begin_fragment_shader_ordering")
196 # A conditional discard, with a single boolean source.
197 intrinsic("discard_if", src_comp
=[1])
199 # ARB_shader_group_vote intrinsics
200 intrinsic("vote_any", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
201 intrinsic("vote_all", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
202 intrinsic("vote_feq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
203 intrinsic("vote_ieq", src_comp
=[0], dest_comp
=1, flags
=[CAN_ELIMINATE
])
205 # Ballot ALU operations from SPIR-V.
207 # These operations work like their ALU counterparts except that the operate
208 # on a uvec4 which is treated as a 128bit integer. Also, they are, in
209 # general, free to ignore any bits which are above the subgroup size.
210 intrinsic("ballot_bitfield_extract", src_comp
=[4, 1], dest_comp
=1, flags
=[CAN_ELIMINATE
])
211 intrinsic("ballot_bit_count_reduce", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
212 intrinsic("ballot_bit_count_inclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
213 intrinsic("ballot_bit_count_exclusive", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
214 intrinsic("ballot_find_lsb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
215 intrinsic("ballot_find_msb", src_comp
=[4], dest_comp
=1, flags
=[CAN_ELIMINATE
])
217 # Shuffle operations from SPIR-V.
218 intrinsic("shuffle", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
219 intrinsic("shuffle_xor", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
220 intrinsic("shuffle_up", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
221 intrinsic("shuffle_down", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
223 # Quad operations from SPIR-V.
224 intrinsic("quad_broadcast", src_comp
=[0, 1], dest_comp
=0, flags
=[CAN_ELIMINATE
])
225 intrinsic("quad_swap_horizontal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
226 intrinsic("quad_swap_vertical", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
227 intrinsic("quad_swap_diagonal", src_comp
=[0], dest_comp
=0, flags
=[CAN_ELIMINATE
])
229 intrinsic("reduce", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
, CLUSTER_SIZE
],
230 flags
=[CAN_ELIMINATE
])
231 intrinsic("inclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
232 flags
=[CAN_ELIMINATE
])
233 intrinsic("exclusive_scan", src_comp
=[0], dest_comp
=0, indices
=[REDUCTION_OP
],
234 flags
=[CAN_ELIMINATE
])
236 # Basic Geometry Shader intrinsics.
238 # emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single
239 # index, which is the stream ID to write to.
241 # end_primitive implements GLSL's EndPrimitive() built-in.
242 intrinsic("emit_vertex", indices
=[STREAM_ID
])
243 intrinsic("end_primitive", indices
=[STREAM_ID
])
245 # Geometry Shader intrinsics with a vertex count.
247 # Alternatively, drivers may implement these intrinsics, and use
248 # nir_lower_gs_intrinsics() to convert from the basic intrinsics.
250 # These maintain a count of the number of vertices emitted, as an additional
251 # unsigned integer source.
252 intrinsic("emit_vertex_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
253 intrinsic("end_primitive_with_counter", src_comp
=[1], indices
=[STREAM_ID
])
254 intrinsic("set_vertex_count", src_comp
=[1])
258 # The *_var variants take an atomic_uint nir_variable, while the other,
259 # lowered, variants take a constant buffer index and register offset.
261 def atomic(name
, flags
=[]):
262 intrinsic(name
+ "_deref", src_comp
=[1], dest_comp
=1, flags
=flags
)
263 intrinsic(name
, src_comp
=[1], dest_comp
=1, indices
=[BASE
], flags
=flags
)
266 intrinsic(name
+ "_deref", src_comp
=[1, 1], dest_comp
=1)
267 intrinsic(name
, src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
270 intrinsic(name
+ "_deref", src_comp
=[1, 1, 1], dest_comp
=1)
271 intrinsic(name
, src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
273 atomic("atomic_counter_inc")
274 atomic("atomic_counter_pre_dec")
275 atomic("atomic_counter_post_dec")
276 atomic("atomic_counter_read", flags
=[CAN_ELIMINATE
])
277 atomic2("atomic_counter_add")
278 atomic2("atomic_counter_min")
279 atomic2("atomic_counter_max")
280 atomic2("atomic_counter_and")
281 atomic2("atomic_counter_or")
282 atomic2("atomic_counter_xor")
283 atomic2("atomic_counter_exchange")
284 atomic3("atomic_counter_comp_swap")
286 # Image load, store and atomic intrinsics.
288 # All image intrinsics take an image target passed as a nir_variable. The
289 # variable is passed in using a chain of nir_deref_instr with as the first
290 # source of the image intrinsic. Image variables contain a number of memory
291 # and layout qualifiers that influence the semantics of the intrinsic.
293 # All image intrinsics take a four-coordinate vector and a sample index as
294 # 2nd and 3rd sources, determining the location within the image that will be
295 # accessed by the intrinsic. Components not applicable to the image target
296 # in use are undefined. Image store takes an additional four-component
297 # argument with the value to be written, and image atomic operations take
298 # either one or two additional scalar arguments with the same meaning as in
299 # the ARB_shader_image_load_store specification.
300 intrinsic("image_deref_load", src_comp
=[1, 4, 1], dest_comp
=0,
301 flags
=[CAN_ELIMINATE
])
302 intrinsic("image_deref_store", src_comp
=[1, 4, 1, 0])
303 intrinsic("image_deref_atomic_add", src_comp
=[1, 4, 1, 1], dest_comp
=1)
304 intrinsic("image_deref_atomic_min", src_comp
=[1, 4, 1, 1], dest_comp
=1)
305 intrinsic("image_deref_atomic_max", src_comp
=[1, 4, 1, 1], dest_comp
=1)
306 intrinsic("image_deref_atomic_and", src_comp
=[1, 4, 1, 1], dest_comp
=1)
307 intrinsic("image_deref_atomic_or", src_comp
=[1, 4, 1, 1], dest_comp
=1)
308 intrinsic("image_deref_atomic_xor", src_comp
=[1, 4, 1, 1], dest_comp
=1)
309 intrinsic("image_deref_atomic_exchange", src_comp
=[1, 4, 1, 1], dest_comp
=1)
310 intrinsic("image_deref_atomic_comp_swap", src_comp
=[1, 4, 1, 1, 1], dest_comp
=1)
311 intrinsic("image_deref_atomic_fadd", src_comp
=[1, 4, 1, 1], dest_comp
=1)
312 intrinsic("image_deref_size", src_comp
=[1], dest_comp
=0, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
313 intrinsic("image_deref_samples", src_comp
=[1], dest_comp
=1, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
315 # Intel-specific query for loading from the brw_image_param struct passed
316 # into the shader as a uniform. The variable is a deref to the image
317 # variable. The const index specifies which of the six parameters to load.
318 intrinsic("image_deref_load_param_intel", src_comp
=[1], dest_comp
=0,
319 indices
=[BASE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
320 intrinsic("image_deref_load_raw_intel", src_comp
=[1, 1], dest_comp
=0,
321 flags
=[CAN_ELIMINATE
])
322 intrinsic("image_deref_store_raw_intel", src_comp
=[1, 1, 0])
324 # Vulkan descriptor set intrinsics
326 # The Vulkan API uses a different binding model from GL. In the Vulkan
327 # API, all external resources are represented by a tuple:
329 # (descriptor set, binding, array index)
331 # where the array index is the only thing allowed to be indirect. The
332 # vulkan_surface_index intrinsic takes the descriptor set and binding as
333 # its first two indices and the array index as its source. The third
334 # index is a nir_variable_mode in case that's useful to the backend.
336 # The intended usage is that the shader will call vulkan_surface_index to
337 # get an index and then pass that as the buffer index ubo/ssbo calls.
339 # The vulkan_resource_reindex intrinsic takes a resource index in src0
340 # (the result of a vulkan_resource_index or vulkan_resource_reindex) which
341 # corresponds to the tuple (set, binding, index) and computes an index
342 # corresponding to tuple (set, binding, idx + src1).
343 intrinsic("vulkan_resource_index", src_comp
=[1], dest_comp
=1,
344 indices
=[DESC_SET
, BINDING
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
345 intrinsic("vulkan_resource_reindex", src_comp
=[1, 1], dest_comp
=1,
346 flags
=[CAN_ELIMINATE
, CAN_REORDER
])
348 # variable atomic intrinsics
350 # All of these variable atomic memory operations read a value from memory,
351 # compute a new value using one of the operations below, write the new value
352 # to memory, and return the original value read.
354 # All operations take 2 sources except CompSwap that takes 3. These sources
357 # 0: A deref to the memory on which to perform the atomic
358 # 1: The data parameter to the atomic function (i.e. the value to add
359 # in shared_atomic_add, etc).
360 # 2: For CompSwap only: the second data parameter.
361 intrinsic("deref_atomic_add", src_comp
=[1, 1], dest_comp
=1)
362 intrinsic("deref_atomic_imin", src_comp
=[1, 1], dest_comp
=1)
363 intrinsic("deref_atomic_umin", src_comp
=[1, 1], dest_comp
=1)
364 intrinsic("deref_atomic_imax", src_comp
=[1, 1], dest_comp
=1)
365 intrinsic("deref_atomic_umax", src_comp
=[1, 1], dest_comp
=1)
366 intrinsic("deref_atomic_and", src_comp
=[1, 1], dest_comp
=1)
367 intrinsic("deref_atomic_or", src_comp
=[1, 1], dest_comp
=1)
368 intrinsic("deref_atomic_xor", src_comp
=[1, 1], dest_comp
=1)
369 intrinsic("deref_atomic_exchange", src_comp
=[1, 1], dest_comp
=1)
370 intrinsic("deref_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1)
371 intrinsic("deref_atomic_fadd", src_comp
=[1, 1], dest_comp
=1)
372 intrinsic("deref_atomic_fmin", src_comp
=[1, 1], dest_comp
=1)
373 intrinsic("deref_atomic_fmax", src_comp
=[1, 1], dest_comp
=1)
374 intrinsic("deref_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1)
376 # SSBO atomic intrinsics
378 # All of the SSBO atomic memory operations read a value from memory,
379 # compute a new value using one of the operations below, write the new
380 # value to memory, and return the original value read.
382 # All operations take 3 sources except CompSwap that takes 4. These
385 # 0: The SSBO buffer index.
386 # 1: The offset into the SSBO buffer of the variable that the atomic
387 # operation will operate on.
388 # 2: The data parameter to the atomic function (i.e. the value to add
389 # in ssbo_atomic_add, etc).
390 # 3: For CompSwap only: the second data parameter.
391 intrinsic("ssbo_atomic_add", src_comp
=[1, 1, 1], dest_comp
=1)
392 intrinsic("ssbo_atomic_imin", src_comp
=[1, 1, 1], dest_comp
=1)
393 intrinsic("ssbo_atomic_umin", src_comp
=[1, 1, 1], dest_comp
=1)
394 intrinsic("ssbo_atomic_imax", src_comp
=[1, 1, 1], dest_comp
=1)
395 intrinsic("ssbo_atomic_umax", src_comp
=[1, 1, 1], dest_comp
=1)
396 intrinsic("ssbo_atomic_and", src_comp
=[1, 1, 1], dest_comp
=1)
397 intrinsic("ssbo_atomic_or", src_comp
=[1, 1, 1], dest_comp
=1)
398 intrinsic("ssbo_atomic_xor", src_comp
=[1, 1, 1], dest_comp
=1)
399 intrinsic("ssbo_atomic_exchange", src_comp
=[1, 1, 1], dest_comp
=1)
400 intrinsic("ssbo_atomic_comp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
401 intrinsic("ssbo_atomic_fadd", src_comp
=[1, 1, 1], dest_comp
=1)
402 intrinsic("ssbo_atomic_fmin", src_comp
=[1, 1, 1], dest_comp
=1)
403 intrinsic("ssbo_atomic_fmax", src_comp
=[1, 1, 1], dest_comp
=1)
404 intrinsic("ssbo_atomic_fcomp_swap", src_comp
=[1, 1, 1, 1], dest_comp
=1)
406 # CS shared variable atomic intrinsics
408 # All of the shared variable atomic memory operations read a value from
409 # memory, compute a new value using one of the operations below, write the
410 # new value to memory, and return the original value read.
412 # All operations take 2 sources except CompSwap that takes 3. These
415 # 0: The offset into the shared variable storage region that the atomic
416 # operation will operate on.
417 # 1: The data parameter to the atomic function (i.e. the value to add
418 # in shared_atomic_add, etc).
419 # 2: For CompSwap only: the second data parameter.
420 intrinsic("shared_atomic_add", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
421 intrinsic("shared_atomic_imin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
422 intrinsic("shared_atomic_umin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
423 intrinsic("shared_atomic_imax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
424 intrinsic("shared_atomic_umax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
425 intrinsic("shared_atomic_and", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
426 intrinsic("shared_atomic_or", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
427 intrinsic("shared_atomic_xor", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
428 intrinsic("shared_atomic_exchange", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
429 intrinsic("shared_atomic_comp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
430 intrinsic("shared_atomic_fadd", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
431 intrinsic("shared_atomic_fmin", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
432 intrinsic("shared_atomic_fmax", src_comp
=[1, 1], dest_comp
=1, indices
=[BASE
])
433 intrinsic("shared_atomic_fcomp_swap", src_comp
=[1, 1, 1], dest_comp
=1, indices
=[BASE
])
435 def system_value(name
, dest_comp
, indices
=[]):
436 intrinsic("load_" + name
, [], dest_comp
, indices
,
437 flags
=[CAN_ELIMINATE
, CAN_REORDER
], sysval
=True)
439 system_value("frag_coord", 4)
440 system_value("front_face", 1)
441 system_value("vertex_id", 1)
442 system_value("vertex_id_zero_base", 1)
443 system_value("first_vertex", 1)
444 system_value("is_indexed_draw", 1)
445 system_value("base_vertex", 1)
446 system_value("instance_id", 1)
447 system_value("base_instance", 1)
448 system_value("draw_id", 1)
449 system_value("sample_id", 1)
450 # sample_id_no_per_sample is like sample_id but does not imply per-
451 # sample shading. See the lower_helper_invocation option.
452 system_value("sample_id_no_per_sample", 1)
453 system_value("sample_pos", 2)
454 system_value("sample_mask_in", 1)
455 system_value("primitive_id", 1)
456 system_value("invocation_id", 1)
457 system_value("tess_coord", 3)
458 system_value("tess_level_outer", 4)
459 system_value("tess_level_inner", 2)
460 system_value("patch_vertices_in", 1)
461 system_value("local_invocation_id", 3)
462 system_value("local_invocation_index", 1)
463 system_value("work_group_id", 3)
464 system_value("user_clip_plane", 4, indices
=[UCP_ID
])
465 system_value("num_work_groups", 3)
466 system_value("helper_invocation", 1)
467 system_value("alpha_ref_float", 1)
468 system_value("layer_id", 1)
469 system_value("view_index", 1)
470 system_value("subgroup_size", 1)
471 system_value("subgroup_invocation", 1)
472 system_value("subgroup_eq_mask", 0)
473 system_value("subgroup_ge_mask", 0)
474 system_value("subgroup_gt_mask", 0)
475 system_value("subgroup_le_mask", 0)
476 system_value("subgroup_lt_mask", 0)
477 system_value("num_subgroups", 1)
478 system_value("subgroup_id", 1)
479 system_value("local_group_size", 3)
480 system_value("global_invocation_id", 3)
481 system_value("work_dim", 1)
483 # Blend constant color values. Float values are clamped.#
484 system_value("blend_const_color_r_float", 1)
485 system_value("blend_const_color_g_float", 1)
486 system_value("blend_const_color_b_float", 1)
487 system_value("blend_const_color_a_float", 1)
488 system_value("blend_const_color_rgba8888_unorm", 1)
489 system_value("blend_const_color_aaaa8888_unorm", 1)
491 # Barycentric coordinate intrinsics.
493 # These set up the barycentric coordinates for a particular interpolation.
494 # The first three are for the simple cases: pixel, centroid, or per-sample
495 # (at gl_SampleID). The next two handle interpolating at a specified
496 # sample location, or interpolating with a vec2 offset,
498 # The interp_mode index should be either the INTERP_MODE_SMOOTH or
499 # INTERP_MODE_NOPERSPECTIVE enum values.
501 # The vec2 value produced by these intrinsics is intended for use as the
502 # barycoord source of a load_interpolated_input intrinsic.
504 def barycentric(name
, src_comp
=[]):
505 intrinsic("load_barycentric_" + name
, src_comp
=src_comp
, dest_comp
=2,
506 indices
=[INTERP_MODE
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
508 # no sources. const_index[] = { interp_mode }
510 barycentric("centroid")
511 barycentric("sample")
512 # src[] = { sample_id }. const_index[] = { interp_mode }
513 barycentric("at_sample", [1])
514 # src[] = { offset.xy }. const_index[] = { interp_mode }
515 barycentric("at_offset", [2])
517 # Load operations pull data from some piece of GPU memory. All load
518 # operations operate in terms of offsets into some piece of theoretical
519 # memory. Loads from externally visible memory (UBO and SSBO) simply take a
520 # byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)
521 # take a base+offset pair where the base (const_index[0]) gives the location
522 # of the start of the variable being loaded and and the offset source is a
523 # offset into that variable.
525 # Uniform load operations have a second "range" index that specifies the
526 # range (starting at base) of the data from which we are loading. If
527 # const_index[1] == 0, then the range is unknown.
529 # Some load operations such as UBO/SSBO load and per_vertex loads take an
530 # additional source to specify which UBO/SSBO/vertex to load from.
532 # The exact address type depends on the lowering pass that generates the
533 # load/store intrinsics. Typically, this is vec4 units for things such as
534 # varying slots and float units for fragment shader inputs. UBO and SSBO
535 # offsets are always in bytes.
537 def load(name
, num_srcs
, indices
=[], flags
=[]):
538 intrinsic("load_" + name
, [1] * num_srcs
, dest_comp
=0, indices
=indices
,
541 # src[] = { offset }. const_index[] = { base, range }
542 load("uniform", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
543 # src[] = { buffer_index, offset }. No const_index
544 load("ubo", 2, flags
=[CAN_ELIMINATE
, CAN_REORDER
])
545 # src[] = { offset }. const_index[] = { base, component }
546 load("input", 1, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
547 # src[] = { vertex, offset }. const_index[] = { base, component }
548 load("per_vertex_input", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
, CAN_REORDER
])
549 # src[] = { barycoord, offset }. const_index[] = { base, component }
550 intrinsic("load_interpolated_input", src_comp
=[2, 1], dest_comp
=0,
551 indices
=[BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
, CAN_REORDER
])
553 # src[] = { buffer_index, offset }. No const_index
554 load("ssbo", 2, flags
=[CAN_ELIMINATE
])
555 # src[] = { offset }. const_index[] = { base, component }
556 load("output", 1, [BASE
, COMPONENT
], flags
=[CAN_ELIMINATE
])
557 # src[] = { vertex, offset }. const_index[] = { base }
558 load("per_vertex_output", 2, [BASE
, COMPONENT
], [CAN_ELIMINATE
])
559 # src[] = { offset }. const_index[] = { base }
560 load("shared", 1, [BASE
], [CAN_ELIMINATE
])
561 # src[] = { offset }. const_index[] = { base, range }
562 load("push_constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
563 # src[] = { offset }. const_index[] = { base, range }
564 load("constant", 1, [BASE
, RANGE
], [CAN_ELIMINATE
, CAN_REORDER
])
566 # Stores work the same way as loads, except now the first source is the value
567 # to store and the second (and possibly third) source specify where to store
568 # the value. SSBO and shared memory stores also have a write mask as
571 def store(name
, num_srcs
, indices
=[], flags
=[]):
572 intrinsic("store_" + name
, [0] + ([1] * (num_srcs
- 1)), indices
=indices
, flags
=flags
)
574 # src[] = { value, offset }. const_index[] = { base, write_mask, component }
575 store("output", 2, [BASE
, WRMASK
, COMPONENT
])
576 # src[] = { value, vertex, offset }.
577 # const_index[] = { base, write_mask, component }
578 store("per_vertex_output", 3, [BASE
, WRMASK
, COMPONENT
])
579 # src[] = { value, block_index, offset }. const_index[] = { write_mask }
580 store("ssbo", 3, [WRMASK
])
581 # src[] = { value, offset }. const_index[] = { base, write_mask }
582 store("shared", 2, [BASE
, WRMASK
])