Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_context.h
4565 views
/*1* Copyright © 2017 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* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the 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 NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/22#ifndef IRIS_CONTEXT_H23#define IRIS_CONTEXT_H2425#include "pipe/p_context.h"26#include "pipe/p_state.h"27#include "util/set.h"28#include "util/slab.h"29#include "util/u_debug.h"30#include "util/u_threaded_context.h"31#include "intel/blorp/blorp.h"32#include "intel/dev/intel_debug.h"33#include "intel/common/intel_l3_config.h"34#include "intel/compiler/brw_compiler.h"35#include "iris_batch.h"36#include "iris_binder.h"37#include "iris_fence.h"38#include "iris_resource.h"39#include "iris_screen.h"4041struct iris_bo;42struct iris_context;43struct blorp_batch;44struct blorp_params;4546#define IRIS_MAX_TEXTURE_BUFFER_SIZE (1 << 27)47#define IRIS_MAX_TEXTURE_SAMPLERS 3248/* IRIS_MAX_ABOS and IRIS_MAX_SSBOS must be the same. */49#define IRIS_MAX_ABOS 1650#define IRIS_MAX_SSBOS 1651#define IRIS_MAX_VIEWPORTS 1652#define IRIS_MAX_CLIP_PLANES 853#define IRIS_MAX_GLOBAL_BINDINGS 325455enum iris_param_domain {56BRW_PARAM_DOMAIN_BUILTIN = 0,57BRW_PARAM_DOMAIN_IMAGE,58};5960enum {61DRI_CONF_BO_REUSE_DISABLED,62DRI_CONF_BO_REUSE_ALL63};6465#define BRW_PARAM(domain, val) (BRW_PARAM_DOMAIN_##domain << 24 | (val))66#define BRW_PARAM_DOMAIN(param) ((uint32_t)(param) >> 24)67#define BRW_PARAM_VALUE(param) ((uint32_t)(param) & 0x00ffffff)68#define BRW_PARAM_IMAGE(idx, offset) BRW_PARAM(IMAGE, ((idx) << 8) | (offset))69#define BRW_PARAM_IMAGE_IDX(value) (BRW_PARAM_VALUE(value) >> 8)70#define BRW_PARAM_IMAGE_OFFSET(value)(BRW_PARAM_VALUE(value) & 0xf)7172/**73* Dirty flags. When state changes, we flag some combination of these74* to indicate that particular GPU commands need to be re-emitted.75*76* Each bit typically corresponds to a single 3DSTATE_* command packet, but77* in rare cases they map to a group of related packets that need to be78* emitted together.79*80* See iris_upload_render_state().81*/82#define IRIS_DIRTY_COLOR_CALC_STATE (1ull << 0)83#define IRIS_DIRTY_POLYGON_STIPPLE (1ull << 1)84#define IRIS_DIRTY_SCISSOR_RECT (1ull << 2)85#define IRIS_DIRTY_WM_DEPTH_STENCIL (1ull << 3)86#define IRIS_DIRTY_CC_VIEWPORT (1ull << 4)87#define IRIS_DIRTY_SF_CL_VIEWPORT (1ull << 5)88#define IRIS_DIRTY_PS_BLEND (1ull << 6)89#define IRIS_DIRTY_BLEND_STATE (1ull << 7)90#define IRIS_DIRTY_RASTER (1ull << 8)91#define IRIS_DIRTY_CLIP (1ull << 9)92#define IRIS_DIRTY_SBE (1ull << 10)93#define IRIS_DIRTY_LINE_STIPPLE (1ull << 11)94#define IRIS_DIRTY_VERTEX_ELEMENTS (1ull << 12)95#define IRIS_DIRTY_MULTISAMPLE (1ull << 13)96#define IRIS_DIRTY_VERTEX_BUFFERS (1ull << 14)97#define IRIS_DIRTY_SAMPLE_MASK (1ull << 15)98#define IRIS_DIRTY_URB (1ull << 16)99#define IRIS_DIRTY_DEPTH_BUFFER (1ull << 17)100#define IRIS_DIRTY_WM (1ull << 18)101#define IRIS_DIRTY_SO_BUFFERS (1ull << 19)102#define IRIS_DIRTY_SO_DECL_LIST (1ull << 20)103#define IRIS_DIRTY_STREAMOUT (1ull << 21)104#define IRIS_DIRTY_VF_SGVS (1ull << 22)105#define IRIS_DIRTY_VF (1ull << 23)106#define IRIS_DIRTY_VF_TOPOLOGY (1ull << 24)107#define IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES (1ull << 25)108#define IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES (1ull << 26)109#define IRIS_DIRTY_VF_STATISTICS (1ull << 27)110#define IRIS_DIRTY_PMA_FIX (1ull << 28)111#define IRIS_DIRTY_DEPTH_BOUNDS (1ull << 29)112#define IRIS_DIRTY_RENDER_BUFFER (1ull << 30)113#define IRIS_DIRTY_STENCIL_REF (1ull << 31)114115#define IRIS_ALL_DIRTY_FOR_COMPUTE (IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES)116117#define IRIS_ALL_DIRTY_FOR_RENDER (~IRIS_ALL_DIRTY_FOR_COMPUTE)118119/**120* Per-stage dirty flags. When state changes, we flag some combination of121* these to indicate that particular GPU commands need to be re-emitted.122* Unlike the IRIS_DIRTY_* flags these are shader stage-specific and can be123* indexed by shifting the mask by the shader stage index.124*125* See iris_upload_render_state().126*/127#define IRIS_STAGE_DIRTY_SAMPLER_STATES_VS (1ull << 0)128#define IRIS_STAGE_DIRTY_SAMPLER_STATES_TCS (1ull << 1)129#define IRIS_STAGE_DIRTY_SAMPLER_STATES_TES (1ull << 2)130#define IRIS_STAGE_DIRTY_SAMPLER_STATES_GS (1ull << 3)131#define IRIS_STAGE_DIRTY_SAMPLER_STATES_PS (1ull << 4)132#define IRIS_STAGE_DIRTY_SAMPLER_STATES_CS (1ull << 5)133#define IRIS_STAGE_DIRTY_UNCOMPILED_VS (1ull << 6)134#define IRIS_STAGE_DIRTY_UNCOMPILED_TCS (1ull << 7)135#define IRIS_STAGE_DIRTY_UNCOMPILED_TES (1ull << 8)136#define IRIS_STAGE_DIRTY_UNCOMPILED_GS (1ull << 9)137#define IRIS_STAGE_DIRTY_UNCOMPILED_FS (1ull << 10)138#define IRIS_STAGE_DIRTY_UNCOMPILED_CS (1ull << 11)139#define IRIS_STAGE_DIRTY_VS (1ull << 12)140#define IRIS_STAGE_DIRTY_TCS (1ull << 13)141#define IRIS_STAGE_DIRTY_TES (1ull << 14)142#define IRIS_STAGE_DIRTY_GS (1ull << 15)143#define IRIS_STAGE_DIRTY_FS (1ull << 16)144#define IRIS_STAGE_DIRTY_CS (1ull << 17)145#define IRIS_SHIFT_FOR_STAGE_DIRTY_CONSTANTS 18146#define IRIS_STAGE_DIRTY_CONSTANTS_VS (1ull << 18)147#define IRIS_STAGE_DIRTY_CONSTANTS_TCS (1ull << 19)148#define IRIS_STAGE_DIRTY_CONSTANTS_TES (1ull << 20)149#define IRIS_STAGE_DIRTY_CONSTANTS_GS (1ull << 21)150#define IRIS_STAGE_DIRTY_CONSTANTS_FS (1ull << 22)151#define IRIS_STAGE_DIRTY_CONSTANTS_CS (1ull << 23)152#define IRIS_STAGE_DIRTY_BINDINGS_VS (1ull << 24)153#define IRIS_STAGE_DIRTY_BINDINGS_TCS (1ull << 25)154#define IRIS_STAGE_DIRTY_BINDINGS_TES (1ull << 26)155#define IRIS_STAGE_DIRTY_BINDINGS_GS (1ull << 27)156#define IRIS_STAGE_DIRTY_BINDINGS_FS (1ull << 28)157#define IRIS_STAGE_DIRTY_BINDINGS_CS (1ull << 29)158159#define IRIS_ALL_STAGE_DIRTY_FOR_COMPUTE (IRIS_STAGE_DIRTY_CS | \160IRIS_STAGE_DIRTY_SAMPLER_STATES_CS | \161IRIS_STAGE_DIRTY_UNCOMPILED_CS | \162IRIS_STAGE_DIRTY_CONSTANTS_CS | \163IRIS_STAGE_DIRTY_BINDINGS_CS)164165#define IRIS_ALL_STAGE_DIRTY_FOR_RENDER (~IRIS_ALL_STAGE_DIRTY_FOR_COMPUTE)166167#define IRIS_ALL_STAGE_DIRTY_BINDINGS_FOR_RENDER (IRIS_STAGE_DIRTY_BINDINGS_VS | \168IRIS_STAGE_DIRTY_BINDINGS_TCS | \169IRIS_STAGE_DIRTY_BINDINGS_TES | \170IRIS_STAGE_DIRTY_BINDINGS_GS | \171IRIS_STAGE_DIRTY_BINDINGS_FS)172173#define IRIS_ALL_STAGE_DIRTY_BINDINGS (IRIS_ALL_STAGE_DIRTY_BINDINGS_FOR_RENDER | \174IRIS_STAGE_DIRTY_BINDINGS_CS)175176/**177* Non-orthogonal state (NOS) dependency flags.178*179* Shader programs may depend on non-orthogonal state. These flags are180* used to indicate that a shader's key depends on the state provided by181* a certain Gallium CSO. Changing any CSOs marked as a dependency will182* cause the driver to re-compute the shader key, possibly triggering a183* shader recompile.184*/185enum iris_nos_dep {186IRIS_NOS_FRAMEBUFFER,187IRIS_NOS_DEPTH_STENCIL_ALPHA,188IRIS_NOS_RASTERIZER,189IRIS_NOS_BLEND,190IRIS_NOS_LAST_VUE_MAP,191192IRIS_NOS_COUNT,193};194195/** @{196*197* Program cache keys for state based recompiles.198*/199200struct iris_base_prog_key {201unsigned program_string_id;202};203204struct iris_vue_prog_key {205struct iris_base_prog_key base;206207unsigned nr_userclip_plane_consts:4;208};209210struct iris_vs_prog_key {211struct iris_vue_prog_key vue;212};213214struct iris_tcs_prog_key {215struct iris_vue_prog_key vue;216217uint16_t tes_primitive_mode;218219uint8_t input_vertices;220221bool quads_workaround;222223/** A bitfield of per-patch outputs written. */224uint32_t patch_outputs_written;225226/** A bitfield of per-vertex outputs written. */227uint64_t outputs_written;228};229230struct iris_tes_prog_key {231struct iris_vue_prog_key vue;232233/** A bitfield of per-patch inputs read. */234uint32_t patch_inputs_read;235236/** A bitfield of per-vertex inputs read. */237uint64_t inputs_read;238};239240struct iris_gs_prog_key {241struct iris_vue_prog_key vue;242};243244struct iris_fs_prog_key {245struct iris_base_prog_key base;246247unsigned nr_color_regions:5;248bool flat_shade:1;249bool alpha_test_replicate_alpha:1;250bool alpha_to_coverage:1;251bool clamp_fragment_color:1;252bool persample_interp:1;253bool multisample_fbo:1;254bool force_dual_color_blend:1;255bool coherent_fb_fetch:1;256257uint8_t color_outputs_valid;258uint64_t input_slots_valid;259};260261struct iris_cs_prog_key {262struct iris_base_prog_key base;263};264265union iris_any_prog_key {266struct iris_base_prog_key base;267struct iris_vue_prog_key vue;268struct iris_vs_prog_key vs;269struct iris_tcs_prog_key tcs;270struct iris_tes_prog_key tes;271struct iris_gs_prog_key gs;272struct iris_fs_prog_key fs;273struct iris_cs_prog_key cs;274};275276/** @} */277278struct iris_depth_stencil_alpha_state;279280/**281* Cache IDs for the in-memory program cache (ice->shaders.cache).282*/283enum iris_program_cache_id {284IRIS_CACHE_VS = MESA_SHADER_VERTEX,285IRIS_CACHE_TCS = MESA_SHADER_TESS_CTRL,286IRIS_CACHE_TES = MESA_SHADER_TESS_EVAL,287IRIS_CACHE_GS = MESA_SHADER_GEOMETRY,288IRIS_CACHE_FS = MESA_SHADER_FRAGMENT,289IRIS_CACHE_CS = MESA_SHADER_COMPUTE,290IRIS_CACHE_BLORP,291};292293/** @{294*295* Defines for PIPE_CONTROL operations, which trigger cache flushes,296* synchronization, pipelined memory writes, and so on.297*298* The bits here are not the actual hardware values. The actual fields299* move between various generations, so we just have flags for each300* potential operation, and use genxml to encode the actual packet.301*/302enum pipe_control_flags303{304PIPE_CONTROL_FLUSH_LLC = (1 << 1),305PIPE_CONTROL_LRI_POST_SYNC_OP = (1 << 2),306PIPE_CONTROL_STORE_DATA_INDEX = (1 << 3),307PIPE_CONTROL_CS_STALL = (1 << 4),308PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET = (1 << 5),309PIPE_CONTROL_SYNC_GFDT = (1 << 6),310PIPE_CONTROL_TLB_INVALIDATE = (1 << 7),311PIPE_CONTROL_MEDIA_STATE_CLEAR = (1 << 8),312PIPE_CONTROL_WRITE_IMMEDIATE = (1 << 9),313PIPE_CONTROL_WRITE_DEPTH_COUNT = (1 << 10),314PIPE_CONTROL_WRITE_TIMESTAMP = (1 << 11),315PIPE_CONTROL_DEPTH_STALL = (1 << 12),316PIPE_CONTROL_RENDER_TARGET_FLUSH = (1 << 13),317PIPE_CONTROL_INSTRUCTION_INVALIDATE = (1 << 14),318PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE = (1 << 15),319PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE = (1 << 16),320PIPE_CONTROL_NOTIFY_ENABLE = (1 << 17),321PIPE_CONTROL_FLUSH_ENABLE = (1 << 18),322PIPE_CONTROL_DATA_CACHE_FLUSH = (1 << 19),323PIPE_CONTROL_VF_CACHE_INVALIDATE = (1 << 20),324PIPE_CONTROL_CONST_CACHE_INVALIDATE = (1 << 21),325PIPE_CONTROL_STATE_CACHE_INVALIDATE = (1 << 22),326PIPE_CONTROL_STALL_AT_SCOREBOARD = (1 << 23),327PIPE_CONTROL_DEPTH_CACHE_FLUSH = (1 << 24),328PIPE_CONTROL_TILE_CACHE_FLUSH = (1 << 25),329PIPE_CONTROL_FLUSH_HDC = (1 << 26),330};331332#define PIPE_CONTROL_CACHE_FLUSH_BITS \333(PIPE_CONTROL_DEPTH_CACHE_FLUSH | \334PIPE_CONTROL_DATA_CACHE_FLUSH | \335PIPE_CONTROL_TILE_CACHE_FLUSH | \336PIPE_CONTROL_RENDER_TARGET_FLUSH)337338#define PIPE_CONTROL_CACHE_INVALIDATE_BITS \339(PIPE_CONTROL_STATE_CACHE_INVALIDATE | \340PIPE_CONTROL_CONST_CACHE_INVALIDATE | \341PIPE_CONTROL_VF_CACHE_INVALIDATE | \342PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | \343PIPE_CONTROL_INSTRUCTION_INVALIDATE)344345enum iris_predicate_state {346/* The first two states are used if we can determine whether to draw347* without having to look at the values in the query object buffer. This348* will happen if there is no conditional render in progress, if the query349* object is already completed or if something else has already added350* samples to the preliminary result.351*/352IRIS_PREDICATE_STATE_RENDER,353IRIS_PREDICATE_STATE_DONT_RENDER,354355/* In this case whether to draw or not depends on the result of an356* MI_PREDICATE command so the predicate enable bit needs to be checked.357*/358IRIS_PREDICATE_STATE_USE_BIT,359};360361/** @} */362363/**364* An uncompiled, API-facing shader. This is the Gallium CSO for shaders.365* It primarily contains the NIR for the shader.366*367* Each API-facing shader can be compiled into multiple shader variants,368* based on non-orthogonal state dependencies, recorded in the shader key.369*370* See iris_compiled_shader, which represents a compiled shader variant.371*/372struct iris_uncompiled_shader {373struct nir_shader *nir;374375struct pipe_stream_output_info stream_output;376377/* A SHA1 of the serialized NIR for the disk cache. */378unsigned char nir_sha1[20];379380unsigned program_id;381382/** Bitfield of (1 << IRIS_NOS_*) flags. */383unsigned nos;384385/** Have any shader variants been compiled yet? */386bool compiled_once;387388/** Should we use ALT mode for math? Useful for ARB programs. */389bool use_alt_mode;390391bool needs_edge_flag;392393/* Whether shader uses atomic operations. */394bool uses_atomic_load_store;395396/** Size (in bytes) of the kernel input data */397unsigned kernel_input_size;398399/** Size (in bytes) of the local (shared) data passed as kernel inputs */400unsigned kernel_shared_size;401402/** List of iris_compiled_shader variants */403struct list_head variants;404405/** Lock for the variants list */406simple_mtx_t lock;407};408409enum iris_surface_group {410IRIS_SURFACE_GROUP_RENDER_TARGET,411IRIS_SURFACE_GROUP_RENDER_TARGET_READ,412IRIS_SURFACE_GROUP_CS_WORK_GROUPS,413IRIS_SURFACE_GROUP_TEXTURE,414IRIS_SURFACE_GROUP_IMAGE,415IRIS_SURFACE_GROUP_UBO,416IRIS_SURFACE_GROUP_SSBO,417418IRIS_SURFACE_GROUP_COUNT,419};420421enum {422/* Invalid value for a binding table index. */423IRIS_SURFACE_NOT_USED = 0xa0a0a0a0,424};425426struct iris_binding_table {427uint32_t size_bytes;428429/** Number of surfaces in each group, before compacting. */430uint32_t sizes[IRIS_SURFACE_GROUP_COUNT];431432/** Initial offset of each group. */433uint32_t offsets[IRIS_SURFACE_GROUP_COUNT];434435/** Mask of surfaces used in each group. */436uint64_t used_mask[IRIS_SURFACE_GROUP_COUNT];437};438439/**440* A compiled shader variant, containing a pointer to the GPU assembly,441* as well as program data and other packets needed by state upload.442*443* There can be several iris_compiled_shader variants per API-level shader444* (iris_uncompiled_shader), due to state-based recompiles (brw_*_prog_key).445*/446struct iris_compiled_shader {447struct pipe_reference ref;448449/** Link in the iris_uncompiled_shader::variants list */450struct list_head link;451452/** Key for this variant (but not for BLORP programs) */453union iris_any_prog_key key;454455/** Reference to the uploaded assembly. */456struct iris_state_ref assembly;457458/** Pointer to the assembly in the BO's map. */459void *map;460461/** The program data (owned by the program cache hash table) */462struct brw_stage_prog_data *prog_data;463464/** A list of system values to be uploaded as uniforms. */465enum brw_param_builtin *system_values;466unsigned num_system_values;467468/** Size (in bytes) of the kernel input data */469unsigned kernel_input_size;470471/** Number of constbufs expected by the shader. */472unsigned num_cbufs;473474/**475* Derived 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets476* (the VUE-based information for transform feedback outputs).477*/478uint32_t *streamout;479480struct iris_binding_table bt;481482/**483* Shader packets and other data derived from prog_data. These must be484* completely determined from prog_data.485*/486uint8_t derived_data[0];487};488489/**490* API context state that is replicated per shader stage.491*/492struct iris_shader_state {493/** Uniform Buffers */494struct pipe_shader_buffer constbuf[PIPE_MAX_CONSTANT_BUFFERS];495struct iris_state_ref constbuf_surf_state[PIPE_MAX_CONSTANT_BUFFERS];496497bool sysvals_need_upload;498499/** Shader Storage Buffers */500struct pipe_shader_buffer ssbo[PIPE_MAX_SHADER_BUFFERS];501struct iris_state_ref ssbo_surf_state[PIPE_MAX_SHADER_BUFFERS];502503/** Shader Storage Images (image load store) */504struct iris_image_view image[PIPE_MAX_SHADER_IMAGES];505506struct iris_state_ref sampler_table;507struct iris_sampler_state *samplers[IRIS_MAX_TEXTURE_SAMPLERS];508struct iris_sampler_view *textures[IRIS_MAX_TEXTURE_SAMPLERS];509510/** Bitfield of which constant buffers are bound (non-null). */511uint32_t bound_cbufs;512513/** Bitfield of which image views are bound (non-null). */514uint32_t bound_image_views;515516/** Bitfield of which sampler views are bound (non-null). */517uint32_t bound_sampler_views;518519/** Bitfield of which shader storage buffers are bound (non-null). */520uint32_t bound_ssbos;521522/** Bitfield of which shader storage buffers are writable. */523uint32_t writable_ssbos;524};525526/**527* Gallium CSO for stream output (transform feedback) targets.528*/529struct iris_stream_output_target {530struct pipe_stream_output_target base;531532/** Storage holding the offset where we're writing in the buffer */533struct iris_state_ref offset;534535/** Stride (bytes-per-vertex) during this transform feedback operation */536uint16_t stride;537538/** Does the next 3DSTATE_SO_BUFFER need to zero the offsets? */539bool zero_offset;540};541542/**543* A pool containing SAMPLER_BORDER_COLOR_STATE entries.544*545* See iris_border_color.c for more information.546*/547struct iris_border_color_pool {548struct iris_bo *bo;549void *map;550unsigned insert_point;551552/** Map from border colors to offsets in the buffer. */553struct hash_table *ht;554};555556/**557* The API context (derived from pipe_context).558*559* Most driver state is tracked here.560*/561struct iris_context {562struct pipe_context ctx;563struct threaded_context *thrctx;564565/** A debug callback for KHR_debug output. */566struct pipe_debug_callback dbg;567568/** A device reset status callback for notifying that the GPU is hosed. */569struct pipe_device_reset_callback reset;570571/** A set of dmabuf resources dirtied beyond their default aux-states. */572struct set *dirty_dmabufs;573574/** Slab allocator for iris_transfer_map objects. */575struct slab_child_pool transfer_pool;576577/** Slab allocator for threaded_context's iris_transfer_map objects */578struct slab_child_pool transfer_pool_unsync;579580struct blorp_context blorp;581582struct iris_batch batches[IRIS_BATCH_COUNT];583584struct u_upload_mgr *query_buffer_uploader;585586struct {587struct {588/**589* Either the value of BaseVertex for indexed draw calls or the value590* of the argument <first> for non-indexed draw calls.591*/592int firstvertex;593int baseinstance;594} params;595596/**597* Are the above values the ones stored in the draw_params buffer?598* If so, we can compare them against new values to see if anything599* changed. If not, we need to assume they changed.600*/601bool params_valid;602603/**604* Resource and offset that stores draw_parameters from the indirect605* buffer or to the buffer that stures the previous values for non606* indirect draws.607*/608struct iris_state_ref draw_params;609610struct {611/**612* The value of DrawID. This always comes in from it's own vertex613* buffer since it's not part of the indirect draw parameters.614*/615int drawid;616617/**618* Stores if an indexed or non-indexed draw (~0/0). Useful to619* calculate BaseVertex as an AND of firstvertex and is_indexed_draw.620*/621int is_indexed_draw;622} derived_params;623624/**625* Resource and offset used for GL_ARB_shader_draw_parameters which626* contains parameters that are not present in the indirect buffer as627* drawid and is_indexed_draw. They will go in their own vertex element.628*/629struct iris_state_ref derived_draw_params;630} draw;631632struct {633struct iris_uncompiled_shader *uncompiled[MESA_SHADER_STAGES];634struct iris_compiled_shader *prog[MESA_SHADER_STAGES];635struct iris_compiled_shader *last_vue_shader;636struct {637unsigned size[4];638unsigned entries[4];639unsigned start[4];640bool constrained;641} urb;642643/** Uploader for shader assembly from the driver thread */644struct u_upload_mgr *uploader_driver;645/** Uploader for shader assembly from the threaded context */646struct u_upload_mgr *uploader_unsync;647struct hash_table *cache;648649/** Is a GS or TES outputting points or lines? */650bool output_topology_is_points_or_lines;651652/**653* Scratch buffers for various sizes and stages.654*655* Indexed by the "Per-Thread Scratch Space" field's 4-bit encoding,656* and shader stage.657*/658struct iris_bo *scratch_bos[1 << 4][MESA_SHADER_STAGES];659660/**661* Scratch buffer surface states on Gfx12.5+662*/663struct iris_state_ref scratch_surfs[1 << 4];664} shaders;665666struct intel_perf_context *perf_ctx;667668/** Frame number for debug prints */669uint32_t frame;670671struct {672uint64_t dirty;673uint64_t stage_dirty;674uint64_t stage_dirty_for_nos[IRIS_NOS_COUNT];675676unsigned num_viewports;677unsigned sample_mask;678struct iris_blend_state *cso_blend;679struct iris_rasterizer_state *cso_rast;680struct iris_depth_stencil_alpha_state *cso_zsa;681struct iris_vertex_element_state *cso_vertex_elements;682struct pipe_blend_color blend_color;683struct pipe_poly_stipple poly_stipple;684struct pipe_viewport_state viewports[IRIS_MAX_VIEWPORTS];685struct pipe_scissor_state scissors[IRIS_MAX_VIEWPORTS];686struct pipe_stencil_ref stencil_ref;687struct pipe_framebuffer_state framebuffer;688struct pipe_clip_state clip_planes;689690float default_outer_level[4];691float default_inner_level[2];692693/** Bitfield of which vertex buffers are bound (non-null). */694uint64_t bound_vertex_buffers;695696bool primitive_restart;697unsigned cut_index;698enum pipe_prim_type prim_mode:8;699bool prim_is_points_or_lines;700uint8_t vertices_per_patch;701702bool window_space_position;703704/** The last compute group size */705uint32_t last_block[3];706707/** The last compute grid size */708uint32_t last_grid[3];709/** Reference to the BO containing the compute grid size */710struct iris_state_ref grid_size;711/** Reference to the SURFACE_STATE for the compute grid resource */712struct iris_state_ref grid_surf_state;713714/**715* Array of aux usages for drawing, altered to account for any716* self-dependencies from resources bound for sampling and rendering.717*/718enum isl_aux_usage draw_aux_usage[BRW_MAX_DRAW_BUFFERS];719720/** Aux usage of the fb's depth buffer (which may or may not exist). */721enum isl_aux_usage hiz_usage;722723enum intel_urb_deref_block_size urb_deref_block_size;724725/** Are depth writes enabled? (Depth buffer may or may not exist.) */726bool depth_writes_enabled;727728/** Are stencil writes enabled? (Stencil buffer may or may not exist.) */729bool stencil_writes_enabled;730731/** GenX-specific current state */732struct iris_genx_state *genx;733734struct iris_shader_state shaders[MESA_SHADER_STAGES];735736/** Do vertex shader uses shader draw parameters ? */737bool vs_uses_draw_params;738bool vs_uses_derived_draw_params;739bool vs_needs_sgvs_element;740741/** Do vertex shader uses edge flag ? */742bool vs_needs_edge_flag;743744/** Do any samplers need border color? One bit per shader stage. */745uint8_t need_border_colors;746747/** Global resource bindings */748struct pipe_resource *global_bindings[IRIS_MAX_GLOBAL_BINDINGS];749750struct pipe_stream_output_target *so_target[PIPE_MAX_SO_BUFFERS];751bool streamout_active;752753bool statistics_counters_enabled;754755/** Current conditional rendering mode */756enum iris_predicate_state predicate;757758/**759* Query BO with a MI_PREDICATE_RESULT snapshot calculated on the760* render context that needs to be uploaded to the compute context.761*/762struct iris_bo *compute_predicate;763764/** Is a PIPE_QUERY_PRIMITIVES_GENERATED query active? */765bool prims_generated_query_active;766767/** 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets */768uint32_t *streamout;769770/** The SURFACE_STATE for a 1x1x1 null surface. */771struct iris_state_ref unbound_tex;772773/** The SURFACE_STATE for a framebuffer-sized null surface. */774struct iris_state_ref null_fb;775776struct u_upload_mgr *surface_uploader;777struct u_upload_mgr *bindless_uploader;778struct u_upload_mgr *dynamic_uploader;779780struct iris_binder binder;781782struct iris_border_color_pool border_color_pool;783784/** The high 16-bits of the last VBO/index buffer addresses */785uint16_t last_vbo_high_bits[33];786uint16_t last_index_bo_high_bits;787788/**789* Resources containing streamed state which our render context790* currently points to. Used to re-add these to the validation791* list when we start a new batch and haven't resubmitted commands.792*/793struct {794struct pipe_resource *cc_vp;795struct pipe_resource *sf_cl_vp;796struct pipe_resource *color_calc;797struct pipe_resource *scissor;798struct pipe_resource *blend;799struct pipe_resource *index_buffer;800struct pipe_resource *cs_thread_ids;801struct pipe_resource *cs_desc;802} last_res;803804/** Records the size of variable-length state for INTEL_DEBUG=bat */805struct hash_table_u64 *sizes;806807/** Last rendering scale argument provided to genX(emit_hashing_mode). */808unsigned current_hash_scale;809} state;810};811812#define perf_debug(dbg, ...) do { \813if (INTEL_DEBUG & DEBUG_PERF) \814dbg_printf(__VA_ARGS__); \815if (unlikely(dbg)) \816pipe_debug_message(dbg, PERF_INFO, __VA_ARGS__); \817} while(0)818819struct pipe_context *820iris_create_context(struct pipe_screen *screen, void *priv, unsigned flags);821822void iris_lost_context_state(struct iris_batch *batch);823824void iris_mark_dirty_dmabuf(struct iris_context *ice,825struct pipe_resource *res);826void iris_flush_dirty_dmabufs(struct iris_context *ice);827828void iris_init_blit_functions(struct pipe_context *ctx);829void iris_init_clear_functions(struct pipe_context *ctx);830void iris_init_program_functions(struct pipe_context *ctx);831void iris_init_resource_functions(struct pipe_context *ctx);832void iris_init_perfquery_functions(struct pipe_context *ctx);833void iris_update_compiled_shaders(struct iris_context *ice);834void iris_update_compiled_compute_shader(struct iris_context *ice);835void iris_fill_cs_push_const_buffer(struct brw_cs_prog_data *cs_prog_data,836unsigned threads,837uint32_t *dst);838839840/* iris_blit.c */841void iris_blorp_surf_for_resource(struct isl_device *isl_dev,842struct blorp_surf *surf,843struct pipe_resource *p_res,844enum isl_aux_usage aux_usage,845unsigned level,846bool is_render_target);847void iris_copy_region(struct blorp_context *blorp,848struct iris_batch *batch,849struct pipe_resource *dst,850unsigned dst_level,851unsigned dstx, unsigned dsty, unsigned dstz,852struct pipe_resource *src,853unsigned src_level,854const struct pipe_box *src_box);855856/* iris_draw.c */857858void iris_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info,859unsigned drawid_offset,860const struct pipe_draw_indirect_info *indirect,861const struct pipe_draw_start_count_bias *draws,862unsigned num_draws);863void iris_launch_grid(struct pipe_context *, const struct pipe_grid_info *);864865/* iris_pipe_control.c */866867void iris_emit_pipe_control_flush(struct iris_batch *batch,868const char *reason, uint32_t flags);869void iris_emit_pipe_control_write(struct iris_batch *batch,870const char *reason, uint32_t flags,871struct iris_bo *bo, uint32_t offset,872uint64_t imm);873void iris_emit_end_of_pipe_sync(struct iris_batch *batch,874const char *reason, uint32_t flags);875void iris_emit_buffer_barrier_for(struct iris_batch *batch,876struct iris_bo *bo,877enum iris_domain access);878void iris_flush_all_caches(struct iris_batch *batch);879880#define iris_handle_always_flush_cache(batch) \881if (unlikely(batch->screen->driconf.always_flush_cache)) \882iris_flush_all_caches(batch);883884void iris_init_flush_functions(struct pipe_context *ctx);885886/* iris_border_color.c */887888void iris_init_border_color_pool(struct iris_context *ice);889void iris_destroy_border_color_pool(struct iris_context *ice);890void iris_border_color_pool_reserve(struct iris_context *ice, unsigned count);891uint32_t iris_upload_border_color(struct iris_context *ice,892union pipe_color_union *color);893894/* iris_program.c */895void iris_upload_ubo_ssbo_surf_state(struct iris_context *ice,896struct pipe_shader_buffer *buf,897struct iris_state_ref *surf_state,898isl_surf_usage_flags_t usage);899const struct shader_info *iris_get_shader_info(const struct iris_context *ice,900gl_shader_stage stage);901struct iris_bo *iris_get_scratch_space(struct iris_context *ice,902unsigned per_thread_scratch,903gl_shader_stage stage);904const struct iris_state_ref *iris_get_scratch_surf(struct iris_context *ice,905unsigned per_thread_scratch);906uint32_t iris_group_index_to_bti(const struct iris_binding_table *bt,907enum iris_surface_group group,908uint32_t index);909uint32_t iris_bti_to_group_index(const struct iris_binding_table *bt,910enum iris_surface_group group,911uint32_t bti);912913/* iris_disk_cache.c */914915void iris_disk_cache_store(struct disk_cache *cache,916const struct iris_uncompiled_shader *ish,917const struct iris_compiled_shader *shader,918const void *prog_key,919uint32_t prog_key_size);920struct iris_compiled_shader *921iris_disk_cache_retrieve(struct iris_screen *screen,922struct u_upload_mgr *uploader,923struct iris_uncompiled_shader *ish,924const void *prog_key,925uint32_t prog_key_size);926927/* iris_program_cache.c */928929void iris_init_program_cache(struct iris_context *ice);930void iris_destroy_program_cache(struct iris_context *ice);931struct iris_compiled_shader *iris_find_cached_shader(struct iris_context *ice,932enum iris_program_cache_id,933uint32_t key_size,934const void *key);935struct iris_compiled_shader *iris_upload_shader(struct iris_screen *screen,936struct iris_uncompiled_shader *,937struct hash_table *driver_ht,938struct u_upload_mgr *uploader,939enum iris_program_cache_id,940uint32_t key_size,941const void *key,942const void *assembly,943struct brw_stage_prog_data *,944uint32_t *streamout,945enum brw_param_builtin *sysv,946unsigned num_system_values,947unsigned kernel_input_size,948unsigned num_cbufs,949const struct iris_binding_table *bt);950void iris_delete_shader_variant(struct iris_compiled_shader *shader);951952static inline void953iris_shader_variant_reference(struct iris_compiled_shader **dst,954struct iris_compiled_shader *src)955{956struct iris_compiled_shader *old_dst = *dst;957958if (pipe_reference(old_dst ? &old_dst->ref: NULL, src ? &src->ref : NULL))959iris_delete_shader_variant(old_dst);960961*dst = src;962}963964bool iris_blorp_lookup_shader(struct blorp_batch *blorp_batch,965const void *key,966uint32_t key_size,967uint32_t *kernel_out,968void *prog_data_out);969bool iris_blorp_upload_shader(struct blorp_batch *blorp_batch, uint32_t stage,970const void *key, uint32_t key_size,971const void *kernel, uint32_t kernel_size,972const struct brw_stage_prog_data *prog_data,973uint32_t prog_data_size,974uint32_t *kernel_out,975void *prog_data_out);976977/* iris_resolve.c */978979void iris_predraw_resolve_inputs(struct iris_context *ice,980struct iris_batch *batch,981bool *draw_aux_buffer_disabled,982gl_shader_stage stage,983bool consider_framebuffer);984void iris_predraw_resolve_framebuffer(struct iris_context *ice,985struct iris_batch *batch,986bool *draw_aux_buffer_disabled);987void iris_postdraw_update_resolve_tracking(struct iris_context *ice,988struct iris_batch *batch);989void iris_cache_flush_for_render(struct iris_batch *batch,990struct iris_bo *bo,991enum isl_aux_usage aux_usage);992int iris_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,993struct pipe_driver_query_info *info);994int iris_get_driver_query_group_info(struct pipe_screen *pscreen,995unsigned index,996struct pipe_driver_query_group_info *info);997998/* iris_state.c */999void gfx9_toggle_preemption(struct iris_context *ice,1000struct iris_batch *batch,1001const struct pipe_draw_info *draw);1002100310041005#ifdef genX1006# include "iris_genx_protos.h"1007#else1008# define genX(x) gfx4_##x1009# include "iris_genx_protos.h"1010# undef genX1011# define genX(x) gfx5_##x1012# include "iris_genx_protos.h"1013# undef genX1014# define genX(x) gfx6_##x1015# include "iris_genx_protos.h"1016# undef genX1017# define genX(x) gfx7_##x1018# include "iris_genx_protos.h"1019# undef genX1020# define genX(x) gfx75_##x1021# include "iris_genx_protos.h"1022# undef genX1023# define genX(x) gfx8_##x1024# include "iris_genx_protos.h"1025# undef genX1026# define genX(x) gfx9_##x1027# include "iris_genx_protos.h"1028# undef genX1029# define genX(x) gfx11_##x1030# include "iris_genx_protos.h"1031# undef genX1032# define genX(x) gfx12_##x1033# include "iris_genx_protos.h"1034# undef genX1035# define genX(x) gfx125_##x1036# include "iris_genx_protos.h"1037# undef genX1038#endif10391040#endif104110421043