xref: /aosp_15_r20/external/mesa3d/src/compiler/nir/nir_intrinsics.py (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1#
2# Copyright (C) 2018 Red Hat
3# Copyright (C) 2014 Intel Corporation
4#
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:
11#
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
14# Software.
15#
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
22# IN THE SOFTWARE.
23#
24
25# This file defines all the available intrinsics in one place.
26#
27# The Intrinsic class corresponds one-to-one with nir_intrinsic_info
28# structure.
29
30src0 = ('src', 0)
31src1 = ('src', 1)
32src2 = ('src', 2)
33src3 = ('src', 3)
34src4 = ('src', 4)
35
36class Index(object):
37    def __init__(self, c_data_type, name):
38        self.c_data_type = c_data_type
39        self.name = name
40
41class Intrinsic(object):
42   """Class that represents all the information about an intrinsic opcode.
43   NOTE: this must be kept in sync with nir_intrinsic_info.
44   """
45   def __init__(self, name, src_components, dest_components,
46                indices, flags, sysval, bit_sizes):
47       """Parameters:
48
49       - name: the intrinsic name
50       - src_components: list of the number of components per src, 0 means
51         vectorized instruction with number of components given in the
52         num_components field in nir_intrinsic_instr.
53       - dest_components: number of destination components, -1 means no
54         dest, 0 means number of components given in num_components field
55         in nir_intrinsic_instr.
56       - indices: list of constant indicies
57       - flags: list of semantic flags
58       - sysval: is this a system-value intrinsic
59       - bit_sizes: allowed dest bit_sizes or the source it must match
60       """
61       assert isinstance(name, str)
62       assert isinstance(src_components, list)
63       if src_components:
64           assert isinstance(src_components[0], int)
65       assert isinstance(dest_components, int)
66       assert isinstance(indices, list)
67       if indices:
68           assert isinstance(indices[0], Index)
69       assert isinstance(flags, list)
70       if flags:
71           assert isinstance(flags[0], str)
72       assert isinstance(sysval, bool)
73       if isinstance(bit_sizes, list):
74           assert not bit_sizes or isinstance(bit_sizes[0], int)
75       else:
76           assert isinstance(bit_sizes, tuple)
77           assert bit_sizes[0] == 'src'
78           assert isinstance(bit_sizes[1], int)
79
80       self.name = name
81       self.num_srcs = len(src_components)
82       self.src_components = src_components
83       self.has_dest = (dest_components >= 0)
84       self.dest_components = dest_components
85       self.num_indices = len(indices)
86       self.indices = indices
87       self.flags = flags
88       self.sysval = sysval
89       self.bit_sizes = bit_sizes if isinstance(bit_sizes, list) else []
90       self.bit_size_src = bit_sizes[1] if isinstance(bit_sizes, tuple) else -1
91
92#
93# Possible flags:
94#
95
96CAN_ELIMINATE = "NIR_INTRINSIC_CAN_ELIMINATE"
97CAN_REORDER   = "NIR_INTRINSIC_CAN_REORDER"
98
99INTR_INDICES = []
100INTR_OPCODES = {}
101
102def index(c_data_type, name):
103    idx = Index(c_data_type, name)
104    INTR_INDICES.append(idx)
105    globals()[name.upper()] = idx
106
107# Defines a new NIR intrinsic.  By default, the intrinsic will have no sources
108# and no destination.
109#
110# You can set dest_comp=n to enable a destination for the intrinsic, in which
111# case it will have that many components, or =0 for "as many components as the
112# NIR destination value."
113#
114# Set src_comp=n to enable sources for the intruction.  It can be an array of
115# component counts, or (for convenience) a scalar component count if there's
116# only one source.  If a component count is 0, it will be as many components as
117# the intrinsic has based on the dest_comp.
118def intrinsic(name, src_comp=[], dest_comp=-1, indices=[],
119              flags=[], sysval=False, bit_sizes=[]):
120    assert name not in INTR_OPCODES
121    INTR_OPCODES[name] = Intrinsic(name, src_comp, dest_comp,
122                                   indices, flags, sysval, bit_sizes)
123
124#
125# Possible indices:
126#
127
128# Generally instructions that take a offset src argument, can encode
129# a constant 'base' value which is added to the offset.
130index("int", "base")
131
132# For store instructions, a writemask for the store.
133index("unsigned", "write_mask")
134
135# The stream-id for GS emit_vertex/end_primitive intrinsics.
136index("unsigned", "stream_id")
137
138# The clip-plane id for load_user_clip_plane intrinsic.
139index("unsigned", "ucp_id")
140
141# The offset to the start of the NIR_INTRINSIC_RANGE.  This is an alternative
142# to NIR_INTRINSIC_BASE for describing the valid range in intrinsics that don't
143# have the implicit addition of a base to the offset.
144#
145# If the [range_base, range] is [0, ~0], then we don't know the possible
146# range of the access.
147index("unsigned", "range_base")
148
149# The amount of data, starting from BASE or RANGE_BASE, that this
150# instruction may access.  This is used to provide bounds if the offset is
151# not constant.
152index("unsigned", "range")
153
154# The Vulkan descriptor set for vulkan_resource_index intrinsic.
155index("unsigned", "desc_set")
156
157# The Vulkan descriptor set binding for vulkan_resource_index intrinsic.
158index("unsigned", "binding")
159
160# Component offset
161index("unsigned", "component")
162
163# Column index for matrix system values
164index("unsigned", "column")
165
166# Interpolation mode (only meaningful for FS inputs)
167index("unsigned", "interp_mode")
168
169# A binary nir_op to use when performing a reduction or scan operation
170index("unsigned", "reduction_op")
171
172# Cluster size for reduction operations
173index("unsigned", "cluster_size")
174
175# Parameter index for a load_param intrinsic
176index("unsigned", "param_idx")
177
178# Image dimensionality for image intrinsics
179index("enum glsl_sampler_dim", "image_dim")
180
181# Non-zero if we are accessing an array image
182index("bool", "image_array")
183
184# Image format for image intrinsics
185# Vertex buffer format for load_typed_buffer_amd
186index("enum pipe_format", "format")
187
188# Access qualifiers for image and memory access intrinsics. ACCESS_RESTRICT is
189# not set at the intrinsic if the NIR was created from SPIR-V.
190index("enum gl_access_qualifier", "access")
191
192# call index for split raytracing shaders
193index("unsigned", "call_idx")
194
195# The stack size increment/decrement for split raytracing shaders
196index("unsigned", "stack_size")
197
198# Alignment for offsets and addresses
199#
200# These two parameters, specify an alignment in terms of a multiplier and
201# an offset.  The multiplier is always a power of two.  The offset or
202# address parameter X of the intrinsic is guaranteed to satisfy the
203# following:
204#
205#                (X - align_offset) % align_mul == 0
206#
207# For constant offset values, align_mul will be NIR_ALIGN_MUL_MAX and the
208# align_offset will be modulo that.
209index("unsigned", "align_mul")
210index("unsigned", "align_offset")
211
212# The Vulkan descriptor type for a vulkan_resource_[re]index intrinsic.
213index("unsigned", "desc_type")
214
215# The nir_alu_type of input data to a store or conversion
216index("nir_alu_type", "src_type")
217
218# The nir_alu_type of the data output from a load or conversion
219index("nir_alu_type", "dest_type")
220
221# The swizzle mask for quad_swizzle_amd & masked_swizzle_amd
222index("unsigned", "swizzle_mask")
223
224# Allow FI=1 for quad_swizzle_amd & masked_swizzle_amd
225index("bool", "fetch_inactive")
226
227# Offsets for load_shared2_amd/store_shared2_amd
228index("uint8_t", "offset0")
229index("uint8_t", "offset1")
230
231# If true, both offsets have an additional stride of 64 dwords (ie. they are multiplied by 256 bytes
232# in hardware, instead of 4).
233index("bool", "st64")
234
235# When set, range analysis will use it for nir_unsigned_upper_bound
236index("unsigned", "arg_upper_bound_u32_amd")
237
238# Separate source/dest access flags for copies
239index("enum gl_access_qualifier", "dst_access")
240index("enum gl_access_qualifier", "src_access")
241
242# Driver location of attribute
243index("unsigned", "driver_location")
244
245# Ordering and visibility of a memory operation
246index("nir_memory_semantics", "memory_semantics")
247
248# Modes affected by a memory operation
249index("nir_variable_mode", "memory_modes")
250
251# Scope of a memory operation
252index("mesa_scope", "memory_scope")
253
254# Scope of a control barrier
255index("mesa_scope", "execution_scope")
256
257# Semantics of an IO instruction
258index("struct nir_io_semantics", "io_semantics")
259
260# Transform feedback info
261index("struct nir_io_xfb", "io_xfb")
262index("struct nir_io_xfb", "io_xfb2")
263
264# Ray query values accessible from the RayQueryKHR object
265index("nir_ray_query_value", "ray_query_value")
266
267# Select between committed and candidate ray queriy intersections
268index("bool", "committed")
269
270# Rounding mode for conversions
271index("nir_rounding_mode", "rounding_mode")
272
273# Whether or not to saturate in conversions
274index("unsigned", "saturate")
275
276# Whether or not trace_ray_intel is synchronous
277index("bool", "synchronous")
278
279# Value ID to identify SSA value loaded/stored on the stack
280index("unsigned", "value_id")
281
282# Whether to sign-extend offsets in address arithmatic (else zero extend)
283index("bool", "sign_extend")
284
285# Instruction specific flags
286index("unsigned", "flags")
287
288# Logical operation of an atomic intrinsic
289index("nir_atomic_op", "atomic_op")
290
291# Block identifier to push promotion
292index("unsigned", "resource_block_intel")
293
294# Various flags describing the resource access
295index("nir_resource_data_intel", "resource_access_intel")
296
297# Register metadata
298# number of vector components
299index("unsigned", "num_components")
300# size of array (0 for no array)
301index("unsigned", "num_array_elems")
302# The bit-size of each channel; must be one of 1, 8, 16, 32, or 64
303index("unsigned", "bit_size")
304# True if this register may have different values in different SIMD invocations
305# of the shader.
306index("bool", "divergent")
307
308# On a register load, floating-point absolute value/negate loaded value.
309index("bool", "legacy_fabs")
310index("bool", "legacy_fneg")
311
312# On a register store, floating-point saturate the stored value.
313index("bool", "legacy_fsat")
314
315# For Cooperative Matrix intrinsics.
316index("struct glsl_cmat_description", "cmat_desc")
317index("enum glsl_matrix_layout", "matrix_layout")
318index("nir_cmat_signed", "cmat_signed_mask")
319index("nir_op", "alu_op")
320
321# For Intel DPAS instrinsic.
322index("unsigned", "systolic_depth")
323index("unsigned", "repeat_count")
324
325# For an AGX tilebuffer intrinsics, whether the coordinates are implicit or
326# explicit. Implicit coordinates are used in fragment shaders, explicit
327# coordinates in compute.
328index("bool", "explicit_coord")
329
330intrinsic("nop", flags=[CAN_ELIMINATE])
331
332# Uses a value and cannot be eliminated.
333#
334# This is helpful when writing unit tests
335intrinsic("use", src_comp=[0], flags=[])
336
337intrinsic("convert_alu_types", dest_comp=0, src_comp=[0],
338          indices=[SRC_TYPE, DEST_TYPE, ROUNDING_MODE, SATURATE],
339          flags=[CAN_ELIMINATE, CAN_REORDER])
340
341intrinsic("load_param", dest_comp=0, indices=[PARAM_IDX], flags=[CAN_ELIMINATE])
342
343intrinsic("load_deref", dest_comp=0, src_comp=[-1],
344          indices=[ACCESS], flags=[CAN_ELIMINATE])
345intrinsic("store_deref", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])
346intrinsic("copy_deref", src_comp=[-1, -1], indices=[DST_ACCESS, SRC_ACCESS])
347intrinsic("memcpy_deref", src_comp=[-1, -1, 1], indices=[DST_ACCESS, SRC_ACCESS])
348
349# Returns an opaque handle representing a register indexed by BASE. The
350# logically def-use list of a register is given by the use list of this handle.
351# The shape of the underlying register is given by the indices, the handle
352# itself is always a 32-bit scalar.
353intrinsic("decl_reg", dest_comp=1,
354          indices=[NUM_COMPONENTS, NUM_ARRAY_ELEMS, BIT_SIZE, DIVERGENT],
355          flags=[CAN_ELIMINATE])
356
357# Load a register given as the source directly with base offset BASE.
358intrinsic("load_reg", dest_comp=0, src_comp=[1],
359          indices=[BASE, LEGACY_FABS, LEGACY_FNEG], flags=[CAN_ELIMINATE])
360
361# Load a register given as first source indirectly with base offset BASE and
362# indirect offset as second source.
363intrinsic("load_reg_indirect", dest_comp=0, src_comp=[1, 1],
364          indices=[BASE, LEGACY_FABS, LEGACY_FNEG], flags=[CAN_ELIMINATE])
365
366# Store the value in the first source to a register given as the second source
367# directly with base offset BASE.
368intrinsic("store_reg", src_comp=[0, 1],
369          indices=[BASE, WRITE_MASK, LEGACY_FSAT])
370
371# Store the value in the first source to a register given as the second
372# source indirectly with base offset BASE and indirect offset as third source.
373intrinsic("store_reg_indirect", src_comp=[0, 1, 1],
374          indices=[BASE, WRITE_MASK, LEGACY_FSAT])
375
376# Interpolation of input.  The interp_deref_at* intrinsics are similar to the
377# load_var intrinsic acting on a shader input except that they interpolate the
378# input differently.  The at_sample, at_offset and at_vertex intrinsics take an
379# additional source that is an integer sample id, a vec2 position offset, or a
380# vertex ID respectively.
381
382intrinsic("interp_deref_at_centroid", dest_comp=0, src_comp=[1],
383          flags=[ CAN_ELIMINATE, CAN_REORDER])
384intrinsic("interp_deref_at_sample", src_comp=[1, 1], dest_comp=0,
385          flags=[CAN_ELIMINATE, CAN_REORDER])
386intrinsic("interp_deref_at_offset", src_comp=[1, 2], dest_comp=0,
387          flags=[CAN_ELIMINATE, CAN_REORDER])
388intrinsic("interp_deref_at_vertex", src_comp=[1, 1], dest_comp=0,
389          flags=[CAN_ELIMINATE, CAN_REORDER])
390
391# Gets the length of an unsized array at the end of a buffer
392intrinsic("deref_buffer_array_length", src_comp=[-1], dest_comp=1,
393          indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])
394
395# Ask the driver for the size of a given SSBO. It takes the buffer index
396# as source.
397intrinsic("get_ssbo_size", src_comp=[-1], dest_comp=1, bit_sizes=[32],
398          indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])
399intrinsic("get_ubo_size", src_comp=[-1], dest_comp=1,
400          flags=[CAN_ELIMINATE, CAN_REORDER])
401
402# Intrinsics which provide a run-time mode-check.  Unlike the compile-time
403# mode checks, a pointer can only have exactly one mode at runtime.
404intrinsic("deref_mode_is", src_comp=[-1], dest_comp=1,
405          indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])
406intrinsic("addr_mode_is", src_comp=[-1], dest_comp=1,
407          indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])
408
409intrinsic("is_sparse_texels_resident", dest_comp=1, src_comp=[1], bit_sizes=[1,32],
410          flags=[CAN_ELIMINATE, CAN_REORDER])
411# result code is resident only if both inputs are resident
412intrinsic("sparse_residency_code_and", dest_comp=1, src_comp=[1, 1], bit_sizes=[32],
413          flags=[CAN_ELIMINATE, CAN_REORDER])
414
415# Unlike is_sparse_texels_resident, this intrinsic is required to consume
416# the destination of the nir_tex_instr or sparse_load intrinsic directly.
417# As such it is allowed to ignore the .e component where we usually store
418# sparse information.
419intrinsic("is_sparse_resident_zink", dest_comp=1, src_comp=[0], bit_sizes=[1],
420          flags=[CAN_ELIMINATE, CAN_REORDER])
421
422# The following intrinsics calculate screen-space partial derivatives. These are
423# not CAN_REORDER as they cannot be moved across discards.
424for suffix in ["", "_fine", "_coarse"]:
425    for axis in ["x", "y"]:
426        intrinsic(f"dd{axis}{suffix}", dest_comp=0, src_comp=[0],
427                  bit_sizes=[16, 32], flags=[CAN_ELIMINATE])
428
429# a barrier is an intrinsic with no inputs/outputs but which can't be moved
430# around/optimized in general
431def barrier(name):
432    intrinsic(name)
433
434# Demote fragment shader invocation to a helper invocation.  Any stores to
435# memory after this instruction are suppressed and the fragment does not write
436# outputs to the framebuffer.  Unlike discard, demote needs to ensure that
437# derivatives will still work for invocations that were not demoted.
438#
439# As specified by SPV_EXT_demote_to_helper_invocation.
440barrier("demote")
441intrinsic("is_helper_invocation", dest_comp=1, flags=[CAN_ELIMINATE])
442
443# SpvOpTerminateInvocation from SPIR-V.  Essentially a discard "for real".
444barrier("terminate")
445
446# Control/Memory barrier with explicit scope.  Follows the semantics of SPIR-V
447# OpMemoryBarrier and OpControlBarrier, used to implement Vulkan Memory Model.
448# Storage that the barrier applies is represented using NIR variable modes.
449# For an OpMemoryBarrier, set EXECUTION_SCOPE to SCOPE_NONE.
450intrinsic("barrier",
451          indices=[EXECUTION_SCOPE, MEMORY_SCOPE, MEMORY_SEMANTICS, MEMORY_MODES])
452
453# Shader clock intrinsic with semantics analogous to the clock2x32ARB()
454# GLSL intrinsic.
455# The latter can be used as code motion barrier, which is currently not
456# feasible with NIR.
457intrinsic("shader_clock", dest_comp=2, bit_sizes=[32], flags=[CAN_ELIMINATE],
458          indices=[MEMORY_SCOPE])
459
460# Shader ballot intrinsics with semantics analogous to the
461#
462#    ballotARB()
463#    readInvocationARB()
464#    readFirstInvocationARB()
465#
466# GLSL functions from ARB_shader_ballot.
467intrinsic("ballot", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])
468intrinsic("read_invocation", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
469intrinsic("read_first_invocation", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
470
471# Same as ballot, but inactive invocations contribute undefined bits.
472intrinsic("ballot_relaxed", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])
473
474# Allows the backend compiler to move this value to an uniform register.
475# Result is undefined if src is not uniform.
476# Unlike read_first_invocation, it may be replaced by a divergent move or CSE'd.
477intrinsic("as_uniform", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
478
479# Returns the value of the first source for the lane where the second source is
480# true. The second source must be true for exactly one lane.
481intrinsic("read_invocation_cond_ir3", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
482
483# Additional SPIR-V ballot intrinsics
484#
485# These correspond to the SPIR-V opcodes
486#
487#    OpGroupNonUniformElect
488#    OpSubgroupFirstInvocationKHR
489#    OpGroupNonUniformInverseBallot
490intrinsic("elect", dest_comp=1, flags=[CAN_ELIMINATE])
491intrinsic("first_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
492intrinsic("last_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
493intrinsic("inverse_ballot", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
494
495barrier("begin_invocation_interlock")
496barrier("end_invocation_interlock")
497
498# A conditional demote/terminate, with a single boolean source.
499intrinsic("demote_if", src_comp=[1])
500intrinsic("terminate_if", src_comp=[1])
501
502# ARB_shader_group_vote intrinsics
503intrinsic("vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
504intrinsic("vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
505intrinsic("vote_feq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
506intrinsic("vote_ieq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
507
508# Ballot ALU operations from SPIR-V.
509#
510# These operations work like their ALU counterparts except that the operate
511# on a uvec4 which is treated as a 128bit integer.  Also, they are, in
512# general, free to ignore any bits which are above the subgroup size.
513intrinsic("ballot_bitfield_extract", src_comp=[4, 1], dest_comp=1, flags=[CAN_ELIMINATE])
514intrinsic("ballot_bit_count_reduce", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
515intrinsic("ballot_bit_count_inclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
516intrinsic("ballot_bit_count_exclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
517intrinsic("ballot_find_lsb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
518intrinsic("ballot_find_msb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
519
520# Shuffle operations from SPIR-V.
521intrinsic("shuffle", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
522intrinsic("shuffle_xor", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
523intrinsic("shuffle_up", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
524intrinsic("shuffle_down", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
525
526# Quad operations from SPIR-V.
527intrinsic("quad_broadcast", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
528intrinsic("quad_swap_horizontal", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
529intrinsic("quad_swap_vertical", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
530intrinsic("quad_swap_diagonal", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
531
532# Similar to vote_any and vote_all, but per-quad instead of per-wavefront.
533# Equivalent to subgroupOr(val, 4) and subgroupAnd(val, 4) assuming val is
534# boolean.
535intrinsic("quad_vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
536intrinsic("quad_vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
537
538# Rotate operation from SPIR-V: SpvOpGroupNonUniformRotateKHR.
539intrinsic("rotate", src_comp=[0, 1], dest_comp=0, bit_sizes=src0,
540          indices=[CLUSTER_SIZE], flags=[CAN_ELIMINATE]);
541
542intrinsic("reduce", src_comp=[0], dest_comp=0, bit_sizes=src0,
543          indices=[REDUCTION_OP, CLUSTER_SIZE], flags=[CAN_ELIMINATE])
544intrinsic("inclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,
545          indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])
546intrinsic("exclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,
547          indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])
548
549# AMD shader ballot operations
550intrinsic("quad_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,
551          indices=[SWIZZLE_MASK, FETCH_INACTIVE], flags=[CAN_ELIMINATE])
552intrinsic("masked_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,
553          indices=[SWIZZLE_MASK, FETCH_INACTIVE], flags=[CAN_ELIMINATE])
554intrinsic("write_invocation_amd", src_comp=[0, 0, 1], dest_comp=0, bit_sizes=src0,
555          flags=[CAN_ELIMINATE])
556# src = [ mask, addition ]
557intrinsic("mbcnt_amd", src_comp=[1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
558# Compiled to v_permlane16_b32. src = [ value, lanesel_lo, lanesel_hi ]
559intrinsic("lane_permute_16_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
560# subgroup shuffle up/down with cluster size 16.
561# base in [-15, -1]: DPP_ROW_SR
562# base in [  1, 15]: DPP_ROW_SL, otherwise invalid.
563# Returns zero for invocations that try to read out of bounds
564intrinsic("dpp16_shift_amd", src_comp=[0], dest_comp=0, bit_sizes=src0, indices=[BASE], flags=[CAN_ELIMINATE])
565
566# Basic Geometry Shader intrinsics.
567#
568# emit_vertex implements GLSL's EmitStreamVertex() built-in.  It takes a single
569# index, which is the stream ID to write to.
570#
571# end_primitive implements GLSL's EndPrimitive() built-in.
572intrinsic("emit_vertex",   indices=[STREAM_ID])
573intrinsic("end_primitive", indices=[STREAM_ID])
574
575# Geometry Shader intrinsics with a vertex count.
576#
577# Alternatively, drivers may implement these intrinsics, and use
578# nir_lower_gs_intrinsics() to convert from the basic intrinsics.
579#
580# These contain four additional unsigned integer sources:
581# 1. The total number of vertices emitted so far.
582# 2. The number of vertices emitted for the current primitive
583#    so far if we're counting, otherwise undef.
584# 3. The total number of primitives emitted so far.
585# 4. The total number of decomposed primitives emitted so far. This counts like
586#    the PRIMITIVES_GENERATED query: a triangle strip with 5 vertices is counted
587#    as 3 primitives (not 1).
588intrinsic("emit_vertex_with_counter", src_comp=[1, 1, 1, 1], indices=[STREAM_ID])
589intrinsic("end_primitive_with_counter", src_comp=[1, 1, 1, 1], indices=[STREAM_ID])
590# Contains the final total vertex, primitive, and decomposed primitives counts
591# in the current GS thread.
592intrinsic("set_vertex_and_primitive_count", src_comp=[1, 1, 1], indices=[STREAM_ID])
593
594# Launches mesh shader workgroups from a task shader, with explicit task_payload.
595# Rules:
596# - This is a terminating instruction.
597# - May only occur in workgroup-uniform control flow.
598# - Dispatch sizes may be divergent (in which case the values
599#   from the first invocation are used).
600# Meaning of indices:
601# - BASE: address of the task_payload variable used.
602# - RANGE: size of the task_payload variable used.
603#
604# src[] = {vec(x, y, z)}
605intrinsic("launch_mesh_workgroups", src_comp=[3], indices=[BASE, RANGE])
606
607# Launches mesh shader workgroups from a task shader, with task_payload variable deref.
608# Same rules as launch_mesh_workgroups apply here as well.
609# src[] = {vec(x, y, z), payload pointer}
610intrinsic("launch_mesh_workgroups_with_payload_deref", src_comp=[3, -1], indices=[])
611
612# Trace a ray through an acceleration structure
613#
614# This instruction has a lot of parameters:
615#   0. Acceleration Structure
616#   1. Ray Flags
617#   2. Cull Mask
618#   3. SBT Offset
619#   4. SBT Stride
620#   5. Miss shader index
621#   6. Ray Origin
622#   7. Ray Tmin
623#   8. Ray Direction
624#   9. Ray Tmax
625#   10. Payload
626intrinsic("trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1])
627# src[] = { hit_t, hit_kind }
628intrinsic("report_ray_intersection", src_comp=[1, 1], dest_comp=1)
629intrinsic("ignore_ray_intersection")
630intrinsic("accept_ray_intersection") # Not in SPIR-V; useful for lowering
631intrinsic("terminate_ray")
632# src[] = { sbt_index, payload }
633intrinsic("execute_callable", src_comp=[1, -1])
634
635# Initialize a ray query
636#
637#   0. Ray Query
638#   1. Acceleration Structure
639#   2. Ray Flags
640#   3. Cull Mask
641#   4. Ray Origin
642#   5. Ray Tmin
643#   6. Ray Direction
644#   7. Ray Tmax
645intrinsic("rq_initialize", src_comp=[-1, -1, 1, 1, 3, 1, 3, 1])
646# src[] = { query }
647intrinsic("rq_terminate", src_comp=[-1])
648# src[] = { query }
649intrinsic("rq_proceed", src_comp=[-1], dest_comp=1)
650# src[] = { query, hit }
651intrinsic("rq_generate_intersection", src_comp=[-1, 1])
652# src[] = { query }
653intrinsic("rq_confirm_intersection", src_comp=[-1])
654# src[] = { query }
655intrinsic("rq_load", src_comp=[-1], dest_comp=0, indices=[RAY_QUERY_VALUE,COMMITTED,COLUMN])
656
657# Driver independent raytracing helpers
658
659# rt_resume is a helper that that be the first instruction accesing the
660# stack/scratch in a resume shader for a raytracing pipeline. It includes the
661# resume index (for nir_lower_shader_calls_internal reasons) and the stack size
662# of the variables spilled during the call. The stack size can be use to e.g.
663# adjust a stack pointer.
664intrinsic("rt_resume", indices=[CALL_IDX, STACK_SIZE])
665
666# Lowered version of execute_callabe that includes the index of the resume
667# shader, and the amount of scratch space needed for this call (.ie. how much
668# to increase a stack pointer by).
669# src[] = { sbt_index, payload }
670intrinsic("rt_execute_callable", src_comp=[1, -1], indices=[CALL_IDX,STACK_SIZE])
671
672# Lowered version of trace_ray in a similar vein to rt_execute_callable.
673# src same as trace_ray
674intrinsic("rt_trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1],
675          indices=[CALL_IDX, STACK_SIZE])
676
677
678# Atomic counters
679#
680# The *_deref variants take an atomic_uint nir_variable, while the other,
681# lowered, variants take a buffer index and register offset.  The buffer index
682# is always constant, as there's no way to declare an array of atomic counter
683# buffers.
684#
685# The register offset may be non-constant but must by dynamically uniform
686# ("Atomic counters aggregated into arrays within a shader can only be indexed
687# with dynamically uniform integral expressions, otherwise results are
688# undefined.")
689def atomic(name, flags=[]):
690    intrinsic(name + "_deref", src_comp=[-1], dest_comp=1, flags=flags)
691    intrinsic(name, src_comp=[1], dest_comp=1, indices=[BASE, RANGE_BASE], flags=flags)
692
693def atomic2(name):
694    intrinsic(name + "_deref", src_comp=[-1, 1], dest_comp=1)
695    intrinsic(name, src_comp=[1, 1], dest_comp=1, indices=[BASE, RANGE_BASE])
696
697def atomic3(name):
698    intrinsic(name + "_deref", src_comp=[-1, 1, 1], dest_comp=1)
699    intrinsic(name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE, RANGE_BASE])
700
701atomic("atomic_counter_inc")
702atomic("atomic_counter_pre_dec")
703atomic("atomic_counter_post_dec")
704atomic("atomic_counter_read", flags=[CAN_ELIMINATE])
705atomic2("atomic_counter_add")
706atomic2("atomic_counter_min")
707atomic2("atomic_counter_max")
708atomic2("atomic_counter_and")
709atomic2("atomic_counter_or")
710atomic2("atomic_counter_xor")
711atomic2("atomic_counter_exchange")
712atomic3("atomic_counter_comp_swap")
713
714# Image load, store and atomic intrinsics.
715#
716# All image intrinsics come in three versions.  One which take an image target
717# passed as a deref chain as the first source, one which takes an index as the
718# first source, and one which takes a bindless handle as the first source.
719# In the first version, the image variable contains the memory and layout
720# qualifiers that influence the semantics of the intrinsic.  In the second and
721# third, the image format and access qualifiers are provided as constant
722# indices.  Up through GLSL ES 3.10, the image index source may only be a
723# constant array access.  GLSL ES 3.20 and GLSL 4.00 allow dynamically uniform
724# indexing.
725#
726# All image intrinsics take a four-coordinate vector and a sample index as
727# 2nd and 3rd sources, determining the location within the image that will be
728# accessed by the intrinsic.  Components not applicable to the image target
729# in use are undefined.  Image store takes an additional four-component
730# argument with the value to be written, and image atomic operations take
731# either one or two additional scalar arguments with the same meaning as in
732# the ARB_shader_image_load_store specification.
733#
734# The last source of many image intrinsics is the LOD. This source is zero
735# unless e.g. SPV_AMD_shader_image_load_store_lod is supported.
736def image(name, src_comp=[], extra_indices=[], **kwargs):
737    intrinsic("image_deref_" + name, src_comp=[-1] + src_comp,
738              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
739    intrinsic("image_" + name, src_comp=[1] + src_comp,
740              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS, RANGE_BASE] + extra_indices, **kwargs)
741    intrinsic("bindless_image_" + name, src_comp=[-1] + src_comp,
742              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
743
744image("load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
745image("sparse_load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
746image("store", src_comp=[4, 1, 0, 1], extra_indices=[SRC_TYPE])
747image("atomic",  src_comp=[4, 1, 1], dest_comp=1, extra_indices=[ATOMIC_OP])
748image("atomic_swap", src_comp=[4, 1, 1, 1], dest_comp=1, extra_indices=[ATOMIC_OP])
749image("size",    dest_comp=0, src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])
750image("levels",  dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
751image("samples", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
752image("texel_address", dest_comp=1, src_comp=[4, 1],
753      flags=[CAN_ELIMINATE, CAN_REORDER])
754# This returns true if all samples within the pixel have equal color values.
755image("samples_identical", dest_comp=1, src_comp=[4], flags=[CAN_ELIMINATE])
756# Non-uniform access is not lowered for image_descriptor_amd.
757# dest_comp can be either 4 (buffer) or 8 (image).
758image("descriptor_amd", dest_comp=0, src_comp=[], flags=[CAN_ELIMINATE, CAN_REORDER])
759# CL-specific format queries
760image("format", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
761image("order", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
762# Multisample fragment mask load
763# src_comp[0] is same as image load src_comp[0]
764image("fragment_mask_load_amd", src_comp=[4], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
765
766# Vulkan descriptor set intrinsics
767#
768# The Vulkan API uses a different binding model from GL.  In the Vulkan
769# API, all external resources are represented by a tuple:
770#
771# (descriptor set, binding, array index)
772#
773# where the array index is the only thing allowed to be indirect.  The
774# vulkan_surface_index intrinsic takes the descriptor set and binding as
775# its first two indices and the array index as its source.  The third
776# index is a nir_variable_mode in case that's useful to the backend.
777#
778# The intended usage is that the shader will call vulkan_surface_index to
779# get an index and then pass that as the buffer index ubo/ssbo calls.
780#
781# The vulkan_resource_reindex intrinsic takes a resource index in src0
782# (the result of a vulkan_resource_index or vulkan_resource_reindex) which
783# corresponds to the tuple (set, binding, index) and computes an index
784# corresponding to tuple (set, binding, idx + src1).
785intrinsic("vulkan_resource_index", src_comp=[1], dest_comp=0,
786          indices=[DESC_SET, BINDING, DESC_TYPE],
787          flags=[CAN_ELIMINATE, CAN_REORDER])
788intrinsic("vulkan_resource_reindex", src_comp=[0, 1], dest_comp=0,
789          indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])
790intrinsic("load_vulkan_descriptor", src_comp=[-1], dest_comp=0,
791          indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])
792
793# atomic intrinsics
794#
795# All of these atomic memory operations read a value from memory, compute a new
796# value using one of the operations below, write the new value to memory, and
797# return the original value read.
798#
799# All variable operations take 2 sources except CompSwap that takes 3. These
800# sources represent:
801#
802# 0: A deref to the memory on which to perform the atomic
803# 1: The data parameter to the atomic function (i.e. the value to add
804#    in shared_atomic_add, etc).
805# 2: For CompSwap only: the second data parameter.
806#
807# All SSBO operations take 3 sources except CompSwap that takes 4. These
808# sources represent:
809#
810# 0: The SSBO buffer index (dynamically uniform in GLSL, possibly non-uniform
811#    with VK_EXT_descriptor_indexing).
812# 1: The offset into the SSBO buffer of the variable that the atomic
813#    operation will operate on.
814# 2: The data parameter to the atomic function (i.e. the value to add
815#    in ssbo_atomic_add, etc).
816# 3: For CompSwap only: the second data parameter.
817#
818# All shared (and task payload) variable operations take 2 sources
819# except CompSwap that takes 3.
820# These sources represent:
821#
822# 0: The offset into the shared variable storage region that the atomic
823#    operation will operate on.
824# 1: The data parameter to the atomic function (i.e. the value to add
825#    in shared_atomic_add, etc).
826# 2: For CompSwap only: the second data parameter.
827#
828# All global operations take 2 sources except CompSwap that takes 3. These
829# sources represent:
830#
831# 0: The memory address that the atomic operation will operate on.
832# 1: The data parameter to the atomic function (i.e. the value to add
833#    in shared_atomic_add, etc).
834# 2: For CompSwap only: the second data parameter.
835#
836# The 2x32 global variants use a vec2 for the memory address where component X
837# has the low 32-bit and component Y has the high 32-bit.
838#
839# IR3 global operations take 32b vec2 as memory address. IR3 doesn't support
840# float atomics.
841#
842# AGX global variants take a 64-bit base address plus a 32-bit offset in words.
843# The offset is sign-extended or zero-extended based on the SIGN_EXTEND index.
844
845intrinsic("deref_atomic",  src_comp=[-1, 1], dest_comp=1, indices=[ACCESS, ATOMIC_OP])
846intrinsic("ssbo_atomic",  src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS, ATOMIC_OP])
847intrinsic("shared_atomic",  src_comp=[1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
848intrinsic("task_payload_atomic",  src_comp=[1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
849intrinsic("global_atomic",  src_comp=[1, 1], dest_comp=1, indices=[ATOMIC_OP])
850intrinsic("global_atomic_2x32",  src_comp=[2, 1], dest_comp=1, indices=[ATOMIC_OP])
851intrinsic("global_atomic_amd",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
852intrinsic("global_atomic_ir3",  src_comp=[2, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
853intrinsic("global_atomic_agx",  src_comp=[1, 1, 1], dest_comp=1, indices=[ATOMIC_OP, SIGN_EXTEND])
854
855intrinsic("deref_atomic_swap",  src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS, ATOMIC_OP])
856intrinsic("ssbo_atomic_swap",  src_comp=[-1, 1, 1, 1], dest_comp=1, indices=[ACCESS, ATOMIC_OP])
857intrinsic("shared_atomic_swap",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
858intrinsic("task_payload_atomic_swap",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
859intrinsic("global_atomic_swap",  src_comp=[1, 1, 1], dest_comp=1, indices=[ATOMIC_OP])
860intrinsic("global_atomic_swap_2x32",  src_comp=[2, 1, 1], dest_comp=1, indices=[ATOMIC_OP])
861intrinsic("global_atomic_swap_amd",  src_comp=[1, 1, 1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
862intrinsic("global_atomic_swap_ir3",  src_comp=[2, 1, 1], dest_comp=1, indices=[BASE, ATOMIC_OP])
863intrinsic("global_atomic_swap_agx",  src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ATOMIC_OP, SIGN_EXTEND])
864
865def system_value(name, dest_comp, indices=[], bit_sizes=[32]):
866    intrinsic("load_" + name, [], dest_comp, indices,
867              flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True,
868              bit_sizes=bit_sizes)
869
870system_value("frag_coord", 4)
871# 16-bit integer vec2 of the pixel X/Y in the framebuffer.
872system_value("pixel_coord", 2, bit_sizes=[16])
873# Scalar load of frag_coord Z/W components (component=2 for Z, component=3 for
874# W). Backends can lower frag_coord to pixel_coord + frag_coord_zw, in case
875# X/Y is available as an integer but Z/W requires interpolation.
876system_value("frag_coord_zw", 1, indices=[COMPONENT])
877system_value("point_coord", 2)
878system_value("line_coord", 1)
879system_value("front_face", 1, bit_sizes=[1, 32])
880system_value("vertex_id", 1)
881system_value("vertex_id_zero_base", 1)
882system_value("first_vertex", 1)
883system_value("is_indexed_draw", 1)
884system_value("base_vertex", 1)
885system_value("instance_id", 1)
886system_value("base_instance", 1)
887system_value("draw_id", 1)
888system_value("sample_id", 1)
889# sample_id_no_per_sample is like sample_id but does not imply per-
890# sample shading.  See the lower_helper_invocation option.
891system_value("sample_id_no_per_sample", 1)
892system_value("sample_pos", 2)
893# sample_pos_or_center is like sample_pos but does not imply per-sample
894# shading.  When per-sample dispatch is not enabled, it returns (0.5, 0.5).
895system_value("sample_pos_or_center", 2)
896system_value("sample_mask_in", 1)
897system_value("primitive_id", 1)
898system_value("invocation_id", 1)
899system_value("tess_coord", 3)
900# First 2 components of tess_coord only
901system_value("tess_coord_xy", 2)
902system_value("tess_level_outer", 4)
903system_value("tess_level_inner", 2)
904system_value("tess_level_outer_default", 4)
905system_value("tess_level_inner_default", 2)
906system_value("patch_vertices_in", 1)
907system_value("local_invocation_id", 3)
908system_value("local_invocation_index", 1)
909# workgroup_id does not include the base_workgroup_id
910system_value("workgroup_id", 3)
911# The workgroup_index is intended for situations when a 3 dimensional
912# workgroup_id is not available on the HW, but a 1 dimensional index is.
913system_value("workgroup_index", 1)
914# API specific base added to the workgroup_id, e.g. baseGroup* of vkCmdDispatchBase
915system_value("base_workgroup_id", 3, bit_sizes=[32, 64])
916system_value("user_clip_plane", 4, indices=[UCP_ID])
917system_value("num_workgroups", 3)
918system_value("num_vertices", 1)
919system_value("helper_invocation", 1, bit_sizes=[1, 32])
920system_value("layer_id", 1)
921system_value("view_index", 1)
922system_value("subgroup_size", 1)
923system_value("subgroup_invocation", 1)
924
925# These intrinsics provide a bitmask for all invocations, with one bit per
926# invocation starting with the least significant bit, according to the
927# following table,
928#
929#    variable           equation for bit values
930#    ----------------   --------------------------------
931#    subgroup_eq_mask   bit index == subgroup_invocation
932#    subgroup_ge_mask   bit index >= subgroup_invocation
933#    subgroup_gt_mask   bit index >  subgroup_invocation
934#    subgroup_le_mask   bit index <= subgroup_invocation
935#    subgroup_lt_mask   bit index <  subgroup_invocation
936#
937# These correspond to gl_SubGroupEqMaskARB, etc. from GL_ARB_shader_ballot,
938# and the above documentation is "borrowed" from that extension spec.
939system_value("subgroup_eq_mask", 0, bit_sizes=[32, 64])
940system_value("subgroup_ge_mask", 0, bit_sizes=[32, 64])
941system_value("subgroup_gt_mask", 0, bit_sizes=[32, 64])
942system_value("subgroup_le_mask", 0, bit_sizes=[32, 64])
943system_value("subgroup_lt_mask", 0, bit_sizes=[32, 64])
944
945system_value("num_subgroups", 1)
946system_value("subgroup_id", 1)
947system_value("workgroup_size", 3)
948# note: the definition of global_invocation_id is based on
949# ((workgroup_id + base_workgroup_id) * workgroup_size) + local_invocation_id.
950system_value("global_invocation_id", 3, bit_sizes=[32, 64])
951# API specific base added to the global_invocation_id
952# e.g. global_work_offset of clEnqueueNDRangeKernel
953system_value("base_global_invocation_id", 3, bit_sizes=[32, 64])
954system_value("global_invocation_index", 1, bit_sizes=[32, 64])
955# threads per dimension in an invocation
956system_value("global_size", 3, bit_sizes=[32, 64])
957system_value("work_dim", 1)
958system_value("line_width", 1)
959system_value("aa_line_width", 1)
960# BASE=0 for global/shader, BASE=1 for local/function
961system_value("scratch_base_ptr", 0, bit_sizes=[32,64], indices=[BASE])
962system_value("constant_base_ptr", 0, bit_sizes=[32,64])
963system_value("shared_base_ptr", 0, bit_sizes=[32,64])
964system_value("global_base_ptr", 0, bit_sizes=[32,64])
965# Address and size of a transform feedback buffer, indexed by BASE
966system_value("xfb_address", 1, bit_sizes=[32,64], indices=[BASE])
967system_value("xfb_size", 1, bit_sizes=[32], indices=[BASE])
968
969# Address of the associated index buffer in a transform feedback program for an
970# indexed draw. This will be used so transform feedback can pull the gl_VertexID
971# from the index buffer.
972system_value("xfb_index_buffer", 1, bit_sizes=[32,64])
973
974system_value("frag_size", 2)
975system_value("frag_invocation_count", 1)
976# Whether smooth lines or polygon smoothing is enabled
977system_value("poly_line_smooth_enabled", 1, bit_sizes=[1])
978
979# System values for ray tracing.
980system_value("ray_launch_id", 3)
981system_value("ray_launch_size", 3)
982system_value("ray_world_origin", 3)
983system_value("ray_world_direction", 3)
984system_value("ray_object_origin", 3)
985system_value("ray_object_direction", 3)
986system_value("ray_t_min", 1)
987system_value("ray_t_max", 1)
988system_value("ray_object_to_world", 3, indices=[COLUMN])
989system_value("ray_world_to_object", 3, indices=[COLUMN])
990system_value("ray_hit_kind", 1)
991system_value("ray_flags", 1)
992system_value("ray_geometry_index", 1)
993system_value("ray_instance_custom_index", 1)
994system_value("shader_record_ptr", 1, bit_sizes=[64])
995system_value("cull_mask", 1)
996system_value("ray_triangle_vertex_positions", 3, indices=[COLUMN])
997
998# Driver-specific viewport scale/offset parameters.
999#
1000# VC4 and V3D need to emit a scaled version of the position in the vertex
1001# shaders for binning, and having system values lets us move the math for that
1002# into NIR.
1003#
1004# Panfrost needs to implement all coordinate transformation in the
1005# vertex shader; system values allow us to share this routine in NIR.
1006system_value("viewport_x_scale", 1)
1007system_value("viewport_y_scale", 1)
1008system_value("viewport_z_scale", 1)
1009system_value("viewport_x_offset", 1)
1010system_value("viewport_y_offset", 1)
1011system_value("viewport_z_offset", 1)
1012system_value("viewport_scale", 3)
1013system_value("viewport_offset", 3)
1014# Pack xy scale and offset into a vec4 load (used by AMD NGG primitive culling)
1015system_value("viewport_xy_scale_and_offset", 4)
1016
1017# Blend constant color values.  Float values are clamped. Vectored versions are
1018# provided as well for driver convenience
1019
1020system_value("blend_const_color_r_float", 1)
1021system_value("blend_const_color_g_float", 1)
1022system_value("blend_const_color_b_float", 1)
1023system_value("blend_const_color_a_float", 1)
1024system_value("blend_const_color_rgba", 4)
1025system_value("blend_const_color_rgba8888_unorm", 1)
1026system_value("blend_const_color_aaaa8888_unorm", 1)
1027
1028# System values for gl_Color, for radeonsi which interpolates these in the
1029# shader prolog to handle two-sided color without recompiles and therefore
1030# doesn't handle these in the main shader part like normal varyings.
1031system_value("color0", 4)
1032system_value("color1", 4)
1033
1034# System value for internal compute shaders in radeonsi.
1035system_value("user_data_amd", 8)
1036
1037# In a fragment shader, the current sample mask. At the beginning of the shader,
1038# this is the same as load_sample_mask_in, but as the shader is executed, it may
1039# be affected by writes, discards, etc.
1040#
1041# No frontend generates this, but drivers may use it for internal lowerings.
1042intrinsic("load_sample_mask", [], 1, [], flags=[CAN_ELIMINATE], sysval=True,
1043          bit_sizes=[32])
1044
1045# Barycentric coordinate intrinsics.
1046#
1047# These set up the barycentric coordinates for a particular interpolation.
1048# The first four are for the simple cases: pixel, centroid, per-sample
1049# (at gl_SampleID), or pull model (1/W, 1/I, 1/J) at the pixel center. The next
1050# two handle interpolating at a specified sample location, or interpolating
1051# with a vec2 offset,
1052#
1053# The interp_mode index should be either the INTERP_MODE_SMOOTH or
1054# INTERP_MODE_NOPERSPECTIVE enum values.
1055#
1056# The vec2 value produced by these intrinsics is intended for use as the
1057# barycoord source of a load_interpolated_input intrinsic.
1058#
1059# The vec3 variants are intended to be used for input barycentric coordinates
1060# which are system values on most hardware, compared to the vec2 variants which
1061# interpolates input varyings.
1062
1063def barycentric(name, dst_comp, src_comp=[]):
1064    intrinsic("load_barycentric_" + name, src_comp=src_comp, dest_comp=dst_comp,
1065              indices=[INTERP_MODE], flags=[CAN_ELIMINATE, CAN_REORDER])
1066
1067# no sources.
1068barycentric("pixel", 2)
1069barycentric("coord_pixel", 3)
1070barycentric("centroid", 2)
1071barycentric("coord_centroid", 3)
1072barycentric("sample", 2)
1073barycentric("coord_sample", 3)
1074barycentric("model", 3)
1075# src[] = { sample_id }.
1076barycentric("at_sample", 2, [1])
1077barycentric("coord_at_sample", 3, [1])
1078# src[] = { offset.xy }.
1079barycentric("at_offset", 2, [2])
1080barycentric("at_offset_nv", 2, [1])
1081barycentric("coord_at_offset", 3, [2])
1082
1083# Load sample position:
1084#
1085# Takes a sample # and returns a sample position.  Used for lowering
1086# interpolateAtSample() to interpolateAtOffset()
1087intrinsic("load_sample_pos_from_id", src_comp=[1], dest_comp=2,
1088          flags=[CAN_ELIMINATE, CAN_REORDER])
1089
1090intrinsic("load_persp_center_rhw_ir3", dest_comp=1,
1091          flags=[CAN_ELIMINATE, CAN_REORDER])
1092
1093# Load texture scaling values:
1094#
1095# Takes a sampler # and returns 1/size values for multiplying to normalize
1096# texture coordinates.  Used for lowering rect textures.
1097intrinsic("load_texture_scale", src_comp=[1], dest_comp=2,
1098          flags=[CAN_ELIMINATE, CAN_REORDER])
1099
1100# Gets the texture src. This intrinsic will be lowered once functions have
1101# been inlined and we know if the src is bindless or not.
1102intrinsic("deref_texture_src", src_comp=[1], dest_comp=1,
1103          flags=[CAN_ELIMINATE, CAN_REORDER])
1104
1105# Fragment shader input interpolation delta intrinsic.
1106#
1107# For hw where fragment shader input interpolation is handled in shader, the
1108# load_fs_input_interp deltas intrinsics can be used to load the input deltas
1109# used for interpolation as follows:
1110#
1111#    vec3 iid = load_fs_input_interp_deltas(varying_slot)
1112#    vec2 bary = load_barycentric_*(...)
1113#    float result = iid.x + iid.y * bary.y + iid.z * bary.x
1114
1115intrinsic("load_fs_input_interp_deltas", src_comp=[1], dest_comp=3,
1116          indices=[BASE, COMPONENT, IO_SEMANTICS], flags=[CAN_ELIMINATE, CAN_REORDER])
1117
1118# Load operations pull data from some piece of GPU memory.  All load
1119# operations operate in terms of offsets into some piece of theoretical
1120# memory.  Loads from externally visible memory (UBO and SSBO) simply take a
1121# byte offset as a source.  Loads from opaque memory (uniforms, inputs, etc.)
1122# take a base+offset pair where the nir_intrinsic_base() gives the location
1123# of the start of the variable being loaded and and the offset source is a
1124# offset into that variable.
1125#
1126# Uniform load operations have a nir_intrinsic_range() index that specifies the
1127# range (starting at base) of the data from which we are loading.  If
1128# range == 0, then the range is unknown.
1129#
1130# UBO load operations have a nir_intrinsic_range_base() and
1131# nir_intrinsic_range() that specify the byte range [range_base,
1132# range_base+range] of the UBO that the src offset access must lie within.
1133#
1134# Some load operations such as UBO/SSBO load and per_vertex loads take an
1135# additional source to specify which UBO/SSBO/vertex to load from.
1136#
1137# The exact address type depends on the lowering pass that generates the
1138# load/store intrinsics.  Typically, this is vec4 units for things such as
1139# varying slots and float units for fragment shader inputs.  UBO and SSBO
1140# offsets are always in bytes.
1141
1142def load(name, src_comp, indices=[], flags=[]):
1143    intrinsic("load_" + name, src_comp, dest_comp=0, indices=indices,
1144              flags=flags)
1145
1146# src[] = { offset }.
1147load("uniform", [1], [BASE, RANGE, DEST_TYPE], [CAN_ELIMINATE, CAN_REORDER])
1148# src[] = { buffer_index, offset }.
1149load("ubo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET, RANGE_BASE, RANGE], flags=[CAN_ELIMINATE, CAN_REORDER])
1150# src[] = { buffer_index, offset in vec4 units }.  base is also in vec4 units.
1151load("ubo_vec4", [-1, 1], [ACCESS, BASE, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER])
1152# src[] = { offset }.
1153load("input", [1], [BASE, RANGE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1154# src[] = { vertex_id, offset }.
1155load("input_vertex", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1156# src[] = { vertex, offset }.
1157load("per_vertex_input", [1, 1], [BASE, RANGE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1158# src[] = { barycoord, offset }.
1159load("interpolated_input", [2, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1160# src[] = { offset }.
1161load("per_primitive_input", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1162
1163# src[] = { buffer_index, offset }.
1164load("ssbo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1165# src[] = { buffer_index, offset }
1166load("ssbo_address", [1, 1], [], [CAN_ELIMINATE, CAN_REORDER])
1167# src[] = { offset }.
1168load("output", [1], [BASE, RANGE, COMPONENT, DEST_TYPE, IO_SEMANTICS], flags=[CAN_ELIMINATE])
1169# src[] = { vertex, offset }.
1170load("per_vertex_output", [1, 1], [BASE, RANGE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])
1171# src[] = { primitive, offset }.
1172load("per_primitive_output", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])
1173# src[] = { offset }.
1174load("shared", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1175# src[] = { offset }.
1176load("task_payload", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1177# src[] = { offset }.
1178load("push_constant", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE, CAN_REORDER])
1179# src[] = { offset }.
1180load("constant", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET],
1181     [CAN_ELIMINATE, CAN_REORDER])
1182# src[] = { address }.
1183load("global", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1184# src[] = { address }.
1185load("global_2x32", [2], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1186# src[] = { address }.
1187load("global_constant", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
1188     [CAN_ELIMINATE, CAN_REORDER])
1189# src[] = { base_address, offset }.
1190load("global_constant_offset", [1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
1191     [CAN_ELIMINATE, CAN_REORDER])
1192# src[] = { base_address, offset, bound }.
1193load("global_constant_bounded", [1, 1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
1194     [CAN_ELIMINATE, CAN_REORDER])
1195# src[] = { address }.
1196load("kernel_input", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE, CAN_REORDER])
1197# src[] = { offset }.
1198load("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1199
1200# Stores work the same way as loads, except now the first source is the value
1201# to store and the second (and possibly third) source specify where to store
1202# the value.  SSBO and shared memory stores also have a
1203# nir_intrinsic_write_mask()
1204
1205def store(name, srcs, indices=[], flags=[]):
1206    intrinsic("store_" + name, [0] + srcs, indices=indices, flags=flags)
1207
1208# src[] = { value, offset }.
1209store("output", [1], [BASE, RANGE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS, IO_XFB, IO_XFB2])
1210# src[] = { value, vertex, offset }.
1211store("per_vertex_output", [1, 1], [BASE, RANGE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
1212# src[] = { value, primitive, offset }.
1213store("per_primitive_output", [1, 1], [BASE, RANGE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
1214# src[] = { value, block_index, offset }
1215store("ssbo", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1216# src[] = { value, offset }.
1217store("shared", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
1218# src[] = { value, offset }.
1219store("task_payload", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
1220# src[] = { value, address }.
1221store("global", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1222# src[] = { value, address }.
1223store("global_2x32", [2], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1224# src[] = { value, offset }.
1225store("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK])
1226
1227# Intrinsic to load/store from the call stack.
1228# BASE is the offset relative to the current position of the stack
1229# src[] = { }.
1230intrinsic("load_stack", [], dest_comp=0,
1231          indices=[BASE, ALIGN_MUL, ALIGN_OFFSET, CALL_IDX, VALUE_ID],
1232          flags=[CAN_ELIMINATE])
1233# src[] = { value }.
1234intrinsic("store_stack", [0],
1235          indices=[BASE, ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK, CALL_IDX, VALUE_ID])
1236
1237
1238# A bit field to implement SPIRV FragmentShadingRateKHR
1239# bit | name              | description
1240#   0 | Vertical2Pixels   | Fragment invocation covers 2 pixels vertically
1241#   1 | Vertical4Pixels   | Fragment invocation covers 4 pixels vertically
1242#   2 | Horizontal2Pixels | Fragment invocation covers 2 pixels horizontally
1243#   3 | Horizontal4Pixels | Fragment invocation covers 4 pixels horizontally
1244intrinsic("load_frag_shading_rate", dest_comp=1, bit_sizes=[32],
1245          flags=[CAN_ELIMINATE, CAN_REORDER])
1246
1247# Whether the rasterized fragment is fully covered by the generating primitive.
1248system_value("fully_covered", dest_comp=1, bit_sizes=[1])
1249
1250# OpenCL printf instruction
1251# First source is an index to the format string (u_printf_info element of the shader)
1252# Second source is a deref to a struct containing the args
1253# Dest is success or failure
1254intrinsic("printf", src_comp=[1, 1], dest_comp=1, bit_sizes=[32])
1255# Since most drivers will want to lower to just dumping args
1256# in a buffer, nir_lower_printf will do that, but requires
1257# the driver to at least provide a base location
1258system_value("printf_buffer_address", 1, bit_sizes=[32,64])
1259# If driver wants to have all printfs from various shaders merged into a
1260# single output buffer, it needs each shader to have its own base identifier
1261# from which each printf is indexed.
1262system_value("printf_base_identifier", 1, bit_sizes=[32])
1263
1264# Mesh shading MultiView intrinsics
1265system_value("mesh_view_count", 1)
1266load("mesh_view_indices", [1], [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
1267
1268# Used to pass values from the preamble to the main shader.
1269# This should use something similar to Vulkan push constants and load_preamble
1270# should be relatively cheap.
1271# For now we only support accesses with a constant offset.
1272load("preamble", [], indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
1273store("preamble", [], indices=[BASE])
1274
1275# A 64-bit bitfield indexed by I/O location storing 1 in bits corresponding to
1276# varyings that have the flat interpolation specifier in the fragment shader and
1277# 0 otherwise
1278system_value("flat_mask", 1, bit_sizes=[64])
1279
1280# Whether provoking vertex mode is last
1281system_value("provoking_last", 1)
1282
1283# SPV_KHR_cooperative_matrix.
1284#
1285# Cooperative matrices are referred through derefs to variables,
1286# the destination of the operations appears as the first source,
1287# ordering follows SPIR-V operation.
1288#
1289# Load/Store include an extra source for stride, since that
1290# can be a _dynamically_ uniform value.
1291#
1292# Length takes a type not a value, that's encoded as a MATRIX_DESC.
1293intrinsic("cmat_construct", src_comp=[-1, 1])
1294intrinsic("cmat_load", src_comp=[-1, -1, 1], indices=[MATRIX_LAYOUT])
1295intrinsic("cmat_store", src_comp=[-1, -1, 1], indices=[MATRIX_LAYOUT])
1296intrinsic("cmat_length", src_comp=[], dest_comp=1, indices=[CMAT_DESC], bit_sizes=[32])
1297intrinsic("cmat_muladd", src_comp=[-1, -1, -1, -1], indices=[SATURATE, CMAT_SIGNED_MASK])
1298intrinsic("cmat_unary_op", src_comp=[-1, -1], indices=[ALU_OP])
1299intrinsic("cmat_binary_op", src_comp=[-1, -1, -1], indices=[ALU_OP])
1300intrinsic("cmat_scalar_op", src_comp=[-1, -1, -1], indices=[ALU_OP])
1301intrinsic("cmat_bitcast", src_comp=[-1, -1])
1302intrinsic("cmat_extract", src_comp=[-1, 1], dest_comp=1)
1303intrinsic("cmat_insert", src_comp=[-1, 1, -1, 1])
1304intrinsic("cmat_copy", src_comp=[-1, -1])
1305
1306# IR3-specific version of most SSBO intrinsics. The only different
1307# compare to the originals is that they add an extra source to hold
1308# the dword-offset, which is needed by the backend code apart from
1309# the byte-offset already provided by NIR in one of the sources.
1310#
1311# NIR lowering pass 'ir3_nir_lower_io_offset' will replace the
1312# original SSBO intrinsics by these, placing the computed
1313# dword-offset always in the last source.
1314#
1315# The float versions are not handled because those are not supported
1316# by the backend.
1317store("ssbo_ir3", [1, 1, 1],
1318      indices=[BASE, WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1319load("ssbo_ir3",  [1, 1, 1],
1320     indices=[BASE, ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
1321intrinsic("ssbo_atomic_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1,
1322          indices=[ACCESS, ATOMIC_OP])
1323intrinsic("ssbo_atomic_swap_ir3",  src_comp=[1, 1, 1, 1, 1], dest_comp=1,
1324          indices=[ACCESS, ATOMIC_OP])
1325
1326# System values for freedreno geometry shaders.
1327system_value("vs_primitive_stride_ir3", 1)
1328system_value("vs_vertex_stride_ir3", 1)
1329system_value("gs_header_ir3", 1)
1330system_value("primitive_location_ir3", 1, indices=[DRIVER_LOCATION])
1331
1332# System values for freedreno tessellation shaders.
1333system_value("hs_patch_stride_ir3", 1)
1334system_value("tess_factor_base_ir3", 2)
1335system_value("tess_param_base_ir3", 2)
1336system_value("tcs_header_ir3", 1)
1337system_value("rel_patch_id_ir3", 1)
1338
1339# System values for freedreno compute shaders.
1340system_value("subgroup_id_shift_ir3", 1)
1341
1342# System values for freedreno fragment shaders.
1343intrinsic("load_frag_coord_unscaled_ir3", dest_comp=4,
1344          flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
1345
1346# Per-view gl_FragSizeEXT and gl_FragCoord offset.
1347intrinsic("load_frag_size_ir3", src_comp=[1], dest_comp=2, indices=[RANGE],
1348        flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
1349intrinsic("load_frag_offset_ir3", src_comp=[1], dest_comp=2, indices=[RANGE],
1350        flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
1351
1352# IR3-specific load/store intrinsics. These access a buffer used to pass data
1353# between geometry stages - perhaps it's explicit access to the vertex cache.
1354
1355# src[] = { value, offset }.
1356store("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET])
1357# src[] = { offset }.
1358load("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1359
1360# IR3-specific load/store global intrinsics. They take a 64-bit base address
1361# and a 32-bit offset.  The hardware will add the base and the offset, which
1362# saves us from doing 64-bit math on the base address.
1363
1364# src[] = { value, address(vec2 of hi+lo uint32_t), offset }.
1365# const_index[] = { write_mask, align_mul, align_offset }
1366store("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1367# src[] = { address(vec2 of hi+lo uint32_t), offset }.
1368# const_index[] = { access, align_mul, align_offset }
1369# the alignment applies to the base address
1370load("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET, RANGE_BASE, RANGE], flags=[CAN_ELIMINATE])
1371
1372# Etnaviv-specific load/glboal intrinsics. They take a 32-bit base address and
1373# a 32-bit offset, which doesn't need to be an immediate.
1374# src[] = { value, address, 32-bit offset }.
1375store("global_etna", [1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1376# src[] = { address, 32-bit offset }.
1377load("global_etna", [1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1378
1379# IR3-specific bindless handle specifier. Similar to vulkan_resource_index, but
1380# without the binding because the hardware expects a single flattened index
1381# rather than a (binding, index) pair. We may also want to use this with GL.
1382# Note that this doesn't actually turn into a HW instruction.
1383intrinsic("bindless_resource_ir3", [1], dest_comp=1, indices=[DESC_SET], flags=[CAN_ELIMINATE, CAN_REORDER])
1384
1385# IR3-specific intrinsics for shader preamble. These are meant to be used like
1386# this:
1387#
1388# if (preamble_start()) {
1389#    if (subgroupElect()) {
1390#       // preamble
1391#       ...
1392#       preamble_end();
1393#    }
1394# }
1395# // main shader
1396# ...
1397
1398intrinsic("preamble_start_ir3", [], dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
1399
1400barrier("preamble_end_ir3")
1401
1402# IR3-specific intrinsic to choose any invocation. This is implemented the same
1403# as elect, except that it doesn't require helper invocations. Used by preambles.
1404intrinsic("elect_any_ir3", dest_comp=1, flags=[CAN_ELIMINATE])
1405
1406# IR3-specific intrinsic for stc. Should be used in the shader preamble.
1407store("const_ir3", [], indices=[BASE])
1408
1409# IR3-specific intrinsic for loading from a const reg.
1410load("const_ir3", [1], indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
1411
1412# IR3-specific intrinsic for ldc.k. Copies UBO to constant file.
1413# base is the const file base in components, range is the amount to copy in
1414# vec4's.
1415intrinsic("copy_ubo_to_uniform_ir3", [1, 1], indices=[BASE, RANGE])
1416
1417# IR3-specific intrinsic for ldg.k.
1418# base is an offset to apply to the address in bytes, range_base is the
1419# const file base in components, range is the amount to copy in vec4's.
1420intrinsic("copy_global_to_uniform_ir3", [2], indices=[BASE, RANGE_BASE, RANGE])
1421
1422# IR3-specific intrinsic for stsc. Loads from push consts to constant file
1423# Should be used in the shader preamble.
1424intrinsic("copy_push_const_to_uniform_ir3", [1], indices=[BASE, RANGE])
1425
1426intrinsic("brcst_active_ir3", dest_comp=1, src_comp=[1, 1], bit_sizes=src0,
1427          indices=[CLUSTER_SIZE])
1428intrinsic("reduce_clusters_ir3", dest_comp=1, src_comp=[1], bit_sizes=src0,
1429          indices=[REDUCTION_OP])
1430intrinsic("inclusive_scan_clusters_ir3", dest_comp=1, src_comp=[1],
1431          bit_sizes=src0, indices=[REDUCTION_OP])
1432intrinsic("exclusive_scan_clusters_ir3", dest_comp=1, src_comp=[1, 1],
1433          bit_sizes=src0, indices=[REDUCTION_OP])
1434
1435# IR3-specific intrinsics for prefetching descriptors in preambles.
1436intrinsic("prefetch_sam_ir3", [1, 1], flags=[CAN_REORDER])
1437intrinsic("prefetch_tex_ir3", [1], flags=[CAN_REORDER])
1438intrinsic("prefetch_ubo_ir3", [1], flags=[CAN_REORDER])
1439
1440# Intrinsics used by the Midgard/Bifrost blend pipeline. These are defined
1441# within a blend shader to read/write the raw value from the tile buffer,
1442# without applying any format conversion in the process. If the shader needs
1443# usable pixel values, it must apply format conversions itself.
1444#
1445# These definitions are generic, but they are explicitly vendored to prevent
1446# other drivers from using them, as their semantics is defined in terms of the
1447# Midgard/Bifrost hardware tile buffer and may not line up with anything sane.
1448# One notable divergence is sRGB, which is asymmetric: raw_input_pan requires
1449# an sRGB->linear conversion, but linear values should be written to
1450# raw_output_pan and the hardware handles linear->sRGB.
1451#
1452# store_raw_output_pan is used only for blend shaders, and writes out only a
1453# single 128-bit chunk. To support multisampling, the BASE index specifies the
1454# bas sample index written out.
1455
1456# src[] = { value }
1457store("raw_output_pan", [], [IO_SEMANTICS, BASE])
1458store("combined_output_pan", [1, 1, 1, 4], [IO_SEMANTICS, COMPONENT, SRC_TYPE, DEST_TYPE])
1459load("raw_output_pan", [1], [IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1460
1461# Loads the sampler paramaters <min_lod, max_lod, lod_bias>
1462# src[] = { sampler_index }
1463load("sampler_lod_parameters_pan", [1], flags=[CAN_ELIMINATE, CAN_REORDER])
1464
1465# Like load_output but using a specified render target conversion descriptor
1466load("converted_output_pan", [1], indices=[DEST_TYPE, IO_SEMANTICS], flags=[CAN_ELIMINATE])
1467
1468# Load the render target conversion descriptor for a given render target given
1469# in the BASE index. Converts to a type with size given by the source type.
1470# Valid in fragment and blend stages.
1471system_value("rt_conversion_pan", 1, indices=[BASE, SRC_TYPE], bit_sizes=[32])
1472
1473# Loads the sample position array on Bifrost, in a packed Arm-specific format
1474system_value("sample_positions_pan", 1, bit_sizes=[64])
1475
1476# In a fragment shader, is the framebuffer single-sampled? 0/~0 bool
1477system_value("multisampled_pan", 1, bit_sizes=[32])
1478
1479# R600 specific instrincs
1480#
1481# location where the tesselation data is stored in LDS
1482system_value("tcs_in_param_base_r600", 4)
1483system_value("tcs_out_param_base_r600", 4)
1484system_value("tcs_rel_patch_id_r600", 1)
1485system_value("tcs_tess_factor_base_r600", 1)
1486
1487# load as many components as needed giving per-component addresses
1488intrinsic("load_local_shared_r600", src_comp=[0], dest_comp=0, indices = [], flags = [CAN_ELIMINATE])
1489
1490store("local_shared_r600", [1], [WRITE_MASK])
1491store("tf_r600", [])
1492
1493# AMD GCN/RDNA specific intrinsics
1494
1495# This barrier is a hint that prevents moving the instruction that computes
1496# src after this barrier. It's a constraint for the instruction scheduler.
1497# Otherwise it's identical to a move instruction.
1498# The VGPR version forces the src value to be stored in a VGPR, while the SGPR
1499# version enforces an SGPR.
1500intrinsic("optimization_barrier_vgpr_amd", dest_comp=0, src_comp=[0],
1501          flags=[CAN_ELIMINATE])
1502intrinsic("optimization_barrier_sgpr_amd", dest_comp=0, src_comp=[0],
1503          flags=[CAN_ELIMINATE])
1504
1505# These are no-op intrinsics used as a simple source and user of SSA defs for testing.
1506intrinsic("unit_test_amd", src_comp=[0], indices=[BASE])
1507intrinsic("unit_test_uniform_amd", dest_comp=0, indices=[BASE])
1508intrinsic("unit_test_divergent_amd", dest_comp=0, indices=[BASE])
1509
1510# Untyped buffer load/store instructions of arbitrary length.
1511# src[] = { descriptor, vector byte offset, scalar byte offset, index offset }
1512# The index offset is multiplied by the stride in the descriptor.
1513# The vector/scalar offsets are in bytes, BASE is a constant byte offset.
1514intrinsic("load_buffer_amd", src_comp=[4, 1, 1, 1], dest_comp=0, indices=[BASE, MEMORY_MODES, ACCESS], flags=[CAN_ELIMINATE])
1515# src[] = { store value, descriptor, vector byte offset, scalar byte offset, index offset }
1516intrinsic("store_buffer_amd", src_comp=[0, 4, 1, 1, 1], indices=[BASE, WRITE_MASK, MEMORY_MODES, ACCESS])
1517
1518# Typed buffer load of arbitrary length, using a specified format.
1519# src[] = { descriptor, vector byte offset, scalar byte offset, index offset }
1520#
1521# The compiler backend is responsible for emitting correct HW instructions according to alignment, range etc.
1522# Users of this intrinsic must ensure that the first component being loaded is really the first component
1523# of the specified format, because range analysis assumes this.
1524# The size of the specified format also determines the memory range that this instruction is allowed to access.
1525#
1526# The index offset is multiplied by the stride in the descriptor, if any.
1527# The vector/scalar offsets are in bytes, BASE is a constant byte offset.
1528intrinsic("load_typed_buffer_amd", src_comp=[4, 1, 1, 1], dest_comp=0, indices=[BASE, MEMORY_MODES, ACCESS, FORMAT, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
1529
1530# src[] = { address, unsigned 32-bit offset }.
1531load("global_amd", [1, 1], indices=[BASE, ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
1532# src[] = { value, address, unsigned 32-bit offset }.
1533store("global_amd", [1, 1], indices=[BASE, ACCESS, ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK])
1534
1535# Same as shared_atomic_add, but with GDS. src[] = {store_val, gds_addr, m0}
1536intrinsic("gds_atomic_add_amd",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
1537
1538# Optimized shared_atomic_add (1/-1) with constant address
1539# returning the uniform pre-op value for all invocations.
1540intrinsic("shared_append_amd",  src_comp=[], dest_comp=1, bit_sizes=[32], indices=[BASE])
1541intrinsic("shared_consume_amd",  src_comp=[], dest_comp=1, bit_sizes=[32], indices=[BASE])
1542
1543# src[] = { sample_id, num_samples }
1544intrinsic("load_sample_positions_amd", src_comp=[1, 1], dest_comp=2, flags=[CAN_ELIMINATE, CAN_REORDER])
1545
1546# Descriptor where TCS outputs are stored for TES
1547system_value("ring_tess_offchip_amd", 4)
1548system_value("ring_tess_offchip_offset_amd", 1)
1549# Descriptor where TCS outputs are stored for the HW tessellator
1550system_value("ring_tess_factors_amd", 4)
1551system_value("ring_tess_factors_offset_amd", 1)
1552# Descriptor where ES outputs are stored for GS to read on GFX6-8
1553system_value("ring_esgs_amd", 4)
1554system_value("ring_es2gs_offset_amd", 1)
1555# Address of the task shader draw ring (used for VARYING_SLOT_TASK_COUNT)
1556system_value("ring_task_draw_amd", 4)
1557# Address of the task shader payload ring (used for all other outputs)
1558system_value("ring_task_payload_amd", 4)
1559# Address of the mesh shader scratch ring (used for excess mesh shader outputs)
1560system_value("ring_mesh_scratch_amd", 4)
1561system_value("ring_mesh_scratch_offset_amd", 1)
1562# Pointer into the draw and payload rings
1563system_value("task_ring_entry_amd", 1)
1564# Descriptor where NGG attributes are stored on GFX11.
1565system_value("ring_attr_amd", 4)
1566system_value("ring_attr_offset_amd", 1)
1567
1568# Load provoking vertex info
1569system_value("provoking_vtx_amd", 1)
1570
1571# Load rasterization primitive
1572system_value("rasterization_primitive_amd", 1);
1573
1574# Number of patches processed by each TCS workgroup
1575system_value("tcs_num_patches_amd", 1)
1576# Whether TCS should store tessellation level outputs for TES to read
1577system_value("tcs_tess_levels_to_tes_amd", dest_comp=1, bit_sizes=[1])
1578# Tessellation primitive mode for TCS
1579system_value("tcs_primitive_mode_amd", 1)
1580# Relative tessellation patch ID within the current workgroup
1581system_value("tess_rel_patch_id_amd", 1)
1582# Vertex offsets used for GS per-vertex inputs
1583system_value("gs_vertex_offset_amd", 1, [BASE])
1584# Number of rasterization samples
1585system_value("rasterization_samples_amd", 1)
1586
1587# Descriptor where GS outputs are stored for GS copy shader to read on GFX6-9
1588system_value("ring_gsvs_amd", 4, indices=[STREAM_ID])
1589# Write offset in gsvs ring for legacy GS shader
1590system_value("ring_gs2vs_offset_amd", 1)
1591
1592# Streamout configuration
1593system_value("streamout_config_amd", 1)
1594# Position to write within the streamout buffers
1595system_value("streamout_write_index_amd", 1)
1596# Offset to write within a streamout buffer
1597system_value("streamout_offset_amd", 1, indices=[BASE])
1598
1599# AMD merged shader intrinsics
1600
1601# Whether the current invocation index in the subgroup is less than the source. The source must be
1602# subgroup uniform and bits 0-7 must be less than or equal to the wave size.
1603intrinsic("is_subgroup_invocation_lt_amd", src_comp=[1], dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1604
1605# AMD NGG intrinsics
1606
1607# Number of initial input vertices in the current workgroup.
1608system_value("workgroup_num_input_vertices_amd", 1)
1609# Number of initial input primitives in the current workgroup.
1610system_value("workgroup_num_input_primitives_amd", 1)
1611# For NGG passthrough mode only. Pre-packed argument for export_primitive_amd.
1612system_value("packed_passthrough_primitive_amd", 1)
1613# Whether NGG should execute shader query for pipeline statistics.
1614system_value("pipeline_stat_query_enabled_amd", dest_comp=1, bit_sizes=[1])
1615# Whether NGG should execute shader query for primitive generated.
1616system_value("prim_gen_query_enabled_amd", dest_comp=1, bit_sizes=[1])
1617# Whether NGG should execute shader query for primitive streamouted.
1618system_value("prim_xfb_query_enabled_amd", dest_comp=1, bit_sizes=[1])
1619# 64-bit memory address to struct {uint32_t ordered_id; uint32_t dwords_written;}[4]
1620system_value("xfb_state_address_gfx12_amd", dest_comp=1, bit_sizes=[64])
1621# Merged wave info. Bits 0-7 are the ES thread count, 8-15 are the GS thread count, 16-24 is the
1622# GS Wave ID, 24-27 is the wave index in the workgroup, and 28-31 is the workgroup size in waves.
1623system_value("merged_wave_info_amd", dest_comp=1)
1624# Global ID for GS waves on GCN/RDNA legacy GS.
1625system_value("gs_wave_id_amd", dest_comp=1)
1626# Whether the shader should clamp vertex color outputs to [0, 1].
1627system_value("clamp_vertex_color_amd", dest_comp=1, bit_sizes=[1])
1628# Whether the shader should cull front facing triangles.
1629intrinsic("load_cull_front_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1630# Whether the shader should cull back facing triangles.
1631intrinsic("load_cull_back_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1632# True if face culling should use CCW (false if CW).
1633intrinsic("load_cull_ccw_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1634# Whether the shader should cull small primitives that are not visible in a pixel.
1635intrinsic("load_cull_small_primitives_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1636# Whether any culling setting is enabled in the shader.
1637intrinsic("load_cull_any_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1638# Small primitive culling precision
1639intrinsic("load_cull_small_prim_precision_amd", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
1640# Initial edge flags in a Vertex Shader, packed into the format the HW needs for primitive export.
1641intrinsic("load_initial_edgeflags_amd", src_comp=[], dest_comp=1, bit_sizes=[32], indices=[])
1642# Corresponds to s_sendmsg in the GCN/RDNA ISA, src[] = { m0_content }, BASE = imm
1643intrinsic("sendmsg_amd", src_comp=[1], indices=[BASE])
1644# Overwrites VS input registers, for use with vertex compaction after culling. src = {vertex_id, instance_id}.
1645intrinsic("overwrite_vs_arguments_amd", src_comp=[1, 1], indices=[])
1646# Overwrites TES input registers, for use with vertex compaction after culling. src = {tes_u, tes_v, rel_patch_id, patch_id}.
1647intrinsic("overwrite_tes_arguments_amd", src_comp=[1, 1, 1, 1], indices=[])
1648
1649# The address of the sbt descriptors.
1650system_value("sbt_base_amd", 1, bit_sizes=[64])
1651
1652# 1. HW descriptor
1653# 2. BVH node(64-bit pointer as 2x32 ...)
1654# 3. ray extent
1655# 4. ray origin
1656# 5. ray direction
1657# 6. inverse ray direction (componentwise 1.0/ray direction)
1658intrinsic("bvh64_intersect_ray_amd", [4, 2, 1, 3, 3, 3], 4, flags=[CAN_ELIMINATE, CAN_REORDER])
1659
1660# Return of a callable in raytracing pipelines
1661intrinsic("rt_return_amd")
1662
1663# offset into scratch for the input callable data in a raytracing pipeline.
1664system_value("rt_arg_scratch_offset_amd", 1)
1665
1666# Whether to call the anyhit shader for an intersection in an intersection shader.
1667system_value("intersection_opaque_amd", 1, bit_sizes=[1])
1668
1669# pointer to the next resume shader
1670system_value("resume_shader_address_amd", 1, bit_sizes=[64], indices=[CALL_IDX])
1671
1672# Ray Tracing Traversal inputs
1673system_value("sbt_offset_amd", 1)
1674system_value("sbt_stride_amd", 1)
1675system_value("accel_struct_amd", 1, bit_sizes=[64])
1676system_value("cull_mask_and_flags_amd", 1)
1677
1678#   0. SBT Index
1679#   1. Ray Tmax
1680#   2. Primitive Id
1681#   3. Instance Addr
1682#   4. Geometry Id and Flags
1683#   5. Hit Kind
1684intrinsic("execute_closest_hit_amd", src_comp=[1, 1, 1, 1, 1, 1])
1685
1686#   0. Ray Tmax
1687intrinsic("execute_miss_amd", src_comp=[1])
1688
1689# Used for saving and restoring hit attribute variables.
1690# BASE=dword index
1691intrinsic("load_hit_attrib_amd", dest_comp=1, bit_sizes=[32], indices=[BASE])
1692intrinsic("store_hit_attrib_amd", src_comp=[1], indices=[BASE])
1693
1694# Load forced VRS rates.
1695intrinsic("load_force_vrs_rates_amd", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
1696
1697intrinsic("load_scalar_arg_amd", dest_comp=0, bit_sizes=[32],
1698          indices=[BASE, ARG_UPPER_BOUND_U32_AMD],
1699          flags=[CAN_ELIMINATE, CAN_REORDER])
1700intrinsic("load_vector_arg_amd", dest_comp=0, bit_sizes=[32],
1701          indices=[BASE, ARG_UPPER_BOUND_U32_AMD, FLAGS],
1702          flags=[CAN_ELIMINATE, CAN_REORDER])
1703store("scalar_arg_amd", [], [BASE])
1704store("vector_arg_amd", [], [BASE])
1705
1706# src[] = { 32/64-bit base address, 32-bit offset }.
1707#
1708# Similar to load_global_constant, the memory accessed must be read-only. This
1709# restriction justifies the CAN_REORDER flag. Additionally, the base/offset must
1710# be subgroup uniform.
1711intrinsic("load_smem_amd", src_comp=[1, 1], dest_comp=0, bit_sizes=[32],
1712                           indices=[ALIGN_MUL, ALIGN_OFFSET],
1713                           flags=[CAN_ELIMINATE, CAN_REORDER])
1714
1715# src[] = { offset }.
1716intrinsic("load_shared2_amd", [1], dest_comp=2, indices=[OFFSET0, OFFSET1, ST64], flags=[CAN_ELIMINATE])
1717
1718# src[] = { value, offset }.
1719intrinsic("store_shared2_amd", [2, 1], indices=[OFFSET0, OFFSET1, ST64])
1720
1721# Vertex stride in LS-HS buffer
1722system_value("lshs_vertex_stride_amd", 1)
1723
1724# Vertex stride in ES-GS buffer
1725system_value("esgs_vertex_stride_amd", 1)
1726
1727# Per patch data offset in HS VRAM output buffer
1728system_value("hs_out_patch_data_offset_amd", 1)
1729
1730# line_width * 0.5 / abs(viewport_scale[2])
1731system_value("clip_half_line_width_amd", 2)
1732
1733# Number of vertices in a primitive
1734system_value("num_vertices_per_primitive_amd", 1)
1735
1736# Load streamout buffer desc
1737# BASE = buffer index
1738intrinsic("load_streamout_buffer_amd", dest_comp=4, indices=[BASE], bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
1739
1740# An ID for each workgroup ordered by primitve sequence
1741system_value("ordered_id_amd", 1)
1742
1743# Add src1 to global streamout buffer offsets in the specified order.
1744# Only 1 lane must be active.
1745# src[] = { ordered_id, counter }
1746# WRITE_MASK = mask for counter channel to update
1747intrinsic("ordered_xfb_counter_add_gfx11_amd", dest_comp=0, src_comp=[1, 0], indices=[WRITE_MASK], bit_sizes=[32])
1748
1749# Execute the atomic ordered add loop. This does what ds_ordered_count did in previous generations.
1750# This is implemented with inline assembly to get the most optimal code.
1751#
1752# Inputs:
1753#   exec = one lane per counter (use nir_push_if, streamout should always enable 4 lanes)
1754#   src[0] = 64-bit SGPR atomic base address (streamout should use nir_load_xfb_state_address_gfx12_amd)
1755#   src[1] = 32-bit VGPR voffset (streamout should set local_invocation_index * 8)
1756#   src[2] = 32-bit SGPR ordered_id (use nir_load_ordered_id_amd for streamout, compute shaders
1757#            should generated it manually)
1758#   src[3] = 64-bit VGPR atomic src, use pack_64_2x32_split(ordered_id, value), streamout should do:
1759#            pack_64_2x32_split(ordered_id, "dwords written per workgroup" for each buffer)
1760#
1761# dst = 32-bit VGPR of the previous value of 32-bit value in memory, returned for all enabled lanes
1762
1763# Example - streamout: It's used to add dwords_written[] to global streamout offsets.
1764# * Exactly 4 lanes must be active, one for each buffer binding.
1765# * Disabled buffers must set dwords_written=0 for their lane, but the lane
1766#   must be enabled.
1767#
1768intrinsic("ordered_add_loop_gfx12_amd", dest_comp=1, src_comp=[1, 1, 1, 1], bit_sizes=[32])
1769
1770# Subtract from global streamout buffer offsets. Used to fix up the offsets
1771# when we overflow streamout buffers.
1772# src[] = { offsets }
1773# WRITE_MASK = mask of offsets to subtract
1774intrinsic("xfb_counter_sub_gfx11_amd", src_comp=[0], indices=[WRITE_MASK], bit_sizes=[32])
1775
1776# Provoking vertex index in a primitive
1777system_value("provoking_vtx_in_prim_amd", 1)
1778
1779# Atomically add current wave's primitive count to query result
1780#   * GS emitted primitive is primitive emitted by any GS stream
1781#   * generated primitive is primitive that has been produced for that stream by VS/TES/GS
1782#   * streamout primitve is primitve that has been written to xfb buffer, may be different
1783#     than generated primitive when xfb buffer is too small to hold more primitives
1784# src[] = { primitive_count }.
1785intrinsic("atomic_add_gs_emit_prim_count_amd", [1])
1786intrinsic("atomic_add_gen_prim_count_amd", [1], indices=[STREAM_ID])
1787intrinsic("atomic_add_xfb_prim_count_amd", [1], indices=[STREAM_ID])
1788
1789# Atomically add current shader's invocation count to query result
1790# src[] = { invocation_count }.
1791intrinsic("atomic_add_shader_invocation_count_amd", [1])
1792
1793# LDS offset for scratch section in NGG shader
1794system_value("lds_ngg_scratch_base_amd", 1)
1795# LDS offset for NGG GS shader vertex emit
1796system_value("lds_ngg_gs_out_vertex_base_amd", 1)
1797
1798# AMD GPU shader output export instruction
1799# src[] = { export_value, row }
1800# BASE = export target
1801# FLAGS = AC_EXP_FLAG_*
1802intrinsic("export_amd", [0], indices=[BASE, WRITE_MASK, FLAGS])
1803intrinsic("export_row_amd", [0, 1], indices=[BASE, WRITE_MASK, FLAGS])
1804
1805# Export dual source blend outputs with swizzle operation
1806# src[] = { mrt0, mrt1 }
1807intrinsic("export_dual_src_blend_amd", [0, 0], indices=[WRITE_MASK])
1808
1809# Alpha test reference value
1810system_value("alpha_reference_amd", 1)
1811
1812# Whether to enable barycentric optimization
1813system_value("barycentric_optimize_amd", dest_comp=1, bit_sizes=[1])
1814
1815# Copy the input into a register which will remain valid for entire quads, even in control flow.
1816# This should only be used directly for texture sources.
1817intrinsic("strict_wqm_coord_amd", src_comp=[0], dest_comp=0, bit_sizes=[32], indices=[BASE],
1818          flags=[CAN_ELIMINATE])
1819
1820intrinsic("cmat_muladd_amd", src_comp=[16, 16, 0], dest_comp=0, bit_sizes=src2,
1821          indices=[SATURATE, CMAT_SIGNED_MASK], flags=[CAN_ELIMINATE])
1822
1823# Get the debug log buffer descriptor.
1824intrinsic("load_debug_log_desc_amd", bit_sizes=[32], dest_comp=4, flags=[CAN_ELIMINATE, CAN_REORDER])
1825
1826# s_sleep BASE (sleep for 64*BASE cycles). BASE must be in [0, 0xffff].
1827# BASE=0 is valid but isn't useful.
1828# GFX12+: If BASE & 0x8000, sleep forever (until wakeup, trap, or kill).
1829intrinsic("sleep_amd", indices=[BASE])
1830
1831# s_nop BASE (sleep for BASE+1 cycles, BASE must be in [0, 15]).
1832intrinsic("nop_amd", indices=[BASE])
1833
1834system_value("ray_tracing_stack_base_lvp", 1)
1835
1836system_value("shader_call_data_offset_lvp", 1)
1837
1838# Broadcom-specific instrinc for tile buffer color reads.
1839#
1840# The hardware requires that we read the samples and components of a pixel
1841# in order, so we cannot eliminate or remove any loads in a sequence.
1842#
1843# src[] = { render_target }
1844# BASE = sample index
1845load("tlb_color_brcm", [1], [BASE, COMPONENT], [])
1846
1847# V3D-specific instrinc for per-sample tile buffer color writes.
1848#
1849# The driver backend needs to identify per-sample color writes and emit
1850# specific code for them.
1851#
1852# src[] = { value, render_target }
1853# BASE = sample index
1854store("tlb_sample_color_v3d", [1], [BASE, COMPONENT, SRC_TYPE], [])
1855
1856# V3D-specific intrinsic to load the number of layers attached to
1857# the target framebuffer
1858intrinsic("load_fb_layers_v3d", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
1859
1860# V3D-specific intrinsic to load W coordinate from the fragment shader payload
1861intrinsic("load_fep_w_v3d", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
1862
1863# Active invocation index within the subgroup.
1864# Equivalent to popcount(ballot(true) & ((1 << subgroup_invocation) - 1))
1865intrinsic("load_active_subgroup_invocation_agx", dest_comp=1, flags=[CAN_ELIMINATE])
1866
1867# Total active invocations within the subgroup.
1868# Equivalent to popcount(ballot(true))
1869intrinsic("load_active_subgroup_count_agx", dest_comp=1, flags=[CAN_ELIMINATE])
1870
1871# Like ballot() but only within a quad.
1872intrinsic("quad_ballot_agx", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
1873
1874# With [0, 1] clipping, no transform is needed on the output z' = z. But with [-1,
1875# 1] clipping, we need to transform z' = (z + w) / 2. We express both cases as a
1876# lerp between z and w, where this is the lerp coefficient: 0 for [0, 1] and 0.5
1877# for [-1, 1].
1878system_value("clip_z_coeff_agx", 1)
1879
1880# True if drawing triangle fans with first vertex provoking, false otherwise.
1881# This affects flatshading, which is defined weirdly for fans with first.
1882system_value("is_first_fan_agx", 1, bit_sizes=[1])
1883
1884# mesa_prim for the input topology (in a geometry shader)
1885system_value("input_topology_agx", 1)
1886
1887# Load a bindless sampler handle mapping a binding table sampler.
1888intrinsic("load_sampler_handle_agx", [1], 1, [],
1889          flags=[CAN_ELIMINATE, CAN_REORDER],
1890          bit_sizes=[16])
1891
1892# Load a bindless texture handle mapping a binding table texture.
1893intrinsic("load_texture_handle_agx", [1], 2, [],
1894          flags=[CAN_ELIMINATE, CAN_REORDER],
1895          bit_sizes=[32])
1896
1897# Given a vec2 bindless texture handle, load the address of the texture
1898# descriptor described by that vec2. This allows inspecting the descriptor from
1899# the shader. This does not actually load the content of the descriptor, only
1900# the content of the handle (which is the address of the descriptor).
1901intrinsic("load_from_texture_handle_agx", [2], 1, [],
1902          flags=[CAN_ELIMINATE, CAN_REORDER],
1903          bit_sizes=[64])
1904
1905# Load the coefficient register corresponding to a given fragment shader input.
1906# Coefficient registers are vec3s that are dotted with <x, y, 1> to interpolate
1907# the input, where x and y are relative to the 32x32 supertile.
1908intrinsic("load_coefficients_agx", [1],
1909          bit_sizes = [32],
1910          dest_comp = 3,
1911          indices=[COMPONENT, IO_SEMANTICS, INTERP_MODE],
1912          flags=[CAN_ELIMINATE, CAN_REORDER])
1913
1914# src[] = { value, index }
1915# Store a vertex shader output to the Unified Vertex Store (UVS). Indexed by UVS
1916# index, which must be assigned by the driver based on the linked fragment
1917# shader's interpolation qualifiers. This corresponds to the native instruction.
1918store("uvs_agx", [1], [], [CAN_REORDER])
1919
1920# Driver intrinsic to map a location to a UVS index. This is generated when
1921# lowering store_output to store_uvs_agx, and must be lowered by the driver.
1922intrinsic("load_uvs_index_agx", dest_comp = 1, bit_sizes=[16],
1923          indices=[IO_SEMANTICS], flags=[CAN_ELIMINATE, CAN_REORDER])
1924
1925# Load/store a pixel in local memory. This operation is formatted, with
1926# conversion between the specified format and the implied register format of the
1927# source/destination (for store/loads respectively). This mostly matters for
1928# converting between floating-point registers and normalized memory formats.
1929#
1930# The format is the pipe_format of the local memory (the source), see
1931# ail for the supported list.
1932#
1933# Logically, this loads/stores a single sample. The sample to load is
1934# specified by the bitfield sample mask source. However, for stores multiple
1935# bits of the sample mask may be set, which will replicate the value. For
1936# pixel rate shading, use 0xFF as the mask to store to all samples regardless of
1937# the sample count.
1938#
1939# All calculations are relative to an immediate byte offset into local
1940# memory, which acts relative to the start of the sample. These instructions
1941# logically access:
1942#
1943#   (((((y * tile_width) + x) * nr_samples) + sample) * sample_stride) + offset
1944#
1945# src[] = { sample mask }
1946# base = offset
1947load("local_pixel_agx", [1], [BASE, FORMAT], [CAN_REORDER, CAN_ELIMINATE])
1948# src[] = { value, sample mask, coordinates }
1949# base = offset
1950store("local_pixel_agx", [1, -1], [BASE, WRITE_MASK, FORMAT, EXPLICIT_COORD], [CAN_REORDER])
1951
1952# Combined depth/stencil emit, applying to a mask of samples. base indicates
1953# which to write (1 = depth, 2 = stencil, 3 = both).
1954#
1955# src[] = { sample mask, depth, stencil }
1956intrinsic("store_zs_agx", [1, 1, 1], indices=[BASE], flags=[])
1957
1958# Store a block from local memory into a bound image. Used to write out render
1959# targets within the end-of-tile shader, although it is valid in general compute
1960# kernels.
1961#
1962# The format is the pipe_format of the local memory (the source), see
1963# ail for the supported list. The image format is
1964# specified in the PBE descriptor.
1965#
1966# The image dimension is used to distinguish multisampled images from
1967# non-multisampled images. It must be 2D or MS.
1968#
1969# extra src[] = { logical offset within shared memory, coordinates/layer }
1970image("store_block_agx", [1, -1], extra_indices=[EXPLICIT_COORD])
1971
1972# Formatted load/store. The format is the pipe_format in memory (see ail for the
1973# supported list). This accesses:
1974#
1975#     address + extend(index) << (format shift + shift)
1976#
1977# The nir_intrinsic_base() index encodes the shift. The sign_extend index
1978# determines whether sign- or zero-extension is used for the index.
1979#
1980# All loads and stores on AGX uses these hardware instructions, so while these are
1981# logically load_global_agx/load_global_constant_agx/store_global_agx, the
1982# _global is omitted as it adds nothing.
1983#
1984# src[] = { address, index }.
1985load("agx", [1, 1], [ACCESS, BASE, FORMAT, SIGN_EXTEND], [CAN_ELIMINATE])
1986load("constant_agx", [1, 1], [ACCESS, BASE, FORMAT, SIGN_EXTEND],
1987     [CAN_ELIMINATE, CAN_REORDER])
1988# src[] = { value, address, index }.
1989store("agx", [1, 1], [ACCESS, BASE, FORMAT, SIGN_EXTEND])
1990
1991# Logical complement of load_front_face, mapping to an AGX system value
1992system_value("back_face_agx", 1, bit_sizes=[1, 32])
1993
1994# Load the base address of an indexed vertex attribute (for lowering).
1995intrinsic("load_vbo_base_agx", src_comp=[1], dest_comp=1, bit_sizes=[64],
1996          flags=[CAN_ELIMINATE, CAN_REORDER])
1997
1998# When vertex robustness is enabled, loads the maximum valid attribute index for
1999# a given attribute. This is unsigned: the driver ensures that at least one
2000# vertex is always valid to load, directing loads to a zero sink if necessary.
2001intrinsic("load_attrib_clamp_agx", src_comp=[1], dest_comp=1,
2002          bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
2003
2004# Load a driver-internal system value from a given system value set at a given
2005# binding within the set. This is used for correctness when lowering things like
2006# UBOs with merged shaders.
2007#
2008# The FLAGS are used internally for loading the index of the uniform itself,
2009# rather than the contents, used for lowering bindless handles (which encode
2010# uniform indices as immediates in the NIR for technical reasons).
2011load("sysval_agx", [], [DESC_SET, BINDING, FLAGS], [CAN_REORDER, CAN_ELIMINATE])
2012
2013# Write out a sample mask for a targeted subset of samples, specified in the two
2014# masks. Maps to the corresponding AGX instruction, the actual workings are
2015# documented elsewhere as they are too complicated for this comment.
2016intrinsic("sample_mask_agx", src_comp=[1, 1])
2017
2018# Discard a subset of samples given by a specified sample mask. This acts like a
2019# per-sample discard, or an inverted accumulating gl_SampleMask write. The
2020# compiler will lower to sample_mask_agx, but that lowering is nontrivial as
2021# sample_mask_agx also triggers depth/stencil testing.
2022intrinsic("discard_agx", src_comp=[1])
2023
2024# For a given row of the polygon stipple given as an integer source in [0, 31],
2025# load the 32-bit stipple pattern for that row.
2026intrinsic("load_polygon_stipple_agx", src_comp=[1], dest_comp=1, bit_sizes=[32],
2027          flags=[CAN_ELIMINATE, CAN_ELIMINATE])
2028
2029# The fixed-function sample mask specified in the API (e.g. glSampleMask)
2030system_value("api_sample_mask_agx", 1, bit_sizes=[16])
2031
2032# Bit mask of samples currently being shaded. For API-level sample shading, this
2033# will usually equal (1 << sample_id). Multiple bits can be set when sample
2034# shading is only enabled due to framebuffer fetch, and the framebuffer has
2035# multiple samples with the same value.
2036#
2037# Used as a loop variable with dynamic sample shading.
2038system_value("active_samples_agx", 1, bit_sizes=[16])
2039
2040# Loads the sample position array as fixed point packed into a 32-bit word
2041system_value("sample_positions_agx", 1, bit_sizes=[32])
2042
2043# In a non-monolithic fragment shader part, returns whether this shader part is
2044# responsible for Z/S testing after its final discard. ~0/0 boolean.
2045system_value("shader_part_tests_zs_agx", 1, bit_sizes=[16])
2046
2047# Returns whether the API depth test is NEVER. We emulate this in shader when
2048# fragment side effects are used to ensure the fragment shader executes.
2049system_value("depth_never_agx", 1, bit_sizes=[16])
2050
2051# In a fragment shader, returns the log2 of the number of samples in the
2052# tilebuffer. This is the unprocessed value written in the corresponding USC
2053# word. Used to determine whether sample mask writes have any effect when sample
2054# count is dynamic.
2055system_value("samples_log2_agx", 1, bit_sizes=[16])
2056
2057# Loads the fixed-function glPointSize() value, or zero if the
2058# shader-supplied value should be used.
2059system_value("fixed_point_size_agx", 1, bit_sizes=[32])
2060
2061# Bit mask of TEX locations that are replaced with point sprites
2062system_value("tex_sprite_mask_agx", 1, bit_sizes=[16])
2063
2064# Image loads go through the texture cache, which is not coherent with the PBE
2065# or memory access, so fencing is necessary for writes to become visible.
2066
2067# Make writes via main memory (image atomics) visible for texturing.
2068barrier("fence_pbe_to_tex_agx")
2069
2070# Make writes from global memory instructions (atomics) visible for texturing.
2071barrier("fence_mem_to_tex_agx")
2072
2073# Variant of fence_pbe_to_tex_agx specialized to stores in pixel shaders that
2074# act like render target writes, in conjunction with fragment interlock.
2075barrier("fence_pbe_to_tex_pixel_agx")
2076
2077# Unknown fence used in the helper program on exit.
2078barrier("fence_helper_exit_agx")
2079
2080# Pointer to the buffer passing outputs VS->TCS, VS->GS, or TES->GS linkage.
2081system_value("vs_output_buffer_agx", 1, bit_sizes=[64])
2082
2083# Mask of VS->TCS, VS->GS, or TES->GS outputs. This is modelled as a sysval
2084# directly so it can be dynamic with shader objects or constant folded with
2085# pipelines (including GPL)
2086system_value("vs_outputs_agx", 1, bit_sizes=[64])
2087
2088# Address of state for AGX input assembly lowering for geometry/tessellation
2089system_value("input_assembly_buffer_agx", 1, bit_sizes=[64])
2090
2091# Address of the parameter buffer for AGX geometry shaders
2092system_value("geometry_param_buffer_agx", 1, bit_sizes=[64])
2093
2094# Address of the parameter buffer for AGX tessellation shaders
2095system_value("tess_param_buffer_agx", 1, bit_sizes=[64])
2096
2097# Address of the pipeline statistic query result indexed by BASE
2098system_value("stat_query_address_agx", 1, bit_sizes=[64], indices=[BASE])
2099
2100# Helper shader intrinsics
2101# src[] = { value }.
2102intrinsic("doorbell_agx", src_comp=[1])
2103
2104# src[] = { index, stack_address }.
2105intrinsic("stack_map_agx", src_comp=[1, 1])
2106
2107# src[] = { index }.
2108# dst[] = { stack_address }.
2109intrinsic("stack_unmap_agx", src_comp=[1], dest_comp=1, bit_sizes=[32])
2110
2111# dst[] = { GPU core ID }.
2112system_value("core_id_agx", 1, bit_sizes=[32])
2113
2114# dst[] = { Helper operation type }.
2115load("helper_op_id_agx", [], [], [CAN_ELIMINATE])
2116
2117# dst[] = { Helper argument low 32 bits }.
2118load("helper_arg_lo_agx", [], [], [CAN_ELIMINATE])
2119
2120# dst[] = { Helper argument high 32 bits }.
2121load("helper_arg_hi_agx", [], [], [CAN_ELIMINATE])
2122
2123# Export a vector. At the end of the shader part, the source is copied to the
2124# indexed GPRs starting at BASE. Exports must not overlap within a shader part.
2125# Must only appear in the last block of the shader part.
2126intrinsic("export_agx", [0], indices=[BASE])
2127
2128# Load an exported vector at the beginning of the shader part from GPRs starting
2129# at BASE. Must only appear in the first block of the shader part.
2130load("exported_agx", [], [BASE], [CAN_ELIMINATE])
2131
2132# Intel-specific query for loading from the isl_image_param struct passed
2133# into the shader as a uniform.  The variable is a deref to the image
2134# variable. The const index specifies which of the six parameters to load.
2135intrinsic("image_deref_load_param_intel", src_comp=[1], dest_comp=0,
2136          indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
2137image("load_raw_intel", src_comp=[1], dest_comp=0,
2138      flags=[CAN_ELIMINATE])
2139image("store_raw_intel", src_comp=[1, 0])
2140
2141# Number of data items being operated on for a SIMD program.
2142system_value("simd_width_intel", 1)
2143
2144# Load a relocatable 32-bit value
2145intrinsic("load_reloc_const_intel", dest_comp=1, bit_sizes=[32],
2146          indices=[PARAM_IDX, BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
2147
2148# 1 component 32bit surface index that can be used for bindless or BTI heaps
2149#
2150# This intrinsic is used to figure out what UBOs accesses could be promoted to
2151# push constants. To allow promoting a load_ubo to push constants, we need to
2152# know that the surface & offset are constants. If we want to use the bindless
2153# heap for this we have to build the surface index with a pushed constant for
2154# the descriptor set which prevents us from doing a nir_src_is_const() check.
2155# With this intrinsic, we can just check the surface_index src with
2156# nir_src_is_const() and ignore set_offset.
2157#
2158# src[] = { set_offset, surface_index, array_index, bindless_base_offset }
2159intrinsic("resource_intel", dest_comp=1, bit_sizes=[32],
2160          src_comp=[1, 1, 1, 1],
2161          indices=[DESC_SET, BINDING, RESOURCE_ACCESS_INTEL, RESOURCE_BLOCK_INTEL],
2162          flags=[CAN_ELIMINATE, CAN_REORDER])
2163
2164# OpSubgroupBlockReadINTEL and OpSubgroupBlockWriteINTEL from SPV_INTEL_subgroups.
2165intrinsic("load_deref_block_intel", dest_comp=0, src_comp=[-1],
2166          indices=[ACCESS], flags=[CAN_ELIMINATE])
2167intrinsic("store_deref_block_intel", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])
2168
2169# src[] = { address }.
2170load("global_block_intel", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
2171
2172# src[] = { buffer_index, offset }.
2173load("ssbo_block_intel", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
2174
2175# src[] = { offset }.
2176load("shared_block_intel", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
2177
2178# src[] = { value, address }.
2179store("global_block_intel", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
2180
2181# src[] = { value, block_index, offset }
2182store("ssbo_block_intel", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
2183
2184# src[] = { value, offset }.
2185store("shared_block_intel", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
2186
2187# src[] = { address }.
2188load("global_constant_uniform_block_intel", [1],
2189     [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE, CAN_REORDER])
2190
2191# Similar to load_global_const_block_intel but for UBOs
2192# offset should be uniform
2193# src[] = { buffer_index, offset }.
2194load("ubo_uniform_block_intel", [-1, 1],
2195     [ACCESS, ALIGN_MUL, ALIGN_OFFSET, RANGE_BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
2196
2197# Similar to load_global_const_block_intel but for SSBOs
2198# offset should be uniform
2199# src[] = { buffer_index, offset }.
2200load("ssbo_uniform_block_intel", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
2201
2202# Similar to load_global_const_block_intel but for shared memory
2203# src[] = { offset }.
2204load("shared_uniform_block_intel", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
2205
2206# Intrinsics for Intel mesh shading
2207system_value("mesh_inline_data_intel", 1, [ALIGN_OFFSET], bit_sizes=[32, 64])
2208
2209# Intrinsics for Intel bindless thread dispatch
2210# BASE=brw_topoloy_id
2211system_value("topology_id_intel", 1, indices=[BASE])
2212system_value("btd_stack_id_intel", 1)
2213system_value("btd_global_arg_addr_intel", 1, bit_sizes=[64])
2214system_value("btd_local_arg_addr_intel", 1, bit_sizes=[64])
2215system_value("btd_resume_sbt_addr_intel", 1, bit_sizes=[64])
2216# src[] = { global_arg_addr, btd_record }
2217intrinsic("btd_spawn_intel", src_comp=[1, 1])
2218# RANGE=stack_size
2219intrinsic("btd_stack_push_intel", indices=[STACK_SIZE])
2220# src[] = { }
2221intrinsic("btd_retire_intel")
2222
2223# Intel-specific ray-tracing intrinsic
2224# src[] = { globals, level, operation } SYNCHRONOUS=synchronous
2225intrinsic("trace_ray_intel", src_comp=[1, 1, 1], indices=[SYNCHRONOUS])
2226
2227# System values used for ray-tracing on Intel
2228system_value("ray_base_mem_addr_intel", 1, bit_sizes=[64])
2229system_value("ray_hw_stack_size_intel", 1)
2230system_value("ray_sw_stack_size_intel", 1)
2231system_value("ray_num_dss_rt_stacks_intel", 1)
2232system_value("ray_hit_sbt_addr_intel", 1, bit_sizes=[64])
2233system_value("ray_hit_sbt_stride_intel", 1, bit_sizes=[16])
2234system_value("ray_miss_sbt_addr_intel", 1, bit_sizes=[64])
2235system_value("ray_miss_sbt_stride_intel", 1, bit_sizes=[16])
2236system_value("callable_sbt_addr_intel", 1, bit_sizes=[64])
2237system_value("callable_sbt_stride_intel", 1, bit_sizes=[16])
2238system_value("leaf_opaque_intel", 1, bit_sizes=[1])
2239system_value("leaf_procedural_intel", 1, bit_sizes=[1])
2240# Values :
2241#  0: AnyHit
2242#  1: ClosestHit
2243#  2: Miss
2244#  3: Intersection
2245system_value("btd_shader_type_intel", 1)
2246system_value("ray_query_global_intel", 1, bit_sizes=[64])
2247
2248# Source 0: Accumulator matrix (type specified by DEST_TYPE)
2249# Source 1: A matrix (type specified by SRC_TYPE)
2250# Source 2: B matrix (type specified by SRC_TYPE)
2251#
2252# The matrix parameters are the slices owned by the invocation.
2253#
2254# The accumulator is source 0 because that is the source the intrinsic
2255# infrastructure in NIR uses to determine the number of components in the
2256# result.
2257#
2258# The number of components for the second source is -1 to avoid validation of
2259# its value. Some supported configurations will have the component count of
2260# that matrix different than the others.
2261intrinsic("dpas_intel", dest_comp=0, src_comp=[0, -1, 0],
2262          indices=[DEST_TYPE, SRC_TYPE, SATURATE, SYSTOLIC_DEPTH, REPEAT_COUNT],
2263          flags=[CAN_ELIMINATE])
2264
2265# NVIDIA-specific intrinsics
2266# src[] = { index, offset }.
2267intrinsic("ldc_nv", dest_comp=0, src_comp=[1, 1],
2268          indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET],
2269          flags=[CAN_ELIMINATE, CAN_REORDER])
2270# [Un]pins an LDCX handle around non-uniform control-flow sections
2271# src[] = { handle }.
2272intrinsic("pin_cx_handle_nv", src_comp=[1])
2273intrinsic("unpin_cx_handle_nv", src_comp=[1])
2274# src[] = { handle, offset }.
2275intrinsic("ldcx_nv", dest_comp=0, src_comp=[1, 1],
2276          indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET],
2277          flags=[CAN_ELIMINATE, CAN_REORDER])
2278intrinsic("load_sysval_nv", dest_comp=1, src_comp=[], bit_sizes=[32, 64],
2279          indices=[ACCESS, BASE], flags=[CAN_ELIMINATE])
2280intrinsic("isberd_nv", dest_comp=1, src_comp=[1], bit_sizes=[32],
2281          flags=[CAN_ELIMINATE, CAN_REORDER])
2282intrinsic("al2p_nv", dest_comp=1, src_comp=[1], bit_sizes=[32],
2283          indices=[BASE, FLAGS], flags=[CAN_ELIMINATE, CAN_REORDER])
2284# src[] = { vtx, offset }.
2285# FLAGS is struct nak_nir_attr_io_flags
2286intrinsic("ald_nv", dest_comp=0, src_comp=[1, 1], bit_sizes=[32],
2287          indices=[BASE, RANGE_BASE, RANGE, FLAGS, ACCESS],
2288          flags=[CAN_ELIMINATE])
2289# src[] = { data, vtx, offset }.
2290# FLAGS is struct nak_nir_attr_io_flags
2291intrinsic("ast_nv", src_comp=[0, 1, 1],
2292          indices=[BASE, RANGE_BASE, RANGE, FLAGS], flags=[])
2293# src[] = { inv_w, offset }.
2294intrinsic("ipa_nv", dest_comp=1, src_comp=[1, 1], bit_sizes=[32],
2295          indices=[BASE, FLAGS], flags=[CAN_ELIMINATE, CAN_REORDER])
2296# FLAGS indicate if we load vertex_id == 2
2297intrinsic("ldtram_nv", dest_comp=2, bit_sizes=[32],
2298          indices=[BASE, FLAGS], flags=[CAN_ELIMINATE, CAN_REORDER])
2299
2300# NVIDIA-specific Geometry Shader intrinsics.
2301# These contain an additional integer source and destination with the primitive handle input/output.
2302intrinsic("emit_vertex_nv", dest_comp=1, src_comp=[1], indices=[STREAM_ID])
2303intrinsic("end_primitive_nv", dest_comp=1, src_comp=[1], indices=[STREAM_ID])
2304# Contains the final primitive handle and indicate the end of emission.
2305intrinsic("final_primitive_nv", src_comp=[1])
2306
2307# src[] = { data }.
2308intrinsic("fs_out_nv", src_comp=[1], indices=[BASE], flags=[])
2309barrier("copy_fs_outputs_nv")
2310
2311intrinsic("bar_set_nv", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
2312intrinsic("bar_break_nv", dest_comp=1, bit_sizes=[32], src_comp=[1, 1])
2313# src[] = { bar, bar_set }
2314intrinsic("bar_sync_nv", src_comp=[1, 1])
2315
2316# Stall until the given SSA value is available
2317intrinsic("ssa_bar_nv", src_comp=[1])
2318
2319# NVIDIA-specific system values
2320system_value("warps_per_sm_nv", 1, bit_sizes=[32])
2321system_value("sm_count_nv", 1, bit_sizes=[32])
2322system_value("warp_id_nv", 1, bit_sizes=[32])
2323system_value("sm_id_nv", 1, bit_sizes=[32])
2324
2325# In order to deal with flipped render targets, gl_PointCoord may be flipped
2326# in the shader requiring a shader key or extra instructions or it may be
2327# flipped in hardware based on a state bit.  This version of gl_PointCoord
2328# is defined to be whatever thing the hardware can easily give you, so long as
2329# it's in normalized coordinates in the range [0, 1] across the point.
2330intrinsic("load_point_coord_maybe_flipped", dest_comp=2, bit_sizes=[32])
2331
2332
2333# Load texture size values:
2334#
2335# Takes a sampler # and returns width, height and depth.  If texture is a array
2336# texture it returns width, height and array size.  Used for txs lowering.
2337intrinsic("load_texture_size_etna", src_comp=[1], dest_comp=3,
2338          flags=[CAN_ELIMINATE, CAN_REORDER])
2339
2340# Zink specific intrinsics
2341
2342# src[] = { field }.
2343load("push_constant_zink", [1], [COMPONENT], [CAN_ELIMINATE, CAN_REORDER])
2344
2345system_value("shader_index", 1, bit_sizes=[32])
2346
2347system_value("coalesced_input_count", 1, bit_sizes=[32])
2348
2349# Initialize a payload array per scope
2350#
2351#   0. Payloads deref
2352#   1. Payload count
2353#   2. Node index
2354intrinsic("initialize_node_payloads", src_comp=[-1, 1, 1], indices=[EXECUTION_SCOPE])
2355
2356# Optionally enqueue payloads after shader finished writing to them
2357intrinsic("enqueue_node_payloads", src_comp=[-1])
2358
2359# Returns true if it has been called for every payload.
2360intrinsic("finalize_incoming_node_payload", src_comp=[-1], dest_comp=1)
2361