17ec681f3Smrg/*
27ec681f3Smrg * Copyright © 2019 Red Hat.
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg * IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#pragma once
257ec681f3Smrg#include <stdlib.h>
267ec681f3Smrg#include <stdio.h>
277ec681f3Smrg#include <stdbool.h>
287ec681f3Smrg#include <string.h>
297ec681f3Smrg#include <assert.h>
307ec681f3Smrg#include <stdint.h>
317ec681f3Smrg
327ec681f3Smrg#include "util/macros.h"
337ec681f3Smrg#include "util/list.h"
347ec681f3Smrg#include "util/u_dynarray.h"
357ec681f3Smrg#include "util/simple_mtx.h"
367ec681f3Smrg#include "util/u_queue.h"
377ec681f3Smrg
387ec681f3Smrg#include "compiler/shader_enums.h"
397ec681f3Smrg#include "pipe/p_screen.h"
407ec681f3Smrg#include "pipe/p_state.h"
417ec681f3Smrg#include "cso_cache/cso_context.h"
427ec681f3Smrg#include "nir.h"
437ec681f3Smrg
447ec681f3Smrg/* Pre-declarations needed for WSI entrypoints */
457ec681f3Smrgstruct wl_surface;
467ec681f3Smrgstruct wl_display;
477ec681f3Smrgtypedef struct xcb_connection_t xcb_connection_t;
487ec681f3Smrgtypedef uint32_t xcb_visualid_t;
497ec681f3Smrgtypedef uint32_t xcb_window_t;
507ec681f3Smrg
517ec681f3Smrg#define VK_PROTOTYPES
527ec681f3Smrg#include <vulkan/vulkan.h>
537ec681f3Smrg#include <vulkan/vk_icd.h>
547ec681f3Smrg
557ec681f3Smrg#include "lvp_entrypoints.h"
567ec681f3Smrg#include "vk_device.h"
577ec681f3Smrg#include "vk_instance.h"
587ec681f3Smrg#include "vk_image.h"
597ec681f3Smrg#include "vk_log.h"
607ec681f3Smrg#include "vk_physical_device.h"
617ec681f3Smrg#include "vk_shader_module.h"
627ec681f3Smrg#include "vk_util.h"
637ec681f3Smrg#include "vk_format.h"
647ec681f3Smrg#include "vk_cmd_queue.h"
657ec681f3Smrg#include "vk_command_buffer.h"
667ec681f3Smrg#include "vk_queue.h"
677ec681f3Smrg
687ec681f3Smrg#include "wsi_common.h"
697ec681f3Smrg
707ec681f3Smrg#include <assert.h>
717ec681f3Smrg#ifdef __cplusplus
727ec681f3Smrgextern "C" {
737ec681f3Smrg#endif
747ec681f3Smrg
757ec681f3Smrg#define MAX_SETS         8
767ec681f3Smrg#define MAX_PUSH_CONSTANTS_SIZE 128
777ec681f3Smrg#define MAX_PUSH_DESCRIPTORS 32
787ec681f3Smrg
797ec681f3Smrg#ifdef _WIN32
807ec681f3Smrg#define lvp_printflike(a, b)
817ec681f3Smrg#else
827ec681f3Smrg#define lvp_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
837ec681f3Smrg#endif
847ec681f3Smrg
857ec681f3Smrgint lvp_get_instance_entrypoint_index(const char *name);
867ec681f3Smrgint lvp_get_device_entrypoint_index(const char *name);
877ec681f3Smrgint lvp_get_physical_device_entrypoint_index(const char *name);
887ec681f3Smrg
897ec681f3Smrgconst char *lvp_get_instance_entry_name(int index);
907ec681f3Smrgconst char *lvp_get_physical_device_entry_name(int index);
917ec681f3Smrgconst char *lvp_get_device_entry_name(int index);
927ec681f3Smrg
937ec681f3Smrgbool lvp_instance_entrypoint_is_enabled(int index, uint32_t core_version,
947ec681f3Smrg                                         const struct vk_instance_extension_table *instance);
957ec681f3Smrgbool lvp_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
967ec681f3Smrg                                                const struct vk_instance_extension_table *instance);
977ec681f3Smrgbool lvp_device_entrypoint_is_enabled(int index, uint32_t core_version,
987ec681f3Smrg                                       const struct vk_instance_extension_table *instance,
997ec681f3Smrg                                       const struct vk_device_extension_table *device);
1007ec681f3Smrg
1017ec681f3Smrg#define LVP_DEBUG_ALL_ENTRYPOINTS (1 << 0)
1027ec681f3Smrg
1037ec681f3Smrgvoid __lvp_finishme(const char *file, int line, const char *format, ...)
1047ec681f3Smrg   lvp_printflike(3, 4);
1057ec681f3Smrg
1067ec681f3Smrg#define lvp_finishme(format, ...) \
1077ec681f3Smrg   __lvp_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
1087ec681f3Smrg
1097ec681f3Smrg#define stub_return(v) \
1107ec681f3Smrg   do { \
1117ec681f3Smrg      lvp_finishme("stub %s", __func__); \
1127ec681f3Smrg      return (v); \
1137ec681f3Smrg   } while (0)
1147ec681f3Smrg
1157ec681f3Smrg#define stub() \
1167ec681f3Smrg   do { \
1177ec681f3Smrg      lvp_finishme("stub %s", __func__); \
1187ec681f3Smrg      return; \
1197ec681f3Smrg   } while (0)
1207ec681f3Smrg
1217ec681f3Smrg#define LVP_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1227ec681f3Smrg
1237ec681f3Smrg#define lvp_foreach_stage(stage, stage_bits)                         \
1247ec681f3Smrg   for (gl_shader_stage stage,                                       \
1257ec681f3Smrg        __tmp = (gl_shader_stage)((stage_bits) & LVP_STAGE_MASK);    \
1267ec681f3Smrg        stage = ffs(__tmp) - 1, __tmp;                     \
1277ec681f3Smrg        __tmp &= ~(1 << (stage)))
1287ec681f3Smrg
1297ec681f3Smrgstruct lvp_physical_device {
1307ec681f3Smrg   struct vk_physical_device vk;
1317ec681f3Smrg
1327ec681f3Smrg   struct pipe_loader_device *pld;
1337ec681f3Smrg   struct pipe_screen *pscreen;
1347ec681f3Smrg   uint32_t max_images;
1357ec681f3Smrg
1367ec681f3Smrg   struct wsi_device                       wsi_device;
1377ec681f3Smrg};
1387ec681f3Smrg
1397ec681f3Smrgstruct lvp_instance {
1407ec681f3Smrg   struct vk_instance vk;
1417ec681f3Smrg
1427ec681f3Smrg   uint32_t apiVersion;
1437ec681f3Smrg   int physicalDeviceCount;
1447ec681f3Smrg   struct lvp_physical_device physicalDevice;
1457ec681f3Smrg
1467ec681f3Smrg   uint64_t debug_flags;
1477ec681f3Smrg
1487ec681f3Smrg   struct pipe_loader_device *devs;
1497ec681f3Smrg   int num_devices;
1507ec681f3Smrg};
1517ec681f3Smrg
1527ec681f3SmrgVkResult lvp_init_wsi(struct lvp_physical_device *physical_device);
1537ec681f3Smrgvoid lvp_finish_wsi(struct lvp_physical_device *physical_device);
1547ec681f3Smrg
1557ec681f3Smrgbool lvp_physical_device_extension_supported(struct lvp_physical_device *dev,
1567ec681f3Smrg                                              const char *name);
1577ec681f3Smrg
1587ec681f3Smrgstruct lvp_queue {
1597ec681f3Smrg   struct vk_queue vk;
1607ec681f3Smrg   struct lvp_device *                         device;
1617ec681f3Smrg   struct pipe_context *ctx;
1627ec681f3Smrg   struct cso_context *cso;
1637ec681f3Smrg   bool shutdown;
1647ec681f3Smrg   uint64_t timeline;
1657ec681f3Smrg   struct util_queue queue;
1667ec681f3Smrg   simple_mtx_t last_lock;
1677ec681f3Smrg   uint64_t last_finished;
1687ec681f3Smrg   uint64_t last_fence_timeline;
1697ec681f3Smrg   struct pipe_fence_handle *last_fence;
1707ec681f3Smrg   volatile int count;
1717ec681f3Smrg};
1727ec681f3Smrg
1737ec681f3Smrgstruct lvp_semaphore_wait {
1747ec681f3Smrg   struct lvp_semaphore *sema;
1757ec681f3Smrg   uint64_t wait;
1767ec681f3Smrg};
1777ec681f3Smrg
1787ec681f3Smrgstruct lvp_queue_work {
1797ec681f3Smrg   struct list_head list;
1807ec681f3Smrg   uint32_t cmd_buffer_count;
1817ec681f3Smrg   uint32_t timeline_count;
1827ec681f3Smrg   uint32_t wait_count;
1837ec681f3Smrg   uint64_t timeline;
1847ec681f3Smrg   struct lvp_fence *fence;
1857ec681f3Smrg   struct lvp_cmd_buffer **cmd_buffers;
1867ec681f3Smrg   struct lvp_semaphore_timeline **timelines;
1877ec681f3Smrg   VkSemaphore *waits;
1887ec681f3Smrg   uint64_t *wait_vals;
1897ec681f3Smrg};
1907ec681f3Smrg
1917ec681f3Smrgstruct lvp_pipeline_cache {
1927ec681f3Smrg   struct vk_object_base                        base;
1937ec681f3Smrg   struct lvp_device *                          device;
1947ec681f3Smrg   VkAllocationCallbacks                        alloc;
1957ec681f3Smrg};
1967ec681f3Smrg
1977ec681f3Smrgstruct lvp_device {
1987ec681f3Smrg   struct vk_device vk;
1997ec681f3Smrg
2007ec681f3Smrg   struct lvp_queue queue;
2017ec681f3Smrg   struct lvp_instance *                       instance;
2027ec681f3Smrg   struct lvp_physical_device *physical_device;
2037ec681f3Smrg   struct pipe_screen *pscreen;
2047ec681f3Smrg};
2057ec681f3Smrg
2067ec681f3Smrgvoid lvp_device_get_cache_uuid(void *uuid);
2077ec681f3Smrg
2087ec681f3Smrgenum lvp_device_memory_type {
2097ec681f3Smrg   LVP_DEVICE_MEMORY_TYPE_DEFAULT,
2107ec681f3Smrg   LVP_DEVICE_MEMORY_TYPE_USER_PTR,
2117ec681f3Smrg   LVP_DEVICE_MEMORY_TYPE_OPAQUE_FD,
2127ec681f3Smrg};
2137ec681f3Smrg
2147ec681f3Smrgstruct lvp_device_memory {
2157ec681f3Smrg   struct vk_object_base base;
2167ec681f3Smrg   struct pipe_memory_allocation *pmem;
2177ec681f3Smrg   uint32_t                                     type_index;
2187ec681f3Smrg   VkDeviceSize                                 map_size;
2197ec681f3Smrg   void *                                       map;
2207ec681f3Smrg   enum lvp_device_memory_type memory_type;
2217ec681f3Smrg   int                                          backed_fd;
2227ec681f3Smrg};
2237ec681f3Smrg
2247ec681f3Smrgstruct lvp_image {
2257ec681f3Smrg   struct vk_image vk;
2267ec681f3Smrg   VkDeviceSize size;
2277ec681f3Smrg   uint32_t alignment;
2287ec681f3Smrg   struct pipe_memory_allocation *pmem;
2297ec681f3Smrg   unsigned memory_offset;
2307ec681f3Smrg   struct pipe_resource *bo;
2317ec681f3Smrg};
2327ec681f3Smrg
2337ec681f3Smrgstatic inline uint32_t
2347ec681f3Smrglvp_get_layerCount(const struct lvp_image *image,
2357ec681f3Smrg                   const VkImageSubresourceRange *range)
2367ec681f3Smrg{
2377ec681f3Smrg   return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
2387ec681f3Smrg      image->bo->array_size - range->baseArrayLayer : range->layerCount;
2397ec681f3Smrg}
2407ec681f3Smrg
2417ec681f3Smrgstatic inline uint32_t
2427ec681f3Smrglvp_get_levelCount(const struct lvp_image *image,
2437ec681f3Smrg                   const VkImageSubresourceRange *range)
2447ec681f3Smrg{
2457ec681f3Smrg   return range->levelCount == VK_REMAINING_MIP_LEVELS ?
2467ec681f3Smrg      (image->bo->last_level + 1) - range->baseMipLevel : range->levelCount;
2477ec681f3Smrg}
2487ec681f3Smrg
2497ec681f3Smrgstruct lvp_image_view {
2507ec681f3Smrg   struct vk_object_base base;
2517ec681f3Smrg   const struct lvp_image *image; /**< VkImageViewCreateInfo::image */
2527ec681f3Smrg
2537ec681f3Smrg   VkImageViewType view_type;
2547ec681f3Smrg   VkFormat format;
2557ec681f3Smrg   enum pipe_format pformat;
2567ec681f3Smrg   VkComponentMapping components;
2577ec681f3Smrg   VkImageSubresourceRange subresourceRange;
2587ec681f3Smrg
2597ec681f3Smrg   struct pipe_surface *surface; /* have we created a pipe surface for this? */
2607ec681f3Smrg};
2617ec681f3Smrg
2627ec681f3Smrgstruct lvp_subpass_attachment {
2637ec681f3Smrg   uint32_t         attachment;
2647ec681f3Smrg   VkImageLayout    layout;
2657ec681f3Smrg   bool             in_render_loop;
2667ec681f3Smrg};
2677ec681f3Smrg
2687ec681f3Smrgstruct lvp_subpass {
2697ec681f3Smrg   uint32_t                                     attachment_count;
2707ec681f3Smrg   struct lvp_subpass_attachment *             attachments;
2717ec681f3Smrg
2727ec681f3Smrg   uint32_t                                     input_count;
2737ec681f3Smrg   uint32_t                                     color_count;
2747ec681f3Smrg   struct lvp_subpass_attachment *              input_attachments;
2757ec681f3Smrg   struct lvp_subpass_attachment *              color_attachments;
2767ec681f3Smrg   struct lvp_subpass_attachment *              resolve_attachments;
2777ec681f3Smrg   struct lvp_subpass_attachment *              depth_stencil_attachment;
2787ec681f3Smrg   struct lvp_subpass_attachment *              ds_resolve_attachment;
2797ec681f3Smrg   VkResolveModeFlagBits                        depth_resolve_mode;
2807ec681f3Smrg   VkResolveModeFlagBits                        stencil_resolve_mode;
2817ec681f3Smrg
2827ec681f3Smrg   /** Subpass has at least one color resolve attachment */
2837ec681f3Smrg   bool                                         has_color_resolve;
2847ec681f3Smrg
2857ec681f3Smrg   /** Subpass has at least one color attachment */
2867ec681f3Smrg   bool                                         has_color_att;
2877ec681f3Smrg
2887ec681f3Smrg   VkSampleCountFlagBits                        max_sample_count;
2897ec681f3Smrg
2907ec681f3Smrg   uint32_t                                     view_mask;
2917ec681f3Smrg};
2927ec681f3Smrg
2937ec681f3Smrgstruct lvp_render_pass_attachment {
2947ec681f3Smrg   VkFormat                                     format;
2957ec681f3Smrg   uint32_t                                     samples;
2967ec681f3Smrg   VkAttachmentLoadOp                           load_op;
2977ec681f3Smrg   VkAttachmentLoadOp                           stencil_load_op;
2987ec681f3Smrg   VkImageLayout                                initial_layout;
2997ec681f3Smrg   VkImageLayout                                final_layout;
3007ec681f3Smrg
3017ec681f3Smrg   /* The subpass id in which the attachment will be used first/last. */
3027ec681f3Smrg   uint32_t                                     first_subpass_idx;
3037ec681f3Smrg   uint32_t                                     last_subpass_idx;
3047ec681f3Smrg};
3057ec681f3Smrg
3067ec681f3Smrgstruct lvp_render_pass {
3077ec681f3Smrg   struct vk_object_base                        base;
3087ec681f3Smrg   uint32_t                                     attachment_count;
3097ec681f3Smrg   uint32_t                                     subpass_count;
3107ec681f3Smrg   struct lvp_subpass_attachment *              subpass_attachments;
3117ec681f3Smrg   struct lvp_render_pass_attachment *          attachments;
3127ec681f3Smrg   bool has_color_attachment;
3137ec681f3Smrg   bool has_zs_attachment;
3147ec681f3Smrg   struct lvp_subpass                           subpasses[0];
3157ec681f3Smrg};
3167ec681f3Smrg
3177ec681f3Smrgstruct lvp_sampler {
3187ec681f3Smrg   struct vk_object_base base;
3197ec681f3Smrg   VkSamplerCreateInfo create_info;
3207ec681f3Smrg   union pipe_color_union border_color;
3217ec681f3Smrg   VkSamplerReductionMode reduction_mode;
3227ec681f3Smrg   uint32_t state[4];
3237ec681f3Smrg};
3247ec681f3Smrg
3257ec681f3Smrgstruct lvp_framebuffer {
3267ec681f3Smrg   struct vk_object_base                        base;
3277ec681f3Smrg   uint32_t                                     width;
3287ec681f3Smrg   uint32_t                                     height;
3297ec681f3Smrg   uint32_t                                     layers;
3307ec681f3Smrg
3317ec681f3Smrg   bool                                         imageless;
3327ec681f3Smrg   uint32_t                                     attachment_count;
3337ec681f3Smrg   struct lvp_image_view *                      attachments[0];
3347ec681f3Smrg};
3357ec681f3Smrg
3367ec681f3Smrgstruct lvp_descriptor_set_binding_layout {
3377ec681f3Smrg   uint16_t descriptor_index;
3387ec681f3Smrg   /* Number of array elements in this binding */
3397ec681f3Smrg   VkDescriptorType type;
3407ec681f3Smrg   uint16_t array_size;
3417ec681f3Smrg   bool valid;
3427ec681f3Smrg
3437ec681f3Smrg   int16_t dynamic_index;
3447ec681f3Smrg   struct {
3457ec681f3Smrg      int16_t const_buffer_index;
3467ec681f3Smrg      int16_t shader_buffer_index;
3477ec681f3Smrg      int16_t sampler_index;
3487ec681f3Smrg      int16_t sampler_view_index;
3497ec681f3Smrg      int16_t image_index;
3507ec681f3Smrg   } stage[MESA_SHADER_STAGES];
3517ec681f3Smrg
3527ec681f3Smrg   /* Immutable samplers (or NULL if no immutable samplers) */
3537ec681f3Smrg   struct lvp_sampler **immutable_samplers;
3547ec681f3Smrg};
3557ec681f3Smrg
3567ec681f3Smrgstruct lvp_descriptor_set_layout {
3577ec681f3Smrg   struct vk_object_base base;
3587ec681f3Smrg
3597ec681f3Smrg   const VkAllocationCallbacks *alloc;
3607ec681f3Smrg   /* Descriptor set layouts can be destroyed at almost any time */
3617ec681f3Smrg   uint32_t ref_cnt;
3627ec681f3Smrg
3637ec681f3Smrg   /* Number of bindings in this descriptor set */
3647ec681f3Smrg   uint16_t binding_count;
3657ec681f3Smrg
3667ec681f3Smrg   /* Total size of the descriptor set with room for all array entries */
3677ec681f3Smrg   uint16_t size;
3687ec681f3Smrg
3697ec681f3Smrg   /* Shader stages affected by this descriptor set */
3707ec681f3Smrg   uint16_t shader_stages;
3717ec681f3Smrg
3727ec681f3Smrg   struct {
3737ec681f3Smrg      uint16_t const_buffer_count;
3747ec681f3Smrg      uint16_t shader_buffer_count;
3757ec681f3Smrg      uint16_t sampler_count;
3767ec681f3Smrg      uint16_t sampler_view_count;
3777ec681f3Smrg      uint16_t image_count;
3787ec681f3Smrg   } stage[MESA_SHADER_STAGES];
3797ec681f3Smrg
3807ec681f3Smrg   /* Number of dynamic offsets used by this descriptor set */
3817ec681f3Smrg   uint16_t dynamic_offset_count;
3827ec681f3Smrg
3837ec681f3Smrg   /* Bindings in this descriptor set */
3847ec681f3Smrg   struct lvp_descriptor_set_binding_layout binding[0];
3857ec681f3Smrg};
3867ec681f3Smrg
3877ec681f3Smrgvoid lvp_descriptor_set_layout_destroy(struct lvp_device *device,
3887ec681f3Smrg                                       struct lvp_descriptor_set_layout *layout);
3897ec681f3Smrg
3907ec681f3Smrgstatic inline void
3917ec681f3Smrglvp_descriptor_set_layout_ref(struct lvp_descriptor_set_layout *layout)
3927ec681f3Smrg{
3937ec681f3Smrg   assert(layout && layout->ref_cnt >= 1);
3947ec681f3Smrg   p_atomic_inc(&layout->ref_cnt);
3957ec681f3Smrg}
3967ec681f3Smrg
3977ec681f3Smrgstatic inline void
3987ec681f3Smrglvp_descriptor_set_layout_unref(struct lvp_device *device,
3997ec681f3Smrg                                struct lvp_descriptor_set_layout *layout)
4007ec681f3Smrg{
4017ec681f3Smrg   assert(layout && layout->ref_cnt >= 1);
4027ec681f3Smrg   if (p_atomic_dec_zero(&layout->ref_cnt))
4037ec681f3Smrg      lvp_descriptor_set_layout_destroy(device, layout);
4047ec681f3Smrg}
4057ec681f3Smrg
4067ec681f3Smrgunion lvp_descriptor_info {
4077ec681f3Smrg   struct {
4087ec681f3Smrg      struct lvp_sampler *sampler;
4097ec681f3Smrg      struct lvp_image_view *iview;
4107ec681f3Smrg      VkImageLayout image_layout;
4117ec681f3Smrg   };
4127ec681f3Smrg   struct {
4137ec681f3Smrg      struct lvp_buffer *buffer;
4147ec681f3Smrg      VkDeviceSize offset;
4157ec681f3Smrg      VkDeviceSize range;
4167ec681f3Smrg   };
4177ec681f3Smrg   struct lvp_buffer_view *buffer_view;
4187ec681f3Smrg};
4197ec681f3Smrg
4207ec681f3Smrgstruct lvp_descriptor {
4217ec681f3Smrg   VkDescriptorType type;
4227ec681f3Smrg
4237ec681f3Smrg   union lvp_descriptor_info info;
4247ec681f3Smrg};
4257ec681f3Smrg
4267ec681f3Smrgstruct lvp_descriptor_set {
4277ec681f3Smrg   struct vk_object_base base;
4287ec681f3Smrg   struct lvp_descriptor_set_layout *layout;
4297ec681f3Smrg   struct list_head link;
4307ec681f3Smrg   struct lvp_descriptor descriptors[0];
4317ec681f3Smrg};
4327ec681f3Smrg
4337ec681f3Smrgstruct lvp_descriptor_pool {
4347ec681f3Smrg   struct vk_object_base base;
4357ec681f3Smrg   VkDescriptorPoolCreateFlags flags;
4367ec681f3Smrg   uint32_t max_sets;
4377ec681f3Smrg
4387ec681f3Smrg   struct list_head sets;
4397ec681f3Smrg};
4407ec681f3Smrg
4417ec681f3Smrgstruct lvp_descriptor_update_template {
4427ec681f3Smrg   struct vk_object_base base;
4437ec681f3Smrg   uint32_t entry_count;
4447ec681f3Smrg   uint32_t set;
4457ec681f3Smrg   VkDescriptorUpdateTemplateType type;
4467ec681f3Smrg   VkPipelineBindPoint bind_point;
4477ec681f3Smrg   struct lvp_pipeline_layout *pipeline_layout;
4487ec681f3Smrg   VkDescriptorUpdateTemplateEntry entry[0];
4497ec681f3Smrg};
4507ec681f3Smrg
4517ec681f3SmrgVkResult
4527ec681f3Smrglvp_descriptor_set_create(struct lvp_device *device,
4537ec681f3Smrg                          struct lvp_descriptor_set_layout *layout,
4547ec681f3Smrg                          struct lvp_descriptor_set **out_set);
4557ec681f3Smrg
4567ec681f3Smrgvoid
4577ec681f3Smrglvp_descriptor_set_destroy(struct lvp_device *device,
4587ec681f3Smrg                           struct lvp_descriptor_set *set);
4597ec681f3Smrg
4607ec681f3Smrgstruct lvp_pipeline_layout {
4617ec681f3Smrg   struct vk_object_base base;
4627ec681f3Smrg   struct {
4637ec681f3Smrg      struct lvp_descriptor_set_layout *layout;
4647ec681f3Smrg      uint32_t dynamic_offset_start;
4657ec681f3Smrg   } set[MAX_SETS];
4667ec681f3Smrg
4677ec681f3Smrg   uint32_t num_sets;
4687ec681f3Smrg   uint32_t push_constant_size;
4697ec681f3Smrg   struct {
4707ec681f3Smrg      bool has_dynamic_offsets;
4717ec681f3Smrg   } stage[MESA_SHADER_STAGES];
4727ec681f3Smrg};
4737ec681f3Smrg
4747ec681f3Smrgstruct lvp_pipeline {
4757ec681f3Smrg   struct vk_object_base base;
4767ec681f3Smrg   struct lvp_device *                          device;
4777ec681f3Smrg   struct lvp_pipeline_layout *                 layout;
4787ec681f3Smrg
4797ec681f3Smrg   void *mem_ctx;
4807ec681f3Smrg   bool is_compute_pipeline;
4817ec681f3Smrg   bool force_min_sample;
4827ec681f3Smrg   nir_shader *pipeline_nir[MESA_SHADER_STAGES];
4837ec681f3Smrg   void *shader_cso[PIPE_SHADER_TYPES];
4847ec681f3Smrg   VkGraphicsPipelineCreateInfo graphics_create_info;
4857ec681f3Smrg   VkComputePipelineCreateInfo compute_create_info;
4867ec681f3Smrg   uint32_t line_stipple_factor;
4877ec681f3Smrg   uint16_t line_stipple_pattern;
4887ec681f3Smrg   bool line_stipple_enable;
4897ec681f3Smrg   bool line_smooth;
4907ec681f3Smrg   bool disable_multisample;
4917ec681f3Smrg   bool line_rectangular;
4927ec681f3Smrg   bool gs_output_lines;
4937ec681f3Smrg   bool provoking_vertex_last;
4947ec681f3Smrg};
4957ec681f3Smrg
4967ec681f3Smrgstruct lvp_event {
4977ec681f3Smrg   struct vk_object_base base;
4987ec681f3Smrg   volatile uint64_t event_storage;
4997ec681f3Smrg};
5007ec681f3Smrg
5017ec681f3Smrgstruct lvp_fence {
5027ec681f3Smrg   struct vk_object_base base;
5037ec681f3Smrg   uint64_t timeline;
5047ec681f3Smrg   struct util_queue_fence fence;
5057ec681f3Smrg   struct pipe_fence_handle *handle;
5067ec681f3Smrg   bool signalled;
5077ec681f3Smrg};
5087ec681f3Smrg
5097ec681f3Smrgstruct lvp_semaphore_timeline {
5107ec681f3Smrg   struct lvp_semaphore_timeline *next;
5117ec681f3Smrg   uint64_t signal; //api
5127ec681f3Smrg   uint64_t timeline; //queue
5137ec681f3Smrg   struct pipe_fence_handle *fence;
5147ec681f3Smrg};
5157ec681f3Smrg
5167ec681f3Smrgstruct lvp_semaphore {
5177ec681f3Smrg   struct vk_object_base base;
5187ec681f3Smrg   bool is_timeline;
5197ec681f3Smrg   uint64_t current;
5207ec681f3Smrg   simple_mtx_t lock;
5217ec681f3Smrg   mtx_t submit_lock;
5227ec681f3Smrg   cnd_t submit;
5237ec681f3Smrg   void *mem;
5247ec681f3Smrg   struct util_dynarray links;
5257ec681f3Smrg   struct lvp_semaphore_timeline *timeline;
5267ec681f3Smrg   struct lvp_semaphore_timeline *latest;
5277ec681f3Smrg};
5287ec681f3Smrg
5297ec681f3Smrgstruct lvp_buffer {
5307ec681f3Smrg   struct vk_object_base base;
5317ec681f3Smrg
5327ec681f3Smrg   VkDeviceSize                                 size;
5337ec681f3Smrg
5347ec681f3Smrg   VkBufferUsageFlags                           usage;
5357ec681f3Smrg   VkDeviceSize                                 offset;
5367ec681f3Smrg
5377ec681f3Smrg   struct pipe_memory_allocation *pmem;
5387ec681f3Smrg   struct pipe_resource *bo;
5397ec681f3Smrg   uint64_t total_size;
5407ec681f3Smrg};
5417ec681f3Smrg
5427ec681f3Smrgstruct lvp_buffer_view {
5437ec681f3Smrg   struct vk_object_base base;
5447ec681f3Smrg   VkFormat format;
5457ec681f3Smrg   enum pipe_format pformat;
5467ec681f3Smrg   struct lvp_buffer *buffer;
5477ec681f3Smrg   uint32_t offset;
5487ec681f3Smrg   uint64_t range;
5497ec681f3Smrg};
5507ec681f3Smrg
5517ec681f3Smrgstruct lvp_query_pool {
5527ec681f3Smrg   struct vk_object_base base;
5537ec681f3Smrg   VkQueryType type;
5547ec681f3Smrg   uint32_t count;
5557ec681f3Smrg   VkQueryPipelineStatisticFlags pipeline_stats;
5567ec681f3Smrg   enum pipe_query_type base_type;
5577ec681f3Smrg   struct pipe_query *queries[0];
5587ec681f3Smrg};
5597ec681f3Smrg
5607ec681f3Smrgstruct lvp_cmd_pool {
5617ec681f3Smrg   struct vk_object_base                        base;
5627ec681f3Smrg   VkAllocationCallbacks                        alloc;
5637ec681f3Smrg   struct list_head                             cmd_buffers;
5647ec681f3Smrg   struct list_head                             free_cmd_buffers;
5657ec681f3Smrg};
5667ec681f3Smrg
5677ec681f3Smrg
5687ec681f3Smrgenum lvp_cmd_buffer_status {
5697ec681f3Smrg   LVP_CMD_BUFFER_STATUS_INVALID,
5707ec681f3Smrg   LVP_CMD_BUFFER_STATUS_INITIAL,
5717ec681f3Smrg   LVP_CMD_BUFFER_STATUS_RECORDING,
5727ec681f3Smrg   LVP_CMD_BUFFER_STATUS_EXECUTABLE,
5737ec681f3Smrg   LVP_CMD_BUFFER_STATUS_PENDING,
5747ec681f3Smrg};
5757ec681f3Smrg
5767ec681f3Smrgstruct lvp_cmd_buffer {
5777ec681f3Smrg   struct vk_command_buffer vk;
5787ec681f3Smrg
5797ec681f3Smrg   struct lvp_device *                          device;
5807ec681f3Smrg
5817ec681f3Smrg   VkCommandBufferLevel                         level;
5827ec681f3Smrg   enum lvp_cmd_buffer_status status;
5837ec681f3Smrg   struct lvp_cmd_pool *                        pool;
5847ec681f3Smrg   struct list_head                             pool_link;
5857ec681f3Smrg
5867ec681f3Smrg   struct vk_cmd_queue                          queue;
5877ec681f3Smrg
5887ec681f3Smrg   uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
5897ec681f3Smrg};
5907ec681f3Smrg
5917ec681f3Smrg
5927ec681f3Smrg#define LVP_FROM_HANDLE(__lvp_type, __name, __handle) \
5937ec681f3Smrg   struct __lvp_type *__name = __lvp_type ## _from_handle(__handle)
5947ec681f3Smrg
5957ec681f3SmrgVK_DEFINE_HANDLE_CASTS(lvp_cmd_buffer, vk.base, VkCommandBuffer,
5967ec681f3Smrg                       VK_OBJECT_TYPE_COMMAND_BUFFER)
5977ec681f3SmrgVK_DEFINE_HANDLE_CASTS(lvp_device, vk.base, VkDevice, VK_OBJECT_TYPE_DEVICE)
5987ec681f3SmrgVK_DEFINE_HANDLE_CASTS(lvp_instance, vk.base, VkInstance, VK_OBJECT_TYPE_INSTANCE)
5997ec681f3SmrgVK_DEFINE_HANDLE_CASTS(lvp_physical_device, vk.base, VkPhysicalDevice,
6007ec681f3Smrg                       VK_OBJECT_TYPE_PHYSICAL_DEVICE)
6017ec681f3SmrgVK_DEFINE_HANDLE_CASTS(lvp_queue, vk.base, VkQueue, VK_OBJECT_TYPE_QUEUE)
6027ec681f3Smrg
6037ec681f3Smrg   VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_cmd_pool, base,VkCommandPool,
6047ec681f3Smrg                                  VK_OBJECT_TYPE_COMMAND_POOL)
6057ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_buffer, base, VkBuffer,
6067ec681f3Smrg                               VK_OBJECT_TYPE_BUFFER)
6077ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_buffer_view, base, VkBufferView,
6087ec681f3Smrg                               VK_OBJECT_TYPE_BUFFER_VIEW)
6097ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_pool, base, VkDescriptorPool,
6107ec681f3Smrg                               VK_OBJECT_TYPE_DESCRIPTOR_POOL)
6117ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_set, base, VkDescriptorSet,
6127ec681f3Smrg                               VK_OBJECT_TYPE_DESCRIPTOR_SET)
6137ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_set_layout, base, VkDescriptorSetLayout,
6147ec681f3Smrg                               VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
6157ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_update_template, base, VkDescriptorUpdateTemplate,
6167ec681f3Smrg                               VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
6177ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_device_memory, base, VkDeviceMemory,
6187ec681f3Smrg                               VK_OBJECT_TYPE_DEVICE_MEMORY)
6197ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_event, base, VkEvent, VK_OBJECT_TYPE_EVENT)
6207ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_framebuffer, base, VkFramebuffer,
6217ec681f3Smrg                               VK_OBJECT_TYPE_FRAMEBUFFER)
6227ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
6237ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_image_view, base, VkImageView,
6247ec681f3Smrg                               VK_OBJECT_TYPE_IMAGE_VIEW);
6257ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_pipeline_cache, base, VkPipelineCache,
6267ec681f3Smrg                               VK_OBJECT_TYPE_PIPELINE_CACHE)
6277ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_pipeline, base, VkPipeline,
6287ec681f3Smrg                               VK_OBJECT_TYPE_PIPELINE)
6297ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_pipeline_layout, base, VkPipelineLayout,
6307ec681f3Smrg                               VK_OBJECT_TYPE_PIPELINE_LAYOUT)
6317ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_query_pool, base, VkQueryPool,
6327ec681f3Smrg                               VK_OBJECT_TYPE_QUERY_POOL)
6337ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_render_pass, base, VkRenderPass,
6347ec681f3Smrg                               VK_OBJECT_TYPE_RENDER_PASS)
6357ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_sampler, base, VkSampler,
6367ec681f3Smrg                               VK_OBJECT_TYPE_SAMPLER)
6377ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_fence, base, VkFence, VK_OBJECT_TYPE_FENCE);
6387ec681f3SmrgVK_DEFINE_NONDISP_HANDLE_CASTS(lvp_semaphore, base, VkSemaphore,
6397ec681f3Smrg                               VK_OBJECT_TYPE_SEMAPHORE);
6407ec681f3Smrg
6417ec681f3Smrgstruct lvp_attachment_state {
6427ec681f3Smrg   VkImageAspectFlags pending_clear_aspects;
6437ec681f3Smrg   VkClearValue clear_value;
6447ec681f3Smrg};
6457ec681f3Smrg
6467ec681f3Smrgstruct lvp_write_descriptor {
6477ec681f3Smrg   uint32_t dst_binding;
6487ec681f3Smrg   uint32_t dst_array_element;
6497ec681f3Smrg   uint32_t descriptor_count;
6507ec681f3Smrg   VkDescriptorType descriptor_type;
6517ec681f3Smrg};
6527ec681f3Smrg
6537ec681f3Smrgstruct lvp_cmd_push_descriptor_set {
6547ec681f3Smrg   VkPipelineBindPoint bind_point;
6557ec681f3Smrg   struct lvp_pipeline_layout *layout;
6567ec681f3Smrg   uint32_t set;
6577ec681f3Smrg   uint32_t descriptor_write_count;
6587ec681f3Smrg   struct lvp_write_descriptor *descriptors;
6597ec681f3Smrg   union lvp_descriptor_info *infos;
6607ec681f3Smrg};
6617ec681f3Smrg
6627ec681f3SmrgVkResult lvp_execute_cmds(struct lvp_device *device,
6637ec681f3Smrg                          struct lvp_queue *queue,
6647ec681f3Smrg                          struct lvp_cmd_buffer *cmd_buffer);
6657ec681f3Smrg
6667ec681f3Smrgstruct lvp_image *lvp_swapchain_get_image(VkSwapchainKHR swapchain,
6677ec681f3Smrg					  uint32_t index);
6687ec681f3Smrg
6697ec681f3Smrgstatic inline enum pipe_format
6707ec681f3Smrglvp_vk_format_to_pipe_format(VkFormat format)
6717ec681f3Smrg{
6727ec681f3Smrg   /* Some formats cause problems with CTS right now.*/
6737ec681f3Smrg   if (format == VK_FORMAT_R4G4B4A4_UNORM_PACK16 ||
6747ec681f3Smrg       format == VK_FORMAT_R5G5B5A1_UNORM_PACK16 ||
6757ec681f3Smrg       format == VK_FORMAT_R8_SRGB ||
6767ec681f3Smrg       format == VK_FORMAT_R8G8_SRGB ||
6777ec681f3Smrg       format == VK_FORMAT_R64G64B64A64_SFLOAT ||
6787ec681f3Smrg       format == VK_FORMAT_R64_SFLOAT ||
6797ec681f3Smrg       format == VK_FORMAT_R64G64_SFLOAT ||
6807ec681f3Smrg       format == VK_FORMAT_R64G64B64_SFLOAT ||
6817ec681f3Smrg       format == VK_FORMAT_A2R10G10B10_SINT_PACK32 ||
6827ec681f3Smrg       format == VK_FORMAT_A2B10G10R10_SINT_PACK32 ||
6837ec681f3Smrg       format == VK_FORMAT_G8B8G8R8_422_UNORM ||
6847ec681f3Smrg       format == VK_FORMAT_B8G8R8G8_422_UNORM ||
6857ec681f3Smrg       format == VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM ||
6867ec681f3Smrg       format == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM ||
6877ec681f3Smrg       format == VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM ||
6887ec681f3Smrg       format == VK_FORMAT_G8_B8R8_2PLANE_422_UNORM ||
6897ec681f3Smrg       format == VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM ||
6907ec681f3Smrg       format == VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM ||
6917ec681f3Smrg       format == VK_FORMAT_G16_B16R16_2PLANE_420_UNORM ||
6927ec681f3Smrg       format == VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM ||
6937ec681f3Smrg       format == VK_FORMAT_G16_B16R16_2PLANE_422_UNORM ||
6947ec681f3Smrg       format == VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM ||
6957ec681f3Smrg       format == VK_FORMAT_D16_UNORM_S8_UINT)
6967ec681f3Smrg      return PIPE_FORMAT_NONE;
6977ec681f3Smrg
6987ec681f3Smrg   return vk_format_to_pipe_format(format);
6997ec681f3Smrg}
7007ec681f3Smrg
7017ec681f3Smrgvoid
7027ec681f3Smrgqueue_thread_noop(void *data, void *gdata, int thread_index);
7037ec681f3Smrg#ifdef __cplusplus
7047ec681f3Smrg}
7057ec681f3Smrg#endif
706