1 /*
2  * Copyright 2018 Collabora Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef ZINK_SCREEN_H
25 #define ZINK_SCREEN_H
26 
27 #include "zink_device_info.h"
28 
29 #include "pipe/p_screen.h"
30 #include "util/slab.h"
31 
32 #include <vulkan/vulkan.h>
33 
34 #if defined(__APPLE__)
35 // Source of MVK_VERSION
36 #include "MoltenVK/vk_mvk_moltenvk.h"
37 #endif
38 
39 extern uint32_t zink_debug;
40 
41 #define ZINK_DEBUG_NIR 0x1
42 #define ZINK_DEBUG_SPIRV 0x2
43 #define ZINK_DEBUG_TGSI 0x4
44 #define ZINK_DEBUG_VALIDATION 0x8
45 
46 struct zink_screen {
47    struct pipe_screen base;
48 
49    struct sw_winsys *winsys;
50 
51    struct slab_parent_pool transfer_pool;
52 
53    VkInstance instance;
54    VkPhysicalDevice pdev;
55 
56    struct zink_device_info info;
57 
58    bool have_X8_D24_UNORM_PACK32;
59    bool have_D24_UNORM_S8_UINT;
60    bool have_triangle_fans;
61 
62    uint32_t gfx_queue;
63    uint32_t timestamp_valid_bits;
64    VkDevice dev;
65    VkDebugUtilsMessengerEXT debugUtilsCallbackHandle;
66 
67    uint32_t loader_version;
68    bool have_physical_device_prop2_ext;
69    bool have_debug_utils_ext;
70 #if defined(MVK_VERSION)
71    bool have_moltenvk;
72 #endif
73 
74    PFN_vkGetPhysicalDeviceFeatures2 vk_GetPhysicalDeviceFeatures2;
75    PFN_vkGetPhysicalDeviceProperties2 vk_GetPhysicalDeviceProperties2;
76 
77    PFN_vkGetMemoryFdKHR vk_GetMemoryFdKHR;
78    PFN_vkCmdBeginConditionalRenderingEXT vk_CmdBeginConditionalRenderingEXT;
79    PFN_vkCmdEndConditionalRenderingEXT vk_CmdEndConditionalRenderingEXT;
80 
81    PFN_vkCmdBindTransformFeedbackBuffersEXT vk_CmdBindTransformFeedbackBuffersEXT;
82    PFN_vkCmdBeginTransformFeedbackEXT vk_CmdBeginTransformFeedbackEXT;
83    PFN_vkCmdEndTransformFeedbackEXT vk_CmdEndTransformFeedbackEXT;
84    PFN_vkCmdBeginQueryIndexedEXT vk_CmdBeginQueryIndexedEXT;
85    PFN_vkCmdEndQueryIndexedEXT vk_CmdEndQueryIndexedEXT;
86    PFN_vkCmdDrawIndirectByteCountEXT vk_CmdDrawIndirectByteCountEXT;
87 
88    PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vk_GetPhysicalDeviceCalibrateableTimeDomainsEXT;
89    PFN_vkGetCalibratedTimestampsEXT vk_GetCalibratedTimestampsEXT;
90 
91    PFN_vkCmdSetViewportWithCountEXT vk_CmdSetViewportWithCountEXT;
92    PFN_vkCmdSetScissorWithCountEXT vk_CmdSetScissorWithCountEXT;
93 
94    PFN_vkCreateDebugUtilsMessengerEXT vk_CreateDebugUtilsMessengerEXT;
95    PFN_vkDestroyDebugUtilsMessengerEXT vk_DestroyDebugUtilsMessengerEXT;
96 
97 #if defined(MVK_VERSION)
98    PFN_vkGetMoltenVKConfigurationMVK vk_GetMoltenVKConfigurationMVK;
99    PFN_vkSetMoltenVKConfigurationMVK vk_SetMoltenVKConfigurationMVK;
100 
101    PFN_vkGetPhysicalDeviceMetalFeaturesMVK vk_GetPhysicalDeviceMetalFeaturesMVK;
102    PFN_vkGetVersionStringsMVK vk_GetVersionStringsMVK;
103    PFN_vkUseIOSurfaceMVK vk_UseIOSurfaceMVK;
104    PFN_vkGetIOSurfaceMVK vk_GetIOSurfaceMVK;
105 #endif
106 };
107 
108 static inline struct zink_screen *
zink_screen(struct pipe_screen * pipe)109 zink_screen(struct pipe_screen *pipe)
110 {
111    return (struct zink_screen *)pipe;
112 }
113 
114 VkFormat
115 zink_get_format(struct zink_screen *screen, enum pipe_format format);
116 
117 bool
118 zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format);
119 
120 #endif
121