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 #if DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 34
57 DRI_CONF_VK_REQUIRE_ASTC(true)
58 #else
59 DRI_CONF_VK_REQUIRE_ASTC(false)
60 #endif
61 DRI_CONF_SECTION_END
62
63 DRI_CONF_SECTION_QUALITY
64 DRI_CONF_PP_LOWER_DEPTH_RANGE_RATE()
65 DRI_CONF_SECTION_END
66 };
67
anv_EnumerateInstanceVersion(uint32_t * pApiVersion)68 VkResult anv_EnumerateInstanceVersion(
69 uint32_t* pApiVersion)
70 {
71 *pApiVersion = ANV_API_VERSION;
72 return VK_SUCCESS;
73 }
74
75 static const struct vk_instance_extension_table instance_extensions = {
76 .KHR_device_group_creation = true,
77 .KHR_external_fence_capabilities = true,
78 .KHR_external_memory_capabilities = true,
79 .KHR_external_semaphore_capabilities = true,
80 .KHR_get_physical_device_properties2 = true,
81 .EXT_debug_report = true,
82 .EXT_debug_utils = true,
83
84 #ifdef ANV_USE_WSI_PLATFORM
85 .KHR_get_surface_capabilities2 = true,
86 .KHR_surface = true,
87 .KHR_surface_protected_capabilities = true,
88 .EXT_surface_maintenance1 = true,
89 .EXT_swapchain_colorspace = true,
90 #endif
91 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
92 .KHR_wayland_surface = true,
93 #endif
94 #ifdef VK_USE_PLATFORM_XCB_KHR
95 .KHR_xcb_surface = true,
96 #endif
97 #ifdef VK_USE_PLATFORM_XLIB_KHR
98 .KHR_xlib_surface = true,
99 #endif
100 #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
101 .EXT_acquire_xlib_display = true,
102 #endif
103 #ifdef VK_USE_PLATFORM_DISPLAY_KHR
104 .KHR_display = true,
105 .KHR_get_display_properties2 = true,
106 .EXT_direct_mode_display = true,
107 .EXT_display_surface_counter = true,
108 .EXT_acquire_drm_display = true,
109 #endif
110 #ifndef VK_USE_PLATFORM_WIN32_KHR
111 .EXT_headless_surface = true,
112 #endif
113 };
114
anv_EnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties)115 VkResult anv_EnumerateInstanceExtensionProperties(
116 const char* pLayerName,
117 uint32_t* pPropertyCount,
118 VkExtensionProperties* pProperties)
119 {
120 if (pLayerName)
121 return vk_error(NULL, VK_ERROR_LAYER_NOT_PRESENT);
122
123 return vk_enumerate_instance_extension_properties(
124 &instance_extensions, pPropertyCount, pProperties);
125 }
126
127 static void
anv_init_dri_options(struct anv_instance * instance)128 anv_init_dri_options(struct anv_instance *instance)
129 {
130 driParseOptionInfo(&instance->available_dri_options, anv_dri_options,
131 ARRAY_SIZE(anv_dri_options));
132 driParseConfigFiles(&instance->dri_options,
133 &instance->available_dri_options, 0, "anv", NULL, NULL,
134 instance->vk.app_info.app_name,
135 instance->vk.app_info.app_version,
136 instance->vk.app_info.engine_name,
137 instance->vk.app_info.engine_version);
138
139 instance->assume_full_subgroups =
140 driQueryOptioni(&instance->dri_options, "anv_assume_full_subgroups");
141 instance->assume_full_subgroups_with_barrier =
142 driQueryOptionb(&instance->dri_options, "anv_assume_full_subgroups_with_barrier");
143 instance->limit_trig_input_range =
144 driQueryOptionb(&instance->dri_options, "limit_trig_input_range");
145 instance->sample_mask_out_opengl_behaviour =
146 driQueryOptionb(&instance->dri_options, "anv_sample_mask_out_opengl_behaviour");
147 instance->force_filter_addr_rounding =
148 driQueryOptionb(&instance->dri_options, "anv_force_filter_addr_rounding");
149 instance->lower_depth_range_rate =
150 driQueryOptionf(&instance->dri_options, "lower_depth_range_rate");
151 instance->no_16bit =
152 driQueryOptionb(&instance->dri_options, "no_16bit");
153 instance->intel_enable_wa_14018912822 =
154 driQueryOptionb(&instance->dri_options, "intel_enable_wa_14018912822");
155 instance->mesh_conv_prim_attrs_to_vert_attrs =
156 driQueryOptioni(&instance->dri_options, "anv_mesh_conv_prim_attrs_to_vert_attrs");
157 instance->fp64_workaround_enabled =
158 driQueryOptionb(&instance->dri_options, "fp64_workaround_enabled");
159 instance->generated_indirect_threshold =
160 driQueryOptioni(&instance->dri_options, "generated_indirect_threshold");
161 instance->generated_indirect_ring_threshold =
162 driQueryOptioni(&instance->dri_options, "generated_indirect_ring_threshold");
163 instance->query_clear_with_blorp_threshold =
164 driQueryOptioni(&instance->dri_options, "query_clear_with_blorp_threshold");
165 instance->query_copy_with_shader_threshold =
166 driQueryOptioni(&instance->dri_options, "query_copy_with_shader_threshold");
167 instance->force_vk_vendor =
168 driQueryOptioni(&instance->dri_options, "force_vk_vendor");
169 instance->has_fake_sparse =
170 driQueryOptionb(&instance->dri_options, "fake_sparse");
171 instance->enable_tbimr = driQueryOptionb(&instance->dri_options, "intel_tbimr");
172 instance->disable_fcv =
173 driQueryOptionb(&instance->dri_options, "anv_disable_fcv");
174 instance->enable_buffer_comp =
175 driQueryOptionb(&instance->dri_options, "anv_enable_buffer_comp");
176 instance->external_memory_implicit_sync =
177 driQueryOptionb(&instance->dri_options, "anv_external_memory_implicit_sync");
178 instance->compression_control_enabled =
179 driQueryOptionb(&instance->dri_options, "compression_control_enabled");
180 instance->anv_fake_nonlocal_memory =
181 driQueryOptionb(&instance->dri_options, "anv_fake_nonlocal_memory");
182 instance->anv_upper_bound_descriptor_pool_sampler =
183 driQueryOptionb(&instance->dri_options,
184 "anv_upper_bound_descriptor_pool_sampler");
185
186 instance->stack_ids = driQueryOptioni(&instance->dri_options, "intel_stack_id");
187 switch (instance->stack_ids) {
188 case 256:
189 case 512:
190 case 1024:
191 case 2048:
192 break;
193 default:
194 mesa_logw("Invalid value provided for drirc intel_stack_id=%u, reverting to 512.",
195 instance->stack_ids);
196 instance->stack_ids = 512;
197 break;
198 }
199 instance->force_guc_low_latency =
200 driQueryOptionb(&instance->dri_options, "force_guc_low_latency");
201 }
202
anv_CreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)203 VkResult anv_CreateInstance(
204 const VkInstanceCreateInfo* pCreateInfo,
205 const VkAllocationCallbacks* pAllocator,
206 VkInstance* pInstance)
207 {
208 struct anv_instance *instance;
209 VkResult result;
210
211 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
212
213 if (pAllocator == NULL)
214 pAllocator = vk_default_allocator();
215
216 instance = vk_alloc(pAllocator, sizeof(*instance), 8,
217 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
218 if (!instance)
219 return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
220
221 struct vk_instance_dispatch_table dispatch_table;
222 vk_instance_dispatch_table_from_entrypoints(
223 &dispatch_table, &anv_instance_entrypoints, true);
224 vk_instance_dispatch_table_from_entrypoints(
225 &dispatch_table, &wsi_instance_entrypoints, false);
226
227 result = vk_instance_init(&instance->vk, &instance_extensions,
228 &dispatch_table, pCreateInfo, pAllocator);
229 if (result != VK_SUCCESS) {
230 vk_free(pAllocator, instance);
231 return vk_error(NULL, result);
232 }
233
234 instance->vk.physical_devices.try_create_for_drm = anv_physical_device_try_create;
235 instance->vk.physical_devices.destroy = anv_physical_device_destroy;
236
237 VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
238
239 anv_init_dri_options(instance);
240
241 intel_driver_ds_init();
242
243 *pInstance = anv_instance_to_handle(instance);
244
245 return VK_SUCCESS;
246 }
247
anv_DestroyInstance(VkInstance _instance,const VkAllocationCallbacks * pAllocator)248 void anv_DestroyInstance(
249 VkInstance _instance,
250 const VkAllocationCallbacks* pAllocator)
251 {
252 ANV_FROM_HANDLE(anv_instance, instance, _instance);
253
254 if (!instance)
255 return;
256
257 VG(VALGRIND_DESTROY_MEMPOOL(instance));
258
259 driDestroyOptionCache(&instance->dri_options);
260 driDestroyOptionInfo(&instance->available_dri_options);
261
262 vk_instance_finish(&instance->vk);
263 vk_free(&instance->vk.alloc, instance);
264 }
265
anv_GetInstanceProcAddr(VkInstance _instance,const char * pName)266 PFN_vkVoidFunction anv_GetInstanceProcAddr(
267 VkInstance _instance,
268 const char* pName)
269 {
270 ANV_FROM_HANDLE(anv_instance, instance, _instance);
271 return vk_instance_get_proc_addr(instance ? &instance->vk : NULL,
272 &anv_instance_entrypoints,
273 pName);
274 }
275
276 /* With version 1+ of the loader interface the ICD should expose
277 * vk_icdGetInstanceProcAddr to work around certain LD_PRELOAD issues seen in apps.
278 */
279 PUBLIC
vk_icdGetInstanceProcAddr(VkInstance instance,const char * pName)280 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(
281 VkInstance instance,
282 const char* pName)
283 {
284 return anv_GetInstanceProcAddr(instance, pName);
285 }
286