Path: blob/21.2-virgl/src/broadcom/compiler/v3d_compiler.h
4564 views
/*1* Copyright © 2016 Broadcom2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef V3D_COMPILER_H24#define V3D_COMPILER_H2526#include <assert.h>27#include <stdio.h>28#include <stdlib.h>29#include <stdbool.h>30#include <stdint.h>31#include <string.h>3233#include "util/macros.h"34#include "common/v3d_debug.h"35#include "common/v3d_device_info.h"36#include "common/v3d_limits.h"37#include "compiler/nir/nir.h"38#include "util/list.h"39#include "util/u_math.h"4041#include "qpu/qpu_instr.h"42#include "pipe/p_state.h"4344/**45* Maximum number of outstanding TMU operations we can queue for execution.46*47* This is mostly limited by the size of the TMU fifos. The Input and Config48* fifos can stall, but we prefer that than injecting TMU flushes manually49* in the driver, so we can ignore these, but we can't overflow the Output fifo,50* which has 16 / threads per-thread entries, meaning that the maximum number51* of outstanding LDTMUs we can ever have is 8, for a 2-way threaded shader.52* This means that at most we can have 8 outstanding TMU loads, if each load53* is just one component.54*55* NOTE: we could actually have a larger value here because TMU stores don't56* consume any entries in the Output fifo (so we could have any number of57* outstanding stores) and the driver keeps track of used Output fifo entries58* and will flush if we ever needs more than 8, but since loads are much more59* common than stores, it is probably not worth it.60*/61#define MAX_TMU_QUEUE_SIZE 86263/**64* Maximum offset distance in bytes between two consecutive constant UBO loads65* for the same UBO where we would favor updating the unifa address by emitting66* dummy ldunifa instructions to avoid writing the unifa register.67*/68#define MAX_UNIFA_SKIP_DISTANCE 166970struct nir_builder;7172struct v3d_fs_inputs {73/**74* Array of the meanings of the VPM inputs this shader needs.75*76* It doesn't include those that aren't part of the VPM, like77* point/line coordinates.78*/79struct v3d_varying_slot *input_slots;80uint32_t num_inputs;81};8283enum qfile {84/** An unused source or destination register. */85QFILE_NULL,8687/** A physical register, such as the W coordinate payload. */88QFILE_REG,89/** One of the regsiters for fixed function interactions. */90QFILE_MAGIC,9192/**93* A virtual register, that will be allocated to actual accumulator94* or physical registers later.95*/96QFILE_TEMP,9798/**99* VPM reads use this with an index value to say what part of the VPM100* is being read.101*/102QFILE_VPM,103104/**105* Stores an immediate value in the index field that will be used106* directly by qpu_load_imm().107*/108QFILE_LOAD_IMM,109110/**111* Stores an immediate value in the index field that can be turned112* into a small immediate field by qpu_encode_small_immediate().113*/114QFILE_SMALL_IMM,115};116117/**118* A reference to a QPU register or a virtual temp register.119*/120struct qreg {121enum qfile file;122uint32_t index;123};124125static inline struct qreg vir_reg(enum qfile file, uint32_t index)126{127return (struct qreg){file, index};128}129130static inline struct qreg vir_magic_reg(uint32_t index)131{132return (struct qreg){QFILE_MAGIC, index};133}134135static inline struct qreg vir_nop_reg(void)136{137return (struct qreg){QFILE_NULL, 0};138}139140/**141* A reference to an actual register at the QPU level, for register142* allocation.143*/144struct qpu_reg {145bool magic;146bool smimm;147int index;148};149150struct qinst {151/** Entry in qblock->instructions */152struct list_head link;153154/**155* The instruction being wrapped. Its condition codes, pack flags,156* signals, etc. will all be used, with just the register references157* being replaced by the contents of qinst->dst and qinst->src[].158*/159struct v3d_qpu_instr qpu;160161/* Pre-register-allocation references to src/dst registers */162struct qreg dst;163struct qreg src[3];164bool is_last_thrsw;165166/* If the instruction reads a uniform (other than through src[i].file167* == QFILE_UNIF), that uniform's index in c->uniform_contents. ~0168* otherwise.169*/170int uniform;171};172173enum quniform_contents {174/**175* Indicates that a constant 32-bit value is copied from the program's176* uniform contents.177*/178QUNIFORM_CONSTANT,179/**180* Indicates that the program's uniform contents are used as an index181* into the GL uniform storage.182*/183QUNIFORM_UNIFORM,184185/** @{186* Scaling factors from clip coordinates to relative to the viewport187* center.188*189* This is used by the coordinate and vertex shaders to produce the190* 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed191* point offsets from the viewport ccenter.192*/193QUNIFORM_VIEWPORT_X_SCALE,194QUNIFORM_VIEWPORT_Y_SCALE,195/** @} */196197QUNIFORM_VIEWPORT_Z_OFFSET,198QUNIFORM_VIEWPORT_Z_SCALE,199200QUNIFORM_USER_CLIP_PLANE,201202/**203* A reference to a V3D 3.x texture config parameter 0 uniform.204*205* This is a uniform implicitly loaded with a QPU_W_TMU* write, which206* defines texture type, miplevels, and such. It will be found as a207* parameter to the first QOP_TEX_[STRB] instruction in a sequence.208*/209QUNIFORM_TEXTURE_CONFIG_P0_0,210QUNIFORM_TEXTURE_CONFIG_P0_1,211QUNIFORM_TEXTURE_CONFIG_P0_2,212QUNIFORM_TEXTURE_CONFIG_P0_3,213QUNIFORM_TEXTURE_CONFIG_P0_4,214QUNIFORM_TEXTURE_CONFIG_P0_5,215QUNIFORM_TEXTURE_CONFIG_P0_6,216QUNIFORM_TEXTURE_CONFIG_P0_7,217QUNIFORM_TEXTURE_CONFIG_P0_8,218QUNIFORM_TEXTURE_CONFIG_P0_9,219QUNIFORM_TEXTURE_CONFIG_P0_10,220QUNIFORM_TEXTURE_CONFIG_P0_11,221QUNIFORM_TEXTURE_CONFIG_P0_12,222QUNIFORM_TEXTURE_CONFIG_P0_13,223QUNIFORM_TEXTURE_CONFIG_P0_14,224QUNIFORM_TEXTURE_CONFIG_P0_15,225QUNIFORM_TEXTURE_CONFIG_P0_16,226QUNIFORM_TEXTURE_CONFIG_P0_17,227QUNIFORM_TEXTURE_CONFIG_P0_18,228QUNIFORM_TEXTURE_CONFIG_P0_19,229QUNIFORM_TEXTURE_CONFIG_P0_20,230QUNIFORM_TEXTURE_CONFIG_P0_21,231QUNIFORM_TEXTURE_CONFIG_P0_22,232QUNIFORM_TEXTURE_CONFIG_P0_23,233QUNIFORM_TEXTURE_CONFIG_P0_24,234QUNIFORM_TEXTURE_CONFIG_P0_25,235QUNIFORM_TEXTURE_CONFIG_P0_26,236QUNIFORM_TEXTURE_CONFIG_P0_27,237QUNIFORM_TEXTURE_CONFIG_P0_28,238QUNIFORM_TEXTURE_CONFIG_P0_29,239QUNIFORM_TEXTURE_CONFIG_P0_30,240QUNIFORM_TEXTURE_CONFIG_P0_31,241QUNIFORM_TEXTURE_CONFIG_P0_32,242243/**244* A reference to a V3D 3.x texture config parameter 1 uniform.245*246* This is a uniform implicitly loaded with a QPU_W_TMU* write, which247* has the pointer to the indirect texture state. Our data[] field248* will have a packed p1 value, but the address field will be just249* which texture unit's texture should be referenced.250*/251QUNIFORM_TEXTURE_CONFIG_P1,252253/* A V3D 4.x texture config parameter. The high 8 bits will be254* which texture or sampler is being sampled, and the driver must255* replace the address field with the appropriate address.256*/257QUNIFORM_TMU_CONFIG_P0,258QUNIFORM_TMU_CONFIG_P1,259260QUNIFORM_IMAGE_TMU_CONFIG_P0,261262QUNIFORM_TEXTURE_FIRST_LEVEL,263264QUNIFORM_TEXTURE_WIDTH,265QUNIFORM_TEXTURE_HEIGHT,266QUNIFORM_TEXTURE_DEPTH,267QUNIFORM_TEXTURE_ARRAY_SIZE,268QUNIFORM_TEXTURE_LEVELS,269QUNIFORM_TEXTURE_SAMPLES,270271QUNIFORM_UBO_ADDR,272273QUNIFORM_TEXRECT_SCALE_X,274QUNIFORM_TEXRECT_SCALE_Y,275276/* Returns the base offset of the SSBO given by the data value. */277QUNIFORM_SSBO_OFFSET,278279/* Returns the size of the SSBO or UBO given by the data value. */280QUNIFORM_GET_SSBO_SIZE,281QUNIFORM_GET_UBO_SIZE,282283/* Sizes (in pixels) of a shader image given by the data value. */284QUNIFORM_IMAGE_WIDTH,285QUNIFORM_IMAGE_HEIGHT,286QUNIFORM_IMAGE_DEPTH,287QUNIFORM_IMAGE_ARRAY_SIZE,288289QUNIFORM_LINE_WIDTH,290291/* The line width sent to hardware. This includes the expanded width292* when anti-aliasing is enabled.293*/294QUNIFORM_AA_LINE_WIDTH,295296/* Number of workgroups passed to glDispatchCompute in the dimension297* selected by the data value.298*/299QUNIFORM_NUM_WORK_GROUPS,300301/* Base workgroup offset passed to vkCmdDispatchBase in the dimension302* selected by the data value.303*/304QUNIFORM_WORK_GROUP_BASE,305306/**307* Returns the the offset of the scratch buffer for register spilling.308*/309QUNIFORM_SPILL_OFFSET,310QUNIFORM_SPILL_SIZE_PER_THREAD,311312/**313* Returns the offset of the shared memory for compute shaders.314*315* This will be accessed using TMU general memory operations, so the316* L2T cache will effectively be the shared memory area.317*/318QUNIFORM_SHARED_OFFSET,319320/**321* Returns the number of layers in the framebuffer.322*323* This is used to cap gl_Layer in geometry shaders to avoid324* out-of-bounds accesses into the tile state during binning.325*/326QUNIFORM_FB_LAYERS,327};328329static inline uint32_t v3d_unit_data_create(uint32_t unit, uint32_t value)330{331assert(value < (1 << 24));332return unit << 24 | value;333}334335static inline uint32_t v3d_unit_data_get_unit(uint32_t data)336{337return data >> 24;338}339340static inline uint32_t v3d_unit_data_get_offset(uint32_t data)341{342return data & 0xffffff;343}344345struct v3d_varying_slot {346uint8_t slot_and_component;347};348349static inline struct v3d_varying_slot350v3d_slot_from_slot_and_component(uint8_t slot, uint8_t component)351{352assert(slot < 255 / 4);353return (struct v3d_varying_slot){ (slot << 2) + component };354}355356static inline uint8_t v3d_slot_get_slot(struct v3d_varying_slot slot)357{358return slot.slot_and_component >> 2;359}360361static inline uint8_t v3d_slot_get_component(struct v3d_varying_slot slot)362{363return slot.slot_and_component & 3;364}365366enum v3d_execution_environment {367V3D_ENVIRONMENT_OPENGL = 0,368V3D_ENVIRONMENT_VULKAN,369};370371struct v3d_key {372void *shader_state;373struct {374uint8_t swizzle[4];375} tex[V3D_MAX_TEXTURE_SAMPLERS];376struct {377uint8_t return_size;378uint8_t return_channels;379} sampler[V3D_MAX_TEXTURE_SAMPLERS];380381uint8_t num_tex_used;382uint8_t num_samplers_used;383uint8_t ucp_enables;384bool is_last_geometry_stage;385bool robust_buffer_access;386387enum v3d_execution_environment environment;388};389390struct v3d_fs_key {391struct v3d_key base;392bool is_points;393bool is_lines;394bool line_smoothing;395bool point_coord_upper_left;396bool msaa;397bool sample_coverage;398bool sample_alpha_to_coverage;399bool sample_alpha_to_one;400/* Mask of which color render targets are present. */401uint8_t cbufs;402uint8_t swap_color_rb;403/* Mask of which render targets need to be written as 32-bit floats */404uint8_t f32_color_rb;405/* Masks of which render targets need to be written as ints/uints.406* Used by gallium to work around lost information in TGSI.407*/408uint8_t int_color_rb;409uint8_t uint_color_rb;410411/* Color format information per render target. Only set when logic412* operations are enabled.413*/414struct {415enum pipe_format format;416const uint8_t *swizzle;417} color_fmt[V3D_MAX_DRAW_BUFFERS];418419uint8_t logicop_func;420uint32_t point_sprite_mask;421422struct pipe_rt_blend_state blend;423424/* If the fragment shader reads gl_PrimitiveID then we have 2 scenarios:425*426* - If there is a geometry shader, then gl_PrimitiveID must be written427* by it and the fragment shader loads it as a regular explicit input428* varying. This is the only valid use case in GLES 3.1.429*430* - If there is not a geometry shader (allowed since GLES 3.2 and431* Vulkan 1.0), then gl_PrimitiveID must be implicitly written by432* hardware and is considered an implicit input varying in the433* fragment shader.434*/435bool has_gs;436};437438struct v3d_gs_key {439struct v3d_key base;440441struct v3d_varying_slot used_outputs[V3D_MAX_FS_INPUTS];442uint8_t num_used_outputs;443444bool is_coord;445bool per_vertex_point_size;446};447448struct v3d_vs_key {449struct v3d_key base;450451struct v3d_varying_slot used_outputs[V3D_MAX_ANY_STAGE_INPUTS];452uint8_t num_used_outputs;453454/* A bit-mask indicating if we need to swap the R/B channels for455* vertex attributes. Since the hardware doesn't provide any456* means to swizzle vertex attributes we need to do it in the shader.457*/458uint32_t va_swap_rb_mask;459460bool is_coord;461bool per_vertex_point_size;462bool clamp_color;463};464465/** A basic block of VIR intructions. */466struct qblock {467struct list_head link;468469struct list_head instructions;470471struct set *predecessors;472struct qblock *successors[2];473474int index;475476/* Instruction IPs for the first and last instruction of the block.477* Set by qpu_schedule.c.478*/479uint32_t start_qpu_ip;480uint32_t end_qpu_ip;481482/* Instruction IP for the branch instruction of the block. Set by483* qpu_schedule.c.484*/485uint32_t branch_qpu_ip;486487/** Offset within the uniform stream at the start of the block. */488uint32_t start_uniform;489/** Offset within the uniform stream of the branch instruction */490uint32_t branch_uniform;491492/**493* Has the terminating branch of this block already been emitted494* by a break or continue?495*/496bool branch_emitted;497498/** @{ used by v3d_vir_live_variables.c */499BITSET_WORD *def;500BITSET_WORD *defin;501BITSET_WORD *defout;502BITSET_WORD *use;503BITSET_WORD *live_in;504BITSET_WORD *live_out;505int start_ip, end_ip;506/** @} */507};508509/** Which util/list.h add mode we should use when inserting an instruction. */510enum vir_cursor_mode {511vir_cursor_add,512vir_cursor_addtail,513};514515/**516* Tracking structure for where new instructions should be inserted. Create517* with one of the vir_after_inst()-style helper functions.518*519* This does not protect against removal of the block or instruction, so we520* have an assert in instruction removal to try to catch it.521*/522struct vir_cursor {523enum vir_cursor_mode mode;524struct list_head *link;525};526527static inline struct vir_cursor528vir_before_inst(struct qinst *inst)529{530return (struct vir_cursor){ vir_cursor_addtail, &inst->link };531}532533static inline struct vir_cursor534vir_after_inst(struct qinst *inst)535{536return (struct vir_cursor){ vir_cursor_add, &inst->link };537}538539static inline struct vir_cursor540vir_before_block(struct qblock *block)541{542return (struct vir_cursor){ vir_cursor_add, &block->instructions };543}544545static inline struct vir_cursor546vir_after_block(struct qblock *block)547{548return (struct vir_cursor){ vir_cursor_addtail, &block->instructions };549}550551enum v3d_compilation_result {552V3D_COMPILATION_SUCCEEDED,553V3D_COMPILATION_FAILED_REGISTER_ALLOCATION,554V3D_COMPILATION_FAILED,555};556557/**558* Compiler state saved across compiler invocations, for any expensive global559* setup.560*/561struct v3d_compiler {562const struct v3d_device_info *devinfo;563struct ra_regs *regs;564struct ra_class *reg_class_any[3];565struct ra_class *reg_class_r5[3];566struct ra_class *reg_class_phys[3];567struct ra_class *reg_class_phys_or_acc[3];568};569570/**571* This holds partially interpolated inputs as provided by hardware572* (The Vp = A*(x - x0) + B*(y - y0) term), as well as the C coefficient573* required to compute the final interpolated value.574*/575struct v3d_interp_input {576struct qreg vp;577struct qreg C;578unsigned mode; /* interpolation mode */579};580581struct v3d_compile {582const struct v3d_device_info *devinfo;583nir_shader *s;584nir_function_impl *impl;585struct exec_list *cf_node_list;586const struct v3d_compiler *compiler;587588void (*debug_output)(const char *msg,589void *debug_output_data);590void *debug_output_data;591592/**593* Mapping from nir_register * or nir_ssa_def * to array of struct594* qreg for the values.595*/596struct hash_table *def_ht;597598/* For each temp, the instruction generating its value. */599struct qinst **defs;600uint32_t defs_array_size;601602/* TMU pipelining tracking */603struct {604/* NIR registers that have been updated with a TMU operation605* that has not been flushed yet.606*/607struct set *outstanding_regs;608609uint32_t output_fifo_size;610611struct {612nir_dest *dest;613uint8_t num_components;614uint8_t component_mask;615} flush[MAX_TMU_QUEUE_SIZE];616uint32_t flush_count;617} tmu;618619/**620* Inputs to the shader, arranged by TGSI declaration order.621*622* Not all fragment shader QFILE_VARY reads are present in this array.623*/624struct qreg *inputs;625/**626* Partially interpolated inputs to the shader.627*/628struct v3d_interp_input *interp;629struct qreg *outputs;630bool msaa_per_sample_output;631struct qreg color_reads[V3D_MAX_DRAW_BUFFERS * V3D_MAX_SAMPLES * 4];632struct qreg sample_colors[V3D_MAX_DRAW_BUFFERS * V3D_MAX_SAMPLES * 4];633uint32_t inputs_array_size;634uint32_t outputs_array_size;635uint32_t uniforms_array_size;636637/* Booleans for whether the corresponding QFILE_VARY[i] is638* flat-shaded. This includes gl_FragColor flat-shading, which is639* customized based on the shademodel_flat shader key.640*/641uint32_t flat_shade_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];642643uint32_t noperspective_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];644645uint32_t centroid_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];646647bool uses_center_w;648bool writes_z;649bool uses_implicit_point_line_varyings;650651/* True if a fragment shader reads gl_PrimitiveID */652bool fs_uses_primitive_id;653654/* If the fragment shader does anything that requires to force655* per-sample MSAA, such as reading gl_SampleID.656*/657bool force_per_sample_msaa;658659/* Whether we are using the fallback scheduler. This will be set after660* register allocation has failed once.661*/662bool fallback_scheduler;663664/* Disable TMU pipelining. This may increase the chances of being able665* to compile shaders with high register pressure that require to emit666* TMU spills.667*/668bool disable_tmu_pipelining;669bool pipelined_any_tmu;670671/* Disable sorting of UBO loads with constant offset. This may672* increase the chances of being able to compile shaders with high673* register pressure.674*/675bool disable_constant_ubo_load_sorting;676bool sorted_any_ubo_loads;677678/* Emits ldunif for each new uniform, even if the uniform was already679* emitted in the same block. Useful to compile shaders with high680* register pressure or to disable the optimization during uniform681* spills.682*/683bool disable_ldunif_opt;684685/* Disables loop unrolling to reduce register pressure. */686bool disable_loop_unrolling;687bool unrolled_any_loops;688689/* Minimum number of threads we are willing to use to register allocate690* a shader with the current compilation strategy. This only prevents691* us from lowering the thread count to register allocate successfully,692* which can be useful when we prefer doing other changes to the693* compilation strategy before dropping thread count.694*/695uint32_t min_threads_for_reg_alloc;696697/* Whether TMU spills are allowed. If this is disabled it may cause698* register allocation to fail. We set this to favor other compilation699* strategies that can reduce register pressure and hopefully reduce or700* eliminate TMU spills in the shader.701*/702bool tmu_spilling_allowed;703704/* The UBO index and block used with the last unifa load, as well as the705* current unifa offset *after* emitting that load. This is used to skip706* unifa writes (and their 3 delay slot) when the next UBO load reads707* right after the previous one in the same block.708*/709struct qblock *current_unifa_block;710int32_t current_unifa_index;711uint32_t current_unifa_offset;712713/* State for whether we're executing on each channel currently. 0 if714* yes, otherwise a block number + 1 that the channel jumped to.715*/716struct qreg execute;717bool in_control_flow;718719struct qreg line_x, point_x, point_y, primitive_id;720721/**722* Instance ID, which comes in before the vertex attribute payload if723* the shader record requests it.724*/725struct qreg iid;726727/**728* Base Instance ID, which comes in before the vertex attribute payload729* (after Instance ID) if the shader record requests it.730*/731struct qreg biid;732733/**734* Vertex ID, which comes in before the vertex attribute payload735* (after Base Instance) if the shader record requests it.736*/737struct qreg vid;738739/* Fragment shader payload regs. */740struct qreg payload_w, payload_w_centroid, payload_z;741742struct qreg cs_payload[2];743struct qreg cs_shared_offset;744int local_invocation_index_bits;745746/* If the shader uses subgroup functionality */747bool has_subgroups;748749uint8_t vattr_sizes[V3D_MAX_VS_INPUTS / 4];750uint32_t vpm_output_size;751752/* Size in bytes of registers that have been spilled. This is how much753* space needs to be available in the spill BO per thread per QPU.754*/755uint32_t spill_size;756/* Shader-db stats */757uint32_t spills, fills, loops;758/**759* Register spilling's per-thread base address, shared between each760* spill/fill's addressing calculations.761*/762struct qreg spill_base;763/* Bit vector of which temps may be spilled */764BITSET_WORD *spillable;765766/**767* Array of the VARYING_SLOT_* of all FS QFILE_VARY reads.768*769* This includes those that aren't part of the VPM varyings, like770* point/line coordinates.771*/772struct v3d_varying_slot input_slots[V3D_MAX_FS_INPUTS];773774/**775* An entry per outputs[] in the VS indicating what the VARYING_SLOT_*776* of the output is. Used to emit from the VS in the order that the777* FS needs.778*/779struct v3d_varying_slot *output_slots;780781struct pipe_shader_state *shader_state;782struct v3d_key *key;783struct v3d_fs_key *fs_key;784struct v3d_gs_key *gs_key;785struct v3d_vs_key *vs_key;786787/* Live ranges of temps. */788int *temp_start, *temp_end;789bool live_intervals_valid;790791uint32_t *uniform_data;792enum quniform_contents *uniform_contents;793uint32_t uniform_array_size;794uint32_t num_uniforms;795uint32_t output_position_index;796nir_variable *output_color_var[4];797uint32_t output_sample_mask_index;798799struct qreg undef;800uint32_t num_temps;801802struct vir_cursor cursor;803struct list_head blocks;804int next_block_index;805struct qblock *cur_block;806struct qblock *loop_cont_block;807struct qblock *loop_break_block;808/**809* Which temp, if any, do we currently have in the flags?810* This is set when processing a comparison instruction, and811* reset to -1 by anything else that touches the flags.812*/813int32_t flags_temp;814enum v3d_qpu_cond flags_cond;815816uint64_t *qpu_insts;817uint32_t qpu_inst_count;818uint32_t qpu_inst_size;819uint32_t qpu_inst_stalled_count;820uint32_t nop_count;821822/* For the FS, the number of varying inputs not counting the823* point/line varyings payload824*/825uint32_t num_inputs;826827uint32_t program_id;828uint32_t variant_id;829830/* Set to compile program in in 1x, 2x, or 4x threaded mode, where831* SIG_THREAD_SWITCH is used to hide texturing latency at the cost of832* limiting ourselves to the part of the physical reg space.833*834* On V3D 3.x, 2x or 4x divide the physical reg space by 2x or 4x. On835* V3D 4.x, all shaders are 2x threaded, and 4x only divides the836* physical reg space in half.837*/838uint8_t threads;839struct qinst *last_thrsw;840bool last_thrsw_at_top_level;841842bool emitted_tlb_load;843bool lock_scoreboard_on_first_thrsw;844845/* Total number of spilled registers in the program */846uint32_t spill_count;847848enum v3d_compilation_result compilation_result;849850bool tmu_dirty_rcl;851};852853struct v3d_uniform_list {854enum quniform_contents *contents;855uint32_t *data;856uint32_t count;857};858859struct v3d_prog_data {860struct v3d_uniform_list uniforms;861862uint32_t spill_size;863864uint8_t threads;865866/* For threads > 1, whether the program should be dispatched in the867* after-final-THRSW state.868*/869bool single_seg;870871bool tmu_dirty_rcl;872873bool has_control_barrier;874};875876struct v3d_vs_prog_data {877struct v3d_prog_data base;878879bool uses_iid, uses_biid, uses_vid;880881/* Number of components read from each vertex attribute. */882uint8_t vattr_sizes[V3D_MAX_VS_INPUTS / 4];883884/* Total number of components read, for the shader state record. */885uint32_t vpm_input_size;886887/* Total number of components written, for the shader state record. */888uint32_t vpm_output_size;889890/* Set if there should be separate VPM segments for input and output.891* If unset, vpm_input_size will be 0.892*/893bool separate_segments;894895/* Value to be programmed in VCM_CACHE_SIZE. */896uint8_t vcm_cache_size;897898/* Maps the nir->data.location to its899* nir->data.driver_location. In general we are using the900* driver location as index (like vattr_sizes above), so this901* map is useful when what we have is the location902*903* Returns -1 if the location is not used904*/905int32_t driver_location_map[V3D_MAX_VS_INPUTS];906};907908struct v3d_gs_prog_data {909struct v3d_prog_data base;910911/* Whether the program reads gl_PrimitiveIDIn */912bool uses_pid;913914/* Number of components read from each input varying. */915uint8_t input_sizes[V3D_MAX_GS_INPUTS / 4];916917/* Number of inputs */918uint8_t num_inputs;919struct v3d_varying_slot input_slots[V3D_MAX_GS_INPUTS];920921/* Total number of components written, for the shader state record. */922uint32_t vpm_output_size;923924/* Maximum SIMD dispatch width to not exceed VPM output size limits925* in the geometry shader. Notice that the final dispatch width has to926* be decided at draw time and could be lower based on the VPM pressure927* added by other shader stages.928*/929uint8_t simd_width;930931/* Output primitive type */932uint8_t out_prim_type;933934/* Number of GS invocations */935uint8_t num_invocations;936937bool writes_psiz;938};939940struct v3d_fs_prog_data {941struct v3d_prog_data base;942943/* Whether the program reads gl_PrimitiveID */944bool uses_pid;945946struct v3d_varying_slot input_slots[V3D_MAX_FS_INPUTS];947948/* Array of flat shade flags.949*950* Each entry is only 24 bits (high 8 bits 0), to match the hardware951* packet layout.952*/953uint32_t flat_shade_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];954955uint32_t noperspective_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];956957uint32_t centroid_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];958959uint8_t num_inputs;960bool writes_z;961bool disable_ez;962bool uses_center_w;963bool uses_implicit_point_line_varyings;964bool lock_scoreboard_on_first_thrsw;965bool force_per_sample_msaa;966};967968struct v3d_compute_prog_data {969struct v3d_prog_data base;970/* Size in bytes of the workgroup's shared space. */971uint32_t shared_size;972uint16_t local_size[3];973/* If the shader uses subgroup functionality */974bool has_subgroups;975};976977struct vpm_config {978uint32_t As;979uint32_t Vc;980uint32_t Gs;981uint32_t Gd;982uint32_t Gv;983uint32_t Ve;984uint32_t gs_width;985};986987bool988v3d_compute_vpm_config(struct v3d_device_info *devinfo,989struct v3d_vs_prog_data *vs_bin,990struct v3d_vs_prog_data *vs,991struct v3d_gs_prog_data *gs_bin,992struct v3d_gs_prog_data *gs,993struct vpm_config *vpm_cfg_bin,994struct vpm_config *vpm_cfg);995996static inline bool997vir_has_uniform(struct qinst *inst)998{999return inst->uniform != ~0;1000}10011002const struct v3d_compiler *v3d_compiler_init(const struct v3d_device_info *devinfo);1003void v3d_compiler_free(const struct v3d_compiler *compiler);1004void v3d_optimize_nir(struct v3d_compile *c, struct nir_shader *s);10051006uint64_t *v3d_compile(const struct v3d_compiler *compiler,1007struct v3d_key *key,1008struct v3d_prog_data **prog_data,1009nir_shader *s,1010void (*debug_output)(const char *msg,1011void *debug_output_data),1012void *debug_output_data,1013int program_id, int variant_id,1014uint32_t *final_assembly_size);10151016uint32_t v3d_prog_data_size(gl_shader_stage stage);1017void v3d_nir_to_vir(struct v3d_compile *c);10181019void vir_compile_destroy(struct v3d_compile *c);1020const char *vir_get_stage_name(struct v3d_compile *c);1021struct qblock *vir_new_block(struct v3d_compile *c);1022void vir_set_emit_block(struct v3d_compile *c, struct qblock *block);1023void vir_link_blocks(struct qblock *predecessor, struct qblock *successor);1024struct qblock *vir_entry_block(struct v3d_compile *c);1025struct qblock *vir_exit_block(struct v3d_compile *c);1026struct qinst *vir_add_inst(enum v3d_qpu_add_op op, struct qreg dst,1027struct qreg src0, struct qreg src1);1028struct qinst *vir_mul_inst(enum v3d_qpu_mul_op op, struct qreg dst,1029struct qreg src0, struct qreg src1);1030struct qinst *vir_branch_inst(struct v3d_compile *c,1031enum v3d_qpu_branch_cond cond);1032void vir_remove_instruction(struct v3d_compile *c, struct qinst *qinst);1033uint32_t vir_get_uniform_index(struct v3d_compile *c,1034enum quniform_contents contents,1035uint32_t data);1036struct qreg vir_uniform(struct v3d_compile *c,1037enum quniform_contents contents,1038uint32_t data);1039void vir_schedule_instructions(struct v3d_compile *c);1040void v3d_setup_spill_base(struct v3d_compile *c);1041struct v3d_qpu_instr v3d_qpu_nop(void);10421043struct qreg vir_emit_def(struct v3d_compile *c, struct qinst *inst);1044struct qinst *vir_emit_nondef(struct v3d_compile *c, struct qinst *inst);1045void vir_set_cond(struct qinst *inst, enum v3d_qpu_cond cond);1046void vir_set_pf(struct v3d_compile *c, struct qinst *inst, enum v3d_qpu_pf pf);1047void vir_set_uf(struct v3d_compile *c, struct qinst *inst, enum v3d_qpu_uf uf);1048void vir_set_unpack(struct qinst *inst, int src,1049enum v3d_qpu_input_unpack unpack);1050void vir_set_pack(struct qinst *inst, enum v3d_qpu_output_pack pack);10511052struct qreg vir_get_temp(struct v3d_compile *c);1053void vir_emit_last_thrsw(struct v3d_compile *c);1054void vir_calculate_live_intervals(struct v3d_compile *c);1055int vir_get_nsrc(struct qinst *inst);1056bool vir_has_side_effects(struct v3d_compile *c, struct qinst *inst);1057bool vir_get_add_op(struct qinst *inst, enum v3d_qpu_add_op *op);1058bool vir_get_mul_op(struct qinst *inst, enum v3d_qpu_mul_op *op);1059bool vir_is_raw_mov(struct qinst *inst);1060bool vir_is_tex(const struct v3d_device_info *devinfo, struct qinst *inst);1061bool vir_is_add(struct qinst *inst);1062bool vir_is_mul(struct qinst *inst);1063bool vir_writes_r3(const struct v3d_device_info *devinfo, struct qinst *inst);1064bool vir_writes_r4(const struct v3d_device_info *devinfo, struct qinst *inst);1065struct qreg vir_follow_movs(struct v3d_compile *c, struct qreg reg);1066uint8_t vir_channels_written(struct qinst *inst);1067struct qreg ntq_get_src(struct v3d_compile *c, nir_src src, int i);1068void ntq_store_dest(struct v3d_compile *c, nir_dest *dest, int chan,1069struct qreg result);1070bool ntq_tmu_fifo_overflow(struct v3d_compile *c, uint32_t components);1071void ntq_add_pending_tmu_flush(struct v3d_compile *c, nir_dest *dest,1072uint32_t component_mask);1073void ntq_flush_tmu(struct v3d_compile *c);1074void vir_emit_thrsw(struct v3d_compile *c);10751076void vir_dump(struct v3d_compile *c);1077void vir_dump_inst(struct v3d_compile *c, struct qinst *inst);1078void vir_dump_uniform(enum quniform_contents contents, uint32_t data);10791080void vir_validate(struct v3d_compile *c);10811082void vir_optimize(struct v3d_compile *c);1083bool vir_opt_algebraic(struct v3d_compile *c);1084bool vir_opt_constant_folding(struct v3d_compile *c);1085bool vir_opt_copy_propagate(struct v3d_compile *c);1086bool vir_opt_dead_code(struct v3d_compile *c);1087bool vir_opt_peephole_sf(struct v3d_compile *c);1088bool vir_opt_redundant_flags(struct v3d_compile *c);1089bool vir_opt_small_immediates(struct v3d_compile *c);1090bool vir_opt_vpm(struct v3d_compile *c);1091bool vir_opt_constant_alu(struct v3d_compile *c);1092void v3d_nir_lower_blend(nir_shader *s, struct v3d_compile *c);1093void v3d_nir_lower_io(nir_shader *s, struct v3d_compile *c);1094void v3d_nir_lower_line_smooth(nir_shader *shader);1095void v3d_nir_lower_logic_ops(nir_shader *s, struct v3d_compile *c);1096void v3d_nir_lower_robust_buffer_access(nir_shader *shader, struct v3d_compile *c);1097void v3d_nir_lower_scratch(nir_shader *s);1098void v3d_nir_lower_txf_ms(nir_shader *s, struct v3d_compile *c);1099void v3d_nir_lower_image_load_store(nir_shader *s);1100void vir_lower_uniforms(struct v3d_compile *c);11011102void v3d33_vir_vpm_read_setup(struct v3d_compile *c, int num_components);1103void v3d33_vir_vpm_write_setup(struct v3d_compile *c);1104void v3d33_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr);1105void v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr);1106void v3d40_vir_emit_image_load_store(struct v3d_compile *c,1107nir_intrinsic_instr *instr);11081109void v3d_vir_to_qpu(struct v3d_compile *c, struct qpu_reg *temp_registers);1110uint32_t v3d_qpu_schedule_instructions(struct v3d_compile *c);1111void qpu_validate(struct v3d_compile *c);1112struct qpu_reg *v3d_register_allocate(struct v3d_compile *c, bool *spilled);1113bool vir_init_reg_sets(struct v3d_compiler *compiler);11141115int v3d_shaderdb_dump(struct v3d_compile *c, char **shaderdb_str);11161117bool v3d_gl_format_is_return_32(GLenum format);11181119uint32_t1120v3d_get_op_for_atomic_add(nir_intrinsic_instr *instr, unsigned src);11211122static inline bool1123quniform_contents_is_texture_p0(enum quniform_contents contents)1124{1125return (contents >= QUNIFORM_TEXTURE_CONFIG_P0_0 &&1126contents < (QUNIFORM_TEXTURE_CONFIG_P0_0 +1127V3D_MAX_TEXTURE_SAMPLERS));1128}11291130static inline bool1131vir_in_nonuniform_control_flow(struct v3d_compile *c)1132{1133return c->execute.file != QFILE_NULL;1134}11351136static inline struct qreg1137vir_uniform_ui(struct v3d_compile *c, uint32_t ui)1138{1139return vir_uniform(c, QUNIFORM_CONSTANT, ui);1140}11411142static inline struct qreg1143vir_uniform_f(struct v3d_compile *c, float f)1144{1145return vir_uniform(c, QUNIFORM_CONSTANT, fui(f));1146}11471148#define VIR_ALU0(name, vir_inst, op) \1149static inline struct qreg \1150vir_##name(struct v3d_compile *c) \1151{ \1152return vir_emit_def(c, vir_inst(op, c->undef, \1153c->undef, c->undef)); \1154} \1155static inline struct qinst * \1156vir_##name##_dest(struct v3d_compile *c, struct qreg dest) \1157{ \1158return vir_emit_nondef(c, vir_inst(op, dest, \1159c->undef, c->undef)); \1160}11611162#define VIR_ALU1(name, vir_inst, op) \1163static inline struct qreg \1164vir_##name(struct v3d_compile *c, struct qreg a) \1165{ \1166return vir_emit_def(c, vir_inst(op, c->undef, \1167a, c->undef)); \1168} \1169static inline struct qinst * \1170vir_##name##_dest(struct v3d_compile *c, struct qreg dest, \1171struct qreg a) \1172{ \1173return vir_emit_nondef(c, vir_inst(op, dest, a, \1174c->undef)); \1175}11761177#define VIR_ALU2(name, vir_inst, op) \1178static inline struct qreg \1179vir_##name(struct v3d_compile *c, struct qreg a, struct qreg b) \1180{ \1181return vir_emit_def(c, vir_inst(op, c->undef, a, b)); \1182} \1183static inline struct qinst * \1184vir_##name##_dest(struct v3d_compile *c, struct qreg dest, \1185struct qreg a, struct qreg b) \1186{ \1187return vir_emit_nondef(c, vir_inst(op, dest, a, b)); \1188}11891190#define VIR_NODST_0(name, vir_inst, op) \1191static inline struct qinst * \1192vir_##name(struct v3d_compile *c) \1193{ \1194return vir_emit_nondef(c, vir_inst(op, c->undef, \1195c->undef, c->undef)); \1196}11971198#define VIR_NODST_1(name, vir_inst, op) \1199static inline struct qinst * \1200vir_##name(struct v3d_compile *c, struct qreg a) \1201{ \1202return vir_emit_nondef(c, vir_inst(op, c->undef, \1203a, c->undef)); \1204}12051206#define VIR_NODST_2(name, vir_inst, op) \1207static inline struct qinst * \1208vir_##name(struct v3d_compile *c, struct qreg a, struct qreg b) \1209{ \1210return vir_emit_nondef(c, vir_inst(op, c->undef, \1211a, b)); \1212}12131214#define VIR_SFU(name) \1215static inline struct qreg \1216vir_##name(struct v3d_compile *c, struct qreg a) \1217{ \1218if (c->devinfo->ver >= 41) { \1219return vir_emit_def(c, vir_add_inst(V3D_QPU_A_##name, \1220c->undef, \1221a, c->undef)); \1222} else { \1223vir_FMOV_dest(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_##name), a); \1224return vir_FMOV(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_R4)); \1225} \1226} \1227static inline struct qinst * \1228vir_##name##_dest(struct v3d_compile *c, struct qreg dest, \1229struct qreg a) \1230{ \1231if (c->devinfo->ver >= 41) { \1232return vir_emit_nondef(c, vir_add_inst(V3D_QPU_A_##name, \1233dest, \1234a, c->undef)); \1235} else { \1236vir_FMOV_dest(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_##name), a); \1237return vir_FMOV_dest(c, dest, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_R4)); \1238} \1239}12401241#define VIR_A_ALU2(name) VIR_ALU2(name, vir_add_inst, V3D_QPU_A_##name)1242#define VIR_M_ALU2(name) VIR_ALU2(name, vir_mul_inst, V3D_QPU_M_##name)1243#define VIR_A_ALU1(name) VIR_ALU1(name, vir_add_inst, V3D_QPU_A_##name)1244#define VIR_M_ALU1(name) VIR_ALU1(name, vir_mul_inst, V3D_QPU_M_##name)1245#define VIR_A_ALU0(name) VIR_ALU0(name, vir_add_inst, V3D_QPU_A_##name)1246#define VIR_M_ALU0(name) VIR_ALU0(name, vir_mul_inst, V3D_QPU_M_##name)1247#define VIR_A_NODST_2(name) VIR_NODST_2(name, vir_add_inst, V3D_QPU_A_##name)1248#define VIR_M_NODST_2(name) VIR_NODST_2(name, vir_mul_inst, V3D_QPU_M_##name)1249#define VIR_A_NODST_1(name) VIR_NODST_1(name, vir_add_inst, V3D_QPU_A_##name)1250#define VIR_M_NODST_1(name) VIR_NODST_1(name, vir_mul_inst, V3D_QPU_M_##name)1251#define VIR_A_NODST_0(name) VIR_NODST_0(name, vir_add_inst, V3D_QPU_A_##name)12521253VIR_A_ALU2(FADD)1254VIR_A_ALU2(VFPACK)1255VIR_A_ALU2(FSUB)1256VIR_A_ALU2(FMIN)1257VIR_A_ALU2(FMAX)12581259VIR_A_ALU2(ADD)1260VIR_A_ALU2(SUB)1261VIR_A_ALU2(SHL)1262VIR_A_ALU2(SHR)1263VIR_A_ALU2(ASR)1264VIR_A_ALU2(ROR)1265VIR_A_ALU2(MIN)1266VIR_A_ALU2(MAX)1267VIR_A_ALU2(UMIN)1268VIR_A_ALU2(UMAX)1269VIR_A_ALU2(AND)1270VIR_A_ALU2(OR)1271VIR_A_ALU2(XOR)1272VIR_A_ALU2(VADD)1273VIR_A_ALU2(VSUB)1274VIR_A_NODST_2(STVPMV)1275VIR_A_NODST_2(STVPMD)1276VIR_A_ALU1(NOT)1277VIR_A_ALU1(NEG)1278VIR_A_ALU1(FLAPUSH)1279VIR_A_ALU1(FLBPUSH)1280VIR_A_ALU1(FLPOP)1281VIR_A_ALU0(FLAFIRST)1282VIR_A_ALU0(FLNAFIRST)1283VIR_A_ALU1(SETMSF)1284VIR_A_ALU1(SETREVF)1285VIR_A_ALU0(TIDX)1286VIR_A_ALU0(EIDX)1287VIR_A_ALU1(LDVPMV_IN)1288VIR_A_ALU1(LDVPMV_OUT)1289VIR_A_ALU1(LDVPMD_IN)1290VIR_A_ALU1(LDVPMD_OUT)1291VIR_A_ALU2(LDVPMG_IN)1292VIR_A_ALU2(LDVPMG_OUT)1293VIR_A_ALU0(TMUWT)12941295VIR_A_ALU0(IID)1296VIR_A_ALU0(FXCD)1297VIR_A_ALU0(XCD)1298VIR_A_ALU0(FYCD)1299VIR_A_ALU0(YCD)1300VIR_A_ALU0(MSF)1301VIR_A_ALU0(REVF)1302VIR_A_ALU0(BARRIERID)1303VIR_A_ALU0(SAMPID)1304VIR_A_NODST_1(VPMSETUP)1305VIR_A_NODST_0(VPMWT)1306VIR_A_ALU2(FCMP)1307VIR_A_ALU2(VFMAX)13081309VIR_A_ALU1(FROUND)1310VIR_A_ALU1(FTOIN)1311VIR_A_ALU1(FTRUNC)1312VIR_A_ALU1(FTOIZ)1313VIR_A_ALU1(FFLOOR)1314VIR_A_ALU1(FTOUZ)1315VIR_A_ALU1(FCEIL)1316VIR_A_ALU1(FTOC)13171318VIR_A_ALU1(FDX)1319VIR_A_ALU1(FDY)13201321VIR_A_ALU1(ITOF)1322VIR_A_ALU1(CLZ)1323VIR_A_ALU1(UTOF)13241325VIR_M_ALU2(UMUL24)1326VIR_M_ALU2(FMUL)1327VIR_M_ALU2(SMUL24)1328VIR_M_NODST_2(MULTOP)13291330VIR_M_ALU1(MOV)1331VIR_M_ALU1(FMOV)13321333VIR_SFU(RECIP)1334VIR_SFU(RSQRT)1335VIR_SFU(EXP)1336VIR_SFU(LOG)1337VIR_SFU(SIN)1338VIR_SFU(RSQRT2)13391340static inline struct qinst *1341vir_MOV_cond(struct v3d_compile *c, enum v3d_qpu_cond cond,1342struct qreg dest, struct qreg src)1343{1344struct qinst *mov = vir_MOV_dest(c, dest, src);1345vir_set_cond(mov, cond);1346return mov;1347}13481349static inline struct qreg1350vir_SEL(struct v3d_compile *c, enum v3d_qpu_cond cond,1351struct qreg src0, struct qreg src1)1352{1353struct qreg t = vir_get_temp(c);1354vir_MOV_dest(c, t, src1);1355vir_MOV_cond(c, cond, t, src0);1356return t;1357}13581359static inline struct qinst *1360vir_NOP(struct v3d_compile *c)1361{1362return vir_emit_nondef(c, vir_add_inst(V3D_QPU_A_NOP,1363c->undef, c->undef, c->undef));1364}13651366static inline struct qreg1367vir_LDTMU(struct v3d_compile *c)1368{1369if (c->devinfo->ver >= 41) {1370struct qinst *ldtmu = vir_add_inst(V3D_QPU_A_NOP, c->undef,1371c->undef, c->undef);1372ldtmu->qpu.sig.ldtmu = true;13731374return vir_emit_def(c, ldtmu);1375} else {1376vir_NOP(c)->qpu.sig.ldtmu = true;1377return vir_MOV(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_R4));1378}1379}13801381static inline struct qreg1382vir_UMUL(struct v3d_compile *c, struct qreg src0, struct qreg src1)1383{1384vir_MULTOP(c, src0, src1);1385return vir_UMUL24(c, src0, src1);1386}13871388static inline struct qreg1389vir_TLBU_COLOR_READ(struct v3d_compile *c, uint32_t config)1390{1391assert(c->devinfo->ver >= 41); /* XXX */1392assert((config & 0xffffff00) == 0xffffff00);13931394struct qinst *ldtlb = vir_add_inst(V3D_QPU_A_NOP, c->undef,1395c->undef, c->undef);1396ldtlb->qpu.sig.ldtlbu = true;1397ldtlb->uniform = vir_get_uniform_index(c, QUNIFORM_CONSTANT, config);1398return vir_emit_def(c, ldtlb);1399}14001401static inline struct qreg1402vir_TLB_COLOR_READ(struct v3d_compile *c)1403{1404assert(c->devinfo->ver >= 41); /* XXX */14051406struct qinst *ldtlb = vir_add_inst(V3D_QPU_A_NOP, c->undef,1407c->undef, c->undef);1408ldtlb->qpu.sig.ldtlb = true;1409return vir_emit_def(c, ldtlb);1410}14111412/*1413static inline struct qreg1414vir_LOAD_IMM(struct v3d_compile *c, uint32_t val)1415{1416return vir_emit_def(c, vir_inst(QOP_LOAD_IMM, c->undef,1417vir_reg(QFILE_LOAD_IMM, val), c->undef));1418}14191420static inline struct qreg1421vir_LOAD_IMM_U2(struct v3d_compile *c, uint32_t val)1422{1423return vir_emit_def(c, vir_inst(QOP_LOAD_IMM_U2, c->undef,1424vir_reg(QFILE_LOAD_IMM, val),1425c->undef));1426}1427static inline struct qreg1428vir_LOAD_IMM_I2(struct v3d_compile *c, uint32_t val)1429{1430return vir_emit_def(c, vir_inst(QOP_LOAD_IMM_I2, c->undef,1431vir_reg(QFILE_LOAD_IMM, val),1432c->undef));1433}1434*/14351436static inline struct qinst *1437vir_BRANCH(struct v3d_compile *c, enum v3d_qpu_branch_cond cond)1438{1439/* The actual uniform_data value will be set at scheduling time */1440return vir_emit_nondef(c, vir_branch_inst(c, cond));1441}14421443#define vir_for_each_block(block, c) \1444list_for_each_entry(struct qblock, block, &c->blocks, link)14451446#define vir_for_each_block_rev(block, c) \1447list_for_each_entry_rev(struct qblock, block, &c->blocks, link)14481449/* Loop over the non-NULL members of the successors array. */1450#define vir_for_each_successor(succ, block) \1451for (struct qblock *succ = block->successors[0]; \1452succ != NULL; \1453succ = (succ == block->successors[1] ? NULL : \1454block->successors[1]))14551456#define vir_for_each_inst(inst, block) \1457list_for_each_entry(struct qinst, inst, &block->instructions, link)14581459#define vir_for_each_inst_rev(inst, block) \1460list_for_each_entry_rev(struct qinst, inst, &block->instructions, link)14611462#define vir_for_each_inst_safe(inst, block) \1463list_for_each_entry_safe(struct qinst, inst, &block->instructions, link)14641465#define vir_for_each_inst_inorder(inst, c) \1466vir_for_each_block(_block, c) \1467vir_for_each_inst(inst, _block)14681469#define vir_for_each_inst_inorder_safe(inst, c) \1470vir_for_each_block(_block, c) \1471vir_for_each_inst_safe(inst, _block)14721473#endif /* V3D_COMPILER_H */147414751476