1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * © Copyright 2018 Alyssa Rosenzweig 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#ifndef __BUILDER_H__ 26bf215546Sopenharmony_ci#define __BUILDER_H__ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#define _LARGEFILE64_SOURCE 1 29bf215546Sopenharmony_ci#include <sys/mman.h> 30bf215546Sopenharmony_ci#include <assert.h> 31bf215546Sopenharmony_ci#include "pan_resource.h" 32bf215546Sopenharmony_ci#include "pan_job.h" 33bf215546Sopenharmony_ci#include "pan_blend_cso.h" 34bf215546Sopenharmony_ci#include "pan_encoder.h" 35bf215546Sopenharmony_ci#include "pan_texture.h" 36bf215546Sopenharmony_ci#include "pan_earlyzs.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 39bf215546Sopenharmony_ci#include "pipe/p_config.h" 40bf215546Sopenharmony_ci#include "pipe/p_context.h" 41bf215546Sopenharmony_ci#include "pipe/p_defines.h" 42bf215546Sopenharmony_ci#include "pipe/p_format.h" 43bf215546Sopenharmony_ci#include "pipe/p_screen.h" 44bf215546Sopenharmony_ci#include "pipe/p_state.h" 45bf215546Sopenharmony_ci#include "util/u_blitter.h" 46bf215546Sopenharmony_ci#include "util/hash_table.h" 47bf215546Sopenharmony_ci#include "util/simple_mtx.h" 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci#include "midgard/midgard_compile.h" 50bf215546Sopenharmony_ci#include "compiler/shader_enums.h" 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci#define SET_BIT(lval, bit, cond) \ 53bf215546Sopenharmony_ci if (cond) \ 54bf215546Sopenharmony_ci lval |= (bit); \ 55bf215546Sopenharmony_ci else \ 56bf215546Sopenharmony_ci lval &= ~(bit); 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci/* Dirty tracking flags. 3D is for general 3D state. Shader flags are 59bf215546Sopenharmony_ci * per-stage. Renderer refers to Renderer State Descriptors. Vertex refers to 60bf215546Sopenharmony_ci * vertex attributes/elements. */ 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_cienum pan_dirty_3d { 63bf215546Sopenharmony_ci PAN_DIRTY_VIEWPORT = BITFIELD_BIT(0), 64bf215546Sopenharmony_ci PAN_DIRTY_SCISSOR = BITFIELD_BIT(1), 65bf215546Sopenharmony_ci PAN_DIRTY_VERTEX = BITFIELD_BIT(2), 66bf215546Sopenharmony_ci PAN_DIRTY_PARAMS = BITFIELD_BIT(3), 67bf215546Sopenharmony_ci PAN_DIRTY_DRAWID = BITFIELD_BIT(4), 68bf215546Sopenharmony_ci PAN_DIRTY_TLS_SIZE = BITFIELD_BIT(5), 69bf215546Sopenharmony_ci PAN_DIRTY_ZS = BITFIELD_BIT(6), 70bf215546Sopenharmony_ci PAN_DIRTY_BLEND = BITFIELD_BIT(7), 71bf215546Sopenharmony_ci PAN_DIRTY_MSAA = BITFIELD_BIT(8), 72bf215546Sopenharmony_ci PAN_DIRTY_OQ = BITFIELD_BIT(9), 73bf215546Sopenharmony_ci PAN_DIRTY_RASTERIZER = BITFIELD_BIT(10), 74bf215546Sopenharmony_ci PAN_DIRTY_POINTS = BITFIELD_BIT(11), 75bf215546Sopenharmony_ci PAN_DIRTY_SO = BITFIELD_BIT(12), 76bf215546Sopenharmony_ci}; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_cienum pan_dirty_shader { 79bf215546Sopenharmony_ci PAN_DIRTY_STAGE_SHADER = BITFIELD_BIT(0), 80bf215546Sopenharmony_ci PAN_DIRTY_STAGE_TEXTURE = BITFIELD_BIT(1), 81bf215546Sopenharmony_ci PAN_DIRTY_STAGE_SAMPLER = BITFIELD_BIT(2), 82bf215546Sopenharmony_ci PAN_DIRTY_STAGE_IMAGE = BITFIELD_BIT(3), 83bf215546Sopenharmony_ci PAN_DIRTY_STAGE_CONST = BITFIELD_BIT(4), 84bf215546Sopenharmony_ci PAN_DIRTY_STAGE_SSBO = BITFIELD_BIT(5), 85bf215546Sopenharmony_ci}; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_cistruct panfrost_constant_buffer { 88bf215546Sopenharmony_ci struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS]; 89bf215546Sopenharmony_ci uint32_t enabled_mask; 90bf215546Sopenharmony_ci}; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_cistruct panfrost_query { 93bf215546Sopenharmony_ci /* Passthrough from Gallium */ 94bf215546Sopenharmony_ci unsigned type; 95bf215546Sopenharmony_ci unsigned index; 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci /* For computed queries. 64-bit to prevent overflow */ 98bf215546Sopenharmony_ci struct { 99bf215546Sopenharmony_ci uint64_t start; 100bf215546Sopenharmony_ci uint64_t end; 101bf215546Sopenharmony_ci }; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci /* Memory for the GPU to writeback the value of the query */ 104bf215546Sopenharmony_ci struct pipe_resource *rsrc; 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci /* Whether an occlusion query is for a MSAA framebuffer */ 107bf215546Sopenharmony_ci bool msaa; 108bf215546Sopenharmony_ci}; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_cistruct pipe_fence_handle { 111bf215546Sopenharmony_ci struct pipe_reference reference; 112bf215546Sopenharmony_ci uint32_t syncobj; 113bf215546Sopenharmony_ci bool signaled; 114bf215546Sopenharmony_ci}; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_cistruct panfrost_streamout_target { 117bf215546Sopenharmony_ci struct pipe_stream_output_target base; 118bf215546Sopenharmony_ci uint32_t offset; 119bf215546Sopenharmony_ci}; 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_cistruct panfrost_streamout { 122bf215546Sopenharmony_ci struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS]; 123bf215546Sopenharmony_ci unsigned num_targets; 124bf215546Sopenharmony_ci}; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_cistruct panfrost_context { 127bf215546Sopenharmony_ci /* Gallium context */ 128bf215546Sopenharmony_ci struct pipe_context base; 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci /* Dirty global state */ 131bf215546Sopenharmony_ci enum pan_dirty_3d dirty; 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci /* Per shader stage dirty state */ 134bf215546Sopenharmony_ci enum pan_dirty_shader dirty_shader[PIPE_SHADER_TYPES]; 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci /* Unowned pools, so manage yourself. */ 137bf215546Sopenharmony_ci struct panfrost_pool descs, shaders; 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci /* Sync obj used to keep track of in-flight jobs. */ 140bf215546Sopenharmony_ci uint32_t syncobj; 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci /* Set of 32 batches. When the set is full, the LRU entry (the batch 143bf215546Sopenharmony_ci * with the smallest seqnum) is flushed to free a slot. 144bf215546Sopenharmony_ci */ 145bf215546Sopenharmony_ci struct { 146bf215546Sopenharmony_ci uint64_t seqnum; 147bf215546Sopenharmony_ci struct panfrost_batch slots[PAN_MAX_BATCHES]; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci /** Set of active batches for faster traversal */ 150bf215546Sopenharmony_ci BITSET_DECLARE(active, PAN_MAX_BATCHES); 151bf215546Sopenharmony_ci } batches; 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci /* Map from resources to panfrost_batches */ 154bf215546Sopenharmony_ci struct hash_table *writers; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci /* Bound job batch */ 157bf215546Sopenharmony_ci struct panfrost_batch *batch; 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci /* Within a launch_grid call.. */ 160bf215546Sopenharmony_ci const struct pipe_grid_info *compute_grid; 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci struct pipe_framebuffer_state pipe_framebuffer; 163bf215546Sopenharmony_ci struct panfrost_streamout streamout; 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci bool active_queries; 166bf215546Sopenharmony_ci uint64_t prims_generated; 167bf215546Sopenharmony_ci uint64_t tf_prims_generated; 168bf215546Sopenharmony_ci struct panfrost_query *occlusion_query; 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_ci bool indirect_draw; 171bf215546Sopenharmony_ci unsigned drawid; 172bf215546Sopenharmony_ci unsigned vertex_count; 173bf215546Sopenharmony_ci unsigned instance_count; 174bf215546Sopenharmony_ci unsigned offset_start; 175bf215546Sopenharmony_ci unsigned base_vertex; 176bf215546Sopenharmony_ci unsigned base_instance; 177bf215546Sopenharmony_ci mali_ptr first_vertex_sysval_ptr; 178bf215546Sopenharmony_ci mali_ptr base_vertex_sysval_ptr; 179bf215546Sopenharmony_ci mali_ptr base_instance_sysval_ptr; 180bf215546Sopenharmony_ci enum pipe_prim_type active_prim; 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci /* If instancing is enabled, vertex count padded for instance; if 183bf215546Sopenharmony_ci * it is disabled, just equal to plain vertex count */ 184bf215546Sopenharmony_ci unsigned padded_count; 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci struct panfrost_constant_buffer constant_buffer[PIPE_SHADER_TYPES]; 187bf215546Sopenharmony_ci struct panfrost_rasterizer *rasterizer; 188bf215546Sopenharmony_ci struct panfrost_shader_variants *shader[PIPE_SHADER_TYPES]; 189bf215546Sopenharmony_ci struct panfrost_vertex_state *vertex; 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; 192bf215546Sopenharmony_ci uint32_t vb_mask; 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci struct pipe_shader_buffer ssbo[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS]; 195bf215546Sopenharmony_ci uint32_t ssbo_mask[PIPE_SHADER_TYPES]; 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_ci struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES]; 198bf215546Sopenharmony_ci uint32_t image_mask[PIPE_SHADER_TYPES]; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci struct panfrost_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; 201bf215546Sopenharmony_ci unsigned sampler_count[PIPE_SHADER_TYPES]; 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci struct panfrost_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS]; 204bf215546Sopenharmony_ci unsigned sampler_view_count[PIPE_SHADER_TYPES]; 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci struct blitter_context *blitter; 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci struct panfrost_blend_state *blend; 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci /* On Valhall, does the current blend state use a blend shader for any 211bf215546Sopenharmony_ci * output? We need this information in a hot path to decide if 212bf215546Sopenharmony_ci * per-sample shading should be enabled. 213bf215546Sopenharmony_ci */ 214bf215546Sopenharmony_ci bool valhall_has_blend_shader; 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci struct pipe_viewport_state pipe_viewport; 217bf215546Sopenharmony_ci struct pipe_scissor_state scissor; 218bf215546Sopenharmony_ci struct pipe_blend_color blend_color; 219bf215546Sopenharmony_ci struct panfrost_zsa_state *depth_stencil; 220bf215546Sopenharmony_ci struct pipe_stencil_ref stencil_ref; 221bf215546Sopenharmony_ci uint16_t sample_mask; 222bf215546Sopenharmony_ci unsigned min_samples; 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci struct panfrost_query *cond_query; 225bf215546Sopenharmony_ci bool cond_cond; 226bf215546Sopenharmony_ci enum pipe_render_cond_flag cond_mode; 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci bool is_noop; 229bf215546Sopenharmony_ci 230bf215546Sopenharmony_ci /* Mask of active render targets */ 231bf215546Sopenharmony_ci uint8_t fb_rt_mask; 232bf215546Sopenharmony_ci}; 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci/* Corresponds to the CSO */ 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_cistruct panfrost_rasterizer; 237bf215546Sopenharmony_ci 238bf215546Sopenharmony_ci/* Linked varyings */ 239bf215546Sopenharmony_cistruct pan_linkage { 240bf215546Sopenharmony_ci /* If the upload is owned by the CSO instead 241bf215546Sopenharmony_ci * of the pool, the referenced BO. Else, 242bf215546Sopenharmony_ci * NULL. */ 243bf215546Sopenharmony_ci struct panfrost_bo *bo; 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci /* Uploaded attribute descriptors */ 246bf215546Sopenharmony_ci mali_ptr producer, consumer; 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_ci /* Varyings buffers required */ 249bf215546Sopenharmony_ci uint32_t present; 250bf215546Sopenharmony_ci 251bf215546Sopenharmony_ci /* Per-vertex stride for general varying buffer */ 252bf215546Sopenharmony_ci uint32_t stride; 253bf215546Sopenharmony_ci}; 254bf215546Sopenharmony_ci 255bf215546Sopenharmony_ci#define RSD_WORDS 16 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci/* Variants bundle together to form the backing CSO, bundling multiple 258bf215546Sopenharmony_ci * shaders with varying emulated features baked in 259bf215546Sopenharmony_ci */ 260bf215546Sopenharmony_cistruct panfrost_fs_key { 261bf215546Sopenharmony_ci /* Number of colour buffers */ 262bf215546Sopenharmony_ci unsigned nr_cbufs; 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_ci /* Midgard shaders that read the tilebuffer must be keyed for 265bf215546Sopenharmony_ci * non-blendable formats 266bf215546Sopenharmony_ci */ 267bf215546Sopenharmony_ci enum pipe_format rt_formats[8]; 268bf215546Sopenharmony_ci 269bf215546Sopenharmony_ci /* From rasterize state, to lower point sprites */ 270bf215546Sopenharmony_ci uint16_t sprite_coord_enable; 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci /* User clip plane lowering */ 273bf215546Sopenharmony_ci uint8_t clip_plane_enable; 274bf215546Sopenharmony_ci}; 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_cistruct panfrost_shader_key { 277bf215546Sopenharmony_ci /* Valhall needs special handling for desktop GL varyings */ 278bf215546Sopenharmony_ci uint32_t fixed_varying_mask; 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci /* If we need vertex shader keys, union it in */ 281bf215546Sopenharmony_ci struct panfrost_fs_key fs; 282bf215546Sopenharmony_ci}; 283bf215546Sopenharmony_ci 284bf215546Sopenharmony_ci/* A shader state corresponds to the actual, current variant of the shader */ 285bf215546Sopenharmony_cistruct panfrost_shader_state { 286bf215546Sopenharmony_ci /* Respectively, shader binary and Renderer State Descriptor */ 287bf215546Sopenharmony_ci struct panfrost_pool_ref bin, state; 288bf215546Sopenharmony_ci 289bf215546Sopenharmony_ci /* For fragment shaders, a prepared (but not uploaded RSD) */ 290bf215546Sopenharmony_ci uint32_t partial_rsd[RSD_WORDS]; 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_ci struct pan_shader_info info; 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci struct pan_earlyzs_lut earlyzs; 295bf215546Sopenharmony_ci 296bf215546Sopenharmony_ci /* Attached transform feedback program, if one exists */ 297bf215546Sopenharmony_ci struct panfrost_shader_state *xfb; 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_ci /* Linked varyings, for non-separable programs */ 300bf215546Sopenharmony_ci struct pan_linkage linkage; 301bf215546Sopenharmony_ci 302bf215546Sopenharmony_ci struct pipe_stream_output_info stream_output; 303bf215546Sopenharmony_ci uint64_t so_mask; 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci struct panfrost_shader_key key; 306bf215546Sopenharmony_ci 307bf215546Sopenharmony_ci /* Mask of state that dirties the sysvals */ 308bf215546Sopenharmony_ci unsigned dirty_3d, dirty_shader; 309bf215546Sopenharmony_ci}; 310bf215546Sopenharmony_ci 311bf215546Sopenharmony_ci/* A collection of varyings (the CSO) */ 312bf215546Sopenharmony_cistruct panfrost_shader_variants { 313bf215546Sopenharmony_ci nir_shader *nir; 314bf215546Sopenharmony_ci 315bf215546Sopenharmony_ci union { 316bf215546Sopenharmony_ci struct pipe_stream_output_info stream_output; 317bf215546Sopenharmony_ci unsigned req_input_mem; 318bf215546Sopenharmony_ci }; 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ci /** Lock for the variants array */ 321bf215546Sopenharmony_ci simple_mtx_t lock; 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_ci struct panfrost_shader_state *variants; 324bf215546Sopenharmony_ci unsigned variant_space; 325bf215546Sopenharmony_ci 326bf215546Sopenharmony_ci unsigned variant_count; 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_ci /* On vertex shaders, bit mask of special desktop-only varyings to link 329bf215546Sopenharmony_ci * with the fragment shader. Used on Valhall to implement separable 330bf215546Sopenharmony_ci * shaders for desktop GL. 331bf215546Sopenharmony_ci */ 332bf215546Sopenharmony_ci uint32_t fixed_varying_mask; 333bf215546Sopenharmony_ci 334bf215546Sopenharmony_ci /* The current active variant */ 335bf215546Sopenharmony_ci unsigned active_variant; 336bf215546Sopenharmony_ci}; 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci/** (Vertex buffer index, divisor) tuple that will become an Attribute Buffer 339bf215546Sopenharmony_ci * Descriptor at draw-time on Midgard 340bf215546Sopenharmony_ci */ 341bf215546Sopenharmony_cistruct pan_vertex_buffer { 342bf215546Sopenharmony_ci unsigned vbi; 343bf215546Sopenharmony_ci unsigned divisor; 344bf215546Sopenharmony_ci}; 345bf215546Sopenharmony_ci 346bf215546Sopenharmony_ciunsigned 347bf215546Sopenharmony_cipan_assign_vertex_buffer(struct pan_vertex_buffer *buffers, 348bf215546Sopenharmony_ci unsigned *nr_bufs, 349bf215546Sopenharmony_ci unsigned vbi, 350bf215546Sopenharmony_ci unsigned divisor); 351bf215546Sopenharmony_ci 352bf215546Sopenharmony_cistruct panfrost_zsa_state; 353bf215546Sopenharmony_cistruct panfrost_sampler_state; 354bf215546Sopenharmony_cistruct panfrost_sampler_view; 355bf215546Sopenharmony_cistruct panfrost_vertex_state; 356bf215546Sopenharmony_ci 357bf215546Sopenharmony_cistatic inline struct panfrost_context * 358bf215546Sopenharmony_cipan_context(struct pipe_context *pcontext) 359bf215546Sopenharmony_ci{ 360bf215546Sopenharmony_ci return (struct panfrost_context *) pcontext; 361bf215546Sopenharmony_ci} 362bf215546Sopenharmony_ci 363bf215546Sopenharmony_cistatic inline struct panfrost_streamout_target * 364bf215546Sopenharmony_cipan_so_target(struct pipe_stream_output_target *target) 365bf215546Sopenharmony_ci{ 366bf215546Sopenharmony_ci return (struct panfrost_streamout_target *)target; 367bf215546Sopenharmony_ci} 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_cistatic inline struct panfrost_shader_state * 370bf215546Sopenharmony_cipanfrost_get_shader_state(struct panfrost_context *ctx, 371bf215546Sopenharmony_ci enum pipe_shader_type st) 372bf215546Sopenharmony_ci{ 373bf215546Sopenharmony_ci struct panfrost_shader_variants *all = ctx->shader[st]; 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ci if (!all) 376bf215546Sopenharmony_ci return NULL; 377bf215546Sopenharmony_ci 378bf215546Sopenharmony_ci return &all->variants[all->active_variant]; 379bf215546Sopenharmony_ci} 380bf215546Sopenharmony_ci 381bf215546Sopenharmony_cistruct pipe_context * 382bf215546Sopenharmony_cipanfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags); 383bf215546Sopenharmony_ci 384bf215546Sopenharmony_cibool 385bf215546Sopenharmony_cipanfrost_writes_point_size(struct panfrost_context *ctx); 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_cistruct panfrost_ptr 388bf215546Sopenharmony_cipanfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler); 389bf215546Sopenharmony_ci 390bf215546Sopenharmony_civoid 391bf215546Sopenharmony_cipanfrost_flush( 392bf215546Sopenharmony_ci struct pipe_context *pipe, 393bf215546Sopenharmony_ci struct pipe_fence_handle **fence, 394bf215546Sopenharmony_ci unsigned flags); 395bf215546Sopenharmony_ci 396bf215546Sopenharmony_cibool 397bf215546Sopenharmony_cipanfrost_render_condition_check(struct panfrost_context *ctx); 398bf215546Sopenharmony_ci 399bf215546Sopenharmony_civoid 400bf215546Sopenharmony_cipanfrost_update_shader_variant(struct panfrost_context *ctx, 401bf215546Sopenharmony_ci enum pipe_shader_type type); 402bf215546Sopenharmony_civoid 403bf215546Sopenharmony_cipanfrost_shader_compile(struct pipe_screen *pscreen, 404bf215546Sopenharmony_ci struct panfrost_pool *shader_pool, 405bf215546Sopenharmony_ci struct panfrost_pool *desc_pool, 406bf215546Sopenharmony_ci const nir_shader *ir, 407bf215546Sopenharmony_ci struct panfrost_shader_state *state); 408bf215546Sopenharmony_ci 409bf215546Sopenharmony_civoid 410bf215546Sopenharmony_cipanfrost_analyze_sysvals(struct panfrost_shader_state *ss); 411bf215546Sopenharmony_ci 412bf215546Sopenharmony_cimali_ptr 413bf215546Sopenharmony_cipanfrost_get_index_buffer(struct panfrost_batch *batch, 414bf215546Sopenharmony_ci const struct pipe_draw_info *info, 415bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw); 416bf215546Sopenharmony_ci 417bf215546Sopenharmony_cimali_ptr 418bf215546Sopenharmony_cipanfrost_get_index_buffer_bounded(struct panfrost_batch *batch, 419bf215546Sopenharmony_ci const struct pipe_draw_info *info, 420bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw, 421bf215546Sopenharmony_ci unsigned *min_index, unsigned *max_index); 422bf215546Sopenharmony_ci 423bf215546Sopenharmony_ci/* Instancing */ 424bf215546Sopenharmony_ci 425bf215546Sopenharmony_cimali_ptr 426bf215546Sopenharmony_cipanfrost_vertex_buffer_address(struct panfrost_context *ctx, unsigned i); 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_ci/* Compute */ 429bf215546Sopenharmony_ci 430bf215546Sopenharmony_civoid 431bf215546Sopenharmony_cipanfrost_compute_context_init(struct pipe_context *pctx); 432bf215546Sopenharmony_ci 433bf215546Sopenharmony_cistatic inline void 434bf215546Sopenharmony_cipanfrost_dirty_state_all(struct panfrost_context *ctx) 435bf215546Sopenharmony_ci{ 436bf215546Sopenharmony_ci ctx->dirty = ~0; 437bf215546Sopenharmony_ci 438bf215546Sopenharmony_ci for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) 439bf215546Sopenharmony_ci ctx->dirty_shader[i] = ~0; 440bf215546Sopenharmony_ci} 441bf215546Sopenharmony_ci 442bf215546Sopenharmony_cistatic inline void 443bf215546Sopenharmony_cipanfrost_clean_state_3d(struct panfrost_context *ctx) 444bf215546Sopenharmony_ci{ 445bf215546Sopenharmony_ci ctx->dirty = 0; 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_ci for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) { 448bf215546Sopenharmony_ci if (i != PIPE_SHADER_COMPUTE) 449bf215546Sopenharmony_ci ctx->dirty_shader[i] = 0; 450bf215546Sopenharmony_ci } 451bf215546Sopenharmony_ci} 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_civoid 454bf215546Sopenharmony_cipanfrost_set_batch_masks_blend(struct panfrost_batch *batch); 455bf215546Sopenharmony_ci 456bf215546Sopenharmony_civoid 457bf215546Sopenharmony_cipanfrost_set_batch_masks_zs(struct panfrost_batch *batch); 458bf215546Sopenharmony_ci 459bf215546Sopenharmony_civoid 460bf215546Sopenharmony_cipanfrost_track_image_access(struct panfrost_batch *batch, 461bf215546Sopenharmony_ci enum pipe_shader_type stage, 462bf215546Sopenharmony_ci struct pipe_image_view *image); 463bf215546Sopenharmony_ci 464bf215546Sopenharmony_ci#endif 465