101e04c3fSmrg#
201e04c3fSmrg# Copyright (C) 2018 Red Hat
301e04c3fSmrg# Copyright (C) 2014 Intel Corporation
401e04c3fSmrg#
501e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a
601e04c3fSmrg# copy of this software and associated documentation files (the "Software"),
701e04c3fSmrg# to deal in the Software without restriction, including without limitation
801e04c3fSmrg# the rights to use, copy, modify, merge, publish, distribute, sublicense,
901e04c3fSmrg# and/or sell copies of the Software, and to permit persons to whom the
1001e04c3fSmrg# Software is furnished to do so, subject to the following conditions:
1101e04c3fSmrg#
1201e04c3fSmrg# The above copyright notice and this permission notice (including the next
1301e04c3fSmrg# paragraph) shall be included in all copies or substantial portions of the
1401e04c3fSmrg# Software.
1501e04c3fSmrg#
1601e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1701e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1801e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1901e04c3fSmrg# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2001e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2101e04c3fSmrg# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2201e04c3fSmrg# IN THE SOFTWARE.
2301e04c3fSmrg#
2401e04c3fSmrg
2501e04c3fSmrg# This file defines all the available intrinsics in one place.
2601e04c3fSmrg#
2701e04c3fSmrg# The Intrinsic class corresponds one-to-one with nir_intrinsic_info
2801e04c3fSmrg# structure.
2901e04c3fSmrg
307ec681f3Smrgsrc0 = ('src', 0)
317ec681f3Smrgsrc1 = ('src', 1)
327ec681f3Smrgsrc2 = ('src', 2)
337ec681f3Smrgsrc3 = ('src', 3)
347ec681f3Smrgsrc4 = ('src', 4)
357ec681f3Smrg
367ec681f3Smrgclass Index(object):
377ec681f3Smrg    def __init__(self, c_data_type, name):
387ec681f3Smrg        self.c_data_type = c_data_type
397ec681f3Smrg        self.name = name
407ec681f3Smrg
4101e04c3fSmrgclass Intrinsic(object):
4201e04c3fSmrg   """Class that represents all the information about an intrinsic opcode.
4301e04c3fSmrg   NOTE: this must be kept in sync with nir_intrinsic_info.
4401e04c3fSmrg   """
4501e04c3fSmrg   def __init__(self, name, src_components, dest_components,
467e102996Smaya                indices, flags, sysval, bit_sizes):
4701e04c3fSmrg       """Parameters:
4801e04c3fSmrg
4901e04c3fSmrg       - name: the intrinsic name
5001e04c3fSmrg       - src_components: list of the number of components per src, 0 means
5101e04c3fSmrg         vectorized instruction with number of components given in the
5201e04c3fSmrg         num_components field in nir_intrinsic_instr.
5301e04c3fSmrg       - dest_components: number of destination components, -1 means no
5401e04c3fSmrg         dest, 0 means number of components given in num_components field
5501e04c3fSmrg         in nir_intrinsic_instr.
5601e04c3fSmrg       - indices: list of constant indicies
5701e04c3fSmrg       - flags: list of semantic flags
5801e04c3fSmrg       - sysval: is this a system-value intrinsic
597ec681f3Smrg       - bit_sizes: allowed dest bit_sizes or the source it must match
6001e04c3fSmrg       """
6101e04c3fSmrg       assert isinstance(name, str)
6201e04c3fSmrg       assert isinstance(src_components, list)
6301e04c3fSmrg       if src_components:
6401e04c3fSmrg           assert isinstance(src_components[0], int)
6501e04c3fSmrg       assert isinstance(dest_components, int)
6601e04c3fSmrg       assert isinstance(indices, list)
6701e04c3fSmrg       if indices:
687ec681f3Smrg           assert isinstance(indices[0], Index)
6901e04c3fSmrg       assert isinstance(flags, list)
7001e04c3fSmrg       if flags:
7101e04c3fSmrg           assert isinstance(flags[0], str)
7201e04c3fSmrg       assert isinstance(sysval, bool)
737ec681f3Smrg       if isinstance(bit_sizes, list):
747ec681f3Smrg           assert not bit_sizes or isinstance(bit_sizes[0], int)
757ec681f3Smrg       else:
767ec681f3Smrg           assert isinstance(bit_sizes, tuple)
777ec681f3Smrg           assert bit_sizes[0] == 'src'
787ec681f3Smrg           assert isinstance(bit_sizes[1], int)
7901e04c3fSmrg
8001e04c3fSmrg       self.name = name
8101e04c3fSmrg       self.num_srcs = len(src_components)
8201e04c3fSmrg       self.src_components = src_components
8301e04c3fSmrg       self.has_dest = (dest_components >= 0)
8401e04c3fSmrg       self.dest_components = dest_components
8501e04c3fSmrg       self.num_indices = len(indices)
8601e04c3fSmrg       self.indices = indices
8701e04c3fSmrg       self.flags = flags
8801e04c3fSmrg       self.sysval = sysval
897ec681f3Smrg       self.bit_sizes = bit_sizes if isinstance(bit_sizes, list) else []
907ec681f3Smrg       self.bit_size_src = bit_sizes[1] if isinstance(bit_sizes, tuple) else -1
9101e04c3fSmrg
9201e04c3fSmrg#
9301e04c3fSmrg# Possible flags:
9401e04c3fSmrg#
9501e04c3fSmrg
9601e04c3fSmrgCAN_ELIMINATE = "NIR_INTRINSIC_CAN_ELIMINATE"
9701e04c3fSmrgCAN_REORDER   = "NIR_INTRINSIC_CAN_REORDER"
9801e04c3fSmrg
997ec681f3SmrgINTR_INDICES = []
10001e04c3fSmrgINTR_OPCODES = {}
10101e04c3fSmrg
1027ec681f3Smrgdef index(c_data_type, name):
1037ec681f3Smrg    idx = Index(c_data_type, name)
1047ec681f3Smrg    INTR_INDICES.append(idx)
1057ec681f3Smrg    globals()[name.upper()] = idx
1067ec681f3Smrg
1077e102996Smaya# Defines a new NIR intrinsic.  By default, the intrinsic will have no sources
1087e102996Smaya# and no destination.
1097e102996Smaya#
1107e102996Smaya# You can set dest_comp=n to enable a destination for the intrinsic, in which
1117e102996Smaya# case it will have that many components, or =0 for "as many components as the
1127e102996Smaya# NIR destination value."
1137e102996Smaya#
1147e102996Smaya# Set src_comp=n to enable sources for the intruction.  It can be an array of
1157e102996Smaya# component counts, or (for convenience) a scalar component count if there's
1167e102996Smaya# only one source.  If a component count is 0, it will be as many components as
1177e102996Smaya# the intrinsic has based on the dest_comp.
11801e04c3fSmrgdef intrinsic(name, src_comp=[], dest_comp=-1, indices=[],
1197e102996Smaya              flags=[], sysval=False, bit_sizes=[]):
12001e04c3fSmrg    assert name not in INTR_OPCODES
12101e04c3fSmrg    INTR_OPCODES[name] = Intrinsic(name, src_comp, dest_comp,
1227e102996Smaya                                   indices, flags, sysval, bit_sizes)
12301e04c3fSmrg
1247ec681f3Smrg#
1257ec681f3Smrg# Possible indices:
1267ec681f3Smrg#
1277ec681f3Smrg
1287ec681f3Smrg# Generally instructions that take a offset src argument, can encode
1297ec681f3Smrg# a constant 'base' value which is added to the offset.
1307ec681f3Smrgindex("int", "base")
1317ec681f3Smrg
1327ec681f3Smrg# For store instructions, a writemask for the store.
1337ec681f3Smrgindex("unsigned", "write_mask")
1347ec681f3Smrg
1357ec681f3Smrg# The stream-id for GS emit_vertex/end_primitive intrinsics.
1367ec681f3Smrgindex("unsigned", "stream_id")
1377ec681f3Smrg
1387ec681f3Smrg# The clip-plane id for load_user_clip_plane intrinsic.
1397ec681f3Smrgindex("unsigned", "ucp_id")
1407ec681f3Smrg
1417ec681f3Smrg# The offset to the start of the NIR_INTRINSIC_RANGE.  This is an alternative
1427ec681f3Smrg# to NIR_INTRINSIC_BASE for describing the valid range in intrinsics that don't
1437ec681f3Smrg# have the implicit addition of a base to the offset.
1447ec681f3Smrg#
1457ec681f3Smrg# If the [range_base, range] is [0, ~0], then we don't know the possible
1467ec681f3Smrg# range of the access.
1477ec681f3Smrgindex("unsigned", "range_base")
1487ec681f3Smrg
1497ec681f3Smrg# The amount of data, starting from BASE or RANGE_BASE, that this
1507ec681f3Smrg# instruction may access.  This is used to provide bounds if the offset is
1517ec681f3Smrg# not constant.
1527ec681f3Smrgindex("unsigned", "range")
1537ec681f3Smrg
1547ec681f3Smrg# The Vulkan descriptor set for vulkan_resource_index intrinsic.
1557ec681f3Smrgindex("unsigned", "desc_set")
1567ec681f3Smrg
1577ec681f3Smrg# The Vulkan descriptor set binding for vulkan_resource_index intrinsic.
1587ec681f3Smrgindex("unsigned", "binding")
1597ec681f3Smrg
1607ec681f3Smrg# Component offset
1617ec681f3Smrgindex("unsigned", "component")
1627ec681f3Smrg
1637ec681f3Smrg# Column index for matrix system values
1647ec681f3Smrgindex("unsigned", "column")
1657ec681f3Smrg
1667ec681f3Smrg# Interpolation mode (only meaningful for FS inputs)
1677ec681f3Smrgindex("unsigned", "interp_mode")
1687ec681f3Smrg
1697ec681f3Smrg# A binary nir_op to use when performing a reduction or scan operation
1707ec681f3Smrgindex("unsigned", "reduction_op")
1717ec681f3Smrg
1727ec681f3Smrg# Cluster size for reduction operations
1737ec681f3Smrgindex("unsigned", "cluster_size")
1747ec681f3Smrg
1757ec681f3Smrg# Parameter index for a load_param intrinsic
1767ec681f3Smrgindex("unsigned", "param_idx")
1777ec681f3Smrg
1787ec681f3Smrg# Image dimensionality for image intrinsics
1797ec681f3Smrgindex("enum glsl_sampler_dim", "image_dim")
1807ec681f3Smrg
1817ec681f3Smrg# Non-zero if we are accessing an array image
1827ec681f3Smrgindex("bool", "image_array")
1837ec681f3Smrg
1847ec681f3Smrg# Image format for image intrinsics
1857ec681f3Smrgindex("enum pipe_format", "format")
1867ec681f3Smrg
1877ec681f3Smrg# Access qualifiers for image and memory access intrinsics. ACCESS_RESTRICT is
1887ec681f3Smrg# not set at the intrinsic if the NIR was created from SPIR-V.
1897ec681f3Smrgindex("enum gl_access_qualifier", "access")
1907ec681f3Smrg
1917ec681f3Smrg# call index for split raytracing shaders
1927ec681f3Smrgindex("unsigned", "call_idx")
1937ec681f3Smrg
1947ec681f3Smrg# The stack size increment/decrement for split raytracing shaders
1957ec681f3Smrgindex("unsigned", "stack_size")
1967ec681f3Smrg
1977ec681f3Smrg# Alignment for offsets and addresses
1987ec681f3Smrg#
1997ec681f3Smrg# These two parameters, specify an alignment in terms of a multiplier and
2007ec681f3Smrg# an offset.  The multiplier is always a power of two.  The offset or
2017ec681f3Smrg# address parameter X of the intrinsic is guaranteed to satisfy the
2027ec681f3Smrg# following:
2037ec681f3Smrg#
2047ec681f3Smrg#                (X - align_offset) % align_mul == 0
2057ec681f3Smrg#
2067ec681f3Smrg# For constant offset values, align_mul will be NIR_ALIGN_MUL_MAX and the
2077ec681f3Smrg# align_offset will be modulo that.
2087ec681f3Smrgindex("unsigned", "align_mul")
2097ec681f3Smrgindex("unsigned", "align_offset")
2107ec681f3Smrg
2117ec681f3Smrg# The Vulkan descriptor type for a vulkan_resource_[re]index intrinsic.
2127ec681f3Smrgindex("unsigned", "desc_type")
2137ec681f3Smrg
2147ec681f3Smrg# The nir_alu_type of input data to a store or conversion
2157ec681f3Smrgindex("nir_alu_type", "src_type")
2167ec681f3Smrg
2177ec681f3Smrg# The nir_alu_type of the data output from a load or conversion
2187ec681f3Smrgindex("nir_alu_type", "dest_type")
2197ec681f3Smrg
2207ec681f3Smrg# The swizzle mask for quad_swizzle_amd & masked_swizzle_amd
2217ec681f3Smrgindex("unsigned", "swizzle_mask")
2227ec681f3Smrg
2237ec681f3Smrg# Whether the load_buffer_amd/store_buffer_amd is swizzled
2247ec681f3Smrgindex("bool", "is_swizzled")
2257ec681f3Smrg
2267ec681f3Smrg# The SLC ("system level coherent") bit of load_buffer_amd/store_buffer_amd
2277ec681f3Smrgindex("bool", "slc_amd")
2287ec681f3Smrg
2297ec681f3Smrg# Separate source/dest access flags for copies
2307ec681f3Smrgindex("enum gl_access_qualifier", "dst_access")
2317ec681f3Smrgindex("enum gl_access_qualifier", "src_access")
2327ec681f3Smrg
2337ec681f3Smrg# Driver location of attribute
2347ec681f3Smrgindex("unsigned", "driver_location")
2357ec681f3Smrg
2367ec681f3Smrg# Ordering and visibility of a memory operation
2377ec681f3Smrgindex("nir_memory_semantics", "memory_semantics")
2387ec681f3Smrg
2397ec681f3Smrg# Modes affected by a memory operation
2407ec681f3Smrgindex("nir_variable_mode", "memory_modes")
2417ec681f3Smrg
2427ec681f3Smrg# Scope of a memory operation
2437ec681f3Smrgindex("nir_scope", "memory_scope")
2447ec681f3Smrg
2457ec681f3Smrg# Scope of a control barrier
2467ec681f3Smrgindex("nir_scope", "execution_scope")
2477ec681f3Smrg
2487ec681f3Smrg# Semantics of an IO instruction
2497ec681f3Smrgindex("struct nir_io_semantics", "io_semantics")
2507ec681f3Smrg
2517ec681f3Smrg# Rounding mode for conversions
2527ec681f3Smrgindex("nir_rounding_mode", "rounding_mode")
2537ec681f3Smrg
2547ec681f3Smrg# Whether or not to saturate in conversions
2557ec681f3Smrgindex("unsigned", "saturate")
2567ec681f3Smrg
25701e04c3fSmrgintrinsic("nop", flags=[CAN_ELIMINATE])
25801e04c3fSmrg
2597ec681f3Smrgintrinsic("convert_alu_types", dest_comp=0, src_comp=[0],
2607ec681f3Smrg          indices=[SRC_TYPE, DEST_TYPE, ROUNDING_MODE, SATURATE],
2617ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
2627ec681f3Smrg
26301e04c3fSmrgintrinsic("load_param", dest_comp=0, indices=[PARAM_IDX], flags=[CAN_ELIMINATE])
26401e04c3fSmrg
2657e102996Smayaintrinsic("load_deref", dest_comp=0, src_comp=[-1],
2667e102996Smaya          indices=[ACCESS], flags=[CAN_ELIMINATE])
2677ec681f3Smrgintrinsic("store_deref", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])
2687e102996Smayaintrinsic("copy_deref", src_comp=[-1, -1], indices=[DST_ACCESS, SRC_ACCESS])
2697ec681f3Smrgintrinsic("memcpy_deref", src_comp=[-1, -1, 1], indices=[DST_ACCESS, SRC_ACCESS])
27001e04c3fSmrg
27101e04c3fSmrg# Interpolation of input.  The interp_deref_at* intrinsics are similar to the
27201e04c3fSmrg# load_var intrinsic acting on a shader input except that they interpolate the
2737ec681f3Smrg# input differently.  The at_sample, at_offset and at_vertex intrinsics take an
2747ec681f3Smrg# additional source that is an integer sample id, a vec2 position offset, or a
2757ec681f3Smrg# vertex ID respectively.
27601e04c3fSmrg
27701e04c3fSmrgintrinsic("interp_deref_at_centroid", dest_comp=0, src_comp=[1],
27801e04c3fSmrg          flags=[ CAN_ELIMINATE, CAN_REORDER])
27901e04c3fSmrgintrinsic("interp_deref_at_sample", src_comp=[1, 1], dest_comp=0,
28001e04c3fSmrg          flags=[CAN_ELIMINATE, CAN_REORDER])
28101e04c3fSmrgintrinsic("interp_deref_at_offset", src_comp=[1, 2], dest_comp=0,
28201e04c3fSmrg          flags=[CAN_ELIMINATE, CAN_REORDER])
2837ec681f3Smrgintrinsic("interp_deref_at_vertex", src_comp=[1, 1], dest_comp=0,
2847ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
28501e04c3fSmrg
2867e102996Smaya# Gets the length of an unsized array at the end of a buffer
2877e102996Smayaintrinsic("deref_buffer_array_length", src_comp=[-1], dest_comp=1,
2887ec681f3Smrg          indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])
2897e102996Smaya
2907ec681f3Smrg# Ask the driver for the size of a given SSBO. It takes the buffer index
29101e04c3fSmrg# as source.
2927ec681f3Smrgintrinsic("get_ssbo_size", src_comp=[-1], dest_comp=1, bit_sizes=[32],
2937ec681f3Smrg          indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])
2947ec681f3Smrgintrinsic("get_ubo_size", src_comp=[-1], dest_comp=1,
2957ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
2967ec681f3Smrg
2977ec681f3Smrg# Intrinsics which provide a run-time mode-check.  Unlike the compile-time
2987ec681f3Smrg# mode checks, a pointer can only have exactly one mode at runtime.
2997ec681f3Smrgintrinsic("deref_mode_is", src_comp=[-1], dest_comp=1,
3007ec681f3Smrg          indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])
3017ec681f3Smrgintrinsic("addr_mode_is", src_comp=[-1], dest_comp=1,
3027ec681f3Smrg          indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])
3037ec681f3Smrg
3047ec681f3Smrgintrinsic("is_sparse_texels_resident", dest_comp=1, src_comp=[1], bit_sizes=[1],
3057ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
3067ec681f3Smrg# result code is resident only if both inputs are resident
3077ec681f3Smrgintrinsic("sparse_residency_code_and", dest_comp=1, src_comp=[1, 1], bit_sizes=[32],
30801e04c3fSmrg          flags=[CAN_ELIMINATE, CAN_REORDER])
30901e04c3fSmrg
31001e04c3fSmrg# a barrier is an intrinsic with no inputs/outputs but which can't be moved
31101e04c3fSmrg# around/optimized in general
31201e04c3fSmrgdef barrier(name):
31301e04c3fSmrg    intrinsic(name)
31401e04c3fSmrg
31501e04c3fSmrgbarrier("discard")
31601e04c3fSmrg
3177ec681f3Smrg# Demote fragment shader invocation to a helper invocation.  Any stores to
3187ec681f3Smrg# memory after this instruction are suppressed and the fragment does not write
3197ec681f3Smrg# outputs to the framebuffer.  Unlike discard, demote needs to ensure that
3207ec681f3Smrg# derivatives will still work for invocations that were not demoted.
3217ec681f3Smrg#
3227ec681f3Smrg# As specified by SPV_EXT_demote_to_helper_invocation.
3237ec681f3Smrgbarrier("demote")
3247ec681f3Smrgintrinsic("is_helper_invocation", dest_comp=1, flags=[CAN_ELIMINATE])
3257ec681f3Smrg
3267ec681f3Smrg# SpvOpTerminateInvocation from SPIR-V.  Essentially a discard "for real".
3277ec681f3Smrgbarrier("terminate")
3287ec681f3Smrg
3297ec681f3Smrg# A workgroup-level control barrier.  Any thread which hits this barrier will
3307ec681f3Smrg# pause until all threads within the current workgroup have also hit the
3317ec681f3Smrg# barrier.  For compute shaders, the workgroup is defined as the local group.
3327ec681f3Smrg# For tessellation control shaders, the workgroup is defined as the current
3337ec681f3Smrg# patch.  This intrinsic does not imply any sort of memory barrier.
3347ec681f3Smrgbarrier("control_barrier")
3357ec681f3Smrg
33601e04c3fSmrg# Memory barrier with semantics analogous to the memoryBarrier() GLSL
33701e04c3fSmrg# intrinsic.
33801e04c3fSmrgbarrier("memory_barrier")
33901e04c3fSmrg
3407ec681f3Smrg# Control/Memory barrier with explicit scope.  Follows the semantics of SPIR-V
3417ec681f3Smrg# OpMemoryBarrier and OpControlBarrier, used to implement Vulkan Memory Model.
3427ec681f3Smrg# Storage that the barrier applies is represented using NIR variable modes.
3437ec681f3Smrg# For an OpMemoryBarrier, set EXECUTION_SCOPE to NIR_SCOPE_NONE.
3447ec681f3Smrgintrinsic("scoped_barrier",
3457ec681f3Smrg          indices=[EXECUTION_SCOPE, MEMORY_SCOPE, MEMORY_SEMANTICS, MEMORY_MODES])
3467ec681f3Smrg
34701e04c3fSmrg# Shader clock intrinsic with semantics analogous to the clock2x32ARB()
34801e04c3fSmrg# GLSL intrinsic.
34901e04c3fSmrg# The latter can be used as code motion barrier, which is currently not
35001e04c3fSmrg# feasible with NIR.
3517ec681f3Smrgintrinsic("shader_clock", dest_comp=2, bit_sizes=[32], flags=[CAN_ELIMINATE],
3527ec681f3Smrg          indices=[MEMORY_SCOPE])
35301e04c3fSmrg
35401e04c3fSmrg# Shader ballot intrinsics with semantics analogous to the
35501e04c3fSmrg#
35601e04c3fSmrg#    ballotARB()
35701e04c3fSmrg#    readInvocationARB()
35801e04c3fSmrg#    readFirstInvocationARB()
35901e04c3fSmrg#
36001e04c3fSmrg# GLSL functions from ARB_shader_ballot.
36101e04c3fSmrgintrinsic("ballot", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])
3627ec681f3Smrgintrinsic("read_invocation", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
3637ec681f3Smrgintrinsic("read_first_invocation", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
3647ec681f3Smrg
3657ec681f3Smrg# Returns the value of the first source for the lane where the second source is
3667ec681f3Smrg# true. The second source must be true for exactly one lane.
3677ec681f3Smrgintrinsic("read_invocation_cond_ir3", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
36801e04c3fSmrg
36901e04c3fSmrg# Additional SPIR-V ballot intrinsics
37001e04c3fSmrg#
37101e04c3fSmrg# These correspond to the SPIR-V opcodes
37201e04c3fSmrg#
3737ec681f3Smrg#    OpGroupNonUniformElect
37401e04c3fSmrg#    OpSubgroupFirstInvocationKHR
37501e04c3fSmrgintrinsic("elect", dest_comp=1, flags=[CAN_ELIMINATE])
3767ec681f3Smrgintrinsic("first_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
3777ec681f3Smrgintrinsic("last_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
37801e04c3fSmrg
37901e04c3fSmrg# Memory barrier with semantics analogous to the compute shader
38001e04c3fSmrg# groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),
38101e04c3fSmrg# memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.
38201e04c3fSmrgbarrier("group_memory_barrier")
38301e04c3fSmrgbarrier("memory_barrier_atomic_counter")
38401e04c3fSmrgbarrier("memory_barrier_buffer")
38501e04c3fSmrgbarrier("memory_barrier_image")
38601e04c3fSmrgbarrier("memory_barrier_shared")
38701e04c3fSmrgbarrier("begin_invocation_interlock")
38801e04c3fSmrgbarrier("end_invocation_interlock")
38901e04c3fSmrg
3907ec681f3Smrg# Memory barrier for synchronizing TCS patch outputs
3917ec681f3Smrgbarrier("memory_barrier_tcs_patch")
3927ec681f3Smrg
3937ec681f3Smrg# A conditional discard/demote/terminate, with a single boolean source.
39401e04c3fSmrgintrinsic("discard_if", src_comp=[1])
3957ec681f3Smrgintrinsic("demote_if", src_comp=[1])
3967ec681f3Smrgintrinsic("terminate_if", src_comp=[1])
39701e04c3fSmrg
39801e04c3fSmrg# ARB_shader_group_vote intrinsics
39901e04c3fSmrgintrinsic("vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
40001e04c3fSmrgintrinsic("vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])
40101e04c3fSmrgintrinsic("vote_feq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
40201e04c3fSmrgintrinsic("vote_ieq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])
40301e04c3fSmrg
40401e04c3fSmrg# Ballot ALU operations from SPIR-V.
40501e04c3fSmrg#
40601e04c3fSmrg# These operations work like their ALU counterparts except that the operate
40701e04c3fSmrg# on a uvec4 which is treated as a 128bit integer.  Also, they are, in
40801e04c3fSmrg# general, free to ignore any bits which are above the subgroup size.
40901e04c3fSmrgintrinsic("ballot_bitfield_extract", src_comp=[4, 1], dest_comp=1, flags=[CAN_ELIMINATE])
41001e04c3fSmrgintrinsic("ballot_bit_count_reduce", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
41101e04c3fSmrgintrinsic("ballot_bit_count_inclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
41201e04c3fSmrgintrinsic("ballot_bit_count_exclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
41301e04c3fSmrgintrinsic("ballot_find_lsb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
41401e04c3fSmrgintrinsic("ballot_find_msb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])
41501e04c3fSmrg
41601e04c3fSmrg# Shuffle operations from SPIR-V.
4177ec681f3Smrgintrinsic("shuffle", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
4187ec681f3Smrgintrinsic("shuffle_xor", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
4197ec681f3Smrgintrinsic("shuffle_up", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
4207ec681f3Smrgintrinsic("shuffle_down", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])
42101e04c3fSmrg
42201e04c3fSmrg# Quad operations from SPIR-V.
42301e04c3fSmrgintrinsic("quad_broadcast", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])
42401e04c3fSmrgintrinsic("quad_swap_horizontal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
42501e04c3fSmrgintrinsic("quad_swap_vertical", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
42601e04c3fSmrgintrinsic("quad_swap_diagonal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])
42701e04c3fSmrg
4287ec681f3Smrgintrinsic("reduce", src_comp=[0], dest_comp=0, bit_sizes=src0,
4297ec681f3Smrg          indices=[REDUCTION_OP, CLUSTER_SIZE], flags=[CAN_ELIMINATE])
4307ec681f3Smrgintrinsic("inclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,
4317ec681f3Smrg          indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])
4327ec681f3Smrgintrinsic("exclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,
4337ec681f3Smrg          indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])
4347ec681f3Smrg
4357ec681f3Smrg# AMD shader ballot operations
4367ec681f3Smrgintrinsic("quad_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,
4377ec681f3Smrg          indices=[SWIZZLE_MASK], flags=[CAN_ELIMINATE])
4387ec681f3Smrgintrinsic("masked_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,
4397ec681f3Smrg          indices=[SWIZZLE_MASK], flags=[CAN_ELIMINATE])
4407ec681f3Smrgintrinsic("write_invocation_amd", src_comp=[0, 0, 1], dest_comp=0, bit_sizes=src0,
44101e04c3fSmrg          flags=[CAN_ELIMINATE])
4427ec681f3Smrg# src = [ mask, addition ]
4437ec681f3Smrgintrinsic("mbcnt_amd", src_comp=[1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
4447ec681f3Smrg# Compiled to v_perm_b32. src = [ in_bytes_hi, in_bytes_lo, selector ]
4457ec681f3Smrgintrinsic("byte_permute_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
4467ec681f3Smrg# Compiled to v_permlane16_b32. src = [ value, lanesel_lo, lanesel_hi ]
4477ec681f3Smrgintrinsic("lane_permute_16_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])
44801e04c3fSmrg
44901e04c3fSmrg# Basic Geometry Shader intrinsics.
45001e04c3fSmrg#
45101e04c3fSmrg# emit_vertex implements GLSL's EmitStreamVertex() built-in.  It takes a single
45201e04c3fSmrg# index, which is the stream ID to write to.
45301e04c3fSmrg#
45401e04c3fSmrg# end_primitive implements GLSL's EndPrimitive() built-in.
45501e04c3fSmrgintrinsic("emit_vertex",   indices=[STREAM_ID])
45601e04c3fSmrgintrinsic("end_primitive", indices=[STREAM_ID])
45701e04c3fSmrg
45801e04c3fSmrg# Geometry Shader intrinsics with a vertex count.
45901e04c3fSmrg#
46001e04c3fSmrg# Alternatively, drivers may implement these intrinsics, and use
46101e04c3fSmrg# nir_lower_gs_intrinsics() to convert from the basic intrinsics.
46201e04c3fSmrg#
4637ec681f3Smrg# These contain two additional unsigned integer sources:
4647ec681f3Smrg# 1. The total number of vertices emitted so far.
4657ec681f3Smrg# 2. The number of vertices emitted for the current primitive
4667ec681f3Smrg#    so far if we're counting, otherwise undef.
4677ec681f3Smrgintrinsic("emit_vertex_with_counter", src_comp=[1, 1], indices=[STREAM_ID])
4687ec681f3Smrgintrinsic("end_primitive_with_counter", src_comp=[1, 1], indices=[STREAM_ID])
4697ec681f3Smrg# Contains the final total vertex and primitive counts in the current GS thread.
4707ec681f3Smrgintrinsic("set_vertex_and_primitive_count", src_comp=[1, 1], indices=[STREAM_ID])
4717ec681f3Smrg
4727ec681f3Smrg# Trace a ray through an acceleration structure
4737ec681f3Smrg#
4747ec681f3Smrg# This instruction has a lot of parameters:
4757ec681f3Smrg#   0. Acceleration Structure
4767ec681f3Smrg#   1. Ray Flags
4777ec681f3Smrg#   2. Cull Mask
4787ec681f3Smrg#   3. SBT Offset
4797ec681f3Smrg#   4. SBT Stride
4807ec681f3Smrg#   5. Miss shader index
4817ec681f3Smrg#   6. Ray Origin
4827ec681f3Smrg#   7. Ray Tmin
4837ec681f3Smrg#   8. Ray Direction
4847ec681f3Smrg#   9. Ray Tmax
4857ec681f3Smrg#   10. Payload
4867ec681f3Smrgintrinsic("trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1])
4877ec681f3Smrg# src[] = { hit_t, hit_kind }
4887ec681f3Smrgintrinsic("report_ray_intersection", src_comp=[1, 1], dest_comp=1)
4897ec681f3Smrgintrinsic("ignore_ray_intersection")
4907ec681f3Smrgintrinsic("accept_ray_intersection") # Not in SPIR-V; useful for lowering
4917ec681f3Smrgintrinsic("terminate_ray")
4927ec681f3Smrg# src[] = { sbt_index, payload }
4937ec681f3Smrgintrinsic("execute_callable", src_comp=[1, -1])
4947ec681f3Smrg
4957ec681f3Smrg# Driver independent raytracing helpers
4967ec681f3Smrg
4977ec681f3Smrg# rt_resume is a helper that that be the first instruction accesing the
4987ec681f3Smrg# stack/scratch in a resume shader for a raytracing pipeline. It includes the
4997ec681f3Smrg# resume index (for nir_lower_shader_calls_internal reasons) and the stack size
5007ec681f3Smrg# of the variables spilled during the call. The stack size can be use to e.g.
5017ec681f3Smrg# adjust a stack pointer.
5027ec681f3Smrgintrinsic("rt_resume", indices=[CALL_IDX, STACK_SIZE])
5037ec681f3Smrg
5047ec681f3Smrg# Lowered version of execute_callabe that includes the index of the resume
5057ec681f3Smrg# shader, and the amount of scratch space needed for this call (.ie. how much
5067ec681f3Smrg# to increase a stack pointer by).
5077ec681f3Smrg# src[] = { sbt_index, payload }
5087ec681f3Smrgintrinsic("rt_execute_callable", src_comp=[1, -1], indices=[CALL_IDX,STACK_SIZE])
5097ec681f3Smrg
5107ec681f3Smrg# Lowered version of trace_ray in a similar vein to rt_execute_callable.
5117ec681f3Smrg# src same as trace_ray
5127ec681f3Smrgintrinsic("rt_trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1],
5137ec681f3Smrg          indices=[CALL_IDX, STACK_SIZE])
5147ec681f3Smrg
51501e04c3fSmrg
51601e04c3fSmrg# Atomic counters
51701e04c3fSmrg#
51801e04c3fSmrg# The *_var variants take an atomic_uint nir_variable, while the other,
51901e04c3fSmrg# lowered, variants take a constant buffer index and register offset.
52001e04c3fSmrg
52101e04c3fSmrgdef atomic(name, flags=[]):
5227e102996Smaya    intrinsic(name + "_deref", src_comp=[-1], dest_comp=1, flags=flags)
52301e04c3fSmrg    intrinsic(name, src_comp=[1], dest_comp=1, indices=[BASE], flags=flags)
52401e04c3fSmrg
52501e04c3fSmrgdef atomic2(name):
5267e102996Smaya    intrinsic(name + "_deref", src_comp=[-1, 1], dest_comp=1)
52701e04c3fSmrg    intrinsic(name, src_comp=[1, 1], dest_comp=1, indices=[BASE])
52801e04c3fSmrg
52901e04c3fSmrgdef atomic3(name):
5307e102996Smaya    intrinsic(name + "_deref", src_comp=[-1, 1, 1], dest_comp=1)
53101e04c3fSmrg    intrinsic(name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
53201e04c3fSmrg
53301e04c3fSmrgatomic("atomic_counter_inc")
53401e04c3fSmrgatomic("atomic_counter_pre_dec")
53501e04c3fSmrgatomic("atomic_counter_post_dec")
53601e04c3fSmrgatomic("atomic_counter_read", flags=[CAN_ELIMINATE])
53701e04c3fSmrgatomic2("atomic_counter_add")
53801e04c3fSmrgatomic2("atomic_counter_min")
53901e04c3fSmrgatomic2("atomic_counter_max")
54001e04c3fSmrgatomic2("atomic_counter_and")
54101e04c3fSmrgatomic2("atomic_counter_or")
54201e04c3fSmrgatomic2("atomic_counter_xor")
54301e04c3fSmrgatomic2("atomic_counter_exchange")
54401e04c3fSmrgatomic3("atomic_counter_comp_swap")
54501e04c3fSmrg
54601e04c3fSmrg# Image load, store and atomic intrinsics.
54701e04c3fSmrg#
5487e102996Smaya# All image intrinsics come in three versions.  One which take an image target
5497e102996Smaya# passed as a deref chain as the first source, one which takes an index as the
5507e102996Smaya# first source, and one which takes a bindless handle as the first source.
5517e102996Smaya# In the first version, the image variable contains the memory and layout
5527e102996Smaya# qualifiers that influence the semantics of the intrinsic.  In the second and
5537e102996Smaya# third, the image format and access qualifiers are provided as constant
5547e102996Smaya# indices.
55501e04c3fSmrg#
55601e04c3fSmrg# All image intrinsics take a four-coordinate vector and a sample index as
55701e04c3fSmrg# 2nd and 3rd sources, determining the location within the image that will be
55801e04c3fSmrg# accessed by the intrinsic.  Components not applicable to the image target
55901e04c3fSmrg# in use are undefined.  Image store takes an additional four-component
56001e04c3fSmrg# argument with the value to be written, and image atomic operations take
56101e04c3fSmrg# either one or two additional scalar arguments with the same meaning as in
56201e04c3fSmrg# the ARB_shader_image_load_store specification.
5637ec681f3Smrgdef image(name, src_comp=[], extra_indices=[], **kwargs):
5647ec681f3Smrg    intrinsic("image_deref_" + name, src_comp=[-1] + src_comp,
5657ec681f3Smrg              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
56601e04c3fSmrg    intrinsic("image_" + name, src_comp=[1] + src_comp,
5677ec681f3Smrg              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
5687e102996Smaya    intrinsic("bindless_image_" + name, src_comp=[1] + src_comp,
5697ec681f3Smrg              indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
57001e04c3fSmrg
5717ec681f3Smrgimage("load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
5727ec681f3Smrgimage("sparse_load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
5737ec681f3Smrgimage("store", src_comp=[4, 1, 0, 1], extra_indices=[SRC_TYPE])
57401e04c3fSmrgimage("atomic_add",  src_comp=[4, 1, 1], dest_comp=1)
5757ec681f3Smrgimage("atomic_imin",  src_comp=[4, 1, 1], dest_comp=1)
5767ec681f3Smrgimage("atomic_umin",  src_comp=[4, 1, 1], dest_comp=1)
5777ec681f3Smrgimage("atomic_imax",  src_comp=[4, 1, 1], dest_comp=1)
5787ec681f3Smrgimage("atomic_umax",  src_comp=[4, 1, 1], dest_comp=1)
57901e04c3fSmrgimage("atomic_and",  src_comp=[4, 1, 1], dest_comp=1)
58001e04c3fSmrgimage("atomic_or",   src_comp=[4, 1, 1], dest_comp=1)
58101e04c3fSmrgimage("atomic_xor",  src_comp=[4, 1, 1], dest_comp=1)
58201e04c3fSmrgimage("atomic_exchange",  src_comp=[4, 1, 1], dest_comp=1)
58301e04c3fSmrgimage("atomic_comp_swap", src_comp=[4, 1, 1, 1], dest_comp=1)
5847ec681f3Smrgimage("atomic_fadd",  src_comp=[4, 1, 1], dest_comp=1)
5857ec681f3Smrgimage("atomic_fmin",  src_comp=[4, 1, 1], dest_comp=1)
5867ec681f3Smrgimage("atomic_fmax",  src_comp=[4, 1, 1], dest_comp=1)
5877ec681f3Smrgimage("size",    dest_comp=0, src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])
58801e04c3fSmrgimage("samples", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
5897ec681f3Smrgimage("atomic_inc_wrap",  src_comp=[4, 1, 1], dest_comp=1)
5907ec681f3Smrgimage("atomic_dec_wrap",  src_comp=[4, 1, 1], dest_comp=1)
5917ec681f3Smrg# CL-specific format queries
5927ec681f3Smrgimage("format", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
5937ec681f3Smrgimage("order", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
59401e04c3fSmrg
59501e04c3fSmrg# Vulkan descriptor set intrinsics
59601e04c3fSmrg#
59701e04c3fSmrg# The Vulkan API uses a different binding model from GL.  In the Vulkan
59801e04c3fSmrg# API, all external resources are represented by a tuple:
59901e04c3fSmrg#
60001e04c3fSmrg# (descriptor set, binding, array index)
60101e04c3fSmrg#
60201e04c3fSmrg# where the array index is the only thing allowed to be indirect.  The
60301e04c3fSmrg# vulkan_surface_index intrinsic takes the descriptor set and binding as
60401e04c3fSmrg# its first two indices and the array index as its source.  The third
60501e04c3fSmrg# index is a nir_variable_mode in case that's useful to the backend.
60601e04c3fSmrg#
60701e04c3fSmrg# The intended usage is that the shader will call vulkan_surface_index to
60801e04c3fSmrg# get an index and then pass that as the buffer index ubo/ssbo calls.
60901e04c3fSmrg#
61001e04c3fSmrg# The vulkan_resource_reindex intrinsic takes a resource index in src0
61101e04c3fSmrg# (the result of a vulkan_resource_index or vulkan_resource_reindex) which
61201e04c3fSmrg# corresponds to the tuple (set, binding, index) and computes an index
61301e04c3fSmrg# corresponding to tuple (set, binding, idx + src1).
6147e102996Smayaintrinsic("vulkan_resource_index", src_comp=[1], dest_comp=0,
6157e102996Smaya          indices=[DESC_SET, BINDING, DESC_TYPE],
61601e04c3fSmrg          flags=[CAN_ELIMINATE, CAN_REORDER])
6177e102996Smayaintrinsic("vulkan_resource_reindex", src_comp=[0, 1], dest_comp=0,
6187e102996Smaya          indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])
6197e102996Smayaintrinsic("load_vulkan_descriptor", src_comp=[-1], dest_comp=0,
6207e102996Smaya          indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])
62101e04c3fSmrg
6227ec681f3Smrg# atomic intrinsics
62301e04c3fSmrg#
6247ec681f3Smrg# All of these atomic memory operations read a value from memory, compute a new
6257ec681f3Smrg# value using one of the operations below, write the new value to memory, and
6267ec681f3Smrg# return the original value read.
62701e04c3fSmrg#
6287ec681f3Smrg# All variable operations take 2 sources except CompSwap that takes 3. These
6297ec681f3Smrg# sources represent:
63001e04c3fSmrg#
63101e04c3fSmrg# 0: A deref to the memory on which to perform the atomic
63201e04c3fSmrg# 1: The data parameter to the atomic function (i.e. the value to add
63301e04c3fSmrg#    in shared_atomic_add, etc).
63401e04c3fSmrg# 2: For CompSwap only: the second data parameter.
6357ec681f3Smrg#
6367ec681f3Smrg# All SSBO operations take 3 sources except CompSwap that takes 4. These
63701e04c3fSmrg# sources represent:
63801e04c3fSmrg#
63901e04c3fSmrg# 0: The SSBO buffer index.
64001e04c3fSmrg# 1: The offset into the SSBO buffer of the variable that the atomic
64101e04c3fSmrg#    operation will operate on.
64201e04c3fSmrg# 2: The data parameter to the atomic function (i.e. the value to add
64301e04c3fSmrg#    in ssbo_atomic_add, etc).
64401e04c3fSmrg# 3: For CompSwap only: the second data parameter.
64501e04c3fSmrg#
6467ec681f3Smrg# All shared variable operations take 2 sources except CompSwap that takes 3.
6477ec681f3Smrg# These sources represent:
64801e04c3fSmrg#
64901e04c3fSmrg# 0: The offset into the shared variable storage region that the atomic
65001e04c3fSmrg#    operation will operate on.
65101e04c3fSmrg# 1: The data parameter to the atomic function (i.e. the value to add
65201e04c3fSmrg#    in shared_atomic_add, etc).
65301e04c3fSmrg# 2: For CompSwap only: the second data parameter.
6547e102996Smaya#
6557ec681f3Smrg# All global operations take 2 sources except CompSwap that takes 3. These
6567e102996Smaya# sources represent:
6577e102996Smaya#
6587e102996Smaya# 0: The memory address that the atomic operation will operate on.
6597e102996Smaya# 1: The data parameter to the atomic function (i.e. the value to add
6607e102996Smaya#    in shared_atomic_add, etc).
6617e102996Smaya# 2: For CompSwap only: the second data parameter.
6627ec681f3Smrg
6637ec681f3Smrgdef memory_atomic_data1(name):
6647ec681f3Smrg    intrinsic("deref_atomic_" + name,  src_comp=[-1, 1], dest_comp=1, indices=[ACCESS])
6657ec681f3Smrg    intrinsic("ssbo_atomic_" + name,  src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS])
6667ec681f3Smrg    intrinsic("shared_atomic_" + name,  src_comp=[1, 1], dest_comp=1, indices=[BASE])
6677ec681f3Smrg    intrinsic("global_atomic_" + name,  src_comp=[1, 1], dest_comp=1, indices=[BASE])
6687ec681f3Smrg
6697ec681f3Smrgdef memory_atomic_data2(name):
6707ec681f3Smrg    intrinsic("deref_atomic_" + name,  src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS])
6717ec681f3Smrg    intrinsic("ssbo_atomic_" + name,  src_comp=[-1, 1, 1, 1], dest_comp=1, indices=[ACCESS])
6727ec681f3Smrg    intrinsic("shared_atomic_" + name,  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
6737ec681f3Smrg    intrinsic("global_atomic_" + name,  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
6747ec681f3Smrg
6757ec681f3Smrgmemory_atomic_data1("add")
6767ec681f3Smrgmemory_atomic_data1("imin")
6777ec681f3Smrgmemory_atomic_data1("umin")
6787ec681f3Smrgmemory_atomic_data1("imax")
6797ec681f3Smrgmemory_atomic_data1("umax")
6807ec681f3Smrgmemory_atomic_data1("and")
6817ec681f3Smrgmemory_atomic_data1("or")
6827ec681f3Smrgmemory_atomic_data1("xor")
6837ec681f3Smrgmemory_atomic_data1("exchange")
6847ec681f3Smrgmemory_atomic_data1("fadd")
6857ec681f3Smrgmemory_atomic_data1("fmin")
6867ec681f3Smrgmemory_atomic_data1("fmax")
6877ec681f3Smrgmemory_atomic_data2("comp_swap")
6887ec681f3Smrgmemory_atomic_data2("fcomp_swap")
6897e102996Smaya
6907e102996Smayadef system_value(name, dest_comp, indices=[], bit_sizes=[32]):
69101e04c3fSmrg    intrinsic("load_" + name, [], dest_comp, indices,
6927e102996Smaya              flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True,
6937e102996Smaya              bit_sizes=bit_sizes)
69401e04c3fSmrg
69501e04c3fSmrgsystem_value("frag_coord", 4)
6967ec681f3Smrgsystem_value("point_coord", 2)
6977ec681f3Smrgsystem_value("line_coord", 1)
6987e102996Smayasystem_value("front_face", 1, bit_sizes=[1, 32])
69901e04c3fSmrgsystem_value("vertex_id", 1)
70001e04c3fSmrgsystem_value("vertex_id_zero_base", 1)
70101e04c3fSmrgsystem_value("first_vertex", 1)
70201e04c3fSmrgsystem_value("is_indexed_draw", 1)
70301e04c3fSmrgsystem_value("base_vertex", 1)
70401e04c3fSmrgsystem_value("instance_id", 1)
70501e04c3fSmrgsystem_value("base_instance", 1)
70601e04c3fSmrgsystem_value("draw_id", 1)
70701e04c3fSmrgsystem_value("sample_id", 1)
70801e04c3fSmrg# sample_id_no_per_sample is like sample_id but does not imply per-
70901e04c3fSmrg# sample shading.  See the lower_helper_invocation option.
71001e04c3fSmrgsystem_value("sample_id_no_per_sample", 1)
71101e04c3fSmrgsystem_value("sample_pos", 2)
71201e04c3fSmrgsystem_value("sample_mask_in", 1)
71301e04c3fSmrgsystem_value("primitive_id", 1)
71401e04c3fSmrgsystem_value("invocation_id", 1)
71501e04c3fSmrgsystem_value("tess_coord", 3)
71601e04c3fSmrgsystem_value("tess_level_outer", 4)
71701e04c3fSmrgsystem_value("tess_level_inner", 2)
7187ec681f3Smrgsystem_value("tess_level_outer_default", 4)
7197ec681f3Smrgsystem_value("tess_level_inner_default", 2)
72001e04c3fSmrgsystem_value("patch_vertices_in", 1)
72101e04c3fSmrgsystem_value("local_invocation_id", 3)
72201e04c3fSmrgsystem_value("local_invocation_index", 1)
7237ec681f3Smrg# zero_base indicates it starts from 0 for the current dispatch
7247ec681f3Smrg# non-zero_base indicates the base is included
7257ec681f3Smrgsystem_value("workgroup_id", 3, bit_sizes=[32, 64])
7267ec681f3Smrgsystem_value("workgroup_id_zero_base", 3)
7277ec681f3Smrgsystem_value("base_workgroup_id", 3, bit_sizes=[32, 64])
72801e04c3fSmrgsystem_value("user_clip_plane", 4, indices=[UCP_ID])
7297ec681f3Smrgsystem_value("num_workgroups", 3, bit_sizes=[32, 64])
7307e102996Smayasystem_value("helper_invocation", 1, bit_sizes=[1, 32])
73101e04c3fSmrgsystem_value("layer_id", 1)
73201e04c3fSmrgsystem_value("view_index", 1)
73301e04c3fSmrgsystem_value("subgroup_size", 1)
73401e04c3fSmrgsystem_value("subgroup_invocation", 1)
7357e102996Smayasystem_value("subgroup_eq_mask", 0, bit_sizes=[32, 64])
7367e102996Smayasystem_value("subgroup_ge_mask", 0, bit_sizes=[32, 64])
7377e102996Smayasystem_value("subgroup_gt_mask", 0, bit_sizes=[32, 64])
7387e102996Smayasystem_value("subgroup_le_mask", 0, bit_sizes=[32, 64])
7397e102996Smayasystem_value("subgroup_lt_mask", 0, bit_sizes=[32, 64])
74001e04c3fSmrgsystem_value("num_subgroups", 1)
74101e04c3fSmrgsystem_value("subgroup_id", 1)
7427ec681f3Smrgsystem_value("workgroup_size", 3)
7437ec681f3Smrg# note: the definition of global_invocation_id_zero_base is based on
7447ec681f3Smrg# (workgroup_id * workgroup_size) + local_invocation_id.
7457ec681f3Smrg# it is *not* based on workgroup_id_zero_base, meaning the work group
7467ec681f3Smrg# base is already accounted for, and the global base is additive on top of that
7477e102996Smayasystem_value("global_invocation_id", 3, bit_sizes=[32, 64])
7487ec681f3Smrgsystem_value("global_invocation_id_zero_base", 3, bit_sizes=[32, 64])
7497ec681f3Smrgsystem_value("base_global_invocation_id", 3, bit_sizes=[32, 64])
7507e102996Smayasystem_value("global_invocation_index", 1, bit_sizes=[32, 64])
75101e04c3fSmrgsystem_value("work_dim", 1)
7527ec681f3Smrgsystem_value("line_width", 1)
7537ec681f3Smrgsystem_value("aa_line_width", 1)
7547ec681f3Smrg# BASE=0 for global/shader, BASE=1 for local/function
7557ec681f3Smrgsystem_value("scratch_base_ptr", 0, bit_sizes=[32,64], indices=[BASE])
7567ec681f3Smrgsystem_value("constant_base_ptr", 0, bit_sizes=[32,64])
7577ec681f3Smrgsystem_value("shared_base_ptr", 0, bit_sizes=[32,64])
7587ec681f3Smrg
7597ec681f3Smrg# System values for ray tracing.
7607ec681f3Smrgsystem_value("ray_launch_id", 3)
7617ec681f3Smrgsystem_value("ray_launch_size", 3)
7627ec681f3Smrgsystem_value("ray_world_origin", 3)
7637ec681f3Smrgsystem_value("ray_world_direction", 3)
7647ec681f3Smrgsystem_value("ray_object_origin", 3)
7657ec681f3Smrgsystem_value("ray_object_direction", 3)
7667ec681f3Smrgsystem_value("ray_t_min", 1)
7677ec681f3Smrgsystem_value("ray_t_max", 1)
7687ec681f3Smrgsystem_value("ray_object_to_world", 3, indices=[COLUMN])
7697ec681f3Smrgsystem_value("ray_world_to_object", 3, indices=[COLUMN])
7707ec681f3Smrgsystem_value("ray_hit_kind", 1)
7717ec681f3Smrgsystem_value("ray_flags", 1)
7727ec681f3Smrgsystem_value("ray_geometry_index", 1)
7737ec681f3Smrgsystem_value("ray_instance_custom_index", 1)
7747ec681f3Smrgsystem_value("shader_record_ptr", 1, bit_sizes=[64])
7757ec681f3Smrg
7767e102996Smaya# Driver-specific viewport scale/offset parameters.
7777e102996Smaya#
7787e102996Smaya# VC4 and V3D need to emit a scaled version of the position in the vertex
7797e102996Smaya# shaders for binning, and having system values lets us move the math for that
7807e102996Smaya# into NIR.
7817e102996Smaya#
7827e102996Smaya# Panfrost needs to implement all coordinate transformation in the
7837e102996Smaya# vertex shader; system values allow us to share this routine in NIR.
7847ec681f3Smrg#
7857ec681f3Smrg# RADV uses these for NGG primitive culling.
7867e102996Smayasystem_value("viewport_x_scale", 1)
7877e102996Smayasystem_value("viewport_y_scale", 1)
7887e102996Smayasystem_value("viewport_z_scale", 1)
7897ec681f3Smrgsystem_value("viewport_x_offset", 1)
7907ec681f3Smrgsystem_value("viewport_y_offset", 1)
7917e102996Smayasystem_value("viewport_z_offset", 1)
7927e102996Smayasystem_value("viewport_scale", 3)
7937e102996Smayasystem_value("viewport_offset", 3)
79401e04c3fSmrg
7957ec681f3Smrg# Blend constant color values.  Float values are clamped. Vectored versions are
7967ec681f3Smrg# provided as well for driver convenience
7977ec681f3Smrg
79801e04c3fSmrgsystem_value("blend_const_color_r_float", 1)
79901e04c3fSmrgsystem_value("blend_const_color_g_float", 1)
80001e04c3fSmrgsystem_value("blend_const_color_b_float", 1)
80101e04c3fSmrgsystem_value("blend_const_color_a_float", 1)
8027ec681f3Smrgsystem_value("blend_const_color_rgba", 4)
80301e04c3fSmrgsystem_value("blend_const_color_rgba8888_unorm", 1)
80401e04c3fSmrgsystem_value("blend_const_color_aaaa8888_unorm", 1)
80501e04c3fSmrg
8067ec681f3Smrg# System values for gl_Color, for radeonsi which interpolates these in the
8077ec681f3Smrg# shader prolog to handle two-sided color without recompiles and therefore
8087ec681f3Smrg# doesn't handle these in the main shader part like normal varyings.
8097ec681f3Smrgsystem_value("color0", 4)
8107ec681f3Smrgsystem_value("color1", 4)
8117ec681f3Smrg
8127ec681f3Smrg# System value for internal compute shaders in radeonsi.
8137ec681f3Smrgsystem_value("user_data_amd", 4)
8147ec681f3Smrg
81501e04c3fSmrg# Barycentric coordinate intrinsics.
81601e04c3fSmrg#
81701e04c3fSmrg# These set up the barycentric coordinates for a particular interpolation.
8187ec681f3Smrg# The first four are for the simple cases: pixel, centroid, per-sample
8197ec681f3Smrg# (at gl_SampleID), or pull model (1/W, 1/I, 1/J) at the pixel center. The next
8207ec681f3Smrg# two handle interpolating at a specified sample location, or interpolating
8217ec681f3Smrg# with a vec2 offset,
82201e04c3fSmrg#
82301e04c3fSmrg# The interp_mode index should be either the INTERP_MODE_SMOOTH or
82401e04c3fSmrg# INTERP_MODE_NOPERSPECTIVE enum values.
82501e04c3fSmrg#
82601e04c3fSmrg# The vec2 value produced by these intrinsics is intended for use as the
82701e04c3fSmrg# barycoord source of a load_interpolated_input intrinsic.
82801e04c3fSmrg
8297ec681f3Smrgdef barycentric(name, dst_comp, src_comp=[]):
8307ec681f3Smrg    intrinsic("load_barycentric_" + name, src_comp=src_comp, dest_comp=dst_comp,
83101e04c3fSmrg              indices=[INTERP_MODE], flags=[CAN_ELIMINATE, CAN_REORDER])
83201e04c3fSmrg
8337e102996Smaya# no sources.
8347ec681f3Smrgbarycentric("pixel", 2)
8357ec681f3Smrgbarycentric("centroid", 2)
8367ec681f3Smrgbarycentric("sample", 2)
8377ec681f3Smrgbarycentric("model", 3)
8387e102996Smaya# src[] = { sample_id }.
8397ec681f3Smrgbarycentric("at_sample", 2, [1])
8407e102996Smaya# src[] = { offset.xy }.
8417ec681f3Smrgbarycentric("at_offset", 2, [2])
84201e04c3fSmrg
8437e102996Smaya# Load sample position:
8447e102996Smaya#
8457e102996Smaya# Takes a sample # and returns a sample position.  Used for lowering
8467e102996Smaya# interpolateAtSample() to interpolateAtOffset()
8477e102996Smayaintrinsic("load_sample_pos_from_id", src_comp=[1], dest_comp=2,
8487e102996Smaya          flags=[CAN_ELIMINATE, CAN_REORDER])
8497e102996Smaya
8507e102996Smaya# Loads what I believe is the primitive size, for scaling ij to pixel size:
8517e102996Smayaintrinsic("load_size_ir3", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
8527e102996Smaya
8537ec681f3Smrg# Load texture scaling values:
8547ec681f3Smrg#
8557ec681f3Smrg# Takes a sampler # and returns 1/size values for multiplying to normalize
8567ec681f3Smrg# texture coordinates.  Used for lowering rect textures.
8577ec681f3Smrgintrinsic("load_texture_rect_scaling", src_comp=[1], dest_comp=2,
8587ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
8597ec681f3Smrg
8607ec681f3Smrg# Fragment shader input interpolation delta intrinsic.
8617ec681f3Smrg#
8627ec681f3Smrg# For hw where fragment shader input interpolation is handled in shader, the
8637ec681f3Smrg# load_fs_input_interp deltas intrinsics can be used to load the input deltas
8647ec681f3Smrg# used for interpolation as follows:
8657ec681f3Smrg#
8667ec681f3Smrg#    vec3 iid = load_fs_input_interp_deltas(varying_slot)
8677ec681f3Smrg#    vec2 bary = load_barycentric_*(...)
8687ec681f3Smrg#    float result = iid.x + iid.y * bary.y + iid.z * bary.x
8697ec681f3Smrg
8707ec681f3Smrgintrinsic("load_fs_input_interp_deltas", src_comp=[1], dest_comp=3,
8717ec681f3Smrg          indices=[BASE, COMPONENT, IO_SEMANTICS], flags=[CAN_ELIMINATE, CAN_REORDER])
8727ec681f3Smrg
87301e04c3fSmrg# Load operations pull data from some piece of GPU memory.  All load
87401e04c3fSmrg# operations operate in terms of offsets into some piece of theoretical
87501e04c3fSmrg# memory.  Loads from externally visible memory (UBO and SSBO) simply take a
87601e04c3fSmrg# byte offset as a source.  Loads from opaque memory (uniforms, inputs, etc.)
8777e102996Smaya# take a base+offset pair where the nir_intrinsic_base() gives the location
87801e04c3fSmrg# of the start of the variable being loaded and and the offset source is a
87901e04c3fSmrg# offset into that variable.
88001e04c3fSmrg#
8817e102996Smaya# Uniform load operations have a nir_intrinsic_range() index that specifies the
88201e04c3fSmrg# range (starting at base) of the data from which we are loading.  If
8837e102996Smaya# range == 0, then the range is unknown.
88401e04c3fSmrg#
8857ec681f3Smrg# UBO load operations have a nir_intrinsic_range_base() and
8867ec681f3Smrg# nir_intrinsic_range() that specify the byte range [range_base,
8877ec681f3Smrg# range_base+range] of the UBO that the src offset access must lie within.
8887ec681f3Smrg#
88901e04c3fSmrg# Some load operations such as UBO/SSBO load and per_vertex loads take an
89001e04c3fSmrg# additional source to specify which UBO/SSBO/vertex to load from.
89101e04c3fSmrg#
89201e04c3fSmrg# The exact address type depends on the lowering pass that generates the
89301e04c3fSmrg# load/store intrinsics.  Typically, this is vec4 units for things such as
89401e04c3fSmrg# varying slots and float units for fragment shader inputs.  UBO and SSBO
89501e04c3fSmrg# offsets are always in bytes.
89601e04c3fSmrg
8977ec681f3Smrgdef load(name, src_comp, indices=[], flags=[]):
8987ec681f3Smrg    intrinsic("load_" + name, src_comp, dest_comp=0, indices=indices,
89901e04c3fSmrg              flags=flags)
90001e04c3fSmrg
9017e102996Smaya# src[] = { offset }.
9027ec681f3Smrgload("uniform", [1], [BASE, RANGE, DEST_TYPE], [CAN_ELIMINATE, CAN_REORDER])
9037e102996Smaya# src[] = { buffer_index, offset }.
9047ec681f3Smrgload("ubo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET, RANGE_BASE, RANGE], flags=[CAN_ELIMINATE, CAN_REORDER])
9057ec681f3Smrg# src[] = { buffer_index, offset in vec4 units }
9067ec681f3Smrgload("ubo_vec4", [-1, 1], [ACCESS, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER])
9077e102996Smaya# src[] = { offset }.
9087ec681f3Smrgload("input", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
9097ec681f3Smrg# src[] = { vertex_id, offset }.
9107ec681f3Smrgload("input_vertex", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
9117e102996Smaya# src[] = { vertex, offset }.
9127ec681f3Smrgload("per_vertex_input", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
9137e102996Smaya# src[] = { barycoord, offset }.
9147ec681f3Smrgload("interpolated_input", [2, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])
91501e04c3fSmrg
9167e102996Smaya# src[] = { buffer_index, offset }.
9177ec681f3Smrgload("ssbo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
9187ec681f3Smrg# src[] = { buffer_index }
9197ec681f3Smrgload("ssbo_address", [1], [], [CAN_ELIMINATE, CAN_REORDER])
9207e102996Smaya# src[] = { offset }.
9217ec681f3Smrgload("output", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], flags=[CAN_ELIMINATE])
9227e102996Smaya# src[] = { vertex, offset }.
9237ec681f3Smrgload("per_vertex_output", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])
9247ec681f3Smrg# src[] = { primitive, offset }.
9257ec681f3Smrgload("per_primitive_output", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])
9267e102996Smaya# src[] = { offset }.
9277ec681f3Smrgload("shared", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
9287e102996Smaya# src[] = { offset }.
9297ec681f3Smrgload("push_constant", [1], [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
9307e102996Smaya# src[] = { offset }.
9317ec681f3Smrgload("constant", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET],
9327ec681f3Smrg     [CAN_ELIMINATE, CAN_REORDER])
9337ec681f3Smrg# src[] = { address }.
9347ec681f3Smrgload("global", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
9357e102996Smaya# src[] = { address }.
9367ec681f3Smrgload("global_constant", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
9377ec681f3Smrg     [CAN_ELIMINATE, CAN_REORDER])
9387ec681f3Smrg# src[] = { base_address, offset }.
9397ec681f3Smrgload("global_constant_offset", [1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
9407ec681f3Smrg     [CAN_ELIMINATE, CAN_REORDER])
9417ec681f3Smrg# src[] = { base_address, offset, bound }.
9427ec681f3Smrgload("global_constant_bounded", [1, 1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],
9437ec681f3Smrg     [CAN_ELIMINATE, CAN_REORDER])
9447e102996Smaya# src[] = { address }.
9457ec681f3Smrgload("kernel_input", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE, CAN_REORDER])
9467e102996Smaya# src[] = { offset }.
9477ec681f3Smrgload("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
94801e04c3fSmrg
94901e04c3fSmrg# Stores work the same way as loads, except now the first source is the value
95001e04c3fSmrg# to store and the second (and possibly third) source specify where to store
9517e102996Smaya# the value.  SSBO and shared memory stores also have a
9527e102996Smaya# nir_intrinsic_write_mask()
95301e04c3fSmrg
9547ec681f3Smrgdef store(name, srcs, indices=[], flags=[]):
9557ec681f3Smrg    intrinsic("store_" + name, [0] + srcs, indices=indices, flags=flags)
95601e04c3fSmrg
9577e102996Smaya# src[] = { value, offset }.
9587ec681f3Smrgstore("output", [1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
95901e04c3fSmrg# src[] = { value, vertex, offset }.
9607ec681f3Smrgstore("per_vertex_output", [1, 1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
9617ec681f3Smrg# src[] = { value, primitive, offset }.
9627ec681f3Smrgstore("per_primitive_output", [1, 1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])
9637e102996Smaya# src[] = { value, block_index, offset }
9647ec681f3Smrgstore("ssbo", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
9657e102996Smaya# src[] = { value, offset }.
9667ec681f3Smrgstore("shared", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
9677e102996Smaya# src[] = { value, address }.
9687ec681f3Smrgstore("global", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
9697e102996Smaya# src[] = { value, offset }.
9707ec681f3Smrgstore("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK])
9717ec681f3Smrg
9727ec681f3Smrg# A bit field to implement SPIRV FragmentShadingRateKHR
9737ec681f3Smrg# bit | name              | description
9747ec681f3Smrg#   0 | Vertical2Pixels   | Fragment invocation covers 2 pixels vertically
9757ec681f3Smrg#   1 | Vertical4Pixels   | Fragment invocation covers 4 pixels vertically
9767ec681f3Smrg#   2 | Horizontal2Pixels | Fragment invocation covers 2 pixels horizontally
9777ec681f3Smrg#   3 | Horizontal4Pixels | Fragment invocation covers 4 pixels horizontally
9787ec681f3Smrgintrinsic("load_frag_shading_rate", dest_comp=1, bit_sizes=[32],
9797ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
9807ec681f3Smrg
9817ec681f3Smrg# OpenCL printf instruction
9827ec681f3Smrg# First source is a deref to the format string
9837ec681f3Smrg# Second source is a deref to a struct containing the args
9847ec681f3Smrg# Dest is success or failure
9857ec681f3Smrgintrinsic("printf", src_comp=[1, 1], dest_comp=1, bit_sizes=[32])
9867ec681f3Smrg# Since most drivers will want to lower to just dumping args
9877ec681f3Smrg# in a buffer, nir_lower_printf will do that, but requires
9887ec681f3Smrg# the driver to at least provide a base location
9897ec681f3Smrgsystem_value("printf_buffer_address", 1, bit_sizes=[32,64])
9907e102996Smaya
9917e102996Smaya# IR3-specific version of most SSBO intrinsics. The only different
9927e102996Smaya# compare to the originals is that they add an extra source to hold
9937e102996Smaya# the dword-offset, which is needed by the backend code apart from
9947e102996Smaya# the byte-offset already provided by NIR in one of the sources.
9957e102996Smaya#
9967e102996Smaya# NIR lowering pass 'ir3_nir_lower_io_offset' will replace the
9977e102996Smaya# original SSBO intrinsics by these, placing the computed
9987e102996Smaya# dword-offset always in the last source.
9997e102996Smaya#
10007e102996Smaya# The float versions are not handled because those are not supported
10017e102996Smaya# by the backend.
10027ec681f3Smrgstore("ssbo_ir3", [1, 1, 1],
10037ec681f3Smrg      indices=[WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
10047ec681f3Smrgload("ssbo_ir3",  [1, 1, 1],
10057ec681f3Smrg     indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
10067ec681f3Smrgintrinsic("ssbo_atomic_add_ir3",        src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10077ec681f3Smrgintrinsic("ssbo_atomic_imin_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10087ec681f3Smrgintrinsic("ssbo_atomic_umin_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10097ec681f3Smrgintrinsic("ssbo_atomic_imax_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10107ec681f3Smrgintrinsic("ssbo_atomic_umax_ir3",       src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10117ec681f3Smrgintrinsic("ssbo_atomic_and_ir3",        src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10127ec681f3Smrgintrinsic("ssbo_atomic_or_ir3",         src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10137ec681f3Smrgintrinsic("ssbo_atomic_xor_ir3",        src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10147ec681f3Smrgintrinsic("ssbo_atomic_exchange_ir3",   src_comp=[1, 1, 1, 1],    dest_comp=1, indices=[ACCESS])
10157ec681f3Smrgintrinsic("ssbo_atomic_comp_swap_ir3",  src_comp=[1, 1, 1, 1, 1], dest_comp=1, indices=[ACCESS])
10167ec681f3Smrg
10177ec681f3Smrg# System values for freedreno geometry shaders.
10187ec681f3Smrgsystem_value("vs_primitive_stride_ir3", 1)
10197ec681f3Smrgsystem_value("vs_vertex_stride_ir3", 1)
10207ec681f3Smrgsystem_value("gs_header_ir3", 1)
10217ec681f3Smrgsystem_value("primitive_location_ir3", 1, indices=[DRIVER_LOCATION])
10227ec681f3Smrg
10237ec681f3Smrg# System values for freedreno tessellation shaders.
10247ec681f3Smrgsystem_value("hs_patch_stride_ir3", 1)
10257ec681f3Smrgsystem_value("tess_factor_base_ir3", 2)
10267ec681f3Smrgsystem_value("tess_param_base_ir3", 2)
10277ec681f3Smrgsystem_value("tcs_header_ir3", 1)
10287ec681f3Smrgsystem_value("rel_patch_id_ir3", 1)
10297ec681f3Smrg
10307ec681f3Smrg# System values for freedreno compute shaders.
10317ec681f3Smrgsystem_value("subgroup_id_shift_ir3", 1)
10327ec681f3Smrg
10337ec681f3Smrg# IR3-specific intrinsics for tessellation control shaders.  cond_end_ir3 end
10347ec681f3Smrg# the shader when src0 is false and is used to narrow down the TCS shader to
10357ec681f3Smrg# just thread 0 before writing out tessellation levels.
10367ec681f3Smrgintrinsic("cond_end_ir3", src_comp=[1])
10377ec681f3Smrg# end_patch_ir3 is used just before thread 0 exist the TCS and presumably
10387ec681f3Smrg# signals the TE that the patch is complete and can be tessellated.
10397ec681f3Smrgintrinsic("end_patch_ir3")
10407ec681f3Smrg
10417ec681f3Smrg# IR3-specific load/store intrinsics. These access a buffer used to pass data
10427ec681f3Smrg# between geometry stages - perhaps it's explicit access to the vertex cache.
10437ec681f3Smrg
10447ec681f3Smrg# src[] = { value, offset }.
10457ec681f3Smrgstore("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET])
10467ec681f3Smrg# src[] = { offset }.
10477ec681f3Smrgload("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
10487ec681f3Smrg
10497ec681f3Smrg# IR3-specific load/store global intrinsics. They take a 64-bit base address
10507ec681f3Smrg# and a 32-bit offset.  The hardware will add the base and the offset, which
10517ec681f3Smrg# saves us from doing 64-bit math on the base address.
10527ec681f3Smrg
10537ec681f3Smrg# src[] = { value, address(vec2 of hi+lo uint32_t), offset }.
10547ec681f3Smrg# const_index[] = { write_mask, align_mul, align_offset }
10557ec681f3Smrgstore("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET])
10567ec681f3Smrg# src[] = { address(vec2 of hi+lo uint32_t), offset }.
10577ec681f3Smrg# const_index[] = { access, align_mul, align_offset }
10587ec681f3Smrgload("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])
10597ec681f3Smrg
10607ec681f3Smrg# IR3-specific bindless handle specifier. Similar to vulkan_resource_index, but
10617ec681f3Smrg# without the binding because the hardware expects a single flattened index
10627ec681f3Smrg# rather than a (binding, index) pair. We may also want to use this with GL.
10637ec681f3Smrg# Note that this doesn't actually turn into a HW instruction.
10647ec681f3Smrgintrinsic("bindless_resource_ir3", [1], dest_comp=1, indices=[DESC_SET], flags=[CAN_ELIMINATE, CAN_REORDER])
10657ec681f3Smrg
10667ec681f3Smrg# DXIL specific intrinsics
10677ec681f3Smrg# src[] = { value, mask, index, offset }.
10687ec681f3Smrgintrinsic("store_ssbo_masked_dxil", [1, 1, 1, 1])
10697ec681f3Smrg# src[] = { value, index }.
10707ec681f3Smrgintrinsic("store_shared_dxil", [1, 1])
10717ec681f3Smrg# src[] = { value, mask, index }.
10727ec681f3Smrgintrinsic("store_shared_masked_dxil", [1, 1, 1])
10737ec681f3Smrg# src[] = { value, index }.
10747ec681f3Smrgintrinsic("store_scratch_dxil", [1, 1])
10757ec681f3Smrg# src[] = { index }.
10767ec681f3Smrgload("shared_dxil", [1], [], [CAN_ELIMINATE])
10777ec681f3Smrg# src[] = { index }.
10787ec681f3Smrgload("scratch_dxil", [1], [], [CAN_ELIMINATE])
10797ec681f3Smrg# src[] = { deref_var, offset }
10807ec681f3Smrgload("ptr_dxil", [1, 1], [], [])
10817ec681f3Smrg# src[] = { index, 16-byte-based-offset }
10827ec681f3Smrgload("ubo_dxil", [1, 1], [], [CAN_ELIMINATE, CAN_REORDER])
10837ec681f3Smrg
10847ec681f3Smrg# DXIL Shared atomic intrinsics
10857ec681f3Smrg#
10867ec681f3Smrg# All of the shared variable atomic memory operations read a value from
10877ec681f3Smrg# memory, compute a new value using one of the operations below, write the
10887ec681f3Smrg# new value to memory, and return the original value read.
10897ec681f3Smrg#
10907ec681f3Smrg# All operations take 2 sources:
10917ec681f3Smrg#
10927ec681f3Smrg# 0: The index in the i32 array for by the shared memory region
10937ec681f3Smrg# 1: The data parameter to the atomic function (i.e. the value to add
10947ec681f3Smrg#    in shared_atomic_add, etc).
10957ec681f3Smrgintrinsic("shared_atomic_add_dxil",  src_comp=[1, 1], dest_comp=1)
10967ec681f3Smrgintrinsic("shared_atomic_imin_dxil", src_comp=[1, 1], dest_comp=1)
10977ec681f3Smrgintrinsic("shared_atomic_umin_dxil", src_comp=[1, 1], dest_comp=1)
10987ec681f3Smrgintrinsic("shared_atomic_imax_dxil", src_comp=[1, 1], dest_comp=1)
10997ec681f3Smrgintrinsic("shared_atomic_umax_dxil", src_comp=[1, 1], dest_comp=1)
11007ec681f3Smrgintrinsic("shared_atomic_and_dxil",  src_comp=[1, 1], dest_comp=1)
11017ec681f3Smrgintrinsic("shared_atomic_or_dxil",   src_comp=[1, 1], dest_comp=1)
11027ec681f3Smrgintrinsic("shared_atomic_xor_dxil",  src_comp=[1, 1], dest_comp=1)
11037ec681f3Smrgintrinsic("shared_atomic_exchange_dxil", src_comp=[1, 1], dest_comp=1)
11047ec681f3Smrgintrinsic("shared_atomic_comp_swap_dxil", src_comp=[1, 1, 1], dest_comp=1)
11057ec681f3Smrg
11067ec681f3Smrg# Intrinsics used by the Midgard/Bifrost blend pipeline. These are defined
11077ec681f3Smrg# within a blend shader to read/write the raw value from the tile buffer,
11087ec681f3Smrg# without applying any format conversion in the process. If the shader needs
11097ec681f3Smrg# usable pixel values, it must apply format conversions itself.
11107ec681f3Smrg#
11117ec681f3Smrg# These definitions are generic, but they are explicitly vendored to prevent
11127ec681f3Smrg# other drivers from using them, as their semantics is defined in terms of the
11137ec681f3Smrg# Midgard/Bifrost hardware tile buffer and may not line up with anything sane.
11147ec681f3Smrg# One notable divergence is sRGB, which is asymmetric: raw_input_pan requires
11157ec681f3Smrg# an sRGB->linear conversion, but linear values should be written to
11167ec681f3Smrg# raw_output_pan and the hardware handles linear->sRGB.
11177ec681f3Smrg
11187ec681f3Smrg# src[] = { value }
11197ec681f3Smrgstore("raw_output_pan", [], [])
11207ec681f3Smrgstore("combined_output_pan", [1, 1, 1], [BASE, COMPONENT, SRC_TYPE])
11217ec681f3Smrgload("raw_output_pan", [1], [BASE], [CAN_ELIMINATE, CAN_REORDER])
11227ec681f3Smrg
11237ec681f3Smrg# Loads the sampler paramaters <min_lod, max_lod, lod_bias>
11247ec681f3Smrg# src[] = { sampler_index }
11257ec681f3Smrgload("sampler_lod_parameters_pan", [1], flags=[CAN_ELIMINATE, CAN_REORDER])
11267ec681f3Smrg
11277ec681f3Smrg# Loads the sample position array on Bifrost, in a packed Arm-specific format
11287ec681f3Smrgsystem_value("sample_positions_pan", 1, bit_sizes=[64])
11297ec681f3Smrg
11307ec681f3Smrg# R600 specific instrincs
11317ec681f3Smrg#
11327ec681f3Smrg# location where the tesselation data is stored in LDS
11337ec681f3Smrgsystem_value("tcs_in_param_base_r600", 4)
11347ec681f3Smrgsystem_value("tcs_out_param_base_r600", 4)
11357ec681f3Smrgsystem_value("tcs_rel_patch_id_r600", 1)
11367ec681f3Smrgsystem_value("tcs_tess_factor_base_r600", 1)
11377ec681f3Smrg
11387ec681f3Smrg# the tess coords come as xy only, z has to be calculated
11397ec681f3Smrgsystem_value("tess_coord_r600", 2)
11407ec681f3Smrg
11417ec681f3Smrg# load as many components as needed giving per-component addresses
11427ec681f3Smrgintrinsic("load_local_shared_r600", src_comp=[0], dest_comp=0, indices = [], flags = [CAN_ELIMINATE])
11437ec681f3Smrg
11447ec681f3Smrgstore("local_shared_r600", [1], [WRITE_MASK])
11457ec681f3Smrgstore("tf_r600", [])
11467ec681f3Smrg
11477ec681f3Smrg# AMD GCN/RDNA specific intrinsics
11487ec681f3Smrg
11497ec681f3Smrg# src[] = { descriptor, base address, scalar offset }
11507ec681f3Smrgintrinsic("load_buffer_amd", src_comp=[4, 1, 1], dest_comp=0, indices=[BASE, IS_SWIZZLED, SLC_AMD, MEMORY_MODES], flags=[CAN_ELIMINATE])
11517ec681f3Smrg# src[] = { store value, descriptor, base address, scalar offset }
11527ec681f3Smrgintrinsic("store_buffer_amd", src_comp=[0, 4, 1, 1], indices=[BASE, WRITE_MASK, IS_SWIZZLED, SLC_AMD, MEMORY_MODES])
11537ec681f3Smrg
11547ec681f3Smrg# Same as shared_atomic_add, but with GDS. src[] = {store_val, gds_addr, m0}
11557ec681f3Smrgintrinsic("gds_atomic_add_amd",  src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
11567ec681f3Smrg
11577ec681f3Smrg# Descriptor where TCS outputs are stored for TES
11587ec681f3Smrgsystem_value("ring_tess_offchip_amd", 4)
11597ec681f3Smrgsystem_value("ring_tess_offchip_offset_amd", 1)
11607ec681f3Smrg# Descriptor where TCS outputs are stored for the HW tessellator
11617ec681f3Smrgsystem_value("ring_tess_factors_amd", 4)
11627ec681f3Smrgsystem_value("ring_tess_factors_offset_amd", 1)
11637ec681f3Smrg# Descriptor where ES outputs are stored for GS to read on GFX6-8
11647ec681f3Smrgsystem_value("ring_esgs_amd", 4)
11657ec681f3Smrgsystem_value("ring_es2gs_offset_amd", 1)
11667ec681f3Smrg
11677ec681f3Smrg# Number of patches processed by each TCS workgroup
11687ec681f3Smrgsystem_value("tcs_num_patches_amd", 1)
11697ec681f3Smrg# Relative tessellation patch ID within the current workgroup
11707ec681f3Smrgsystem_value("tess_rel_patch_id_amd", 1)
11717ec681f3Smrg# Vertex offsets used for GS per-vertex inputs
11727ec681f3Smrgsystem_value("gs_vertex_offset_amd", 1, [BASE])
11737ec681f3Smrg
11747ec681f3Smrg# AMD merged shader intrinsics
11757ec681f3Smrg
11767ec681f3Smrg# Whether the current invocation has an input vertex / primitive to process (also known as "ES thread" or "GS thread").
11777ec681f3Smrg# Not safe to reorder because it changes after overwrite_subgroup_num_vertices_and_primitives_amd.
11787ec681f3Smrg# Also, the generated code is more optimal if they are not CSE'd.
11797ec681f3Smrgintrinsic("has_input_vertex_amd", src_comp=[], dest_comp=1, bit_sizes=[1], indices=[])
11807ec681f3Smrgintrinsic("has_input_primitive_amd", src_comp=[], dest_comp=1, bit_sizes=[1], indices=[])
11817ec681f3Smrg
11827ec681f3Smrg# AMD NGG intrinsics
11837ec681f3Smrg
11847ec681f3Smrg# Number of initial input vertices in the current workgroup.
11857ec681f3Smrgsystem_value("workgroup_num_input_vertices_amd", 1)
11867ec681f3Smrg# Number of initial input primitives in the current workgroup.
11877ec681f3Smrgsystem_value("workgroup_num_input_primitives_amd", 1)
11887ec681f3Smrg# For NGG passthrough mode only. Pre-packed argument for export_primitive_amd.
11897ec681f3Smrgsystem_value("packed_passthrough_primitive_amd", 1)
11907ec681f3Smrg# Whether NGG GS should execute shader query.
11917ec681f3Smrgsystem_value("shader_query_enabled_amd", dest_comp=1, bit_sizes=[1])
11927ec681f3Smrg# Whether the shader should cull front facing triangles.
11937ec681f3Smrgintrinsic("load_cull_front_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
11947ec681f3Smrg# Whether the shader should cull back facing triangles.
11957ec681f3Smrgintrinsic("load_cull_back_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
11967ec681f3Smrg# True if face culling should use CCW (false if CW).
11977ec681f3Smrgintrinsic("load_cull_ccw_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
11987ec681f3Smrg# Whether the shader should cull small primitives that are not visible in a pixel.
11997ec681f3Smrgintrinsic("load_cull_small_primitives_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
12007ec681f3Smrg# Whether any culling setting is enabled in the shader.
12017ec681f3Smrgintrinsic("load_cull_any_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])
12027ec681f3Smrg# Small primitive culling precision
12037ec681f3Smrgintrinsic("load_cull_small_prim_precision_amd", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])
12047ec681f3Smrg# Initial edge flags in a Vertex Shader, packed into the format the HW needs for primitive export.
12057ec681f3Smrgintrinsic("load_initial_edgeflags_amd", src_comp=[], dest_comp=1, bit_sizes=[32], indices=[])
12067ec681f3Smrg# Exports the current invocation's vertex. This is a placeholder where all vertex attribute export instructions should be emitted.
12077ec681f3Smrgintrinsic("export_vertex_amd", src_comp=[], indices=[])
12087ec681f3Smrg# Exports the current invocation's primitive. src[] = {packed_primitive_data}.
12097ec681f3Smrgintrinsic("export_primitive_amd", src_comp=[1], indices=[])
12107ec681f3Smrg# Allocates export space for vertices and primitives. src[] = {num_vertices, num_primitives}.
12117ec681f3Smrgintrinsic("alloc_vertices_and_primitives_amd", src_comp=[1, 1], indices=[])
12127ec681f3Smrg# Overwrites VS input registers, for use with vertex compaction after culling. src = {vertex_id, instance_id}.
12137ec681f3Smrgintrinsic("overwrite_vs_arguments_amd", src_comp=[1, 1], indices=[])
12147ec681f3Smrg# Overwrites TES input registers, for use with vertex compaction after culling. src = {tes_u, tes_v, rel_patch_id, patch_id}.
12157ec681f3Smrgintrinsic("overwrite_tes_arguments_amd", src_comp=[1, 1, 1, 1], indices=[])
12167ec681f3Smrg
12177ec681f3Smrg# loads a descriptor for an sbt.
12187ec681f3Smrg# src = [index] BINDING = which table
12197ec681f3Smrgintrinsic("load_sbt_amd", dest_comp=4, bit_sizes=[32], indices=[BINDING],
12207ec681f3Smrg          flags=[CAN_ELIMINATE, CAN_REORDER])
12217ec681f3Smrg
12227ec681f3Smrg# 1. HW descriptor
12237ec681f3Smrg# 2. BVH node(64-bit pointer as 2x32 ...)
12247ec681f3Smrg# 3. ray extent
12257ec681f3Smrg# 4. ray origin
12267ec681f3Smrg# 5. ray direction
12277ec681f3Smrg# 6. inverse ray direction (componentwise 1.0/ray direction)
12287ec681f3Smrgintrinsic("bvh64_intersect_ray_amd", [4, 2, 1, 3, 3, 3], 4, flags=[CAN_ELIMINATE, CAN_REORDER])
12297ec681f3Smrg
12307ec681f3Smrg# Return of a callable in raytracing pipelines
12317ec681f3Smrgintrinsic("rt_return_amd")
12327ec681f3Smrg
12337ec681f3Smrg# offset into scratch for the input callable data in a raytracing pipeline.
12347ec681f3Smrgsystem_value("rt_arg_scratch_offset_amd", 1)
12357ec681f3Smrg
12367ec681f3Smrg# Whether to call the anyhit shader for an intersection in an intersection shader.
12377ec681f3Smrgsystem_value("intersection_opaque_amd", 1, bit_sizes=[1])
12387ec681f3Smrg
12397ec681f3Smrg# V3D-specific instrinc for tile buffer color reads.
12407ec681f3Smrg#
12417ec681f3Smrg# The hardware requires that we read the samples and components of a pixel
12427ec681f3Smrg# in order, so we cannot eliminate or remove any loads in a sequence.
12437ec681f3Smrg#
12447ec681f3Smrg# src[] = { render_target }
12457ec681f3Smrg# BASE = sample index
12467ec681f3Smrgload("tlb_color_v3d", [1], [BASE, COMPONENT], [])
12477ec681f3Smrg
12487ec681f3Smrg# V3D-specific instrinc for per-sample tile buffer color writes.
12497ec681f3Smrg#
12507ec681f3Smrg# The driver backend needs to identify per-sample color writes and emit
12517ec681f3Smrg# specific code for them.
12527ec681f3Smrg#
12537ec681f3Smrg# src[] = { value, render_target }
12547ec681f3Smrg# BASE = sample index
12557ec681f3Smrgstore("tlb_sample_color_v3d", [1], [BASE, COMPONENT, SRC_TYPE], [])
12567ec681f3Smrg
12577ec681f3Smrg# V3D-specific intrinsic to load the number of layers attached to
12587ec681f3Smrg# the target framebuffer
12597ec681f3Smrgintrinsic("load_fb_layers_v3d", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
12607ec681f3Smrg
12617ec681f3Smrg# Logical complement of load_front_face, mapping to an AGX system value
12627ec681f3Smrgsystem_value("back_face_agx", 1, bit_sizes=[1, 32])
12637ec681f3Smrg
12647ec681f3Smrg# Intel-specific query for loading from the brw_image_param struct passed
12657ec681f3Smrg# into the shader as a uniform.  The variable is a deref to the image
12667ec681f3Smrg# variable. The const index specifies which of the six parameters to load.
12677ec681f3Smrgintrinsic("image_deref_load_param_intel", src_comp=[1], dest_comp=0,
12687ec681f3Smrg          indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
12697ec681f3Smrgimage("load_raw_intel", src_comp=[1], dest_comp=0,
12707ec681f3Smrg      flags=[CAN_ELIMINATE])
12717ec681f3Smrgimage("store_raw_intel", src_comp=[1, 0])
12727ec681f3Smrg
12737ec681f3Smrg# Intrinsic to load a block of at least 32B of constant data from a 64-bit
12747ec681f3Smrg# global memory address.  The memory address must be uniform and 32B-aligned.
12757ec681f3Smrg# The second source is a predicate which indicates whether or not to actually
12767ec681f3Smrg# do the load.
12777ec681f3Smrg# src[] = { address, predicate }.
12787ec681f3Smrgintrinsic("load_global_const_block_intel", src_comp=[1, 1], dest_comp=0,
12797ec681f3Smrg          bit_sizes=[32], indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])
12807ec681f3Smrg
12817ec681f3Smrg# Number of data items being operated on for a SIMD program.
12827ec681f3Smrgsystem_value("simd_width_intel", 1)
12837ec681f3Smrg
12847ec681f3Smrg# Load a relocatable 32-bit value
12857ec681f3Smrgintrinsic("load_reloc_const_intel", dest_comp=1, bit_sizes=[32],
12867ec681f3Smrg          indices=[PARAM_IDX], flags=[CAN_ELIMINATE, CAN_REORDER])
12877ec681f3Smrg
12887ec681f3Smrg# 64-bit global address for a Vulkan descriptor set
12897ec681f3Smrg# src[0] = { set }
12907ec681f3Smrgintrinsic("load_desc_set_address_intel", dest_comp=1, bit_sizes=[64],
12917ec681f3Smrg          src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])
12927ec681f3Smrg
12937ec681f3Smrg# OpSubgroupBlockReadINTEL and OpSubgroupBlockWriteINTEL from SPV_INTEL_subgroups.
12947ec681f3Smrgintrinsic("load_deref_block_intel", dest_comp=0, src_comp=[-1],
12957ec681f3Smrg          indices=[ACCESS], flags=[CAN_ELIMINATE])
12967ec681f3Smrgintrinsic("store_deref_block_intel", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])
12977ec681f3Smrg
12987ec681f3Smrg# src[] = { address }.
12997ec681f3Smrgload("global_block_intel", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
13007ec681f3Smrg
13017ec681f3Smrg# src[] = { buffer_index, offset }.
13027ec681f3Smrgload("ssbo_block_intel", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
13037ec681f3Smrg
13047ec681f3Smrg# src[] = { offset }.
13057ec681f3Smrgload("shared_block_intel", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])
13067ec681f3Smrg
13077ec681f3Smrg# src[] = { value, address }.
13087ec681f3Smrgstore("global_block_intel", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
13097ec681f3Smrg
13107ec681f3Smrg# src[] = { value, block_index, offset }
13117ec681f3Smrgstore("ssbo_block_intel", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])
13127ec681f3Smrg
13137ec681f3Smrg# src[] = { value, offset }.
13147ec681f3Smrgstore("shared_block_intel", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])
13157ec681f3Smrg
13167ec681f3Smrg# Intrinsics for Intel bindless thread dispatch
13177ec681f3Smrgsystem_value("btd_dss_id_intel", 1)
13187ec681f3Smrgsystem_value("btd_stack_id_intel", 1)
13197ec681f3Smrgsystem_value("btd_global_arg_addr_intel", 1, bit_sizes=[64])
13207ec681f3Smrgsystem_value("btd_local_arg_addr_intel", 1, bit_sizes=[64])
13217ec681f3Smrgsystem_value("btd_resume_sbt_addr_intel", 1, bit_sizes=[64])
13227ec681f3Smrg# src[] = { global_arg_addr, btd_record }
13237ec681f3Smrgintrinsic("btd_spawn_intel", src_comp=[1, 1])
13247ec681f3Smrg# RANGE=stack_size
13257ec681f3Smrgintrinsic("btd_stack_push_intel", indices=[STACK_SIZE])
13267ec681f3Smrg# src[] = { }
13277ec681f3Smrgintrinsic("btd_retire_intel")
13287ec681f3Smrg
13297ec681f3Smrg# Intel-specific ray-tracing intrinsics
13307ec681f3Smrgintrinsic("trace_ray_initial_intel")
13317ec681f3Smrgintrinsic("trace_ray_commit_intel")
13327ec681f3Smrgintrinsic("trace_ray_continue_intel")
13337ec681f3Smrg
13347ec681f3Smrg# System values used for ray-tracing on Intel
13357ec681f3Smrgsystem_value("ray_base_mem_addr_intel", 1, bit_sizes=[64])
13367ec681f3Smrgsystem_value("ray_hw_stack_size_intel", 1)
13377ec681f3Smrgsystem_value("ray_sw_stack_size_intel", 1)
13387ec681f3Smrgsystem_value("ray_num_dss_rt_stacks_intel", 1)
13397ec681f3Smrgsystem_value("ray_hit_sbt_addr_intel", 1, bit_sizes=[64])
13407ec681f3Smrgsystem_value("ray_hit_sbt_stride_intel", 1, bit_sizes=[16])
13417ec681f3Smrgsystem_value("ray_miss_sbt_addr_intel", 1, bit_sizes=[64])
13427ec681f3Smrgsystem_value("ray_miss_sbt_stride_intel", 1, bit_sizes=[16])
13437ec681f3Smrgsystem_value("callable_sbt_addr_intel", 1, bit_sizes=[64])
13447ec681f3Smrgsystem_value("callable_sbt_stride_intel", 1, bit_sizes=[16])
13457ec681f3Smrgsystem_value("leaf_opaque_intel", 1, bit_sizes=[1])
13467ec681f3Smrgsystem_value("leaf_procedural_intel", 1, bit_sizes=[1])
1347