1 /* Copyright © 2024 Intel Corporation
2 * SPDX-License-Identifier: MIT
3 */
4
5 #include "anv_private.h"
6 #include "anv_api_version.h"
7
8 #include "util/driconf.h"
9
10 static const driOptionDescription anv_dri_options[] = {
11 DRI_CONF_SECTION_PERFORMANCE
12 DRI_CONF_ADAPTIVE_SYNC(true)
13 DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
14 DRI_CONF_VK_X11_STRICT_IMAGE_COUNT(false)
15 DRI_CONF_VK_KHR_PRESENT_WAIT(false)
16 DRI_CONF_VK_XWAYLAND_WAIT_READY(false)
17 DRI_CONF_ANV_ASSUME_FULL_SUBGROUPS(0)
18 DRI_CONF_ANV_ASSUME_FULL_SUBGROUPS_WITH_BARRIER(false)
19 DRI_CONF_ANV_DISABLE_FCV(false)
20 DRI_CONF_ANV_ENABLE_BUFFER_COMP(false)
21 DRI_CONF_ANV_EXTERNAL_MEMORY_IMPLICIT_SYNC(true)
22 DRI_CONF_ANV_FORCE_GUC_LOW_LATENCY(false)
23 DRI_CONF_ANV_SAMPLE_MASK_OUT_OPENGL_BEHAVIOUR(false)
24 DRI_CONF_ANV_FORCE_FILTER_ADDR_ROUNDING(false)
25 DRI_CONF_ANV_FP64_WORKAROUND_ENABLED(false)
26 DRI_CONF_ANV_GENERATED_INDIRECT_THRESHOLD(4)
27 DRI_CONF_ANV_GENERATED_INDIRECT_RING_THRESHOLD(100)
28 DRI_CONF_NO_16BIT(false)
29 DRI_CONF_INTEL_ENABLE_WA_14018912822(false)
30 DRI_CONF_INTEL_SAMPLER_ROUTE_TO_LSC(false)
31 DRI_CONF_ANV_QUERY_CLEAR_WITH_BLORP_THRESHOLD(6)
32 DRI_CONF_ANV_QUERY_COPY_WITH_SHADER_THRESHOLD(6)
33 DRI_CONF_ANV_FORCE_INDIRECT_DESCRIPTORS(false)
34 DRI_CONF_SHADER_SPILLING_RATE(11)
35 DRI_CONF_OPT_B(intel_tbimr, true, "Enable TBIMR tiled rendering")
36 DRI_CONF_ANV_COMPRESSION_CONTROL_ENABLED(false)
37 DRI_CONF_ANV_FAKE_NONLOCAL_MEMORY(false)
38 DRI_CONF_OPT_E(intel_stack_id, 512, 256, 2048,
39 "Control the number stackIDs (i.e. number of unique rays in the RT subsytem)",
40 DRI_CONF_ENUM(256, "256 stackids")
41 DRI_CONF_ENUM(512, "512 stackids")
42 DRI_CONF_ENUM(1024, "1024 stackids")
43 DRI_CONF_ENUM(2048, "2048 stackids"))
44 DRI_CONF_ANV_UPPER_BOUND_DESCRIPTOR_POOL_SAMPLER(false)
45 DRI_CONF_SECTION_END
46
47 DRI_CONF_SECTION_DEBUG
48 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
49 DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST(false)
50 DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false)
51 DRI_CONF_VK_X11_IGNORE_SUBOPTIMAL(false)
52 DRI_CONF_LIMIT_TRIG_INPUT_RANGE(false)
53 DRI_CONF_ANV_MESH_CONV_PRIM_ATTRS_TO_VERT_ATTRS(-2)
54 DRI_CONF_FORCE_VK_VENDOR()
55 DRI_CONF_FAKE_SPARSE(false)
56 DRI_CONF_CUSTOM_BORDER_COLORS_WITHOUT_FORMAT(!DETECT_OS_ANDROID)
57 #if DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 34
58 DRI_CONF_VK_REQUIRE_ASTC(true)
59 #else
60 DRI_CONF_VK_REQUIRE_ASTC(false)
61 #endif
62 DRI_CONF_SECTION_END
63
64 DRI_CONF_SECTION_QUALITY
65 DRI_CONF_PP_LOWER_DEPTH_RANGE_RATE()
66 DRI_CONF_SECTION_END
67 };
68
anv_EnumerateInstanceVersion(uint32_t * pApiVersion)69 VkResult anv_EnumerateInstanceVersion(
70 uint32_t* pApiVersion)
71 {
72 *pApiVersion = ANV_API_VERSION;
73 return VK_SUCCESS;
74 }
75
76 static const struct vk_instance_extension_table instance_extensions = {
77 .KHR_device_group_creation = true,
78 .KHR_external_fence_capabilities = true,
79 .KHR_external_memory_capabilities = true,
80 .KHR_external_semaphore_capabilities = true,
81 .KHR_get_physical_device_properties2 = true,
82 .EXT_debug_report = true,
83 .EXT_debug_utils = true,
84
85 #ifdef ANV_USE_WSI_PLATFORM
86 .KHR_get_surface_capabilities2 = true,
87 .KHR_surface = true,
88 .KHR_surface_protected_capabilities = true,
89 .EXT_surface_maintenance1 = true,
90 .EXT_swapchain_colorspace = true,
91 #endif
92 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
93 .KHR_wayland_surface = true,
94 #endif
95 #ifdef VK_USE_PLATFORM_XCB_KHR
96 .KHR_xcb_surface = true,
97 #endif
98 #ifdef VK_USE_PLATFORM_XLIB_KHR
99 .KHR_xlib_surface = true,
100 #endif
101 #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
102 .EXT_acquire_xlib_display = true,
103 #endif
104 #ifdef VK_USE_PLATFORM_DISPLAY_KHR
105 .KHR_display = true,
106 .KHR_get_display_properties2 = true,
107 .EXT_direct_mode_display = true,
108 .EXT_display_surface_counter = true,
109 .EXT_acquire_drm_display = true,
110 #endif
111 #ifndef VK_USE_PLATFORM_WIN32_KHR
112 .EXT_headless_surface = true,
113 #endif
114 };
115
anv_EnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties)116 VkResult anv_EnumerateInstanceExtensionProperties(
117 const char* pLayerName,
118 uint32_t* pPropertyCount,
119 VkExtensionProperties* pProperties)
120 {
121 if (pLayerName)
122 return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
123
124 return vk_enumerate_instance_extension_properties(
125 &instance_extensions, pPropertyCount, pProperties);
126 }
127
128 static void
anv_init_dri_options(struct anv_instance * instance)129 anv_init_dri_options(struct anv_instance *instance)
130 {
131 driParseOptionInfo(&instance->available_dri_options, anv_dri_options,
132 ARRAY_SIZE(anv_dri_options));
133 driParseConfigFiles(&instance->dri_options,
134 &instance->available_dri_options, 0, "anv", NULL, NULL,
135 instance->vk.app_info.app_name,
136 instance->vk.app_info.app_version,
137 instance->vk.app_info.engine_name,
138 instance->vk.app_info.engine_version);
139
140 instance->assume_full_subgroups =
141 driQueryOptioni(&instance->dri_options, "anv_assume_full_subgroups");
142 instance->assume_full_subgroups_with_barrier =
143 driQueryOptionb(&instance->dri_options, "anv_assume_full_subgroups_with_barrier");
144 instance->limit_trig_input_range =
145 driQueryOptionb(&instance->dri_options, "limit_trig_input_range");
146 instance->sample_mask_out_opengl_behaviour =
147 driQueryOptionb(&instance->dri_options, "anv_sample_mask_out_opengl_behaviour");
148 instance->force_filter_addr_rounding =
149 driQueryOptionb(&instance->dri_options, "anv_force_filter_addr_rounding");
150 instance->lower_depth_range_rate =
151 driQueryOptionf(&instance->dri_options, "lower_depth_range_rate");
152 instance->no_16bit =
153 driQueryOptionb(&instance->dri_options, "no_16bit");
154 instance->intel_enable_wa_14018912822 =
155 driQueryOptionb(&instance->dri_options, "intel_enable_wa_14018912822");
156 instance->mesh_conv_prim_attrs_to_vert_attrs =
157 driQueryOptioni(&instance->dri_options, "anv_mesh_conv_prim_attrs_to_vert_attrs");
158 instance->fp64_workaround_enabled =
159 driQueryOptionb(&instance->dri_options, "fp64_workaround_enabled");
160 instance->generated_indirect_threshold =
161 driQueryOptioni(&instance->dri_options, "generated_indirect_threshold");
162 instance->generated_indirect_ring_threshold =
163 driQueryOptioni(&instance->dri_options, "generated_indirect_ring_threshold");
164 instance->query_clear_with_blorp_threshold =
165 driQueryOptioni(&instance->dri_options, "query_clear_with_blorp_threshold");
166 instance->query_copy_with_shader_threshold =
167 driQueryOptioni(&instance->dri_options, "query_copy_with_shader_threshold");
168 instance->force_vk_vendor =
169 driQueryOptioni(&instance->dri_options, "force_vk_vendor");
170 instance->has_fake_sparse =
171 driQueryOptionb(&instance->dri_options, "fake_sparse");
172 instance->enable_tbimr = driQueryOptionb(&instance->dri_options, "intel_tbimr");
173 instance->disable_fcv =
174 driQueryOptionb(&instance->dri_options, "anv_disable_fcv");
175 instance->enable_buffer_comp =
176 driQueryOptionb(&instance->dri_options, "anv_enable_buffer_comp");
177 instance->external_memory_implicit_sync =
178 driQueryOptionb(&instance->dri_options, "anv_external_memory_implicit_sync");
179 instance->compression_control_enabled =
180 driQueryOptionb(&instance->dri_options, "compression_control_enabled");
181 instance->anv_fake_nonlocal_memory =
182 driQueryOptionb(&instance->dri_options, "anv_fake_nonlocal_memory");
183 instance->anv_upper_bound_descriptor_pool_sampler =
184 driQueryOptionb(&instance->dri_options,
185 "anv_upper_bound_descriptor_pool_sampler");
186 instance->custom_border_colors_without_format =
187 driQueryOptionb(&instance->dri_options,
188 "custom_border_colors_without_format");
189
190 instance->stack_ids = driQueryOptioni(&instance->dri_options, "intel_stack_id");
191 switch (instance->stack_ids) {
192 case 256:
193 case 512:
194 case 1024:
195 case 2048:
196 break;
197 default:
198 mesa_logw("Invalid value provided for drirc intel_stack_id=%u, reverting to 512.",
199 instance->stack_ids);
200 instance->stack_ids = 512;
201 break;
202 }
203 instance->force_guc_low_latency =
204 driQueryOptionb(&instance->dri_options, "force_guc_low_latency");
205 }
206
anv_CreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)207 VkResult anv_CreateInstance(
208 const VkInstanceCreateInfo* pCreateInfo,
209 const VkAllocationCallbacks* pAllocator,
210 VkInstance* pInstance)
211 {
212 struct anv_instance *instance;
213 VkResult result;
214
215 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
216
217 if (pAllocator == NULL)
218 pAllocator = vk_default_allocator();
219
220 instance = vk_alloc(pAllocator, sizeof(*instance), 8,
221 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
222 if (!instance)
223 return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
224
225 struct vk_instance_dispatch_table dispatch_table;
226 vk_instance_dispatch_table_from_entrypoints(
227 &dispatch_table, &anv_instance_entrypoints, true);
228 vk_instance_dispatch_table_from_entrypoints(
229 &dispatch_table, &wsi_instance_entrypoints, false);
230
231 result = vk_instance_init(&instance->vk, &instance_extensions,
232 &dispatch_table, pCreateInfo, pAllocator);
233 if (result != VK_SUCCESS) {
234 vk_free(pAllocator, instance);
235 return vk_error(NULL, result);
236 }
237
238 instance->vk.physical_devices.try_create_for_drm = anv_physical_device_try_create;
239 instance->vk.physical_devices.destroy = anv_physical_device_destroy;
240
241 VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
242
243 anv_init_dri_options(instance);
244
245 intel_driver_ds_init();
246
247 *pInstance = anv_instance_to_handle(instance);
248
249 return VK_SUCCESS;
250 }
251
anv_DestroyInstance(VkInstance _instance,const VkAllocationCallbacks * pAllocator)252 void anv_DestroyInstance(
253 VkInstance _instance,
254 const VkAllocationCallbacks* pAllocator)
255 {
256 ANV_FROM_HANDLE(anv_instance, instance, _instance);
257
258 if (!instance)
259 return;
260
261 VG(VALGRIND_DESTROY_MEMPOOL(instance));
262
263 driDestroyOptionCache(&instance->dri_options);
264 driDestroyOptionInfo(&instance->available_dri_options);
265
266 vk_instance_finish(&instance->vk);
267 vk_free(&instance->vk.alloc, instance);
268 }
269
anv_GetInstanceProcAddr(VkInstance _instance,const char * pName)270 PFN_vkVoidFunction anv_GetInstanceProcAddr(
271 VkInstance _instance,
272 const char* pName)
273 {
274 ANV_FROM_HANDLE(anv_instance, instance, _instance);
275 return vk_instance_get_proc_addr(instance ? &instance->vk : NULL,
276 &anv_instance_entrypoints,
277 pName);
278 }
279
280 /* With version 1+ of the loader interface the ICD should expose
281 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
282 */
283 PUBLIC
vk_icdGetInstanceProcAddr(VkInstance instance,const char * pName)284 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
285 VkInstance instance,
286 const char* pName)
287 {
288 return anv_GetInstanceProcAddr(instance, pName);
289 }
290