Path: blob/21.2-virgl/src/amd/vulkan/radv_private.h
7206 views
/*1* Copyright © 2016 Red Hat.2* Copyright © 2016 Bas Nieuwenhuizen3*4* based in part on anv driver which is:5* Copyright © 2015 Intel Corporation6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the "Software"),9* to deal in the Software without restriction, including without limitation10* the rights to use, copy, modify, merge, publish, distribute, sublicense,11* and/or sell copies of the Software, and to permit persons to whom the12* Software is furnished to do so, subject to the following conditions:13*14* The above copyright notice and this permission notice (including the next15* paragraph) shall be included in all copies or substantial portions of the16* Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR19* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,20* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL21* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER22* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING23* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS24* IN THE SOFTWARE.25*/2627#ifndef RADV_PRIVATE_H28#define RADV_PRIVATE_H2930#include <assert.h>31#include <stdbool.h>32#include <stdint.h>33#include <stdio.h>34#include <stdlib.h>35#include <string.h>36#ifdef HAVE_VALGRIND37#include <memcheck.h>38#include <valgrind.h>39#define VG(x) x40#else41#define VG(x) ((void)0)42#endif4344#include "c11/threads.h"45#ifndef _WIN3246#include <amdgpu.h>47#include <xf86drm.h>48#endif49#include "compiler/shader_enums.h"50#include "util/bitscan.h"51#include "util/cnd_monotonic.h"52#include "util/list.h"53#include "util/macros.h"54#include "util/rwlock.h"55#include "util/xmlconfig.h"56#include "vk_alloc.h"57#include "vk_debug_report.h"58#include "vk_device.h"59#include "vk_format.h"60#include "vk_instance.h"61#include "vk_physical_device.h"62#include "vk_shader_module.h"63#include "vk_util.h"6465#include "ac_binary.h"66#include "ac_gpu_info.h"67#include "ac_shader_util.h"68#include "ac_sqtt.h"69#include "ac_surface.h"70#include "radv_constants.h"71#include "radv_descriptor_set.h"72#include "radv_radeon_winsys.h"73#include "sid.h"7475/* Pre-declarations needed for WSI entrypoints */76struct wl_surface;77struct wl_display;78typedef struct xcb_connection_t xcb_connection_t;79typedef uint32_t xcb_visualid_t;80typedef uint32_t xcb_window_t;8182#include <vulkan/vk_android_native_buffer.h>83#include <vulkan/vk_icd.h>84#include <vulkan/vulkan.h>85#include <vulkan/vulkan_android.h>8687#include "radv_entrypoints.h"8889#include "wsi_common.h"9091/* Helper to determine if we should compile92* any of the Android AHB support.93*94* To actually enable the ext we also need95* the necessary kernel support.96*/97#if defined(ANDROID) && ANDROID_API_LEVEL >= 2698#define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 199#include <vndk/hardware_buffer.h>100#else101#define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 0102#endif103104#ifdef _WIN32105#define RADV_SUPPORT_CALIBRATED_TIMESTAMPS 0106#else107#define RADV_SUPPORT_CALIBRATED_TIMESTAMPS 1108#endif109110#ifdef _WIN32111#define radv_printflike(a, b)112#else113#define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))114#endif115116static inline uint32_t117align_u32(uint32_t v, uint32_t a)118{119assert(a != 0 && a == (a & -a));120return (v + a - 1) & ~(a - 1);121}122123static inline uint32_t124align_u32_npot(uint32_t v, uint32_t a)125{126return (v + a - 1) / a * a;127}128129static inline uint64_t130align_u64(uint64_t v, uint64_t a)131{132assert(a != 0 && a == (a & -a));133return (v + a - 1) & ~(a - 1);134}135136static inline int32_t137align_i32(int32_t v, int32_t a)138{139assert(a != 0 && a == (a & -a));140return (v + a - 1) & ~(a - 1);141}142143/** Alignment must be a power of 2. */144static inline bool145radv_is_aligned(uintmax_t n, uintmax_t a)146{147assert(a == (a & -a));148return (n & (a - 1)) == 0;149}150151static inline uint32_t152round_up_u32(uint32_t v, uint32_t a)153{154return (v + a - 1) / a;155}156157static inline uint64_t158round_up_u64(uint64_t v, uint64_t a)159{160return (v + a - 1) / a;161}162163static inline uint32_t164radv_minify(uint32_t n, uint32_t levels)165{166if (unlikely(n == 0))167return 0;168else169return MAX2(n >> levels, 1);170}171static inline float172radv_clamp_f(float f, float min, float max)173{174assert(min < max);175176if (f > max)177return max;178else if (f < min)179return min;180else181return f;182}183184static inline bool185radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)186{187if (*inout_mask & clear_mask) {188*inout_mask &= ~clear_mask;189return true;190} else {191return false;192}193}194195/* Whenever we generate an error, pass it through this function. Useful for196* debugging, where we can break on it. Only call at error site, not when197* propagating errors. Might be useful to plug in a stack trace here.198*/199200struct radv_image_view;201struct radv_instance;202203VkResult __vk_errorv(struct radv_instance *instance, const void *object,204VkDebugReportObjectTypeEXT type, VkResult error, const char *file, int line,205const char *format, va_list args);206207VkResult __vk_errorf(struct radv_instance *instance, const void *object,208VkDebugReportObjectTypeEXT type, VkResult error, const char *file, int line,209const char *format, ...) radv_printflike(7, 8);210211#define vk_error(instance, error) \212__vk_errorf(instance, NULL, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, error, __FILE__, __LINE__, \213NULL);214#define vk_errorf(instance, error, format, ...) \215__vk_errorf(instance, NULL, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, error, __FILE__, __LINE__, \216format, ##__VA_ARGS__);217218void __radv_finishme(const char *file, int line, const char *format, ...) radv_printflike(3, 4);219void radv_loge(const char *format, ...) radv_printflike(1, 2);220void radv_loge_v(const char *format, va_list va);221void radv_logi(const char *format, ...) radv_printflike(1, 2);222void radv_logi_v(const char *format, va_list va);223224/**225* Print a FINISHME message, including its source location.226*/227#define radv_finishme(format, ...) \228do { \229static bool reported = false; \230if (!reported) { \231__radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \232reported = true; \233} \234} while (0)235236/* A non-fatal assert. Useful for debugging. */237#ifdef NDEBUG238#define radv_assert(x) \239do { \240} while (0)241#else242#define radv_assert(x) \243do { \244if (unlikely(!(x))) \245fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \246} while (0)247#endif248249int radv_get_instance_entrypoint_index(const char *name);250int radv_get_device_entrypoint_index(const char *name);251int radv_get_physical_device_entrypoint_index(const char *name);252253const char *radv_get_instance_entry_name(int index);254const char *radv_get_physical_device_entry_name(int index);255const char *radv_get_device_entry_name(int index);256257struct radv_physical_device {258struct vk_physical_device vk;259260/* Link in radv_instance::physical_devices */261struct list_head link;262263struct radv_instance *instance;264265struct radeon_winsys *ws;266struct radeon_info rad_info;267char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];268uint8_t driver_uuid[VK_UUID_SIZE];269uint8_t device_uuid[VK_UUID_SIZE];270uint8_t cache_uuid[VK_UUID_SIZE];271272int local_fd;273int master_fd;274struct wsi_device wsi_device;275276bool out_of_order_rast_allowed;277278/* Whether DCC should be enabled for MSAA textures. */279bool dcc_msaa_allowed;280281/* Whether to enable NGG. */282bool use_ngg;283284/* Whether to enable NGG streamout. */285bool use_ngg_streamout;286287/* Number of threads per wave. */288uint8_t ps_wave_size;289uint8_t cs_wave_size;290uint8_t ge_wave_size;291292/* Whether to use the LLVM compiler backend */293bool use_llvm;294295/* This is the drivers on-disk cache used as a fallback as opposed to296* the pipeline cache defined by apps.297*/298struct disk_cache *disk_cache;299300VkPhysicalDeviceMemoryProperties memory_properties;301enum radeon_bo_domain memory_domains[VK_MAX_MEMORY_TYPES];302enum radeon_bo_flag memory_flags[VK_MAX_MEMORY_TYPES];303unsigned heaps;304305#ifndef _WIN32306int available_nodes;307drmPciBusInfo bus_info;308309dev_t primary_devid;310dev_t render_devid;311#endif312};313314struct radv_instance {315struct vk_instance vk;316317VkAllocationCallbacks alloc;318319uint64_t debug_flags;320uint64_t perftest_flags;321322bool physical_devices_enumerated;323struct list_head physical_devices;324325struct driOptionCache dri_options;326struct driOptionCache available_dri_options;327328/**329* Workarounds for game bugs.330*/331bool enable_mrt_output_nan_fixup;332bool disable_tc_compat_htile_in_general;333bool disable_shrink_image_store;334bool absolute_depth_bias;335bool report_apu_as_dgpu;336};337338VkResult radv_init_wsi(struct radv_physical_device *physical_device);339void radv_finish_wsi(struct radv_physical_device *physical_device);340341struct cache_entry;342343struct radv_pipeline_cache {344struct vk_object_base base;345struct radv_device *device;346mtx_t mutex;347VkPipelineCacheCreateFlags flags;348349uint32_t total_size;350uint32_t table_size;351uint32_t kernel_count;352struct cache_entry **hash_table;353bool modified;354355VkAllocationCallbacks alloc;356};357358struct radv_pipeline_key {359uint32_t instance_rate_inputs;360uint32_t instance_rate_divisors[MAX_VERTEX_ATTRIBS];361uint8_t vertex_attribute_formats[MAX_VERTEX_ATTRIBS];362uint32_t vertex_attribute_bindings[MAX_VERTEX_ATTRIBS];363uint32_t vertex_attribute_offsets[MAX_VERTEX_ATTRIBS];364uint32_t vertex_attribute_strides[MAX_VERTEX_ATTRIBS];365uint8_t vertex_binding_align[MAX_VBS];366enum ac_fetch_format vertex_alpha_adjust[MAX_VERTEX_ATTRIBS];367uint32_t vertex_post_shuffle;368unsigned tess_input_vertices;369uint32_t col_format;370uint32_t is_int8;371uint32_t is_int10;372uint8_t log2_ps_iter_samples;373uint8_t num_samples;374uint32_t has_multiview_view_index : 1;375uint32_t optimisations_disabled : 1;376uint32_t provoking_vtx_last : 1;377uint8_t topology;378379/* Non-zero if a required subgroup size is specified via380* VK_EXT_subgroup_size_control.381*/382uint8_t compute_subgroup_size;383bool require_full_subgroups;384};385386struct radv_shader_binary;387struct radv_shader_variant;388389void radv_pipeline_cache_init(struct radv_pipeline_cache *cache, struct radv_device *device);390void radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);391bool radv_pipeline_cache_load(struct radv_pipeline_cache *cache, const void *data, size_t size);392393bool radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,394struct radv_pipeline_cache *cache,395const unsigned char *sha1,396struct radv_shader_variant **variants,397bool *found_in_application_cache);398399void radv_pipeline_cache_insert_shaders(struct radv_device *device,400struct radv_pipeline_cache *cache,401const unsigned char *sha1,402struct radv_shader_variant **variants,403struct radv_shader_binary *const *binaries);404405enum radv_blit_ds_layout {406RADV_BLIT_DS_LAYOUT_TILE_ENABLE,407RADV_BLIT_DS_LAYOUT_TILE_DISABLE,408RADV_BLIT_DS_LAYOUT_COUNT,409};410411static inline enum radv_blit_ds_layout412radv_meta_blit_ds_to_type(VkImageLayout layout)413{414return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_BLIT_DS_LAYOUT_TILE_DISABLE415: RADV_BLIT_DS_LAYOUT_TILE_ENABLE;416}417418static inline VkImageLayout419radv_meta_blit_ds_to_layout(enum radv_blit_ds_layout ds_layout)420{421return ds_layout == RADV_BLIT_DS_LAYOUT_TILE_ENABLE ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL422: VK_IMAGE_LAYOUT_GENERAL;423}424425enum radv_meta_dst_layout {426RADV_META_DST_LAYOUT_GENERAL,427RADV_META_DST_LAYOUT_OPTIMAL,428RADV_META_DST_LAYOUT_COUNT,429};430431static inline enum radv_meta_dst_layout432radv_meta_dst_layout_from_layout(VkImageLayout layout)433{434return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_META_DST_LAYOUT_GENERAL435: RADV_META_DST_LAYOUT_OPTIMAL;436}437438static inline VkImageLayout439radv_meta_dst_layout_to_layout(enum radv_meta_dst_layout layout)440{441return layout == RADV_META_DST_LAYOUT_OPTIMAL ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL442: VK_IMAGE_LAYOUT_GENERAL;443}444445struct radv_meta_state {446VkAllocationCallbacks alloc;447448struct radv_pipeline_cache cache;449450/*451* For on-demand pipeline creation, makes sure that452* only one thread tries to build a pipeline at the same time.453*/454mtx_t mtx;455456/**457* Use array element `i` for images with `2^i` samples.458*/459struct {460VkRenderPass render_pass[NUM_META_FS_KEYS];461VkPipeline color_pipelines[NUM_META_FS_KEYS];462463VkRenderPass depthstencil_rp;464VkPipeline depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];465VkPipeline stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];466VkPipeline depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];467468VkPipeline depth_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];469VkPipeline stencil_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];470VkPipeline depthstencil_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];471} clear[MAX_SAMPLES_LOG2];472473VkPipelineLayout clear_color_p_layout;474VkPipelineLayout clear_depth_p_layout;475VkPipelineLayout clear_depth_unrestricted_p_layout;476477/* Optimized compute fast HTILE clear for stencil or depth only. */478VkPipeline clear_htile_mask_pipeline;479VkPipelineLayout clear_htile_mask_p_layout;480VkDescriptorSetLayout clear_htile_mask_ds_layout;481482/* Copy VRS into HTILE. */483VkPipeline copy_vrs_htile_pipeline;484VkPipelineLayout copy_vrs_htile_p_layout;485VkDescriptorSetLayout copy_vrs_htile_ds_layout;486487struct {488VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];489490/** Pipeline that blits from a 1D image. */491VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];492493/** Pipeline that blits from a 2D image. */494VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];495496/** Pipeline that blits from a 3D image. */497VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];498499VkRenderPass depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];500VkPipeline depth_only_1d_pipeline;501VkPipeline depth_only_2d_pipeline;502VkPipeline depth_only_3d_pipeline;503504VkRenderPass stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];505VkPipeline stencil_only_1d_pipeline;506VkPipeline stencil_only_2d_pipeline;507VkPipeline stencil_only_3d_pipeline;508VkPipelineLayout pipeline_layout;509VkDescriptorSetLayout ds_layout;510} blit;511512struct {513VkPipelineLayout p_layouts[5];514VkDescriptorSetLayout ds_layouts[5];515VkPipeline pipelines[5][NUM_META_FS_KEYS];516517VkPipeline depth_only_pipeline[5];518519VkPipeline stencil_only_pipeline[5];520} blit2d[MAX_SAMPLES_LOG2];521522VkRenderPass blit2d_render_passes[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];523VkRenderPass blit2d_depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];524VkRenderPass blit2d_stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];525526struct {527VkPipelineLayout img_p_layout;528VkDescriptorSetLayout img_ds_layout;529VkPipeline pipeline;530VkPipeline pipeline_3d;531} itob;532struct {533VkPipelineLayout img_p_layout;534VkDescriptorSetLayout img_ds_layout;535VkPipeline pipeline;536VkPipeline pipeline_3d;537} btoi;538struct {539VkPipelineLayout img_p_layout;540VkDescriptorSetLayout img_ds_layout;541VkPipeline pipeline;542} btoi_r32g32b32;543struct {544VkPipelineLayout img_p_layout;545VkDescriptorSetLayout img_ds_layout;546VkPipeline pipeline[MAX_SAMPLES_LOG2];547VkPipeline pipeline_3d;548} itoi;549struct {550VkPipelineLayout img_p_layout;551VkDescriptorSetLayout img_ds_layout;552VkPipeline pipeline;553} itoi_r32g32b32;554struct {555VkPipelineLayout img_p_layout;556VkDescriptorSetLayout img_ds_layout;557VkPipeline pipeline[MAX_SAMPLES_LOG2];558VkPipeline pipeline_3d;559} cleari;560struct {561VkPipelineLayout img_p_layout;562VkDescriptorSetLayout img_ds_layout;563VkPipeline pipeline;564} cleari_r32g32b32;565566struct {567VkPipelineLayout p_layout;568VkPipeline pipeline[NUM_META_FS_KEYS];569VkRenderPass pass[NUM_META_FS_KEYS];570} resolve;571572struct {573VkDescriptorSetLayout ds_layout;574VkPipelineLayout p_layout;575struct {576VkPipeline pipeline;577VkPipeline i_pipeline;578VkPipeline srgb_pipeline;579} rc[MAX_SAMPLES_LOG2];580581VkPipeline depth_zero_pipeline;582struct {583VkPipeline average_pipeline;584VkPipeline max_pipeline;585VkPipeline min_pipeline;586} depth[MAX_SAMPLES_LOG2];587588VkPipeline stencil_zero_pipeline;589struct {590VkPipeline max_pipeline;591VkPipeline min_pipeline;592} stencil[MAX_SAMPLES_LOG2];593} resolve_compute;594595struct {596VkDescriptorSetLayout ds_layout;597VkPipelineLayout p_layout;598599struct {600VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];601VkPipeline pipeline[NUM_META_FS_KEYS];602} rc[MAX_SAMPLES_LOG2];603604VkRenderPass depth_render_pass;605VkPipeline depth_zero_pipeline;606struct {607VkPipeline average_pipeline;608VkPipeline max_pipeline;609VkPipeline min_pipeline;610} depth[MAX_SAMPLES_LOG2];611612VkRenderPass stencil_render_pass;613VkPipeline stencil_zero_pipeline;614struct {615VkPipeline max_pipeline;616VkPipeline min_pipeline;617} stencil[MAX_SAMPLES_LOG2];618} resolve_fragment;619620struct {621VkPipelineLayout p_layout;622VkPipeline decompress_pipeline;623VkPipeline resummarize_pipeline;624VkRenderPass pass;625} depth_decomp[MAX_SAMPLES_LOG2];626627struct {628VkPipelineLayout p_layout;629VkPipeline cmask_eliminate_pipeline;630VkPipeline fmask_decompress_pipeline;631VkPipeline dcc_decompress_pipeline;632VkRenderPass pass;633634VkDescriptorSetLayout dcc_decompress_compute_ds_layout;635VkPipelineLayout dcc_decompress_compute_p_layout;636VkPipeline dcc_decompress_compute_pipeline;637} fast_clear_flush;638639struct {640VkPipelineLayout fill_p_layout;641VkPipelineLayout copy_p_layout;642VkDescriptorSetLayout fill_ds_layout;643VkDescriptorSetLayout copy_ds_layout;644VkPipeline fill_pipeline;645VkPipeline copy_pipeline;646} buffer;647648struct {649VkDescriptorSetLayout ds_layout;650VkPipelineLayout p_layout;651VkPipeline occlusion_query_pipeline;652VkPipeline pipeline_statistics_query_pipeline;653VkPipeline tfb_query_pipeline;654VkPipeline timestamp_query_pipeline;655} query;656657struct {658VkDescriptorSetLayout ds_layout;659VkPipelineLayout p_layout;660VkPipeline pipeline[MAX_SAMPLES_LOG2];661} fmask_expand;662663struct {664VkDescriptorSetLayout ds_layout;665VkPipelineLayout p_layout;666VkPipeline pipeline;667} dcc_retile;668669struct {670VkPipelineLayout leaf_p_layout;671VkPipeline leaf_pipeline;672VkPipelineLayout internal_p_layout;673VkPipeline internal_pipeline;674} accel_struct_build;675};676677/* queue types */678#define RADV_QUEUE_GENERAL 0679#define RADV_QUEUE_COMPUTE 1680#define RADV_QUEUE_TRANSFER 2681682/* Not a real queue family */683#define RADV_QUEUE_FOREIGN 3684685#define RADV_MAX_QUEUE_FAMILIES 3686687#define RADV_NUM_HW_CTX (RADEON_CTX_PRIORITY_REALTIME + 1)688689struct radv_deferred_queue_submission;690691enum ring_type radv_queue_family_to_ring(int f);692693struct radv_queue {694struct vk_object_base base;695struct radv_device *device;696struct radeon_winsys_ctx *hw_ctx;697enum radeon_ctx_priority priority;698uint32_t queue_family_index;699int queue_idx;700VkDeviceQueueCreateFlags flags;701702uint32_t scratch_size_per_wave;703uint32_t scratch_waves;704uint32_t compute_scratch_size_per_wave;705uint32_t compute_scratch_waves;706uint32_t esgs_ring_size;707uint32_t gsvs_ring_size;708bool has_tess_rings;709bool has_gds;710bool has_gds_oa;711bool has_sample_positions;712713struct radeon_winsys_bo *scratch_bo;714struct radeon_winsys_bo *descriptor_bo;715struct radeon_winsys_bo *compute_scratch_bo;716struct radeon_winsys_bo *esgs_ring_bo;717struct radeon_winsys_bo *gsvs_ring_bo;718struct radeon_winsys_bo *tess_rings_bo;719struct radeon_winsys_bo *gds_bo;720struct radeon_winsys_bo *gds_oa_bo;721struct radeon_cmdbuf *initial_preamble_cs;722struct radeon_cmdbuf *initial_full_flush_preamble_cs;723struct radeon_cmdbuf *continue_preamble_cs;724725struct list_head pending_submissions;726mtx_t pending_mutex;727728mtx_t thread_mutex;729struct u_cnd_monotonic thread_cond;730struct radv_deferred_queue_submission *thread_submission;731thrd_t submission_thread;732bool thread_exit;733bool thread_running;734bool cond_created;735};736737#define RADV_BORDER_COLOR_COUNT 4096738#define RADV_BORDER_COLOR_BUFFER_SIZE (sizeof(VkClearColorValue) * RADV_BORDER_COLOR_COUNT)739740struct radv_device_border_color_data {741bool used[RADV_BORDER_COLOR_COUNT];742743struct radeon_winsys_bo *bo;744VkClearColorValue *colors_gpu_ptr;745746/* Mutex is required to guarantee vkCreateSampler thread safety747* given that we are writing to a buffer and checking color occupation */748mtx_t mutex;749};750751enum radv_force_vrs {752RADV_FORCE_VRS_NONE = 0,753RADV_FORCE_VRS_2x2,754RADV_FORCE_VRS_2x1,755RADV_FORCE_VRS_1x2,756};757758struct radv_device {759struct vk_device vk;760761struct radv_instance *instance;762struct radeon_winsys *ws;763764struct radeon_winsys_ctx *hw_ctx[RADV_NUM_HW_CTX];765struct radv_meta_state meta_state;766767struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];768int queue_count[RADV_MAX_QUEUE_FAMILIES];769struct radeon_cmdbuf *empty_cs[RADV_MAX_QUEUE_FAMILIES];770771bool pbb_allowed;772uint32_t tess_offchip_block_dw_size;773uint32_t scratch_waves;774uint32_t dispatch_initiator;775776uint32_t gs_table_depth;777778/* MSAA sample locations.779* The first index is the sample index.780* The second index is the coordinate: X, Y. */781float sample_locations_1x[1][2];782float sample_locations_2x[2][2];783float sample_locations_4x[4][2];784float sample_locations_8x[8][2];785786/* GFX7 and later */787uint32_t gfx_init_size_dw;788struct radeon_winsys_bo *gfx_init;789790struct radeon_winsys_bo *trace_bo;791uint32_t *trace_id_ptr;792793/* Whether to keep shader debug info, for tracing or VK_AMD_shader_info */794bool keep_shader_info;795796struct radv_physical_device *physical_device;797798/* Backup in-memory cache to be used if the app doesn't provide one */799struct radv_pipeline_cache *mem_cache;800801/*802* use different counters so MSAA MRTs get consecutive surface indices,803* even if MASK is allocated in between.804*/805uint32_t image_mrt_offset_counter;806uint32_t fmask_mrt_offset_counter;807struct list_head shader_slabs;808mtx_t shader_slab_mutex;809810/* For detecting VM faults reported by dmesg. */811uint64_t dmesg_timestamp;812813/* Whether the app has enabled the robustBufferAccess/robustBufferAccess2 features. */814bool robust_buffer_access;815bool robust_buffer_access2;816817/* Whether gl_FragCoord.z should be adjusted for VRS due to a hw bug818* on some GFX10.3 chips.819*/820bool adjust_frag_coord_z;821822/* Whether the driver uses a global BO list. */823bool use_global_bo_list;824825/* Whether attachment VRS is enabled. */826bool attachment_vrs_enabled;827828/* Whether anisotropy is forced with RADV_TEX_ANISO (-1 is disabled). */829int force_aniso;830831struct radv_device_border_color_data border_color_data;832833/* Condition variable for legacy timelines, to notify waiters when a834* new point gets submitted. */835struct u_cnd_monotonic timeline_cond;836837/* Thread trace. */838struct ac_thread_trace_data thread_trace;839840/* Trap handler. */841struct radv_shader_variant *trap_handler_shader;842struct radeon_winsys_bo *tma_bo; /* Trap Memory Address */843uint32_t *tma_ptr;844845/* Overallocation. */846bool overallocation_disallowed;847uint64_t allocated_memory_size[VK_MAX_MEMORY_HEAPS];848mtx_t overallocation_mutex;849850/* Track the number of device loss occurs. */851int lost;852853/* Whether the user forced VRS rates on GFX10.3+. */854enum radv_force_vrs force_vrs;855856/* Depth image for VRS when not bound by the app. */857struct {858struct radv_image *image;859struct radv_device_memory *mem;860} vrs;861};862863VkResult _radv_device_set_lost(struct radv_device *device, const char *file, int line,864const char *msg, ...) radv_printflike(4, 5);865866#define radv_device_set_lost(dev, ...) _radv_device_set_lost(dev, __FILE__, __LINE__, __VA_ARGS__)867868static inline bool869radv_device_is_lost(const struct radv_device *device)870{871return unlikely(p_atomic_read(&device->lost));872}873874struct radv_device_memory {875struct vk_object_base base;876struct radeon_winsys_bo *bo;877/* for dedicated allocations */878struct radv_image *image;879struct radv_buffer *buffer;880uint32_t heap_index;881uint64_t alloc_size;882void *map;883void *user_ptr;884885#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER886struct AHardwareBuffer *android_hardware_buffer;887#endif888};889890struct radv_descriptor_range {891uint64_t va;892uint32_t size;893};894895struct radv_descriptor_set_header {896struct vk_object_base base;897const struct radv_descriptor_set_layout *layout;898uint32_t size;899uint32_t buffer_count;900901struct radeon_winsys_bo *bo;902uint64_t va;903uint32_t *mapped_ptr;904struct radv_descriptor_range *dynamic_descriptors;905};906907struct radv_descriptor_set {908struct radv_descriptor_set_header header;909910struct radeon_winsys_bo *descriptors[];911};912913struct radv_push_descriptor_set {914struct radv_descriptor_set_header set;915uint32_t capacity;916};917918struct radv_descriptor_pool_entry {919uint32_t offset;920uint32_t size;921struct radv_descriptor_set *set;922};923924struct radv_descriptor_pool {925struct vk_object_base base;926struct radeon_winsys_bo *bo;927uint8_t *host_bo;928uint8_t *mapped_ptr;929uint64_t current_offset;930uint64_t size;931932uint8_t *host_memory_base;933uint8_t *host_memory_ptr;934uint8_t *host_memory_end;935936uint32_t entry_count;937uint32_t max_entry_count;938struct radv_descriptor_pool_entry entries[0];939};940941struct radv_descriptor_update_template_entry {942VkDescriptorType descriptor_type;943944/* The number of descriptors to update */945uint32_t descriptor_count;946947/* Into mapped_ptr or dynamic_descriptors, in units of the respective array */948uint32_t dst_offset;949950/* In dwords. Not valid/used for dynamic descriptors */951uint32_t dst_stride;952953uint32_t buffer_offset;954955/* Only valid for combined image samplers and samplers */956uint8_t has_sampler;957uint8_t sampler_offset;958959/* In bytes */960size_t src_offset;961size_t src_stride;962963/* For push descriptors */964const uint32_t *immutable_samplers;965};966967struct radv_descriptor_update_template {968struct vk_object_base base;969uint32_t entry_count;970VkPipelineBindPoint bind_point;971struct radv_descriptor_update_template_entry entry[0];972};973974struct radv_buffer {975struct vk_object_base base;976VkDeviceSize size;977978VkBufferUsageFlags usage;979VkBufferCreateFlags flags;980981/* Set when bound */982struct radeon_winsys_bo *bo;983VkDeviceSize offset;984985bool shareable;986};987988enum radv_dynamic_state_bits {989RADV_DYNAMIC_VIEWPORT = 1ull << 0,990RADV_DYNAMIC_SCISSOR = 1ull << 1,991RADV_DYNAMIC_LINE_WIDTH = 1ull << 2,992RADV_DYNAMIC_DEPTH_BIAS = 1ull << 3,993RADV_DYNAMIC_BLEND_CONSTANTS = 1ull << 4,994RADV_DYNAMIC_DEPTH_BOUNDS = 1ull << 5,995RADV_DYNAMIC_STENCIL_COMPARE_MASK = 1ull << 6,996RADV_DYNAMIC_STENCIL_WRITE_MASK = 1ull << 7,997RADV_DYNAMIC_STENCIL_REFERENCE = 1ull << 8,998RADV_DYNAMIC_DISCARD_RECTANGLE = 1ull << 9,999RADV_DYNAMIC_SAMPLE_LOCATIONS = 1ull << 10,1000RADV_DYNAMIC_LINE_STIPPLE = 1ull << 11,1001RADV_DYNAMIC_CULL_MODE = 1ull << 12,1002RADV_DYNAMIC_FRONT_FACE = 1ull << 13,1003RADV_DYNAMIC_PRIMITIVE_TOPOLOGY = 1ull << 14,1004RADV_DYNAMIC_DEPTH_TEST_ENABLE = 1ull << 15,1005RADV_DYNAMIC_DEPTH_WRITE_ENABLE = 1ull << 16,1006RADV_DYNAMIC_DEPTH_COMPARE_OP = 1ull << 17,1007RADV_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE = 1ull << 18,1008RADV_DYNAMIC_STENCIL_TEST_ENABLE = 1ull << 19,1009RADV_DYNAMIC_STENCIL_OP = 1ull << 20,1010RADV_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE = 1ull << 21,1011RADV_DYNAMIC_FRAGMENT_SHADING_RATE = 1ull << 22,1012RADV_DYNAMIC_PATCH_CONTROL_POINTS = 1ull << 23,1013RADV_DYNAMIC_RASTERIZER_DISCARD_ENABLE = 1ull << 24,1014RADV_DYNAMIC_DEPTH_BIAS_ENABLE = 1ull << 25,1015RADV_DYNAMIC_LOGIC_OP = 1ull << 26,1016RADV_DYNAMIC_PRIMITIVE_RESTART_ENABLE = 1ull << 27,1017RADV_DYNAMIC_COLOR_WRITE_ENABLE = 1ull << 28,1018RADV_DYNAMIC_ALL = (1ull << 29) - 1,1019};10201021enum radv_cmd_dirty_bits {1022/* Keep the dynamic state dirty bits in sync with1023* enum radv_dynamic_state_bits */1024RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1ull << 0,1025RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1ull << 1,1026RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1ull << 2,1027RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1ull << 3,1028RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1ull << 4,1029RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1ull << 5,1030RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1ull << 6,1031RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1ull << 7,1032RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1ull << 8,1033RADV_CMD_DIRTY_DYNAMIC_DISCARD_RECTANGLE = 1ull << 9,1034RADV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS = 1ull << 10,1035RADV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE = 1ull << 11,1036RADV_CMD_DIRTY_DYNAMIC_CULL_MODE = 1ull << 12,1037RADV_CMD_DIRTY_DYNAMIC_FRONT_FACE = 1ull << 13,1038RADV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY = 1ull << 14,1039RADV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE = 1ull << 15,1040RADV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE = 1ull << 16,1041RADV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP = 1ull << 17,1042RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE = 1ull << 18,1043RADV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE = 1ull << 19,1044RADV_CMD_DIRTY_DYNAMIC_STENCIL_OP = 1ull << 20,1045RADV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE = 1ull << 21,1046RADV_CMD_DIRTY_DYNAMIC_FRAGMENT_SHADING_RATE = 1ull << 22,1047RADV_CMD_DIRTY_DYNAMIC_PATCH_CONTROL_POINTS = 1ull << 23,1048RADV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE = 1ull << 24,1049RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS_ENABLE = 1ull << 25,1050RADV_CMD_DIRTY_DYNAMIC_LOGIC_OP = 1ull << 26,1051RADV_CMD_DIRTY_DYNAMIC_PRIMITIVE_RESTART_ENABLE = 1ull << 27,1052RADV_CMD_DIRTY_DYNAMIC_COLOR_WRITE_ENABLE = 1ull << 28,1053RADV_CMD_DIRTY_DYNAMIC_ALL = (1ull << 29) - 1,1054RADV_CMD_DIRTY_PIPELINE = 1ull << 29,1055RADV_CMD_DIRTY_INDEX_BUFFER = 1ull << 30,1056RADV_CMD_DIRTY_FRAMEBUFFER = 1ull << 31,1057RADV_CMD_DIRTY_VERTEX_BUFFER = 1ull << 32,1058RADV_CMD_DIRTY_STREAMOUT_BUFFER = 1ull << 331059};10601061enum radv_cmd_flush_bits {1062/* Instruction cache. */1063RADV_CMD_FLAG_INV_ICACHE = 1 << 0,1064/* Scalar L1 cache. */1065RADV_CMD_FLAG_INV_SCACHE = 1 << 1,1066/* Vector L1 cache. */1067RADV_CMD_FLAG_INV_VCACHE = 1 << 2,1068/* L2 cache + L2 metadata cache writeback & invalidate.1069* GFX6-8: Used by shaders only. GFX9-10: Used by everything. */1070RADV_CMD_FLAG_INV_L2 = 1 << 3,1071/* L2 writeback (write dirty L2 lines to memory for non-L2 clients).1072* Only used for coherency with non-L2 clients like CB, DB, CP on GFX6-8.1073* GFX6-7 will do complete invalidation, because the writeback is unsupported. */1074RADV_CMD_FLAG_WB_L2 = 1 << 4,1075/* Invalidate the metadata cache. To be used when the DCC/HTILE metadata1076* changed and we want to read an image from shaders. */1077RADV_CMD_FLAG_INV_L2_METADATA = 1 << 5,1078/* Framebuffer caches */1079RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 6,1080RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 7,1081RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 8,1082RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 9,1083/* Engine synchronization. */1084RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 10,1085RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 11,1086RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 12,1087RADV_CMD_FLAG_VGT_FLUSH = 1 << 13,1088/* Pipeline query controls. */1089RADV_CMD_FLAG_START_PIPELINE_STATS = 1 << 14,1090RADV_CMD_FLAG_STOP_PIPELINE_STATS = 1 << 15,1091RADV_CMD_FLAG_VGT_STREAMOUT_SYNC = 1 << 16,10921093RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER =1094(RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |1095RADV_CMD_FLAG_FLUSH_AND_INV_DB | RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)1096};10971098struct radv_vertex_binding {1099struct radv_buffer *buffer;1100VkDeviceSize offset;1101VkDeviceSize size;1102VkDeviceSize stride;1103};11041105struct radv_streamout_binding {1106struct radv_buffer *buffer;1107VkDeviceSize offset;1108VkDeviceSize size;1109};11101111struct radv_streamout_state {1112/* Mask of bound streamout buffers. */1113uint8_t enabled_mask;11141115/* External state that comes from the last vertex stage, it must be1116* set explicitely when binding a new graphics pipeline.1117*/1118uint16_t stride_in_dw[MAX_SO_BUFFERS];1119uint32_t enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */11201121/* State of VGT_STRMOUT_BUFFER_(CONFIG|END) */1122uint32_t hw_enabled_mask;11231124/* State of VGT_STRMOUT_(CONFIG|EN) */1125bool streamout_enabled;1126};11271128struct radv_viewport_state {1129uint32_t count;1130VkViewport viewports[MAX_VIEWPORTS];1131};11321133struct radv_scissor_state {1134uint32_t count;1135VkRect2D scissors[MAX_SCISSORS];1136};11371138struct radv_discard_rectangle_state {1139uint32_t count;1140VkRect2D rectangles[MAX_DISCARD_RECTANGLES];1141};11421143struct radv_sample_locations_state {1144VkSampleCountFlagBits per_pixel;1145VkExtent2D grid_size;1146uint32_t count;1147VkSampleLocationEXT locations[MAX_SAMPLE_LOCATIONS];1148};11491150struct radv_dynamic_state {1151/**1152* Bitmask of (1ull << VK_DYNAMIC_STATE_*).1153* Defines the set of saved dynamic state.1154*/1155uint64_t mask;11561157struct radv_viewport_state viewport;11581159struct radv_scissor_state scissor;11601161float line_width;11621163struct {1164float bias;1165float clamp;1166float slope;1167} depth_bias;11681169float blend_constants[4];11701171struct {1172float min;1173float max;1174} depth_bounds;11751176struct {1177uint32_t front;1178uint32_t back;1179} stencil_compare_mask;11801181struct {1182uint32_t front;1183uint32_t back;1184} stencil_write_mask;11851186struct {1187struct {1188VkStencilOp fail_op;1189VkStencilOp pass_op;1190VkStencilOp depth_fail_op;1191VkCompareOp compare_op;1192} front;11931194struct {1195VkStencilOp fail_op;1196VkStencilOp pass_op;1197VkStencilOp depth_fail_op;1198VkCompareOp compare_op;1199} back;1200} stencil_op;12011202struct {1203uint32_t front;1204uint32_t back;1205} stencil_reference;12061207struct radv_discard_rectangle_state discard_rectangle;12081209struct radv_sample_locations_state sample_location;12101211struct {1212uint32_t factor;1213uint16_t pattern;1214} line_stipple;12151216VkCullModeFlags cull_mode;1217VkFrontFace front_face;1218unsigned primitive_topology;12191220bool depth_test_enable;1221bool depth_write_enable;1222VkCompareOp depth_compare_op;1223bool depth_bounds_test_enable;1224bool stencil_test_enable;12251226struct {1227VkExtent2D size;1228VkFragmentShadingRateCombinerOpKHR combiner_ops[2];1229} fragment_shading_rate;12301231bool depth_bias_enable;1232bool primitive_restart_enable;1233bool rasterizer_discard_enable;12341235unsigned logic_op;12361237uint32_t color_write_enable;1238};12391240extern const struct radv_dynamic_state default_dynamic_state;12411242const char *radv_get_debug_option_name(int id);12431244const char *radv_get_perftest_option_name(int id);12451246int radv_get_int_debug_option(const char *name, int default_value);12471248struct radv_color_buffer_info {1249uint64_t cb_color_base;1250uint64_t cb_color_cmask;1251uint64_t cb_color_fmask;1252uint64_t cb_dcc_base;1253uint32_t cb_color_slice;1254uint32_t cb_color_view;1255uint32_t cb_color_info;1256uint32_t cb_color_attrib;1257uint32_t cb_color_attrib2; /* GFX9 and later */1258uint32_t cb_color_attrib3; /* GFX10 and later */1259uint32_t cb_dcc_control;1260uint32_t cb_color_cmask_slice;1261uint32_t cb_color_fmask_slice;1262union {1263uint32_t cb_color_pitch; // GFX6-GFX81264uint32_t cb_mrt_epitch; // GFX9+1265};1266};12671268struct radv_ds_buffer_info {1269uint64_t db_z_read_base;1270uint64_t db_stencil_read_base;1271uint64_t db_z_write_base;1272uint64_t db_stencil_write_base;1273uint64_t db_htile_data_base;1274uint32_t db_depth_info;1275uint32_t db_z_info;1276uint32_t db_stencil_info;1277uint32_t db_depth_view;1278uint32_t db_depth_size;1279uint32_t db_depth_slice;1280uint32_t db_htile_surface;1281uint32_t pa_su_poly_offset_db_fmt_cntl;1282uint32_t db_z_info2; /* GFX9 only */1283uint32_t db_stencil_info2; /* GFX9 only */1284};12851286void radv_initialise_color_surface(struct radv_device *device, struct radv_color_buffer_info *cb,1287struct radv_image_view *iview);1288void radv_initialise_ds_surface(struct radv_device *device, struct radv_ds_buffer_info *ds,1289struct radv_image_view *iview);12901291/**1292* Attachment state when recording a renderpass instance.1293*1294* The clear value is valid only if there exists a pending clear.1295*/1296struct radv_attachment_state {1297VkImageAspectFlags pending_clear_aspects;1298uint32_t cleared_views;1299VkClearValue clear_value;1300VkImageLayout current_layout;1301VkImageLayout current_stencil_layout;1302bool current_in_render_loop;1303bool disable_dcc;1304struct radv_sample_locations_state sample_location;13051306union {1307struct radv_color_buffer_info cb;1308struct radv_ds_buffer_info ds;1309};1310struct radv_image_view *iview;1311};13121313struct radv_descriptor_state {1314struct radv_descriptor_set *sets[MAX_SETS];1315uint32_t dirty;1316uint32_t valid;1317struct radv_push_descriptor_set push_set;1318bool push_dirty;1319uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];1320};13211322struct radv_subpass_sample_locs_state {1323uint32_t subpass_idx;1324struct radv_sample_locations_state sample_location;1325};13261327enum rgp_flush_bits {1328RGP_FLUSH_WAIT_ON_EOP_TS = 0x1,1329RGP_FLUSH_VS_PARTIAL_FLUSH = 0x2,1330RGP_FLUSH_PS_PARTIAL_FLUSH = 0x4,1331RGP_FLUSH_CS_PARTIAL_FLUSH = 0x8,1332RGP_FLUSH_PFP_SYNC_ME = 0x10,1333RGP_FLUSH_SYNC_CP_DMA = 0x20,1334RGP_FLUSH_INVAL_VMEM_L0 = 0x40,1335RGP_FLUSH_INVAL_ICACHE = 0x80,1336RGP_FLUSH_INVAL_SMEM_L0 = 0x100,1337RGP_FLUSH_FLUSH_L2 = 0x200,1338RGP_FLUSH_INVAL_L2 = 0x400,1339RGP_FLUSH_FLUSH_CB = 0x800,1340RGP_FLUSH_INVAL_CB = 0x1000,1341RGP_FLUSH_FLUSH_DB = 0x2000,1342RGP_FLUSH_INVAL_DB = 0x4000,1343RGP_FLUSH_INVAL_L1 = 0x8000,1344};13451346struct radv_cmd_state {1347/* Vertex descriptors */1348uint64_t vb_va;13491350bool predicating;1351uint64_t dirty;13521353uint32_t prefetch_L2_mask;13541355struct radv_pipeline *pipeline;1356struct radv_pipeline *emitted_pipeline;1357struct radv_pipeline *compute_pipeline;1358struct radv_pipeline *emitted_compute_pipeline;1359struct radv_pipeline *rt_pipeline; /* emitted = emitted_compute_pipeline */1360struct radv_framebuffer *framebuffer;1361struct radv_render_pass *pass;1362const struct radv_subpass *subpass;1363struct radv_dynamic_state dynamic;1364struct radv_attachment_state *attachments;1365struct radv_streamout_state streamout;1366VkRect2D render_area;13671368uint32_t num_subpass_sample_locs;1369struct radv_subpass_sample_locs_state *subpass_sample_locs;13701371/* Index buffer */1372struct radv_buffer *index_buffer;1373uint64_t index_offset;1374uint32_t index_type;1375uint32_t max_index_count;1376uint64_t index_va;1377int32_t last_index_type;13781379int32_t last_primitive_reset_en;1380uint32_t last_primitive_reset_index;1381enum radv_cmd_flush_bits flush_bits;1382unsigned active_occlusion_queries;1383bool perfect_occlusion_queries_enabled;1384unsigned active_pipeline_queries;1385unsigned active_pipeline_gds_queries;1386uint32_t trace_id;1387uint32_t last_ia_multi_vgt_param;13881389uint32_t last_num_instances;1390uint32_t last_first_instance;1391uint32_t last_vertex_offset;1392uint32_t last_drawid;13931394uint32_t last_sx_ps_downconvert;1395uint32_t last_sx_blend_opt_epsilon;1396uint32_t last_sx_blend_opt_control;13971398/* Whether CP DMA is busy/idle. */1399bool dma_is_busy;14001401/* Conditional rendering info. */1402uint8_t predication_op; /* 32-bit or 64-bit predicate value */1403int predication_type; /* -1: disabled, 0: normal, 1: inverted */1404uint64_t predication_va;14051406/* Inheritance info. */1407VkQueryPipelineStatisticFlags inherited_pipeline_statistics;14081409bool context_roll_without_scissor_emitted;14101411/* SQTT related state. */1412uint32_t current_event_type;1413uint32_t num_events;1414uint32_t num_layout_transitions;1415bool pending_sqtt_barrier_end;1416enum rgp_flush_bits sqtt_flush_bits;14171418/* NGG culling state. */1419uint32_t last_nggc_settings;1420int8_t last_nggc_settings_sgpr_idx;1421bool last_nggc_skip;14221423uint8_t cb_mip[MAX_RTS];14241425/* Whether DRAW_{INDEX}_INDIRECT_MULTI is emitted. */1426bool uses_draw_indirect_multi;1427};14281429struct radv_cmd_pool {1430struct vk_object_base base;1431VkAllocationCallbacks alloc;1432struct list_head cmd_buffers;1433struct list_head free_cmd_buffers;1434uint32_t queue_family_index;1435};14361437struct radv_cmd_buffer_upload {1438uint8_t *map;1439unsigned offset;1440uint64_t size;1441struct radeon_winsys_bo *upload_bo;1442struct list_head list;1443};14441445enum radv_cmd_buffer_status {1446RADV_CMD_BUFFER_STATUS_INVALID,1447RADV_CMD_BUFFER_STATUS_INITIAL,1448RADV_CMD_BUFFER_STATUS_RECORDING,1449RADV_CMD_BUFFER_STATUS_EXECUTABLE,1450RADV_CMD_BUFFER_STATUS_PENDING,1451};14521453struct radv_cmd_buffer {1454struct vk_object_base base;14551456struct radv_device *device;14571458struct radv_cmd_pool *pool;1459struct list_head pool_link;14601461VkCommandBufferUsageFlags usage_flags;1462VkCommandBufferLevel level;1463enum radv_cmd_buffer_status status;1464struct radeon_cmdbuf *cs;1465struct radv_cmd_state state;1466struct radv_vertex_binding vertex_bindings[MAX_VBS];1467struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];1468uint32_t queue_family_index;14691470uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];1471VkShaderStageFlags push_constant_stages;1472struct radv_descriptor_set_header meta_push_descriptors;14731474struct radv_descriptor_state descriptors[MAX_BIND_POINTS];14751476struct radv_cmd_buffer_upload upload;14771478uint32_t scratch_size_per_wave_needed;1479uint32_t scratch_waves_wanted;1480uint32_t compute_scratch_size_per_wave_needed;1481uint32_t compute_scratch_waves_wanted;1482uint32_t esgs_ring_size_needed;1483uint32_t gsvs_ring_size_needed;1484bool tess_rings_needed;1485bool gds_needed; /* for GFX10 streamout and NGG GS queries */1486bool gds_oa_needed; /* for GFX10 streamout */1487bool sample_positions_needed;14881489VkResult record_result;14901491uint64_t gfx9_fence_va;1492uint32_t gfx9_fence_idx;1493uint64_t gfx9_eop_bug_va;14941495/**1496* Whether a query pool has been resetted and we have to flush caches.1497*/1498bool pending_reset_query;14991500/**1501* Bitmask of pending active query flushes.1502*/1503enum radv_cmd_flush_bits active_query_flush_bits;1504};15051506struct radv_image;1507struct radv_image_view;15081509bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);15101511void si_emit_graphics(struct radv_device *device, struct radeon_cmdbuf *cs);1512void si_emit_compute(struct radv_device *device, struct radeon_cmdbuf *cs);15131514void cik_create_gfx_config(struct radv_device *device);15151516void si_write_viewport(struct radeon_cmdbuf *cs, int first_vp, int count,1517const VkViewport *viewports);1518void si_write_scissors(struct radeon_cmdbuf *cs, int first, int count, const VkRect2D *scissors,1519const VkViewport *viewports, bool can_use_guardband);1520uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer, bool instanced_draw,1521bool indirect_draw, bool count_from_stream_output,1522uint32_t draw_vertex_count, unsigned topology,1523bool prim_restart_enable);1524void si_cs_emit_write_event_eop(struct radeon_cmdbuf *cs, enum chip_class chip_class, bool is_mec,1525unsigned event, unsigned event_flags, unsigned dst_sel,1526unsigned data_sel, uint64_t va, uint32_t new_fence,1527uint64_t gfx9_eop_bug_va);15281529void radv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va, uint32_t ref,1530uint32_t mask);1531void si_cs_emit_cache_flush(struct radeon_cmdbuf *cs, enum chip_class chip_class,1532uint32_t *fence_ptr, uint64_t va, bool is_mec,1533enum radv_cmd_flush_bits flush_bits,1534enum rgp_flush_bits *sqtt_flush_bits, uint64_t gfx9_eop_bug_va);1535void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);1536void si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer, bool draw_visible,1537unsigned pred_op, uint64_t va);1538void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer, uint64_t src_va, uint64_t dest_va,1539uint64_t size);1540void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va, unsigned size);1541void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va, uint64_t size,1542unsigned value);1543void si_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer);15441545void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);1546bool radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer, unsigned size,1547unsigned *out_offset, void **ptr);1548void radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,1549const struct radv_subpass *subpass);1550bool radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer, unsigned size,1551const void *data, unsigned *out_offset);15521553void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);1554void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);1555void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);1556void radv_depth_stencil_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer,1557VkImageAspectFlags aspects,1558VkResolveModeFlagBits resolve_mode);1559void radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);1560void radv_depth_stencil_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer,1561VkImageAspectFlags aspects,1562VkResolveModeFlagBits resolve_mode);1563void radv_emit_default_sample_locations(struct radeon_cmdbuf *cs, int nr_samples);1564unsigned radv_get_default_max_sample_dist(int log_samples);1565void radv_device_init_msaa(struct radv_device *device);1566VkResult radv_device_init_vrs_image(struct radv_device *device);15671568void radv_update_ds_clear_metadata(struct radv_cmd_buffer *cmd_buffer,1569const struct radv_image_view *iview,1570VkClearDepthStencilValue ds_clear_value,1571VkImageAspectFlags aspects);15721573void radv_update_color_clear_metadata(struct radv_cmd_buffer *cmd_buffer,1574const struct radv_image_view *iview, int cb_idx,1575uint32_t color_values[2]);15761577bool radv_image_use_dcc_image_stores(const struct radv_device *device,1578const struct radv_image *image);1579bool radv_image_use_dcc_predication(const struct radv_device *device,1580const struct radv_image *image);1581void radv_update_fce_metadata(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,1582const VkImageSubresourceRange *range, bool value);15831584void radv_update_dcc_metadata(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,1585const VkImageSubresourceRange *range, bool value);1586enum radv_cmd_flush_bits radv_src_access_flush(struct radv_cmd_buffer *cmd_buffer,1587VkAccessFlags src_flags,1588const struct radv_image *image);1589enum radv_cmd_flush_bits radv_dst_access_flush(struct radv_cmd_buffer *cmd_buffer,1590VkAccessFlags dst_flags,1591const struct radv_image *image);1592uint32_t radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer, const struct radv_image *image,1593struct radeon_winsys_bo *bo, uint64_t offset, uint64_t size,1594uint32_t value);1595void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);1596bool radv_get_memory_fd(struct radv_device *device, struct radv_device_memory *memory, int *pFD);1597void radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAllocator,1598struct radv_device_memory *mem);15991600static inline void1601radv_emit_shader_pointer_head(struct radeon_cmdbuf *cs, unsigned sh_offset, unsigned pointer_count,1602bool use_32bit_pointers)1603{1604radeon_emit(cs, PKT3(PKT3_SET_SH_REG, pointer_count * (use_32bit_pointers ? 1 : 2), 0));1605radeon_emit(cs, (sh_offset - SI_SH_REG_OFFSET) >> 2);1606}16071608static inline void1609radv_emit_shader_pointer_body(struct radv_device *device, struct radeon_cmdbuf *cs, uint64_t va,1610bool use_32bit_pointers)1611{1612radeon_emit(cs, va);16131614if (use_32bit_pointers) {1615assert(va == 0 || (va >> 32) == device->physical_device->rad_info.address32_hi);1616} else {1617radeon_emit(cs, va >> 32);1618}1619}16201621static inline void1622radv_emit_shader_pointer(struct radv_device *device, struct radeon_cmdbuf *cs, uint32_t sh_offset,1623uint64_t va, bool global)1624{1625bool use_32bit_pointers = !global;16261627radv_emit_shader_pointer_head(cs, sh_offset, 1, use_32bit_pointers);1628radv_emit_shader_pointer_body(device, cs, va, use_32bit_pointers);1629}16301631static inline struct radv_descriptor_state *1632radv_get_descriptors_state(struct radv_cmd_buffer *cmd_buffer, VkPipelineBindPoint bind_point)1633{1634switch (bind_point) {1635case VK_PIPELINE_BIND_POINT_GRAPHICS:1636case VK_PIPELINE_BIND_POINT_COMPUTE:1637return &cmd_buffer->descriptors[bind_point];1638case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR:1639return &cmd_buffer->descriptors[2];1640default:1641unreachable("Unhandled bind point");1642}1643}16441645void1646radv_get_viewport_xform(const VkViewport *viewport, float scale[3], float translate[3]);16471648/*1649* Takes x,y,z as exact numbers of invocations, instead of blocks.1650*1651* Limitations: Can't call normal dispatch functions without binding or rebinding1652* the compute pipeline.1653*/1654void radv_unaligned_dispatch(struct radv_cmd_buffer *cmd_buffer, uint32_t x, uint32_t y,1655uint32_t z);16561657struct radv_event {1658struct vk_object_base base;1659struct radeon_winsys_bo *bo;1660uint64_t *map;1661};16621663#define RADV_HASH_SHADER_NO_NGG (1 << 0)1664#define RADV_HASH_SHADER_CS_WAVE32 (1 << 1)1665#define RADV_HASH_SHADER_PS_WAVE32 (1 << 2)1666#define RADV_HASH_SHADER_GE_WAVE32 (1 << 3)1667#define RADV_HASH_SHADER_LLVM (1 << 4)1668#define RADV_HASH_SHADER_DISCARD_TO_DEMOTE (1 << 5)1669#define RADV_HASH_SHADER_MRT_NAN_FIXUP (1 << 6)1670#define RADV_HASH_SHADER_INVARIANT_GEOM (1 << 7)1671#define RADV_HASH_SHADER_KEEP_STATISTICS (1 << 8)1672#define RADV_HASH_SHADER_FORCE_VRS_2x2 (1 << 9)1673#define RADV_HASH_SHADER_FORCE_VRS_2x1 (1 << 10)1674#define RADV_HASH_SHADER_FORCE_VRS_1x2 (1 << 11)1675#define RADV_HASH_SHADER_FORCE_NGG_CULLING (1 << 13)16761677void radv_hash_shaders(unsigned char *hash, const VkPipelineShaderStageCreateInfo **stages,1678const struct radv_pipeline_layout *layout,1679const struct radv_pipeline_key *key, uint32_t flags);16801681#define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)16821683#define radv_foreach_stage(stage, stage_bits) \1684for (gl_shader_stage stage, __tmp = (gl_shader_stage)((stage_bits)&RADV_STAGE_MASK); \1685stage = ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))16861687extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];1688unsigned radv_format_meta_fs_key(struct radv_device *device, VkFormat format);16891690struct radv_multisample_state {1691uint32_t db_eqaa;1692uint32_t pa_sc_mode_cntl_0;1693uint32_t pa_sc_mode_cntl_1;1694uint32_t pa_sc_aa_config;1695uint32_t pa_sc_aa_mask[2];1696unsigned num_samples;1697};16981699struct radv_vrs_state {1700uint32_t pa_cl_vrs_cntl;1701};17021703struct radv_prim_vertex_count {1704uint8_t min;1705uint8_t incr;1706};17071708struct radv_ia_multi_vgt_param_helpers {1709uint32_t base;1710bool partial_es_wave;1711uint8_t primgroup_size;1712bool ia_switch_on_eoi;1713bool partial_vs_wave;1714};17151716struct radv_binning_state {1717uint32_t pa_sc_binner_cntl_0;1718};17191720#define SI_GS_PER_ES 12817211722struct radv_pipeline {1723struct vk_object_base base;1724struct radv_device *device;1725struct radv_dynamic_state dynamic_state;17261727struct radv_pipeline_layout *layout;17281729bool need_indirect_descriptor_sets;1730struct radv_shader_variant *shaders[MESA_SHADER_STAGES];1731struct radv_shader_variant *gs_copy_shader;1732VkShaderStageFlags active_stages;17331734struct radeon_cmdbuf cs;1735uint32_t ctx_cs_hash;1736struct radeon_cmdbuf ctx_cs;17371738uint32_t binding_stride[MAX_VBS];17391740uint8_t attrib_bindings[MAX_VERTEX_ATTRIBS];1741uint32_t attrib_ends[MAX_VERTEX_ATTRIBS];1742uint32_t attrib_index_offset[MAX_VERTEX_ATTRIBS];17431744bool use_per_attribute_vb_descs;1745uint32_t vb_desc_usage_mask;1746uint32_t vb_desc_alloc_size;17471748uint32_t user_data_0[MESA_SHADER_STAGES];1749union {1750struct {1751struct radv_multisample_state ms;1752struct radv_binning_state binning;1753struct radv_vrs_state vrs;1754uint32_t spi_baryc_cntl;1755unsigned esgs_ring_size;1756unsigned gsvs_ring_size;1757uint32_t vtx_base_sgpr;1758struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;1759uint8_t vtx_emit_num;1760bool uses_drawid;1761bool uses_baseinstance;1762bool can_use_guardband;1763uint64_t needed_dynamic_state;1764bool disable_out_of_order_rast_for_occlusion;1765unsigned tess_patch_control_points;1766unsigned pa_su_sc_mode_cntl;1767unsigned db_depth_control;1768unsigned pa_cl_clip_cntl;1769unsigned cb_color_control;1770bool uses_dynamic_stride;1771bool uses_conservative_overestimate;17721773/* Used for rbplus */1774uint32_t col_format;1775uint32_t cb_target_mask;17761777/* Whether the pipeline uses NGG (GFX10+). */1778bool is_ngg;1779bool has_ngg_culling;17801781/* Last pre-PS API stage */1782gl_shader_stage last_vgt_api_stage;1783} graphics;1784};17851786unsigned max_waves;1787unsigned scratch_bytes_per_wave;17881789/* Not NULL if graphics pipeline uses streamout. */1790struct radv_shader_variant *streamout_shader;17911792/* Unique pipeline hash identifier. */1793uint64_t pipeline_hash;1794};17951796static inline bool1797radv_pipeline_has_gs(const struct radv_pipeline *pipeline)1798{1799return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;1800}18011802static inline bool1803radv_pipeline_has_tess(const struct radv_pipeline *pipeline)1804{1805return pipeline->shaders[MESA_SHADER_TESS_CTRL] ? true : false;1806}18071808bool radv_pipeline_has_ngg_passthrough(const struct radv_pipeline *pipeline);18091810bool radv_pipeline_has_gs_copy_shader(const struct radv_pipeline *pipeline);18111812struct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,1813gl_shader_stage stage, int idx);18141815struct radv_shader_variant *radv_get_shader(const struct radv_pipeline *pipeline,1816gl_shader_stage stage);18171818struct radv_graphics_pipeline_create_info {1819bool use_rectlist;1820bool db_depth_clear;1821bool db_stencil_clear;1822bool db_depth_disable_expclear;1823bool db_stencil_disable_expclear;1824bool depth_compress_disable;1825bool stencil_compress_disable;1826bool resummarize_enable;1827uint32_t custom_blend_mode;1828};18291830VkResult radv_graphics_pipeline_create(VkDevice device, VkPipelineCache cache,1831const VkGraphicsPipelineCreateInfo *pCreateInfo,1832const struct radv_graphics_pipeline_create_info *extra,1833const VkAllocationCallbacks *alloc, VkPipeline *pPipeline);18341835struct radv_binning_settings {1836unsigned context_states_per_bin; /* allowed range: [1, 6] */1837unsigned persistent_states_per_bin; /* allowed range: [1, 32] */1838unsigned fpovs_per_batch; /* allowed range: [0, 255], 0 = unlimited */1839};18401841struct radv_binning_settings radv_get_binning_settings(const struct radv_physical_device *pdev);18421843struct vk_format_description;1844uint32_t radv_translate_buffer_dataformat(const struct util_format_description *desc,1845int first_non_void);1846uint32_t radv_translate_buffer_numformat(const struct util_format_description *desc,1847int first_non_void);1848bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);1849uint32_t radv_translate_colorformat(VkFormat format);1850uint32_t radv_translate_color_numformat(VkFormat format, const struct util_format_description *desc,1851int first_non_void);1852uint32_t radv_colorformat_endian_swap(uint32_t colorformat);1853unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);1854uint32_t radv_translate_dbformat(VkFormat format);1855uint32_t radv_translate_tex_dataformat(VkFormat format, const struct util_format_description *desc,1856int first_non_void);1857uint32_t radv_translate_tex_numformat(VkFormat format, const struct util_format_description *desc,1858int first_non_void);1859bool radv_format_pack_clear_color(VkFormat format, uint32_t clear_vals[2],1860VkClearColorValue *value);1861bool radv_is_storage_image_format_supported(struct radv_physical_device *physical_device,1862VkFormat format);1863bool radv_is_colorbuffer_format_supported(const struct radv_physical_device *pdevice,1864VkFormat format, bool *blendable);1865bool radv_dcc_formats_compatible(VkFormat format1, VkFormat format2);1866bool radv_is_atomic_format_supported(VkFormat format);1867bool radv_device_supports_etc(struct radv_physical_device *physical_device);18681869struct radv_image_plane {1870VkFormat format;1871struct radeon_surf surface;1872};18731874struct radv_image {1875struct vk_object_base base;1876VkImageType type;1877/* The original VkFormat provided by the client. This may not match any1878* of the actual surface formats.1879*/1880VkFormat vk_format;1881VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */1882struct ac_surf_info info;1883VkImageTiling tiling; /** VkImageCreateInfo::tiling */1884VkImageCreateFlags flags; /** VkImageCreateInfo::flags */18851886VkDeviceSize size;1887uint32_t alignment;18881889unsigned queue_family_mask;1890bool exclusive;1891bool shareable;1892bool l2_coherent;18931894/* Set when bound */1895struct radeon_winsys_bo *bo;1896VkDeviceSize offset;1897bool tc_compatible_cmask;18981899uint64_t clear_value_offset;1900uint64_t fce_pred_offset;1901uint64_t dcc_pred_offset;19021903/*1904* Metadata for the TC-compat zrange workaround. If the 32-bit value1905* stored at this offset is UINT_MAX, the driver will emit1906* DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the1907* SET_CONTEXT_REG packet.1908*/1909uint64_t tc_compat_zrange_offset;19101911/* For VK_ANDROID_native_buffer, the WSI image owns the memory, */1912VkDeviceMemory owned_memory;19131914unsigned plane_count;1915struct radv_image_plane planes[0];1916};19171918/* Whether the image has a htile that is known consistent with the contents of1919* the image and is allowed to be in compressed form.1920*1921* If this is false reads that don't use the htile should be able to return1922* correct results.1923*/1924bool radv_layout_is_htile_compressed(const struct radv_device *device,1925const struct radv_image *image, VkImageLayout layout,1926bool in_render_loop, unsigned queue_mask);19271928bool radv_layout_can_fast_clear(const struct radv_device *device, const struct radv_image *image,1929unsigned level, VkImageLayout layout, bool in_render_loop,1930unsigned queue_mask);19311932bool radv_layout_dcc_compressed(const struct radv_device *device, const struct radv_image *image,1933unsigned level, VkImageLayout layout, bool in_render_loop,1934unsigned queue_mask);19351936bool radv_layout_fmask_compressed(const struct radv_device *device, const struct radv_image *image,1937VkImageLayout layout, unsigned queue_mask);19381939/**1940* Return whether the image has CMASK metadata for color surfaces.1941*/1942static inline bool1943radv_image_has_cmask(const struct radv_image *image)1944{1945return image->planes[0].surface.cmask_offset;1946}19471948/**1949* Return whether the image has FMASK metadata for color surfaces.1950*/1951static inline bool1952radv_image_has_fmask(const struct radv_image *image)1953{1954return image->planes[0].surface.fmask_offset;1955}19561957/**1958* Return whether the image has DCC metadata for color surfaces.1959*/1960static inline bool1961radv_image_has_dcc(const struct radv_image *image)1962{1963return !(image->planes[0].surface.flags & RADEON_SURF_Z_OR_SBUFFER) &&1964image->planes[0].surface.meta_offset;1965}19661967/**1968* Return whether the image is TC-compatible CMASK.1969*/1970static inline bool1971radv_image_is_tc_compat_cmask(const struct radv_image *image)1972{1973return radv_image_has_fmask(image) && image->tc_compatible_cmask;1974}19751976/**1977* Return whether DCC metadata is enabled for a level.1978*/1979static inline bool1980radv_dcc_enabled(const struct radv_image *image, unsigned level)1981{1982return radv_image_has_dcc(image) && level < image->planes[0].surface.num_meta_levels;1983}19841985/**1986* Return whether the image has CB metadata.1987*/1988static inline bool1989radv_image_has_CB_metadata(const struct radv_image *image)1990{1991return radv_image_has_cmask(image) || radv_image_has_fmask(image) || radv_image_has_dcc(image);1992}19931994/**1995* Return whether the image has HTILE metadata for depth surfaces.1996*/1997static inline bool1998radv_image_has_htile(const struct radv_image *image)1999{2000return image->planes[0].surface.flags & RADEON_SURF_Z_OR_SBUFFER &&2001image->planes[0].surface.meta_size;2002}20032004/**2005* Return whether the image has VRS HTILE metadata for depth surfaces2006*/2007static inline bool2008radv_image_has_vrs_htile(const struct radv_device *device, const struct radv_image *image)2009{2010/* Any depth buffer can potentially use VRS. */2011return device->attachment_vrs_enabled && radv_image_has_htile(image) &&2012(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);2013}20142015/**2016* Return whether HTILE metadata is enabled for a level.2017*/2018static inline bool2019radv_htile_enabled(const struct radv_image *image, unsigned level)2020{2021return radv_image_has_htile(image) && level < image->planes[0].surface.num_meta_levels;2022}20232024/**2025* Return whether the image is TC-compatible HTILE.2026*/2027static inline bool2028radv_image_is_tc_compat_htile(const struct radv_image *image)2029{2030return radv_image_has_htile(image) &&2031(image->planes[0].surface.flags & RADEON_SURF_TC_COMPATIBLE_HTILE);2032}20332034/**2035* Return whether the entire HTILE buffer can be used for depth in order to2036* improve HiZ Z-Range precision.2037*/2038static inline bool2039radv_image_tile_stencil_disabled(const struct radv_device *device, const struct radv_image *image)2040{2041if (device->physical_device->rad_info.chip_class >= GFX9) {2042return !vk_format_has_stencil(image->vk_format) && !radv_image_has_vrs_htile(device, image);2043} else {2044/* Due to a hw bug, TILE_STENCIL_DISABLE must be set to 0 for2045* the TC-compat ZRANGE issue even if no stencil is used.2046*/2047return !vk_format_has_stencil(image->vk_format) && !radv_image_is_tc_compat_htile(image);2048}2049}20502051static inline bool2052radv_image_has_clear_value(const struct radv_image *image)2053{2054return image->clear_value_offset != 0;2055}20562057static inline uint64_t2058radv_image_get_fast_clear_va(const struct radv_image *image, uint32_t base_level)2059{2060assert(radv_image_has_clear_value(image));20612062uint64_t va = radv_buffer_get_va(image->bo);2063va += image->offset + image->clear_value_offset + base_level * 8;2064return va;2065}20662067static inline uint64_t2068radv_image_get_fce_pred_va(const struct radv_image *image, uint32_t base_level)2069{2070assert(image->fce_pred_offset != 0);20712072uint64_t va = radv_buffer_get_va(image->bo);2073va += image->offset + image->fce_pred_offset + base_level * 8;2074return va;2075}20762077static inline uint64_t2078radv_image_get_dcc_pred_va(const struct radv_image *image, uint32_t base_level)2079{2080assert(image->dcc_pred_offset != 0);20812082uint64_t va = radv_buffer_get_va(image->bo);2083va += image->offset + image->dcc_pred_offset + base_level * 8;2084return va;2085}20862087static inline uint64_t2088radv_get_tc_compat_zrange_va(const struct radv_image *image, uint32_t base_level)2089{2090assert(image->tc_compat_zrange_offset != 0);20912092uint64_t va = radv_buffer_get_va(image->bo);2093va += image->offset + image->tc_compat_zrange_offset + base_level * 4;2094return va;2095}20962097static inline uint64_t2098radv_get_ds_clear_value_va(const struct radv_image *image, uint32_t base_level)2099{2100assert(radv_image_has_clear_value(image));21012102uint64_t va = radv_buffer_get_va(image->bo);2103va += image->offset + image->clear_value_offset + base_level * 8;2104return va;2105}21062107static inline uint32_t2108radv_get_htile_initial_value(const struct radv_device *device, const struct radv_image *image)2109{2110uint32_t initial_value;21112112if (radv_image_tile_stencil_disabled(device, image)) {2113/* Z only (no stencil):2114*2115* |31 18|17 4|3 0|2116* +---------+---------+-------+2117* | Max Z | Min Z | ZMask |2118*/2119initial_value = 0xfffc000f;2120} else {2121/* Z and stencil:2122*2123* |31 12|11 10|9 8|7 6|5 4|3 0|2124* +-----------+-----+------+-----+-----+-------+2125* | Z Range | | SMem | SR1 | SR0 | ZMask |2126*2127* SR0/SR1 contains the stencil test results. Initializing2128* SR0/SR1 to 0x3 means the stencil test result is unknown.2129*2130* Z, stencil and 4 bit VRS encoding:2131* |31 12|11 10|9 8|7 6|5 4|3 0|2132* +-----------+------------+------+------------+-----+-------+2133* | Z Range | VRS y-rate | SMem | VRS x-rate | SR0 | ZMask |2134*/2135if (radv_image_has_vrs_htile(device, image)) {2136/* Initialize the VRS x-rate value at 0, so the hw interprets it as 1 sample. */2137initial_value = 0xfffff33f;2138} else {2139initial_value = 0xfffff3ff;2140}2141}21422143return initial_value;2144}21452146static inline bool2147radv_image_get_iterate256(struct radv_device *device, struct radv_image *image)2148{2149/* ITERATE_256 is required for depth or stencil MSAA images that are TC-compatible HTILE. */2150return device->physical_device->rad_info.chip_class >= GFX10 &&2151(image->usage & (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |2152VK_IMAGE_USAGE_TRANSFER_DST_BIT)) &&2153radv_image_is_tc_compat_htile(image) &&2154image->info.samples > 1;2155}21562157unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family,2158uint32_t queue_family);21592160static inline uint32_t2161radv_get_layerCount(const struct radv_image *image, const VkImageSubresourceRange *range)2162{2163return range->layerCount == VK_REMAINING_ARRAY_LAYERS2164? image->info.array_size - range->baseArrayLayer2165: range->layerCount;2166}21672168static inline uint32_t2169radv_get_levelCount(const struct radv_image *image, const VkImageSubresourceRange *range)2170{2171return range->levelCount == VK_REMAINING_MIP_LEVELS ? image->info.levels - range->baseMipLevel2172: range->levelCount;2173}21742175bool radv_image_is_renderable(struct radv_device *device, struct radv_image *image);21762177struct radeon_bo_metadata;2178void radv_init_metadata(struct radv_device *device, struct radv_image *image,2179struct radeon_bo_metadata *metadata);21802181void radv_image_override_offset_stride(struct radv_device *device, struct radv_image *image,2182uint64_t offset, uint32_t stride);21832184union radv_descriptor {2185struct {2186uint32_t plane0_descriptor[8];2187uint32_t fmask_descriptor[8];2188};2189struct {2190uint32_t plane_descriptors[3][8];2191};2192};21932194struct radv_image_view {2195struct vk_object_base base;2196struct radv_image *image; /**< VkImageViewCreateInfo::image */21972198VkImageViewType type;2199VkImageAspectFlags aspect_mask;2200VkFormat vk_format;2201unsigned plane_id;2202uint32_t base_layer;2203uint32_t layer_count;2204uint32_t base_mip;2205uint32_t level_count;2206VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */22072208/* Whether the image iview supports fast clear. */2209bool support_fast_clear;22102211union radv_descriptor descriptor;22122213/* Descriptor for use as a storage image as opposed to a sampled image.2214* This has a few differences for cube maps (e.g. type).2215*/2216union radv_descriptor storage_descriptor;2217};22182219struct radv_image_create_info {2220const VkImageCreateInfo *vk_info;2221bool scanout;2222bool no_metadata_planes;2223const struct radeon_bo_metadata *bo_metadata;2224};22252226VkResult2227radv_image_create_layout(struct radv_device *device, struct radv_image_create_info create_info,2228const struct VkImageDrmFormatModifierExplicitCreateInfoEXT *mod_info,2229struct radv_image *image);22302231VkResult radv_image_create(VkDevice _device, const struct radv_image_create_info *info,2232const VkAllocationCallbacks *alloc, VkImage *pImage);22332234bool radv_are_formats_dcc_compatible(const struct radv_physical_device *pdev, const void *pNext,2235VkFormat format, VkImageCreateFlags flags);22362237bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format);22382239VkResult radv_image_from_gralloc(VkDevice device_h, const VkImageCreateInfo *base_info,2240const VkNativeBufferANDROID *gralloc_info,2241const VkAllocationCallbacks *alloc, VkImage *out_image_h);2242uint64_t radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,2243const VkImageUsageFlags vk_usage);2244VkResult radv_import_ahb_memory(struct radv_device *device, struct radv_device_memory *mem,2245unsigned priority,2246const VkImportAndroidHardwareBufferInfoANDROID *info);2247VkResult radv_create_ahb_memory(struct radv_device *device, struct radv_device_memory *mem,2248unsigned priority, const VkMemoryAllocateInfo *pAllocateInfo);22492250VkFormat radv_select_android_external_format(const void *next, VkFormat default_format);22512252bool radv_android_gralloc_supports_format(VkFormat format, VkImageUsageFlagBits usage);22532254struct radv_image_view_extra_create_info {2255bool disable_compression;2256bool enable_compression;2257};22582259void radv_image_view_init(struct radv_image_view *view, struct radv_device *device,2260const VkImageViewCreateInfo *pCreateInfo,2261const struct radv_image_view_extra_create_info *extra_create_info);22622263VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);22642265struct radv_sampler_ycbcr_conversion {2266struct vk_object_base base;2267VkFormat format;2268VkSamplerYcbcrModelConversion ycbcr_model;2269VkSamplerYcbcrRange ycbcr_range;2270VkComponentMapping components;2271VkChromaLocation chroma_offsets[2];2272VkFilter chroma_filter;2273};22742275struct radv_buffer_view {2276struct vk_object_base base;2277struct radeon_winsys_bo *bo;2278VkFormat vk_format;2279uint64_t range; /**< VkBufferViewCreateInfo::range */2280uint32_t state[4];2281};2282void radv_buffer_view_init(struct radv_buffer_view *view, struct radv_device *device,2283const VkBufferViewCreateInfo *pCreateInfo);22842285static inline struct VkExtent3D2286radv_sanitize_image_extent(const VkImageType imageType, const struct VkExtent3D imageExtent)2287{2288switch (imageType) {2289case VK_IMAGE_TYPE_1D:2290return (VkExtent3D){imageExtent.width, 1, 1};2291case VK_IMAGE_TYPE_2D:2292return (VkExtent3D){imageExtent.width, imageExtent.height, 1};2293case VK_IMAGE_TYPE_3D:2294return imageExtent;2295default:2296unreachable("invalid image type");2297}2298}22992300static inline struct VkOffset3D2301radv_sanitize_image_offset(const VkImageType imageType, const struct VkOffset3D imageOffset)2302{2303switch (imageType) {2304case VK_IMAGE_TYPE_1D:2305return (VkOffset3D){imageOffset.x, 0, 0};2306case VK_IMAGE_TYPE_2D:2307return (VkOffset3D){imageOffset.x, imageOffset.y, 0};2308case VK_IMAGE_TYPE_3D:2309return imageOffset;2310default:2311unreachable("invalid image type");2312}2313}23142315static inline bool2316radv_image_extent_compare(const struct radv_image *image, const VkExtent3D *extent)2317{2318if (extent->width != image->info.width || extent->height != image->info.height ||2319extent->depth != image->info.depth)2320return false;2321return true;2322}23232324struct radv_sampler {2325struct vk_object_base base;2326uint32_t state[4];2327struct radv_sampler_ycbcr_conversion *ycbcr_sampler;2328uint32_t border_color_slot;2329};23302331struct radv_framebuffer {2332struct vk_object_base base;2333uint32_t width;2334uint32_t height;2335uint32_t layers;23362337bool imageless;23382339uint32_t attachment_count;2340struct radv_image_view *attachments[0];2341};23422343struct radv_subpass_barrier {2344VkPipelineStageFlags src_stage_mask;2345VkAccessFlags src_access_mask;2346VkAccessFlags dst_access_mask;2347};23482349void radv_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,2350const struct radv_subpass_barrier *barrier);23512352struct radv_subpass_attachment {2353uint32_t attachment;2354VkImageLayout layout;2355VkImageLayout stencil_layout;2356bool in_render_loop;2357};23582359struct radv_subpass {2360uint32_t attachment_count;2361struct radv_subpass_attachment *attachments;23622363uint32_t input_count;2364uint32_t color_count;2365struct radv_subpass_attachment *input_attachments;2366struct radv_subpass_attachment *color_attachments;2367struct radv_subpass_attachment *resolve_attachments;2368struct radv_subpass_attachment *depth_stencil_attachment;2369struct radv_subpass_attachment *ds_resolve_attachment;2370struct radv_subpass_attachment *vrs_attachment;2371VkResolveModeFlagBits depth_resolve_mode;2372VkResolveModeFlagBits stencil_resolve_mode;23732374/** Subpass has at least one color resolve attachment */2375bool has_color_resolve;23762377/** Subpass has at least one color attachment */2378bool has_color_att;23792380struct radv_subpass_barrier start_barrier;23812382uint32_t view_mask;23832384VkSampleCountFlagBits color_sample_count;2385VkSampleCountFlagBits depth_sample_count;2386VkSampleCountFlagBits max_sample_count;23872388/* Whether the subpass has ingoing/outgoing external dependencies. */2389bool has_ingoing_dep;2390bool has_outgoing_dep;2391};23922393uint32_t radv_get_subpass_id(struct radv_cmd_buffer *cmd_buffer);23942395struct radv_render_pass_attachment {2396VkFormat format;2397uint32_t samples;2398VkAttachmentLoadOp load_op;2399VkAttachmentLoadOp stencil_load_op;2400VkImageLayout initial_layout;2401VkImageLayout final_layout;2402VkImageLayout stencil_initial_layout;2403VkImageLayout stencil_final_layout;24042405/* The subpass id in which the attachment will be used first/last. */2406uint32_t first_subpass_idx;2407uint32_t last_subpass_idx;2408};24092410struct radv_render_pass {2411struct vk_object_base base;2412uint32_t attachment_count;2413uint32_t subpass_count;2414struct radv_subpass_attachment *subpass_attachments;2415struct radv_render_pass_attachment *attachments;2416struct radv_subpass_barrier end_barrier;2417struct radv_subpass subpasses[0];2418};24192420VkResult radv_device_init_meta(struct radv_device *device);2421void radv_device_finish_meta(struct radv_device *device);24222423struct radv_query_pool {2424struct vk_object_base base;2425struct radeon_winsys_bo *bo;2426uint32_t stride;2427uint32_t availability_offset;2428uint64_t size;2429char *ptr;2430VkQueryType type;2431uint32_t pipeline_stats_mask;2432};24332434typedef enum {2435RADV_SEMAPHORE_NONE,2436RADV_SEMAPHORE_SYNCOBJ,2437RADV_SEMAPHORE_TIMELINE_SYNCOBJ,2438RADV_SEMAPHORE_TIMELINE,2439} radv_semaphore_kind;24402441struct radv_deferred_queue_submission;24422443struct radv_timeline_waiter {2444struct list_head list;2445struct radv_deferred_queue_submission *submission;2446uint64_t value;2447};24482449struct radv_timeline_point {2450struct list_head list;24512452uint64_t value;2453uint32_t syncobj;24542455/* Separate from the list to accomodate CPU wait being async, as well2456* as prevent point deletion during submission. */2457unsigned wait_count;2458};24592460struct radv_timeline {2461mtx_t mutex;24622463uint64_t highest_signaled;2464uint64_t highest_submitted;24652466struct list_head points;24672468/* Keep free points on hand so we do not have to recreate syncobjs all2469* the time. */2470struct list_head free_points;24712472/* Submissions that are deferred waiting for a specific value to be2473* submitted. */2474struct list_head waiters;2475};24762477struct radv_timeline_syncobj {2478/* Keep syncobj first, so common-code can just handle this as2479* non-timeline syncobj. */2480uint32_t syncobj;2481uint64_t max_point; /* max submitted point. */2482};24832484struct radv_semaphore_part {2485radv_semaphore_kind kind;2486union {2487uint32_t syncobj;2488struct radv_timeline timeline;2489struct radv_timeline_syncobj timeline_syncobj;2490};2491};24922493struct radv_semaphore {2494struct vk_object_base base;2495struct radv_semaphore_part permanent;2496struct radv_semaphore_part temporary;2497};24982499bool radv_queue_internal_submit(struct radv_queue *queue, struct radeon_cmdbuf *cs);25002501void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer, VkPipelineBindPoint bind_point,2502struct radv_descriptor_set *set, unsigned idx);25032504void radv_update_descriptor_sets(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,2505VkDescriptorSet overrideSet, uint32_t descriptorWriteCount,2506const VkWriteDescriptorSet *pDescriptorWrites,2507uint32_t descriptorCopyCount,2508const VkCopyDescriptorSet *pDescriptorCopies);25092510void radv_update_descriptor_set_with_template(struct radv_device *device,2511struct radv_cmd_buffer *cmd_buffer,2512struct radv_descriptor_set *set,2513VkDescriptorUpdateTemplate descriptorUpdateTemplate,2514const void *pData);25152516void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,2517VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout _layout,2518uint32_t set, uint32_t descriptorWriteCount,2519const VkWriteDescriptorSet *pDescriptorWrites);25202521uint32_t radv_init_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,2522const VkImageSubresourceRange *range, uint32_t value);25232524uint32_t radv_init_fmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,2525const VkImageSubresourceRange *range);25262527typedef enum {2528RADV_FENCE_NONE,2529RADV_FENCE_SYNCOBJ,2530} radv_fence_kind;25312532struct radv_fence_part {2533radv_fence_kind kind;25342535/* DRM syncobj handle for syncobj-based fences. */2536uint32_t syncobj;2537};25382539struct radv_fence {2540struct vk_object_base base;2541struct radv_fence_part permanent;2542struct radv_fence_part temporary;2543};25442545/* radv_nir_to_llvm.c */2546struct radv_shader_args;25472548void llvm_compile_shader(struct radv_device *device, unsigned shader_count,2549struct nir_shader *const *shaders, struct radv_shader_binary **binary,2550struct radv_shader_args *args);25512552unsigned radv_nir_get_max_workgroup_size(enum chip_class chip_class, gl_shader_stage stage,2553const struct nir_shader *nir);25542555/* radv_shader_info.h */2556struct radv_shader_info;2557struct radv_shader_variant_key;25582559void radv_nir_shader_info_pass(struct radv_device *device, const struct nir_shader *nir,2560const struct radv_pipeline_layout *layout,2561const struct radv_shader_variant_key *key,2562struct radv_shader_info *info);25632564void radv_nir_shader_info_init(struct radv_shader_info *info);25652566bool radv_thread_trace_init(struct radv_device *device);2567void radv_thread_trace_finish(struct radv_device *device);2568bool radv_begin_thread_trace(struct radv_queue *queue);2569bool radv_end_thread_trace(struct radv_queue *queue);2570bool radv_get_thread_trace(struct radv_queue *queue, struct ac_thread_trace *thread_trace);2571void radv_emit_thread_trace_userdata(const struct radv_device *device, struct radeon_cmdbuf *cs,2572const void *data, uint32_t num_dwords);2573/* radv_sqtt_layer_.c */2574struct radv_barrier_data {2575union {2576struct {2577uint16_t depth_stencil_expand : 1;2578uint16_t htile_hiz_range_expand : 1;2579uint16_t depth_stencil_resummarize : 1;2580uint16_t dcc_decompress : 1;2581uint16_t fmask_decompress : 1;2582uint16_t fast_clear_eliminate : 1;2583uint16_t fmask_color_expand : 1;2584uint16_t init_mask_ram : 1;2585uint16_t reserved : 8;2586};2587uint16_t all;2588} layout_transitions;2589};25902591/**2592* Value for the reason field of an RGP barrier start marker originating from2593* the Vulkan client (does not include PAL-defined values). (Table 15)2594*/2595enum rgp_barrier_reason {2596RGP_BARRIER_UNKNOWN_REASON = 0xFFFFFFFF,25972598/* External app-generated barrier reasons, i.e. API synchronization2599* commands Range of valid values: [0x00000001 ... 0x7FFFFFFF].2600*/2601RGP_BARRIER_EXTERNAL_CMD_PIPELINE_BARRIER = 0x00000001,2602RGP_BARRIER_EXTERNAL_RENDER_PASS_SYNC = 0x00000002,2603RGP_BARRIER_EXTERNAL_CMD_WAIT_EVENTS = 0x00000003,26042605/* Internal barrier reasons, i.e. implicit synchronization inserted by2606* the Vulkan driver Range of valid values: [0xC0000000 ... 0xFFFFFFFE].2607*/2608RGP_BARRIER_INTERNAL_BASE = 0xC0000000,2609RGP_BARRIER_INTERNAL_PRE_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 0,2610RGP_BARRIER_INTERNAL_POST_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 1,2611RGP_BARRIER_INTERNAL_GPU_EVENT_RECYCLE_STALL = RGP_BARRIER_INTERNAL_BASE + 2,2612RGP_BARRIER_INTERNAL_PRE_COPY_QUERY_POOL_RESULTS_SYNC = RGP_BARRIER_INTERNAL_BASE + 32613};26142615void radv_describe_begin_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);2616void radv_describe_end_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);2617void radv_describe_draw(struct radv_cmd_buffer *cmd_buffer);2618void radv_describe_dispatch(struct radv_cmd_buffer *cmd_buffer, int x, int y, int z);2619void radv_describe_begin_render_pass_clear(struct radv_cmd_buffer *cmd_buffer,2620VkImageAspectFlagBits aspects);2621void radv_describe_end_render_pass_clear(struct radv_cmd_buffer *cmd_buffer);2622void radv_describe_begin_render_pass_resolve(struct radv_cmd_buffer *cmd_buffer);2623void radv_describe_end_render_pass_resolve(struct radv_cmd_buffer *cmd_buffer);2624void radv_describe_barrier_start(struct radv_cmd_buffer *cmd_buffer,2625enum rgp_barrier_reason reason);2626void radv_describe_barrier_end(struct radv_cmd_buffer *cmd_buffer);2627void radv_describe_barrier_end_delayed(struct radv_cmd_buffer *cmd_buffer);2628void radv_describe_layout_transition(struct radv_cmd_buffer *cmd_buffer,2629const struct radv_barrier_data *barrier);26302631uint64_t radv_get_current_time(void);26322633static inline uint32_t2634si_conv_gl_prim_to_vertices(unsigned gl_prim)2635{2636switch (gl_prim) {2637case 0: /* GL_POINTS */2638return 1;2639case 1: /* GL_LINES */2640case 3: /* GL_LINE_STRIP */2641return 2;2642case 4: /* GL_TRIANGLES */2643case 5: /* GL_TRIANGLE_STRIP */2644return 3;2645case 0xA: /* GL_LINE_STRIP_ADJACENCY_ARB */2646return 4;2647case 0xc: /* GL_TRIANGLES_ADJACENCY_ARB */2648return 6;2649case 7: /* GL_QUADS */2650return V_028A6C_TRISTRIP;2651default:2652assert(0);2653return 0;2654}2655}26562657struct radv_extra_render_pass_begin_info {2658bool disable_dcc;2659};26602661void radv_cmd_buffer_begin_render_pass(struct radv_cmd_buffer *cmd_buffer,2662const VkRenderPassBeginInfo *pRenderPassBegin,2663const struct radv_extra_render_pass_begin_info *extra_info);2664void radv_cmd_buffer_end_render_pass(struct radv_cmd_buffer *cmd_buffer);26652666static inline uint32_t2667si_translate_prim(unsigned topology)2668{2669switch (topology) {2670case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:2671return V_008958_DI_PT_POINTLIST;2672case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:2673return V_008958_DI_PT_LINELIST;2674case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:2675return V_008958_DI_PT_LINESTRIP;2676case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:2677return V_008958_DI_PT_TRILIST;2678case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:2679return V_008958_DI_PT_TRISTRIP;2680case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:2681return V_008958_DI_PT_TRIFAN;2682case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:2683return V_008958_DI_PT_LINELIST_ADJ;2684case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:2685return V_008958_DI_PT_LINESTRIP_ADJ;2686case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:2687return V_008958_DI_PT_TRILIST_ADJ;2688case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:2689return V_008958_DI_PT_TRISTRIP_ADJ;2690case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:2691return V_008958_DI_PT_PATCH;2692default:2693assert(0);2694return 0;2695}2696}26972698static inline uint32_t2699si_translate_stencil_op(enum VkStencilOp op)2700{2701switch (op) {2702case VK_STENCIL_OP_KEEP:2703return V_02842C_STENCIL_KEEP;2704case VK_STENCIL_OP_ZERO:2705return V_02842C_STENCIL_ZERO;2706case VK_STENCIL_OP_REPLACE:2707return V_02842C_STENCIL_REPLACE_TEST;2708case VK_STENCIL_OP_INCREMENT_AND_CLAMP:2709return V_02842C_STENCIL_ADD_CLAMP;2710case VK_STENCIL_OP_DECREMENT_AND_CLAMP:2711return V_02842C_STENCIL_SUB_CLAMP;2712case VK_STENCIL_OP_INVERT:2713return V_02842C_STENCIL_INVERT;2714case VK_STENCIL_OP_INCREMENT_AND_WRAP:2715return V_02842C_STENCIL_ADD_WRAP;2716case VK_STENCIL_OP_DECREMENT_AND_WRAP:2717return V_02842C_STENCIL_SUB_WRAP;2718default:2719return 0;2720}2721}27222723static inline uint32_t2724si_translate_blend_logic_op(VkLogicOp op)2725{2726switch (op) {2727case VK_LOGIC_OP_CLEAR:2728return V_028808_ROP3_CLEAR;2729case VK_LOGIC_OP_AND:2730return V_028808_ROP3_AND;2731case VK_LOGIC_OP_AND_REVERSE:2732return V_028808_ROP3_AND_REVERSE;2733case VK_LOGIC_OP_COPY:2734return V_028808_ROP3_COPY;2735case VK_LOGIC_OP_AND_INVERTED:2736return V_028808_ROP3_AND_INVERTED;2737case VK_LOGIC_OP_NO_OP:2738return V_028808_ROP3_NO_OP;2739case VK_LOGIC_OP_XOR:2740return V_028808_ROP3_XOR;2741case VK_LOGIC_OP_OR:2742return V_028808_ROP3_OR;2743case VK_LOGIC_OP_NOR:2744return V_028808_ROP3_NOR;2745case VK_LOGIC_OP_EQUIVALENT:2746return V_028808_ROP3_EQUIVALENT;2747case VK_LOGIC_OP_INVERT:2748return V_028808_ROP3_INVERT;2749case VK_LOGIC_OP_OR_REVERSE:2750return V_028808_ROP3_OR_REVERSE;2751case VK_LOGIC_OP_COPY_INVERTED:2752return V_028808_ROP3_COPY_INVERTED;2753case VK_LOGIC_OP_OR_INVERTED:2754return V_028808_ROP3_OR_INVERTED;2755case VK_LOGIC_OP_NAND:2756return V_028808_ROP3_NAND;2757case VK_LOGIC_OP_SET:2758return V_028808_ROP3_SET;2759default:2760unreachable("Unhandled logic op");2761}2762}27632764/**2765* Helper used for debugging compiler issues by enabling/disabling LLVM for a2766* specific shader stage (developers only).2767*/2768static inline bool2769radv_use_llvm_for_stage(struct radv_device *device, UNUSED gl_shader_stage stage)2770{2771return device->physical_device->use_llvm;2772}27732774struct radv_acceleration_structure {2775struct vk_object_base base;27762777struct radeon_winsys_bo *bo;2778uint64_t mem_offset;2779uint64_t size;2780};27812782static inline uint64_t2783radv_accel_struct_get_va(const struct radv_acceleration_structure *accel)2784{2785return radv_buffer_get_va(accel->bo) + accel->mem_offset;2786}27872788#define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \2789\2790static inline struct __radv_type *__radv_type##_from_handle(__VkType _handle) \2791{ \2792return (struct __radv_type *)_handle; \2793} \2794\2795static inline __VkType __radv_type##_to_handle(struct __radv_type *_obj) \2796{ \2797return (__VkType)_obj; \2798}27992800#define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \2801\2802static inline struct __radv_type *__radv_type##_from_handle(__VkType _handle) \2803{ \2804return (struct __radv_type *)(uintptr_t)_handle; \2805} \2806\2807static inline __VkType __radv_type##_to_handle(struct __radv_type *_obj) \2808{ \2809return (__VkType)(uintptr_t)_obj; \2810}28112812#define RADV_FROM_HANDLE(__radv_type, __name, __handle) \2813struct __radv_type *__name = __radv_type##_from_handle(__handle)28142815RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)2816RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)2817RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)2818RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)2819RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)28202821RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_acceleration_structure, VkAccelerationStructureKHR)2822RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)2823RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)2824RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)2825RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)2826RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)2827RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)2828RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplate)2829RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)2830RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)2831RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)2832RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)2833RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)2834RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);2835RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)2836RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)2837RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)2838RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)2839RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)2840RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)2841RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)2842RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)28432844#endif /* RADV_PRIVATE_H */284528462847