Path: blob/21.2-virgl/src/compiler/nir/nir_intrinsics.py
4547 views
#1# Copyright (C) 2018 Red Hat2# Copyright (C) 2014 Intel Corporation3#4# Permission is hereby granted, free of charge, to any person obtaining a5# copy of this software and associated documentation files (the "Software"),6# to deal in the Software without restriction, including without limitation7# the rights to use, copy, modify, merge, publish, distribute, sublicense,8# and/or sell copies of the Software, and to permit persons to whom the9# Software is furnished to do so, subject to the following conditions:10#11# The above copyright notice and this permission notice (including the next12# paragraph) shall be included in all copies or substantial portions of the13# Software.14#15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS21# IN THE SOFTWARE.22#2324# This file defines all the available intrinsics in one place.25#26# The Intrinsic class corresponds one-to-one with nir_intrinsic_info27# structure.2829src0 = ('src', 0)30src1 = ('src', 1)31src2 = ('src', 2)32src3 = ('src', 3)33src4 = ('src', 4)3435class Index(object):36def __init__(self, c_data_type, name):37self.c_data_type = c_data_type38self.name = name3940class Intrinsic(object):41"""Class that represents all the information about an intrinsic opcode.42NOTE: this must be kept in sync with nir_intrinsic_info.43"""44def __init__(self, name, src_components, dest_components,45indices, flags, sysval, bit_sizes):46"""Parameters:4748- name: the intrinsic name49- src_components: list of the number of components per src, 0 means50vectorized instruction with number of components given in the51num_components field in nir_intrinsic_instr.52- dest_components: number of destination components, -1 means no53dest, 0 means number of components given in num_components field54in nir_intrinsic_instr.55- indices: list of constant indicies56- flags: list of semantic flags57- sysval: is this a system-value intrinsic58- bit_sizes: allowed dest bit_sizes or the source it must match59"""60assert isinstance(name, str)61assert isinstance(src_components, list)62if src_components:63assert isinstance(src_components[0], int)64assert isinstance(dest_components, int)65assert isinstance(indices, list)66if indices:67assert isinstance(indices[0], Index)68assert isinstance(flags, list)69if flags:70assert isinstance(flags[0], str)71assert isinstance(sysval, bool)72if isinstance(bit_sizes, list):73assert not bit_sizes or isinstance(bit_sizes[0], int)74else:75assert isinstance(bit_sizes, tuple)76assert bit_sizes[0] == 'src'77assert isinstance(bit_sizes[1], int)7879self.name = name80self.num_srcs = len(src_components)81self.src_components = src_components82self.has_dest = (dest_components >= 0)83self.dest_components = dest_components84self.num_indices = len(indices)85self.indices = indices86self.flags = flags87self.sysval = sysval88self.bit_sizes = bit_sizes if isinstance(bit_sizes, list) else []89self.bit_size_src = bit_sizes[1] if isinstance(bit_sizes, tuple) else -19091#92# Possible flags:93#9495CAN_ELIMINATE = "NIR_INTRINSIC_CAN_ELIMINATE"96CAN_REORDER = "NIR_INTRINSIC_CAN_REORDER"9798INTR_INDICES = []99INTR_OPCODES = {}100101def index(c_data_type, name):102idx = Index(c_data_type, name)103INTR_INDICES.append(idx)104globals()[name.upper()] = idx105106# Defines a new NIR intrinsic. By default, the intrinsic will have no sources107# and no destination.108#109# You can set dest_comp=n to enable a destination for the intrinsic, in which110# case it will have that many components, or =0 for "as many components as the111# NIR destination value."112#113# Set src_comp=n to enable sources for the intruction. It can be an array of114# component counts, or (for convenience) a scalar component count if there's115# only one source. If a component count is 0, it will be as many components as116# the intrinsic has based on the dest_comp.117def intrinsic(name, src_comp=[], dest_comp=-1, indices=[],118flags=[], sysval=False, bit_sizes=[]):119assert name not in INTR_OPCODES120INTR_OPCODES[name] = Intrinsic(name, src_comp, dest_comp,121indices, flags, sysval, bit_sizes)122123#124# Possible indices:125#126127# Generally instructions that take a offset src argument, can encode128# a constant 'base' value which is added to the offset.129index("int", "base")130131# For store instructions, a writemask for the store.132index("unsigned", "write_mask")133134# The stream-id for GS emit_vertex/end_primitive intrinsics.135index("unsigned", "stream_id")136137# The clip-plane id for load_user_clip_plane intrinsic.138index("unsigned", "ucp_id")139140# The offset to the start of the NIR_INTRINSIC_RANGE. This is an alternative141# to NIR_INTRINSIC_BASE for describing the valid range in intrinsics that don't142# have the implicit addition of a base to the offset.143#144# If the [range_base, range] is [0, ~0], then we don't know the possible145# range of the access.146index("unsigned", "range_base")147148# The amount of data, starting from BASE or RANGE_BASE, that this149# instruction may access. This is used to provide bounds if the offset is150# not constant.151index("unsigned", "range")152153# The Vulkan descriptor set for vulkan_resource_index intrinsic.154index("unsigned", "desc_set")155156# The Vulkan descriptor set binding for vulkan_resource_index intrinsic.157index("unsigned", "binding")158159# Component offset160index("unsigned", "component")161162# Column index for matrix system values163index("unsigned", "column")164165# Interpolation mode (only meaningful for FS inputs)166index("unsigned", "interp_mode")167168# A binary nir_op to use when performing a reduction or scan operation169index("unsigned", "reduction_op")170171# Cluster size for reduction operations172index("unsigned", "cluster_size")173174# Parameter index for a load_param intrinsic175index("unsigned", "param_idx")176177# Image dimensionality for image intrinsics178index("enum glsl_sampler_dim", "image_dim")179180# Non-zero if we are accessing an array image181index("bool", "image_array")182183# Image format for image intrinsics184index("enum pipe_format", "format")185186# Access qualifiers for image and memory access intrinsics. ACCESS_RESTRICT is187# not set at the intrinsic if the NIR was created from SPIR-V.188index("enum gl_access_qualifier", "access")189190# call index for split raytracing shaders191index("unsigned", "call_idx")192193# The stack size increment/decrement for split raytracing shaders194index("unsigned", "stack_size")195196# Alignment for offsets and addresses197#198# These two parameters, specify an alignment in terms of a multiplier and199# an offset. The multiplier is always a power of two. The offset or200# address parameter X of the intrinsic is guaranteed to satisfy the201# following:202#203# (X - align_offset) % align_mul == 0204#205# For constant offset values, align_mul will be NIR_ALIGN_MUL_MAX and the206# align_offset will be modulo that.207index("unsigned", "align_mul")208index("unsigned", "align_offset")209210# The Vulkan descriptor type for a vulkan_resource_[re]index intrinsic.211index("unsigned", "desc_type")212213# The nir_alu_type of input data to a store or conversion214index("nir_alu_type", "src_type")215216# The nir_alu_type of the data output from a load or conversion217index("nir_alu_type", "dest_type")218219# The swizzle mask for quad_swizzle_amd & masked_swizzle_amd220index("unsigned", "swizzle_mask")221222# Whether the load_buffer_amd/store_buffer_amd is swizzled223index("bool", "is_swizzled")224225# The SLC ("system level coherent") bit of load_buffer_amd/store_buffer_amd226index("bool", "slc_amd")227228# Separate source/dest access flags for copies229index("enum gl_access_qualifier", "dst_access")230index("enum gl_access_qualifier", "src_access")231232# Driver location of attribute233index("unsigned", "driver_location")234235# Ordering and visibility of a memory operation236index("nir_memory_semantics", "memory_semantics")237238# Modes affected by a memory operation239index("nir_variable_mode", "memory_modes")240241# Scope of a memory operation242index("nir_scope", "memory_scope")243244# Scope of a control barrier245index("nir_scope", "execution_scope")246247# Semantics of an IO instruction248index("struct nir_io_semantics", "io_semantics")249250# Rounding mode for conversions251index("nir_rounding_mode", "rounding_mode")252253# Whether or not to saturate in conversions254index("unsigned", "saturate")255256intrinsic("nop", flags=[CAN_ELIMINATE])257258intrinsic("convert_alu_types", dest_comp=0, src_comp=[0],259indices=[SRC_TYPE, DEST_TYPE, ROUNDING_MODE, SATURATE],260flags=[CAN_ELIMINATE, CAN_REORDER])261262intrinsic("load_param", dest_comp=0, indices=[PARAM_IDX], flags=[CAN_ELIMINATE])263264intrinsic("load_deref", dest_comp=0, src_comp=[-1],265indices=[ACCESS], flags=[CAN_ELIMINATE])266intrinsic("store_deref", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])267intrinsic("copy_deref", src_comp=[-1, -1], indices=[DST_ACCESS, SRC_ACCESS])268intrinsic("memcpy_deref", src_comp=[-1, -1, 1], indices=[DST_ACCESS, SRC_ACCESS])269270# Interpolation of input. The interp_deref_at* intrinsics are similar to the271# load_var intrinsic acting on a shader input except that they interpolate the272# input differently. The at_sample, at_offset and at_vertex intrinsics take an273# additional source that is an integer sample id, a vec2 position offset, or a274# vertex ID respectively.275276intrinsic("interp_deref_at_centroid", dest_comp=0, src_comp=[1],277flags=[ CAN_ELIMINATE, CAN_REORDER])278intrinsic("interp_deref_at_sample", src_comp=[1, 1], dest_comp=0,279flags=[CAN_ELIMINATE, CAN_REORDER])280intrinsic("interp_deref_at_offset", src_comp=[1, 2], dest_comp=0,281flags=[CAN_ELIMINATE, CAN_REORDER])282intrinsic("interp_deref_at_vertex", src_comp=[1, 1], dest_comp=0,283flags=[CAN_ELIMINATE, CAN_REORDER])284285# Gets the length of an unsized array at the end of a buffer286intrinsic("deref_buffer_array_length", src_comp=[-1], dest_comp=1,287indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])288289# Ask the driver for the size of a given SSBO. It takes the buffer index290# as source.291intrinsic("get_ssbo_size", src_comp=[-1], dest_comp=1, bit_sizes=[32],292indices=[ACCESS], flags=[CAN_ELIMINATE, CAN_REORDER])293intrinsic("get_ubo_size", src_comp=[-1], dest_comp=1,294flags=[CAN_ELIMINATE, CAN_REORDER])295296# Intrinsics which provide a run-time mode-check. Unlike the compile-time297# mode checks, a pointer can only have exactly one mode at runtime.298intrinsic("deref_mode_is", src_comp=[-1], dest_comp=1,299indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])300intrinsic("addr_mode_is", src_comp=[-1], dest_comp=1,301indices=[MEMORY_MODES], flags=[CAN_ELIMINATE, CAN_REORDER])302303intrinsic("is_sparse_texels_resident", dest_comp=1, src_comp=[1], bit_sizes=[1],304flags=[CAN_ELIMINATE, CAN_REORDER])305# result code is resident only if both inputs are resident306intrinsic("sparse_residency_code_and", dest_comp=1, src_comp=[1, 1], bit_sizes=[32],307flags=[CAN_ELIMINATE, CAN_REORDER])308309# a barrier is an intrinsic with no inputs/outputs but which can't be moved310# around/optimized in general311def barrier(name):312intrinsic(name)313314barrier("discard")315316# Demote fragment shader invocation to a helper invocation. Any stores to317# memory after this instruction are suppressed and the fragment does not write318# outputs to the framebuffer. Unlike discard, demote needs to ensure that319# derivatives will still work for invocations that were not demoted.320#321# As specified by SPV_EXT_demote_to_helper_invocation.322barrier("demote")323intrinsic("is_helper_invocation", dest_comp=1, flags=[CAN_ELIMINATE])324325# SpvOpTerminateInvocation from SPIR-V. Essentially a discard "for real".326barrier("terminate")327328# A workgroup-level control barrier. Any thread which hits this barrier will329# pause until all threads within the current workgroup have also hit the330# barrier. For compute shaders, the workgroup is defined as the local group.331# For tessellation control shaders, the workgroup is defined as the current332# patch. This intrinsic does not imply any sort of memory barrier.333barrier("control_barrier")334335# Memory barrier with semantics analogous to the memoryBarrier() GLSL336# intrinsic.337barrier("memory_barrier")338339# Control/Memory barrier with explicit scope. Follows the semantics of SPIR-V340# OpMemoryBarrier and OpControlBarrier, used to implement Vulkan Memory Model.341# Storage that the barrier applies is represented using NIR variable modes.342# For an OpMemoryBarrier, set EXECUTION_SCOPE to NIR_SCOPE_NONE.343intrinsic("scoped_barrier",344indices=[EXECUTION_SCOPE, MEMORY_SCOPE, MEMORY_SEMANTICS, MEMORY_MODES])345346# Shader clock intrinsic with semantics analogous to the clock2x32ARB()347# GLSL intrinsic.348# The latter can be used as code motion barrier, which is currently not349# feasible with NIR.350intrinsic("shader_clock", dest_comp=2, bit_sizes=[32], flags=[CAN_ELIMINATE],351indices=[MEMORY_SCOPE])352353# Shader ballot intrinsics with semantics analogous to the354#355# ballotARB()356# readInvocationARB()357# readFirstInvocationARB()358#359# GLSL functions from ARB_shader_ballot.360intrinsic("ballot", src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE])361intrinsic("read_invocation", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])362intrinsic("read_first_invocation", src_comp=[0], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])363364# Returns the value of the first source for the lane where the second source is365# true. The second source must be true for exactly one lane.366intrinsic("read_invocation_cond_ir3", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])367368# Additional SPIR-V ballot intrinsics369#370# These correspond to the SPIR-V opcodes371#372# OpGroupNonUniformElect373# OpSubgroupFirstInvocationKHR374intrinsic("elect", dest_comp=1, flags=[CAN_ELIMINATE])375intrinsic("first_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])376intrinsic("last_invocation", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])377378# Memory barrier with semantics analogous to the compute shader379# groupMemoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(),380# memoryBarrierImage() and memoryBarrierShared() GLSL intrinsics.381barrier("group_memory_barrier")382barrier("memory_barrier_atomic_counter")383barrier("memory_barrier_buffer")384barrier("memory_barrier_image")385barrier("memory_barrier_shared")386barrier("begin_invocation_interlock")387barrier("end_invocation_interlock")388389# Memory barrier for synchronizing TCS patch outputs390barrier("memory_barrier_tcs_patch")391392# A conditional discard/demote/terminate, with a single boolean source.393intrinsic("discard_if", src_comp=[1])394intrinsic("demote_if", src_comp=[1])395intrinsic("terminate_if", src_comp=[1])396397# ARB_shader_group_vote intrinsics398intrinsic("vote_any", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])399intrinsic("vote_all", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE])400intrinsic("vote_feq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])401intrinsic("vote_ieq", src_comp=[0], dest_comp=1, flags=[CAN_ELIMINATE])402403# Ballot ALU operations from SPIR-V.404#405# These operations work like their ALU counterparts except that the operate406# on a uvec4 which is treated as a 128bit integer. Also, they are, in407# general, free to ignore any bits which are above the subgroup size.408intrinsic("ballot_bitfield_extract", src_comp=[4, 1], dest_comp=1, flags=[CAN_ELIMINATE])409intrinsic("ballot_bit_count_reduce", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])410intrinsic("ballot_bit_count_inclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])411intrinsic("ballot_bit_count_exclusive", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])412intrinsic("ballot_find_lsb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])413intrinsic("ballot_find_msb", src_comp=[4], dest_comp=1, flags=[CAN_ELIMINATE])414415# Shuffle operations from SPIR-V.416intrinsic("shuffle", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])417intrinsic("shuffle_xor", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])418intrinsic("shuffle_up", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])419intrinsic("shuffle_down", src_comp=[0, 1], dest_comp=0, bit_sizes=src0, flags=[CAN_ELIMINATE])420421# Quad operations from SPIR-V.422intrinsic("quad_broadcast", src_comp=[0, 1], dest_comp=0, flags=[CAN_ELIMINATE])423intrinsic("quad_swap_horizontal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])424intrinsic("quad_swap_vertical", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])425intrinsic("quad_swap_diagonal", src_comp=[0], dest_comp=0, flags=[CAN_ELIMINATE])426427intrinsic("reduce", src_comp=[0], dest_comp=0, bit_sizes=src0,428indices=[REDUCTION_OP, CLUSTER_SIZE], flags=[CAN_ELIMINATE])429intrinsic("inclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,430indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])431intrinsic("exclusive_scan", src_comp=[0], dest_comp=0, bit_sizes=src0,432indices=[REDUCTION_OP], flags=[CAN_ELIMINATE])433434# AMD shader ballot operations435intrinsic("quad_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,436indices=[SWIZZLE_MASK], flags=[CAN_ELIMINATE])437intrinsic("masked_swizzle_amd", src_comp=[0], dest_comp=0, bit_sizes=src0,438indices=[SWIZZLE_MASK], flags=[CAN_ELIMINATE])439intrinsic("write_invocation_amd", src_comp=[0, 0, 1], dest_comp=0, bit_sizes=src0,440flags=[CAN_ELIMINATE])441# src = [ mask, addition ]442intrinsic("mbcnt_amd", src_comp=[1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])443# Compiled to v_perm_b32. src = [ in_bytes_hi, in_bytes_lo, selector ]444intrinsic("byte_permute_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])445# Compiled to v_permlane16_b32. src = [ value, lanesel_lo, lanesel_hi ]446intrinsic("lane_permute_16_amd", src_comp=[1, 1, 1], dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE])447448# Basic Geometry Shader intrinsics.449#450# emit_vertex implements GLSL's EmitStreamVertex() built-in. It takes a single451# index, which is the stream ID to write to.452#453# end_primitive implements GLSL's EndPrimitive() built-in.454intrinsic("emit_vertex", indices=[STREAM_ID])455intrinsic("end_primitive", indices=[STREAM_ID])456457# Geometry Shader intrinsics with a vertex count.458#459# Alternatively, drivers may implement these intrinsics, and use460# nir_lower_gs_intrinsics() to convert from the basic intrinsics.461#462# These contain two additional unsigned integer sources:463# 1. The total number of vertices emitted so far.464# 2. The number of vertices emitted for the current primitive465# so far if we're counting, otherwise undef.466intrinsic("emit_vertex_with_counter", src_comp=[1, 1], indices=[STREAM_ID])467intrinsic("end_primitive_with_counter", src_comp=[1, 1], indices=[STREAM_ID])468# Contains the final total vertex and primitive counts in the current GS thread.469intrinsic("set_vertex_and_primitive_count", src_comp=[1, 1], indices=[STREAM_ID])470471# Trace a ray through an acceleration structure472#473# This instruction has a lot of parameters:474# 0. Acceleration Structure475# 1. Ray Flags476# 2. Cull Mask477# 3. SBT Offset478# 4. SBT Stride479# 5. Miss shader index480# 6. Ray Origin481# 7. Ray Tmin482# 8. Ray Direction483# 9. Ray Tmax484# 10. Payload485intrinsic("trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1])486# src[] = { hit_t, hit_kind }487intrinsic("report_ray_intersection", src_comp=[1, 1], dest_comp=1)488intrinsic("ignore_ray_intersection")489intrinsic("accept_ray_intersection") # Not in SPIR-V; useful for lowering490intrinsic("terminate_ray")491# src[] = { sbt_index, payload }492intrinsic("execute_callable", src_comp=[1, -1])493494# Driver independent raytracing helpers495496# rt_resume is a helper that that be the first instruction accesing the497# stack/scratch in a resume shader for a raytracing pipeline. It includes the498# resume index (for nir_lower_shader_calls_internal reasons) and the stack size499# of the variables spilled during the call. The stack size can be use to e.g.500# adjust a stack pointer.501intrinsic("rt_resume", indices=[CALL_IDX, STACK_SIZE])502503# Lowered version of execute_callabe that includes the index of the resume504# shader, and the amount of scratch space needed for this call (.ie. how much505# to increase a stack pointer by).506# src[] = { sbt_index, payload }507intrinsic("rt_execute_callable", src_comp=[1, -1], indices=[CALL_IDX,STACK_SIZE])508509# Lowered version of trace_ray in a similar vein to rt_execute_callable.510# src same as trace_ray511intrinsic("rt_trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1],512indices=[CALL_IDX, STACK_SIZE])513514515# Atomic counters516#517# The *_var variants take an atomic_uint nir_variable, while the other,518# lowered, variants take a constant buffer index and register offset.519520def atomic(name, flags=[]):521intrinsic(name + "_deref", src_comp=[-1], dest_comp=1, flags=flags)522intrinsic(name, src_comp=[1], dest_comp=1, indices=[BASE], flags=flags)523524def atomic2(name):525intrinsic(name + "_deref", src_comp=[-1, 1], dest_comp=1)526intrinsic(name, src_comp=[1, 1], dest_comp=1, indices=[BASE])527528def atomic3(name):529intrinsic(name + "_deref", src_comp=[-1, 1, 1], dest_comp=1)530intrinsic(name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])531532atomic("atomic_counter_inc")533atomic("atomic_counter_pre_dec")534atomic("atomic_counter_post_dec")535atomic("atomic_counter_read", flags=[CAN_ELIMINATE])536atomic2("atomic_counter_add")537atomic2("atomic_counter_min")538atomic2("atomic_counter_max")539atomic2("atomic_counter_and")540atomic2("atomic_counter_or")541atomic2("atomic_counter_xor")542atomic2("atomic_counter_exchange")543atomic3("atomic_counter_comp_swap")544545# Image load, store and atomic intrinsics.546#547# All image intrinsics come in three versions. One which take an image target548# passed as a deref chain as the first source, one which takes an index as the549# first source, and one which takes a bindless handle as the first source.550# In the first version, the image variable contains the memory and layout551# qualifiers that influence the semantics of the intrinsic. In the second and552# third, the image format and access qualifiers are provided as constant553# indices.554#555# All image intrinsics take a four-coordinate vector and a sample index as556# 2nd and 3rd sources, determining the location within the image that will be557# accessed by the intrinsic. Components not applicable to the image target558# in use are undefined. Image store takes an additional four-component559# argument with the value to be written, and image atomic operations take560# either one or two additional scalar arguments with the same meaning as in561# the ARB_shader_image_load_store specification.562def image(name, src_comp=[], extra_indices=[], **kwargs):563intrinsic("image_deref_" + name, src_comp=[1] + src_comp,564indices=[ACCESS] + extra_indices, **kwargs)565intrinsic("image_" + name, src_comp=[1] + src_comp,566indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)567intrinsic("bindless_image_" + name, src_comp=[1] + src_comp,568indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)569570image("load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])571image("sparse_load", src_comp=[4, 1, 1], extra_indices=[DEST_TYPE], dest_comp=0, flags=[CAN_ELIMINATE])572image("store", src_comp=[4, 1, 0, 1], extra_indices=[SRC_TYPE])573image("atomic_add", src_comp=[4, 1, 1], dest_comp=1)574image("atomic_imin", src_comp=[4, 1, 1], dest_comp=1)575image("atomic_umin", src_comp=[4, 1, 1], dest_comp=1)576image("atomic_imax", src_comp=[4, 1, 1], dest_comp=1)577image("atomic_umax", src_comp=[4, 1, 1], dest_comp=1)578image("atomic_and", src_comp=[4, 1, 1], dest_comp=1)579image("atomic_or", src_comp=[4, 1, 1], dest_comp=1)580image("atomic_xor", src_comp=[4, 1, 1], dest_comp=1)581image("atomic_exchange", src_comp=[4, 1, 1], dest_comp=1)582image("atomic_comp_swap", src_comp=[4, 1, 1, 1], dest_comp=1)583image("atomic_fadd", src_comp=[4, 1, 1], dest_comp=1)584image("atomic_fmin", src_comp=[4, 1, 1], dest_comp=1)585image("atomic_fmax", src_comp=[4, 1, 1], dest_comp=1)586image("size", dest_comp=0, src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])587image("samples", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])588image("atomic_inc_wrap", src_comp=[4, 1, 1], dest_comp=1)589image("atomic_dec_wrap", src_comp=[4, 1, 1], dest_comp=1)590# CL-specific format queries591image("format", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])592image("order", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])593594# Vulkan descriptor set intrinsics595#596# The Vulkan API uses a different binding model from GL. In the Vulkan597# API, all external resources are represented by a tuple:598#599# (descriptor set, binding, array index)600#601# where the array index is the only thing allowed to be indirect. The602# vulkan_surface_index intrinsic takes the descriptor set and binding as603# its first two indices and the array index as its source. The third604# index is a nir_variable_mode in case that's useful to the backend.605#606# The intended usage is that the shader will call vulkan_surface_index to607# get an index and then pass that as the buffer index ubo/ssbo calls.608#609# The vulkan_resource_reindex intrinsic takes a resource index in src0610# (the result of a vulkan_resource_index or vulkan_resource_reindex) which611# corresponds to the tuple (set, binding, index) and computes an index612# corresponding to tuple (set, binding, idx + src1).613intrinsic("vulkan_resource_index", src_comp=[1], dest_comp=0,614indices=[DESC_SET, BINDING, DESC_TYPE],615flags=[CAN_ELIMINATE, CAN_REORDER])616intrinsic("vulkan_resource_reindex", src_comp=[0, 1], dest_comp=0,617indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])618intrinsic("load_vulkan_descriptor", src_comp=[-1], dest_comp=0,619indices=[DESC_TYPE], flags=[CAN_ELIMINATE, CAN_REORDER])620621# atomic intrinsics622#623# All of these atomic memory operations read a value from memory, compute a new624# value using one of the operations below, write the new value to memory, and625# return the original value read.626#627# All variable operations take 2 sources except CompSwap that takes 3. These628# sources represent:629#630# 0: A deref to the memory on which to perform the atomic631# 1: The data parameter to the atomic function (i.e. the value to add632# in shared_atomic_add, etc).633# 2: For CompSwap only: the second data parameter.634#635# All SSBO operations take 3 sources except CompSwap that takes 4. These636# sources represent:637#638# 0: The SSBO buffer index.639# 1: The offset into the SSBO buffer of the variable that the atomic640# operation will operate on.641# 2: The data parameter to the atomic function (i.e. the value to add642# in ssbo_atomic_add, etc).643# 3: For CompSwap only: the second data parameter.644#645# All shared variable operations take 2 sources except CompSwap that takes 3.646# These sources represent:647#648# 0: The offset into the shared variable storage region that the atomic649# operation will operate on.650# 1: The data parameter to the atomic function (i.e. the value to add651# in shared_atomic_add, etc).652# 2: For CompSwap only: the second data parameter.653#654# All global operations take 2 sources except CompSwap that takes 3. These655# sources represent:656#657# 0: The memory address that the atomic operation will operate on.658# 1: The data parameter to the atomic function (i.e. the value to add659# in shared_atomic_add, etc).660# 2: For CompSwap only: the second data parameter.661662def memory_atomic_data1(name):663intrinsic("deref_atomic_" + name, src_comp=[-1, 1], dest_comp=1, indices=[ACCESS])664intrinsic("ssbo_atomic_" + name, src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS])665intrinsic("shared_atomic_" + name, src_comp=[1, 1], dest_comp=1, indices=[BASE])666intrinsic("global_atomic_" + name, src_comp=[1, 1], dest_comp=1, indices=[BASE])667668def memory_atomic_data2(name):669intrinsic("deref_atomic_" + name, src_comp=[-1, 1, 1], dest_comp=1, indices=[ACCESS])670intrinsic("ssbo_atomic_" + name, src_comp=[-1, 1, 1, 1], dest_comp=1, indices=[ACCESS])671intrinsic("shared_atomic_" + name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])672intrinsic("global_atomic_" + name, src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])673674memory_atomic_data1("add")675memory_atomic_data1("imin")676memory_atomic_data1("umin")677memory_atomic_data1("imax")678memory_atomic_data1("umax")679memory_atomic_data1("and")680memory_atomic_data1("or")681memory_atomic_data1("xor")682memory_atomic_data1("exchange")683memory_atomic_data1("fadd")684memory_atomic_data1("fmin")685memory_atomic_data1("fmax")686memory_atomic_data2("comp_swap")687memory_atomic_data2("fcomp_swap")688689def system_value(name, dest_comp, indices=[], bit_sizes=[32]):690intrinsic("load_" + name, [], dest_comp, indices,691flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True,692bit_sizes=bit_sizes)693694system_value("frag_coord", 4)695system_value("point_coord", 2)696system_value("line_coord", 1)697system_value("front_face", 1, bit_sizes=[1, 32])698system_value("vertex_id", 1)699system_value("vertex_id_zero_base", 1)700system_value("first_vertex", 1)701system_value("is_indexed_draw", 1)702system_value("base_vertex", 1)703system_value("instance_id", 1)704system_value("base_instance", 1)705system_value("draw_id", 1)706system_value("sample_id", 1)707# sample_id_no_per_sample is like sample_id but does not imply per-708# sample shading. See the lower_helper_invocation option.709system_value("sample_id_no_per_sample", 1)710system_value("sample_pos", 2)711system_value("sample_mask_in", 1)712system_value("primitive_id", 1)713system_value("invocation_id", 1)714system_value("tess_coord", 3)715system_value("tess_level_outer", 4)716system_value("tess_level_inner", 2)717system_value("tess_level_outer_default", 4)718system_value("tess_level_inner_default", 2)719system_value("patch_vertices_in", 1)720system_value("local_invocation_id", 3)721system_value("local_invocation_index", 1)722# zero_base indicates it starts from 0 for the current dispatch723# non-zero_base indicates the base is included724system_value("workgroup_id", 3, bit_sizes=[32, 64])725system_value("workgroup_id_zero_base", 3)726system_value("base_workgroup_id", 3, bit_sizes=[32, 64])727system_value("user_clip_plane", 4, indices=[UCP_ID])728system_value("num_workgroups", 3, bit_sizes=[32, 64])729system_value("helper_invocation", 1, bit_sizes=[1, 32])730system_value("layer_id", 1)731system_value("view_index", 1)732system_value("subgroup_size", 1)733system_value("subgroup_invocation", 1)734system_value("subgroup_eq_mask", 0, bit_sizes=[32, 64])735system_value("subgroup_ge_mask", 0, bit_sizes=[32, 64])736system_value("subgroup_gt_mask", 0, bit_sizes=[32, 64])737system_value("subgroup_le_mask", 0, bit_sizes=[32, 64])738system_value("subgroup_lt_mask", 0, bit_sizes=[32, 64])739system_value("num_subgroups", 1)740system_value("subgroup_id", 1)741system_value("workgroup_size", 3)742# note: the definition of global_invocation_id_zero_base is based on743# (workgroup_id * workgroup_size) + local_invocation_id.744# it is *not* based on workgroup_id_zero_base, meaning the work group745# base is already accounted for, and the global base is additive on top of that746system_value("global_invocation_id", 3, bit_sizes=[32, 64])747system_value("global_invocation_id_zero_base", 3, bit_sizes=[32, 64])748system_value("base_global_invocation_id", 3, bit_sizes=[32, 64])749system_value("global_invocation_index", 1, bit_sizes=[32, 64])750system_value("work_dim", 1)751system_value("line_width", 1)752system_value("aa_line_width", 1)753# BASE=0 for global/shader, BASE=1 for local/function754system_value("scratch_base_ptr", 0, bit_sizes=[32,64], indices=[BASE])755system_value("constant_base_ptr", 0, bit_sizes=[32,64])756system_value("shared_base_ptr", 0, bit_sizes=[32,64])757758# System values for ray tracing.759system_value("ray_launch_id", 3)760system_value("ray_launch_size", 3)761system_value("ray_world_origin", 3)762system_value("ray_world_direction", 3)763system_value("ray_object_origin", 3)764system_value("ray_object_direction", 3)765system_value("ray_t_min", 1)766system_value("ray_t_max", 1)767system_value("ray_object_to_world", 3, indices=[COLUMN])768system_value("ray_world_to_object", 3, indices=[COLUMN])769system_value("ray_hit_kind", 1)770system_value("ray_flags", 1)771system_value("ray_geometry_index", 1)772system_value("ray_instance_custom_index", 1)773system_value("shader_record_ptr", 1, bit_sizes=[64])774775# Driver-specific viewport scale/offset parameters.776#777# VC4 and V3D need to emit a scaled version of the position in the vertex778# shaders for binning, and having system values lets us move the math for that779# into NIR.780#781# Panfrost needs to implement all coordinate transformation in the782# vertex shader; system values allow us to share this routine in NIR.783#784# RADV uses these for NGG primitive culling.785system_value("viewport_x_scale", 1)786system_value("viewport_y_scale", 1)787system_value("viewport_z_scale", 1)788system_value("viewport_x_offset", 1)789system_value("viewport_y_offset", 1)790system_value("viewport_z_offset", 1)791system_value("viewport_scale", 3)792system_value("viewport_offset", 3)793794# Blend constant color values. Float values are clamped. Vectored versions are795# provided as well for driver convenience796797system_value("blend_const_color_r_float", 1)798system_value("blend_const_color_g_float", 1)799system_value("blend_const_color_b_float", 1)800system_value("blend_const_color_a_float", 1)801system_value("blend_const_color_rgba", 4)802system_value("blend_const_color_rgba8888_unorm", 1)803system_value("blend_const_color_aaaa8888_unorm", 1)804805# System values for gl_Color, for radeonsi which interpolates these in the806# shader prolog to handle two-sided color without recompiles and therefore807# doesn't handle these in the main shader part like normal varyings.808system_value("color0", 4)809system_value("color1", 4)810811# System value for internal compute shaders in radeonsi.812system_value("user_data_amd", 4)813814# Barycentric coordinate intrinsics.815#816# These set up the barycentric coordinates for a particular interpolation.817# The first four are for the simple cases: pixel, centroid, per-sample818# (at gl_SampleID), or pull model (1/W, 1/I, 1/J) at the pixel center. The next819# two handle interpolating at a specified sample location, or interpolating820# with a vec2 offset,821#822# The interp_mode index should be either the INTERP_MODE_SMOOTH or823# INTERP_MODE_NOPERSPECTIVE enum values.824#825# The vec2 value produced by these intrinsics is intended for use as the826# barycoord source of a load_interpolated_input intrinsic.827828def barycentric(name, dst_comp, src_comp=[]):829intrinsic("load_barycentric_" + name, src_comp=src_comp, dest_comp=dst_comp,830indices=[INTERP_MODE], flags=[CAN_ELIMINATE, CAN_REORDER])831832# no sources.833barycentric("pixel", 2)834barycentric("centroid", 2)835barycentric("sample", 2)836barycentric("model", 3)837# src[] = { sample_id }.838barycentric("at_sample", 2, [1])839# src[] = { offset.xy }.840barycentric("at_offset", 2, [2])841842# Load sample position:843#844# Takes a sample # and returns a sample position. Used for lowering845# interpolateAtSample() to interpolateAtOffset()846intrinsic("load_sample_pos_from_id", src_comp=[1], dest_comp=2,847flags=[CAN_ELIMINATE, CAN_REORDER])848849# Loads what I believe is the primitive size, for scaling ij to pixel size:850intrinsic("load_size_ir3", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])851852# Load texture scaling values:853#854# Takes a sampler # and returns 1/size values for multiplying to normalize855# texture coordinates. Used for lowering rect textures.856intrinsic("load_texture_rect_scaling", src_comp=[1], dest_comp=2,857flags=[CAN_ELIMINATE, CAN_REORDER])858859# Fragment shader input interpolation delta intrinsic.860#861# For hw where fragment shader input interpolation is handled in shader, the862# load_fs_input_interp deltas intrinsics can be used to load the input deltas863# used for interpolation as follows:864#865# vec3 iid = load_fs_input_interp_deltas(varying_slot)866# vec2 bary = load_barycentric_*(...)867# float result = iid.x + iid.y * bary.y + iid.z * bary.x868869intrinsic("load_fs_input_interp_deltas", src_comp=[1], dest_comp=3,870indices=[BASE, COMPONENT, IO_SEMANTICS], flags=[CAN_ELIMINATE, CAN_REORDER])871872# Load operations pull data from some piece of GPU memory. All load873# operations operate in terms of offsets into some piece of theoretical874# memory. Loads from externally visible memory (UBO and SSBO) simply take a875# byte offset as a source. Loads from opaque memory (uniforms, inputs, etc.)876# take a base+offset pair where the nir_intrinsic_base() gives the location877# of the start of the variable being loaded and and the offset source is a878# offset into that variable.879#880# Uniform load operations have a nir_intrinsic_range() index that specifies the881# range (starting at base) of the data from which we are loading. If882# range == 0, then the range is unknown.883#884# UBO load operations have a nir_intrinsic_range_base() and885# nir_intrinsic_range() that specify the byte range [range_base,886# range_base+range] of the UBO that the src offset access must lie within.887#888# Some load operations such as UBO/SSBO load and per_vertex loads take an889# additional source to specify which UBO/SSBO/vertex to load from.890#891# The exact address type depends on the lowering pass that generates the892# load/store intrinsics. Typically, this is vec4 units for things such as893# varying slots and float units for fragment shader inputs. UBO and SSBO894# offsets are always in bytes.895896def load(name, src_comp, indices=[], flags=[]):897intrinsic("load_" + name, src_comp, dest_comp=0, indices=indices,898flags=flags)899900# src[] = { offset }.901load("uniform", [1], [BASE, RANGE, DEST_TYPE], [CAN_ELIMINATE, CAN_REORDER])902# src[] = { buffer_index, offset }.903load("ubo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET, RANGE_BASE, RANGE], flags=[CAN_ELIMINATE, CAN_REORDER])904# src[] = { buffer_index, offset in vec4 units }905load("ubo_vec4", [-1, 1], [ACCESS, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER])906# src[] = { offset }.907load("input", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])908# src[] = { vertex_id, offset }.909load("input_vertex", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])910# src[] = { vertex, offset }.911load("per_vertex_input", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])912# src[] = { barycoord, offset }.913load("interpolated_input", [2, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE, CAN_REORDER])914915# src[] = { buffer_index, offset }.916load("ssbo", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])917# src[] = { buffer_index }918load("ssbo_address", [1], [], [CAN_ELIMINATE, CAN_REORDER])919# src[] = { offset }.920load("output", [1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], flags=[CAN_ELIMINATE])921# src[] = { vertex, offset }.922load("per_vertex_output", [1, 1], [BASE, COMPONENT, DEST_TYPE, IO_SEMANTICS], [CAN_ELIMINATE])923# src[] = { offset }.924load("shared", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])925# src[] = { offset }.926load("push_constant", [1], [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])927# src[] = { offset }.928load("constant", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET],929[CAN_ELIMINATE, CAN_REORDER])930# src[] = { address }.931load("global", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])932# src[] = { address }.933load("global_constant", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],934[CAN_ELIMINATE, CAN_REORDER])935# src[] = { base_address, offset }.936load("global_constant_offset", [1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],937[CAN_ELIMINATE, CAN_REORDER])938# src[] = { base_address, offset, bound }.939load("global_constant_bounded", [1, 1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET],940[CAN_ELIMINATE, CAN_REORDER])941# src[] = { address }.942load("kernel_input", [1], [BASE, RANGE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE, CAN_REORDER])943# src[] = { offset }.944load("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])945946# Stores work the same way as loads, except now the first source is the value947# to store and the second (and possibly third) source specify where to store948# the value. SSBO and shared memory stores also have a949# nir_intrinsic_write_mask()950951def store(name, srcs, indices=[], flags=[]):952intrinsic("store_" + name, [0] + srcs, indices=indices, flags=flags)953954# src[] = { value, offset }.955store("output", [1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])956# src[] = { value, vertex, offset }.957store("per_vertex_output", [1, 1], [BASE, WRITE_MASK, COMPONENT, SRC_TYPE, IO_SEMANTICS])958# src[] = { value, block_index, offset }959store("ssbo", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])960# src[] = { value, offset }.961store("shared", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])962# src[] = { value, address }.963store("global", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])964# src[] = { value, offset }.965store("scratch", [1], [ALIGN_MUL, ALIGN_OFFSET, WRITE_MASK])966967# A bit field to implement SPIRV FragmentShadingRateKHR968# bit | name | description969# 0 | Vertical2Pixels | Fragment invocation covers 2 pixels vertically970# 1 | Vertical4Pixels | Fragment invocation covers 4 pixels vertically971# 2 | Horizontal2Pixels | Fragment invocation covers 2 pixels horizontally972# 3 | Horizontal4Pixels | Fragment invocation covers 4 pixels horizontally973intrinsic("load_frag_shading_rate", dest_comp=1, bit_sizes=[32],974flags=[CAN_ELIMINATE, CAN_REORDER])975976# OpenCL printf instruction977# First source is a deref to the format string978# Second source is a deref to a struct containing the args979# Dest is success or failure980intrinsic("printf", src_comp=[1, 1], dest_comp=1, bit_sizes=[32])981# Since most drivers will want to lower to just dumping args982# in a buffer, nir_lower_printf will do that, but requires983# the driver to at least provide a base location984system_value("printf_buffer_address", 1, bit_sizes=[32,64])985986# IR3-specific version of most SSBO intrinsics. The only different987# compare to the originals is that they add an extra source to hold988# the dword-offset, which is needed by the backend code apart from989# the byte-offset already provided by NIR in one of the sources.990#991# NIR lowering pass 'ir3_nir_lower_io_offset' will replace the992# original SSBO intrinsics by these, placing the computed993# dword-offset always in the last source.994#995# The float versions are not handled because those are not supported996# by the backend.997store("ssbo_ir3", [1, 1, 1],998indices=[WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])999load("ssbo_ir3", [1, 1, 1],1000indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])1001intrinsic("ssbo_atomic_add_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1002intrinsic("ssbo_atomic_imin_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1003intrinsic("ssbo_atomic_umin_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1004intrinsic("ssbo_atomic_imax_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1005intrinsic("ssbo_atomic_umax_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1006intrinsic("ssbo_atomic_and_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1007intrinsic("ssbo_atomic_or_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1008intrinsic("ssbo_atomic_xor_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1009intrinsic("ssbo_atomic_exchange_ir3", src_comp=[1, 1, 1, 1], dest_comp=1, indices=[ACCESS])1010intrinsic("ssbo_atomic_comp_swap_ir3", src_comp=[1, 1, 1, 1, 1], dest_comp=1, indices=[ACCESS])10111012# System values for freedreno geometry shaders.1013system_value("vs_primitive_stride_ir3", 1)1014system_value("vs_vertex_stride_ir3", 1)1015system_value("gs_header_ir3", 1)1016system_value("primitive_location_ir3", 1, indices=[DRIVER_LOCATION])10171018# System values for freedreno tessellation shaders.1019system_value("hs_patch_stride_ir3", 1)1020system_value("tess_factor_base_ir3", 2)1021system_value("tess_param_base_ir3", 2)1022system_value("tcs_header_ir3", 1)10231024# System values for freedreno compute shaders.1025system_value("subgroup_id_shift_ir3", 1)10261027# IR3-specific intrinsics for tessellation control shaders. cond_end_ir3 end1028# the shader when src0 is false and is used to narrow down the TCS shader to1029# just thread 0 before writing out tessellation levels.1030intrinsic("cond_end_ir3", src_comp=[1])1031# end_patch_ir3 is used just before thread 0 exist the TCS and presumably1032# signals the TE that the patch is complete and can be tessellated.1033intrinsic("end_patch_ir3")10341035# IR3-specific load/store intrinsics. These access a buffer used to pass data1036# between geometry stages - perhaps it's explicit access to the vertex cache.10371038# src[] = { value, offset }.1039store("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET])1040# src[] = { offset }.1041load("shared_ir3", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])10421043# IR3-specific load/store global intrinsics. They take a 64-bit base address1044# and a 32-bit offset. The hardware will add the base and the offset, which1045# saves us from doing 64-bit math on the base address.10461047# src[] = { value, address(vec2 of hi+lo uint32_t), offset }.1048# const_index[] = { write_mask, align_mul, align_offset }1049store("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET])1050# src[] = { address(vec2 of hi+lo uint32_t), offset }.1051# const_index[] = { access, align_mul, align_offset }1052load("global_ir3", [2, 1], indices=[ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE])10531054# IR3-specific bindless handle specifier. Similar to vulkan_resource_index, but1055# without the binding because the hardware expects a single flattened index1056# rather than a (binding, index) pair. We may also want to use this with GL.1057# Note that this doesn't actually turn into a HW instruction.1058intrinsic("bindless_resource_ir3", [1], dest_comp=1, indices=[DESC_SET], flags=[CAN_ELIMINATE, CAN_REORDER])10591060# DXIL specific intrinsics1061# src[] = { value, mask, index, offset }.1062intrinsic("store_ssbo_masked_dxil", [1, 1, 1, 1])1063# src[] = { value, index }.1064intrinsic("store_shared_dxil", [1, 1])1065# src[] = { value, mask, index }.1066intrinsic("store_shared_masked_dxil", [1, 1, 1])1067# src[] = { value, index }.1068intrinsic("store_scratch_dxil", [1, 1])1069# src[] = { index }.1070load("shared_dxil", [1], [], [CAN_ELIMINATE])1071# src[] = { index }.1072load("scratch_dxil", [1], [], [CAN_ELIMINATE])1073# src[] = { deref_var, offset }1074load("ptr_dxil", [1, 1], [], [])1075# src[] = { index, 16-byte-based-offset }1076load("ubo_dxil", [1, 1], [], [CAN_ELIMINATE])10771078# DXIL Shared atomic intrinsics1079#1080# All of the shared variable atomic memory operations read a value from1081# memory, compute a new value using one of the operations below, write the1082# new value to memory, and return the original value read.1083#1084# All operations take 2 sources:1085#1086# 0: The index in the i32 array for by the shared memory region1087# 1: The data parameter to the atomic function (i.e. the value to add1088# in shared_atomic_add, etc).1089intrinsic("shared_atomic_add_dxil", src_comp=[1, 1], dest_comp=1)1090intrinsic("shared_atomic_imin_dxil", src_comp=[1, 1], dest_comp=1)1091intrinsic("shared_atomic_umin_dxil", src_comp=[1, 1], dest_comp=1)1092intrinsic("shared_atomic_imax_dxil", src_comp=[1, 1], dest_comp=1)1093intrinsic("shared_atomic_umax_dxil", src_comp=[1, 1], dest_comp=1)1094intrinsic("shared_atomic_and_dxil", src_comp=[1, 1], dest_comp=1)1095intrinsic("shared_atomic_or_dxil", src_comp=[1, 1], dest_comp=1)1096intrinsic("shared_atomic_xor_dxil", src_comp=[1, 1], dest_comp=1)1097intrinsic("shared_atomic_exchange_dxil", src_comp=[1, 1], dest_comp=1)1098intrinsic("shared_atomic_comp_swap_dxil", src_comp=[1, 1, 1], dest_comp=1)10991100# Intrinsics used by the Midgard/Bifrost blend pipeline. These are defined1101# within a blend shader to read/write the raw value from the tile buffer,1102# without applying any format conversion in the process. If the shader needs1103# usable pixel values, it must apply format conversions itself.1104#1105# These definitions are generic, but they are explicitly vendored to prevent1106# other drivers from using them, as their semantics is defined in terms of the1107# Midgard/Bifrost hardware tile buffer and may not line up with anything sane.1108# One notable divergence is sRGB, which is asymmetric: raw_input_pan requires1109# an sRGB->linear conversion, but linear values should be written to1110# raw_output_pan and the hardware handles linear->sRGB.11111112# src[] = { value }1113store("raw_output_pan", [], [])1114store("combined_output_pan", [1, 1, 1], [BASE, COMPONENT, SRC_TYPE])1115load("raw_output_pan", [1], [BASE], [CAN_ELIMINATE, CAN_REORDER])11161117# Loads the sampler paramaters <min_lod, max_lod, lod_bias>1118# src[] = { sampler_index }1119load("sampler_lod_parameters_pan", [1], flags=[CAN_ELIMINATE, CAN_REORDER])11201121# Loads the sample position array on Bifrost, in a packed Arm-specific format1122system_value("sample_positions_pan", 1, bit_sizes=[64])11231124# R600 specific instrincs1125#1126# location where the tesselation data is stored in LDS1127system_value("tcs_in_param_base_r600", 4)1128system_value("tcs_out_param_base_r600", 4)1129system_value("tcs_rel_patch_id_r600", 1)1130system_value("tcs_tess_factor_base_r600", 1)11311132# the tess coords come as xy only, z has to be calculated1133system_value("tess_coord_r600", 2)11341135# load as many components as needed giving per-component addresses1136intrinsic("load_local_shared_r600", src_comp=[0], dest_comp=0, indices = [], flags = [CAN_ELIMINATE])11371138store("local_shared_r600", [1], [WRITE_MASK])1139store("tf_r600", [])11401141# AMD GCN/RDNA specific intrinsics11421143# src[] = { descriptor, base address, scalar offset }1144intrinsic("load_buffer_amd", src_comp=[4, 1, 1], dest_comp=0, indices=[BASE, IS_SWIZZLED, SLC_AMD, MEMORY_MODES], flags=[CAN_ELIMINATE])1145# src[] = { store value, descriptor, base address, scalar offset }1146intrinsic("store_buffer_amd", src_comp=[0, 4, 1, 1], indices=[BASE, WRITE_MASK, IS_SWIZZLED, SLC_AMD, MEMORY_MODES])11471148# Same as shared_atomic_add, but with GDS. src[] = {store_val, gds_addr, m0}1149intrinsic("gds_atomic_add_amd", src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])11501151# Descriptor where TCS outputs are stored for TES1152system_value("ring_tess_offchip_amd", 4)1153system_value("ring_tess_offchip_offset_amd", 1)1154# Descriptor where TCS outputs are stored for the HW tessellator1155system_value("ring_tess_factors_amd", 4)1156system_value("ring_tess_factors_offset_amd", 1)1157# Descriptor where ES outputs are stored for GS to read on GFX6-81158system_value("ring_esgs_amd", 4)1159system_value("ring_es2gs_offset_amd", 1)11601161# Number of patches processed by each TCS workgroup1162system_value("tcs_num_patches_amd", 1)1163# Relative tessellation patch ID within the current workgroup1164system_value("tess_rel_patch_id_amd", 1)1165# Vertex offsets used for GS per-vertex inputs1166system_value("gs_vertex_offset_amd", 1, [BASE])11671168# AMD merged shader intrinsics11691170# Whether the current invocation has an input vertex / primitive to process (also known as "ES thread" or "GS thread").1171# Not safe to reorder because it changes after overwrite_subgroup_num_vertices_and_primitives_amd.1172# Also, the generated code is more optimal if they are not CSE'd.1173intrinsic("has_input_vertex_amd", src_comp=[], dest_comp=1, bit_sizes=[1], indices=[])1174intrinsic("has_input_primitive_amd", src_comp=[], dest_comp=1, bit_sizes=[1], indices=[])11751176# AMD NGG intrinsics11771178# Number of initial input vertices in the current workgroup.1179system_value("workgroup_num_input_vertices_amd", 1)1180# Number of initial input primitives in the current workgroup.1181system_value("workgroup_num_input_primitives_amd", 1)1182# For NGG passthrough mode only. Pre-packed argument for export_primitive_amd.1183system_value("packed_passthrough_primitive_amd", 1)1184# Whether NGG GS should execute shader query.1185system_value("shader_query_enabled_amd", dest_comp=1, bit_sizes=[1])1186# Whether the shader should cull front facing triangles.1187intrinsic("load_cull_front_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])1188# Whether the shader should cull back facing triangles.1189intrinsic("load_cull_back_face_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])1190# True if face culling should use CCW (false if CW).1191intrinsic("load_cull_ccw_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])1192# Whether the shader should cull small primitives that are not visible in a pixel.1193intrinsic("load_cull_small_primitives_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])1194# Whether any culling setting is enabled in the shader.1195intrinsic("load_cull_any_enabled_amd", dest_comp=1, bit_sizes=[1], flags=[CAN_ELIMINATE])1196# Small primitive culling precision1197intrinsic("load_cull_small_prim_precision_amd", dest_comp=1, bit_sizes=[32], flags=[CAN_ELIMINATE, CAN_REORDER])1198# Initial edge flag in a Vertex Shader. src = {vertex index}.1199intrinsic("load_initial_edgeflag_amd", src_comp=[1], dest_comp=1, indices=[])1200# Exports the current invocation's vertex. This is a placeholder where all vertex attribute export instructions should be emitted.1201intrinsic("export_vertex_amd", src_comp=[], indices=[])1202# Exports the current invocation's primitive. src[] = {packed_primitive_data}.1203intrinsic("export_primitive_amd", src_comp=[1], indices=[])1204# Allocates export space for vertices and primitives. src[] = {num_vertices, num_primitives}.1205intrinsic("alloc_vertices_and_primitives_amd", src_comp=[1, 1], indices=[])1206# Overwrites VS input registers, for use with vertex compaction after culling. src = {vertex_id, instance_id}.1207intrinsic("overwrite_vs_arguments_amd", src_comp=[1, 1], indices=[])1208# Overwrites TES input registers, for use with vertex compaction after culling. src = {tes_u, tes_v, rel_patch_id, patch_id}.1209intrinsic("overwrite_tes_arguments_amd", src_comp=[1, 1, 1, 1], indices=[])1210# Overwrites the input vertex and primitive count in the current subgroup after culling. src = {num_vertices, num_primitives}.1211intrinsic("overwrite_subgroup_num_vertices_and_primitives_amd", src_comp=[1, 1], indices=[])12121213# src = [index] BINDING = which table BASE = offset within handle1214intrinsic("load_sbt_amd", src_comp=[-1], dest_comp=0, indices=[BINDING, BASE],1215flags=[CAN_ELIMINATE, CAN_REORDER])12161217# 1. HW descriptor1218# 2. BVH node(64-bit pointer as 2x32 ...)1219# 3. ray extent1220# 4. ray origin1221# 5. ray direction1222# 6. inverse ray direction (componentwise 1.0/ray direction)1223intrinsic("bvh64_intersect_ray_amd", [4, 2, 1, 3, 3, 3], 4, flags=[CAN_ELIMINATE, CAN_REORDER])12241225# V3D-specific instrinc for tile buffer color reads.1226#1227# The hardware requires that we read the samples and components of a pixel1228# in order, so we cannot eliminate or remove any loads in a sequence.1229#1230# src[] = { render_target }1231# BASE = sample index1232load("tlb_color_v3d", [1], [BASE, COMPONENT], [])12331234# V3D-specific instrinc for per-sample tile buffer color writes.1235#1236# The driver backend needs to identify per-sample color writes and emit1237# specific code for them.1238#1239# src[] = { value, render_target }1240# BASE = sample index1241store("tlb_sample_color_v3d", [1], [BASE, COMPONENT, SRC_TYPE], [])12421243# V3D-specific intrinsic to load the number of layers attached to1244# the target framebuffer1245intrinsic("load_fb_layers_v3d", dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])12461247# Logical complement of load_front_face, mapping to an AGX system value1248system_value("back_face_agx", 1, bit_sizes=[1, 32])12491250# Intel-specific query for loading from the brw_image_param struct passed1251# into the shader as a uniform. The variable is a deref to the image1252# variable. The const index specifies which of the six parameters to load.1253intrinsic("image_deref_load_param_intel", src_comp=[1], dest_comp=0,1254indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])1255image("load_raw_intel", src_comp=[1], dest_comp=0,1256flags=[CAN_ELIMINATE])1257image("store_raw_intel", src_comp=[1, 0])12581259# Intrinsic to load a block of at least 32B of constant data from a 64-bit1260# global memory address. The memory address must be uniform and 32B-aligned.1261# The second source is a predicate which indicates whether or not to actually1262# do the load.1263# src[] = { address, predicate }.1264intrinsic("load_global_const_block_intel", src_comp=[1, 1], dest_comp=0,1265bit_sizes=[32], indices=[BASE], flags=[CAN_ELIMINATE, CAN_REORDER])12661267# Number of data items being operated on for a SIMD program.1268system_value("simd_width_intel", 1)12691270# Load a relocatable 32-bit value1271intrinsic("load_reloc_const_intel", dest_comp=1, bit_sizes=[32],1272indices=[PARAM_IDX], flags=[CAN_ELIMINATE, CAN_REORDER])12731274# 64-bit global address for a Vulkan descriptor set1275# src[0] = { set }1276intrinsic("load_desc_set_address_intel", dest_comp=1, bit_sizes=[64],1277src_comp=[1], flags=[CAN_ELIMINATE, CAN_REORDER])12781279# OpSubgroupBlockReadINTEL and OpSubgroupBlockWriteINTEL from SPV_INTEL_subgroups.1280intrinsic("load_deref_block_intel", dest_comp=0, src_comp=[-1],1281indices=[ACCESS], flags=[CAN_ELIMINATE])1282intrinsic("store_deref_block_intel", src_comp=[-1, 0], indices=[WRITE_MASK, ACCESS])12831284# src[] = { address }.1285load("global_block_intel", [1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])12861287# src[] = { buffer_index, offset }.1288load("ssbo_block_intel", [-1, 1], [ACCESS, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])12891290# src[] = { offset }.1291load("shared_block_intel", [1], [BASE, ALIGN_MUL, ALIGN_OFFSET], [CAN_ELIMINATE])12921293# src[] = { value, address }.1294store("global_block_intel", [1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])12951296# src[] = { value, block_index, offset }1297store("ssbo_block_intel", [-1, 1], [WRITE_MASK, ACCESS, ALIGN_MUL, ALIGN_OFFSET])12981299# src[] = { value, offset }.1300store("shared_block_intel", [1], [BASE, WRITE_MASK, ALIGN_MUL, ALIGN_OFFSET])13011302# Intrinsics for Intel bindless thread dispatch1303system_value("btd_dss_id_intel", 1)1304system_value("btd_stack_id_intel", 1)1305system_value("btd_global_arg_addr_intel", 1, bit_sizes=[64])1306system_value("btd_local_arg_addr_intel", 1, bit_sizes=[64])1307system_value("btd_resume_sbt_addr_intel", 1, bit_sizes=[64])1308# src[] = { global_arg_addr, btd_record }1309intrinsic("btd_spawn_intel", src_comp=[1, 1])1310# RANGE=stack_size1311intrinsic("btd_stack_push_intel", indices=[STACK_SIZE])1312# src[] = { }1313intrinsic("btd_retire_intel")13141315# Intel-specific ray-tracing intrinsics1316intrinsic("trace_ray_initial_intel")1317intrinsic("trace_ray_commit_intel")1318intrinsic("trace_ray_continue_intel")13191320# System values used for ray-tracing on Intel1321system_value("ray_base_mem_addr_intel", 1, bit_sizes=[64])1322system_value("ray_hw_stack_size_intel", 1)1323system_value("ray_sw_stack_size_intel", 1)1324system_value("ray_num_dss_rt_stacks_intel", 1)1325system_value("ray_hit_sbt_addr_intel", 1, bit_sizes=[64])1326system_value("ray_hit_sbt_stride_intel", 1, bit_sizes=[16])1327system_value("ray_miss_sbt_addr_intel", 1, bit_sizes=[64])1328system_value("ray_miss_sbt_stride_intel", 1, bit_sizes=[16])1329system_value("callable_sbt_addr_intel", 1, bit_sizes=[64])1330system_value("callable_sbt_stride_intel", 1, bit_sizes=[16])1331system_value("leaf_opaque_intel", 1, bit_sizes=[1])1332system_value("leaf_procedural_intel", 1, bit_sizes=[1])133313341335