Path: blob/21.2-virgl/src/amd/vulkan/radv_radeon_winsys.h
7655 views
/*1* Copyright © 2016 Red Hat.2* Copyright © 2016 Bas Nieuwenhuizen3*4* Based on radeon_winsys.h which is:5* Copyright 2008 Corbin Simpson <[email protected]>6* Copyright 2010 Marek Olšák <[email protected]>7*8* Permission is hereby granted, free of charge, to any person obtaining a9* copy of this software and associated documentation files (the "Software"),10* to deal in the Software without restriction, including without limitation11* the rights to use, copy, modify, merge, publish, distribute, sublicense,12* and/or sell copies of the Software, and to permit persons to whom the13* Software is furnished to do so, subject to the following conditions:14*15* The above copyright notice and this permission notice (including the next16* paragraph) shall be included in all copies or substantial portions of the17* Software.18*19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL22* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER23* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING24* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS25* IN THE SOFTWARE.26*/2728#ifndef RADV_RADEON_WINSYS_H29#define RADV_RADEON_WINSYS_H3031#include <stdbool.h>32#include <stdint.h>33#include <stdio.h>34#include <stdlib.h>35#include <string.h>36#include "util/u_math.h"37#include "util/u_memory.h"38#include <vulkan/vulkan.h>39#include "amd_family.h"4041struct radeon_info;42struct ac_surf_info;43struct radeon_surf;4445enum radeon_bo_domain { /* bitfield */46RADEON_DOMAIN_GTT = 2,47RADEON_DOMAIN_VRAM = 4,48RADEON_DOMAIN_VRAM_GTT = RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT,49RADEON_DOMAIN_GDS = 8,50RADEON_DOMAIN_OA = 16,51};5253enum radeon_bo_flag { /* bitfield */54RADEON_FLAG_GTT_WC = (1 << 0),55RADEON_FLAG_CPU_ACCESS = (1 << 1),56RADEON_FLAG_NO_CPU_ACCESS = (1 << 2),57RADEON_FLAG_VIRTUAL = (1 << 3),58RADEON_FLAG_VA_UNCACHED = (1 << 4),59RADEON_FLAG_IMPLICIT_SYNC = (1 << 5),60RADEON_FLAG_NO_INTERPROCESS_SHARING = (1 << 6),61RADEON_FLAG_READ_ONLY = (1 << 7),62RADEON_FLAG_32BIT = (1 << 8),63RADEON_FLAG_PREFER_LOCAL_BO = (1 << 9),64RADEON_FLAG_ZERO_VRAM = (1 << 10),65RADEON_FLAG_REPLAYABLE = (1 << 11),66};6768enum radeon_ctx_priority {69RADEON_CTX_PRIORITY_INVALID = -1,70RADEON_CTX_PRIORITY_LOW = 0,71RADEON_CTX_PRIORITY_MEDIUM,72RADEON_CTX_PRIORITY_HIGH,73RADEON_CTX_PRIORITY_REALTIME,74};7576enum radeon_value_id {77RADEON_ALLOCATED_VRAM,78RADEON_ALLOCATED_VRAM_VIS,79RADEON_ALLOCATED_GTT,80RADEON_TIMESTAMP,81RADEON_NUM_BYTES_MOVED,82RADEON_NUM_EVICTIONS,83RADEON_NUM_VRAM_CPU_PAGE_FAULTS,84RADEON_VRAM_USAGE,85RADEON_VRAM_VIS_USAGE,86RADEON_GTT_USAGE,87RADEON_GPU_TEMPERATURE,88RADEON_CURRENT_SCLK,89RADEON_CURRENT_MCLK,90};9192struct radeon_cmdbuf {93unsigned cdw; /* Number of used dwords. */94unsigned max_dw; /* Maximum number of dwords. */95uint32_t *buf; /* The base pointer of the chunk. */96};9798#define RADEON_SURF_TYPE_MASK 0xFF99#define RADEON_SURF_TYPE_SHIFT 0100#define RADEON_SURF_TYPE_1D 0101#define RADEON_SURF_TYPE_2D 1102#define RADEON_SURF_TYPE_3D 2103#define RADEON_SURF_TYPE_CUBEMAP 3104#define RADEON_SURF_TYPE_1D_ARRAY 4105#define RADEON_SURF_TYPE_2D_ARRAY 5106#define RADEON_SURF_MODE_MASK 0xFF107#define RADEON_SURF_MODE_SHIFT 8108109#define RADEON_SURF_GET(v, field) \110(((v) >> RADEON_SURF_##field##_SHIFT) & RADEON_SURF_##field##_MASK)111#define RADEON_SURF_SET(v, field) (((v)&RADEON_SURF_##field##_MASK) << RADEON_SURF_##field##_SHIFT)112#define RADEON_SURF_CLR(v, field) \113((v) & ~(RADEON_SURF_##field##_MASK << RADEON_SURF_##field##_SHIFT))114115enum radeon_bo_layout {116RADEON_LAYOUT_LINEAR = 0,117RADEON_LAYOUT_TILED,118RADEON_LAYOUT_SQUARETILED,119120RADEON_LAYOUT_UNKNOWN121};122123/* Tiling info for display code, DRI sharing, and other data. */124struct radeon_bo_metadata {125/* Tiling flags describing the texture layout for display code126* and DRI sharing.127*/128union {129struct {130enum radeon_bo_layout microtile;131enum radeon_bo_layout macrotile;132unsigned pipe_config;133unsigned bankw;134unsigned bankh;135unsigned tile_split;136unsigned mtilea;137unsigned num_banks;138unsigned stride;139bool scanout;140} legacy;141142struct {143/* surface flags */144unsigned swizzle_mode : 5;145bool scanout;146uint32_t dcc_offset_256b;147uint32_t dcc_pitch_max;148bool dcc_independent_64b_blocks;149bool dcc_independent_128b_blocks;150unsigned dcc_max_compressed_block_size;151} gfx9;152} u;153154/* Additional metadata associated with the buffer, in bytes.155* The maximum size is 64 * 4. This is opaque for the winsys & kernel.156* Supported by amdgpu only.157*/158uint32_t size_metadata;159uint32_t metadata[64];160};161162struct radeon_winsys_ctx;163164struct radeon_winsys_bo {165uint64_t va;166bool is_local;167bool vram_no_cpu_access;168bool use_global_list;169enum radeon_bo_domain initial_domain;170};171struct radv_winsys_sem_counts {172uint32_t syncobj_count;173uint32_t syncobj_reset_count; /* for wait only, whether to reset the syncobj */174uint32_t timeline_syncobj_count;175uint32_t *syncobj;176uint64_t *points;177};178179struct radv_winsys_sem_info {180bool cs_emit_signal;181bool cs_emit_wait;182struct radv_winsys_sem_counts wait;183struct radv_winsys_sem_counts signal;184};185186struct radv_winsys_bo_list {187struct radeon_winsys_bo **bos;188unsigned count;189};190191/* Kernel effectively allows 0-31. This sets some priorities for fixed192* functionality buffers */193enum {194RADV_BO_PRIORITY_APPLICATION_MAX = 28,195196/* virtual buffers have 0 priority since the priority is not used. */197RADV_BO_PRIORITY_VIRTUAL = 0,198199RADV_BO_PRIORITY_METADATA = 10,200/* This should be considerably lower than most of the stuff below,201* but how much lower is hard to say since we don't know application202* assignments. Put it pretty high since it is GTT anyway. */203RADV_BO_PRIORITY_QUERY_POOL = 29,204205RADV_BO_PRIORITY_DESCRIPTOR = 30,206RADV_BO_PRIORITY_UPLOAD_BUFFER = 30,207RADV_BO_PRIORITY_FENCE = 30,208RADV_BO_PRIORITY_SHADER = 31,209RADV_BO_PRIORITY_SCRATCH = 31,210RADV_BO_PRIORITY_CS = 31,211};212213struct radeon_winsys {214void (*destroy)(struct radeon_winsys *ws);215216void (*query_info)(struct radeon_winsys *ws, struct radeon_info *info);217218uint64_t (*query_value)(struct radeon_winsys *ws, enum radeon_value_id value);219220bool (*read_registers)(struct radeon_winsys *ws, unsigned reg_offset, unsigned num_registers,221uint32_t *out);222223const char *(*get_chip_name)(struct radeon_winsys *ws);224225VkResult (*buffer_create)(struct radeon_winsys *ws, uint64_t size, unsigned alignment,226enum radeon_bo_domain domain, enum radeon_bo_flag flags,227unsigned priority, uint64_t address, struct radeon_winsys_bo **out_bo);228229void (*buffer_destroy)(struct radeon_winsys *ws, struct radeon_winsys_bo *bo);230void *(*buffer_map)(struct radeon_winsys_bo *bo);231232VkResult (*buffer_from_ptr)(struct radeon_winsys *ws, void *pointer, uint64_t size,233unsigned priority, struct radeon_winsys_bo **out_bo);234235VkResult (*buffer_from_fd)(struct radeon_winsys *ws, int fd, unsigned priority,236struct radeon_winsys_bo **out_bo, uint64_t *alloc_size);237238bool (*buffer_get_fd)(struct radeon_winsys *ws, struct radeon_winsys_bo *bo, int *fd);239240bool (*buffer_get_flags_from_fd)(struct radeon_winsys *ws, int fd,241enum radeon_bo_domain *domains, enum radeon_bo_flag *flags);242243void (*buffer_unmap)(struct radeon_winsys_bo *bo);244245void (*buffer_set_metadata)(struct radeon_winsys *ws, struct radeon_winsys_bo *bo,246struct radeon_bo_metadata *md);247void (*buffer_get_metadata)(struct radeon_winsys *ws, struct radeon_winsys_bo *bo,248struct radeon_bo_metadata *md);249250VkResult (*buffer_virtual_bind)(struct radeon_winsys *ws, struct radeon_winsys_bo *parent,251uint64_t offset, uint64_t size, struct radeon_winsys_bo *bo,252uint64_t bo_offset);253254VkResult (*buffer_make_resident)(struct radeon_winsys *ws, struct radeon_winsys_bo *bo,255bool resident);256257VkResult (*ctx_create)(struct radeon_winsys *ws, enum radeon_ctx_priority priority,258struct radeon_winsys_ctx **ctx);259void (*ctx_destroy)(struct radeon_winsys_ctx *ctx);260261bool (*ctx_wait_idle)(struct radeon_winsys_ctx *ctx, enum ring_type ring_type, int ring_index);262263enum radeon_bo_domain (*cs_domain)(const struct radeon_winsys *ws);264265struct radeon_cmdbuf *(*cs_create)(struct radeon_winsys *ws, enum ring_type ring_type);266267void (*cs_destroy)(struct radeon_cmdbuf *cs);268269void (*cs_reset)(struct radeon_cmdbuf *cs);270271VkResult (*cs_finalize)(struct radeon_cmdbuf *cs);272273void (*cs_grow)(struct radeon_cmdbuf *cs, size_t min_size);274275VkResult (*cs_submit)(struct radeon_winsys_ctx *ctx, int queue_index,276struct radeon_cmdbuf **cs_array, unsigned cs_count,277struct radeon_cmdbuf *initial_preamble_cs,278struct radeon_cmdbuf *continue_preamble_cs,279struct radv_winsys_sem_info *sem_info, bool can_patch);280281void (*cs_add_buffer)(struct radeon_cmdbuf *cs, struct radeon_winsys_bo *bo);282283void (*cs_execute_secondary)(struct radeon_cmdbuf *parent, struct radeon_cmdbuf *child,284bool allow_ib2);285286void (*cs_dump)(struct radeon_cmdbuf *cs, FILE *file, const int *trace_ids, int trace_id_count);287288void (*dump_bo_ranges)(struct radeon_winsys *ws, FILE *file);289290void (*dump_bo_log)(struct radeon_winsys *ws, FILE *file);291292int (*surface_init)(struct radeon_winsys *ws, const struct ac_surf_info *surf_info,293struct radeon_surf *surf);294295int (*create_syncobj)(struct radeon_winsys *ws, bool create_signaled, uint32_t *handle);296void (*destroy_syncobj)(struct radeon_winsys *ws, uint32_t handle);297298void (*reset_syncobj)(struct radeon_winsys *ws, uint32_t handle);299void (*signal_syncobj)(struct radeon_winsys *ws, uint32_t handle, uint64_t point);300VkResult (*query_syncobj)(struct radeon_winsys *ws, uint32_t handle, uint64_t *point);301bool (*wait_syncobj)(struct radeon_winsys *ws, const uint32_t *handles, uint32_t handle_count,302bool wait_all, uint64_t timeout);303bool (*wait_timeline_syncobj)(struct radeon_winsys *ws, const uint32_t *handles,304const uint64_t *points, uint32_t handle_count, bool wait_all,305bool available, uint64_t timeout);306307int (*export_syncobj)(struct radeon_winsys *ws, uint32_t syncobj, int *fd);308int (*import_syncobj)(struct radeon_winsys *ws, int fd, uint32_t *syncobj);309310int (*export_syncobj_to_sync_file)(struct radeon_winsys *ws, uint32_t syncobj, int *fd);311312/* Note that this, unlike the normal import, uses an existing syncobj. */313int (*import_syncobj_from_sync_file)(struct radeon_winsys *ws, uint32_t syncobj, int fd);314};315316static inline void317radeon_emit(struct radeon_cmdbuf *cs, uint32_t value)318{319cs->buf[cs->cdw++] = value;320}321322static inline void323radeon_emit_array(struct radeon_cmdbuf *cs, const uint32_t *values, unsigned count)324{325memcpy(cs->buf + cs->cdw, values, count * 4);326cs->cdw += count;327}328329static inline uint64_t330radv_buffer_get_va(struct radeon_winsys_bo *bo)331{332return bo->va;333}334335static inline void336radv_cs_add_buffer(struct radeon_winsys *ws, struct radeon_cmdbuf *cs, struct radeon_winsys_bo *bo)337{338if (bo->use_global_list)339return;340341ws->cs_add_buffer(cs, bo);342}343344#endif /* RADV_RADEON_WINSYS_H */345346347