Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_screen.h
4570 views
/*1* Copyright 2018 Collabora Ltd.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef ZINK_SCREEN_H24#define ZINK_SCREEN_H2526#include "zink_device_info.h"27#include "zink_instance.h"28#include "vk_dispatch_table.h"2930#include "util/u_idalloc.h"31#include "pipe/p_screen.h"32#include "util/slab.h"33#include "compiler/nir/nir.h"34#include "util/disk_cache.h"35#include "util/log.h"36#include "util/simple_mtx.h"37#include "util/u_queue.h"38#include "util/u_live_shader_cache.h"3940#include <vulkan/vulkan.h>4142extern uint32_t zink_debug;43struct hash_table;4445struct zink_batch_state;46struct zink_context;47struct zink_descriptor_layout_key;48struct zink_program;49struct zink_shader;50enum zink_descriptor_type;5152#define ZINK_DEBUG_NIR 0x153#define ZINK_DEBUG_SPIRV 0x254#define ZINK_DEBUG_TGSI 0x455#define ZINK_DEBUG_VALIDATION 0x85657enum zink_descriptor_mode {58ZINK_DESCRIPTOR_MODE_AUTO,59ZINK_DESCRIPTOR_MODE_LAZY,60ZINK_DESCRIPTOR_MODE_NOTEMPLATES,61};6263struct zink_modifier_prop {64uint32_t drmFormatModifierCount;65VkDrmFormatModifierPropertiesEXT* pDrmFormatModifierProperties;66};6768struct zink_screen {69struct pipe_screen base;70bool threaded;71uint32_t curr_batch; //the current batch id72uint32_t last_finished; //this is racy but ultimately doesn't matter73VkSemaphore sem;74VkSemaphore prev_sem;75struct util_queue flush_queue;7677bool device_lost;78struct sw_winsys *winsys;7980struct hash_table framebuffer_cache;81simple_mtx_t framebuffer_mtx;82struct hash_table surface_cache;83simple_mtx_t surface_mtx;84struct hash_table bufferview_cache;85simple_mtx_t bufferview_mtx;8687struct slab_parent_pool transfer_pool;88struct disk_cache *disk_cache;89struct util_queue cache_put_thread;90struct util_queue cache_get_thread;9192struct util_live_shader_cache shaders;9394simple_mtx_t mem_cache_mtx;95struct hash_table *resource_mem_cache;96uint64_t mem_cache_size;97unsigned mem_cache_count;9899uint64_t total_video_mem;100uint64_t total_mem;101102VkInstance instance;103struct zink_instance_info instance_info;104105VkPhysicalDevice pdev;106uint32_t vk_version, spirv_version;107struct util_idalloc_mt buffer_ids;108109struct zink_device_info info;110struct nir_shader_compiler_options nir_options;111112bool have_X8_D24_UNORM_PACK32;113bool have_D24_UNORM_S8_UINT;114bool have_triangle_fans;115116uint32_t gfx_queue;117uint32_t max_queues;118uint32_t timestamp_valid_bits;119VkDevice dev;120VkQueue queue; //gfx+compute121VkQueue thread_queue; //gfx+compute122VkDebugUtilsMessengerEXT debugUtilsCallbackHandle;123124uint32_t cur_custom_border_color_samplers;125126bool needs_mesa_wsi;127bool needs_mesa_flush_wsi;128129struct vk_dispatch_table vk;130131bool (*descriptor_program_init)(struct zink_context *ctx, struct zink_program *pg);132void (*descriptor_program_deinit)(struct zink_screen *screen, struct zink_program *pg);133void (*descriptors_update)(struct zink_context *ctx, bool is_compute);134void (*context_update_descriptor_states)(struct zink_context *ctx, bool is_compute);135void (*context_invalidate_descriptor_state)(struct zink_context *ctx, enum pipe_shader_type shader,136enum zink_descriptor_type type,137unsigned start, unsigned count);138bool (*batch_descriptor_init)(struct zink_screen *screen, struct zink_batch_state *bs);139void (*batch_descriptor_reset)(struct zink_screen *screen, struct zink_batch_state *bs);140void (*batch_descriptor_deinit)(struct zink_screen *screen, struct zink_batch_state *bs);141bool (*descriptors_init)(struct zink_context *ctx);142void (*descriptors_deinit)(struct zink_context *ctx);143enum zink_descriptor_mode descriptor_mode;144145struct {146bool dual_color_blend_by_location;147bool inline_uniforms;148} driconf;149150VkFormatProperties format_props[PIPE_FORMAT_COUNT];151struct zink_modifier_prop modifier_props[PIPE_FORMAT_COUNT];152struct {153uint32_t image_view;154uint32_t buffer_view;155} null_descriptor_hashes;156157VkExtent2D maxSampleLocationGridSize[5];158};159160161/* update last_finished to account for batch_id wrapping */162static inline void163zink_screen_update_last_finished(struct zink_screen *screen, uint32_t batch_id)164{165/* last_finished may have wrapped */166if (screen->last_finished < UINT_MAX / 2) {167/* last_finished has wrapped, batch_id has not */168if (batch_id > UINT_MAX / 2)169return;170} else if (batch_id < UINT_MAX / 2) {171/* batch_id has wrapped, last_finished has not */172screen->last_finished = batch_id;173return;174}175/* neither have wrapped */176screen->last_finished = MAX2(batch_id, screen->last_finished);177}178179/* check a batch_id against last_finished while accounting for wrapping */180static inline bool181zink_screen_check_last_finished(struct zink_screen *screen, uint32_t batch_id)182{183/* last_finished may have wrapped */184if (screen->last_finished < UINT_MAX / 2) {185/* last_finished has wrapped, batch_id has not */186if (batch_id > UINT_MAX / 2)187return true;188} else if (batch_id < UINT_MAX / 2) {189/* batch_id has wrapped, last_finished has not */190return false;191}192return screen->last_finished >= batch_id;193}194195bool196zink_screen_init_semaphore(struct zink_screen *screen);197198static inline bool199zink_screen_handle_vkresult(struct zink_screen *screen, VkResult ret)200{201bool success = false;202switch (ret) {203case VK_SUCCESS:204success = true;205break;206case VK_ERROR_DEVICE_LOST:207screen->device_lost = true;208FALLTHROUGH;209default:210success = false;211break;212}213return success;214}215216static inline struct zink_screen *217zink_screen(struct pipe_screen *pipe)218{219return (struct zink_screen *)pipe;220}221222223struct mem_cache_entry {224VkDeviceMemory mem;225void *map;226};227228VkFormat229zink_get_format(struct zink_screen *screen, enum pipe_format format);230231bool232zink_screen_batch_id_wait(struct zink_screen *screen, uint32_t batch_id, uint64_t timeout);233234bool235zink_screen_timeline_wait(struct zink_screen *screen, uint32_t batch_id, uint64_t timeout);236237bool238zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format);239240#define GET_PROC_ADDR_INSTANCE_LOCAL(instance, x) PFN_vk##x vk_##x = (PFN_vk##x)vkGetInstanceProcAddr(instance, "vk"#x)241242void243zink_screen_update_pipeline_cache(struct zink_screen *screen, struct zink_program *pg);244245void246zink_screen_get_pipeline_cache(struct zink_screen *screen, struct zink_program *pg);247248void249zink_screen_init_descriptor_funcs(struct zink_screen *screen, bool fallback);250251void252zink_stub_function_not_loaded(void);253#endif254255256