1af69d88dSmrg/* 2af69d88dSmrg * Copyright © 2014 Broadcom 3af69d88dSmrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 4af69d88dSmrg * 5af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 6af69d88dSmrg * copy of this software and associated documentation files (the "Software"), 7af69d88dSmrg * to deal in the Software without restriction, including without limitation 8af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the 10af69d88dSmrg * Software is furnished to do so, subject to the following conditions: 11af69d88dSmrg * 12af69d88dSmrg * The above copyright notice and this permission notice (including the next 13af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the 14af69d88dSmrg * Software. 15af69d88dSmrg * 16af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20af69d88dSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21af69d88dSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22af69d88dSmrg * IN THE SOFTWARE. 23af69d88dSmrg */ 24af69d88dSmrg 25af69d88dSmrg#ifndef VC4_CONTEXT_H 26af69d88dSmrg#define VC4_CONTEXT_H 27af69d88dSmrg 2801e04c3fSmrg#include <stdio.h> 2901e04c3fSmrg 30af69d88dSmrg#include "pipe/p_context.h" 31af69d88dSmrg#include "pipe/p_state.h" 3201e04c3fSmrg#include "util/slab.h" 3301e04c3fSmrg#include "xf86drm.h" 34af69d88dSmrg 35af69d88dSmrg#define __user 369f464c52Smaya#include "drm-uapi/vc4_drm.h" 37af69d88dSmrg#include "vc4_bufmgr.h" 38af69d88dSmrg#include "vc4_resource.h" 39af69d88dSmrg#include "vc4_cl.h" 40af69d88dSmrg#include "vc4_qir.h" 41af69d88dSmrg 4201e04c3fSmrg#ifndef DRM_VC4_PARAM_SUPPORTS_ETC1 4301e04c3fSmrg#define DRM_VC4_PARAM_SUPPORTS_ETC1 4 4401e04c3fSmrg#endif 4501e04c3fSmrg#ifndef DRM_VC4_PARAM_SUPPORTS_THREADED_FS 4601e04c3fSmrg#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5 4701e04c3fSmrg#endif 4801e04c3fSmrg 4901e04c3fSmrg#ifdef USE_VC4_SIMULATOR 5001e04c3fSmrg#define using_vc4_simulator true 5101e04c3fSmrg#else 5201e04c3fSmrg#define using_vc4_simulator false 5301e04c3fSmrg#endif 5401e04c3fSmrg 55af69d88dSmrg#define VC4_DIRTY_BLEND (1 << 0) 56af69d88dSmrg#define VC4_DIRTY_RASTERIZER (1 << 1) 57af69d88dSmrg#define VC4_DIRTY_ZSA (1 << 2) 58af69d88dSmrg#define VC4_DIRTY_FRAGTEX (1 << 3) 59af69d88dSmrg#define VC4_DIRTY_VERTTEX (1 << 4) 6001e04c3fSmrg 61af69d88dSmrg#define VC4_DIRTY_BLEND_COLOR (1 << 7) 62af69d88dSmrg#define VC4_DIRTY_STENCIL_REF (1 << 8) 63af69d88dSmrg#define VC4_DIRTY_SAMPLE_MASK (1 << 9) 64af69d88dSmrg#define VC4_DIRTY_FRAMEBUFFER (1 << 10) 65af69d88dSmrg#define VC4_DIRTY_STIPPLE (1 << 11) 66af69d88dSmrg#define VC4_DIRTY_VIEWPORT (1 << 12) 67af69d88dSmrg#define VC4_DIRTY_CONSTBUF (1 << 13) 68af69d88dSmrg#define VC4_DIRTY_VTXSTATE (1 << 14) 69af69d88dSmrg#define VC4_DIRTY_VTXBUF (1 << 15) 7001e04c3fSmrg 71af69d88dSmrg#define VC4_DIRTY_SCISSOR (1 << 17) 7201e04c3fSmrg#define VC4_DIRTY_FLAT_SHADE_FLAGS (1 << 18) 7301e04c3fSmrg#define VC4_DIRTY_PRIM_MODE (1 << 19) 7401e04c3fSmrg#define VC4_DIRTY_CLIP (1 << 20) 7501e04c3fSmrg#define VC4_DIRTY_UNCOMPILED_VS (1 << 21) 7601e04c3fSmrg#define VC4_DIRTY_UNCOMPILED_FS (1 << 22) 7701e04c3fSmrg#define VC4_DIRTY_COMPILED_CS (1 << 23) 7801e04c3fSmrg#define VC4_DIRTY_COMPILED_VS (1 << 24) 7901e04c3fSmrg#define VC4_DIRTY_COMPILED_FS (1 << 25) 8001e04c3fSmrg#define VC4_DIRTY_FS_INPUTS (1 << 26) 8101e04c3fSmrg#define VC4_DIRTY_UBO_1_SIZE (1 << 27) 8201e04c3fSmrg 8301e04c3fSmrgstruct vc4_sampler_view { 8401e04c3fSmrg struct pipe_sampler_view base; 8501e04c3fSmrg uint32_t texture_p0; 8601e04c3fSmrg uint32_t texture_p1; 8701e04c3fSmrg bool force_first_level; 8801e04c3fSmrg /** 8901e04c3fSmrg * Resource containing the actual texture that will be sampled. 9001e04c3fSmrg * 9101e04c3fSmrg * We may need to rebase the .base.texture resource to work around the 9201e04c3fSmrg * lack of GL_TEXTURE_BASE_LEVEL, or to upload the texture as tiled. 9301e04c3fSmrg */ 9401e04c3fSmrg struct pipe_resource *texture; 9501e04c3fSmrg}; 96af69d88dSmrg 9701e04c3fSmrgstruct vc4_sampler_state { 9801e04c3fSmrg struct pipe_sampler_state base; 9901e04c3fSmrg uint32_t texture_p1; 10001e04c3fSmrg}; 101af69d88dSmrg 102af69d88dSmrgstruct vc4_texture_stateobj { 103af69d88dSmrg struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS]; 104af69d88dSmrg unsigned num_textures; 105af69d88dSmrg struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; 106af69d88dSmrg unsigned num_samplers; 107af69d88dSmrg}; 108af69d88dSmrg 109af69d88dSmrgstruct vc4_shader_uniform_info { 110af69d88dSmrg enum quniform_contents *contents; 111af69d88dSmrg uint32_t *data; 112af69d88dSmrg uint32_t count; 113af69d88dSmrg uint32_t num_texture_samples; 114af69d88dSmrg}; 115af69d88dSmrg 11601e04c3fSmrgstruct vc4_uncompiled_shader { 11701e04c3fSmrg /** A name for this program, so you can track it in shader-db output. */ 11801e04c3fSmrg uint32_t program_id; 11901e04c3fSmrg /** How many variants of this program were compiled, for shader-db. */ 12001e04c3fSmrg uint32_t compiled_variant_count; 12101e04c3fSmrg struct pipe_shader_state base; 12201e04c3fSmrg}; 12301e04c3fSmrg 12401e04c3fSmrgstruct vc4_fs_inputs { 12501e04c3fSmrg /** 12601e04c3fSmrg * Array of the meanings of the VPM inputs this shader needs. 12701e04c3fSmrg * 12801e04c3fSmrg * It doesn't include those that aren't part of the VPM, like 12901e04c3fSmrg * point/line coordinates. 13001e04c3fSmrg */ 13101e04c3fSmrg struct vc4_varying_slot *input_slots; 13201e04c3fSmrg uint32_t num_inputs; 13301e04c3fSmrg}; 13401e04c3fSmrg 135af69d88dSmrgstruct vc4_compiled_shader { 13601e04c3fSmrg uint64_t program_id; 137af69d88dSmrg struct vc4_bo *bo; 138af69d88dSmrg 13901e04c3fSmrg struct vc4_shader_uniform_info uniforms; 14001e04c3fSmrg 14101e04c3fSmrg /** 14201e04c3fSmrg * VC4_DIRTY_* flags that, when set in vc4->dirty, mean that the 14301e04c3fSmrg * uniforms have to be rewritten (and therefore the shader state 14401e04c3fSmrg * reemitted). 14501e04c3fSmrg */ 14601e04c3fSmrg uint32_t uniform_dirty_bits; 14701e04c3fSmrg 14801e04c3fSmrg /** bitmask of which inputs are color inputs, for flat shade handling. */ 14901e04c3fSmrg uint32_t color_inputs; 15001e04c3fSmrg 15101e04c3fSmrg bool disable_early_z; 15201e04c3fSmrg 15301e04c3fSmrg /* Set if the compile failed, likely due to register allocation 15401e04c3fSmrg * failure. In this case, we have no shader to run and should not try 15501e04c3fSmrg * to do any draws. 15601e04c3fSmrg */ 15701e04c3fSmrg bool failed; 15801e04c3fSmrg 15901e04c3fSmrg bool fs_threaded; 160af69d88dSmrg 161af69d88dSmrg uint8_t num_inputs; 16201e04c3fSmrg 16301e04c3fSmrg /* Byte offsets for the start of the vertex attributes 0-7, and the 16401e04c3fSmrg * total size as "attribute" 8. 16501e04c3fSmrg */ 16601e04c3fSmrg uint8_t vattr_offsets[9]; 16701e04c3fSmrg uint8_t vattrs_live; 16801e04c3fSmrg 16901e04c3fSmrg const struct vc4_fs_inputs *fs_inputs; 170af69d88dSmrg}; 171af69d88dSmrg 172af69d88dSmrgstruct vc4_program_stateobj { 17301e04c3fSmrg struct vc4_uncompiled_shader *bind_vs, *bind_fs; 17401e04c3fSmrg struct vc4_compiled_shader *cs, *vs, *fs; 175af69d88dSmrg}; 176af69d88dSmrg 177af69d88dSmrgstruct vc4_constbuf_stateobj { 178af69d88dSmrg struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS]; 179af69d88dSmrg uint32_t enabled_mask; 180af69d88dSmrg uint32_t dirty_mask; 181af69d88dSmrg}; 182af69d88dSmrg 183af69d88dSmrgstruct vc4_vertexbuf_stateobj { 184af69d88dSmrg struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS]; 185af69d88dSmrg unsigned count; 186af69d88dSmrg uint32_t enabled_mask; 187af69d88dSmrg uint32_t dirty_mask; 188af69d88dSmrg}; 189af69d88dSmrg 190af69d88dSmrgstruct vc4_vertex_stateobj { 191af69d88dSmrg struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS]; 192af69d88dSmrg unsigned num_elements; 193af69d88dSmrg}; 194af69d88dSmrg 19501e04c3fSmrg/* Hash table key for vc4->jobs */ 19601e04c3fSmrgstruct vc4_job_key { 19701e04c3fSmrg struct pipe_surface *cbuf; 19801e04c3fSmrg struct pipe_surface *zsbuf; 19901e04c3fSmrg}; 200af69d88dSmrg 20101e04c3fSmrgstruct vc4_hwperfmon { 20201e04c3fSmrg uint32_t id; 20301e04c3fSmrg uint64_t last_seqno; 20401e04c3fSmrg uint8_t events[DRM_VC4_MAX_PERF_COUNTERS]; 20501e04c3fSmrg uint64_t counters[DRM_VC4_MAX_PERF_COUNTERS]; 20601e04c3fSmrg}; 207af69d88dSmrg 20801e04c3fSmrg/** 20901e04c3fSmrg * A complete bin/render job. 21001e04c3fSmrg * 21101e04c3fSmrg * This is all of the state necessary to submit a bin/render to the kernel. 21201e04c3fSmrg * We want to be able to have multiple in progress at a time, so that we don't 21301e04c3fSmrg * need to flush an existing CL just to switch to rendering to a new render 21401e04c3fSmrg * target (which would mean reading back from the old render target when 21501e04c3fSmrg * starting to render to it again). 21601e04c3fSmrg */ 21701e04c3fSmrgstruct vc4_job { 218af69d88dSmrg struct vc4_cl bcl; 219af69d88dSmrg struct vc4_cl shader_rec; 220af69d88dSmrg struct vc4_cl uniforms; 221af69d88dSmrg struct vc4_cl bo_handles; 222af69d88dSmrg struct vc4_cl bo_pointers; 223af69d88dSmrg uint32_t shader_rec_count; 22401e04c3fSmrg /** 22501e04c3fSmrg * Amount of memory used by the BOs in bo_pointers. 22601e04c3fSmrg * 22701e04c3fSmrg * Used for checking when we should flush the job early so we don't 22801e04c3fSmrg * OOM. 22901e04c3fSmrg */ 23001e04c3fSmrg uint32_t bo_space; 23101e04c3fSmrg 23201e04c3fSmrg /* Last BO hindex referenced from VC4_PACKET_GEM_HANDLES. */ 23301e04c3fSmrg uint32_t last_gem_handle_hindex; 23401e04c3fSmrg 23501e04c3fSmrg /** @{ Surfaces to submit rendering for. */ 23601e04c3fSmrg struct pipe_surface *color_read; 23701e04c3fSmrg struct pipe_surface *color_write; 23801e04c3fSmrg struct pipe_surface *zs_read; 23901e04c3fSmrg struct pipe_surface *zs_write; 24001e04c3fSmrg struct pipe_surface *msaa_color_write; 24101e04c3fSmrg struct pipe_surface *msaa_zs_write; 24201e04c3fSmrg /** @} */ 24301e04c3fSmrg /** @{ 24401e04c3fSmrg * Bounding box of the scissor across all queued drawing. 24501e04c3fSmrg * 24601e04c3fSmrg * Note that the max values are exclusive. 24701e04c3fSmrg */ 24801e04c3fSmrg uint32_t draw_min_x; 24901e04c3fSmrg uint32_t draw_min_y; 25001e04c3fSmrg uint32_t draw_max_x; 25101e04c3fSmrg uint32_t draw_max_y; 25201e04c3fSmrg /** @} */ 25301e04c3fSmrg /** @{ 25401e04c3fSmrg * Width/height of the color framebuffer being rendered to, 25501e04c3fSmrg * for VC4_TILE_RENDERING_MODE_CONFIG. 25601e04c3fSmrg */ 25701e04c3fSmrg uint32_t draw_width; 25801e04c3fSmrg uint32_t draw_height; 25901e04c3fSmrg /** @} */ 26001e04c3fSmrg /** @{ Tile information, depending on MSAA and float color buffer. */ 26101e04c3fSmrg uint32_t draw_tiles_x; /** @< Number of tiles wide for framebuffer. */ 26201e04c3fSmrg uint32_t draw_tiles_y; /** @< Number of tiles high for framebuffer. */ 263af69d88dSmrg 26401e04c3fSmrg uint32_t tile_width; /** @< Width of a tile. */ 26501e04c3fSmrg uint32_t tile_height; /** @< Height of a tile. */ 26601e04c3fSmrg /** Whether the current rendering is in a 4X MSAA tile buffer. */ 26701e04c3fSmrg bool msaa; 26801e04c3fSmrg /** @} */ 269af69d88dSmrg 270af69d88dSmrg /* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the 271af69d88dSmrg * first rendering. 272af69d88dSmrg */ 273af69d88dSmrg uint32_t cleared; 274af69d88dSmrg /* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to 275af69d88dSmrg * (either clears or draws). 276af69d88dSmrg */ 277af69d88dSmrg uint32_t resolve; 278af69d88dSmrg uint32_t clear_color[2]; 279af69d88dSmrg uint32_t clear_depth; /**< 24-bit unorm depth */ 28001e04c3fSmrg uint8_t clear_stencil; 281af69d88dSmrg 282af69d88dSmrg /** 283af69d88dSmrg * Set if some drawing (triangles, blits, or just a glClear()) has 284af69d88dSmrg * been done to the FBO, meaning that we need to 285af69d88dSmrg * DRM_IOCTL_VC4_SUBMIT_CL. 286af69d88dSmrg */ 287af69d88dSmrg bool needs_flush; 288af69d88dSmrg 289af69d88dSmrg /** 29001e04c3fSmrg * Number of draw calls (not counting full buffer clears) queued in 29101e04c3fSmrg * the current job. 292af69d88dSmrg */ 29301e04c3fSmrg uint32_t draw_calls_queued; 29401e04c3fSmrg 29501e04c3fSmrg /** Any flags to be passed in drm_vc4_submit_cl.flags. */ 29601e04c3fSmrg uint32_t flags; 29701e04c3fSmrg 29801e04c3fSmrg /* Performance monitor attached to this job. */ 29901e04c3fSmrg struct vc4_hwperfmon *perfmon; 30001e04c3fSmrg 30101e04c3fSmrg struct vc4_job_key key; 30201e04c3fSmrg}; 30301e04c3fSmrg 30401e04c3fSmrgstruct vc4_context { 30501e04c3fSmrg struct pipe_context base; 30601e04c3fSmrg 30701e04c3fSmrg int fd; 30801e04c3fSmrg struct vc4_screen *screen; 30901e04c3fSmrg 31001e04c3fSmrg /** The 3D rendering job for the currently bound FBO. */ 31101e04c3fSmrg struct vc4_job *job; 31201e04c3fSmrg 31301e04c3fSmrg /* Map from struct vc4_job_key to the job for that FBO. 31401e04c3fSmrg */ 31501e04c3fSmrg struct hash_table *jobs; 31601e04c3fSmrg 31701e04c3fSmrg /** 31801e04c3fSmrg * Map from vc4_resource to a job writing to that resource. 31901e04c3fSmrg * 32001e04c3fSmrg * Primarily for flushing jobs rendering to textures that are now 32101e04c3fSmrg * being read from. 32201e04c3fSmrg */ 32301e04c3fSmrg struct hash_table *write_jobs; 32401e04c3fSmrg 32501e04c3fSmrg struct slab_child_pool transfer_pool; 32601e04c3fSmrg struct blitter_context *blitter; 32701e04c3fSmrg 32801e04c3fSmrg /** bitfield of VC4_DIRTY_* */ 32901e04c3fSmrg uint32_t dirty; 330af69d88dSmrg 33101e04c3fSmrg struct hash_table *fs_cache, *vs_cache; 33201e04c3fSmrg struct set *fs_inputs_set; 33301e04c3fSmrg uint32_t next_uncompiled_program_id; 33401e04c3fSmrg uint64_t next_compiled_program_id; 33501e04c3fSmrg 33601e04c3fSmrg struct ra_regs *regs; 3377ec681f3Smrg struct ra_class *reg_class_any[2]; 3387ec681f3Smrg struct ra_class *reg_class_a_or_b[2]; 3397ec681f3Smrg struct ra_class *reg_class_a_or_b_or_acc[2]; 3407ec681f3Smrg struct ra_class *reg_class_r0_r3; 3417ec681f3Smrg struct ra_class *reg_class_r4_or_a[2]; 3427ec681f3Smrg struct ra_class *reg_class_a[2]; 34301e04c3fSmrg 34401e04c3fSmrg uint8_t prim_mode; 34501e04c3fSmrg 34601e04c3fSmrg /** Maximum index buffer valid for the current shader_rec. */ 34701e04c3fSmrg uint32_t max_index; 34801e04c3fSmrg /** Last index bias baked into the current shader_rec. */ 34901e04c3fSmrg uint32_t last_index_bias; 35001e04c3fSmrg 35101e04c3fSmrg /** Seqno of the last CL flush's job. */ 35201e04c3fSmrg uint64_t last_emit_seqno; 35301e04c3fSmrg 35401e04c3fSmrg struct u_upload_mgr *uploader; 35501e04c3fSmrg 35601e04c3fSmrg struct pipe_shader_state *yuv_linear_blit_vs; 35701e04c3fSmrg struct pipe_shader_state *yuv_linear_blit_fs_8bit; 35801e04c3fSmrg struct pipe_shader_state *yuv_linear_blit_fs_16bit; 359af69d88dSmrg 360af69d88dSmrg /** @{ Current pipeline state objects */ 361af69d88dSmrg struct pipe_scissor_state scissor; 362af69d88dSmrg struct pipe_blend_state *blend; 363af69d88dSmrg struct vc4_rasterizer_state *rasterizer; 364af69d88dSmrg struct vc4_depth_stencil_alpha_state *zsa; 365af69d88dSmrg 366af69d88dSmrg struct vc4_texture_stateobj verttex, fragtex; 367af69d88dSmrg 368af69d88dSmrg struct vc4_program_stateobj prog; 369af69d88dSmrg 370af69d88dSmrg struct vc4_vertex_stateobj *vtx; 371af69d88dSmrg 37201e04c3fSmrg struct { 37301e04c3fSmrg struct pipe_blend_color f; 37401e04c3fSmrg uint8_t ub[4]; 37501e04c3fSmrg } blend_color; 376af69d88dSmrg struct pipe_stencil_ref stencil_ref; 377af69d88dSmrg unsigned sample_mask; 378af69d88dSmrg struct pipe_framebuffer_state framebuffer; 379af69d88dSmrg struct pipe_poly_stipple stipple; 38001e04c3fSmrg struct pipe_clip_state clip; 381af69d88dSmrg struct pipe_viewport_state viewport; 382af69d88dSmrg struct vc4_constbuf_stateobj constbuf[PIPE_SHADER_TYPES]; 383af69d88dSmrg struct vc4_vertexbuf_stateobj vertexbuf; 3849f464c52Smaya struct pipe_debug_callback debug; 38501e04c3fSmrg 38601e04c3fSmrg struct vc4_hwperfmon *perfmon; 387af69d88dSmrg /** @} */ 38801e04c3fSmrg 38901e04c3fSmrg /** Handle of syncobj containing the last submitted job fence. */ 39001e04c3fSmrg uint32_t job_syncobj; 39101e04c3fSmrg 39201e04c3fSmrg int in_fence_fd; 39301e04c3fSmrg /** Handle of the syncobj that holds in_fence_fd for submission. */ 39401e04c3fSmrg uint32_t in_syncobj; 395af69d88dSmrg}; 396af69d88dSmrg 397af69d88dSmrgstruct vc4_rasterizer_state { 398af69d88dSmrg struct pipe_rasterizer_state base; 399af69d88dSmrg 400af69d88dSmrg /* VC4_CONFIGURATION_BITS */ 40101e04c3fSmrg uint8_t config_bits[V3D21_CONFIGURATION_BITS_length]; 40201e04c3fSmrg 40301e04c3fSmrg struct PACKED { 40401e04c3fSmrg uint8_t depth_offset[V3D21_DEPTH_OFFSET_length]; 40501e04c3fSmrg uint8_t point_size[V3D21_POINT_SIZE_length]; 40601e04c3fSmrg uint8_t line_width[V3D21_LINE_WIDTH_length]; 40701e04c3fSmrg } packed; 408af69d88dSmrg 40901e04c3fSmrg /** Raster order flags to be passed in struct drm_vc4_submit_cl.flags. */ 41001e04c3fSmrg uint32_t tile_raster_order_flags; 411af69d88dSmrg}; 412af69d88dSmrg 413af69d88dSmrgstruct vc4_depth_stencil_alpha_state { 414af69d88dSmrg struct pipe_depth_stencil_alpha_state base; 415af69d88dSmrg 416af69d88dSmrg /* VC4_CONFIGURATION_BITS */ 41701e04c3fSmrg uint8_t config_bits[V3D21_CONFIGURATION_BITS_length]; 41801e04c3fSmrg 41901e04c3fSmrg /** Uniforms for stencil state. 42001e04c3fSmrg * 42101e04c3fSmrg * Index 0 is either the front config, or the front-and-back config. 42201e04c3fSmrg * Index 1 is the back config if doing separate back stencil. 42301e04c3fSmrg * Index 2 is the writemask config if it's not a common mask value. 42401e04c3fSmrg */ 42501e04c3fSmrg uint32_t stencil_uniforms[3]; 426af69d88dSmrg}; 427af69d88dSmrg 42801e04c3fSmrg#define perf_debug(...) do { \ 42901e04c3fSmrg if (unlikely(vc4_debug & VC4_DEBUG_PERF)) \ 43001e04c3fSmrg fprintf(stderr, __VA_ARGS__); \ 4319f464c52Smaya if (unlikely(vc4->debug.debug_message)) \ 4329f464c52Smaya pipe_debug_message(&vc4->debug, PERF_INFO, __VA_ARGS__); \ 43301e04c3fSmrg} while (0) 43401e04c3fSmrg 435af69d88dSmrgstatic inline struct vc4_context * 436af69d88dSmrgvc4_context(struct pipe_context *pcontext) 437af69d88dSmrg{ 438af69d88dSmrg return (struct vc4_context *)pcontext; 439af69d88dSmrg} 440af69d88dSmrg 44101e04c3fSmrgstatic inline struct vc4_sampler_view * 44201e04c3fSmrgvc4_sampler_view(struct pipe_sampler_view *psview) 44301e04c3fSmrg{ 44401e04c3fSmrg return (struct vc4_sampler_view *)psview; 44501e04c3fSmrg} 44601e04c3fSmrg 44701e04c3fSmrgstatic inline struct vc4_sampler_state * 44801e04c3fSmrgvc4_sampler_state(struct pipe_sampler_state *psampler) 44901e04c3fSmrg{ 45001e04c3fSmrg return (struct vc4_sampler_state *)psampler; 45101e04c3fSmrg} 45201e04c3fSmrg 45301e04c3fSmrgint vc4_get_driver_query_group_info(struct pipe_screen *pscreen, 45401e04c3fSmrg unsigned index, 45501e04c3fSmrg struct pipe_driver_query_group_info *info); 45601e04c3fSmrgint vc4_get_driver_query_info(struct pipe_screen *pscreen, unsigned index, 45701e04c3fSmrg struct pipe_driver_query_info *info); 45801e04c3fSmrg 459af69d88dSmrgstruct pipe_context *vc4_context_create(struct pipe_screen *pscreen, 46001e04c3fSmrg void *priv, unsigned flags); 461af69d88dSmrgvoid vc4_draw_init(struct pipe_context *pctx); 462af69d88dSmrgvoid vc4_state_init(struct pipe_context *pctx); 463af69d88dSmrgvoid vc4_program_init(struct pipe_context *pctx); 46401e04c3fSmrgvoid vc4_program_fini(struct pipe_context *pctx); 46501e04c3fSmrgvoid vc4_query_init(struct pipe_context *pctx); 466af69d88dSmrgvoid vc4_simulator_init(struct vc4_screen *screen); 46701e04c3fSmrgvoid vc4_simulator_destroy(struct vc4_screen *screen); 46801e04c3fSmrgint vc4_simulator_ioctl(int fd, unsigned long request, void *arg); 4699f464c52Smayavoid vc4_simulator_open_from_handle(int fd, int handle, uint32_t size); 47001e04c3fSmrg 47101e04c3fSmrgstatic inline int 47201e04c3fSmrgvc4_ioctl(int fd, unsigned long request, void *arg) 47301e04c3fSmrg{ 47401e04c3fSmrg if (using_vc4_simulator) 47501e04c3fSmrg return vc4_simulator_ioctl(fd, request, arg); 47601e04c3fSmrg else 47701e04c3fSmrg return drmIoctl(fd, request, arg); 47801e04c3fSmrg} 479af69d88dSmrg 48001e04c3fSmrgvoid vc4_set_shader_uniform_dirty_flags(struct vc4_compiled_shader *shader); 481af69d88dSmrgvoid vc4_write_uniforms(struct vc4_context *vc4, 482af69d88dSmrg struct vc4_compiled_shader *shader, 483af69d88dSmrg struct vc4_constbuf_stateobj *cb, 48401e04c3fSmrg struct vc4_texture_stateobj *texstate); 485af69d88dSmrg 486af69d88dSmrgvoid vc4_flush(struct pipe_context *pctx); 48701e04c3fSmrgint vc4_job_init(struct vc4_context *vc4); 48801e04c3fSmrgint vc4_fence_context_init(struct vc4_context *vc4); 48901e04c3fSmrgstruct vc4_job *vc4_get_job(struct vc4_context *vc4, 49001e04c3fSmrg struct pipe_surface *cbuf, 49101e04c3fSmrg struct pipe_surface *zsbuf); 49201e04c3fSmrgstruct vc4_job *vc4_get_job_for_fbo(struct vc4_context *vc4); 49301e04c3fSmrg 49401e04c3fSmrgvoid vc4_job_submit(struct vc4_context *vc4, struct vc4_job *job); 49501e04c3fSmrgvoid vc4_flush_jobs_writing_resource(struct vc4_context *vc4, 49601e04c3fSmrg struct pipe_resource *prsc); 49701e04c3fSmrgvoid vc4_flush_jobs_reading_resource(struct vc4_context *vc4, 49801e04c3fSmrg struct pipe_resource *prsc); 499af69d88dSmrgvoid vc4_emit_state(struct pipe_context *pctx); 50001e04c3fSmrgvoid vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c); 50101e04c3fSmrgstruct qpu_reg *vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c); 50201e04c3fSmrgbool vc4_update_compiled_shaders(struct vc4_context *vc4, uint8_t prim_mode); 50301e04c3fSmrg 50401e04c3fSmrgbool vc4_rt_format_supported(enum pipe_format f); 50501e04c3fSmrgbool vc4_rt_format_is_565(enum pipe_format f); 50601e04c3fSmrgbool vc4_tex_format_supported(enum pipe_format f); 50701e04c3fSmrguint8_t vc4_get_tex_format(enum pipe_format f); 50801e04c3fSmrgconst uint8_t *vc4_get_format_swizzle(enum pipe_format f); 50901e04c3fSmrgvoid vc4_init_query_functions(struct vc4_context *vc4); 51001e04c3fSmrgvoid vc4_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info); 51101e04c3fSmrgvoid vc4_blitter_save(struct vc4_context *vc4); 512af69d88dSmrg#endif /* VC4_CONTEXT_H */ 513