Path: blob/21.2-virgl/src/panfrost/lib/pan_device.h
4560 views
/**************************************************************************1*2* Copyright 2018-2019 Alyssa Rosenzweig3* Copyright 2018-2019 Collabora, Ltd.4* Copyright © 2015 Intel Corporation5* All Rights Reserved.6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the9* "Software"), to deal in the Software without restriction, including10* without limitation the rights to use, copy, modify, merge, publish,11* distribute, sub license, and/or sell copies of the Software, and to12* permit persons to whom the Software is furnished to do so, subject to13* the following conditions:14*15* The above copyright notice and this permission notice (including the16* next paragraph) shall be included in all copies or substantial portions17* of the Software.18*19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS20* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF21* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.22* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR23* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,24* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE25* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.26*27**************************************************************************/2829#ifndef PAN_DEVICE_H30#define PAN_DEVICE_H3132#include <xf86drm.h>33#include "renderonly/renderonly.h"34#include "util/u_dynarray.h"35#include "util/bitset.h"36#include "util/list.h"37#include "util/sparse_array.h"3839#include "panfrost/util/pan_ir.h"40#include "pan_pool.h"41#include "pan_util.h"4243#include <midgard_pack.h>4445#if defined(__cplusplus)46extern "C" {47#endif4849/* Driver limits */50#define PAN_MAX_CONST_BUFFERS 165152/* How many power-of-two levels in the BO cache do we want? 2^1253* minimum chosen as it is the page size that all allocations are54* rounded to */5556#define MIN_BO_CACHE_BUCKET (12) /* 2^12 = 4KB */57#define MAX_BO_CACHE_BUCKET (22) /* 2^22 = 4MB */5859/* Fencepost problem, hence the off-by-one */60#define NR_BO_CACHE_BUCKETS (MAX_BO_CACHE_BUCKET - MIN_BO_CACHE_BUCKET + 1)6162struct pan_blitter {63struct {64struct pan_pool *pool;65struct hash_table *blit;66struct hash_table *blend;67pthread_mutex_t lock;68} shaders;69struct {70struct pan_pool *pool;71struct hash_table *rsds;72pthread_mutex_t lock;73} rsds;74};7576struct pan_blend_shaders {77struct hash_table *shaders;78pthread_mutex_t lock;79};8081enum pan_indirect_draw_flags {82PAN_INDIRECT_DRAW_NO_INDEX = 0 << 0,83PAN_INDIRECT_DRAW_1B_INDEX = 1 << 0,84PAN_INDIRECT_DRAW_2B_INDEX = 2 << 0,85PAN_INDIRECT_DRAW_4B_INDEX = 3 << 0,86PAN_INDIRECT_DRAW_INDEX_SIZE_MASK = 3 << 0,87PAN_INDIRECT_DRAW_HAS_PSIZ = 1 << 2,88PAN_INDIRECT_DRAW_PRIMITIVE_RESTART = 1 << 3,89PAN_INDIRECT_DRAW_UPDATE_PRIM_SIZE = 1 << 4,90PAN_INDIRECT_DRAW_LAST_FLAG = PAN_INDIRECT_DRAW_UPDATE_PRIM_SIZE,91PAN_INDIRECT_DRAW_FLAGS_MASK = (PAN_INDIRECT_DRAW_LAST_FLAG << 1) - 1,92PAN_INDIRECT_DRAW_MIN_MAX_SEARCH_1B_INDEX = PAN_INDIRECT_DRAW_LAST_FLAG << 1,93PAN_INDIRECT_DRAW_MIN_MAX_SEARCH_2B_INDEX,94PAN_INDIRECT_DRAW_MIN_MAX_SEARCH_4B_INDEX,95PAN_INDIRECT_DRAW_NUM_SHADERS,96};9798struct pan_indirect_draw_shader {99struct panfrost_ubo_push push;100mali_ptr rsd;101};102103struct pan_indirect_draw_shaders {104struct pan_indirect_draw_shader shaders[PAN_INDIRECT_DRAW_NUM_SHADERS];105106/* Take the lock when initializing the draw shaders context or when107* allocating from the binary pool.108*/109pthread_mutex_t lock;110111/* A memory pool for shader binaries. We currently don't allocate a112* single BO for all shaders up-front because estimating shader size113* is not trivial, and changes to the compiler might influence this114* estimation.115*/116struct pan_pool *bin_pool;117118/* BO containing all renderer states attached to the compute shaders.119* Those are built at shader compilation time and re-used every time120* panfrost_emit_indirect_draw() is called.121*/122struct panfrost_bo *states;123124/* Varying memory is allocated dynamically by compute jobs from this125* heap.126*/127struct panfrost_bo *varying_heap;128};129130struct pan_indirect_dispatch {131struct panfrost_ubo_push push;132struct panfrost_bo *bin;133struct panfrost_bo *descs;134};135136/** Implementation-defined tiler features */137struct panfrost_tiler_features {138/** Number of bytes per tiler bin */139unsigned bin_size;140141/** Maximum number of levels that may be simultaneously enabled.142* Invariant: bitcount(hierarchy_mask) <= max_levels */143unsigned max_levels;144};145146struct panfrost_device {147/* For ralloc */148void *memctx;149150int fd;151152/* Properties of the GPU in use */153unsigned arch;154unsigned gpu_id;155unsigned core_count;156unsigned thread_tls_alloc;157struct panfrost_tiler_features tiler_features;158unsigned quirks;159160/* Table of formats, indexed by a PIPE format */161const struct panfrost_format *formats;162163/* Bitmask of supported compressed texture formats */164uint32_t compressed_formats;165166/* debug flags, see pan_util.h how to interpret */167unsigned debug;168169drmVersionPtr kernel_version;170171struct renderonly *ro;172173pthread_mutex_t bo_map_lock;174struct util_sparse_array bo_map;175176struct {177pthread_mutex_t lock;178179/* List containing all cached BOs sorted in LRU (Least180* Recently Used) order. This allows us to quickly evict BOs181* that are more than 1 second old.182*/183struct list_head lru;184185/* The BO cache is a set of buckets with power-of-two sizes186* ranging from 2^12 (4096, the page size) to187* 2^(12 + MAX_BO_CACHE_BUCKETS).188* Each bucket is a linked list of free panfrost_bo objects. */189190struct list_head buckets[NR_BO_CACHE_BUCKETS];191} bo_cache;192193struct pan_blitter blitter;194struct pan_blend_shaders blend_shaders;195struct pan_indirect_draw_shaders indirect_draw_shaders;196struct pan_indirect_dispatch indirect_dispatch;197198/* Tiler heap shared across all tiler jobs, allocated against the199* device since there's only a single tiler. Since this is invisible to200* the CPU, it's okay for multiple contexts to reference it201* simultaneously; by keeping on the device struct, we eliminate a202* costly per-context allocation. */203204struct panfrost_bo *tiler_heap;205206/* The tiler heap is shared by all contexts, and is written by tiler207* jobs and read by fragment job. We need to ensure that a208* vertex/tiler job chain from one context is not inserted between209* the vertex/tiler and fragment job of another context, otherwise210* we end up with tiler heap corruption.211*/212pthread_mutex_t submit_lock;213214/* Sample positions are preloaded into a write-once constant buffer,215* such that they can be referenced fore free later. Needed216* unconditionally on Bifrost, and useful for sharing with Midgard */217218struct panfrost_bo *sample_positions;219};220221void222panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev);223224void225panfrost_close_device(struct panfrost_device *dev);226227bool228panfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt);229230void231panfrost_upload_sample_positions(struct panfrost_device *dev);232233mali_ptr234panfrost_sample_positions(const struct panfrost_device *dev,235enum mali_sample_pattern pattern);236void237panfrost_query_sample_position(238enum mali_sample_pattern pattern,239unsigned sample_idx,240float *out);241242static inline struct panfrost_bo *243pan_lookup_bo(struct panfrost_device *dev, uint32_t gem_handle)244{245return (struct panfrost_bo *)util_sparse_array_get(&dev->bo_map, gem_handle);246}247248static inline bool249pan_is_bifrost(const struct panfrost_device *dev)250{251return dev->arch >= 6 && dev->arch <= 7;252}253254#if defined(__cplusplus)255} // extern "C"256#endif257258#endif259260261