Path: blob/21.2-virgl/src/gallium/drivers/crocus/crocus_context.h
4570 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 CROCUS_CONTEXT_H23#define CROCUS_CONTEXT_H2425#include "pipe/p_context.h"26#include "pipe/p_state.h"27#include "util/u_debug.h"28#include "util/u_threaded_context.h"29#include "intel/blorp/blorp.h"30#include "intel/dev/intel_debug.h"31#include "intel/compiler/brw_compiler.h"32#include "crocus_batch.h"33#include "crocus_fence.h"34#include "crocus_resource.h"35#include "crocus_screen.h"36#include "util/u_blitter.h"3738struct crocus_bo;39struct crocus_context;40struct blorp_batch;41struct blorp_params;4243#define CROCUS_MAX_TEXTURE_BUFFER_SIZE (1 << 27)44#define CROCUS_MAX_TEXTURE_SAMPLERS 3245/* CROCUS_MAX_ABOS and CROCUS_MAX_SSBOS must be the same. */46#define CROCUS_MAX_ABOS 1647#define CROCUS_MAX_SSBOS 1648#define CROCUS_MAX_VIEWPORTS 1649#define CROCUS_MAX_CLIP_PLANES 85051enum crocus_param_domain {52BRW_PARAM_DOMAIN_BUILTIN = 0,53BRW_PARAM_DOMAIN_IMAGE,54};5556enum {57DRI_CONF_BO_REUSE_DISABLED,58DRI_CONF_BO_REUSE_ALL59};6061#define BRW_PARAM(domain, val) (BRW_PARAM_DOMAIN_##domain << 24 | (val))62#define BRW_PARAM_DOMAIN(param) ((uint32_t)(param) >> 24)63#define BRW_PARAM_VALUE(param) ((uint32_t)(param) & 0x00ffffff)64#define BRW_PARAM_IMAGE(idx, offset) BRW_PARAM(IMAGE, ((idx) << 8) | (offset))65#define BRW_PARAM_IMAGE_IDX(value) (BRW_PARAM_VALUE(value) >> 8)66#define BRW_PARAM_IMAGE_OFFSET(value)(BRW_PARAM_VALUE(value) & 0xf)6768/**69* Dirty flags. When state changes, we flag some combination of these70* to indicate that particular GPU commands need to be re-emitted.71*72* Each bit typically corresponds to a single 3DSTATE_* command packet, but73* in rare cases they map to a group of related packets that need to be74* emitted together.75*76* See crocus_upload_render_state().77*/78#define CROCUS_DIRTY_COLOR_CALC_STATE (1ull << 0)79#define CROCUS_DIRTY_POLYGON_STIPPLE (1ull << 1)80#define CROCUS_DIRTY_CC_VIEWPORT (1ull << 2)81#define CROCUS_DIRTY_SF_CL_VIEWPORT (1ull << 3)82#define CROCUS_DIRTY_RASTER (1ull << 4)83#define CROCUS_DIRTY_CLIP (1ull << 5)84#define CROCUS_DIRTY_LINE_STIPPLE (1ull << 6)85#define CROCUS_DIRTY_VERTEX_ELEMENTS (1ull << 7)86#define CROCUS_DIRTY_VERTEX_BUFFERS (1ull << 8)87#define CROCUS_DIRTY_DRAWING_RECTANGLE (1ull << 9)88#define CROCUS_DIRTY_GEN6_URB (1ull << 10)89#define CROCUS_DIRTY_DEPTH_BUFFER (1ull << 11)90#define CROCUS_DIRTY_WM (1ull << 12)91#define CROCUS_DIRTY_SO_DECL_LIST (1ull << 13)92#define CROCUS_DIRTY_STREAMOUT (1ull << 14)93#define CROCUS_DIRTY_GEN4_CONSTANT_COLOR (1ull << 15)94#define CROCUS_DIRTY_GEN4_CURBE (1ull << 16)95#define CROCUS_DIRTY_GEN4_URB_FENCE (1ull << 17)96#define CROCUS_DIRTY_GEN5_PIPELINED_POINTERS (1ull << 18)97#define CROCUS_DIRTY_GEN5_BINDING_TABLE_POINTERS (1ull << 19)98#define CROCUS_DIRTY_GEN6_BLEND_STATE (1ull << 20)99#define CROCUS_DIRTY_GEN6_SCISSOR_RECT (1ull << 21)100#define CROCUS_DIRTY_GEN6_WM_DEPTH_STENCIL (1ull << 22)101#define CROCUS_DIRTY_GEN6_MULTISAMPLE (1ull << 23)102#define CROCUS_DIRTY_GEN6_SAMPLE_MASK (1ull << 24)103#define CROCUS_DIRTY_GEN7_SBE (1ull << 25)104#define CROCUS_DIRTY_GEN7_L3_CONFIG (1ull << 26)105#define CROCUS_DIRTY_GEN7_SO_BUFFERS (1ull << 27)106#define CROCUS_DIRTY_GEN75_VF (1ull << 28)107#define CROCUS_DIRTY_RENDER_RESOLVES_AND_FLUSHES (1ull << 29)108#define CROCUS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES (1ull << 30)109#define CROCUS_DIRTY_VF_STATISTICS (1ull << 31)110#define CROCUS_DIRTY_GEN4_CLIP_PROG (1ull << 32)111#define CROCUS_DIRTY_GEN4_SF_PROG (1ull << 33)112#define CROCUS_DIRTY_GEN4_FF_GS_PROG (1ull << 34)113#define CROCUS_DIRTY_GEN6_SAMPLER_STATE_POINTERS (1ull << 35)114#define CROCUS_DIRTY_GEN6_SVBI (1ull << 36)115#define CROCUS_DIRTY_GEN8_VF_TOPOLOGY (1ull << 37)116#define CROCUS_DIRTY_GEN8_PMA_FIX (1ull << 38)117#define CROCUS_DIRTY_GEN8_VF_SGVS (1ull << 39)118#define CROCUS_DIRTY_GEN8_PS_BLEND (1ull << 40)119120#define CROCUS_ALL_DIRTY_FOR_COMPUTE (CROCUS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES)121122#define CROCUS_ALL_DIRTY_FOR_RENDER (~CROCUS_ALL_DIRTY_FOR_COMPUTE)123124/**125* Per-stage dirty flags. When state changes, we flag some combination of126* these to indicate that particular GPU commands need to be re-emitted.127* Unlike the IRIS_DIRTY_* flags these are shader stage-specific and can be128* indexed by shifting the mask by the shader stage index.129*130* See crocus_upload_render_state().131*/132#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_VS (1ull << 0)133#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_TCS (1ull << 1)134#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_TES (1ull << 2)135#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_GS (1ull << 3)136#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_PS (1ull << 4)137#define CROCUS_STAGE_DIRTY_SAMPLER_STATES_CS (1ull << 5)138#define CROCUS_STAGE_DIRTY_UNCOMPILED_VS (1ull << 6)139#define CROCUS_STAGE_DIRTY_UNCOMPILED_TCS (1ull << 7)140#define CROCUS_STAGE_DIRTY_UNCOMPILED_TES (1ull << 8)141#define CROCUS_STAGE_DIRTY_UNCOMPILED_GS (1ull << 9)142#define CROCUS_STAGE_DIRTY_UNCOMPILED_FS (1ull << 10)143#define CROCUS_STAGE_DIRTY_UNCOMPILED_CS (1ull << 11)144#define CROCUS_STAGE_DIRTY_VS (1ull << 12)145#define CROCUS_STAGE_DIRTY_TCS (1ull << 13)146#define CROCUS_STAGE_DIRTY_TES (1ull << 14)147#define CROCUS_STAGE_DIRTY_GS (1ull << 15)148#define CROCUS_STAGE_DIRTY_FS (1ull << 16)149#define CROCUS_STAGE_DIRTY_CS (1ull << 17)150#define CROCUS_SHIFT_FOR_STAGE_DIRTY_CONSTANTS 18151#define CROCUS_STAGE_DIRTY_CONSTANTS_VS (1ull << 18)152#define CROCUS_STAGE_DIRTY_CONSTANTS_TCS (1ull << 19)153#define CROCUS_STAGE_DIRTY_CONSTANTS_TES (1ull << 20)154#define CROCUS_STAGE_DIRTY_CONSTANTS_GS (1ull << 21)155#define CROCUS_STAGE_DIRTY_CONSTANTS_FS (1ull << 22)156#define CROCUS_STAGE_DIRTY_CONSTANTS_CS (1ull << 23)157#define CROCUS_STAGE_DIRTY_BINDINGS_VS (1ull << 24)158#define CROCUS_STAGE_DIRTY_BINDINGS_TCS (1ull << 25)159#define CROCUS_STAGE_DIRTY_BINDINGS_TES (1ull << 26)160#define CROCUS_STAGE_DIRTY_BINDINGS_GS (1ull << 27)161#define CROCUS_STAGE_DIRTY_BINDINGS_FS (1ull << 28)162#define CROCUS_STAGE_DIRTY_BINDINGS_CS (1ull << 29)163164#define CROCUS_ALL_STAGE_DIRTY_FOR_COMPUTE (CROCUS_STAGE_DIRTY_CS | \165CROCUS_STAGE_DIRTY_SAMPLER_STATES_CS | \166CROCUS_STAGE_DIRTY_UNCOMPILED_CS | \167CROCUS_STAGE_DIRTY_CONSTANTS_CS | \168CROCUS_STAGE_DIRTY_BINDINGS_CS)169170#define CROCUS_ALL_STAGE_DIRTY_FOR_RENDER (~CROCUS_ALL_STAGE_DIRTY_FOR_COMPUTE)171172#define CROCUS_ALL_STAGE_DIRTY_BINDINGS (CROCUS_STAGE_DIRTY_BINDINGS_VS | \173CROCUS_STAGE_DIRTY_BINDINGS_TCS | \174CROCUS_STAGE_DIRTY_BINDINGS_TES | \175CROCUS_STAGE_DIRTY_BINDINGS_GS | \176CROCUS_STAGE_DIRTY_BINDINGS_FS | \177CROCUS_STAGE_DIRTY_BINDINGS_CS)178179#define CROCUS_RENDER_STAGE_DIRTY_CONSTANTS (CROCUS_STAGE_DIRTY_CONSTANTS_VS | \180CROCUS_STAGE_DIRTY_CONSTANTS_TCS | \181CROCUS_STAGE_DIRTY_CONSTANTS_TES | \182CROCUS_STAGE_DIRTY_CONSTANTS_GS | \183CROCUS_STAGE_DIRTY_CONSTANTS_FS)184185/**186* Non-orthogonal state (NOS) dependency flags.187*188* Shader programs may depend on non-orthogonal state. These flags are189* used to indicate that a shader's key depends on the state provided by190* a certain Gallium CSO. Changing any CSOs marked as a dependency will191* cause the driver to re-compute the shader key, possibly triggering a192* shader recompile.193*/194enum crocus_nos_dep {195CROCUS_NOS_FRAMEBUFFER,196CROCUS_NOS_DEPTH_STENCIL_ALPHA,197CROCUS_NOS_RASTERIZER,198CROCUS_NOS_BLEND,199CROCUS_NOS_LAST_VUE_MAP,200CROCUS_NOS_TEXTURES,201CROCUS_NOS_VERTEX_ELEMENTS,202CROCUS_NOS_COUNT,203};204205struct crocus_depth_stencil_alpha_state;206207/**208* Cache IDs for the in-memory program cache (ice->shaders.cache).209*/210enum crocus_program_cache_id {211CROCUS_CACHE_VS = MESA_SHADER_VERTEX,212CROCUS_CACHE_TCS = MESA_SHADER_TESS_CTRL,213CROCUS_CACHE_TES = MESA_SHADER_TESS_EVAL,214CROCUS_CACHE_GS = MESA_SHADER_GEOMETRY,215CROCUS_CACHE_FS = MESA_SHADER_FRAGMENT,216CROCUS_CACHE_CS = MESA_SHADER_COMPUTE,217CROCUS_CACHE_BLORP,218CROCUS_CACHE_SF,219CROCUS_CACHE_CLIP,220CROCUS_CACHE_FF_GS,221};222223/** @{224*225* Defines for PIPE_CONTROL operations, which trigger cache flushes,226* synchronization, pipelined memory writes, and so on.227*228* The bits here are not the actual hardware values. The actual fields229* move between various generations, so we just have flags for each230* potential operation, and use genxml to encode the actual packet.231*/232enum pipe_control_flags233{234PIPE_CONTROL_FLUSH_LLC = (1 << 1),235PIPE_CONTROL_LRI_POST_SYNC_OP = (1 << 2),236PIPE_CONTROL_STORE_DATA_INDEX = (1 << 3),237PIPE_CONTROL_CS_STALL = (1 << 4),238PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET = (1 << 5),239PIPE_CONTROL_SYNC_GFDT = (1 << 6),240PIPE_CONTROL_TLB_INVALIDATE = (1 << 7),241PIPE_CONTROL_MEDIA_STATE_CLEAR = (1 << 8),242PIPE_CONTROL_WRITE_IMMEDIATE = (1 << 9),243PIPE_CONTROL_WRITE_DEPTH_COUNT = (1 << 10),244PIPE_CONTROL_WRITE_TIMESTAMP = (1 << 11),245PIPE_CONTROL_DEPTH_STALL = (1 << 12),246PIPE_CONTROL_RENDER_TARGET_FLUSH = (1 << 13),247PIPE_CONTROL_INSTRUCTION_INVALIDATE = (1 << 14),248PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE = (1 << 15),249PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE = (1 << 16),250PIPE_CONTROL_NOTIFY_ENABLE = (1 << 17),251PIPE_CONTROL_FLUSH_ENABLE = (1 << 18),252PIPE_CONTROL_DATA_CACHE_FLUSH = (1 << 19),253PIPE_CONTROL_VF_CACHE_INVALIDATE = (1 << 20),254PIPE_CONTROL_CONST_CACHE_INVALIDATE = (1 << 21),255PIPE_CONTROL_STATE_CACHE_INVALIDATE = (1 << 22),256PIPE_CONTROL_STALL_AT_SCOREBOARD = (1 << 23),257PIPE_CONTROL_DEPTH_CACHE_FLUSH = (1 << 24),258PIPE_CONTROL_TILE_CACHE_FLUSH = (1 << 25),259};260261#define PIPE_CONTROL_CACHE_FLUSH_BITS \262(PIPE_CONTROL_DEPTH_CACHE_FLUSH | \263PIPE_CONTROL_DATA_CACHE_FLUSH | \264PIPE_CONTROL_RENDER_TARGET_FLUSH)265266#define PIPE_CONTROL_CACHE_INVALIDATE_BITS \267(PIPE_CONTROL_STATE_CACHE_INVALIDATE | \268PIPE_CONTROL_CONST_CACHE_INVALIDATE | \269PIPE_CONTROL_VF_CACHE_INVALIDATE | \270PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | \271PIPE_CONTROL_INSTRUCTION_INVALIDATE)272273enum crocus_predicate_state {274/* The first two states are used if we can determine whether to draw275* without having to look at the values in the query object buffer. This276* will happen if there is no conditional render in progress, if the query277* object is already completed or if something else has already added278* samples to the preliminary result.279*/280CROCUS_PREDICATE_STATE_RENDER,281CROCUS_PREDICATE_STATE_DONT_RENDER,282283/* In this case whether to draw or not depends on the result of an284* MI_PREDICATE command so the predicate enable bit needs to be checked.285*/286CROCUS_PREDICATE_STATE_USE_BIT,287/* In this case, either MI_PREDICATE doesn't exist or we lack the288* necessary kernel features to use it. Stall for the query result.289*/290CROCUS_PREDICATE_STATE_STALL_FOR_QUERY,291};292293/** @} */294295/**296* An uncompiled, API-facing shader. This is the Gallium CSO for shaders.297* It primarily contains the NIR for the shader.298*299* Each API-facing shader can be compiled into multiple shader variants,300* based on non-orthogonal state dependencies, recorded in the shader key.301*302* See crocus_compiled_shader, which represents a compiled shader variant.303*/304struct crocus_uncompiled_shader {305struct nir_shader *nir;306307struct pipe_stream_output_info stream_output;308309/* A SHA1 of the serialized NIR for the disk cache. */310unsigned char nir_sha1[20];311312unsigned program_id;313314/** Bitfield of (1 << CROCUS_NOS_*) flags. */315unsigned nos;316317/** Have any shader variants been compiled yet? */318bool compiled_once;319320/** Should we use ALT mode for math? Useful for ARB programs. */321bool use_alt_mode;322323bool needs_edge_flag;324325/** Constant data scraped from the shader by nir_opt_large_constants */326struct pipe_resource *const_data;327328/** Surface state for const_data */329struct crocus_state_ref const_data_state;330};331332enum crocus_surface_group {333CROCUS_SURFACE_GROUP_RENDER_TARGET,334CROCUS_SURFACE_GROUP_RENDER_TARGET_READ,335CROCUS_SURFACE_GROUP_SOL,336CROCUS_SURFACE_GROUP_CS_WORK_GROUPS,337CROCUS_SURFACE_GROUP_TEXTURE,338CROCUS_SURFACE_GROUP_TEXTURE_GATHER,339CROCUS_SURFACE_GROUP_IMAGE,340CROCUS_SURFACE_GROUP_UBO,341CROCUS_SURFACE_GROUP_SSBO,342343CROCUS_SURFACE_GROUP_COUNT,344};345346enum {347/* Invalid value for a binding table index. */348CROCUS_SURFACE_NOT_USED = 0xa0a0a0a0,349};350351struct crocus_binding_table {352uint32_t size_bytes;353354/** Number of surfaces in each group, before compacting. */355uint32_t sizes[CROCUS_SURFACE_GROUP_COUNT];356357/** Initial offset of each group. */358uint32_t offsets[CROCUS_SURFACE_GROUP_COUNT];359360/** Mask of surfaces used in each group. */361uint64_t used_mask[CROCUS_SURFACE_GROUP_COUNT];362};363364/**365* A compiled shader variant, containing a pointer to the GPU assembly,366* as well as program data and other packets needed by state upload.367*368* There can be several crocus_compiled_shader variants per API-level shader369* (crocus_uncompiled_shader), due to state-based recompiles (brw_*_prog_key).370*/371struct crocus_compiled_shader {372/** Reference to the uploaded assembly. */373uint32_t offset;374375/* asm size in map */376uint32_t map_size;377378/** The program data (owned by the program cache hash table) */379struct brw_stage_prog_data *prog_data;380uint32_t prog_data_size;381382/** A list of system values to be uploaded as uniforms. */383enum brw_param_builtin *system_values;384unsigned num_system_values;385386/** Number of constbufs expected by the shader. */387unsigned num_cbufs;388389/**390* Derived 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets391* (the VUE-based information for transform feedback outputs).392*/393uint32_t *streamout;394395struct crocus_binding_table bt;396397uint32_t bind_bo_offset;398uint32_t surf_offset[128];//TODO399};400401/**402* API context state that is replicated per shader stage.403*/404struct crocus_shader_state {405/** Uniform Buffers */406struct pipe_constant_buffer constbufs[PIPE_MAX_CONSTANT_BUFFERS];407408bool sysvals_need_upload;409410/** Shader Storage Buffers */411struct pipe_shader_buffer ssbo[PIPE_MAX_SHADER_BUFFERS];412413/** Shader Storage Images (image load store) */414struct crocus_image_view image[PIPE_MAX_SHADER_IMAGES];415416struct crocus_sampler_state *samplers[CROCUS_MAX_TEXTURE_SAMPLERS];417struct crocus_sampler_view *textures[CROCUS_MAX_TEXTURE_SAMPLERS];418419/** Bitfield of which constant buffers are bound (non-null). */420uint32_t bound_cbufs;421422/** Bitfield of which image views are bound (non-null). */423uint32_t bound_image_views;424425/** Bitfield of which sampler views are bound (non-null). */426uint32_t bound_sampler_views;427428/** Bitfield of which shader storage buffers are bound (non-null). */429uint32_t bound_ssbos;430431/** Bitfield of which shader storage buffers are writable. */432uint32_t writable_ssbos;433434uint32_t sampler_offset;435};436437/**438* The API context (derived from pipe_context).439*440* Most driver state is tracked here.441*/442struct crocus_context {443struct pipe_context ctx;444struct threaded_context *thrctx;445446/** A debug callback for KHR_debug output. */447struct pipe_debug_callback dbg;448449/** A device reset status callback for notifying that the GPU is hosed. */450struct pipe_device_reset_callback reset;451452/** Slab allocator for crocus_transfer_map objects. */453struct slab_child_pool transfer_pool;454455/** Slab allocator for threaded_context's crocus_transfer_map objects */456struct slab_child_pool transfer_pool_unsync;457458struct blorp_context blorp;459460int batch_count;461struct crocus_batch batches[CROCUS_BATCH_COUNT];462463struct u_upload_mgr *query_buffer_uploader;464465struct blitter_context *blitter;466467struct {468struct {469/**470* Either the value of BaseVertex for indexed draw calls or the value471* of the argument <first> for non-indexed draw calls.472*/473int firstvertex;474int baseinstance;475} params;476477/**478* Are the above values the ones stored in the draw_params buffer?479* If so, we can compare them against new values to see if anything480* changed. If not, we need to assume they changed.481*/482bool params_valid;483484/**485* Resource and offset that stores draw_parameters from the indirect486* buffer or to the buffer that stures the previous values for non487* indirect draws.488*/489struct crocus_state_ref draw_params;490491struct {492/**493* The value of DrawID. This always comes in from it's own vertex494* buffer since it's not part of the indirect draw parameters.495*/496int drawid;497498/**499* Stores if an indexed or non-indexed draw (~0/0). Useful to500* calculate BaseVertex as an AND of firstvertex and is_indexed_draw.501*/502int is_indexed_draw;503} derived_params;504505/**506* Resource and offset used for GL_ARB_shader_draw_parameters which507* contains parameters that are not present in the indirect buffer as508* drawid and is_indexed_draw. They will go in their own vertex element.509*/510struct crocus_state_ref derived_draw_params;511} draw;512513struct {514struct crocus_uncompiled_shader *uncompiled[MESA_SHADER_STAGES];515struct crocus_compiled_shader *prog[MESA_SHADER_STAGES];516struct brw_vue_map *last_vue_map;517518struct crocus_bo *cache_bo;519uint32_t cache_next_offset;520void *cache_bo_map;521struct hash_table *cache;522523unsigned urb_size;524525/* gen 4/5 clip/sf progs */526struct crocus_compiled_shader *clip_prog;527struct crocus_compiled_shader *sf_prog;528/* gen4/5 prims, gen6 streamout */529struct crocus_compiled_shader *ff_gs_prog;530uint32_t clip_offset;531uint32_t sf_offset;532uint32_t wm_offset;533uint32_t vs_offset;534uint32_t gs_offset;535uint32_t cc_offset;536537/** Is a GS or TES outputting points or lines? */538bool output_topology_is_points_or_lines;539540/* Track last VS URB entry size */541unsigned last_vs_entry_size;542543/**544* Scratch buffers for various sizes and stages.545*546* Indexed by the "Per-Thread Scratch Space" field's 4-bit encoding,547* and shader stage.548*/549struct crocus_bo *scratch_bos[1 << 4][MESA_SHADER_STAGES];550} shaders;551552struct {553struct crocus_query *query;554bool condition;555enum pipe_render_cond_flag mode;556} condition;557558struct intel_perf_context *perf_ctx;559560struct {561uint64_t dirty;562uint64_t stage_dirty;563uint64_t stage_dirty_for_nos[CROCUS_NOS_COUNT];564565unsigned num_viewports;566unsigned sample_mask;567struct crocus_blend_state *cso_blend;568struct crocus_rasterizer_state *cso_rast;569struct crocus_depth_stencil_alpha_state *cso_zsa;570struct crocus_vertex_element_state *cso_vertex_elements;571struct pipe_blend_color blend_color;572struct pipe_poly_stipple poly_stipple;573struct pipe_viewport_state viewports[CROCUS_MAX_VIEWPORTS];574struct pipe_scissor_state scissors[CROCUS_MAX_VIEWPORTS];575struct pipe_stencil_ref stencil_ref;576struct pipe_framebuffer_state framebuffer;577struct pipe_clip_state clip_planes;578579float default_outer_level[4];580float default_inner_level[2];581582/** Bitfield of which vertex buffers are bound (non-null). */583uint32_t bound_vertex_buffers;584struct pipe_vertex_buffer vertex_buffers[16];585uint32_t vb_end[16];586587bool primitive_restart;588unsigned cut_index;589enum pipe_prim_type prim_mode:8;590bool prim_is_points_or_lines;591uint8_t vertices_per_patch;592593bool window_space_position;594595/** The last compute group size */596uint32_t last_block[3];597598/** The last compute grid size */599uint32_t last_grid[3];600/** Reference to the BO containing the compute grid size */601struct crocus_state_ref grid_size;602603/**604* Array of aux usages for drawing, altered to account for any605* self-dependencies from resources bound for sampling and rendering.606*/607enum isl_aux_usage draw_aux_usage[BRW_MAX_DRAW_BUFFERS];608609/** Aux usage of the fb's depth buffer (which may or may not exist). */610enum isl_aux_usage hiz_usage;611612/** Bitfield of whether color blending is enabled for RT[i] */613uint8_t blend_enables;614615/** Are depth writes enabled? (Depth buffer may or may not exist.) */616bool depth_writes_enabled;617618/** Are stencil writes enabled? (Stencil buffer may or may not exist.) */619bool stencil_writes_enabled;620621/** GenX-specific current state */622struct crocus_genx_state *genx;623624struct crocus_shader_state shaders[MESA_SHADER_STAGES];625626/** Do vertex shader uses shader draw parameters ? */627bool vs_uses_draw_params;628bool vs_uses_derived_draw_params;629bool vs_needs_sgvs_element;630bool vs_uses_vertexid;631bool vs_uses_instanceid;632633/** Do vertex shader uses edge flag ? */634bool vs_needs_edge_flag;635636struct pipe_stream_output_target *so_target[PIPE_MAX_SO_BUFFERS];637bool streamout_active;638int so_targets;639640bool statistics_counters_enabled;641642/** Current conditional rendering mode */643enum crocus_predicate_state predicate;644bool predicate_supported;645646/**647* Query BO with a MI_PREDICATE_RESULT snapshot calculated on the648* render context that needs to be uploaded to the compute context.649*/650struct crocus_bo *compute_predicate;651652/** Is a PIPE_QUERY_PRIMITIVES_GENERATED query active? */653bool prims_generated_query_active;654655/** 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets */656uint32_t *streamout;657658/**659* Resources containing streamed state which our render context660* currently points to. Used to re-add these to the validation661* list when we start a new batch and haven't resubmitted commands.662*/663struct {664struct pipe_resource *res;665uint32_t offset;666uint32_t size;667uint32_t index_size;668bool prim_restart;669} index_buffer;670671uint32_t sf_vp_address;672uint32_t clip_vp_address;673uint32_t cc_vp_address;674675uint32_t stats_wm;676float global_depth_offset_clamp;677678uint32_t last_xfb_verts_per_prim;679uint64_t svbi;680} state;681682/* BRW_NEW_URB_ALLOCATIONS:683*/684struct {685uint32_t vsize; /* vertex size plus header in urb registers */686uint32_t gsize; /* GS output size in urb registers */687uint32_t hsize; /* Tessellation control output size in urb registers */688uint32_t dsize; /* Tessellation evaluation output size in urb registers */689uint32_t csize; /* constant buffer size in urb registers */690uint32_t sfsize; /* setup data size in urb registers */691692bool constrained;693694uint32_t nr_vs_entries;695uint32_t nr_hs_entries;696uint32_t nr_ds_entries;697uint32_t nr_gs_entries;698uint32_t nr_clip_entries;699uint32_t nr_sf_entries;700uint32_t nr_cs_entries;701702uint32_t vs_start;703uint32_t hs_start;704uint32_t ds_start;705uint32_t gs_start;706uint32_t clip_start;707uint32_t sf_start;708uint32_t cs_start;709/**710* URB size in the current configuration. The units this is expressed711* in are somewhat inconsistent, see intel_device_info::urb::size.712*713* FINISHME: Represent the URB size consistently in KB on all platforms.714*/715uint32_t size;716717/* True if the most recently sent _3DSTATE_URB message allocated718* URB space for the GS.719*/720bool gs_present;721722/* True if the most recently sent _3DSTATE_URB message allocated723* URB space for the HS and DS.724*/725bool tess_present;726} urb;727728/* GEN4/5 curbe */729struct {730unsigned wm_start;731unsigned wm_size;732unsigned clip_start;733unsigned clip_size;734unsigned vs_start;735unsigned vs_size;736unsigned total_size;737738struct crocus_resource *curbe_res;739unsigned curbe_offset;740} curbe;741742/**743* A buffer containing a marker + description of the driver. This buffer is744* added to all execbufs syscalls so that we can identify the driver that745* generated a hang by looking at the content of the buffer in the error746* state. It is also used for hardware workarounds that require scratch747* writes or reads from some unimportant memory. To avoid overriding the748* debug data, use the workaround_address field for workarounds.749*/750struct crocus_bo *workaround_bo;751unsigned workaround_offset;752};753754#define perf_debug(dbg, ...) do { \755if (INTEL_DEBUG & DEBUG_PERF) \756dbg_printf(__VA_ARGS__); \757if (unlikely(dbg)) \758pipe_debug_message(dbg, PERF_INFO, __VA_ARGS__); \759} while(0)760761762struct pipe_context *763crocus_create_context(struct pipe_screen *screen, void *priv, unsigned flags);764765void crocus_lost_context_state(struct crocus_batch *batch);766767void crocus_init_blit_functions(struct pipe_context *ctx);768void crocus_init_clear_functions(struct pipe_context *ctx);769void crocus_init_program_functions(struct pipe_context *ctx);770void crocus_init_resource_functions(struct pipe_context *ctx);771bool crocus_update_compiled_shaders(struct crocus_context *ice);772void crocus_update_compiled_compute_shader(struct crocus_context *ice);773void crocus_fill_cs_push_const_buffer(struct brw_cs_prog_data *cs_prog_data,774unsigned threads, uint32_t *dst);775776777/* crocus_blit.c */778enum crocus_blitter_op779{780CROCUS_SAVE_TEXTURES = 1,781CROCUS_SAVE_FRAMEBUFFER = 2,782CROCUS_SAVE_FRAGMENT_STATE = 4,783CROCUS_DISABLE_RENDER_COND = 8,784};785void crocus_blitter_begin(struct crocus_context *ice, enum crocus_blitter_op op, bool render_cond);786787void crocus_blorp_surf_for_resource(struct crocus_vtable *vtbl,788struct isl_device *isl_dev,789struct blorp_surf *surf,790struct pipe_resource *p_res,791enum isl_aux_usage aux_usage,792unsigned level,793bool is_render_target);794void crocus_copy_region(struct blorp_context *blorp,795struct crocus_batch *batch,796struct pipe_resource *dst,797unsigned dst_level,798unsigned dstx, unsigned dsty, unsigned dstz,799struct pipe_resource *src,800unsigned src_level,801const struct pipe_box *src_box);802803/* crocus_draw.c */804void crocus_draw_vbo(struct pipe_context *ctx,805const struct pipe_draw_info *info,806unsigned drawid_offset,807const struct pipe_draw_indirect_info *indirect,808const struct pipe_draw_start_count_bias *draws,809unsigned num_draws);810void crocus_launch_grid(struct pipe_context *, const struct pipe_grid_info *);811812/* crocus_pipe_control.c */813814void crocus_emit_pipe_control_flush(struct crocus_batch *batch,815const char *reason, uint32_t flags);816void crocus_emit_pipe_control_write(struct crocus_batch *batch,817const char *reason, uint32_t flags,818struct crocus_bo *bo, uint32_t offset,819uint64_t imm);820void crocus_emit_mi_flush(struct crocus_batch *batch);821void crocus_emit_depth_stall_flushes(struct crocus_batch *batch);822void crocus_emit_post_sync_nonzero_flush(struct crocus_batch *batch);823void crocus_emit_end_of_pipe_sync(struct crocus_batch *batch,824const char *reason, uint32_t flags);825void crocus_flush_all_caches(struct crocus_batch *batch);826827#define crocus_handle_always_flush_cache(batch) \828if (unlikely(batch->screen->driconf.always_flush_cache)) \829crocus_flush_all_caches(batch);830831void crocus_init_flush_functions(struct pipe_context *ctx);832833/* crocus_program.c */834const struct shader_info *crocus_get_shader_info(const struct crocus_context *ice,835gl_shader_stage stage);836struct crocus_bo *crocus_get_scratch_space(struct crocus_context *ice,837unsigned per_thread_scratch,838gl_shader_stage stage);839/**840* Map a <group, index> pair to a binding table index.841*842* For example: <UBO, 5> => binding table index 12843*/844static inline uint32_t crocus_group_index_to_bti(const struct crocus_binding_table *bt,845enum crocus_surface_group group,846uint32_t index)847{848assert(index < bt->sizes[group]);849uint64_t mask = bt->used_mask[group];850uint64_t bit = 1ull << index;851if (bit & mask) {852return bt->offsets[group] + util_bitcount64((bit - 1) & mask);853} else {854return CROCUS_SURFACE_NOT_USED;855}856}857858/**859* Map a binding table index back to a <group, index> pair.860*861* For example: binding table index 12 => <UBO, 5>862*/863static inline uint32_t864crocus_bti_to_group_index(const struct crocus_binding_table *bt,865enum crocus_surface_group group, uint32_t bti)866{867uint64_t used_mask = bt->used_mask[group];868assert(bti >= bt->offsets[group]);869870uint32_t c = bti - bt->offsets[group];871while (used_mask) {872int i = u_bit_scan64(&used_mask);873if (c == 0)874return i;875c--;876}877878return CROCUS_SURFACE_NOT_USED;879}880881882/* crocus_disk_cache.c */883884void crocus_disk_cache_store(struct disk_cache *cache,885const struct crocus_uncompiled_shader *ish,886const struct crocus_compiled_shader *shader,887void *map,888const void *prog_key,889uint32_t prog_key_size);890struct crocus_compiled_shader *891crocus_disk_cache_retrieve(struct crocus_context *ice,892const struct crocus_uncompiled_shader *ish,893const void *prog_key,894uint32_t prog_key_size);895896/* crocus_program_cache.c */897898void crocus_init_program_cache(struct crocus_context *ice);899void crocus_destroy_program_cache(struct crocus_context *ice);900void crocus_print_program_cache(struct crocus_context *ice);901struct crocus_compiled_shader *crocus_find_cached_shader(struct crocus_context *ice,902enum crocus_program_cache_id,903uint32_t key_size,904const void *key);905struct crocus_compiled_shader *crocus_upload_shader(struct crocus_context *ice,906enum crocus_program_cache_id,907uint32_t key_size,908const void *key,909const void *assembly,910uint32_t asm_size,911struct brw_stage_prog_data *,912uint32_t prog_data_size,913uint32_t *streamout,914enum brw_param_builtin *sysv,915unsigned num_system_values,916unsigned num_cbufs,917const struct crocus_binding_table *bt);918const void *crocus_find_previous_compile(const struct crocus_context *ice,919enum crocus_program_cache_id cache_id,920unsigned program_string_id);921bool crocus_blorp_lookup_shader(struct blorp_batch *blorp_batch,922const void *key,923uint32_t key_size,924uint32_t *kernel_out,925void *prog_data_out);926bool crocus_blorp_upload_shader(struct blorp_batch *blorp_batch,927uint32_t stage,928const void *key, uint32_t key_size,929const void *kernel, uint32_t kernel_size,930const struct brw_stage_prog_data *prog_data,931uint32_t prog_data_size,932uint32_t *kernel_out,933void *prog_data_out);934935/* crocus_resolve.c */936937void crocus_predraw_resolve_inputs(struct crocus_context *ice,938struct crocus_batch *batch,939bool *draw_aux_buffer_disabled,940gl_shader_stage stage,941bool consider_framebuffer);942void crocus_predraw_resolve_framebuffer(struct crocus_context *ice,943struct crocus_batch *batch,944bool *draw_aux_buffer_disabled);945void crocus_postdraw_update_resolve_tracking(struct crocus_context *ice,946struct crocus_batch *batch);947void crocus_cache_sets_clear(struct crocus_batch *batch);948void crocus_flush_depth_and_render_caches(struct crocus_batch *batch);949void crocus_cache_flush_for_read(struct crocus_batch *batch, struct crocus_bo *bo);950void crocus_cache_flush_for_render(struct crocus_batch *batch,951struct crocus_bo *bo,952enum isl_format format,953enum isl_aux_usage aux_usage);954void crocus_render_cache_add_bo(struct crocus_batch *batch,955struct crocus_bo *bo,956enum isl_format format,957enum isl_aux_usage aux_usage);958void crocus_cache_flush_for_depth(struct crocus_batch *batch, struct crocus_bo *bo);959void crocus_depth_cache_add_bo(struct crocus_batch *batch, struct crocus_bo *bo);960int crocus_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,961struct pipe_driver_query_info *info);962int crocus_get_driver_query_group_info(struct pipe_screen *pscreen,963unsigned index,964struct pipe_driver_query_group_info *info);965966struct pipe_rasterizer_state *crocus_get_rast_state(struct crocus_context *ctx);967968bool crocus_sw_check_cond_render(struct crocus_context *ice);969static inline bool crocus_check_conditional_render(struct crocus_context *ice)970{971if (ice->state.predicate == CROCUS_PREDICATE_STATE_STALL_FOR_QUERY)972return crocus_sw_check_cond_render(ice);973return ice->state.predicate != CROCUS_PREDICATE_STATE_DONT_RENDER;974}975976#ifdef genX977# include "crocus_genx_protos.h"978#else979# define genX(x) gfx4_##x980# include "crocus_genx_protos.h"981# undef genX982# define genX(x) gfx45_##x983# include "crocus_genx_protos.h"984# undef genX985# define genX(x) gfx5_##x986# include "crocus_genx_protos.h"987# undef genX988# define genX(x) gfx6_##x989# include "crocus_genx_protos.h"990# undef genX991# define genX(x) gfx7_##x992# include "crocus_genx_protos.h"993# undef genX994# define genX(x) gfx75_##x995# include "crocus_genx_protos.h"996# undef genX997# define genX(x) gfx8_##x998# include "crocus_genx_protos.h"999# undef genX1000#endif10011002#endif100310041005