1bf215546Sopenharmony_ci#
2bf215546Sopenharmony_ci# Copyright (C) 2018 Red Hat
3bf215546Sopenharmony_ci# Copyright (C) 2014 Intel Corporation
4bf215546Sopenharmony_ci#
5bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci# and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci# Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci#
12bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci# Software.
15bf215546Sopenharmony_ci#
16bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22bf215546Sopenharmony_ci# IN THE SOFTWARE.
23bf215546Sopenharmony_ci#
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci# This file defines all the available intrinsics in one place.
26bf215546Sopenharmony_ci#
27bf215546Sopenharmony_ci# The Intrinsic class corresponds one-to-one with nir_intrinsic_info
28bf215546Sopenharmony_ci# structure.
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_cisrc0 = ('src', 0)
31bf215546Sopenharmony_cisrc1 = ('src', 1)
32bf215546Sopenharmony_cisrc2 = ('src', 2)
33bf215546Sopenharmony_cisrc3 = ('src', 3)
34bf215546Sopenharmony_cisrc4 = ('src', 4)
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ciclass Index(object):
37bf215546Sopenharmony_ci    def __init__(self, c_data_type, name):
38bf215546Sopenharmony_ci        self.c_data_type = c_data_type
39bf215546Sopenharmony_ci        self.name = name
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ciclass Intrinsic(object):
42bf215546Sopenharmony_ci   """Class that represents all the information about an intrinsic opcode.
43bf215546Sopenharmony_ci   NOTE: this must be kept in sync with nir_intrinsic_info.
44bf215546Sopenharmony_ci   """
45bf215546Sopenharmony_ci   def __init__(self, name, src_components, dest_components,
46bf215546Sopenharmony_ci                indices, flags, sysval, bit_sizes):
47bf215546Sopenharmony_ci       """Parameters:
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci       - name: the intrinsic name
50bf215546Sopenharmony_ci       - src_components: list of the number of components per src, 0 means
51bf215546Sopenharmony_ci         vectorized instruction with number of components given in the
52bf215546Sopenharmony_ci         num_components field in nir_intrinsic_instr.
53bf215546Sopenharmony_ci       - dest_components: number of destination components, -1 means no
54bf215546Sopenharmony_ci         dest, 0 means number of components given in num_components field
55bf215546Sopenharmony_ci         in nir_intrinsic_instr.
56bf215546Sopenharmony_ci       - indices: list of constant indicies
57bf215546Sopenharmony_ci       - flags: list of semantic flags
58bf215546Sopenharmony_ci       - sysval: is this a system-value intrinsic
59bf215546Sopenharmony_ci       - bit_sizes: allowed dest bit_sizes or the source it must match
60bf215546Sopenharmony_ci       """
61bf215546Sopenharmony_ci       assert isinstance(name, str)
62bf215546Sopenharmony_ci       assert isinstance(src_components, list)
63bf215546Sopenharmony_ci       if src_components:
64bf215546Sopenharmony_ci           assert isinstance(src_components[0], int)
65bf215546Sopenharmony_ci       assert isinstance(dest_components, int)
66bf215546Sopenharmony_ci       assert isinstance(indices, list)
67bf215546Sopenharmony_ci       if indices:
68bf215546Sopenharmony_ci           assert isinstance(indices[0], Index)
69bf215546Sopenharmony_ci       assert isinstance(flags, list)
70bf215546Sopenharmony_ci       if flags:
71bf215546Sopenharmony_ci           assert isinstance(flags[0], str)
72bf215546Sopenharmony_ci       assert isinstance(sysval, bool)
73bf215546Sopenharmony_ci       if isinstance(bit_sizes, list):
74bf215546Sopenharmony_ci           assert not bit_sizes or isinstance(bit_sizes[0], int)
75bf215546Sopenharmony_ci       else:
76bf215546Sopenharmony_ci           assert isinstance(bit_sizes, tuple)
77bf215546Sopenharmony_ci           assert bit_sizes[0] == 'src'
78bf215546Sopenharmony_ci           assert isinstance(bit_sizes[1], int)
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci       self.name = name
81bf215546Sopenharmony_ci       self.num_srcs = len(src_components)
82bf215546Sopenharmony_ci       self.src_components = src_components
83bf215546Sopenharmony_ci       self.has_dest = (dest_components >= 0)
84bf215546Sopenharmony_ci       self.dest_components = dest_components
85bf215546Sopenharmony_ci       self.num_indices = len(indices)
86bf215546Sopenharmony_ci       self.indices = indices
87bf215546Sopenharmony_ci       self.flags = flags
88bf215546Sopenharmony_ci       self.sysval = sysval
89bf215546Sopenharmony_ci       self.bit_sizes = bit_sizes if isinstance(bit_sizes, list) else []
90bf215546Sopenharmony_ci       self.bit_size_src = bit_sizes[1] if isinstance(bit_sizes, tuple) else -1
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci#
93bf215546Sopenharmony_ci# Possible flags:
94bf215546Sopenharmony_ci#
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ciCAN_ELIMINATE = "NIR_INTRINSIC_CAN_ELIMINATE"
97bf215546Sopenharmony_ciCAN_REORDER   = "NIR_INTRINSIC_CAN_REORDER"
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ciINTR_INDICES = []
100bf215546Sopenharmony_ciINTR_OPCODES = {}
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_cidef index(c_data_type, name):
103bf215546Sopenharmony_ci    idx = Index(c_data_type, name)
104bf215546Sopenharmony_ci    INTR_INDICES.append(idx)
105bf215546Sopenharmony_ci    globals()[name.upper()] = idx
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci# Defines a new NIR intrinsic.  By default, the intrinsic will have no sources
108bf215546Sopenharmony_ci# and no destination.
109bf215546Sopenharmony_ci#
110bf215546Sopenharmony_ci# You can set dest_comp=n to enable a destination for the intrinsic, in which
111bf215546Sopenharmony_ci# case it will have that many components, or =0 for "as many components as the
112bf215546Sopenharmony_ci# NIR destination value."
113bf215546Sopenharmony_ci#
114bf215546Sopenharmony_ci# Set src_comp=n to enable sources for the intruction.  It can be an array of
115bf215546Sopenharmony_ci# component counts, or (for convenience) a scalar component count if there's
116bf215546Sopenharmony_ci# only one source.  If a component count is 0, it will be as many components as
117bf215546Sopenharmony_ci# the intrinsic has based on the dest_comp.
118bf215546Sopenharmony_cidef intrinsic(name, src_comp=[], dest_comp=-1, indices=[],
119bf215546Sopenharmony_ci              flags=[], sysval=False, bit_sizes=[]):
120bf215546Sopenharmony_ci    assert name not in INTR_OPCODES
121bf215546Sopenharmony_ci    INTR_OPCODES[name] = Intrinsic(name, src_comp, dest_comp,
122bf215546Sopenharmony_ci                                   indices, flags, sysval, bit_sizes)
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci#
125bf215546Sopenharmony_ci# Possible indices:
126bf215546Sopenharmony_ci#
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci# Generally instructions that take a offset src argument, can encode
129bf215546Sopenharmony_ci# a constant 'base' value which is added to the offset.
130bf215546Sopenharmony_ciindex("int", "base")
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci# For store instructions, a writemask for the store.
133bf215546Sopenharmony_ciindex("unsigned", "write_mask")
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci# The stream-id for GS emit_vertex/end_primitive intrinsics.
136bf215546Sopenharmony_ciindex("unsigned", "stream_id")
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci# The clip-plane id for load_user_clip_plane intrinsic.
139bf215546Sopenharmony_ciindex("unsigned", "ucp_id")
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci# The offset to the start of the NIR_INTRINSIC_RANGE.  This is an alternative
142bf215546Sopenharmony_ci# to NIR_INTRINSIC_BASE for describing the valid range in intrinsics that don't
143bf215546Sopenharmony_ci# have the implicit addition of a base to the offset.
144bf215546Sopenharmony_ci#
145bf215546Sopenharmony_ci# If the [range_base, range] is [0, ~0], then we don't know the possible
146bf215546Sopenharmony_ci# range of the access.
147bf215546Sopenharmony_ciindex("unsigned", "range_base")
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci# The amount of data, starting from BASE or RANGE_BASE, that this
150bf215546Sopenharmony_ci# instruction may access.  This is used to provide bounds if the offset is
151bf215546Sopenharmony_ci# not constant.
152bf215546Sopenharmony_ciindex("unsigned", "range")
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci# The Vulkan descriptor set for vulkan_resource_index intrinsic.
155bf215546Sopenharmony_ciindex("unsigned", "desc_set")
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci# The Vulkan descriptor set binding for vulkan_resource_index intrinsic.
158bf215546Sopenharmony_ciindex("unsigned", "binding")
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci# Component offset
161bf215546Sopenharmony_ciindex("unsigned", "component")
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci# Column index for matrix system values
164bf215546Sopenharmony_ciindex("unsigned", "column")
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ci# Interpolation mode (only meaningful for FS inputs)
167bf215546Sopenharmony_ciindex("unsigned", "interp_mode")
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci# A binary nir_op to use when performing a reduction or scan operation
170bf215546Sopenharmony_ciindex("unsigned", "reduction_op")
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci# Cluster size for reduction operations
173bf215546Sopenharmony_ciindex("unsigned", "cluster_size")
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci# Parameter index for a load_param intrinsic
176bf215546Sopenharmony_ciindex("unsigned", "param_idx")
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci# Image dimensionality for image intrinsics
179bf215546Sopenharmony_ciindex("enum glsl_sampler_dim", "image_dim")
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ci# Non-zero if we are accessing an array image
182bf215546Sopenharmony_ciindex("bool", "image_array")
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci# Image format for image intrinsics
185bf215546Sopenharmony_ciindex("enum pipe_format", "format")
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_ci# Access qualifiers for image and memory access intrinsics. ACCESS_RESTRICT is
188bf215546Sopenharmony_ci# not set at the intrinsic if the NIR was created from SPIR-V.
189bf215546Sopenharmony_ciindex("enum gl_access_qualifier", "access")
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci# call index for split raytracing shaders
192bf215546Sopenharmony_ciindex("unsigned", "call_idx")
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci# The stack size increment/decrement for split raytracing shaders
195bf215546Sopenharmony_ciindex("unsigned", "stack_size")
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci# Alignment for offsets and addresses
198bf215546Sopenharmony_ci#
199bf215546Sopenharmony_ci# These two parameters, specify an alignment in terms of a multiplier and
200bf215546Sopenharmony_ci# an offset.  The multiplier is always a power of two.  The offset or
201bf215546Sopenharmony_ci# address parameter X of the intrinsic is guaranteed to satisfy the
202bf215546Sopenharmony_ci# following:
203bf215546Sopenharmony_ci#
204bf215546Sopenharmony_ci#                (X - align_offset) % align_mul == 0
205bf215546Sopenharmony_ci#
206bf215546Sopenharmony_ci# For constant offset values, align_mul will be NIR_ALIGN_MUL_MAX and the
207bf215546Sopenharmony_ci# align_offset will be modulo that.
208bf215546Sopenharmony_ciindex("unsigned", "align_mul")
209bf215546Sopenharmony_ciindex("unsigned", "align_offset")
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci# The Vulkan descriptor type for a vulkan_resource_[re]index intrinsic.
212bf215546Sopenharmony_ciindex("unsigned", "desc_type")
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci# The nir_alu_type of input data to a store or conversion
215bf215546Sopenharmony_ciindex("nir_alu_type", "src_type")
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci# The nir_alu_type of the data output from a load or conversion
218bf215546Sopenharmony_ciindex("nir_alu_type", "dest_type")
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ci# The swizzle mask for quad_swizzle_amd & masked_swizzle_amd
221bf215546Sopenharmony_ciindex("unsigned", "swizzle_mask")
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci# Whether the load_buffer_amd/store_buffer_amd is swizzled
224bf215546Sopenharmony_ciindex("bool", "is_swizzled")
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci# The SLC ("system level coherent") bit of load_buffer_amd/store_buffer_amd
227bf215546Sopenharmony_ciindex("bool", "slc_amd")
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ci# Offsets for load_shared2_amd/store_shared2_amd
230bf215546Sopenharmony_ciindex("uint8_t", "offset0")
231bf215546Sopenharmony_ciindex("uint8_t", "offset1")
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci# If true, both offsets have an additional stride of 64 dwords (ie. they are multiplied by 256 bytes
234bf215546Sopenharmony_ci# in hardware, instead of 4).
235bf215546Sopenharmony_ciindex("bool", "st64")
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ci# When set, range analysis will use it for nir_unsigned_upper_bound
238bf215546Sopenharmony_ciindex("unsigned", "arg_upper_bound_u32_amd")
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci# Separate source/dest access flags for copies
241bf215546Sopenharmony_ciindex("enum gl_access_qualifier", "dst_access")
242bf215546Sopenharmony_ciindex("enum gl_access_qualifier", "src_access")
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci# Driver location of attribute
245bf215546Sopenharmony_ciindex("unsigned", "driver_location")
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_ci# Ordering and visibility of a memory operation
248bf215546Sopenharmony_ciindex("nir_memory_semantics", "memory_semantics")
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci# Modes affected by a memory operation
251bf215546Sopenharmony_ciindex("nir_variable_mode", "memory_modes")
252bf215546Sopenharmony_ci
253bf215546Sopenharmony_ci# Scope of a memory operation
254bf215546Sopenharmony_ciindex("nir_scope", "memory_scope")
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_ci# Scope of a control barrier
257bf215546Sopenharmony_ciindex("nir_scope", "execution_scope")
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci# Semantics of an IO instruction
260bf215546Sopenharmony_ciindex("struct nir_io_semantics", "io_semantics")
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci# Transform feedback info
263bf215546Sopenharmony_ciindex("struct nir_io_xfb", "io_xfb")
264bf215546Sopenharmony_ciindex("struct nir_io_xfb", "io_xfb2")
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci# Rounding mode for conversions
267bf215546Sopenharmony_ciindex("nir_rounding_mode", "rounding_mode")
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_ci# Whether or not to saturate in conversions
270bf215546Sopenharmony_ciindex("unsigned", "saturate")
271bf215546Sopenharmony_ci
272bf215546Sopenharmony_ci# Whether or not trace_ray_intel is synchronous
273bf215546Sopenharmony_ciindex("bool", "synchronous")
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_ciintrinsic("nop", flags=[CAN_ELIMINATE])
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ciintrinsic("convert_alu_types", dest_comp=0, src_comp=[0],
278bf215546Sopenharmony_ci          indices=[SRC_TYPE, DEST_TYPE, ROUNDING_MODE, SATURATE],
279bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ciintrinsic("load_param", dest_comp=0, indices=[PARAM_IDX], flags=[CAN_ELIMINATE])
282bf215546Sopenharmony_ci
283bf215546Sopenharmony_ciintrinsic("load_deref", dest_comp=0, src_comp=[-1],
284bf215546Sopenharmony_ci          indices=[ACCESS], flags=[CAN_ELIMINATE])
285bf215546Sopenharmony_ciintrinsic("store_deref", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])
286bf215546Sopenharmony_ciintrinsic("copy_deref", src_comp=[-1, -1], indices=[DST_ACCESS, SRC_ACCESS])
287bf215546Sopenharmony_ciintrinsic("memcpy_deref", src_comp=[-1, -1, 1], indices=[DST_ACCESS, SRC_ACCESS])
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_ci# Interpolation of input.  The interp_deref_at* intrinsics are similar to the
290bf215546Sopenharmony_ci# load_var intrinsic acting on a shader input except that they interpolate the
291bf215546Sopenharmony_ci# input differently.  The at_sample, at_offset and at_vertex intrinsics take an
292bf215546Sopenharmony_ci# additional source that is an integer sample id, a vec2 position offset, or a
293bf215546Sopenharmony_ci# vertex ID respectively.
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ciintrinsic("interp_deref_at_centroid", dest_comp=0, src_comp=[1],
296bf215546Sopenharmony_ci          flags=[ CAN_ELIMINATE, CAN_REORDER])
297bf215546Sopenharmony_ciintrinsic("interp_deref_at_sample", src_comp=[1, 1], dest_comp=0,
298bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
299bf215546Sopenharmony_ciintrinsic("interp_deref_at_offset", src_comp=[1, 2], dest_comp=0,
300bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
301bf215546Sopenharmony_ciintrinsic("interp_deref_at_vertex", src_comp=[1, 1], dest_comp=0,
302bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
303bf215546Sopenharmony_ci
304bf215546Sopenharmony_ci# Gets the length of an unsized array at the end of a buffer
305bf215546Sopenharmony_ciintrinsic("deref_buffer_array_length", src_comp=[-1], dest_comp=1,
306bf215546Sopenharmony_ci          indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])
307bf215546Sopenharmony_ci
308bf215546Sopenharmony_ci# Ask the driver for the size of a given SSBO. It takes the buffer index
309bf215546Sopenharmony_ci# as source.
310bf215546Sopenharmony_ciintrinsic("get_ssbo_size", src_comp=[-1], dest_comp=1, bit_sizes=[32],
311bf215546Sopenharmony_ci          indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])
312bf215546Sopenharmony_ciintrinsic("get_ubo_size", src_comp=[-1], dest_comp=1,
313bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_ci# Intrinsics which provide a run-time mode-check.  Unlike the compile-time
316bf215546Sopenharmony_ci# mode checks, a pointer can only have exactly one mode at runtime.
317bf215546Sopenharmony_ciintrinsic("deref_mode_is", src_comp=[-1], dest_comp=1,
318bf215546Sopenharmony_ci          indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])
319bf215546Sopenharmony_ciintrinsic("addr_mode_is", src_comp=[-1], dest_comp=1,
320bf215546Sopenharmony_ci          indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_ciintrinsic("is_sparse_texels_resident", dest_comp=1, src_comp=[1], bit_sizes=[1,32],
323bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
324bf215546Sopenharmony_ci# result code is resident only if both inputs are resident
325bf215546Sopenharmony_ciintrinsic("sparse_residency_code_and", dest_comp=1, src_comp=[1, 1], bit_sizes=[32],
326bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci# a barrier is an intrinsic with no inputs/outputs but which can't be moved
329bf215546Sopenharmony_ci# around/optimized in general
330bf215546Sopenharmony_cidef barrier(name):
331bf215546Sopenharmony_ci    intrinsic(name)
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_cibarrier("discard")
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_ci# Demote fragment shader invocation to a helper invocation.  Any stores to
336bf215546Sopenharmony_ci# memory after this instruction are suppressed and the fragment does not write
337bf215546Sopenharmony_ci# outputs to the framebuffer.  Unlike discard, demote needs to ensure that
338bf215546Sopenharmony_ci# derivatives will still work for invocations that were not demoted.
339bf215546Sopenharmony_ci#
340bf215546Sopenharmony_ci# As specified by SPV_EXT_demote_to_helper_invocation.
341bf215546Sopenharmony_cibarrier("demote")
342bf215546Sopenharmony_ciintrinsic("is_helper_invocation", dest_comp=1, flags=[CAN_ELIMINATE])
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci# SpvOpTerminateInvocation from SPIR-V.  Essentially a discard "for real".
345bf215546Sopenharmony_cibarrier("terminate")
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ci# A workgroup-level control barrier.  Any thread which hits this barrier will
348bf215546Sopenharmony_ci# pause until all threads within the current workgroup have also hit the
349bf215546Sopenharmony_ci# barrier.  For compute shaders, the workgroup is defined as the local group.
350bf215546Sopenharmony_ci# For tessellation control shaders, the workgroup is defined as the current
351bf215546Sopenharmony_ci# patch.  This intrinsic does not imply any sort of memory barrier.
352bf215546Sopenharmony_cibarrier("control_barrier")
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci# Memory barrier with semantics analogous to the memoryBarrier() GLSL
355bf215546Sopenharmony_ci# intrinsic.
356bf215546Sopenharmony_cibarrier("memory_barrier")
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci# Control/Memory barrier with explicit scope.  Follows the semantics of SPIR-V
359bf215546Sopenharmony_ci# OpMemoryBarrier and OpControlBarrier, used to implement Vulkan Memory Model.
360bf215546Sopenharmony_ci# Storage that the barrier applies is represented using NIR variable modes.
361bf215546Sopenharmony_ci# For an OpMemoryBarrier, set EXECUTION_SCOPE to NIR_SCOPE_NONE.
362bf215546Sopenharmony_ciintrinsic("scoped_barrier",
363bf215546Sopenharmony_ci          indices=[EXECUTION_SCOPE, MEMORY_SCOPE, MEMORY_SEMANTICS, MEMORY_MODES])
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci# Shader clock intrinsic with semantics analogous to the clock2x32ARB()
366bf215546Sopenharmony_ci# GLSL intrinsic.
367bf215546Sopenharmony_ci# The latter can be used as code motion barrier, which is currently not
368bf215546Sopenharmony_ci# feasible with NIR.
369bf215546Sopenharmony_ciintrinsic("shader_clock", dest_comp=2, bit_sizes=[32], flags=[CAN_ELIMINATE],
370bf215546Sopenharmony_ci          indices=[MEMORY_SCOPE])
371bf215546Sopenharmony_ci
372bf215546Sopenharmony_ci# Shader ballot intrinsics with semantics analogous to the
373bf215546Sopenharmony_ci#
374bf215546Sopenharmony_ci#    ballotARB()
375bf215546Sopenharmony_ci#    readInvocationARB()
376bf215546Sopenharmony_ci#    readFirstInvocationARB()
377bf215546Sopenharmony_ci#
378bf215546Sopenharmony_ci# GLSL functions from ARB_shader_ballot.
379bf215546Sopenharmony_ciintrinsic("ballot", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])
380bf215546Sopenharmony_ciintrinsic("read_invocation", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
381bf215546Sopenharmony_ciintrinsic("read_first_invocation", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_ci# Returns the value of the first source for the lane where the second source is
384bf215546Sopenharmony_ci# true. The second source must be true for exactly one lane.
385bf215546Sopenharmony_ciintrinsic("read_invocation_cond_ir3", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci# Additional SPIR-V ballot intrinsics
388bf215546Sopenharmony_ci#
389bf215546Sopenharmony_ci# These correspond to the SPIR-V opcodes
390bf215546Sopenharmony_ci#
391bf215546Sopenharmony_ci#    OpGroupNonUniformElect
392bf215546Sopenharmony_ci#    OpSubgroupFirstInvocationKHR
393bf215546Sopenharmony_ciintrinsic("elect", dest_comp=1, flags=[CAN_ELIMINATE])
394bf215546Sopenharmony_ciintrinsic("first_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
395bf215546Sopenharmony_ciintrinsic("last_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
396bf215546Sopenharmony_ci
397bf215546Sopenharmony_ci# Memory barrier with semantics analogous to the compute shader
398bf215546Sopenharmony_ci# groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
399bf215546Sopenharmony_ci# memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
400bf215546Sopenharmony_cibarrier("group_memory_barrier")
401bf215546Sopenharmony_cibarrier("memory_barrier_atomic_counter")
402bf215546Sopenharmony_cibarrier("memory_barrier_buffer")
403bf215546Sopenharmony_cibarrier("memory_barrier_image")
404bf215546Sopenharmony_cibarrier("memory_barrier_shared")
405bf215546Sopenharmony_cibarrier("begin_invocation_interlock")
406bf215546Sopenharmony_cibarrier("end_invocation_interlock")
407bf215546Sopenharmony_ci
408bf215546Sopenharmony_ci# Memory barrier for synchronizing TCS patch outputs
409bf215546Sopenharmony_cibarrier("memory_barrier_tcs_patch")
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_ci# A conditional discard/demote/terminate, with a single boolean source.
412bf215546Sopenharmony_ciintrinsic("discard_if", src_comp=[1])
413bf215546Sopenharmony_ciintrinsic("demote_if", src_comp=[1])
414bf215546Sopenharmony_ciintrinsic("terminate_if", src_comp=[1])
415bf215546Sopenharmony_ci
416bf215546Sopenharmony_ci# ARB_shader_group_vote intrinsics
417bf215546Sopenharmony_ciintrinsic("vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
418bf215546Sopenharmony_ciintrinsic("vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
419bf215546Sopenharmony_ciintrinsic("vote_feq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
420bf215546Sopenharmony_ciintrinsic("vote_ieq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
421bf215546Sopenharmony_ci
422bf215546Sopenharmony_ci# Ballot ALU operations from SPIR-V.
423bf215546Sopenharmony_ci#
424bf215546Sopenharmony_ci# These operations work like their ALU counterparts except that the operate
425bf215546Sopenharmony_ci# on a uvec4 which is treated as a 128bit integer.  Also, they are, in
426bf215546Sopenharmony_ci# general, free to ignore any bits which are above the subgroup size.
427bf215546Sopenharmony_ciintrinsic("ballot_bitfield_extract", src_comp=[4, 1], dest_comp=1, flags=[CAN_ELIMINATE])
428bf215546Sopenharmony_ciintrinsic("ballot_bit_count_reduce", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
429bf215546Sopenharmony_ciintrinsic("ballot_bit_count_inclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
430bf215546Sopenharmony_ciintrinsic("ballot_bit_count_exclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
431bf215546Sopenharmony_ciintrinsic("ballot_find_lsb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
432bf215546Sopenharmony_ciintrinsic("ballot_find_msb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci# Shuffle operations from SPIR-V.
435bf215546Sopenharmony_ciintrinsic("shuffle", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
436bf215546Sopenharmony_ciintrinsic("shuffle_xor", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
437bf215546Sopenharmony_ciintrinsic("shuffle_up", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
438bf215546Sopenharmony_ciintrinsic("shuffle_down", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
439bf215546Sopenharmony_ci
440bf215546Sopenharmony_ci# Quad operations from SPIR-V.
441bf215546Sopenharmony_ciintrinsic("quad_broadcast", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
442bf215546Sopenharmony_ciintrinsic("quad_swap_horizontal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
443bf215546Sopenharmony_ciintrinsic("quad_swap_vertical", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
444bf215546Sopenharmony_ciintrinsic("quad_swap_diagonal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_ciintrinsic("reduce", src_comp=[0], dest_comp=0, bit_sizes=src0,
447bf215546Sopenharmony_ci          indices=[REDUCTION_OP, CLUSTER_SIZE], flags=[CAN_ELIMINATE])
448bf215546Sopenharmony_ciintrinsic("inclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,
449bf215546Sopenharmony_ci          indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])
450bf215546Sopenharmony_ciintrinsic("exclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,
451bf215546Sopenharmony_ci          indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci# AMD shader ballot operations
454bf215546Sopenharmony_ciintrinsic("quad_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,
455bf215546Sopenharmony_ci          indices=[SWIZZLE_MASK], flags=[CAN_ELIMINATE])
456bf215546Sopenharmony_ciintrinsic("masked_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,
457bf215546Sopenharmony_ci          indices=[SWIZZLE_MASK], flags=[CAN_ELIMINATE])
458bf215546Sopenharmony_ciintrinsic("write_invocation_amd", src_comp=[0, 0, 1], dest_comp=0, bit_sizes=src0,
459bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE])
460bf215546Sopenharmony_ci# src = [ mask, addition ]
461bf215546Sopenharmony_ciintrinsic("mbcnt_amd", src_comp=[1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
462bf215546Sopenharmony_ci# Compiled to v_perm_b32. src = [ in_bytes_hi, in_bytes_lo, selector ]
463bf215546Sopenharmony_ciintrinsic("byte_permute_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
464bf215546Sopenharmony_ci# Compiled to v_permlane16_b32. src = [ value, lanesel_lo, lanesel_hi ]
465bf215546Sopenharmony_ciintrinsic("lane_permute_16_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
466bf215546Sopenharmony_ci
467bf215546Sopenharmony_ci# Basic Geometry Shader intrinsics.
468bf215546Sopenharmony_ci#
469bf215546Sopenharmony_ci# emit_vertex implements GLSL's EmitStreamVertex() built-in.  It takes a single
470bf215546Sopenharmony_ci# index, which is the stream ID to write to.
471bf215546Sopenharmony_ci#
472bf215546Sopenharmony_ci# end_primitive implements GLSL's EndPrimitive() built-in.
473bf215546Sopenharmony_ciintrinsic("emit_vertex",   indices=[STREAM_ID])
474bf215546Sopenharmony_ciintrinsic("end_primitive", indices=[STREAM_ID])
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ci# Geometry Shader intrinsics with a vertex count.
477bf215546Sopenharmony_ci#
478bf215546Sopenharmony_ci# Alternatively, drivers may implement these intrinsics, and use
479bf215546Sopenharmony_ci# nir_lower_gs_intrinsics() to convert from the basic intrinsics.
480bf215546Sopenharmony_ci#
481bf215546Sopenharmony_ci# These contain two additional unsigned integer sources:
482bf215546Sopenharmony_ci# 1. The total number of vertices emitted so far.
483bf215546Sopenharmony_ci# 2. The number of vertices emitted for the current primitive
484bf215546Sopenharmony_ci#    so far if we're counting, otherwise undef.
485bf215546Sopenharmony_ciintrinsic("emit_vertex_with_counter", src_comp=[1, 1], indices=[STREAM_ID])
486bf215546Sopenharmony_ciintrinsic("end_primitive_with_counter", src_comp=[1, 1], indices=[STREAM_ID])
487bf215546Sopenharmony_ci# Contains the final total vertex and primitive counts in the current GS thread.
488bf215546Sopenharmony_ciintrinsic("set_vertex_and_primitive_count", src_comp=[1, 1], indices=[STREAM_ID])
489bf215546Sopenharmony_ci
490bf215546Sopenharmony_ci# Launches mesh shader workgroups from a task shader, with explicit task_payload.
491bf215546Sopenharmony_ci# Rules:
492bf215546Sopenharmony_ci# - This is a terminating instruction.
493bf215546Sopenharmony_ci# - May only occur in workgroup-uniform control flow.
494bf215546Sopenharmony_ci# - Dispatch sizes may be divergent (in which case the values
495bf215546Sopenharmony_ci#   from the first invocation are used).
496bf215546Sopenharmony_ci# Meaning of indices:
497bf215546Sopenharmony_ci# - BASE: address of the task_payload variable used.
498bf215546Sopenharmony_ci# - RANGE: size of the task_payload variable used.
499bf215546Sopenharmony_ci#
500bf215546Sopenharmony_ci# src[] = {vec(x, y, z)}
501bf215546Sopenharmony_ciintrinsic("launch_mesh_workgroups", src_comp=[3], indices=[BASE, RANGE])
502bf215546Sopenharmony_ci
503bf215546Sopenharmony_ci# Trace a ray through an acceleration structure
504bf215546Sopenharmony_ci#
505bf215546Sopenharmony_ci# This instruction has a lot of parameters:
506bf215546Sopenharmony_ci#   0. Acceleration Structure
507bf215546Sopenharmony_ci#   1. Ray Flags
508bf215546Sopenharmony_ci#   2. Cull Mask
509bf215546Sopenharmony_ci#   3. SBT Offset
510bf215546Sopenharmony_ci#   4. SBT Stride
511bf215546Sopenharmony_ci#   5. Miss shader index
512bf215546Sopenharmony_ci#   6. Ray Origin
513bf215546Sopenharmony_ci#   7. Ray Tmin
514bf215546Sopenharmony_ci#   8. Ray Direction
515bf215546Sopenharmony_ci#   9. Ray Tmax
516bf215546Sopenharmony_ci#   10. Payload
517bf215546Sopenharmony_ciintrinsic("trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1])
518bf215546Sopenharmony_ci# src[] = { hit_t, hit_kind }
519bf215546Sopenharmony_ciintrinsic("report_ray_intersection", src_comp=[1, 1], dest_comp=1)
520bf215546Sopenharmony_ciintrinsic("ignore_ray_intersection")
521bf215546Sopenharmony_ciintrinsic("accept_ray_intersection") # Not in SPIR-V; useful for lowering
522bf215546Sopenharmony_ciintrinsic("terminate_ray")
523bf215546Sopenharmony_ci# src[] = { sbt_index, payload }
524bf215546Sopenharmony_ciintrinsic("execute_callable", src_comp=[1, -1])
525bf215546Sopenharmony_ci
526bf215546Sopenharmony_ci# Initialize a ray query
527bf215546Sopenharmony_ci#
528bf215546Sopenharmony_ci#   0. Ray Query
529bf215546Sopenharmony_ci#   1. Acceleration Structure
530bf215546Sopenharmony_ci#   2. Ray Flags
531bf215546Sopenharmony_ci#   3. Cull Mask
532bf215546Sopenharmony_ci#   4. Ray Origin
533bf215546Sopenharmony_ci#   5. Ray Tmin
534bf215546Sopenharmony_ci#   6. Ray Direction
535bf215546Sopenharmony_ci#   7. Ray Tmax
536bf215546Sopenharmony_ciintrinsic("rq_initialize", src_comp=[-1, -1, 1, 1, 3, 1, 3, 1])
537bf215546Sopenharmony_ci# src[] = { query }
538bf215546Sopenharmony_ciintrinsic("rq_terminate", src_comp=[-1])
539bf215546Sopenharmony_ci# src[] = { query }
540bf215546Sopenharmony_ciintrinsic("rq_proceed", src_comp=[-1], dest_comp=1)
541bf215546Sopenharmony_ci# src[] = { query, hit }
542bf215546Sopenharmony_ciintrinsic("rq_generate_intersection", src_comp=[-1, 1])
543bf215546Sopenharmony_ci# src[] = { query }
544bf215546Sopenharmony_ciintrinsic("rq_confirm_intersection", src_comp=[-1])
545bf215546Sopenharmony_ci# src[] = { query, committed } BASE=nir_ray_query_value
546bf215546Sopenharmony_ciintrinsic("rq_load", src_comp=[-1, 1], dest_comp=0, indices=[BASE,COLUMN])
547bf215546Sopenharmony_ci
548bf215546Sopenharmony_ci# Driver independent raytracing helpers
549bf215546Sopenharmony_ci
550bf215546Sopenharmony_ci# rt_resume is a helper that that be the first instruction accesing the
551bf215546Sopenharmony_ci# stack/scratch in a resume shader for a raytracing pipeline. It includes the
552bf215546Sopenharmony_ci# resume index (for nir_lower_shader_calls_internal reasons) and the stack size
553bf215546Sopenharmony_ci# of the variables spilled during the call. The stack size can be use to e.g.
554bf215546Sopenharmony_ci# adjust a stack pointer.
555bf215546Sopenharmony_ciintrinsic("rt_resume", indices=[CALL_IDX, STACK_SIZE])
556bf215546Sopenharmony_ci
557bf215546Sopenharmony_ci# Lowered version of execute_callabe that includes the index of the resume
558bf215546Sopenharmony_ci# shader, and the amount of scratch space needed for this call (.ie. how much
559bf215546Sopenharmony_ci# to increase a stack pointer by).
560bf215546Sopenharmony_ci# src[] = { sbt_index, payload }
561bf215546Sopenharmony_ciintrinsic("rt_execute_callable", src_comp=[1, -1], indices=[CALL_IDX,STACK_SIZE])
562bf215546Sopenharmony_ci
563bf215546Sopenharmony_ci# Lowered version of trace_ray in a similar vein to rt_execute_callable.
564bf215546Sopenharmony_ci# src same as trace_ray
565bf215546Sopenharmony_ciintrinsic("rt_trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1],
566bf215546Sopenharmony_ci          indices=[CALL_IDX, STACK_SIZE])
567bf215546Sopenharmony_ci
568bf215546Sopenharmony_ci
569bf215546Sopenharmony_ci# Atomic counters
570bf215546Sopenharmony_ci#
571bf215546Sopenharmony_ci# The *_deref variants take an atomic_uint nir_variable, while the other,
572bf215546Sopenharmony_ci# lowered, variants take a buffer index and register offset.  The buffer index
573bf215546Sopenharmony_ci# is always constant, as there's no way to declare an array of atomic counter
574bf215546Sopenharmony_ci# buffers.
575bf215546Sopenharmony_ci#
576bf215546Sopenharmony_ci# The register offset may be non-constant but must by dynamically uniform
577bf215546Sopenharmony_ci# ("Atomic counters aggregated into arrays within a shader can only be indexed
578bf215546Sopenharmony_ci# with dynamically uniform integral expressions, otherwise results are
579bf215546Sopenharmony_ci# undefined.")
580bf215546Sopenharmony_cidef atomic(name, flags=[]):
581bf215546Sopenharmony_ci    intrinsic(name + "_deref", src_comp=[-1], dest_comp=1, flags=flags)
582bf215546Sopenharmony_ci    intrinsic(name, src_comp=[1], dest_comp=1, indices=[BASE], flags=flags)
583bf215546Sopenharmony_ci
584bf215546Sopenharmony_cidef atomic2(name):
585bf215546Sopenharmony_ci    intrinsic(name + "_deref", src_comp=[-1, 1], dest_comp=1)
586bf215546Sopenharmony_ci    intrinsic(name, src_comp=[1, 1], dest_comp=1, indices=[BASE])
587bf215546Sopenharmony_ci
588bf215546Sopenharmony_cidef atomic3(name):
589bf215546Sopenharmony_ci    intrinsic(name + "_deref", src_comp=[-1, 1, 1], dest_comp=1)
590bf215546Sopenharmony_ci    intrinsic(name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
591bf215546Sopenharmony_ci
592bf215546Sopenharmony_ciatomic("atomic_counter_inc")
593bf215546Sopenharmony_ciatomic("atomic_counter_pre_dec")
594bf215546Sopenharmony_ciatomic("atomic_counter_post_dec")
595bf215546Sopenharmony_ciatomic("atomic_counter_read", flags=[CAN_ELIMINATE])
596bf215546Sopenharmony_ciatomic2("atomic_counter_add")
597bf215546Sopenharmony_ciatomic2("atomic_counter_min")
598bf215546Sopenharmony_ciatomic2("atomic_counter_max")
599bf215546Sopenharmony_ciatomic2("atomic_counter_and")
600bf215546Sopenharmony_ciatomic2("atomic_counter_or")
601bf215546Sopenharmony_ciatomic2("atomic_counter_xor")
602bf215546Sopenharmony_ciatomic2("atomic_counter_exchange")
603bf215546Sopenharmony_ciatomic3("atomic_counter_comp_swap")
604bf215546Sopenharmony_ci
605bf215546Sopenharmony_ci# Image load, store and atomic intrinsics.
606bf215546Sopenharmony_ci#
607bf215546Sopenharmony_ci# All image intrinsics come in three versions.  One which take an image target
608bf215546Sopenharmony_ci# passed as a deref chain as the first source, one which takes an index as the
609bf215546Sopenharmony_ci# first source, and one which takes a bindless handle as the first source.
610bf215546Sopenharmony_ci# In the first version, the image variable contains the memory and layout
611bf215546Sopenharmony_ci# qualifiers that influence the semantics of the intrinsic.  In the second and
612bf215546Sopenharmony_ci# third, the image format and access qualifiers are provided as constant
613bf215546Sopenharmony_ci# indices.  Up through GLSL ES 3.10, the image index source may only be a
614bf215546Sopenharmony_ci# constant array access.  GLSL ES 3.20 and GLSL 4.00 allow dynamically uniform
615bf215546Sopenharmony_ci# indexing.
616bf215546Sopenharmony_ci#
617bf215546Sopenharmony_ci# All image intrinsics take a four-coordinate vector and a sample index as
618bf215546Sopenharmony_ci# 2nd and 3rd sources, determining the location within the image that will be
619bf215546Sopenharmony_ci# accessed by the intrinsic.  Components not applicable to the image target
620bf215546Sopenharmony_ci# in use are undefined.  Image store takes an additional four-component
621bf215546Sopenharmony_ci# argument with the value to be written, and image atomic operations take
622bf215546Sopenharmony_ci# either one or two additional scalar arguments with the same meaning as in
623bf215546Sopenharmony_ci# the ARB_shader_image_load_store specification.
624bf215546Sopenharmony_cidef image(name, src_comp=[], extra_indices=[], **kwargs):
625bf215546Sopenharmony_ci    intrinsic("image_deref_" + name, src_comp=[-1] + src_comp,
626bf215546Sopenharmony_ci              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
627bf215546Sopenharmony_ci    intrinsic("image_" + name, src_comp=[1] + src_comp,
628bf215546Sopenharmony_ci              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
629bf215546Sopenharmony_ci    intrinsic("bindless_image_" + name, src_comp=[-1] + src_comp,
630bf215546Sopenharmony_ci              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
631bf215546Sopenharmony_ci
632bf215546Sopenharmony_ciimage("load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
633bf215546Sopenharmony_ciimage("sparse_load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
634bf215546Sopenharmony_ciimage("store", src_comp=[4, 1, 0, 1], extra_indices=[SRC_TYPE])
635bf215546Sopenharmony_ciimage("atomic_add",  src_comp=[4, 1, 1], dest_comp=1)
636bf215546Sopenharmony_ciimage("atomic_imin",  src_comp=[4, 1, 1], dest_comp=1)
637bf215546Sopenharmony_ciimage("atomic_umin",  src_comp=[4, 1, 1], dest_comp=1)
638bf215546Sopenharmony_ciimage("atomic_imax",  src_comp=[4, 1, 1], dest_comp=1)
639bf215546Sopenharmony_ciimage("atomic_umax",  src_comp=[4, 1, 1], dest_comp=1)
640bf215546Sopenharmony_ciimage("atomic_and",  src_comp=[4, 1, 1], dest_comp=1)
641bf215546Sopenharmony_ciimage("atomic_or",   src_comp=[4, 1, 1], dest_comp=1)
642bf215546Sopenharmony_ciimage("atomic_xor",  src_comp=[4, 1, 1], dest_comp=1)
643bf215546Sopenharmony_ciimage("atomic_exchange",  src_comp=[4, 1, 1], dest_comp=1)
644bf215546Sopenharmony_ciimage("atomic_comp_swap", src_comp=[4, 1, 1, 1], dest_comp=1)
645bf215546Sopenharmony_ciimage("atomic_fadd",  src_comp=[4, 1, 1], dest_comp=1)
646bf215546Sopenharmony_ciimage("atomic_fmin",  src_comp=[4, 1, 1], dest_comp=1)
647bf215546Sopenharmony_ciimage("atomic_fmax",  src_comp=[4, 1, 1], dest_comp=1)
648bf215546Sopenharmony_ciimage("size",    dest_comp=0, src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])
649bf215546Sopenharmony_ciimage("samples", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
650bf215546Sopenharmony_ciimage("atomic_inc_wrap",  src_comp=[4, 1, 1], dest_comp=1)
651bf215546Sopenharmony_ciimage("atomic_dec_wrap",  src_comp=[4, 1, 1], dest_comp=1)
652bf215546Sopenharmony_ci# CL-specific format queries
653bf215546Sopenharmony_ciimage("format", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
654bf215546Sopenharmony_ciimage("order", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
655bf215546Sopenharmony_ci
656bf215546Sopenharmony_ci# Vulkan descriptor set intrinsics
657bf215546Sopenharmony_ci#
658bf215546Sopenharmony_ci# The Vulkan API uses a different binding model from GL.  In the Vulkan
659bf215546Sopenharmony_ci# API, all external resources are represented by a tuple:
660bf215546Sopenharmony_ci#
661bf215546Sopenharmony_ci# (descriptor set, binding, array index)
662bf215546Sopenharmony_ci#
663bf215546Sopenharmony_ci# where the array index is the only thing allowed to be indirect.  The
664bf215546Sopenharmony_ci# vulkan_surface_index intrinsic takes the descriptor set and binding as
665bf215546Sopenharmony_ci# its first two indices and the array index as its source.  The third
666bf215546Sopenharmony_ci# index is a nir_variable_mode in case that's useful to the backend.
667bf215546Sopenharmony_ci#
668bf215546Sopenharmony_ci# The intended usage is that the shader will call vulkan_surface_index to
669bf215546Sopenharmony_ci# get an index and then pass that as the buffer index ubo/ssbo calls.
670bf215546Sopenharmony_ci#
671bf215546Sopenharmony_ci# The vulkan_resource_reindex intrinsic takes a resource index in src0
672bf215546Sopenharmony_ci# (the result of a vulkan_resource_index or vulkan_resource_reindex) which
673bf215546Sopenharmony_ci# corresponds to the tuple (set, binding, index) and computes an index
674bf215546Sopenharmony_ci# corresponding to tuple (set, binding, idx + src1).
675bf215546Sopenharmony_ciintrinsic("vulkan_resource_index", src_comp=[1], dest_comp=0,
676bf215546Sopenharmony_ci          indices=[DESC_SET, BINDING, DESC_TYPE],
677bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
678bf215546Sopenharmony_ciintrinsic("vulkan_resource_reindex", src_comp=[0, 1], dest_comp=0,
679bf215546Sopenharmony_ci          indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])
680bf215546Sopenharmony_ciintrinsic("load_vulkan_descriptor", src_comp=[-1], dest_comp=0,
681bf215546Sopenharmony_ci          indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])
682bf215546Sopenharmony_ci
683bf215546Sopenharmony_ci# atomic intrinsics
684bf215546Sopenharmony_ci#
685bf215546Sopenharmony_ci# All of these atomic memory operations read a value from memory, compute a new
686bf215546Sopenharmony_ci# value using one of the operations below, write the new value to memory, and
687bf215546Sopenharmony_ci# return the original value read.
688bf215546Sopenharmony_ci#
689bf215546Sopenharmony_ci# All variable operations take 2 sources except CompSwap that takes 3. These
690bf215546Sopenharmony_ci# sources represent:
691bf215546Sopenharmony_ci#
692bf215546Sopenharmony_ci# 0: A deref to the memory on which to perform the atomic
693bf215546Sopenharmony_ci# 1: The data parameter to the atomic function (i.e. the value to add
694bf215546Sopenharmony_ci#    in shared_atomic_add, etc).
695bf215546Sopenharmony_ci# 2: For CompSwap only: the second data parameter.
696bf215546Sopenharmony_ci#
697bf215546Sopenharmony_ci# All SSBO operations take 3 sources except CompSwap that takes 4. These
698bf215546Sopenharmony_ci# sources represent:
699bf215546Sopenharmony_ci#
700bf215546Sopenharmony_ci# 0: The SSBO buffer index (dynamically uniform in GLSL, possibly non-uniform
701bf215546Sopenharmony_ci#    with VK_EXT_descriptor_indexing).
702bf215546Sopenharmony_ci# 1: The offset into the SSBO buffer of the variable that the atomic
703bf215546Sopenharmony_ci#    operation will operate on.
704bf215546Sopenharmony_ci# 2: The data parameter to the atomic function (i.e. the value to add
705bf215546Sopenharmony_ci#    in ssbo_atomic_add, etc).
706bf215546Sopenharmony_ci# 3: For CompSwap only: the second data parameter.
707bf215546Sopenharmony_ci#
708bf215546Sopenharmony_ci# All shared (and task payload) variable operations take 2 sources
709bf215546Sopenharmony_ci# except CompSwap that takes 3.
710bf215546Sopenharmony_ci# These sources represent:
711bf215546Sopenharmony_ci#
712bf215546Sopenharmony_ci# 0: The offset into the shared variable storage region that the atomic
713bf215546Sopenharmony_ci#    operation will operate on.
714bf215546Sopenharmony_ci# 1: The data parameter to the atomic function (i.e. the value to add
715bf215546Sopenharmony_ci#    in shared_atomic_add, etc).
716bf215546Sopenharmony_ci# 2: For CompSwap only: the second data parameter.
717bf215546Sopenharmony_ci#
718bf215546Sopenharmony_ci# All global operations take 2 sources except CompSwap that takes 3. These
719bf215546Sopenharmony_ci# sources represent:
720bf215546Sopenharmony_ci#
721bf215546Sopenharmony_ci# 0: The memory address that the atomic operation will operate on.
722bf215546Sopenharmony_ci# 1: The data parameter to the atomic function (i.e. the value to add
723bf215546Sopenharmony_ci#    in shared_atomic_add, etc).
724bf215546Sopenharmony_ci# 2: For CompSwap only: the second data parameter.
725bf215546Sopenharmony_ci#
726bf215546Sopenharmony_ci# The 2x32 global variants use a vec2 for the memory address where component X
727bf215546Sopenharmony_ci# has the low 32-bit and component Y has the high 32-bit.
728bf215546Sopenharmony_ci#
729bf215546Sopenharmony_ci# IR3 global operations take 32b vec2 as memory address. IR3 doesn't support
730bf215546Sopenharmony_ci# float atomics.
731bf215546Sopenharmony_ci
732bf215546Sopenharmony_cidef memory_atomic_data1(name):
733bf215546Sopenharmony_ci    intrinsic("deref_atomic_" + name,  src_comp=[-1, 1], dest_comp=1, indices=[ACCESS])
734bf215546Sopenharmony_ci    intrinsic("ssbo_atomic_" + name,  src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS])
735bf215546Sopenharmony_ci    intrinsic("shared_atomic_" + name,  src_comp=[1, 1], dest_comp=1, indices=[BASE])
736bf215546Sopenharmony_ci    intrinsic("task_payload_atomic_" + name,  src_comp=[1, 1], dest_comp=1, indices=[BASE])
737bf215546Sopenharmony_ci    intrinsic("global_atomic_" + name,  src_comp=[1, 1], dest_comp=1, indices=[])
738bf215546Sopenharmony_ci    intrinsic("global_atomic_" + name + "_2x32",  src_comp=[2, 1], dest_comp=1, indices=[])
739bf215546Sopenharmony_ci    intrinsic("global_atomic_" + name + "_amd",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
740bf215546Sopenharmony_ci    if not name.startswith('f'):
741bf215546Sopenharmony_ci        intrinsic("global_atomic_" + name + "_ir3",  src_comp=[2, 1], dest_comp=1, indices=[BASE])
742bf215546Sopenharmony_ci
743bf215546Sopenharmony_cidef memory_atomic_data2(name):
744bf215546Sopenharmony_ci    intrinsic("deref_atomic_" + name,  src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS])
745bf215546Sopenharmony_ci    intrinsic("ssbo_atomic_" + name,  src_comp=[-1, 1, 1, 1], dest_comp=1, indices=[ACCESS])
746bf215546Sopenharmony_ci    intrinsic("shared_atomic_" + name,  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
747bf215546Sopenharmony_ci    intrinsic("task_payload_atomic_" + name,  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
748bf215546Sopenharmony_ci    intrinsic("global_atomic_" + name,  src_comp=[1, 1, 1], dest_comp=1, indices=[])
749bf215546Sopenharmony_ci    intrinsic("global_atomic_" + name + "_2x32",  src_comp=[2, 1, 1], dest_comp=1, indices=[])
750bf215546Sopenharmony_ci    intrinsic("global_atomic_" + name + "_amd",  src_comp=[1, 1, 1, 1], dest_comp=1, indices=[BASE])
751bf215546Sopenharmony_ci    if not name.startswith('f'):
752bf215546Sopenharmony_ci        intrinsic("global_atomic_" + name + "_ir3",  src_comp=[2, 1, 1], dest_comp=1, indices=[BASE])
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_cimemory_atomic_data1("add")
755bf215546Sopenharmony_cimemory_atomic_data1("imin")
756bf215546Sopenharmony_cimemory_atomic_data1("umin")
757bf215546Sopenharmony_cimemory_atomic_data1("imax")
758bf215546Sopenharmony_cimemory_atomic_data1("umax")
759bf215546Sopenharmony_cimemory_atomic_data1("and")
760bf215546Sopenharmony_cimemory_atomic_data1("or")
761bf215546Sopenharmony_cimemory_atomic_data1("xor")
762bf215546Sopenharmony_cimemory_atomic_data1("exchange")
763bf215546Sopenharmony_cimemory_atomic_data1("fadd")
764bf215546Sopenharmony_cimemory_atomic_data1("fmin")
765bf215546Sopenharmony_cimemory_atomic_data1("fmax")
766bf215546Sopenharmony_cimemory_atomic_data2("comp_swap")
767bf215546Sopenharmony_cimemory_atomic_data2("fcomp_swap")
768bf215546Sopenharmony_ci
769bf215546Sopenharmony_cidef system_value(name, dest_comp, indices=[], bit_sizes=[32]):
770bf215546Sopenharmony_ci    intrinsic("load_" + name, [], dest_comp, indices,
771bf215546Sopenharmony_ci              flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True,
772bf215546Sopenharmony_ci              bit_sizes=bit_sizes)
773bf215546Sopenharmony_ci
774bf215546Sopenharmony_cisystem_value("frag_coord", 4)
775bf215546Sopenharmony_cisystem_value("point_coord", 2)
776bf215546Sopenharmony_cisystem_value("line_coord", 1)
777bf215546Sopenharmony_cisystem_value("front_face", 1, bit_sizes=[1, 32])
778bf215546Sopenharmony_cisystem_value("vertex_id", 1)
779bf215546Sopenharmony_cisystem_value("vertex_id_zero_base", 1)
780bf215546Sopenharmony_cisystem_value("first_vertex", 1)
781bf215546Sopenharmony_cisystem_value("is_indexed_draw", 1)
782bf215546Sopenharmony_cisystem_value("base_vertex", 1)
783bf215546Sopenharmony_cisystem_value("instance_id", 1)
784bf215546Sopenharmony_cisystem_value("base_instance", 1)
785bf215546Sopenharmony_cisystem_value("draw_id", 1)
786bf215546Sopenharmony_cisystem_value("sample_id", 1)
787bf215546Sopenharmony_ci# sample_id_no_per_sample is like sample_id but does not imply per-
788bf215546Sopenharmony_ci# sample shading.  See the lower_helper_invocation option.
789bf215546Sopenharmony_cisystem_value("sample_id_no_per_sample", 1)
790bf215546Sopenharmony_cisystem_value("sample_pos", 2)
791bf215546Sopenharmony_ci# sample_pos_or_center is like sample_pos but does not imply per-sample
792bf215546Sopenharmony_ci# shading.  When per-sample dispatch is not enabled, it returns (0.5, 0.5).
793bf215546Sopenharmony_cisystem_value("sample_pos_or_center", 2)
794bf215546Sopenharmony_cisystem_value("sample_mask_in", 1)
795bf215546Sopenharmony_cisystem_value("primitive_id", 1)
796bf215546Sopenharmony_cisystem_value("invocation_id", 1)
797bf215546Sopenharmony_cisystem_value("tess_coord", 3)
798bf215546Sopenharmony_cisystem_value("tess_level_outer", 4)
799bf215546Sopenharmony_cisystem_value("tess_level_inner", 2)
800bf215546Sopenharmony_cisystem_value("tess_level_outer_default", 4)
801bf215546Sopenharmony_cisystem_value("tess_level_inner_default", 2)
802bf215546Sopenharmony_cisystem_value("patch_vertices_in", 1)
803bf215546Sopenharmony_cisystem_value("local_invocation_id", 3)
804bf215546Sopenharmony_cisystem_value("local_invocation_index", 1)
805bf215546Sopenharmony_ci# zero_base indicates it starts from 0 for the current dispatch
806bf215546Sopenharmony_ci# non-zero_base indicates the base is included
807bf215546Sopenharmony_cisystem_value("workgroup_id", 3, bit_sizes=[32, 64])
808bf215546Sopenharmony_cisystem_value("workgroup_id_zero_base", 3)
809bf215546Sopenharmony_ci# The workgroup_index is intended for situations when a 3 dimensional
810bf215546Sopenharmony_ci# workgroup_id is not available on the HW, but a 1 dimensional index is.
811bf215546Sopenharmony_cisystem_value("workgroup_index", 1)
812bf215546Sopenharmony_cisystem_value("base_workgroup_id", 3, bit_sizes=[32, 64])
813bf215546Sopenharmony_cisystem_value("user_clip_plane", 4, indices=[UCP_ID])
814bf215546Sopenharmony_cisystem_value("num_workgroups", 3, bit_sizes=[32, 64])
815bf215546Sopenharmony_cisystem_value("num_vertices", 1)
816bf215546Sopenharmony_cisystem_value("helper_invocation", 1, bit_sizes=[1, 32])
817bf215546Sopenharmony_cisystem_value("layer_id", 1)
818bf215546Sopenharmony_cisystem_value("view_index", 1)
819bf215546Sopenharmony_cisystem_value("subgroup_size", 1)
820bf215546Sopenharmony_cisystem_value("subgroup_invocation", 1)
821bf215546Sopenharmony_cisystem_value("subgroup_eq_mask", 0, bit_sizes=[32, 64])
822bf215546Sopenharmony_cisystem_value("subgroup_ge_mask", 0, bit_sizes=[32, 64])
823bf215546Sopenharmony_cisystem_value("subgroup_gt_mask", 0, bit_sizes=[32, 64])
824bf215546Sopenharmony_cisystem_value("subgroup_le_mask", 0, bit_sizes=[32, 64])
825bf215546Sopenharmony_cisystem_value("subgroup_lt_mask", 0, bit_sizes=[32, 64])
826bf215546Sopenharmony_cisystem_value("num_subgroups", 1)
827bf215546Sopenharmony_cisystem_value("subgroup_id", 1)
828bf215546Sopenharmony_cisystem_value("workgroup_size", 3)
829bf215546Sopenharmony_ci# note: the definition of global_invocation_id_zero_base is based on
830bf215546Sopenharmony_ci# (workgroup_id * workgroup_size) + local_invocation_id.
831bf215546Sopenharmony_ci# it is *not* based on workgroup_id_zero_base, meaning the work group
832bf215546Sopenharmony_ci# base is already accounted for, and the global base is additive on top of that
833bf215546Sopenharmony_cisystem_value("global_invocation_id", 3, bit_sizes=[32, 64])
834bf215546Sopenharmony_cisystem_value("global_invocation_id_zero_base", 3, bit_sizes=[32, 64])
835bf215546Sopenharmony_cisystem_value("base_global_invocation_id", 3, bit_sizes=[32, 64])
836bf215546Sopenharmony_cisystem_value("global_invocation_index", 1, bit_sizes=[32, 64])
837bf215546Sopenharmony_cisystem_value("work_dim", 1)
838bf215546Sopenharmony_cisystem_value("line_width", 1)
839bf215546Sopenharmony_cisystem_value("aa_line_width", 1)
840bf215546Sopenharmony_ci# BASE=0 for global/shader, BASE=1 for local/function
841bf215546Sopenharmony_cisystem_value("scratch_base_ptr", 0, bit_sizes=[32,64], indices=[BASE])
842bf215546Sopenharmony_cisystem_value("constant_base_ptr", 0, bit_sizes=[32,64])
843bf215546Sopenharmony_cisystem_value("shared_base_ptr", 0, bit_sizes=[32,64])
844bf215546Sopenharmony_cisystem_value("global_base_ptr", 0, bit_sizes=[32,64])
845bf215546Sopenharmony_ci# Address of a transform feedback buffer, indexed by BASE
846bf215546Sopenharmony_cisystem_value("xfb_address", 1, bit_sizes=[32,64], indices=[BASE])
847bf215546Sopenharmony_ci
848bf215546Sopenharmony_ci# System values for ray tracing.
849bf215546Sopenharmony_cisystem_value("ray_launch_id", 3)
850bf215546Sopenharmony_cisystem_value("ray_launch_size", 3)
851bf215546Sopenharmony_cisystem_value("ray_world_origin", 3)
852bf215546Sopenharmony_cisystem_value("ray_world_direction", 3)
853bf215546Sopenharmony_cisystem_value("ray_object_origin", 3)
854bf215546Sopenharmony_cisystem_value("ray_object_direction", 3)
855bf215546Sopenharmony_cisystem_value("ray_t_min", 1)
856bf215546Sopenharmony_cisystem_value("ray_t_max", 1)
857bf215546Sopenharmony_cisystem_value("ray_object_to_world", 3, indices=[COLUMN])
858bf215546Sopenharmony_cisystem_value("ray_world_to_object", 3, indices=[COLUMN])
859bf215546Sopenharmony_cisystem_value("ray_hit_kind", 1)
860bf215546Sopenharmony_cisystem_value("ray_flags", 1)
861bf215546Sopenharmony_cisystem_value("ray_geometry_index", 1)
862bf215546Sopenharmony_cisystem_value("ray_instance_custom_index", 1)
863bf215546Sopenharmony_cisystem_value("shader_record_ptr", 1, bit_sizes=[64])
864bf215546Sopenharmony_cisystem_value("cull_mask", 1)
865bf215546Sopenharmony_ci
866bf215546Sopenharmony_ci# Driver-specific viewport scale/offset parameters.
867bf215546Sopenharmony_ci#
868bf215546Sopenharmony_ci# VC4 and V3D need to emit a scaled version of the position in the vertex
869bf215546Sopenharmony_ci# shaders for binning, and having system values lets us move the math for that
870bf215546Sopenharmony_ci# into NIR.
871bf215546Sopenharmony_ci#
872bf215546Sopenharmony_ci# Panfrost needs to implement all coordinate transformation in the
873bf215546Sopenharmony_ci# vertex shader; system values allow us to share this routine in NIR.
874bf215546Sopenharmony_ci#
875bf215546Sopenharmony_ci# RADV uses these for NGG primitive culling.
876bf215546Sopenharmony_cisystem_value("viewport_x_scale", 1)
877bf215546Sopenharmony_cisystem_value("viewport_y_scale", 1)
878bf215546Sopenharmony_cisystem_value("viewport_z_scale", 1)
879bf215546Sopenharmony_cisystem_value("viewport_x_offset", 1)
880bf215546Sopenharmony_cisystem_value("viewport_y_offset", 1)
881bf215546Sopenharmony_cisystem_value("viewport_z_offset", 1)
882bf215546Sopenharmony_cisystem_value("viewport_scale", 3)
883bf215546Sopenharmony_cisystem_value("viewport_offset", 3)
884bf215546Sopenharmony_ci
885bf215546Sopenharmony_ci# Blend constant color values.  Float values are clamped. Vectored versions are
886bf215546Sopenharmony_ci# provided as well for driver convenience
887bf215546Sopenharmony_ci
888bf215546Sopenharmony_cisystem_value("blend_const_color_r_float", 1)
889bf215546Sopenharmony_cisystem_value("blend_const_color_g_float", 1)
890bf215546Sopenharmony_cisystem_value("blend_const_color_b_float", 1)
891bf215546Sopenharmony_cisystem_value("blend_const_color_a_float", 1)
892bf215546Sopenharmony_cisystem_value("blend_const_color_rgba", 4)
893bf215546Sopenharmony_cisystem_value("blend_const_color_rgba8888_unorm", 1)
894bf215546Sopenharmony_cisystem_value("blend_const_color_aaaa8888_unorm", 1)
895bf215546Sopenharmony_ci
896bf215546Sopenharmony_ci# System values for gl_Color, for radeonsi which interpolates these in the
897bf215546Sopenharmony_ci# shader prolog to handle two-sided color without recompiles and therefore
898bf215546Sopenharmony_ci# doesn't handle these in the main shader part like normal varyings.
899bf215546Sopenharmony_cisystem_value("color0", 4)
900bf215546Sopenharmony_cisystem_value("color1", 4)
901bf215546Sopenharmony_ci
902bf215546Sopenharmony_ci# System value for internal compute shaders in radeonsi.
903bf215546Sopenharmony_cisystem_value("user_data_amd", 4)
904bf215546Sopenharmony_ci
905bf215546Sopenharmony_ci# Barycentric coordinate intrinsics.
906bf215546Sopenharmony_ci#
907bf215546Sopenharmony_ci# These set up the barycentric coordinates for a particular interpolation.
908bf215546Sopenharmony_ci# The first four are for the simple cases: pixel, centroid, per-sample
909bf215546Sopenharmony_ci# (at gl_SampleID), or pull model (1/W, 1/I, 1/J) at the pixel center. The next
910bf215546Sopenharmony_ci# two handle interpolating at a specified sample location, or interpolating
911bf215546Sopenharmony_ci# with a vec2 offset,
912bf215546Sopenharmony_ci#
913bf215546Sopenharmony_ci# The interp_mode index should be either the INTERP_MODE_SMOOTH or
914bf215546Sopenharmony_ci# INTERP_MODE_NOPERSPECTIVE enum values.
915bf215546Sopenharmony_ci#
916bf215546Sopenharmony_ci# The vec2 value produced by these intrinsics is intended for use as the
917bf215546Sopenharmony_ci# barycoord source of a load_interpolated_input intrinsic.
918bf215546Sopenharmony_ci
919bf215546Sopenharmony_cidef barycentric(name, dst_comp, src_comp=[]):
920bf215546Sopenharmony_ci    intrinsic("load_barycentric_" + name, src_comp=src_comp, dest_comp=dst_comp,
921bf215546Sopenharmony_ci              indices=[INTERP_MODE], flags=[CAN_ELIMINATE, CAN_REORDER])
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci# no sources.
924bf215546Sopenharmony_cibarycentric("pixel", 2)
925bf215546Sopenharmony_cibarycentric("centroid", 2)
926bf215546Sopenharmony_cibarycentric("sample", 2)
927bf215546Sopenharmony_cibarycentric("model", 3)
928bf215546Sopenharmony_ci# src[] = { sample_id }.
929bf215546Sopenharmony_cibarycentric("at_sample", 2, [1])
930bf215546Sopenharmony_ci# src[] = { offset.xy }.
931bf215546Sopenharmony_cibarycentric("at_offset", 2, [2])
932bf215546Sopenharmony_ci
933bf215546Sopenharmony_ci# Load sample position:
934bf215546Sopenharmony_ci#
935bf215546Sopenharmony_ci# Takes a sample # and returns a sample position.  Used for lowering
936bf215546Sopenharmony_ci# interpolateAtSample() to interpolateAtOffset()
937bf215546Sopenharmony_ciintrinsic("load_sample_pos_from_id", src_comp=[1], dest_comp=2,
938bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
939bf215546Sopenharmony_ci
940bf215546Sopenharmony_ciintrinsic("load_persp_center_rhw_ir3", dest_comp=1,
941bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
942bf215546Sopenharmony_ci
943bf215546Sopenharmony_ci# Load texture scaling values:
944bf215546Sopenharmony_ci#
945bf215546Sopenharmony_ci# Takes a sampler # and returns 1/size values for multiplying to normalize
946bf215546Sopenharmony_ci# texture coordinates.  Used for lowering rect textures.
947bf215546Sopenharmony_ciintrinsic("load_texture_rect_scaling", src_comp=[1], dest_comp=2,
948bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
949bf215546Sopenharmony_ci
950bf215546Sopenharmony_ci# Fragment shader input interpolation delta intrinsic.
951bf215546Sopenharmony_ci#
952bf215546Sopenharmony_ci# For hw where fragment shader input interpolation is handled in shader, the
953bf215546Sopenharmony_ci# load_fs_input_interp deltas intrinsics can be used to load the input deltas
954bf215546Sopenharmony_ci# used for interpolation as follows:
955bf215546Sopenharmony_ci#
956bf215546Sopenharmony_ci#    vec3 iid = load_fs_input_interp_deltas(varying_slot)
957bf215546Sopenharmony_ci#    vec2 bary = load_barycentric_*(...)
958bf215546Sopenharmony_ci#    float result = iid.x + iid.y * bary.y + iid.z * bary.x
959bf215546Sopenharmony_ci
960bf215546Sopenharmony_ciintrinsic("load_fs_input_interp_deltas", src_comp=[1], dest_comp=3,
961bf215546Sopenharmony_ci          indices=[BASE, COMPONENT, IO_SEMANTICS], flags=[CAN_ELIMINATE, CAN_REORDER])
962bf215546Sopenharmony_ci
963bf215546Sopenharmony_ci# Load operations pull data from some piece of GPU memory.  All load
964bf215546Sopenharmony_ci# operations operate in terms of offsets into some piece of theoretical
965bf215546Sopenharmony_ci# memory.  Loads from externally visible memory (UBO and SSBO) simply take a
966bf215546Sopenharmony_ci# byte offset as a source.  Loads from opaque memory (uniforms, inputs, etc.)
967bf215546Sopenharmony_ci# take a base+offset pair where the nir_intrinsic_base() gives the location
968bf215546Sopenharmony_ci# of the start of the variable being loaded and and the offset source is a
969bf215546Sopenharmony_ci# offset into that variable.
970bf215546Sopenharmony_ci#
971bf215546Sopenharmony_ci# Uniform load operations have a nir_intrinsic_range() index that specifies the
972bf215546Sopenharmony_ci# range (starting at base) of the data from which we are loading.  If
973bf215546Sopenharmony_ci# range == 0, then the range is unknown.
974bf215546Sopenharmony_ci#
975bf215546Sopenharmony_ci# UBO load operations have a nir_intrinsic_range_base() and
976bf215546Sopenharmony_ci# nir_intrinsic_range() that specify the byte range [range_base,
977bf215546Sopenharmony_ci# range_base+range] of the UBO that the src offset access must lie within.
978bf215546Sopenharmony_ci#
979bf215546Sopenharmony_ci# Some load operations such as UBO/SSBO load and per_vertex loads take an
980bf215546Sopenharmony_ci# additional source to specify which UBO/SSBO/vertex to load from.
981bf215546Sopenharmony_ci#
982bf215546Sopenharmony_ci# The exact address type depends on the lowering pass that generates the
983bf215546Sopenharmony_ci# load/store intrinsics.  Typically, this is vec4 units for things such as
984bf215546Sopenharmony_ci# varying slots and float units for fragment shader inputs.  UBO and SSBO
985bf215546Sopenharmony_ci# offsets are always in bytes.
986bf215546Sopenharmony_ci
987bf215546Sopenharmony_cidef load(name, src_comp, indices=[], flags=[]):
988bf215546Sopenharmony_ci    intrinsic("load_" + name, src_comp, dest_comp=0, indices=indices,
989bf215546Sopenharmony_ci              flags=flags)
990bf215546Sopenharmony_ci
991bf215546Sopenharmony_ci# src[] = { offset }.
992bf215546Sopenharmony_ciload("uniform", [1], [BASE, RANGE, DEST_TYPE], [CAN_ELIMINATE, CAN_REORDER])
993bf215546Sopenharmony_ci# src[] = { buffer_index, offset }.
994bf215546Sopenharmony_ciload("ubo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET, RANGE_BASE, RANGE], flags=[CAN_ELIMINATE, CAN_REORDER])
995bf215546Sopenharmony_ci# src[] = { buffer_index, offset in vec4 units }.  base is also in vec4 units.
996bf215546Sopenharmony_ciload("ubo_vec4", [-1, 1], [ACCESS, BASE, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER])
997bf215546Sopenharmony_ci# src[] = { offset }.
998bf215546Sopenharmony_ciload("input", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
999bf215546Sopenharmony_ci# src[] = { vertex_id, offset }.
1000bf215546Sopenharmony_ciload("input_vertex", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1001bf215546Sopenharmony_ci# src[] = { vertex, offset }.
1002bf215546Sopenharmony_ciload("per_vertex_input", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1003bf215546Sopenharmony_ci# src[] = { barycoord, offset }.
1004bf215546Sopenharmony_ciload("interpolated_input", [2, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
1005bf215546Sopenharmony_ci
1006bf215546Sopenharmony_ci# src[] = { buffer_index, offset }.
1007bf215546Sopenharmony_ciload("ssbo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1008bf215546Sopenharmony_ci# src[] = { buffer_index }
1009bf215546Sopenharmony_ciload("ssbo_address", [1], [], [CAN_ELIMINATE, CAN_REORDER])
1010bf215546Sopenharmony_ci# src[] = { offset }.
1011bf215546Sopenharmony_ciload("output", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], flags=[CAN_ELIMINATE])
1012bf215546Sopenharmony_ci# src[] = { vertex, offset }.
1013bf215546Sopenharmony_ciload("per_vertex_output", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])
1014bf215546Sopenharmony_ci# src[] = { primitive, offset }.
1015bf215546Sopenharmony_ciload("per_primitive_output", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])
1016bf215546Sopenharmony_ci# src[] = { offset }.
1017bf215546Sopenharmony_ciload("shared", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1018bf215546Sopenharmony_ci# src[] = { offset }.
1019bf215546Sopenharmony_ciload("task_payload", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1020bf215546Sopenharmony_ci# src[] = { offset }.
1021bf215546Sopenharmony_ciload("push_constant", [1], [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
1022bf215546Sopenharmony_ci# src[] = { offset }.
1023bf215546Sopenharmony_ciload("constant", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET],
1024bf215546Sopenharmony_ci     [CAN_ELIMINATE, CAN_REORDER])
1025bf215546Sopenharmony_ci# src[] = { address }.
1026bf215546Sopenharmony_ciload("global", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1027bf215546Sopenharmony_ci# src[] = { address }.
1028bf215546Sopenharmony_ciload("global_2x32", [2], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1029bf215546Sopenharmony_ci# src[] = { address }.
1030bf215546Sopenharmony_ciload("global_constant", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
1031bf215546Sopenharmony_ci     [CAN_ELIMINATE, CAN_REORDER])
1032bf215546Sopenharmony_ci# src[] = { base_address, offset }.
1033bf215546Sopenharmony_ciload("global_constant_offset", [1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
1034bf215546Sopenharmony_ci     [CAN_ELIMINATE, CAN_REORDER])
1035bf215546Sopenharmony_ci# src[] = { base_address, offset, bound }.
1036bf215546Sopenharmony_ciload("global_constant_bounded", [1, 1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
1037bf215546Sopenharmony_ci     [CAN_ELIMINATE, CAN_REORDER])
1038bf215546Sopenharmony_ci# src[] = { address }.
1039bf215546Sopenharmony_ciload("kernel_input", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE, CAN_REORDER])
1040bf215546Sopenharmony_ci# src[] = { offset }.
1041bf215546Sopenharmony_ciload("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1042bf215546Sopenharmony_ci
1043bf215546Sopenharmony_ci# Stores work the same way as loads, except now the first source is the value
1044bf215546Sopenharmony_ci# to store and the second (and possibly third) source specify where to store
1045bf215546Sopenharmony_ci# the value.  SSBO and shared memory stores also have a
1046bf215546Sopenharmony_ci# nir_intrinsic_write_mask()
1047bf215546Sopenharmony_ci
1048bf215546Sopenharmony_cidef store(name, srcs, indices=[], flags=[]):
1049bf215546Sopenharmony_ci    intrinsic("store_" + name, [0] + srcs, indices=indices, flags=flags)
1050bf215546Sopenharmony_ci
1051bf215546Sopenharmony_ci# src[] = { value, offset }.
1052bf215546Sopenharmony_cistore("output", [1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS, IO_XFB, IO_XFB2])
1053bf215546Sopenharmony_ci# src[] = { value, vertex, offset }.
1054bf215546Sopenharmony_cistore("per_vertex_output", [1, 1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
1055bf215546Sopenharmony_ci# src[] = { value, primitive, offset }.
1056bf215546Sopenharmony_cistore("per_primitive_output", [1, 1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
1057bf215546Sopenharmony_ci# src[] = { value, block_index, offset }
1058bf215546Sopenharmony_cistore("ssbo", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1059bf215546Sopenharmony_ci# src[] = { value, offset }.
1060bf215546Sopenharmony_cistore("shared", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
1061bf215546Sopenharmony_ci# src[] = { value, offset }.
1062bf215546Sopenharmony_cistore("task_payload", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
1063bf215546Sopenharmony_ci# src[] = { value, address }.
1064bf215546Sopenharmony_cistore("global", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1065bf215546Sopenharmony_ci# src[] = { value, address }.
1066bf215546Sopenharmony_cistore("global_2x32", [2], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1067bf215546Sopenharmony_ci# src[] = { value, offset }.
1068bf215546Sopenharmony_cistore("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK])
1069bf215546Sopenharmony_ci
1070bf215546Sopenharmony_ci# A bit field to implement SPIRV FragmentShadingRateKHR
1071bf215546Sopenharmony_ci# bit | name              | description
1072bf215546Sopenharmony_ci#   0 | Vertical2Pixels   | Fragment invocation covers 2 pixels vertically
1073bf215546Sopenharmony_ci#   1 | Vertical4Pixels   | Fragment invocation covers 4 pixels vertically
1074bf215546Sopenharmony_ci#   2 | Horizontal2Pixels | Fragment invocation covers 2 pixels horizontally
1075bf215546Sopenharmony_ci#   3 | Horizontal4Pixels | Fragment invocation covers 4 pixels horizontally
1076bf215546Sopenharmony_ciintrinsic("load_frag_shading_rate", dest_comp=1, bit_sizes=[32],
1077bf215546Sopenharmony_ci          flags=[CAN_ELIMINATE, CAN_REORDER])
1078bf215546Sopenharmony_ci
1079bf215546Sopenharmony_ci# OpenCL printf instruction
1080bf215546Sopenharmony_ci# First source is a deref to the format string
1081bf215546Sopenharmony_ci# Second source is a deref to a struct containing the args
1082bf215546Sopenharmony_ci# Dest is success or failure
1083bf215546Sopenharmony_ciintrinsic("printf", src_comp=[1, 1], dest_comp=1, bit_sizes=[32])
1084bf215546Sopenharmony_ci# Since most drivers will want to lower to just dumping args
1085bf215546Sopenharmony_ci# in a buffer, nir_lower_printf will do that, but requires
1086bf215546Sopenharmony_ci# the driver to at least provide a base location
1087bf215546Sopenharmony_cisystem_value("printf_buffer_address", 1, bit_sizes=[32,64])
1088bf215546Sopenharmony_ci
1089bf215546Sopenharmony_ci# Mesh shading MultiView intrinsics
1090bf215546Sopenharmony_cisystem_value("mesh_view_count", 1)
1091bf215546Sopenharmony_ciload("mesh_view_indices", [1], [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
1092bf215546Sopenharmony_ci
1093bf215546Sopenharmony_ci# Used to pass values from the preamble to the main shader.
1094bf215546Sopenharmony_ci# This should use something similar to Vulkan push constants and load_preamble
1095bf215546Sopenharmony_ci# should be relatively cheap.
1096bf215546Sopenharmony_ci# For now we only support accesses with a constant offset.
1097bf215546Sopenharmony_ciload("preamble", [], indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
1098bf215546Sopenharmony_cistore("preamble", [], indices=[BASE])
1099bf215546Sopenharmony_ci
1100bf215546Sopenharmony_ci# IR3-specific version of most SSBO intrinsics. The only different
1101bf215546Sopenharmony_ci# compare to the originals is that they add an extra source to hold
1102bf215546Sopenharmony_ci# the dword-offset, which is needed by the backend code apart from
1103bf215546Sopenharmony_ci# the byte-offset already provided by NIR in one of the sources.
1104bf215546Sopenharmony_ci#
1105bf215546Sopenharmony_ci# NIR lowering pass 'ir3_nir_lower_io_offset' will replace the
1106bf215546Sopenharmony_ci# original SSBO intrinsics by these, placing the computed
1107bf215546Sopenharmony_ci# dword-offset always in the last source.
1108bf215546Sopenharmony_ci#
1109bf215546Sopenharmony_ci# The float versions are not handled because those are not supported
1110bf215546Sopenharmony_ci# by the backend.
1111bf215546Sopenharmony_cistore("ssbo_ir3", [1, 1, 1],
1112bf215546Sopenharmony_ci      indices=[WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1113bf215546Sopenharmony_ciload("ssbo_ir3",  [1, 1, 1],
1114bf215546Sopenharmony_ci     indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
1115bf215546Sopenharmony_ciintrinsic("ssbo_atomic_add_ir3",        src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1116bf215546Sopenharmony_ciintrinsic("ssbo_atomic_imin_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1117bf215546Sopenharmony_ciintrinsic("ssbo_atomic_umin_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1118bf215546Sopenharmony_ciintrinsic("ssbo_atomic_imax_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1119bf215546Sopenharmony_ciintrinsic("ssbo_atomic_umax_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1120bf215546Sopenharmony_ciintrinsic("ssbo_atomic_and_ir3",        src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1121bf215546Sopenharmony_ciintrinsic("ssbo_atomic_or_ir3",         src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1122bf215546Sopenharmony_ciintrinsic("ssbo_atomic_xor_ir3",        src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1123bf215546Sopenharmony_ciintrinsic("ssbo_atomic_exchange_ir3",   src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
1124bf215546Sopenharmony_ciintrinsic("ssbo_atomic_comp_swap_ir3",  src_comp=[1, 1, 1, 1, 1], dest_comp=1, indices=[ACCESS])
1125bf215546Sopenharmony_ci
1126bf215546Sopenharmony_ci# System values for freedreno geometry shaders.
1127bf215546Sopenharmony_cisystem_value("vs_primitive_stride_ir3", 1)
1128bf215546Sopenharmony_cisystem_value("vs_vertex_stride_ir3", 1)
1129bf215546Sopenharmony_cisystem_value("gs_header_ir3", 1)
1130bf215546Sopenharmony_cisystem_value("primitive_location_ir3", 1, indices=[DRIVER_LOCATION])
1131bf215546Sopenharmony_ci
1132bf215546Sopenharmony_ci# System values for freedreno tessellation shaders.
1133bf215546Sopenharmony_cisystem_value("hs_patch_stride_ir3", 1)
1134bf215546Sopenharmony_cisystem_value("tess_factor_base_ir3", 2)
1135bf215546Sopenharmony_cisystem_value("tess_param_base_ir3", 2)
1136bf215546Sopenharmony_cisystem_value("tcs_header_ir3", 1)
1137bf215546Sopenharmony_cisystem_value("rel_patch_id_ir3", 1)
1138bf215546Sopenharmony_ci
1139bf215546Sopenharmony_ci# System values for freedreno compute shaders.
1140bf215546Sopenharmony_cisystem_value("subgroup_id_shift_ir3", 1)
1141bf215546Sopenharmony_ci
1142bf215546Sopenharmony_ci# IR3-specific intrinsics for tessellation control shaders.  cond_end_ir3 end
1143bf215546Sopenharmony_ci# the shader when src0 is false and is used to narrow down the TCS shader to
1144bf215546Sopenharmony_ci# just thread 0 before writing out tessellation levels.
1145bf215546Sopenharmony_ciintrinsic("cond_end_ir3", src_comp=[1])
1146bf215546Sopenharmony_ci# end_patch_ir3 is used just before thread 0 exist the TCS and presumably
1147bf215546Sopenharmony_ci# signals the TE that the patch is complete and can be tessellated.
1148bf215546Sopenharmony_ciintrinsic("end_patch_ir3")
1149bf215546Sopenharmony_ci
1150bf215546Sopenharmony_ci# IR3-specific load/store intrinsics. These access a buffer used to pass data
1151bf215546Sopenharmony_ci# between geometry stages - perhaps it's explicit access to the vertex cache.
1152bf215546Sopenharmony_ci
1153bf215546Sopenharmony_ci# src[] = { value, offset }.
1154bf215546Sopenharmony_cistore("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET])
1155bf215546Sopenharmony_ci# src[] = { offset }.
1156bf215546Sopenharmony_ciload("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1157bf215546Sopenharmony_ci
1158bf215546Sopenharmony_ci# IR3-specific load/store global intrinsics. They take a 64-bit base address
1159bf215546Sopenharmony_ci# and a 32-bit offset.  The hardware will add the base and the offset, which
1160bf215546Sopenharmony_ci# saves us from doing 64-bit math on the base address.
1161bf215546Sopenharmony_ci
1162bf215546Sopenharmony_ci# src[] = { value, address(vec2 of hi+lo uint32_t), offset }.
1163bf215546Sopenharmony_ci# const_index[] = { write_mask, align_mul, align_offset }
1164bf215546Sopenharmony_cistore("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1165bf215546Sopenharmony_ci# src[] = { address(vec2 of hi+lo uint32_t), offset }.
1166bf215546Sopenharmony_ci# const_index[] = { access, align_mul, align_offset }
1167bf215546Sopenharmony_ciload("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
1168bf215546Sopenharmony_ci
1169bf215546Sopenharmony_ci# IR3-specific bindless handle specifier. Similar to vulkan_resource_index, but
1170bf215546Sopenharmony_ci# without the binding because the hardware expects a single flattened index
1171bf215546Sopenharmony_ci# rather than a (binding, index) pair. We may also want to use this with GL.
1172bf215546Sopenharmony_ci# Note that this doesn't actually turn into a HW instruction.
1173bf215546Sopenharmony_ciintrinsic("bindless_resource_ir3", [1], dest_comp=1, indices=[DESC_SET], flags=[CAN_ELIMINATE, CAN_REORDER])
1174bf215546Sopenharmony_ci
1175bf215546Sopenharmony_ci# IR3-specific intrinsics for shader preamble. These are meant to be used like
1176bf215546Sopenharmony_ci# this:
1177bf215546Sopenharmony_ci#
1178bf215546Sopenharmony_ci# if (preamble_start()) {
1179bf215546Sopenharmony_ci#    if (subgroupElect()) {
1180bf215546Sopenharmony_ci#       // preamble
1181bf215546Sopenharmony_ci#       ...
1182bf215546Sopenharmony_ci#       preamble_end();
1183bf215546Sopenharmony_ci#    }
1184bf215546Sopenharmony_ci# }
1185bf215546Sopenharmony_ci# // main shader
1186bf215546Sopenharmony_ci# ...
1187bf215546Sopenharmony_ci
1188bf215546Sopenharmony_ciintrinsic("preamble_start_ir3", [], dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
1189bf215546Sopenharmony_ci
1190bf215546Sopenharmony_cibarrier("preamble_end_ir3")
1191bf215546Sopenharmony_ci
1192bf215546Sopenharmony_ci# IR3-specific intrinsic for stc. Should be used in the shader preamble.
1193bf215546Sopenharmony_cistore("uniform_ir3", [], indices=[BASE])
1194bf215546Sopenharmony_ci
1195bf215546Sopenharmony_ci# IR3-specific intrinsic for ldc.k. Copies UBO to constant file.
1196bf215546Sopenharmony_ci# base is the const file base in components, range is the amount to copy in
1197bf215546Sopenharmony_ci# vec4's.
1198bf215546Sopenharmony_ciintrinsic("copy_ubo_to_uniform_ir3", [1, 1], indices=[BASE, RANGE])
1199bf215546Sopenharmony_ci
1200bf215546Sopenharmony_ci# DXIL specific intrinsics
1201bf215546Sopenharmony_ci# src[] = { value, mask, index, offset }.
1202bf215546Sopenharmony_ciintrinsic("store_ssbo_masked_dxil", [1, 1, 1, 1])
1203bf215546Sopenharmony_ci# src[] = { value, index }.
1204bf215546Sopenharmony_ciintrinsic("store_shared_dxil", [1, 1])
1205bf215546Sopenharmony_ci# src[] = { value, mask, index }.
1206bf215546Sopenharmony_ciintrinsic("store_shared_masked_dxil", [1, 1, 1])
1207bf215546Sopenharmony_ci# src[] = { value, index }.
1208bf215546Sopenharmony_ciintrinsic("store_scratch_dxil", [1, 1])
1209bf215546Sopenharmony_ci# src[] = { index }.
1210bf215546Sopenharmony_ciload("shared_dxil", [1], [], [CAN_ELIMINATE])
1211bf215546Sopenharmony_ci# src[] = { index }.
1212bf215546Sopenharmony_ciload("scratch_dxil", [1], [], [CAN_ELIMINATE])
1213bf215546Sopenharmony_ci# src[] = { deref_var, offset }
1214bf215546Sopenharmony_ciload("ptr_dxil", [1, 1], [], [])
1215bf215546Sopenharmony_ci# src[] = { index, 16-byte-based-offset }
1216bf215546Sopenharmony_ciload("ubo_dxil", [1, 1], [], [CAN_ELIMINATE, CAN_REORDER])
1217bf215546Sopenharmony_ci
1218bf215546Sopenharmony_ci# DXIL Shared atomic intrinsics
1219bf215546Sopenharmony_ci#
1220bf215546Sopenharmony_ci# All of the shared variable atomic memory operations read a value from
1221bf215546Sopenharmony_ci# memory, compute a new value using one of the operations below, write the
1222bf215546Sopenharmony_ci# new value to memory, and return the original value read.
1223bf215546Sopenharmony_ci#
1224bf215546Sopenharmony_ci# All operations take 2 sources:
1225bf215546Sopenharmony_ci#
1226bf215546Sopenharmony_ci# 0: The index in the i32 array for by the shared memory region
1227bf215546Sopenharmony_ci# 1: The data parameter to the atomic function (i.e. the value to add
1228bf215546Sopenharmony_ci#    in shared_atomic_add, etc).
1229bf215546Sopenharmony_ciintrinsic("shared_atomic_add_dxil",  src_comp=[1, 1], dest_comp=1)
1230bf215546Sopenharmony_ciintrinsic("shared_atomic_imin_dxil", src_comp=[1, 1], dest_comp=1)
1231bf215546Sopenharmony_ciintrinsic("shared_atomic_umin_dxil", src_comp=[1, 1], dest_comp=1)
1232bf215546Sopenharmony_ciintrinsic("shared_atomic_imax_dxil", src_comp=[1, 1], dest_comp=1)
1233bf215546Sopenharmony_ciintrinsic("shared_atomic_umax_dxil", src_comp=[1, 1], dest_comp=1)
1234bf215546Sopenharmony_ciintrinsic("shared_atomic_and_dxil",  src_comp=[1, 1], dest_comp=1)
1235bf215546Sopenharmony_ciintrinsic("shared_atomic_or_dxil",   src_comp=[1, 1], dest_comp=1)
1236bf215546Sopenharmony_ciintrinsic("shared_atomic_xor_dxil",  src_comp=[1, 1], dest_comp=1)
1237bf215546Sopenharmony_ciintrinsic("shared_atomic_exchange_dxil", src_comp=[1, 1], dest_comp=1)
1238bf215546Sopenharmony_ciintrinsic("shared_atomic_comp_swap_dxil", src_comp=[1, 1, 1], dest_comp=1)
1239bf215546Sopenharmony_ci
1240bf215546Sopenharmony_ci# Intrinsics used by the Midgard/Bifrost blend pipeline. These are defined
1241bf215546Sopenharmony_ci# within a blend shader to read/write the raw value from the tile buffer,
1242bf215546Sopenharmony_ci# without applying any format conversion in the process. If the shader needs
1243bf215546Sopenharmony_ci# usable pixel values, it must apply format conversions itself.
1244bf215546Sopenharmony_ci#
1245bf215546Sopenharmony_ci# These definitions are generic, but they are explicitly vendored to prevent
1246bf215546Sopenharmony_ci# other drivers from using them, as their semantics is defined in terms of the
1247bf215546Sopenharmony_ci# Midgard/Bifrost hardware tile buffer and may not line up with anything sane.
1248bf215546Sopenharmony_ci# One notable divergence is sRGB, which is asymmetric: raw_input_pan requires
1249bf215546Sopenharmony_ci# an sRGB->linear conversion, but linear values should be written to
1250bf215546Sopenharmony_ci# raw_output_pan and the hardware handles linear->sRGB.
1251bf215546Sopenharmony_ci
1252bf215546Sopenharmony_ci# src[] = { value }
1253bf215546Sopenharmony_cistore("raw_output_pan", [], [])
1254bf215546Sopenharmony_cistore("combined_output_pan", [1, 1, 1, 4], [BASE, COMPONENT, SRC_TYPE, DEST_TYPE])
1255bf215546Sopenharmony_ciload("raw_output_pan", [1], [BASE], [CAN_ELIMINATE, CAN_REORDER])
1256bf215546Sopenharmony_ci
1257bf215546Sopenharmony_ci# Loads the sampler paramaters <min_lod, max_lod, lod_bias>
1258bf215546Sopenharmony_ci# src[] = { sampler_index }
1259bf215546Sopenharmony_ciload("sampler_lod_parameters_pan", [1], flags=[CAN_ELIMINATE, CAN_REORDER])
1260bf215546Sopenharmony_ci
1261bf215546Sopenharmony_ci# Loads the sample position array on Bifrost, in a packed Arm-specific format
1262bf215546Sopenharmony_cisystem_value("sample_positions_pan", 1, bit_sizes=[64])
1263bf215546Sopenharmony_ci
1264bf215546Sopenharmony_ci# R600 specific instrincs
1265bf215546Sopenharmony_ci#
1266bf215546Sopenharmony_ci# location where the tesselation data is stored in LDS
1267bf215546Sopenharmony_cisystem_value("tcs_in_param_base_r600", 4)
1268bf215546Sopenharmony_cisystem_value("tcs_out_param_base_r600", 4)
1269bf215546Sopenharmony_cisystem_value("tcs_rel_patch_id_r600", 1)
1270bf215546Sopenharmony_cisystem_value("tcs_tess_factor_base_r600", 1)
1271bf215546Sopenharmony_ci
1272bf215546Sopenharmony_ci# the tess coords come as xy only, z has to be calculated
1273bf215546Sopenharmony_cisystem_value("tess_coord_r600", 2)
1274bf215546Sopenharmony_ci
1275bf215546Sopenharmony_ci# load as many components as needed giving per-component addresses
1276bf215546Sopenharmony_ciintrinsic("load_local_shared_r600", src_comp=[0], dest_comp=0, indices = [], flags = [CAN_ELIMINATE])
1277bf215546Sopenharmony_ci
1278bf215546Sopenharmony_cistore("local_shared_r600", [1], [WRITE_MASK])
1279bf215546Sopenharmony_cistore("tf_r600", [])
1280bf215546Sopenharmony_ci
1281bf215546Sopenharmony_ci# AMD GCN/RDNA specific intrinsics
1282bf215546Sopenharmony_ci
1283bf215546Sopenharmony_ci# src[] = { descriptor, base address, scalar offset }
1284bf215546Sopenharmony_ciintrinsic("load_buffer_amd", src_comp=[4, 1, 1], dest_comp=0, indices=[BASE, IS_SWIZZLED, SLC_AMD, MEMORY_MODES], flags=[CAN_ELIMINATE])
1285bf215546Sopenharmony_ci# src[] = { store value, descriptor, base address, scalar offset }
1286bf215546Sopenharmony_ciintrinsic("store_buffer_amd", src_comp=[0, 4, 1, 1], indices=[BASE, WRITE_MASK, IS_SWIZZLED, SLC_AMD, MEMORY_MODES])
1287bf215546Sopenharmony_ci
1288bf215546Sopenharmony_ci# src[] = { address, unsigned 32-bit offset }.
1289bf215546Sopenharmony_ciload("global_amd", [1, 1], indices=[BASE, ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
1290bf215546Sopenharmony_ci# src[] = { value, address, unsigned 32-bit offset }.
1291bf215546Sopenharmony_cistore("global_amd", [1, 1], indices=[BASE, ACCESS, ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK])
1292bf215546Sopenharmony_ci
1293bf215546Sopenharmony_ci# Same as shared_atomic_add, but with GDS. src[] = {store_val, gds_addr, m0}
1294bf215546Sopenharmony_ciintrinsic("gds_atomic_add_amd",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
1295bf215546Sopenharmony_ci
1296bf215546Sopenharmony_ci# Descriptor where TCS outputs are stored for TES
1297bf215546Sopenharmony_cisystem_value("ring_tess_offchip_amd", 4)
1298bf215546Sopenharmony_cisystem_value("ring_tess_offchip_offset_amd", 1)
1299bf215546Sopenharmony_ci# Descriptor where TCS outputs are stored for the HW tessellator
1300bf215546Sopenharmony_cisystem_value("ring_tess_factors_amd", 4)
1301bf215546Sopenharmony_cisystem_value("ring_tess_factors_offset_amd", 1)
1302bf215546Sopenharmony_ci# Descriptor where ES outputs are stored for GS to read on GFX6-8
1303bf215546Sopenharmony_cisystem_value("ring_esgs_amd", 4)
1304bf215546Sopenharmony_cisystem_value("ring_es2gs_offset_amd", 1)
1305bf215546Sopenharmony_ci# Address of the task shader draw ring (used for VARYING_SLOT_TASK_COUNT)
1306bf215546Sopenharmony_cisystem_value("ring_task_draw_amd", 4)
1307bf215546Sopenharmony_ci# Address of the task shader payload ring (used for all other outputs)
1308bf215546Sopenharmony_cisystem_value("ring_task_payload_amd", 4)
1309bf215546Sopenharmony_ci# Address of the mesh shader scratch ring (used for excess mesh shader outputs)
1310bf215546Sopenharmony_cisystem_value("ring_mesh_scratch_amd", 4)
1311bf215546Sopenharmony_cisystem_value("ring_mesh_scratch_offset_amd", 1)
1312bf215546Sopenharmony_ci# Pointer into the draw and payload rings
1313bf215546Sopenharmony_cisystem_value("task_ring_entry_amd", 1)
1314bf215546Sopenharmony_ci# Pointer into the draw and payload rings
1315bf215546Sopenharmony_cisystem_value("task_ib_addr", 2)
1316bf215546Sopenharmony_cisystem_value("task_ib_stride", 1)
1317bf215546Sopenharmony_ci
1318bf215546Sopenharmony_ci# Number of patches processed by each TCS workgroup
1319bf215546Sopenharmony_cisystem_value("tcs_num_patches_amd", 1)
1320bf215546Sopenharmony_ci# Relative tessellation patch ID within the current workgroup
1321bf215546Sopenharmony_cisystem_value("tess_rel_patch_id_amd", 1)
1322bf215546Sopenharmony_ci# Vertex offsets used for GS per-vertex inputs
1323bf215546Sopenharmony_cisystem_value("gs_vertex_offset_amd", 1, [BASE])
1324bf215546Sopenharmony_ci
1325bf215546Sopenharmony_ci# AMD merged shader intrinsics
1326bf215546Sopenharmony_ci
1327bf215546Sopenharmony_ci# Whether the current invocation has an input vertex / primitive to process (also known as "ES thread" or "GS thread").
1328bf215546Sopenharmony_ci# Not safe to reorder because it changes after overwrite_subgroup_num_vertices_and_primitives_amd.
1329bf215546Sopenharmony_ci# Also, the generated code is more optimal if they are not CSE'd.
1330bf215546Sopenharmony_ciintrinsic("has_input_vertex_amd", src_comp=[], dest_comp=1, bit_sizes=[1], indices=[])
1331bf215546Sopenharmony_ciintrinsic("has_input_primitive_amd", src_comp=[], dest_comp=1, bit_sizes=[1], indices=[])
1332bf215546Sopenharmony_ci
1333bf215546Sopenharmony_ci# AMD NGG intrinsics
1334bf215546Sopenharmony_ci
1335bf215546Sopenharmony_ci# Number of initial input vertices in the current workgroup.
1336bf215546Sopenharmony_cisystem_value("workgroup_num_input_vertices_amd", 1)
1337bf215546Sopenharmony_ci# Number of initial input primitives in the current workgroup.
1338bf215546Sopenharmony_cisystem_value("workgroup_num_input_primitives_amd", 1)
1339bf215546Sopenharmony_ci# For NGG passthrough mode only. Pre-packed argument for export_primitive_amd.
1340bf215546Sopenharmony_cisystem_value("packed_passthrough_primitive_amd", 1)
1341bf215546Sopenharmony_ci# Whether NGG GS should execute shader query.
1342bf215546Sopenharmony_cisystem_value("shader_query_enabled_amd", dest_comp=1, bit_sizes=[1])
1343bf215546Sopenharmony_ci# Whether the shader should cull front facing triangles.
1344bf215546Sopenharmony_ciintrinsic("load_cull_front_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1345bf215546Sopenharmony_ci# Whether the shader should cull back facing triangles.
1346bf215546Sopenharmony_ciintrinsic("load_cull_back_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1347bf215546Sopenharmony_ci# True if face culling should use CCW (false if CW).
1348bf215546Sopenharmony_ciintrinsic("load_cull_ccw_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1349bf215546Sopenharmony_ci# Whether the shader should cull small primitives that are not visible in a pixel.
1350bf215546Sopenharmony_ciintrinsic("load_cull_small_primitives_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1351bf215546Sopenharmony_ci# Whether any culling setting is enabled in the shader.
1352bf215546Sopenharmony_ciintrinsic("load_cull_any_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
1353bf215546Sopenharmony_ci# Small primitive culling precision
1354bf215546Sopenharmony_ciintrinsic("load_cull_small_prim_precision_amd", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
1355bf215546Sopenharmony_ci# Initial edge flags in a Vertex Shader, packed into the format the HW needs for primitive export.
1356bf215546Sopenharmony_ciintrinsic("load_initial_edgeflags_amd", src_comp=[], dest_comp=1, bit_sizes=[32], indices=[])
1357bf215546Sopenharmony_ci# Exports the current invocation's vertex. This is a placeholder where all vertex attribute export instructions should be emitted.
1358bf215546Sopenharmony_ciintrinsic("export_vertex_amd", src_comp=[], indices=[])
1359bf215546Sopenharmony_ci# Exports the current invocation's primitive. src[] = {packed_primitive_data}.
1360bf215546Sopenharmony_ciintrinsic("export_primitive_amd", src_comp=[1], indices=[])
1361bf215546Sopenharmony_ci# Allocates export space for vertices and primitives. src[] = {num_vertices, num_primitives}.
1362bf215546Sopenharmony_ciintrinsic("alloc_vertices_and_primitives_amd", src_comp=[1, 1], indices=[])
1363bf215546Sopenharmony_ci# Overwrites VS input registers, for use with vertex compaction after culling. src = {vertex_id, instance_id}.
1364bf215546Sopenharmony_ciintrinsic("overwrite_vs_arguments_amd", src_comp=[1, 1], indices=[])
1365bf215546Sopenharmony_ci# Overwrites TES input registers, for use with vertex compaction after culling. src = {tes_u, tes_v, rel_patch_id, patch_id}.
1366bf215546Sopenharmony_ciintrinsic("overwrite_tes_arguments_amd", src_comp=[1, 1, 1, 1], indices=[])
1367bf215546Sopenharmony_ci
1368bf215546Sopenharmony_ci# The address of the sbt descriptors.
1369bf215546Sopenharmony_cisystem_value("sbt_base_amd", 1, bit_sizes=[64])
1370bf215546Sopenharmony_ci
1371bf215546Sopenharmony_ci# 1. HW descriptor
1372bf215546Sopenharmony_ci# 2. BVH node(64-bit pointer as 2x32 ...)
1373bf215546Sopenharmony_ci# 3. ray extent
1374bf215546Sopenharmony_ci# 4. ray origin
1375bf215546Sopenharmony_ci# 5. ray direction
1376bf215546Sopenharmony_ci# 6. inverse ray direction (componentwise 1.0/ray direction)
1377bf215546Sopenharmony_ciintrinsic("bvh64_intersect_ray_amd", [4, 2, 1, 3, 3, 3], 4, flags=[CAN_ELIMINATE, CAN_REORDER])
1378bf215546Sopenharmony_ci
1379bf215546Sopenharmony_ci# Return of a callable in raytracing pipelines
1380bf215546Sopenharmony_ciintrinsic("rt_return_amd")
1381bf215546Sopenharmony_ci
1382bf215546Sopenharmony_ci# offset into scratch for the input callable data in a raytracing pipeline.
1383bf215546Sopenharmony_cisystem_value("rt_arg_scratch_offset_amd", 1)
1384bf215546Sopenharmony_ci
1385bf215546Sopenharmony_ci# Whether to call the anyhit shader for an intersection in an intersection shader.
1386bf215546Sopenharmony_cisystem_value("intersection_opaque_amd", 1, bit_sizes=[1])
1387bf215546Sopenharmony_ci
1388bf215546Sopenharmony_ci# Used for indirect ray tracing.
1389bf215546Sopenharmony_cisystem_value("ray_launch_size_addr_amd", 1, bit_sizes=[64])
1390bf215546Sopenharmony_ci
1391bf215546Sopenharmony_ci# Load forced VRS rates.
1392bf215546Sopenharmony_ciintrinsic("load_force_vrs_rates_amd", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
1393bf215546Sopenharmony_ci
1394bf215546Sopenharmony_ciintrinsic("load_scalar_arg_amd", dest_comp=0, bit_sizes=[32], indices=[BASE, ARG_UPPER_BOUND_U32_AMD], flags=[CAN_ELIMINATE, CAN_REORDER])
1395bf215546Sopenharmony_ciintrinsic("load_vector_arg_amd", dest_comp=0, bit_sizes=[32], indices=[BASE, ARG_UPPER_BOUND_U32_AMD], flags=[CAN_ELIMINATE, CAN_REORDER])
1396bf215546Sopenharmony_ci
1397bf215546Sopenharmony_ci# src[] = { 64-bit base address, 32-bit offset }.
1398bf215546Sopenharmony_ciintrinsic("load_smem_amd", src_comp=[1, 1], dest_comp=0, bit_sizes=[32],
1399bf215546Sopenharmony_ci                           indices=[ALIGN_MUL, ALIGN_OFFSET],
1400bf215546Sopenharmony_ci                           flags=[CAN_ELIMINATE, CAN_REORDER])
1401bf215546Sopenharmony_ci
1402bf215546Sopenharmony_ci# src[] = { offset }.
1403bf215546Sopenharmony_ciintrinsic("load_shared2_amd", [1], dest_comp=2, indices=[OFFSET0, OFFSET1, ST64], flags=[CAN_ELIMINATE])
1404bf215546Sopenharmony_ci
1405bf215546Sopenharmony_ci# src[] = { value, offset }.
1406bf215546Sopenharmony_ciintrinsic("store_shared2_amd", [2, 1], indices=[OFFSET0, OFFSET1, ST64])
1407bf215546Sopenharmony_ci
1408bf215546Sopenharmony_ci# Vertex stride in LS-HS buffer
1409bf215546Sopenharmony_cisystem_value("lshs_vertex_stride_amd", 1)
1410bf215546Sopenharmony_ci
1411bf215546Sopenharmony_ci# Per patch data offset in HS VRAM output buffer
1412bf215546Sopenharmony_cisystem_value("hs_out_patch_data_offset_amd", 1)
1413bf215546Sopenharmony_ci
1414bf215546Sopenharmony_ci# V3D-specific instrinc for tile buffer color reads.
1415bf215546Sopenharmony_ci#
1416bf215546Sopenharmony_ci# The hardware requires that we read the samples and components of a pixel
1417bf215546Sopenharmony_ci# in order, so we cannot eliminate or remove any loads in a sequence.
1418bf215546Sopenharmony_ci#
1419bf215546Sopenharmony_ci# src[] = { render_target }
1420bf215546Sopenharmony_ci# BASE = sample index
1421bf215546Sopenharmony_ciload("tlb_color_v3d", [1], [BASE, COMPONENT], [])
1422bf215546Sopenharmony_ci
1423bf215546Sopenharmony_ci# V3D-specific instrinc for per-sample tile buffer color writes.
1424bf215546Sopenharmony_ci#
1425bf215546Sopenharmony_ci# The driver backend needs to identify per-sample color writes and emit
1426bf215546Sopenharmony_ci# specific code for them.
1427bf215546Sopenharmony_ci#
1428bf215546Sopenharmony_ci# src[] = { value, render_target }
1429bf215546Sopenharmony_ci# BASE = sample index
1430bf215546Sopenharmony_cistore("tlb_sample_color_v3d", [1], [BASE, COMPONENT, SRC_TYPE], [])
1431bf215546Sopenharmony_ci
1432bf215546Sopenharmony_ci# V3D-specific intrinsic to load the number of layers attached to
1433bf215546Sopenharmony_ci# the target framebuffer
1434bf215546Sopenharmony_ciintrinsic("load_fb_layers_v3d", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
1435bf215546Sopenharmony_ci
1436bf215546Sopenharmony_ci# Logical complement of load_front_face, mapping to an AGX system value
1437bf215546Sopenharmony_cisystem_value("back_face_agx", 1, bit_sizes=[1, 32])
1438bf215546Sopenharmony_ci
1439bf215546Sopenharmony_ci# Intel-specific query for loading from the brw_image_param struct passed
1440bf215546Sopenharmony_ci# into the shader as a uniform.  The variable is a deref to the image
1441bf215546Sopenharmony_ci# variable. The const index specifies which of the six parameters to load.
1442bf215546Sopenharmony_ciintrinsic("image_deref_load_param_intel", src_comp=[1], dest_comp=0,
1443bf215546Sopenharmony_ci          indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
1444bf215546Sopenharmony_ciimage("load_raw_intel", src_comp=[1], dest_comp=0,
1445bf215546Sopenharmony_ci      flags=[CAN_ELIMINATE])
1446bf215546Sopenharmony_ciimage("store_raw_intel", src_comp=[1, 0])
1447bf215546Sopenharmony_ci
1448bf215546Sopenharmony_ci# Intrinsic to load a block of at least 32B of constant data from a 64-bit
1449bf215546Sopenharmony_ci# global memory address.  The memory address must be uniform and 32B-aligned.
1450bf215546Sopenharmony_ci# The second source is a predicate which indicates whether or not to actually
1451bf215546Sopenharmony_ci# do the load.
1452bf215546Sopenharmony_ci# src[] = { address, predicate }.
1453bf215546Sopenharmony_ciintrinsic("load_global_const_block_intel", src_comp=[1, 1], dest_comp=0,
1454bf215546Sopenharmony_ci          bit_sizes=[32], indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
1455bf215546Sopenharmony_ci
1456bf215546Sopenharmony_ci# Number of data items being operated on for a SIMD program.
1457bf215546Sopenharmony_cisystem_value("simd_width_intel", 1)
1458bf215546Sopenharmony_ci
1459bf215546Sopenharmony_ci# Load a relocatable 32-bit value
1460bf215546Sopenharmony_ciintrinsic("load_reloc_const_intel", dest_comp=1, bit_sizes=[32],
1461bf215546Sopenharmony_ci          indices=[PARAM_IDX], flags=[CAN_ELIMINATE, CAN_REORDER])
1462bf215546Sopenharmony_ci
1463bf215546Sopenharmony_ci# 64-bit global address for a Vulkan descriptor set
1464bf215546Sopenharmony_ci# src[0] = { set }
1465bf215546Sopenharmony_ciintrinsic("load_desc_set_address_intel", dest_comp=1, bit_sizes=[64],
1466bf215546Sopenharmony_ci          src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])
1467bf215546Sopenharmony_ci
1468bf215546Sopenharmony_ci# OpSubgroupBlockReadINTEL and OpSubgroupBlockWriteINTEL from SPV_INTEL_subgroups.
1469bf215546Sopenharmony_ciintrinsic("load_deref_block_intel", dest_comp=0, src_comp=[-1],
1470bf215546Sopenharmony_ci          indices=[ACCESS], flags=[CAN_ELIMINATE])
1471bf215546Sopenharmony_ciintrinsic("store_deref_block_intel", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])
1472bf215546Sopenharmony_ci
1473bf215546Sopenharmony_ci# src[] = { address }.
1474bf215546Sopenharmony_ciload("global_block_intel", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1475bf215546Sopenharmony_ci
1476bf215546Sopenharmony_ci# src[] = { buffer_index, offset }.
1477bf215546Sopenharmony_ciload("ssbo_block_intel", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1478bf215546Sopenharmony_ci
1479bf215546Sopenharmony_ci# src[] = { offset }.
1480bf215546Sopenharmony_ciload("shared_block_intel", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
1481bf215546Sopenharmony_ci
1482bf215546Sopenharmony_ci# src[] = { value, address }.
1483bf215546Sopenharmony_cistore("global_block_intel", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1484bf215546Sopenharmony_ci
1485bf215546Sopenharmony_ci# src[] = { value, block_index, offset }
1486bf215546Sopenharmony_cistore("ssbo_block_intel", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
1487bf215546Sopenharmony_ci
1488bf215546Sopenharmony_ci# src[] = { value, offset }.
1489bf215546Sopenharmony_cistore("shared_block_intel", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
1490bf215546Sopenharmony_ci
1491bf215546Sopenharmony_ci# Intrinsics for Intel mesh shading
1492bf215546Sopenharmony_cisystem_value("mesh_inline_data_intel", 1, [ALIGN_OFFSET], bit_sizes=[32, 64])
1493bf215546Sopenharmony_ci
1494bf215546Sopenharmony_ci# Intrinsics for Intel bindless thread dispatch
1495bf215546Sopenharmony_ci# BASE=brw_topoloy_id
1496bf215546Sopenharmony_cisystem_value("topology_id_intel", 1, indices=[BASE])
1497bf215546Sopenharmony_cisystem_value("btd_stack_id_intel", 1)
1498bf215546Sopenharmony_cisystem_value("btd_global_arg_addr_intel", 1, bit_sizes=[64])
1499bf215546Sopenharmony_cisystem_value("btd_local_arg_addr_intel", 1, bit_sizes=[64])
1500bf215546Sopenharmony_cisystem_value("btd_resume_sbt_addr_intel", 1, bit_sizes=[64])
1501bf215546Sopenharmony_ci# src[] = { global_arg_addr, btd_record }
1502bf215546Sopenharmony_ciintrinsic("btd_spawn_intel", src_comp=[1, 1])
1503bf215546Sopenharmony_ci# RANGE=stack_size
1504bf215546Sopenharmony_ciintrinsic("btd_stack_push_intel", indices=[STACK_SIZE])
1505bf215546Sopenharmony_ci# src[] = { }
1506bf215546Sopenharmony_ciintrinsic("btd_retire_intel")
1507bf215546Sopenharmony_ci
1508bf215546Sopenharmony_ci# Intel-specific ray-tracing intrinsic
1509bf215546Sopenharmony_ci# src[] = { globals, level, operation } SYNCHRONOUS=synchronous
1510bf215546Sopenharmony_ciintrinsic("trace_ray_intel", src_comp=[1, 1, 1], indices=[SYNCHRONOUS])
1511bf215546Sopenharmony_ci
1512bf215546Sopenharmony_ci# System values used for ray-tracing on Intel
1513bf215546Sopenharmony_cisystem_value("ray_base_mem_addr_intel", 1, bit_sizes=[64])
1514bf215546Sopenharmony_cisystem_value("ray_hw_stack_size_intel", 1)
1515bf215546Sopenharmony_cisystem_value("ray_sw_stack_size_intel", 1)
1516bf215546Sopenharmony_cisystem_value("ray_num_dss_rt_stacks_intel", 1)
1517bf215546Sopenharmony_cisystem_value("ray_hit_sbt_addr_intel", 1, bit_sizes=[64])
1518bf215546Sopenharmony_cisystem_value("ray_hit_sbt_stride_intel", 1, bit_sizes=[16])
1519bf215546Sopenharmony_cisystem_value("ray_miss_sbt_addr_intel", 1, bit_sizes=[64])
1520bf215546Sopenharmony_cisystem_value("ray_miss_sbt_stride_intel", 1, bit_sizes=[16])
1521bf215546Sopenharmony_cisystem_value("callable_sbt_addr_intel", 1, bit_sizes=[64])
1522bf215546Sopenharmony_cisystem_value("callable_sbt_stride_intel", 1, bit_sizes=[16])
1523bf215546Sopenharmony_cisystem_value("leaf_opaque_intel", 1, bit_sizes=[1])
1524bf215546Sopenharmony_cisystem_value("leaf_procedural_intel", 1, bit_sizes=[1])
1525bf215546Sopenharmony_ci# Values :
1526bf215546Sopenharmony_ci#  0: AnyHit
1527bf215546Sopenharmony_ci#  1: ClosestHit
1528bf215546Sopenharmony_ci#  2: Miss
1529bf215546Sopenharmony_ci#  3: Intersection
1530bf215546Sopenharmony_cisystem_value("btd_shader_type_intel", 1)
1531bf215546Sopenharmony_cisystem_value("ray_query_global_intel", 1, bit_sizes=[64])
1532bf215546Sopenharmony_ci
1533bf215546Sopenharmony_ci# In order to deal with flipped render targets, gl_PointCoord may be flipped
1534bf215546Sopenharmony_ci# in the shader requiring a shader key or extra instructions or it may be
1535bf215546Sopenharmony_ci# flipped in hardware based on a state bit.  This version of gl_PointCoord
1536bf215546Sopenharmony_ci# is defined to be whatever thing the hardware can easily give you, so long as
1537bf215546Sopenharmony_ci# it's in normalized coordinates in the range [0, 1] across the point.
1538bf215546Sopenharmony_ciintrinsic("load_point_coord_maybe_flipped", dest_comp=2, bit_sizes=[32])
1539