Path: blob/21.2-virgl/src/intel/compiler/brw_compiler.h
4550 views
/*1* Copyright © 2010 - 2015 Intel Corporation2*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 BRW_COMPILER_H24#define BRW_COMPILER_H2526#include <stdio.h>27#include "dev/intel_device_info.h"28#include "main/macros.h"29#include "main/mtypes.h"30#include "util/ralloc.h"3132#ifdef __cplusplus33extern "C" {34#endif3536struct ra_regs;37struct nir_shader;38struct brw_program;3940typedef struct nir_shader nir_shader;4142struct brw_compiler {43const struct intel_device_info *devinfo;4445struct {46struct ra_regs *regs;4748/**49* Array of the ra classes for the unaligned contiguous register50* block sizes used.51*/52struct ra_class **classes;53} vec4_reg_set;5455struct {56struct ra_regs *regs;5758/**59* Array of the ra classes for the unaligned contiguous register60* block sizes used, indexed by register size.61*/62struct ra_class *classes[16];6364/**65* ra class for the aligned barycentrics we use for PLN, which doesn't66* appear in *classes.67*/68struct ra_class *aligned_bary_class;69} fs_reg_sets[3];7071void (*shader_debug_log)(void *, const char *str, ...) PRINTFLIKE(2, 3);72void (*shader_perf_log)(void *, const char *str, ...) PRINTFLIKE(2, 3);7374bool scalar_stage[MESA_ALL_SHADER_STAGES];75bool use_tcs_8_patch;76struct gl_shader_compiler_options glsl_compiler_options[MESA_ALL_SHADER_STAGES];7778/**79* Apply workarounds for SIN and COS output range problems.80* This can negatively impact performance.81*/82bool precise_trig;8384/**85* Is 3DSTATE_CONSTANT_*'s Constant Buffer 0 relative to Dynamic State86* Base Address? (If not, it's a normal GPU address.)87*/88bool constant_buffer_0_is_relative;8990/**91* Whether or not the driver supports pull constants. If not, the compiler92* will attempt to push everything.93*/94bool supports_pull_constants;9596/**97* Whether or not the driver supports NIR shader constants. This controls98* whether nir_opt_large_constants will be run.99*/100bool supports_shader_constants;101102/**103* Whether or not the driver wants uniform params to be compacted by the104* back-end compiler.105*/106bool compact_params;107108/**109* Whether or not the driver wants variable group size to be lowered by the110* back-end compiler.111*/112bool lower_variable_group_size;113114/**115* Whether indirect UBO loads should use the sampler or go through the116* data/constant cache. For the sampler, UBO surface states have to be set117* up with VK_FORMAT_R32G32B32A32_FLOAT whereas if it's going through the118* constant or data cache, UBOs must use VK_FORMAT_RAW.119*/120bool indirect_ubos_use_sampler;121};122123/**124* We use a constant subgroup size of 32. It really only needs to be a125* maximum and, since we do SIMD32 for compute shaders in some cases, it126* needs to be at least 32. SIMD8 and SIMD16 shaders will still claim a127* subgroup size of 32 but will act as if 16 or 24 of those channels are128* disabled.129*/130#define BRW_SUBGROUP_SIZE 32131132static inline bool133brw_shader_stage_is_bindless(gl_shader_stage stage)134{135return stage >= MESA_SHADER_RAYGEN &&136stage <= MESA_SHADER_CALLABLE;137}138139/**140* Program key structures.141*142* When drawing, we look for the currently bound shaders in the program143* cache. This is essentially a hash table lookup, and these are the keys.144*145* Sometimes OpenGL features specified as state need to be simulated via146* shader code, due to a mismatch between the API and the hardware. This147* is often referred to as "non-orthagonal state" or "NOS". We store NOS148* in the program key so it's considered when searching for a program. If149* we haven't seen a particular combination before, we have to recompile a150* new specialized version.151*152* Shader compilation should not look up state in gl_context directly, but153* instead use the copy in the program key. This guarantees recompiles will154* happen correctly.155*156* @{157*/158159enum PACKED gfx6_gather_sampler_wa {160WA_SIGN = 1, /* whether we need to sign extend */161WA_8BIT = 2, /* if we have an 8bit format needing wa */162WA_16BIT = 4, /* if we have a 16bit format needing wa */163};164165/**166* Sampler information needed by VS, WM, and GS program cache keys.167*/168struct brw_sampler_prog_key_data {169/**170* EXT_texture_swizzle and DEPTH_TEXTURE_MODE swizzles.171*/172uint16_t swizzles[MAX_SAMPLERS];173174uint32_t gl_clamp_mask[3];175176/**177* For RG32F, gather4's channel select is broken.178*/179uint32_t gather_channel_quirk_mask;180181/**182* Whether this sampler uses the compressed multisample surface layout.183*/184uint32_t compressed_multisample_layout_mask;185186/**187* Whether this sampler is using 16x multisampling. If so fetching from188* this sampler will be handled with a different instruction, ld2dms_w189* instead of ld2dms.190*/191uint32_t msaa_16;192193/**194* For Sandybridge, which shader w/a we need for gather quirks.195*/196enum gfx6_gather_sampler_wa gfx6_gather_wa[MAX_SAMPLERS];197198/**199* Texture units that have a YUV image bound.200*/201uint32_t y_u_v_image_mask;202uint32_t y_uv_image_mask;203uint32_t yx_xuxv_image_mask;204uint32_t xy_uxvx_image_mask;205uint32_t ayuv_image_mask;206uint32_t xyuv_image_mask;207uint32_t bt709_mask;208uint32_t bt2020_mask;209210/* Scale factor for each texture. */211float scale_factors[32];212};213214/** An enum representing what kind of input gl_SubgroupSize is. */215enum PACKED brw_subgroup_size_type216{217BRW_SUBGROUP_SIZE_API_CONSTANT, /**< Default Vulkan behavior */218BRW_SUBGROUP_SIZE_UNIFORM, /**< OpenGL behavior */219BRW_SUBGROUP_SIZE_VARYING, /**< VK_EXT_subgroup_size_control */220221/* These enums are specifically chosen so that the value of the enum is222* also the subgroup size. If any new values are added, they must respect223* this invariant.224*/225BRW_SUBGROUP_SIZE_REQUIRE_8 = 8, /**< VK_EXT_subgroup_size_control */226BRW_SUBGROUP_SIZE_REQUIRE_16 = 16, /**< VK_EXT_subgroup_size_control */227BRW_SUBGROUP_SIZE_REQUIRE_32 = 32, /**< VK_EXT_subgroup_size_control */228};229230struct brw_base_prog_key {231unsigned program_string_id;232233enum brw_subgroup_size_type subgroup_size_type;234bool robust_buffer_access;235struct brw_sampler_prog_key_data tex;236};237238/**239* The VF can't natively handle certain types of attributes, such as GL_FIXED240* or most 10_10_10_2 types. These flags enable various VS workarounds to241* "fix" attributes at the beginning of shaders.242*/243#define BRW_ATTRIB_WA_COMPONENT_MASK 7 /* mask for GL_FIXED scale channel count */244#define BRW_ATTRIB_WA_NORMALIZE 8 /* normalize in shader */245#define BRW_ATTRIB_WA_BGRA 16 /* swap r/b channels in shader */246#define BRW_ATTRIB_WA_SIGN 32 /* interpret as signed in shader */247#define BRW_ATTRIB_WA_SCALE 64 /* interpret as scaled in shader */248249/**250* OpenGL attribute slots fall in [0, VERT_ATTRIB_MAX - 1] with the range251* [VERT_ATTRIB_GENERIC0, VERT_ATTRIB_MAX - 1] reserved for up to 16 user252* input vertex attributes. In Vulkan, we expose up to 28 user vertex input253* attributes that are mapped to slots also starting at VERT_ATTRIB_GENERIC0.254*/255#define MAX_GL_VERT_ATTRIB VERT_ATTRIB_MAX256#define MAX_VK_VERT_ATTRIB (VERT_ATTRIB_GENERIC0 + 28)257258/**259* Max number of binding table entries used for stream output.260*261* From the OpenGL 3.0 spec, table 6.44 (Transform Feedback State), the262* minimum value of MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS is 64.263*264* On Gfx6, the size of transform feedback data is limited not by the number265* of components but by the number of binding table entries we set aside. We266* use one binding table entry for a float, one entry for a vector, and one267* entry per matrix column. Since the only way we can communicate our268* transform feedback capabilities to the client is via269* MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, we need to plan for the270* worst case, in which all the varyings are floats, so we use up one binding271* table entry per component. Therefore we need to set aside at least 64272* binding table entries for use by transform feedback.273*274* Note: since we don't currently pack varyings, it is currently impossible275* for the client to actually use up all of these binding table entries--if276* all of their varyings were floats, they would run out of varying slots and277* fail to link. But that's a bug, so it seems prudent to go ahead and278* allocate the number of binding table entries we will need once the bug is279* fixed.280*/281#define BRW_MAX_SOL_BINDINGS 64282283/** The program key for Vertex Shaders. */284struct brw_vs_prog_key {285struct brw_base_prog_key base;286287/**288* Per-attribute workaround flags289*290* For each attribute, a combination of BRW_ATTRIB_WA_*.291*292* For OpenGL, where we expose a maximum of 16 user input atttributes293* we only need up to VERT_ATTRIB_MAX slots, however, in Vulkan294* slots preceding VERT_ATTRIB_GENERIC0 are unused and we can295* expose up to 28 user input vertex attributes that are mapped to slots296* starting at VERT_ATTRIB_GENERIC0, so this array needs to be large297* enough to hold this many slots.298*/299uint8_t gl_attrib_wa_flags[MAX2(MAX_GL_VERT_ATTRIB, MAX_VK_VERT_ATTRIB)];300301bool copy_edgeflag:1;302303bool clamp_vertex_color:1;304305/**306* How many user clipping planes are being uploaded to the vertex shader as307* push constants.308*309* These are used for lowering legacy gl_ClipVertex/gl_Position clipping to310* clip distances.311*/312unsigned nr_userclip_plane_consts:4;313314/**315* For pre-Gfx6 hardware, a bitfield indicating which texture coordinates316* are going to be replaced with point coordinates (as a consequence of a317* call to glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)). Because318* our SF thread requires exact matching between VS outputs and FS inputs,319* these texture coordinates will need to be unconditionally included in320* the VUE, even if they aren't written by the vertex shader.321*/322uint8_t point_coord_replace;323};324325/** The program key for Tessellation Control Shaders. */326struct brw_tcs_prog_key327{328struct brw_base_prog_key base;329330GLenum tes_primitive_mode;331332unsigned input_vertices;333334/** A bitfield of per-patch outputs written. */335uint32_t patch_outputs_written;336337/** A bitfield of per-vertex outputs written. */338uint64_t outputs_written;339340bool quads_workaround;341};342343/** The program key for Tessellation Evaluation Shaders. */344struct brw_tes_prog_key345{346struct brw_base_prog_key base;347348/** A bitfield of per-patch inputs read. */349uint32_t patch_inputs_read;350351/** A bitfield of per-vertex inputs read. */352uint64_t inputs_read;353354/**355* How many user clipping planes are being uploaded to the tessellation356* evaluation shader as push constants.357*358* These are used for lowering legacy gl_ClipVertex/gl_Position clipping to359* clip distances.360*/361unsigned nr_userclip_plane_consts:4;362};363364/** The program key for Geometry Shaders. */365struct brw_gs_prog_key366{367struct brw_base_prog_key base;368369/**370* How many user clipping planes are being uploaded to the geometry shader371* as push constants.372*373* These are used for lowering legacy gl_ClipVertex/gl_Position clipping to374* clip distances.375*/376unsigned nr_userclip_plane_consts:4;377};378379enum brw_sf_primitive {380BRW_SF_PRIM_POINTS = 0,381BRW_SF_PRIM_LINES = 1,382BRW_SF_PRIM_TRIANGLES = 2,383BRW_SF_PRIM_UNFILLED_TRIS = 3,384};385386struct brw_sf_prog_key {387uint64_t attrs;388bool contains_flat_varying;389unsigned char interp_mode[65]; /* BRW_VARYING_SLOT_COUNT */390uint8_t point_sprite_coord_replace;391enum brw_sf_primitive primitive:2;392bool do_twoside_color:1;393bool frontface_ccw:1;394bool do_point_sprite:1;395bool do_point_coord:1;396bool sprite_origin_lower_left:1;397bool userclip_active:1;398};399400enum brw_clip_mode {401BRW_CLIP_MODE_NORMAL = 0,402BRW_CLIP_MODE_CLIP_ALL = 1,403BRW_CLIP_MODE_CLIP_NON_REJECTED = 2,404BRW_CLIP_MODE_REJECT_ALL = 3,405BRW_CLIP_MODE_ACCEPT_ALL = 4,406BRW_CLIP_MODE_KERNEL_CLIP = 5,407};408409enum brw_clip_fill_mode {410BRW_CLIP_FILL_MODE_LINE = 0,411BRW_CLIP_FILL_MODE_POINT = 1,412BRW_CLIP_FILL_MODE_FILL = 2,413BRW_CLIP_FILL_MODE_CULL = 3,414};415416/* Note that if unfilled primitives are being emitted, we have to fix417* up polygon offset and flatshading at this point:418*/419struct brw_clip_prog_key {420uint64_t attrs;421bool contains_flat_varying;422bool contains_noperspective_varying;423unsigned char interp_mode[65]; /* BRW_VARYING_SLOT_COUNT */424unsigned primitive:4;425unsigned nr_userclip:4;426bool pv_first:1;427bool do_unfilled:1;428enum brw_clip_fill_mode fill_cw:2; /* includes cull information */429enum brw_clip_fill_mode fill_ccw:2; /* includes cull information */430bool offset_cw:1;431bool offset_ccw:1;432bool copy_bfc_cw:1;433bool copy_bfc_ccw:1;434enum brw_clip_mode clip_mode:3;435436float offset_factor;437float offset_units;438float offset_clamp;439};440441/* A big lookup table is used to figure out which and how many442* additional regs will inserted before the main payload in the WM443* program execution. These mainly relate to depth and stencil444* processing and the early-depth-test optimization.445*/446enum brw_wm_iz_bits {447BRW_WM_IZ_PS_KILL_ALPHATEST_BIT = 0x1,448BRW_WM_IZ_PS_COMPUTES_DEPTH_BIT = 0x2,449BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT = 0x4,450BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT = 0x8,451BRW_WM_IZ_STENCIL_WRITE_ENABLE_BIT = 0x10,452BRW_WM_IZ_STENCIL_TEST_ENABLE_BIT = 0x20,453BRW_WM_IZ_BIT_MAX = 0x40454};455456enum brw_wm_aa_enable {457BRW_WM_AA_NEVER,458BRW_WM_AA_SOMETIMES,459BRW_WM_AA_ALWAYS460};461462/** The program key for Fragment/Pixel Shaders. */463struct brw_wm_prog_key {464struct brw_base_prog_key base;465466/* Some collection of BRW_WM_IZ_* */467uint8_t iz_lookup;468bool stats_wm:1;469bool flat_shade:1;470unsigned nr_color_regions:5;471bool alpha_test_replicate_alpha:1;472bool alpha_to_coverage:1;473bool clamp_fragment_color:1;474bool persample_interp:1;475bool multisample_fbo:1;476bool frag_coord_adds_sample_pos:1;477enum brw_wm_aa_enable line_aa:2;478bool high_quality_derivatives:1;479bool force_dual_color_blend:1;480bool coherent_fb_fetch:1;481bool ignore_sample_mask_out:1;482bool coarse_pixel:1;483484uint8_t color_outputs_valid;485uint64_t input_slots_valid;486GLenum alpha_test_func; /* < For Gfx4/5 MRT alpha test */487float alpha_test_ref;488};489490struct brw_cs_prog_key {491struct brw_base_prog_key base;492};493494struct brw_bs_prog_key {495struct brw_base_prog_key base;496};497498struct brw_ff_gs_prog_key {499uint64_t attrs;500501/**502* Hardware primitive type being drawn, e.g. _3DPRIM_TRILIST.503*/504unsigned primitive:8;505506unsigned pv_first:1;507unsigned need_gs_prog:1;508509/**510* Number of varyings that are output to transform feedback.511*/512unsigned num_transform_feedback_bindings:7; /* 0-BRW_MAX_SOL_BINDINGS */513514/**515* Map from the index of a transform feedback binding table entry to the516* gl_varying_slot that should be streamed out through that binding table517* entry.518*/519unsigned char transform_feedback_bindings[BRW_MAX_SOL_BINDINGS];520521/**522* Map from the index of a transform feedback binding table entry to the523* swizzles that should be used when streaming out data through that524* binding table entry.525*/526unsigned char transform_feedback_swizzles[BRW_MAX_SOL_BINDINGS];527};528529/* brw_any_prog_key is any of the keys that map to an API stage */530union brw_any_prog_key {531struct brw_base_prog_key base;532struct brw_vs_prog_key vs;533struct brw_tcs_prog_key tcs;534struct brw_tes_prog_key tes;535struct brw_gs_prog_key gs;536struct brw_wm_prog_key wm;537struct brw_cs_prog_key cs;538struct brw_bs_prog_key bs;539};540541/*542* Image metadata structure as laid out in the shader parameter543* buffer. Entries have to be 16B-aligned for the vec4 back-end to be544* able to use them. That's okay because the padding and any unused545* entries [most of them except when we're doing untyped surface546* access] will be removed by the uniform packing pass.547*/548#define BRW_IMAGE_PARAM_OFFSET_OFFSET 0549#define BRW_IMAGE_PARAM_SIZE_OFFSET 4550#define BRW_IMAGE_PARAM_STRIDE_OFFSET 8551#define BRW_IMAGE_PARAM_TILING_OFFSET 12552#define BRW_IMAGE_PARAM_SWIZZLING_OFFSET 16553#define BRW_IMAGE_PARAM_SIZE 20554555struct brw_image_param {556/** Offset applied to the X and Y surface coordinates. */557uint32_t offset[2];558559/** Surface X, Y and Z dimensions. */560uint32_t size[3];561562/** X-stride in bytes, Y-stride in pixels, horizontal slice stride in563* pixels, vertical slice stride in pixels.564*/565uint32_t stride[4];566567/** Log2 of the tiling modulus in the X, Y and Z dimension. */568uint32_t tiling[3];569570/**571* Right shift to apply for bit 6 address swizzling. Two different572* swizzles can be specified and will be applied one after the other. The573* resulting address will be:574*575* addr' = addr ^ ((1 << 6) & ((addr >> swizzling[0]) ^576* (addr >> swizzling[1])))577*578* Use \c 0xff if any of the swizzles is not required.579*/580uint32_t swizzling[2];581};582583/** Max number of render targets in a shader */584#define BRW_MAX_DRAW_BUFFERS 8585586/**587* Binding table index for the first gfx6 SOL binding.588*/589#define BRW_GFX6_SOL_BINDING_START 0590591/**592* Stride in bytes between shader_time entries.593*594* We separate entries by a cacheline to reduce traffic between EUs writing to595* different entries.596*/597#define BRW_SHADER_TIME_STRIDE 64598599struct brw_ubo_range600{601uint16_t block;602uint8_t start;603uint8_t length;604};605606/* We reserve the first 2^16 values for builtins */607#define BRW_PARAM_IS_BUILTIN(param) (((param) & 0xffff0000) == 0)608609enum brw_param_builtin {610BRW_PARAM_BUILTIN_ZERO,611612BRW_PARAM_BUILTIN_CLIP_PLANE_0_X,613BRW_PARAM_BUILTIN_CLIP_PLANE_0_Y,614BRW_PARAM_BUILTIN_CLIP_PLANE_0_Z,615BRW_PARAM_BUILTIN_CLIP_PLANE_0_W,616BRW_PARAM_BUILTIN_CLIP_PLANE_1_X,617BRW_PARAM_BUILTIN_CLIP_PLANE_1_Y,618BRW_PARAM_BUILTIN_CLIP_PLANE_1_Z,619BRW_PARAM_BUILTIN_CLIP_PLANE_1_W,620BRW_PARAM_BUILTIN_CLIP_PLANE_2_X,621BRW_PARAM_BUILTIN_CLIP_PLANE_2_Y,622BRW_PARAM_BUILTIN_CLIP_PLANE_2_Z,623BRW_PARAM_BUILTIN_CLIP_PLANE_2_W,624BRW_PARAM_BUILTIN_CLIP_PLANE_3_X,625BRW_PARAM_BUILTIN_CLIP_PLANE_3_Y,626BRW_PARAM_BUILTIN_CLIP_PLANE_3_Z,627BRW_PARAM_BUILTIN_CLIP_PLANE_3_W,628BRW_PARAM_BUILTIN_CLIP_PLANE_4_X,629BRW_PARAM_BUILTIN_CLIP_PLANE_4_Y,630BRW_PARAM_BUILTIN_CLIP_PLANE_4_Z,631BRW_PARAM_BUILTIN_CLIP_PLANE_4_W,632BRW_PARAM_BUILTIN_CLIP_PLANE_5_X,633BRW_PARAM_BUILTIN_CLIP_PLANE_5_Y,634BRW_PARAM_BUILTIN_CLIP_PLANE_5_Z,635BRW_PARAM_BUILTIN_CLIP_PLANE_5_W,636BRW_PARAM_BUILTIN_CLIP_PLANE_6_X,637BRW_PARAM_BUILTIN_CLIP_PLANE_6_Y,638BRW_PARAM_BUILTIN_CLIP_PLANE_6_Z,639BRW_PARAM_BUILTIN_CLIP_PLANE_6_W,640BRW_PARAM_BUILTIN_CLIP_PLANE_7_X,641BRW_PARAM_BUILTIN_CLIP_PLANE_7_Y,642BRW_PARAM_BUILTIN_CLIP_PLANE_7_Z,643BRW_PARAM_BUILTIN_CLIP_PLANE_7_W,644645BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X,646BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Y,647BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Z,648BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_W,649BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X,650BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y,651652BRW_PARAM_BUILTIN_PATCH_VERTICES_IN,653654BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_X,655BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Y,656BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Z,657BRW_PARAM_BUILTIN_SUBGROUP_ID,658BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_X,659BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Y,660BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Z,661BRW_PARAM_BUILTIN_WORK_DIM,662};663664#define BRW_PARAM_BUILTIN_CLIP_PLANE(idx, comp) \665(BRW_PARAM_BUILTIN_CLIP_PLANE_0_X + ((idx) << 2) + (comp))666667#define BRW_PARAM_BUILTIN_IS_CLIP_PLANE(param) \668((param) >= BRW_PARAM_BUILTIN_CLIP_PLANE_0_X && \669(param) <= BRW_PARAM_BUILTIN_CLIP_PLANE_7_W)670671#define BRW_PARAM_BUILTIN_CLIP_PLANE_IDX(param) \672(((param) - BRW_PARAM_BUILTIN_CLIP_PLANE_0_X) >> 2)673674#define BRW_PARAM_BUILTIN_CLIP_PLANE_COMP(param) \675(((param) - BRW_PARAM_BUILTIN_CLIP_PLANE_0_X) & 0x3)676677enum brw_shader_reloc_id {678BRW_SHADER_RELOC_CONST_DATA_ADDR_LOW,679BRW_SHADER_RELOC_CONST_DATA_ADDR_HIGH,680BRW_SHADER_RELOC_SHADER_START_OFFSET,681BRW_SHADER_RELOC_RESUME_SBT_ADDR_LOW,682BRW_SHADER_RELOC_RESUME_SBT_ADDR_HIGH,683};684685enum brw_shader_reloc_type {686/** An arbitrary 32-bit value */687BRW_SHADER_RELOC_TYPE_U32,688/** A MOV instruction with an immediate source */689BRW_SHADER_RELOC_TYPE_MOV_IMM,690};691692/** Represents a code relocation693*694* Relocatable constants are immediates in the code which we want to be able695* to replace post-compile with the actual value.696*/697struct brw_shader_reloc {698/** The 32-bit ID of the relocatable constant */699uint32_t id;700701/** Type of this relocation */702enum brw_shader_reloc_type type;703704/** The offset in the shader to the relocated value705*706* For MOV_IMM relocs, this is an offset to the MOV instruction. This707* allows us to do some sanity checking while we update the value.708*/709uint32_t offset;710711/** Value to be added to the relocated value before it is written */712uint32_t delta;713};714715/** A value to write to a relocation */716struct brw_shader_reloc_value {717/** The 32-bit ID of the relocatable constant */718uint32_t id;719720/** The value with which to replace the relocated immediate */721uint32_t value;722};723724struct brw_stage_prog_data {725struct {726/** size of our binding table. */727uint32_t size_bytes;728729/** @{730* surface indices for the various groups of surfaces731*/732uint32_t pull_constants_start;733uint32_t texture_start;734uint32_t gather_texture_start;735uint32_t ubo_start;736uint32_t ssbo_start;737uint32_t image_start;738uint32_t shader_time_start;739uint32_t plane_start[3];740/** @} */741} binding_table;742743struct brw_ubo_range ubo_ranges[4];744745GLuint nr_params; /**< number of float params/constants */746GLuint nr_pull_params;747748gl_shader_stage stage;749750/* zero_push_reg is a bitfield which indicates what push registers (if any)751* should be zeroed by SW at the start of the shader. The corresponding752* push_reg_mask_param specifies the param index (in 32-bit units) where753* the actual runtime 64-bit mask will be pushed. The shader will zero754* push reg i if755*756* reg_used & zero_push_reg & ~*push_reg_mask_param & (1ull << i)757*758* If this field is set, brw_compiler::compact_params must be false.759*/760uint64_t zero_push_reg;761unsigned push_reg_mask_param;762763unsigned curb_read_length;764unsigned total_scratch;765unsigned total_shared;766767unsigned program_size;768769unsigned const_data_size;770unsigned const_data_offset;771772unsigned num_relocs;773const struct brw_shader_reloc *relocs;774775/** Does this program pull from any UBO or other constant buffers? */776bool has_ubo_pull;777778/**779* Register where the thread expects to find input data from the URB780* (typically uniforms, followed by vertex or fragment attributes).781*/782unsigned dispatch_grf_start_reg;783784bool use_alt_mode; /**< Use ALT floating point mode? Otherwise, IEEE. */785786/* 32-bit identifiers for all push/pull parameters. These can be anything787* the driver wishes them to be; the core of the back-end compiler simply788* re-arranges them. The one restriction is that the bottom 2^16 values789* are reserved for builtins defined in the brw_param_builtin enum defined790* above.791*/792uint32_t *param;793uint32_t *pull_param;794795/* Whether shader uses atomic operations. */796bool uses_atomic_load_store;797};798799static inline uint32_t *800brw_stage_prog_data_add_params(struct brw_stage_prog_data *prog_data,801unsigned nr_new_params)802{803unsigned old_nr_params = prog_data->nr_params;804prog_data->nr_params += nr_new_params;805prog_data->param = reralloc(ralloc_parent(prog_data->param),806prog_data->param, uint32_t,807prog_data->nr_params);808return prog_data->param + old_nr_params;809}810811enum brw_barycentric_mode {812BRW_BARYCENTRIC_PERSPECTIVE_PIXEL = 0,813BRW_BARYCENTRIC_PERSPECTIVE_CENTROID = 1,814BRW_BARYCENTRIC_PERSPECTIVE_SAMPLE = 2,815BRW_BARYCENTRIC_NONPERSPECTIVE_PIXEL = 3,816BRW_BARYCENTRIC_NONPERSPECTIVE_CENTROID = 4,817BRW_BARYCENTRIC_NONPERSPECTIVE_SAMPLE = 5,818BRW_BARYCENTRIC_MODE_COUNT = 6819};820#define BRW_BARYCENTRIC_NONPERSPECTIVE_BITS \821((1 << BRW_BARYCENTRIC_NONPERSPECTIVE_PIXEL) | \822(1 << BRW_BARYCENTRIC_NONPERSPECTIVE_CENTROID) | \823(1 << BRW_BARYCENTRIC_NONPERSPECTIVE_SAMPLE))824825enum brw_pixel_shader_computed_depth_mode {826BRW_PSCDEPTH_OFF = 0, /* PS does not compute depth */827BRW_PSCDEPTH_ON = 1, /* PS computes depth; no guarantee about value */828BRW_PSCDEPTH_ON_GE = 2, /* PS guarantees output depth >= source depth */829BRW_PSCDEPTH_ON_LE = 3, /* PS guarantees output depth <= source depth */830};831832/* Data about a particular attempt to compile a program. Note that833* there can be many of these, each in a different GL state834* corresponding to a different brw_wm_prog_key struct, with different835* compiled programs.836*/837struct brw_wm_prog_data {838struct brw_stage_prog_data base;839840GLuint num_varying_inputs;841842uint8_t reg_blocks_8;843uint8_t reg_blocks_16;844uint8_t reg_blocks_32;845846uint8_t dispatch_grf_start_reg_16;847uint8_t dispatch_grf_start_reg_32;848uint32_t prog_offset_16;849uint32_t prog_offset_32;850851struct {852/** @{853* surface indices the WM-specific surfaces854*/855uint32_t render_target_read_start;856/** @} */857} binding_table;858859uint8_t computed_depth_mode;860bool computed_stencil;861862bool early_fragment_tests;863bool post_depth_coverage;864bool inner_coverage;865bool dispatch_8;866bool dispatch_16;867bool dispatch_32;868bool dual_src_blend;869bool persample_dispatch;870bool uses_pos_offset;871bool uses_omask;872bool uses_kill;873bool uses_src_depth;874bool uses_src_w;875bool uses_depth_w_coefficients;876bool uses_sample_mask;877bool has_render_target_reads;878bool has_side_effects;879bool pulls_bary;880881bool contains_flat_varying;882bool contains_noperspective_varying;883884/**885* Shader is ran at the coarse pixel shading dispatch rate (3DSTATE_CPS).886*/887bool per_coarse_pixel_dispatch;888889/**890* Mask of which interpolation modes are required by the fragment shader.891* Used in hardware setup on gfx6+.892*/893uint32_t barycentric_interp_modes;894895/**896* Mask of which FS inputs are marked flat by the shader source. This is897* needed for setting up 3DSTATE_SF/SBE.898*/899uint32_t flat_inputs;900901/**902* The FS inputs903*/904uint64_t inputs;905906/* Mapping of VUE slots to interpolation modes.907* Used by the Gfx4-5 clip/sf/wm stages.908*/909unsigned char interp_mode[65]; /* BRW_VARYING_SLOT_COUNT */910911/**912* Map from gl_varying_slot to the position within the FS setup data913* payload where the varying's attribute vertex deltas should be delivered.914* For varying slots that are not used by the FS, the value is -1.915*/916int urb_setup[VARYING_SLOT_MAX];917918/**919* Cache structure into the urb_setup array above that contains the920* attribute numbers of active varyings out of urb_setup.921* The actual count is stored in urb_setup_attribs_count.922*/923uint8_t urb_setup_attribs[VARYING_SLOT_MAX];924uint8_t urb_setup_attribs_count;925};926927/** Returns the SIMD width corresponding to a given KSP index928*929* The "Variable Pixel Dispatch" table in the PRM (which can be found, for930* example in Vol. 7 of the SKL PRM) has a mapping from dispatch widths to931* kernel start pointer (KSP) indices that is based on what dispatch widths932* are enabled. This function provides, effectively, the reverse mapping.933*934* If the given KSP is valid with respect to the SIMD8/16/32 enables, a SIMD935* width of 8, 16, or 32 is returned. If the KSP is invalid, 0 is returned.936*/937static inline unsigned938brw_fs_simd_width_for_ksp(unsigned ksp_idx, bool simd8_enabled,939bool simd16_enabled, bool simd32_enabled)940{941/* This function strictly ignores contiguous dispatch */942switch (ksp_idx) {943case 0:944return simd8_enabled ? 8 :945(simd16_enabled && !simd32_enabled) ? 16 :946(simd32_enabled && !simd16_enabled) ? 32 : 0;947case 1:948return (simd32_enabled && (simd16_enabled || simd8_enabled)) ? 32 : 0;949case 2:950return (simd16_enabled && (simd32_enabled || simd8_enabled)) ? 16 : 0;951default:952unreachable("Invalid KSP index");953}954}955956#define brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx) \957brw_fs_simd_width_for_ksp((ksp_idx), (wm_state)._8PixelDispatchEnable, \958(wm_state)._16PixelDispatchEnable, \959(wm_state)._32PixelDispatchEnable)960961#define brw_wm_state_has_ksp(wm_state, ksp_idx) \962(brw_wm_state_simd_width_for_ksp((wm_state), (ksp_idx)) != 0)963964static inline uint32_t965_brw_wm_prog_data_prog_offset(const struct brw_wm_prog_data *prog_data,966unsigned simd_width)967{968switch (simd_width) {969case 8: return 0;970case 16: return prog_data->prog_offset_16;971case 32: return prog_data->prog_offset_32;972default: return 0;973}974}975976#define brw_wm_prog_data_prog_offset(prog_data, wm_state, ksp_idx) \977_brw_wm_prog_data_prog_offset(prog_data, \978brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))979980static inline uint8_t981_brw_wm_prog_data_dispatch_grf_start_reg(const struct brw_wm_prog_data *prog_data,982unsigned simd_width)983{984switch (simd_width) {985case 8: return prog_data->base.dispatch_grf_start_reg;986case 16: return prog_data->dispatch_grf_start_reg_16;987case 32: return prog_data->dispatch_grf_start_reg_32;988default: return 0;989}990}991992#define brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm_state, ksp_idx) \993_brw_wm_prog_data_dispatch_grf_start_reg(prog_data, \994brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))995996static inline uint8_t997_brw_wm_prog_data_reg_blocks(const struct brw_wm_prog_data *prog_data,998unsigned simd_width)999{1000switch (simd_width) {1001case 8: return prog_data->reg_blocks_8;1002case 16: return prog_data->reg_blocks_16;1003case 32: return prog_data->reg_blocks_32;1004default: return 0;1005}1006}10071008#define brw_wm_prog_data_reg_blocks(prog_data, wm_state, ksp_idx) \1009_brw_wm_prog_data_reg_blocks(prog_data, \1010brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))10111012struct brw_push_const_block {1013unsigned dwords; /* Dword count, not reg aligned */1014unsigned regs;1015unsigned size; /* Bytes, register aligned */1016};10171018struct brw_cs_prog_data {1019struct brw_stage_prog_data base;10201021unsigned local_size[3];10221023/* Program offsets for the 8/16/32 SIMD variants. Multiple variants are1024* kept when using variable group size, and the right one can only be1025* decided at dispatch time.1026*/1027unsigned prog_offset[3];10281029/* Bitmask indicating which program offsets are valid. */1030unsigned prog_mask;10311032/* Bitmask indicating which programs have spilled. */1033unsigned prog_spilled;10341035bool uses_barrier;1036bool uses_num_work_groups;1037bool uses_inline_data;1038bool uses_btd_stack_ids;10391040struct {1041struct brw_push_const_block cross_thread;1042struct brw_push_const_block per_thread;1043} push;10441045struct {1046/** @{1047* surface indices the CS-specific surfaces1048*/1049uint32_t work_groups_start;1050/** @} */1051} binding_table;1052};10531054static inline uint32_t1055brw_cs_prog_data_prog_offset(const struct brw_cs_prog_data *prog_data,1056unsigned dispatch_width)1057{1058assert(dispatch_width == 8 ||1059dispatch_width == 16 ||1060dispatch_width == 32);1061const unsigned index = dispatch_width / 16;1062assert(prog_data->prog_mask & (1 << index));1063return prog_data->prog_offset[index];1064}10651066struct brw_bs_prog_data {1067struct brw_stage_prog_data base;10681069/** SIMD size of the root shader */1070uint8_t simd_size;10711072/** Maximum stack size of all shaders */1073uint32_t max_stack_size;10741075/** Offset into the shader where the resume SBT is located */1076uint32_t resume_sbt_offset;1077};10781079struct brw_ff_gs_prog_data {1080unsigned urb_read_length;1081unsigned total_grf;10821083/**1084* Gfx6 transform feedback: Amount by which the streaming vertex buffer1085* indices should be incremented each time the GS is invoked.1086*/1087unsigned svbi_postincrement_value;1088};10891090/**1091* Enum representing the i965-specific vertex results that don't correspond1092* exactly to any element of gl_varying_slot. The values of this enum are1093* assigned such that they don't conflict with gl_varying_slot.1094*/1095typedef enum1096{1097BRW_VARYING_SLOT_NDC = VARYING_SLOT_MAX,1098BRW_VARYING_SLOT_PAD,1099/**1100* Technically this is not a varying but just a placeholder that1101* compile_sf_prog() inserts into its VUE map to cause the gl_PointCoord1102* builtin variable to be compiled correctly. see compile_sf_prog() for1103* more info.1104*/1105BRW_VARYING_SLOT_PNTC,1106BRW_VARYING_SLOT_COUNT1107} brw_varying_slot;11081109/**1110* We always program SF to start reading at an offset of 1 (2 varying slots)1111* from the start of the vertex URB entry. This causes it to skip:1112* - VARYING_SLOT_PSIZ and BRW_VARYING_SLOT_NDC on gfx4-51113* - VARYING_SLOT_PSIZ and VARYING_SLOT_POS on gfx6+1114*/1115#define BRW_SF_URB_ENTRY_READ_OFFSET 111161117/**1118* Bitmask indicating which fragment shader inputs represent varyings (and1119* hence have to be delivered to the fragment shader by the SF/SBE stage).1120*/1121#define BRW_FS_VARYING_INPUT_MASK \1122(BITFIELD64_RANGE(0, VARYING_SLOT_MAX) & \1123~VARYING_BIT_POS & ~VARYING_BIT_FACE)11241125/**1126* Data structure recording the relationship between the gl_varying_slot enum1127* and "slots" within the vertex URB entry (VUE). A "slot" is defined as a1128* single octaword within the VUE (128 bits).1129*1130* Note that each BRW register contains 256 bits (2 octawords), so when1131* accessing the VUE in URB_NOSWIZZLE mode, each register corresponds to two1132* consecutive VUE slots. When accessing the VUE in URB_INTERLEAVED mode (as1133* in a vertex shader), each register corresponds to a single VUE slot, since1134* it contains data for two separate vertices.1135*/1136struct brw_vue_map {1137/**1138* Bitfield representing all varying slots that are (a) stored in this VUE1139* map, and (b) actually written by the shader. Does not include any of1140* the additional varying slots defined in brw_varying_slot.1141*/1142uint64_t slots_valid;11431144/**1145* Is this VUE map for a separate shader pipeline?1146*1147* Separable programs (GL_ARB_separate_shader_objects) can be mixed and matched1148* without the linker having a chance to dead code eliminate unused varyings.1149*1150* This means that we have to use a fixed slot layout, based on the output's1151* location field, rather than assigning slots in a compact contiguous block.1152*/1153bool separate;11541155/**1156* Map from gl_varying_slot value to VUE slot. For gl_varying_slots that are1157* not stored in a slot (because they are not written, or because1158* additional processing is applied before storing them in the VUE), the1159* value is -1.1160*/1161signed char varying_to_slot[VARYING_SLOT_TESS_MAX];11621163/**1164* Map from VUE slot to gl_varying_slot value. For slots that do not1165* directly correspond to a gl_varying_slot, the value comes from1166* brw_varying_slot.1167*1168* For slots that are not in use, the value is BRW_VARYING_SLOT_PAD.1169*/1170signed char slot_to_varying[VARYING_SLOT_TESS_MAX];11711172/**1173* Total number of VUE slots in use1174*/1175int num_slots;11761177/**1178* Number of per-patch VUE slots. Only valid for tessellation control1179* shader outputs and tessellation evaluation shader inputs.1180*/1181int num_per_patch_slots;11821183/**1184* Number of per-vertex VUE slots. Only valid for tessellation control1185* shader outputs and tessellation evaluation shader inputs.1186*/1187int num_per_vertex_slots;1188};11891190void brw_print_vue_map(FILE *fp, const struct brw_vue_map *vue_map,1191gl_shader_stage stage);11921193/**1194* Convert a VUE slot number into a byte offset within the VUE.1195*/1196static inline GLuint brw_vue_slot_to_offset(GLuint slot)1197{1198return 16*slot;1199}12001201/**1202* Convert a vertex output (brw_varying_slot) into a byte offset within the1203* VUE.1204*/1205static inline1206GLuint brw_varying_to_offset(const struct brw_vue_map *vue_map, GLuint varying)1207{1208return brw_vue_slot_to_offset(vue_map->varying_to_slot[varying]);1209}12101211void brw_compute_vue_map(const struct intel_device_info *devinfo,1212struct brw_vue_map *vue_map,1213uint64_t slots_valid,1214bool separate_shader,1215uint32_t pos_slots);12161217void brw_compute_tess_vue_map(struct brw_vue_map *const vue_map,1218uint64_t slots_valid,1219uint32_t is_patch);12201221/* brw_interpolation_map.c */1222void brw_setup_vue_interpolation(const struct brw_vue_map *vue_map,1223struct nir_shader *nir,1224struct brw_wm_prog_data *prog_data);12251226enum shader_dispatch_mode {1227DISPATCH_MODE_4X1_SINGLE = 0,1228DISPATCH_MODE_4X2_DUAL_INSTANCE = 1,1229DISPATCH_MODE_4X2_DUAL_OBJECT = 2,1230DISPATCH_MODE_SIMD8 = 3,12311232DISPATCH_MODE_TCS_SINGLE_PATCH = 0,1233DISPATCH_MODE_TCS_8_PATCH = 2,1234};12351236/**1237* @defgroup Tessellator parameter enumerations.1238*1239* These correspond to the hardware values in 3DSTATE_TE, and are provided1240* as part of the tessellation evaluation shader.1241*1242* @{1243*/1244enum brw_tess_partitioning {1245BRW_TESS_PARTITIONING_INTEGER = 0,1246BRW_TESS_PARTITIONING_ODD_FRACTIONAL = 1,1247BRW_TESS_PARTITIONING_EVEN_FRACTIONAL = 2,1248};12491250enum brw_tess_output_topology {1251BRW_TESS_OUTPUT_TOPOLOGY_POINT = 0,1252BRW_TESS_OUTPUT_TOPOLOGY_LINE = 1,1253BRW_TESS_OUTPUT_TOPOLOGY_TRI_CW = 2,1254BRW_TESS_OUTPUT_TOPOLOGY_TRI_CCW = 3,1255};12561257enum brw_tess_domain {1258BRW_TESS_DOMAIN_QUAD = 0,1259BRW_TESS_DOMAIN_TRI = 1,1260BRW_TESS_DOMAIN_ISOLINE = 2,1261};1262/** @} */12631264struct brw_vue_prog_data {1265struct brw_stage_prog_data base;1266struct brw_vue_map vue_map;12671268/** Should the hardware deliver input VUE handles for URB pull loads? */1269bool include_vue_handles;12701271GLuint urb_read_length;1272GLuint total_grf;12731274uint32_t clip_distance_mask;1275uint32_t cull_distance_mask;12761277/* Used for calculating urb partitions. In the VS, this is the size of the1278* URB entry used for both input and output to the thread. In the GS, this1279* is the size of the URB entry used for output.1280*/1281GLuint urb_entry_size;12821283enum shader_dispatch_mode dispatch_mode;1284};12851286struct brw_vs_prog_data {1287struct brw_vue_prog_data base;12881289GLbitfield64 inputs_read;1290GLbitfield64 double_inputs_read;12911292unsigned nr_attribute_slots;12931294bool uses_vertexid;1295bool uses_instanceid;1296bool uses_is_indexed_draw;1297bool uses_firstvertex;1298bool uses_baseinstance;1299bool uses_drawid;1300};13011302struct brw_tcs_prog_data1303{1304struct brw_vue_prog_data base;13051306/** Should the non-SINGLE_PATCH payload provide primitive ID? */1307bool include_primitive_id;13081309/** Number vertices in output patch */1310int instances;13111312/** Track patch count threshold */1313int patch_count_threshold;1314};131513161317struct brw_tes_prog_data1318{1319struct brw_vue_prog_data base;13201321enum brw_tess_partitioning partitioning;1322enum brw_tess_output_topology output_topology;1323enum brw_tess_domain domain;1324};13251326struct brw_gs_prog_data1327{1328struct brw_vue_prog_data base;13291330unsigned vertices_in;13311332/**1333* Size of an output vertex, measured in HWORDS (32 bytes).1334*/1335unsigned output_vertex_size_hwords;13361337unsigned output_topology;13381339/**1340* Size of the control data (cut bits or StreamID bits), in hwords (321341* bytes). 0 if there is no control data.1342*/1343unsigned control_data_header_size_hwords;13441345/**1346* Format of the control data (either GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_SID1347* if the control data is StreamID bits, or1348* GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT if the control data is cut bits).1349* Ignored if control_data_header_size is 0.1350*/1351unsigned control_data_format;13521353bool include_primitive_id;13541355/**1356* The number of vertices emitted, if constant - otherwise -1.1357*/1358int static_vertex_count;13591360int invocations;13611362/**1363* Gfx6: Provoking vertex convention for odd-numbered triangles1364* in tristrips.1365*/1366GLuint pv_first:1;13671368/**1369* Gfx6: Number of varyings that are output to transform feedback.1370*/1371GLuint num_transform_feedback_bindings:7; /* 0-BRW_MAX_SOL_BINDINGS */13721373/**1374* Gfx6: Map from the index of a transform feedback binding table entry to the1375* gl_varying_slot that should be streamed out through that binding table1376* entry.1377*/1378unsigned char transform_feedback_bindings[64 /* BRW_MAX_SOL_BINDINGS */];13791380/**1381* Gfx6: Map from the index of a transform feedback binding table entry to the1382* swizzles that should be used when streaming out data through that1383* binding table entry.1384*/1385unsigned char transform_feedback_swizzles[64 /* BRW_MAX_SOL_BINDINGS */];1386};13871388struct brw_sf_prog_data {1389uint32_t urb_read_length;1390uint32_t total_grf;13911392/* Each vertex may have upto 12 attributes, 4 components each,1393* except WPOS which requires only 2. (11*4 + 2) == 44 ==> 111394* rows.1395*1396* Actually we use 4 for each, so call it 12 rows.1397*/1398unsigned urb_entry_size;1399};14001401struct brw_clip_prog_data {1402uint32_t curb_read_length; /* user planes? */1403uint32_t clip_mode;1404uint32_t urb_read_length;1405uint32_t total_grf;1406};14071408/* brw_any_prog_data is prog_data for any stage that maps to an API stage */1409union brw_any_prog_data {1410struct brw_stage_prog_data base;1411struct brw_vue_prog_data vue;1412struct brw_vs_prog_data vs;1413struct brw_tcs_prog_data tcs;1414struct brw_tes_prog_data tes;1415struct brw_gs_prog_data gs;1416struct brw_wm_prog_data wm;1417struct brw_cs_prog_data cs;1418struct brw_bs_prog_data bs;1419};14201421#define DEFINE_PROG_DATA_DOWNCAST(STAGE, CHECK) \1422static inline struct brw_##STAGE##_prog_data * \1423brw_##STAGE##_prog_data(struct brw_stage_prog_data *prog_data) \1424{ \1425if (prog_data) \1426assert(CHECK); \1427return (struct brw_##STAGE##_prog_data *) prog_data; \1428} \1429static inline const struct brw_##STAGE##_prog_data * \1430brw_##STAGE##_prog_data_const(const struct brw_stage_prog_data *prog_data) \1431{ \1432if (prog_data) \1433assert(CHECK); \1434return (const struct brw_##STAGE##_prog_data *) prog_data; \1435}14361437DEFINE_PROG_DATA_DOWNCAST(vs, prog_data->stage == MESA_SHADER_VERTEX)1438DEFINE_PROG_DATA_DOWNCAST(tcs, prog_data->stage == MESA_SHADER_TESS_CTRL)1439DEFINE_PROG_DATA_DOWNCAST(tes, prog_data->stage == MESA_SHADER_TESS_EVAL)1440DEFINE_PROG_DATA_DOWNCAST(gs, prog_data->stage == MESA_SHADER_GEOMETRY)1441DEFINE_PROG_DATA_DOWNCAST(wm, prog_data->stage == MESA_SHADER_FRAGMENT)1442DEFINE_PROG_DATA_DOWNCAST(cs, prog_data->stage == MESA_SHADER_COMPUTE)1443DEFINE_PROG_DATA_DOWNCAST(bs, brw_shader_stage_is_bindless(prog_data->stage))14441445DEFINE_PROG_DATA_DOWNCAST(vue, prog_data->stage == MESA_SHADER_VERTEX ||1446prog_data->stage == MESA_SHADER_TESS_CTRL ||1447prog_data->stage == MESA_SHADER_TESS_EVAL ||1448prog_data->stage == MESA_SHADER_GEOMETRY)14491450/* These are not really brw_stage_prog_data. */1451DEFINE_PROG_DATA_DOWNCAST(ff_gs, true)1452DEFINE_PROG_DATA_DOWNCAST(clip, true)1453DEFINE_PROG_DATA_DOWNCAST(sf, true)1454#undef DEFINE_PROG_DATA_DOWNCAST14551456struct brw_compile_stats {1457uint32_t dispatch_width; /**< 0 for vec4 */1458uint32_t instructions;1459uint32_t sends;1460uint32_t loops;1461uint32_t cycles;1462uint32_t spills;1463uint32_t fills;1464};14651466/** @} */14671468struct brw_compiler *1469brw_compiler_create(void *mem_ctx, const struct intel_device_info *devinfo);14701471/**1472* Returns a compiler configuration for use with disk shader cache1473*1474* This value only needs to change for settings that can cause different1475* program generation between two runs on the same hardware.1476*1477* For example, it doesn't need to be different for gen 8 and gen 9 hardware,1478* but it does need to be different if INTEL_DEBUG=nocompact is or isn't used.1479*/1480uint64_t1481brw_get_compiler_config_value(const struct brw_compiler *compiler);14821483unsigned1484brw_prog_data_size(gl_shader_stage stage);14851486unsigned1487brw_prog_key_size(gl_shader_stage stage);14881489void1490brw_prog_key_set_id(union brw_any_prog_key *key, gl_shader_stage, unsigned id);14911492/**1493* Parameters for compiling a vertex shader.1494*1495* Some of these will be modified during the shader compilation.1496*/1497struct brw_compile_vs_params {1498nir_shader *nir;14991500const struct brw_vs_prog_key *key;1501struct brw_vs_prog_data *prog_data;15021503bool edgeflag_is_last; /* true for gallium */1504bool shader_time;1505int shader_time_index;15061507struct brw_compile_stats *stats;15081509void *log_data;15101511char *error_str;15121513/* If unset, DEBUG_VS is used. */1514uint64_t debug_flag;1515};15161517/**1518* Compile a vertex shader.1519*1520* Returns the final assembly and updates the parameters structure.1521*/1522const unsigned *1523brw_compile_vs(const struct brw_compiler *compiler,1524void *mem_ctx,1525struct brw_compile_vs_params *params);15261527/**1528* Compile a tessellation control shader.1529*1530* Returns the final assembly and the program's size.1531*/1532const unsigned *1533brw_compile_tcs(const struct brw_compiler *compiler,1534void *log_data,1535void *mem_ctx,1536const struct brw_tcs_prog_key *key,1537struct brw_tcs_prog_data *prog_data,1538nir_shader *nir,1539int shader_time_index,1540struct brw_compile_stats *stats,1541char **error_str);15421543/**1544* Compile a tessellation evaluation shader.1545*1546* Returns the final assembly and the program's size.1547*/1548const unsigned *1549brw_compile_tes(const struct brw_compiler *compiler, void *log_data,1550void *mem_ctx,1551const struct brw_tes_prog_key *key,1552const struct brw_vue_map *input_vue_map,1553struct brw_tes_prog_data *prog_data,1554nir_shader *nir,1555int shader_time_index,1556struct brw_compile_stats *stats,1557char **error_str);15581559/**1560* Compile a vertex shader.1561*1562* Returns the final assembly and the program's size.1563*/1564const unsigned *1565brw_compile_gs(const struct brw_compiler *compiler, void *log_data,1566void *mem_ctx,1567const struct brw_gs_prog_key *key,1568struct brw_gs_prog_data *prog_data,1569nir_shader *nir,1570int shader_time_index,1571struct brw_compile_stats *stats,1572char **error_str);15731574/**1575* Compile a strips and fans shader.1576*1577* This is a fixed-function shader determined entirely by the shader key and1578* a VUE map.1579*1580* Returns the final assembly and the program's size.1581*/1582const unsigned *1583brw_compile_sf(const struct brw_compiler *compiler,1584void *mem_ctx,1585const struct brw_sf_prog_key *key,1586struct brw_sf_prog_data *prog_data,1587struct brw_vue_map *vue_map,1588unsigned *final_assembly_size);15891590/**1591* Compile a clipper shader.1592*1593* This is a fixed-function shader determined entirely by the shader key and1594* a VUE map.1595*1596* Returns the final assembly and the program's size.1597*/1598const unsigned *1599brw_compile_clip(const struct brw_compiler *compiler,1600void *mem_ctx,1601const struct brw_clip_prog_key *key,1602struct brw_clip_prog_data *prog_data,1603struct brw_vue_map *vue_map,1604unsigned *final_assembly_size);16051606/**1607* Parameters for compiling a fragment shader.1608*1609* Some of these will be modified during the shader compilation.1610*/1611struct brw_compile_fs_params {1612nir_shader *nir;16131614const struct brw_wm_prog_key *key;1615struct brw_wm_prog_data *prog_data;1616const struct brw_vue_map *vue_map;16171618bool shader_time;1619int shader_time_index8;1620int shader_time_index16;1621int shader_time_index32;16221623bool allow_spilling;1624bool use_rep_send;16251626struct brw_compile_stats *stats;16271628void *log_data;16291630char *error_str;16311632/* If unset, DEBUG_WM is used. */1633uint64_t debug_flag;1634};16351636/**1637* Compile a fragment shader.1638*1639* Returns the final assembly and updates the parameters structure.1640*/1641const unsigned *1642brw_compile_fs(const struct brw_compiler *compiler,1643void *mem_ctx,1644struct brw_compile_fs_params *params);16451646/**1647* Parameters for compiling a compute shader.1648*1649* Some of these will be modified during the shader compilation.1650*/1651struct brw_compile_cs_params {1652nir_shader *nir;16531654const struct brw_cs_prog_key *key;1655struct brw_cs_prog_data *prog_data;16561657bool shader_time;1658int shader_time_index;16591660struct brw_compile_stats *stats;16611662void *log_data;16631664char *error_str;1665};16661667/**1668* Compile a compute shader.1669*1670* Returns the final assembly and updates the parameters structure.1671*/1672const unsigned *1673brw_compile_cs(const struct brw_compiler *compiler,1674void *mem_ctx,1675struct brw_compile_cs_params *params);16761677/**1678* Compile a Ray Tracing shader.1679*1680* Returns the final assembly and the program's size.1681*/1682const unsigned *1683brw_compile_bs(const struct brw_compiler *compiler, void *log_data,1684void *mem_ctx,1685const struct brw_bs_prog_key *key,1686struct brw_bs_prog_data *prog_data,1687struct nir_shader *shader,1688unsigned num_resume_shaders,1689struct nir_shader **resume_shaders,1690struct brw_compile_stats *stats,1691char **error_str);16921693/**1694* Compile a fixed function geometry shader.1695*1696* Returns the final assembly and the program's size.1697*/1698const unsigned *1699brw_compile_ff_gs_prog(struct brw_compiler *compiler,1700void *mem_ctx,1701const struct brw_ff_gs_prog_key *key,1702struct brw_ff_gs_prog_data *prog_data,1703struct brw_vue_map *vue_map,1704unsigned *final_assembly_size);17051706void brw_debug_key_recompile(const struct brw_compiler *c, void *log,1707gl_shader_stage stage,1708const struct brw_base_prog_key *old_key,1709const struct brw_base_prog_key *key);17101711/* Shared Local Memory Size is specified as powers of two,1712* and also have a Gen-dependent minimum value if not zero.1713*/1714static inline uint32_t1715intel_calculate_slm_size(unsigned gen, uint32_t bytes)1716{1717assert(bytes <= 64 * 1024);1718if (bytes > 0)1719return MAX2(util_next_power_of_two(bytes), gen >= 9 ? 1024 : 4096);1720else1721return 0;1722}17231724static inline uint32_t1725encode_slm_size(unsigned gen, uint32_t bytes)1726{1727uint32_t slm_size = 0;17281729/* Shared Local Memory is specified as powers of two, and encoded in1730* INTERFACE_DESCRIPTOR_DATA with the following representations:1731*1732* Size | 0 kB | 1 kB | 2 kB | 4 kB | 8 kB | 16 kB | 32 kB | 64 kB |1733* -------------------------------------------------------------------1734* Gfx7-8 | 0 | none | none | 1 | 2 | 4 | 8 | 16 |1735* -------------------------------------------------------------------1736* Gfx9+ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |1737*/17381739if (bytes > 0) {1740slm_size = intel_calculate_slm_size(gen, bytes);1741assert(util_is_power_of_two_nonzero(slm_size));17421743if (gen >= 9) {1744/* Turn an exponent of 10 (1024 kB) into 1. */1745assert(slm_size >= 1024);1746slm_size = ffs(slm_size) - 10;1747} else {1748assert(slm_size >= 4096);1749/* Convert to the pre-Gfx9 representation. */1750slm_size = slm_size / 4096;1751}1752}17531754return slm_size;1755}17561757unsigned1758brw_cs_push_const_total_size(const struct brw_cs_prog_data *cs_prog_data,1759unsigned threads);17601761void1762brw_write_shader_relocs(const struct intel_device_info *devinfo,1763void *program,1764const struct brw_stage_prog_data *prog_data,1765struct brw_shader_reloc_value *values,1766unsigned num_values);17671768struct brw_cs_dispatch_info {1769uint32_t group_size;1770uint32_t simd_size;1771uint32_t threads;17721773/* RightExecutionMask field used in GPGPU_WALKER. */1774uint32_t right_mask;1775};17761777/**1778* Get the dispatch information for a shader to be used with GPGPU_WALKER and1779* similar instructions.1780*1781* If override_local_size is not NULL, it must to point to a 3-element that1782* will override the value from prog_data->local_size. This is used by1783* ARB_compute_variable_group_size, where the size is set only at dispatch1784* time (so prog_data is outdated).1785*/1786struct brw_cs_dispatch_info1787brw_cs_get_dispatch_info(const struct intel_device_info *devinfo,1788const struct brw_cs_prog_data *prog_data,1789const unsigned *override_local_size);17901791/**1792* Return true if the given shader stage is dispatched contiguously by the1793* relevant fixed function starting from channel 0 of the SIMD thread, which1794* implies that the dispatch mask of a thread can be assumed to have the form1795* '2^n - 1' for some n.1796*/1797static inline bool1798brw_stage_has_packed_dispatch(ASSERTED const struct intel_device_info *devinfo,1799gl_shader_stage stage,1800const struct brw_stage_prog_data *prog_data)1801{1802/* The code below makes assumptions about the hardware's thread dispatch1803* behavior that could be proven wrong in future generations -- Make sure1804* to do a full test run with brw_fs_test_dispatch_packing() hooked up to1805* the NIR front-end before changing this assertion.1806*/1807assert(devinfo->ver <= 12);18081809switch (stage) {1810case MESA_SHADER_FRAGMENT: {1811/* The PSD discards subspans coming in with no lit samples, which in the1812* per-pixel shading case implies that each subspan will either be fully1813* lit (due to the VMask being used to allow derivative computations),1814* or not dispatched at all. In per-sample dispatch mode individual1815* samples from the same subspan have a fixed relative location within1816* the SIMD thread, so dispatch of unlit samples cannot be avoided in1817* general and we should return false.1818*/1819const struct brw_wm_prog_data *wm_prog_data =1820(const struct brw_wm_prog_data *)prog_data;1821return !wm_prog_data->persample_dispatch;1822}1823case MESA_SHADER_COMPUTE:1824/* Compute shaders will be spawned with either a fully enabled dispatch1825* mask or with whatever bottom/right execution mask was given to the1826* GPGPU walker command to be used along the workgroup edges -- In both1827* cases the dispatch mask is required to be tightly packed for our1828* invocation index calculations to work.1829*/1830return true;1831default:1832/* Most remaining fixed functions are limited to use a packed dispatch1833* mask due to the hardware representation of the dispatch mask as a1834* single counter representing the number of enabled channels.1835*/1836return true;1837}1838}18391840/**1841* Computes the first varying slot in the URB produced by the previous stage1842* that is used in the next stage. We do this by testing the varying slots in1843* the previous stage's vue map against the inputs read in the next stage.1844*1845* Note that:1846*1847* - Each URB offset contains two varying slots and we can only skip a1848* full offset if both slots are unused, so the value we return here is always1849* rounded down to the closest multiple of two.1850*1851* - gl_Layer and gl_ViewportIndex don't have their own varying slots, they are1852* part of the vue header, so if these are read we can't skip anything.1853*/1854static inline int1855brw_compute_first_urb_slot_required(uint64_t inputs_read,1856const struct brw_vue_map *prev_stage_vue_map)1857{1858if ((inputs_read & (VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT)) == 0) {1859for (int i = 0; i < prev_stage_vue_map->num_slots; i++) {1860int varying = prev_stage_vue_map->slot_to_varying[i];1861if (varying > 0 && (inputs_read & BITFIELD64_BIT(varying)) != 0)1862return ROUND_DOWN_TO(i, 2);1863}1864}18651866return 0;1867}18681869#ifdef __cplusplus1870} /* extern "C" */1871#endif18721873#endif /* BRW_COMPILER_H */187418751876