Debian Codegraph @

src/asahi/vulkan/hk_physical_device.c

raw
1 /*
2 * Copyright 2024 Valve Corporation
3 * Copyright 2024 Alyssa Rosenzweig
4 * Copyright 2022-2023 Collabora Ltd. and Red Hat Inc.
5 * SPDX-License-Identifier: MIT
6 */
7 #include "hk_physical_device.h"
8
9 #include "asahi/compiler/agx_nir_texture.h"
10 #include "asahi/lib/agx_device.h"
11 #include "asahi/lib/agx_nir_lower_vbo.h"
12 #include "util/disk_cache.h"
13 #include "util/mesa-blake3.h"
14 #include "git_sha1.h"
15 #include "hk_buffer.h"
16 #include "hk_entrypoints.h"
17 #include "hk_image.h"
18 #include "hk_instance.h"
19 #include "hk_private.h"
20 #include "hk_shader.h"
21 #include "hk_wsi.h"
22
23 #include "util/simple_mtx.h"
24 #include "vulkan/vulkan_core.h"
25 #include "vulkan/wsi/wsi_common.h"
26 #include "vk_drm_syncobj.h"
27 #include "vk_shader_module.h"
28
29 #include <fcntl.h>
30 #include <string.h>
31 #include <xf86drm.h>
32 #include <sys/stat.h>
33 #include <sys/sysmacros.h>
34
35 static uint32_t
36 hk_get_vk_version()
37 {
38 /* Version override takes priority */
39 const uint32_t version_override = vk_get_version_override();
40 if (version_override)
41 return version_override;
42
43 return VK_MAKE_VERSION(1, 4, VK_HEADER_VERSION);
44 }
45
46 static void
47 hk_get_device_extensions(const struct hk_instance *instance,
48 struct vk_device_extension_table *ext)
49 {
50 *ext = (struct vk_device_extension_table){
51 .KHR_8bit_storage = true,
52 .KHR_16bit_storage = true,
53 .KHR_bind_memory2 = true,
54 .KHR_buffer_device_address = true,
55 .KHR_calibrated_timestamps = true,
56 .KHR_copy_commands2 = true,
57 .KHR_create_renderpass2 = true,
58 .KHR_dedicated_allocation = true,
59 .KHR_depth_stencil_resolve = true,
60 .KHR_descriptor_update_template = true,
61 .KHR_device_group = true,
62 .KHR_draw_indirect_count = true,
63 .KHR_driver_properties = true,
64 .KHR_dynamic_rendering = true,
65 .KHR_dynamic_rendering_local_read = true,
66 .KHR_external_fence = true,
67 .KHR_external_fence_fd = true,
68 .KHR_external_memory = true,
69 .KHR_external_memory_fd = true,
70 .KHR_external_semaphore = true,
71 .KHR_external_semaphore_fd = true,
72 .KHR_format_feature_flags2 = true,
73 .KHR_fragment_shader_barycentric = false,
74 .KHR_get_memory_requirements2 = true,
75 .KHR_global_priority = true,
76 .KHR_image_format_list = true,
77 .KHR_imageless_framebuffer = true,
78 #ifdef HK_USE_WSI_PLATFORM
79 .KHR_incremental_present = true,
80 #endif
81 .KHR_index_type_uint8 = true,
82 .KHR_line_rasterization = true,
83 .KHR_load_store_op_none = true,
84 .KHR_maintenance1 = true,
85 .KHR_maintenance2 = true,
86 .KHR_maintenance3 = true,
87 .KHR_maintenance4 = true,
88 .KHR_maintenance5 = true,
89 .KHR_maintenance6 = true,
90 .KHR_maintenance7 = true,
91 .KHR_maintenance8 = true,
92 .KHR_maintenance9 = true,
93 .KHR_map_memory2 = true,
94 .KHR_multiview = true,
95 .KHR_pipeline_binary = true,
96 .KHR_pipeline_executable_properties = true,
97 .KHR_pipeline_library = true,
98 #ifdef HK_USE_WSI_PLATFORM
99 .KHR_present_id = true,
100 .KHR_present_id2 = true,
101 .KHR_present_wait = true,
102 .KHR_present_wait2 = true,
103 #endif
104 .KHR_push_descriptor = true,
105 .KHR_relaxed_block_layout = true,
106 .KHR_robustness2 = true,
107 .KHR_sampler_mirror_clamp_to_edge = true,
108 .KHR_sampler_ycbcr_conversion = true,
109 .KHR_separate_depth_stencil_layouts = true,
110 .KHR_shader_atomic_int64 = false,
111 .KHR_shader_clock = false,
112 .KHR_shader_draw_parameters = true,
113 .KHR_shader_expect_assume = true,
114 .KHR_shader_float_controls = true,
115 .KHR_shader_float_controls2 = true,
116 .KHR_shader_float16_int8 = true,
117 .KHR_shader_integer_dot_product = true,
118 .KHR_shader_maximal_reconvergence = true,
119 .KHR_shader_non_semantic_info = true,
120 .KHR_shader_quad_control = true,
121 .KHR_shader_relaxed_extended_instruction = true,
122 .KHR_shader_subgroup_extended_types = true,
123 .KHR_shader_subgroup_rotate = true,
124 .KHR_shader_subgroup_uniform_control_flow = true,
125 .KHR_shader_terminate_invocation = true,
126 .KHR_spirv_1_4 = true,
127 .KHR_storage_buffer_storage_class = true,
128 .KHR_timeline_semaphore = true,
129 #ifdef HK_USE_WSI_PLATFORM
130 .KHR_swapchain = true,
131 .KHR_swapchain_maintenance1 = true,
132 .KHR_swapchain_mutable_format = true,
133 #endif
134 .KHR_synchronization2 = true,
135 .KHR_uniform_buffer_standard_layout = true,
136 .KHR_variable_pointers = true,
137 .KHR_vertex_attribute_divisor = true,
138 .KHR_vulkan_memory_model = true,
139 .KHR_workgroup_memory_explicit_layout = true,
140 .KHR_zero_initialize_workgroup_memory = true,
141 .EXT_4444_formats = true,
142 .EXT_attachment_feedback_loop_layout = true,
143 .EXT_blend_operation_advanced = true,
144 .EXT_border_color_swizzle = true,
145 .EXT_buffer_device_address = true,
146 .EXT_calibrated_timestamps = true,
147 .EXT_conditional_rendering = false,
148 .EXT_color_write_enable = true,
149 .EXT_custom_border_color = true,
150 .EXT_depth_bias_control = true,
151 .EXT_depth_clip_control = false,
152 .EXT_depth_clip_enable = true,
153 .EXT_descriptor_indexing = true,
154 #ifdef VK_USE_PLATFORM_DISPLAY_KHR
155 .EXT_display_control = false,
156 #endif
157 .EXT_dynamic_rendering_unused_attachments = true,
158 .EXT_extended_dynamic_state = true,
159 .EXT_extended_dynamic_state2 = true,
160 .EXT_extended_dynamic_state3 = true,
161 .EXT_external_memory_dma_buf = true,
162 .EXT_global_priority = true,
163 .EXT_global_priority_query = true,
164 .EXT_graphics_pipeline_library = true,
165 .EXT_hdr_metadata = true,
166 .EXT_host_query_reset = true,
167 .EXT_host_image_copy = true,
168 .EXT_image_2d_view_of_3d = true,
169 .EXT_image_drm_format_modifier = true,
170 .EXT_image_robustness = true,
171 .EXT_image_sliced_view_of_3d = false,
172 .EXT_image_view_min_lod = instance->image_view_min_lod,
173 .EXT_index_type_uint8 = true,
174 .EXT_inline_uniform_block = true,
175 .EXT_line_rasterization = true,
176 .EXT_load_store_op_none = true,
177 .EXT_map_memory_placed = true,
178 .EXT_memory_budget = false,
179 .EXT_multi_draw = true,
180 .EXT_mutable_descriptor_type = true,
181 .EXT_non_seamless_cube_map = true,
182 .EXT_pipeline_creation_cache_control = true,
183 .EXT_pipeline_creation_feedback = true,
184 .EXT_pipeline_protected_access = true,
185 .EXT_pipeline_robustness = true,
186 .EXT_physical_device_drm = true,
187 #ifdef HK_USE_WSI_PLATFORM
188 .EXT_present_timing = true,
189 #endif
190 .EXT_primitive_topology_list_restart = true,
191 .EXT_private_data = true,
192 .EXT_primitives_generated_query = false,
193 .EXT_provoking_vertex = true,
194 .EXT_queue_family_foreign = true,
195 .EXT_robustness2 = true,
196 .EXT_sample_locations = true,
197 .EXT_sampler_filter_minmax = false,
198 .EXT_scalar_block_layout = true,
199 .EXT_separate_stencil_usage = true,
200 .EXT_shader_image_atomic_int64 = false,
201 .EXT_shader_demote_to_helper_invocation = true,
202 .EXT_shader_module_identifier = true,
203 .EXT_shader_object = true,
204 .EXT_shader_replicated_composites = true,
205 .EXT_shader_stencil_export = true,
206 .EXT_shader_subgroup_ballot = true,
207 .EXT_shader_subgroup_vote = true,
208 .EXT_shader_uniform_buffer_unsized_array = true,
209 .EXT_shader_viewport_index_layer = true,
210 .EXT_subgroup_size_control = true,
211 #ifdef HK_USE_WSI_PLATFORM
212 .EXT_swapchain_maintenance1 = true,
213 #endif
214 .EXT_texel_buffer_alignment = true,
215 .EXT_tooling_info = true,
216 .EXT_transform_feedback = true,
217 .EXT_vertex_attribute_divisor = true,
218 .EXT_vertex_input_dynamic_state = true,
219 .EXT_ycbcr_2plane_444_formats = false,
220 .EXT_ycbcr_image_arrays = false,
221 .GOOGLE_decorate_string = true,
222 .GOOGLE_hlsl_functionality1 = true,
223 .GOOGLE_user_type = true,
224 .VALVE_mutable_descriptor_type = true,
225 };
226 }
227
228 static void
229 hk_get_device_features(
230 const struct agx_device *dev, const struct hk_instance *instance,
231 const struct vk_device_extension_table *supported_extensions,
232 struct vk_features *features)
233 {
234 *features = (struct vk_features){
235 /* Vulkan 1.0 */
236 .robustBufferAccess = true,
237 .fullDrawIndexUint32 = true,
238 .imageCubeArray = true,
239 .independentBlend = true,
240 .geometryShader = true,
241 .tessellationShader = true,
242 .sampleRateShading = true,
243 .dualSrcBlend = true,
244 .logicOp = true,
245 .multiDrawIndirect = true,
246 .drawIndirectFirstInstance = true,
247 .depthClamp = true,
248 .depthBiasClamp = true,
249 .fillModeNonSolid = true,
250 .depthBounds = false,
251 .wideLines = true,
252 .largePoints = true,
253 .alphaToOne = true,
254 .multiViewport = true,
255 .samplerAnisotropy = true,
256 .textureCompressionETC2 = true,
257 .textureCompressionBC = true,
258 .textureCompressionASTC_LDR = true,
259 .occlusionQueryPrecise = true,
260 .pipelineStatisticsQuery = true,
261 .vertexPipelineStoresAndAtomics = instance->vertex_stores,
262 .fragmentStoresAndAtomics = true,
263 .shaderTessellationAndGeometryPointSize = true,
264 .shaderImageGatherExtended = true,
265 .shaderStorageImageExtendedFormats = true,
266 /* TODO: hitting the vertex shader timeout in CTS, but should work */
267 .shaderStorageImageMultisample = false,
268 .shaderStorageImageReadWithoutFormat = true,
269 .shaderStorageImageWriteWithoutFormat = true,
270 .shaderUniformBufferArrayDynamicIndexing = true,
271 .shaderSampledImageArrayDynamicIndexing = true,
272 .shaderStorageBufferArrayDynamicIndexing = true,
273 .shaderStorageImageArrayDynamicIndexing = true,
274 .shaderClipDistance = true,
275 .shaderCullDistance = true,
276 .shaderFloat64 = false,
277 .shaderInt64 = true,
278 .shaderInt16 = true,
279 .shaderResourceResidency = true,
280 .shaderResourceMinLod = true,
281 .sparseBinding = true,
282
283 /* We probably could advertise multisampled sparse but we don't have a use
284 * case yet and it isn't trivial.
285 */
286 .sparseResidency2Samples = false,
287 .sparseResidency4Samples = false,
288 .sparseResidency8Samples = false,
289 .sparseResidencyAliased = true,
290 .sparseResidencyImage2D = true,
291 .sparseResidencyBuffer = true,
292
293 /* This needs investigation. */
294 .sparseResidencyImage3D = false,
295 .variableMultisampleRate = false,
296 .inheritedQueries = true,
297
298 /* Vulkan 1.1 */
299 .storageBuffer16BitAccess = true,
300 .uniformAndStorageBuffer16BitAccess = true,
301 .storagePushConstant16 = true,
302 .storageInputOutput16 = false,
303 .multiview = true,
304 .multiviewGeometryShader = false,
305 .multiviewTessellationShader = false,
306 .variablePointersStorageBuffer = true,
307 .variablePointers = true,
308 .shaderDrawParameters = true,
309 .samplerYcbcrConversion = true,
310
311 /* Vulkan 1.2 */
312 .samplerMirrorClampToEdge = true,
313 .drawIndirectCount = true,
314 .storageBuffer8BitAccess = true,
315 .uniformAndStorageBuffer8BitAccess = true,
316 .storagePushConstant8 = true,
317 .shaderBufferInt64Atomics = false,
318 .shaderSharedInt64Atomics = false,
319 .shaderFloat16 = true,
320 .shaderInt8 = true,
321 .descriptorIndexing = true,
322 .shaderInputAttachmentArrayDynamicIndexing = true,
323 .shaderUniformTexelBufferArrayDynamicIndexing = true,
324 .shaderStorageTexelBufferArrayDynamicIndexing = true,
325 .shaderUniformBufferArrayNonUniformIndexing = true,
326 .shaderSampledImageArrayNonUniformIndexing = true,
327 .shaderStorageBufferArrayNonUniformIndexing = true,
328 .shaderStorageImageArrayNonUniformIndexing = true,
329 .shaderInputAttachmentArrayNonUniformIndexing = true,
330 .shaderUniformTexelBufferArrayNonUniformIndexing = true,
331 .shaderStorageTexelBufferArrayNonUniformIndexing = true,
332 .descriptorBindingUniformBufferUpdateAfterBind = true,
333 .descriptorBindingSampledImageUpdateAfterBind = true,
334 .descriptorBindingStorageImageUpdateAfterBind = true,
335 .descriptorBindingStorageBufferUpdateAfterBind = true,
336 .descriptorBindingUniformTexelBufferUpdateAfterBind = true,
337 .descriptorBindingStorageTexelBufferUpdateAfterBind = true,
338 .descriptorBindingUpdateUnusedWhilePending = true,
339 .descriptorBindingPartiallyBound = true,
340 .descriptorBindingVariableDescriptorCount = true,
341 .runtimeDescriptorArray = true,
342 .samplerFilterMinmax = instance->fake_minmax,
343 .scalarBlockLayout = true,
344 .imagelessFramebuffer = true,
345 .uniformBufferStandardLayout = true,
346 .shaderSubgroupExtendedTypes = true,
347 .separateDepthStencilLayouts = true,
348 .hostQueryReset = true,
349 .timelineSemaphore = true,
350 .bufferDeviceAddress = true,
351 .bufferDeviceAddressCaptureReplay = true,
352 .bufferDeviceAddressMultiDevice = false,
353 .vulkanMemoryModel = true,
354 .vulkanMemoryModelDeviceScope = true,
355 .vulkanMemoryModelAvailabilityVisibilityChains = false,
356 .shaderOutputViewportIndex = true,
357 .shaderOutputLayer = true,
358 .subgroupBroadcastDynamicId = true,
359
360 /* Vulkan 1.3 */
361 .robustImageAccess = true,
362 .inlineUniformBlock = true,
363 .descriptorBindingInlineUniformBlockUpdateAfterBind = true,
364 .pipelineCreationCacheControl = true,
365 .privateData = true,
366 .shaderDemoteToHelperInvocation = true,
367 .shaderTerminateInvocation = true,
368 .subgroupSizeControl = true,
369 .computeFullSubgroups = true,
370 .synchronization2 = true,
371 .shaderZeroInitializeWorkgroupMemory = true,
372 .dynamicRendering = true,
373 .shaderIntegerDotProduct = true,
374 .maintenance4 = true,
375
376 /* Vulkan 1.4 */
377 .pushDescriptor = true,
378
379 /* VK_KHR_dynamic_rendering_local_read */
380 .dynamicRenderingLocalRead = true,
381
382 /* VK_KHR_fragment_shader_barycentric */
383 .fragmentShaderBarycentric = false,
384
385 /* VK_KHR_global_priority */
386 .globalPriorityQuery = true,
387
388 /* VK_KHR_index_type_uint8 */
389 .indexTypeUint8 = true,
390
391 /* VK_KHR_line_rasterization */
392 .rectangularLines = false,
393 .bresenhamLines = true,
394 .smoothLines = false,
395 .stippledRectangularLines = false,
396 .stippledBresenhamLines = false,
397 .stippledSmoothLines = false,
398
399 /* VK_KHR_maintenance5 */
400 .maintenance5 = true,
401
402 /* VK_KHR_maintenance6 */
403 .maintenance6 = true,
404
405 /* VK_KHR_maintenance7 */
406 .maintenance7 = true,
407
408 /* VK_KHR_maintenance8 */
409 .maintenance8 = true,
410
411 /* VK_KHR_maintenance9 */
412 .maintenance9 = true,
413
414 /* VK_KHR_pipeline_binary */
415 .pipelineBinaries = true,
416
417 /* VK_KHR_pipeline_executable_properties */
418 .pipelineExecutableInfo = true,
419
420 /* VK_KHR_present_id */
421 .presentId = true,
422
423 /* VK_KHR_present_id2 */
424 .presentId2 = true,
425
426 /* VK_KHR_present_wait */
427 .presentWait = true,
428
429 /* VK_KHR_present_wait2 */
430 .presentWait2 = true,
431
432 /* VK_KHR_shader_clock */
433 .shaderSubgroupClock = false,
434 .shaderDeviceClock = false,
435
436 /* VK_KHR_shader_expect_assume */
437 .shaderExpectAssume = true,
438
439 /* VK_KHR_shader_float_controls2 */
440 .shaderFloatControls2 = true,
441
442 /* VK_KHR_shader_maximal_reconvergence */
443 .shaderMaximalReconvergence = true,
444
445 /* VK_KHR_shader_quad_control */
446 .shaderQuadControl = true,
447
448 /* VK_KHR_shader_subgroup_rotate */
449 .shaderSubgroupRotate = true,
450 .shaderSubgroupRotateClustered = true,
451
452 /* VK_KHR_vertex_attribute_divisor */
453 .vertexAttributeInstanceRateDivisor = true,
454 .vertexAttributeInstanceRateZeroDivisor = true,
455
456 /* VK_KHR_workgroup_memory_explicit_layout */
457 .workgroupMemoryExplicitLayout = true,
458 .workgroupMemoryExplicitLayoutScalarBlockLayout = true,
459 .workgroupMemoryExplicitLayout8BitAccess = true,
460 .workgroupMemoryExplicitLayout16BitAccess = true,
461
462 /* VK_EXT_4444_formats */
463 .formatA4R4G4B4 = true,
464 .formatA4B4G4R4 = true,
465
466 /* VK_EXT_attachment_feedback_loop_layout */
467 .attachmentFeedbackLoopLayout = true,
468
469 /* VK_EXT_border_color_swizzle */
470 .borderColorSwizzle = true,
471 .borderColorSwizzleFromImage = false,
472
473 /* VK_EXT_buffer_device_address */
474 .bufferDeviceAddressCaptureReplayEXT = true,
475
476 /* VK_EXT_color_write_enable */
477 .colorWriteEnable = true,
478
479 /* VK_EXT_conditional_rendering */
480 .conditionalRendering = false,
481 .inheritedConditionalRendering = false,
482
483 /* VK_EXT_custom_border_color */
484 .customBorderColors = true,
485 .customBorderColorWithoutFormat = true,
486
487 /* VK_EXT_depth_bias_control */
488 .depthBiasControl = true,
489 .leastRepresentableValueForceUnormRepresentation = true,
490 .floatRepresentation = false,
491 .depthBiasExact = true,
492
493 /* VK_EXT_depth_clip_control */
494 .depthClipControl = false,
495
496 /* VK_EXT_depth_clip_enable */
497 .depthClipEnable = true,
498
499 /* VK_EXT_dynamic_rendering_unused_attachments */
500 .dynamicRenderingUnusedAttachments = true,
501
502 /* VK_EXT_extended_dynamic_state */
503 .extendedDynamicState = true,
504
505 /* VK_EXT_extended_dynamic_state2 */
506 .extendedDynamicState2 = true,
507 .extendedDynamicState2LogicOp = true,
508 .extendedDynamicState2PatchControlPoints = true,
509
510 /* VK_EXT_extended_dynamic_state3 */
511 .extendedDynamicState3TessellationDomainOrigin = true,
512 .extendedDynamicState3DepthClampEnable = true,
513 .extendedDynamicState3PolygonMode = true,
514 .extendedDynamicState3RasterizationSamples = true,
515 .extendedDynamicState3SampleMask = true,
516 .extendedDynamicState3AlphaToCoverageEnable = true,
517 .extendedDynamicState3AlphaToOneEnable = true,
518 .extendedDynamicState3LogicOpEnable = true,
519 .extendedDynamicState3ColorBlendEnable = true,
520 .extendedDynamicState3ColorBlendEquation = true,
521 .extendedDynamicState3ColorWriteMask = true,
522 .extendedDynamicState3RasterizationStream = true,
523 .extendedDynamicState3ConservativeRasterizationMode = false,
524 .extendedDynamicState3ExtraPrimitiveOverestimationSize = false,
525 .extendedDynamicState3DepthClipEnable = true,
526 .extendedDynamicState3SampleLocationsEnable = true,
527 .extendedDynamicState3ColorBlendAdvanced = false,
528 .extendedDynamicState3ProvokingVertexMode = true,
529 .extendedDynamicState3LineRasterizationMode = true,
530 .extendedDynamicState3LineStippleEnable = false,
531 .extendedDynamicState3DepthClipNegativeOneToOne = false,
532 .extendedDynamicState3ViewportWScalingEnable = false,
533 .extendedDynamicState3ViewportSwizzle = false,
534 .extendedDynamicState3CoverageToColorEnable = false,
535 .extendedDynamicState3CoverageToColorLocation = false,
536 .extendedDynamicState3CoverageModulationMode = false,
537 .extendedDynamicState3CoverageModulationTableEnable = false,
538 .extendedDynamicState3CoverageModulationTable = false,
539 .extendedDynamicState3CoverageReductionMode = false,
540 .extendedDynamicState3RepresentativeFragmentTestEnable = false,
541 .extendedDynamicState3ShadingRateImageEnable = false,
542
543 /* VK_EXT_graphics_pipeline_library */
544 .graphicsPipelineLibrary = true,
545
546 /* VK_EXT_host_image_copy */
547 .hostImageCopy = true,
548
549 /* VK_EXT_image_2d_view_of_3d */
550 .image2DViewOf3D = true,
551 .sampler2DViewOf3D = true,
552
553 /* VK_EXT_image_sliced_view_of_3d */
554 .imageSlicedViewOf3D = false,
555
556 #ifdef HK_USE_WSI_PLATFORM
557 /* VK_KHR_swapchain_maintenance1 */
558 .swapchainMaintenance1 = true,
559 #endif
560
561 /* VK_EXT_image_view_min_lod */
562 .minLod = instance->image_view_min_lod,
563
564 /* VK_EXT_map_memory_placed */
565 .memoryMapPlaced = true,
566 .memoryMapRangePlaced = false,
567 .memoryUnmapReserve = true,
568
569 /* VK_EXT_multi_draw */
570 .multiDraw = true,
571
572 /* VK_EXT_mutable_descriptor_type */
573 .mutableDescriptorType = true,
574
575 /* VK_EXT_non_seamless_cube_map */
576 .nonSeamlessCubeMap = true,
577
578 /* VK_EXT_pipeline_protected_access */
579 .pipelineProtectedAccess = true,
580
581 /* VK_EXT_pipeline_robustness */
582 .pipelineRobustness = true,
583
584 /* VK_EXT_primitive_topology_list_restart */
585 .primitiveTopologyListRestart = true,
586 .primitiveTopologyPatchListRestart = false,
587
588 /* VK_EXT_primitives_generated_query */
589 .primitivesGeneratedQuery = false,
590 .primitivesGeneratedQueryWithNonZeroStreams = false,
591 .primitivesGeneratedQueryWithRasterizerDiscard = false,
592
593 /* VK_EXT_provoking_vertex */
594 .provokingVertexLast = true,
595 .transformFeedbackPreservesProvokingVertex = true,
596
597 /* VK_KHR_robustness2 */
598 .robustBufferAccess2 = true,
599 .robustImageAccess2 = true,
600 .nullDescriptor = true,
601
602 /* VK_EXT_shader_image_atomic_int64 */
603 .shaderImageInt64Atomics = false,
604 .sparseImageInt64Atomics = false,
605
606 /* VK_EXT_shader_module_identifier */
607 .shaderModuleIdentifier = true,
608
609 /* VK_EXT_shader_object */
610 .shaderObject = true,
611
612 /* VK_EXT_shader_replicated_composites */
613 .shaderReplicatedComposites = true,
614
615 /* VK_KHR_shader_subgroup_uniform_control_flow */
616 .shaderSubgroupUniformControlFlow = true,
617
618 /* VK_EXT_shader_uniform_buffer_unsized_array */
619 .shaderUniformBufferUnsizedArray = true,
620
621 /* VK_EXT_texel_buffer_alignment */
622 .texelBufferAlignment = true,
623
624 /* VK_EXT_transform_feedback */
625 .transformFeedback = true,
626 .geometryStreams = true,
627
628 /* VK_EXT_vertex_input_dynamic_state */
629 .vertexInputDynamicState = true,
630
631 /* VK_EXT_ycbcr_2plane_444_formats */
632 .ycbcr2plane444Formats = false,
633
634 /* VK_EXT_ycbcr_image_arrays */
635 .ycbcrImageArrays = false,
636
637 /* VK_KHR_shader_relaxed_extended_instruction */
638 .shaderRelaxedExtendedInstruction = true,
639
640 /* VK_EXT_blend_operation_advanced */
641 .advancedBlendCoherentOperations = true,
642
643 #ifdef HK_USE_WSI_PLATFORM
644 /* VK_EXT_present_timing */
645 .presentTiming = true,
646 .presentAtRelativeTime = true,
647 .presentAtAbsoluteTime = true,
648 #endif
649 };
650 }
651
652 static void
653 hk_get_device_properties(const struct agx_device *dev,
654 const struct hk_instance *instance,
655 struct vk_properties *properties)
656 {
657 /* Note: update nir_shader_compiler_options.max_samples when changing this. */
658 const VkSampleCountFlagBits sample_counts =
659 VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT;
660
661 uint64_t os_page_size = 16384;
662 os_get_page_size(&os_page_size);
663
664 /* The hardware limit is 128. However, we need to set a lower limit to
665 * account for duplicated system values: clip/cull and viewport targets.
666 * There are up to 8 combined clip/cull planes and only 1 viewport target,
667 * giving a theoretical limit of 119. We round down to 116 to give a sensible
668 * limit in vec4s.
669 */
670 unsigned max_vgt_output_components = 116;
671
672 *properties = (struct vk_properties){
673 .apiVersion = hk_get_vk_version(),
674 .driverVersion = vk_get_driver_version(),
675 .vendorID = instance->force_vk_vendor ?: VK_VENDOR_ID_MESA,
676 .deviceID = 0,
677 .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
678
679 /* Vulkan 1.0 limits */
680 .maxImageDimension1D = 16384,
681 .maxImageDimension2D = 16384,
682 .maxImageDimension3D = 16384,
683 .maxImageDimensionCube = 16384,
684 .maxImageArrayLayers = 2048,
685 .maxTexelBufferElements = AGX_TEXTURE_BUFFER_MAX_SIZE,
686 .maxUniformBufferRange = 65536,
687
688 /* From a hardware perspective, storage buffers are lowered to global
689 * address arithmetic so there is no hard limit. However, making efficient
690 * use of the hardware addressing modes depends on no signed wrapping in
691 * any `amul` operations, which are themselves bounded by
692 * maxStorageBufferRange. Therefore, limit storage buffers to INT32_MAX
693 * bytes instead of UINT32_MAX. This is believed to be acceptable for
694 * Direct3D.
695 */
696 .maxStorageBufferRange = INT32_MAX,
697 .maxPushConstantsSize = HK_MAX_PUSH_SIZE,
698 .maxMemoryAllocationCount = 4096,
699 .maxSamplerAllocationCount = 4000,
700 .bufferImageGranularity = 0x400,
701 .sparseAddressSpaceSize = HK_SPARSE_ADDR_SPACE_SIZE,
702 .maxBoundDescriptorSets = HK_MAX_SETS,
703 .maxPerStageDescriptorSamplers = HK_MAX_DESCRIPTORS,
704 .maxPerStageDescriptorUniformBuffers = HK_MAX_DESCRIPTORS,
705 .maxPerStageDescriptorStorageBuffers = HK_MAX_DESCRIPTORS,
706 .maxPerStageDescriptorSampledImages = HK_MAX_DESCRIPTORS,
707 .maxPerStageDescriptorStorageImages = HK_MAX_DESCRIPTORS,
708 .maxPerStageDescriptorInputAttachments = HK_MAX_DESCRIPTORS,
709 .maxPerStageResources = UINT32_MAX,
710 .maxDescriptorSetSamplers = HK_MAX_DESCRIPTORS,
711 .maxDescriptorSetUniformBuffers = HK_MAX_DESCRIPTORS,
712 .maxDescriptorSetUniformBuffersDynamic = HK_MAX_DYNAMIC_BUFFERS / 2,
713 .maxDescriptorSetStorageBuffers = HK_MAX_DESCRIPTORS,
714 .maxDescriptorSetStorageBuffersDynamic = HK_MAX_DYNAMIC_BUFFERS / 2,
715 .maxDescriptorSetSampledImages = HK_MAX_DESCRIPTORS,
716 .maxDescriptorSetStorageImages = HK_MAX_DESCRIPTORS,
717 .maxDescriptorSetInputAttachments = HK_MAX_DESCRIPTORS,
718 .maxVertexInputAttributes = AGX_MAX_VBUFS,
719 .maxVertexInputBindings = AGX_MAX_ATTRIBS,
720 .maxVertexInputAttributeOffset = 65535,
721 .maxVertexInputBindingStride = 2048,
722
723 .maxVertexOutputComponents = max_vgt_output_components,
724 .maxGeometryShaderInvocations = 32,
725 .maxGeometryInputComponents = 128,
726 .maxGeometryOutputComponents = max_vgt_output_components,
727 .maxGeometryOutputVertices = 1024,
728 .maxGeometryTotalOutputComponents = 1024,
729 .maxTessellationGenerationLevel = 64,
730 .maxTessellationPatchSize = 32,
731 .maxTessellationControlPerVertexInputComponents = 128,
732 .maxTessellationControlPerVertexOutputComponents = 128,
733 .maxTessellationControlPerPatchOutputComponents = 120,
734 .maxTessellationControlTotalOutputComponents = 4216,
735 .maxTessellationEvaluationInputComponents = 128,
736 .maxTessellationEvaluationOutputComponents = max_vgt_output_components,
737
738 /* Set to match maxVertexOutputComponents, hardware limit is higher. */
739 .maxFragmentInputComponents = max_vgt_output_components,
740 .maxFragmentOutputAttachments = HK_MAX_RTS,
741 .maxFragmentDualSrcAttachments = 1,
742 .maxFragmentCombinedOutputResources = HK_MAX_RTS + HK_MAX_DESCRIPTORS,
743 .maxComputeSharedMemorySize = HK_MAX_SHARED_SIZE,
744 .maxComputeWorkGroupCount = {0x7fffffff, 65535, 65535},
745 .maxComputeWorkGroupInvocations = 1024,
746 .maxComputeWorkGroupSize = {1024, 1024, 64},
747 .subPixelPrecisionBits = 8,
748 .subTexelPrecisionBits = 8,
749 .mipmapPrecisionBits = 8,
750 .maxDrawIndexedIndexValue = UINT32_MAX,
751 .maxDrawIndirectCount = UINT16_MAX,
752 .maxSamplerLodBias = 15,
753 .maxSamplerAnisotropy = 16,
754 .maxViewports = HK_MAX_VIEWPORTS,
755 .maxViewportDimensions = {32768, 32768},
756 .viewportBoundsRange = {-65536, 65536},
757 .viewportSubPixelBits = 8,
758 .minMemoryMapAlignment = os_page_size,
759 .minTexelBufferOffsetAlignment = HK_MIN_TEXEL_BUFFER_ALIGNMENT,
760 .minUniformBufferOffsetAlignment = HK_MIN_UBO_ALIGNMENT,
761 .minStorageBufferOffsetAlignment = HK_MIN_SSBO_ALIGNMENT,
762 .minTexelOffset = -8,
763 .maxTexelOffset = 7,
764 .minTexelGatherOffset = -8,
765 .maxTexelGatherOffset = 7,
766 .minInterpolationOffset = -0.5,
767 .maxInterpolationOffset = 0.4375,
768 .subPixelInterpolationOffsetBits = 4,
769 .maxFramebufferHeight = 16384,
770 .maxFramebufferWidth = 16384,
771 .maxFramebufferLayers = 2048,
772 .framebufferColorSampleCounts = sample_counts,
773 .framebufferDepthSampleCounts = sample_counts,
774 .framebufferNoAttachmentsSampleCounts = sample_counts,
775 .framebufferStencilSampleCounts = sample_counts,
776 .maxColorAttachments = HK_MAX_RTS,
777 .sampledImageColorSampleCounts = sample_counts,
778 .sampledImageIntegerSampleCounts = sample_counts,
779 .sampledImageDepthSampleCounts = sample_counts,
780 .sampledImageStencilSampleCounts = sample_counts,
781 .storageImageSampleCounts = sample_counts,
782 .maxSampleMaskWords = 1,
783 .timestampComputeAndGraphics = true,
784 /* FIXME: Is timestamp period actually 1? */
785 .timestampPeriod = 1.0f,
786 .maxClipDistances = 8,
787 .maxCullDistances = 8,
788 .maxCombinedClipAndCullDistances = 8,
789 .discreteQueuePriorities = 2,
790 .pointSizeRange = {1.0, 512.f - 0.0625f},
791 .lineWidthRange = {1.0, 16.0f},
792 .pointSizeGranularity = 0.0625,
793 .lineWidthGranularity = 1.0f / 16.0f,
794 .strictLines = false,
795 .standardSampleLocations = true,
796 .optimalBufferCopyOffsetAlignment = 1,
797 .optimalBufferCopyRowPitchAlignment = 1,
798 .nonCoherentAtomSize = 64,
799
800 /* Vulkan 1.0 sparse properties */
801 .sparseResidencyNonResidentStrict = true,
802 .sparseResidencyAlignedMipSize = false,
803 .sparseResidencyStandard2DBlockShape = true,
804
805 /* We can implement the standard block size for MSAA 4x but maybe not MSAA
806 * 2x?
807 */
808 .sparseResidencyStandard2DMultisampleBlockShape = false,
809
810 /* As far as I can tell, there is no way to implement this on G13. This
811 * is a shame because D3D12 requires it for FL12.2.
812 */
813 .sparseResidencyStandard3DBlockShape = false,
814
815 /* Vulkan 1.1 properties */
816 .subgroupSize = 32,
817 .subgroupSupportedStages =
818 VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_ALL_GRAPHICS,
819 .subgroupSupportedOperations =
820 VK_SUBGROUP_FEATURE_BASIC_BIT | VK_SUBGROUP_FEATURE_BALLOT_BIT |
821 VK_SUBGROUP_FEATURE_VOTE_BIT | VK_SUBGROUP_FEATURE_QUAD_BIT |
822 VK_SUBGROUP_FEATURE_SHUFFLE_BIT |
823 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT |
824 VK_SUBGROUP_FEATURE_ROTATE_BIT_KHR |
825 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT |
826 VK_SUBGROUP_FEATURE_CLUSTERED_BIT |
827 VK_SUBGROUP_FEATURE_ROTATE_CLUSTERED_BIT_KHR,
828 .subgroupQuadOperationsInAllStages = true,
829 .pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY,
830 .maxMultiviewViewCount = HK_MAX_MULTIVIEW_VIEW_COUNT,
831 .maxMultiviewInstanceIndex = UINT32_MAX,
832 .maxPerSetDescriptors = UINT32_MAX,
833 .maxMemoryAllocationSize = (1ull << 37),
834
835 /* Vulkan 1.2 properties */
836 .supportedDepthResolveModes =
837 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_AVERAGE_BIT |
838 VK_RESOLVE_MODE_MIN_BIT | VK_RESOLVE_MODE_MAX_BIT,
839 .supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT |
840 VK_RESOLVE_MODE_MIN_BIT |
841 VK_RESOLVE_MODE_MAX_BIT,
842 .independentResolveNone = true,
843 .independentResolve = true,
844 .driverID = VK_DRIVER_ID_MESA_HONEYKRISP,
845 .conformanceVersion = (VkConformanceVersion){1, 4, 0, 0},
846 .denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL,
847 .roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL,
848 .shaderSignedZeroInfNanPreserveFloat16 = true,
849 .shaderSignedZeroInfNanPreserveFloat32 = true,
850 .shaderSignedZeroInfNanPreserveFloat64 = false,
851 .shaderDenormPreserveFloat16 = true,
852 .shaderDenormPreserveFloat32 = false,
853 .shaderDenormPreserveFloat64 = false,
854 .shaderDenormFlushToZeroFloat16 = false,
855 .shaderDenormFlushToZeroFloat32 = true,
856 .shaderDenormFlushToZeroFloat64 = false,
857 .shaderRoundingModeRTEFloat16 = true,
858 .shaderRoundingModeRTEFloat32 = true,
859 .shaderRoundingModeRTEFloat64 = false,
860 .shaderRoundingModeRTZFloat16 = false,
861 .shaderRoundingModeRTZFloat32 = false,
862 .shaderRoundingModeRTZFloat64 = false,
863 .maxUpdateAfterBindDescriptorsInAllPools = UINT32_MAX,
864 .shaderUniformBufferArrayNonUniformIndexingNative = true,
865 .shaderSampledImageArrayNonUniformIndexingNative = true,
866 .shaderStorageBufferArrayNonUniformIndexingNative = true,
867 .shaderStorageImageArrayNonUniformIndexingNative = true,
868 .shaderInputAttachmentArrayNonUniformIndexingNative = true,
869 .robustBufferAccessUpdateAfterBind = true,
870 .quadDivergentImplicitLod = false,
871 .maxPerStageDescriptorUpdateAfterBindSamplers = HK_MAX_DESCRIPTORS,
872 .maxPerStageDescriptorUpdateAfterBindUniformBuffers = HK_MAX_DESCRIPTORS,
873 .maxPerStageDescriptorUpdateAfterBindStorageBuffers = HK_MAX_DESCRIPTORS,
874 .maxPerStageDescriptorUpdateAfterBindSampledImages = HK_MAX_DESCRIPTORS,
875 .maxPerStageDescriptorUpdateAfterBindStorageImages = HK_MAX_DESCRIPTORS,
876 .maxPerStageDescriptorUpdateAfterBindInputAttachments =
877 HK_MAX_DESCRIPTORS,
878 .maxPerStageUpdateAfterBindResources = UINT32_MAX,
879 .maxDescriptorSetUpdateAfterBindSamplers = HK_MAX_DESCRIPTORS,
880 .maxDescriptorSetUpdateAfterBindUniformBuffers = HK_MAX_DESCRIPTORS,
881 .maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
882 HK_MAX_DYNAMIC_BUFFERS / 2,
883 .maxDescriptorSetUpdateAfterBindStorageBuffers = HK_MAX_DESCRIPTORS,
884 .maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
885 HK_MAX_DYNAMIC_BUFFERS / 2,
886 .maxDescriptorSetUpdateAfterBindSampledImages = HK_MAX_DESCRIPTORS,
887 .maxDescriptorSetUpdateAfterBindStorageImages = HK_MAX_DESCRIPTORS,
888 .maxDescriptorSetUpdateAfterBindInputAttachments = HK_MAX_DESCRIPTORS,
889 .filterMinmaxSingleComponentFormats = instance->fake_minmax,
890 .filterMinmaxImageComponentMapping = false,
891 .maxTimelineSemaphoreValueDifference = UINT64_MAX,
892 .framebufferIntegerColorSampleCounts = sample_counts,
893
894 /* Vulkan 1.3 properties */
895 .minSubgroupSize = 32,
896 .maxSubgroupSize = 32,
897 .maxComputeWorkgroupSubgroups = 1024 / 32,
898 .requiredSubgroupSizeStages = 0,
899 .maxInlineUniformBlockSize = HK_MAX_INLINE_UNIFORM_BLOCK_SIZE,
900 .maxPerStageDescriptorInlineUniformBlocks = 32,
901 .maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = 32,
902 .maxDescriptorSetInlineUniformBlocks = 6 * 32,
903 .maxDescriptorSetUpdateAfterBindInlineUniformBlocks = 6 * 32,
904 .maxInlineUniformTotalSize = 1 << 16,
905 .integerDotProduct4x8BitPackedUnsignedAccelerated = false,
906 .integerDotProduct4x8BitPackedSignedAccelerated = false,
907 .integerDotProduct4x8BitPackedMixedSignednessAccelerated = false,
908 .storageTexelBufferOffsetAlignmentBytes = HK_MIN_TEXEL_BUFFER_ALIGNMENT,
909 .storageTexelBufferOffsetSingleTexelAlignment = true,
910 .uniformTexelBufferOffsetAlignmentBytes = HK_MIN_TEXEL_BUFFER_ALIGNMENT,
911 .uniformTexelBufferOffsetSingleTexelAlignment = true,
912 .maxBufferSize = HK_MAX_BUFFER_SIZE,
913
914 /* Vulkan 1.4 properties */
915 .dynamicRenderingLocalReadDepthStencilAttachments = false,
916 .dynamicRenderingLocalReadMultisampledAttachments = true,
917
918 /* VK_KHR_push_descriptor */
919 .maxPushDescriptors = HK_MAX_PUSH_DESCRIPTORS,
920
921 /* VK_EXT_custom_border_color */
922 .maxCustomBorderColorSamplers = 4000,
923
924 /* VK_EXT_extended_dynamic_state3 */
925 .dynamicPrimitiveTopologyUnrestricted = true,
926
927 /* VK_EXT_graphics_pipeline_library */
928 .graphicsPipelineLibraryFastLinking = true,
929 .graphicsPipelineLibraryIndependentInterpolationDecoration = true,
930
931 /* VK_EXT_host_image_copy */
932
933 /* VK_KHR_line_rasterization */
934 .lineSubPixelPrecisionBits = 8,
935
936 /* VK_KHR_maintenance5 */
937 .earlyFragmentMultisampleCoverageAfterSampleCounting = false,
938 .earlyFragmentSampleMaskTestBeforeSampleCounting = true,
939 .depthStencilSwizzleOneSupport = true,
940 .polygonModePointSize = false,
941 .nonStrictSinglePixelWideLinesUseParallelogram = false,
942 .nonStrictWideLinesUseParallelogram = false,
943
944 /* VK_KHR_maintenance6 */
945 .blockTexelViewCompatibleMultipleLayers = false,
946 .maxCombinedImageSamplerDescriptorCount = 3,
947 .fragmentShadingRateClampCombinerInputs = false,
948
949 /* VK_KHR_maintenance7 */
950 .robustFragmentShadingRateAttachmentAccess = false,
951 .separateDepthStencilAttachmentAccess = false, /* TODO */
952 .maxDescriptorSetTotalUniformBuffersDynamic = HK_MAX_DYNAMIC_BUFFERS / 2,
953 .maxDescriptorSetTotalStorageBuffersDynamic = HK_MAX_DYNAMIC_BUFFERS / 2,
954 .maxDescriptorSetTotalBuffersDynamic = HK_MAX_DYNAMIC_BUFFERS,
955 .maxDescriptorSetUpdateAfterBindTotalUniformBuffersDynamic =
956 HK_MAX_DYNAMIC_BUFFERS / 2,
957 .maxDescriptorSetUpdateAfterBindTotalStorageBuffersDynamic =
958 HK_MAX_DYNAMIC_BUFFERS / 2,
959 .maxDescriptorSetUpdateAfterBindTotalBuffersDynamic =
960 HK_MAX_DYNAMIC_BUFFERS,
961
962 /* VK_KHR_maintenance9 */
963 .image2DViewOf3DSparse = false,
964 .defaultVertexAttributeValue =
965 VK_DEFAULT_VERTEX_ATTRIBUTE_VALUE_ZERO_ZERO_ZERO_ONE_KHR,
966
967 /* VK_EXT_map_memory_placed */
968 .minPlacedMemoryMapAlignment = os_page_size,
969
970 /* VK_EXT_multi_draw */
971 .maxMultiDrawCount = UINT16_MAX,
972
973 /* VK_KHR_pipeline_binary
974 *
975 * InternalCache properties are set by
976 * hk_physical_device_init_pipeline_cache()
977 */
978 .pipelineBinaryCompressedData = false,
979
980 /* VK_EXT_pipeline_robustness */
981 .defaultRobustnessStorageBuffers =
982 VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT,
983 .defaultRobustnessUniformBuffers =
984 VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT,
985 .defaultRobustnessVertexInputs =
986 VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT,
987 .defaultRobustnessImages =
988 VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_2_EXT,
989
990 /* VK_EXT_physical_device_drm gets populated later */
991
992 /* VK_EXT_provoking_vertex */
993 .provokingVertexModePerPipeline = true,
994 .transformFeedbackPreservesTriangleFanProvokingVertex = true,
995
996 /* VK_KHR_robustness2 */
997 .robustStorageBufferAccessSizeAlignment = HK_SSBO_BOUNDS_CHECK_ALIGNMENT,
998 .robustUniformBufferAccessSizeAlignment = HK_MIN_UBO_ALIGNMENT,
999
1000 /* VK_EXT_sample_locations */
1001 .sampleLocationSampleCounts = sample_counts & ~VK_SAMPLE_COUNT_1_BIT,
1002 .maxSampleLocationGridSize = (VkExtent2D){1, 1},
1003 .sampleLocationCoordinateRange[0] = 0.0f,
1004 .sampleLocationCoordinateRange[1] = 0.9375f,
1005 .sampleLocationSubPixelBits = 4,
1006 .variableSampleLocations = false,
1007
1008 /* VK_EXT_shader_object */
1009 .shaderBinaryVersion = 0,
1010
1011 /* VK_EXT_transform_feedback */
1012 .maxTransformFeedbackStreams = 4,
1013 .maxTransformFeedbackBuffers = 4,
1014 .maxTransformFeedbackBufferSize = UINT32_MAX,
1015 .maxTransformFeedbackStreamDataSize = 2048,
1016 .maxTransformFeedbackBufferDataSize = 512,
1017 .maxTransformFeedbackBufferDataStride = 2048,
1018 .transformFeedbackQueries = true,
1019 .transformFeedbackStreamsLinesTriangles = true,
1020 .transformFeedbackRasterizationStreamSelect = true,
1021 .transformFeedbackDraw = false,
1022
1023 /* VK_KHR_vertex_attribute_divisor */
1024 .maxVertexAttribDivisor = UINT32_MAX,
1025 .supportsNonZeroFirstInstance = true,
1026
1027 /* VK_KHR_fragment_shader_barycentric */
1028 .triStripVertexOrderIndependentOfProvokingVertex = false,
1029
1030 /* VK_EXT_blend_operation_advanced */
1031 .advancedBlendMaxColorAttachments = HK_MAX_RTS,
1032 .advancedBlendIndependentBlend = true,
1033 .advancedBlendNonPremultipliedSrcColor = true,
1034 .advancedBlendNonPremultipliedDstColor = true,
1035 .advancedBlendCorrelatedOverlap = true,
1036 .advancedBlendAllOperations = true,
1037 };
1038
1039 strncpy(properties->deviceName, dev->name, sizeof(properties->deviceName));
1040
1041 /* VK_EXT_shader_module_identifier */
1042 static_assert(sizeof(vk_shaderModuleIdentifierAlgorithmUUID) ==
1043 sizeof(properties->shaderModuleIdentifierAlgorithmUUID));
1044 memcpy(properties->shaderModuleIdentifierAlgorithmUUID,
1045 vk_shaderModuleIdentifierAlgorithmUUID,
1046 sizeof(properties->shaderModuleIdentifierAlgorithmUUID));
1047
1048 uint8_t dev_uuid[VK_UUID_SIZE];
1049 agx_get_device_uuid(dev, &dev_uuid);
1050 static_assert(sizeof(dev_uuid) == VK_UUID_SIZE);
1051 memcpy(properties->deviceUUID, &dev_uuid, VK_UUID_SIZE);
1052 static_assert(sizeof(instance->driver_build_sha) >= VK_UUID_SIZE);
1053 memcpy(properties->driverUUID, instance->driver_build_sha, VK_UUID_SIZE);
1054
1055 strncpy(properties->driverName, "Honeykrisp", VK_MAX_DRIVER_NAME_SIZE);
1056 snprintf(properties->driverInfo, VK_MAX_DRIVER_INFO_SIZE,
1057 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1);
1058
1059 /* We don't use the layouts ATM so just report all layouts from
1060 * extensions that we support as compatible.
1061 */
1062 static const VkImageLayout supported_layouts[] = {
1063 VK_IMAGE_LAYOUT_GENERAL, /* required by spec */
1064 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1065 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1066 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
1067 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1068 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1069 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1070 VK_IMAGE_LAYOUT_PREINITIALIZED,
1071 VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL,
1072 VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL,
1073 VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
1074 VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL,
1075 VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL,
1076 VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL,
1077 VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL,
1078 VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL,
1079 // VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT,
1080 VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT,
1081 };
1082
1083 properties->pCopySrcLayouts = (VkImageLayout *)supported_layouts;
1084 properties->copySrcLayoutCount = ARRAY_SIZE(supported_layouts);
1085 properties->pCopyDstLayouts = (VkImageLayout *)supported_layouts;
1086 properties->copyDstLayoutCount = ARRAY_SIZE(supported_layouts);
1087
1088 /* We're a UMR so we can always map every kind of memory */
1089 properties->identicalMemoryTypeRequirements = true;
1090
1091 {
1092 blake3_hasher blake3_ctx;
1093 uint8_t blake3[BLAKE3_KEY_LEN];
1094
1095 _mesa_blake3_init(&blake3_ctx);
1096 /* Make sure we don't match with other vendors */
1097 const char *driver = "honeykrisp-v1";
1098 _mesa_blake3_update(&blake3_ctx, driver, strlen(driver));
1099 _mesa_blake3_final(&blake3_ctx, blake3);
1100
1101 memcpy(properties->optimalTilingLayoutUUID, blake3, VK_UUID_SIZE);
1102 }
1103 }
1104
1105 static void
1106 hk_physical_device_init_pipeline_cache(struct hk_physical_device *pdev)
1107 {
1108 struct hk_instance *instance = hk_physical_device_instance(pdev);
1109
1110 blake3_hasher blake3_ctx;
1111 _mesa_blake3_init(&blake3_ctx);
1112
1113 _mesa_blake3_update(&blake3_ctx, instance->driver_build_sha,
1114 sizeof(instance->driver_build_sha));
1115
1116 const uint64_t compiler_flags = hk_physical_device_compiler_flags(pdev);
1117 _mesa_blake3_update(&blake3_ctx, &compiler_flags, sizeof(compiler_flags));
1118
1119 unsigned char blake3[BLAKE3_KEY_LEN];
1120 _mesa_blake3_final(&blake3_ctx, blake3);
1121
1122 static_assert(BLAKE3_KEY_LEN >= VK_UUID_SIZE);
1123 memcpy(pdev->vk.properties.pipelineCacheUUID, blake3, VK_UUID_SIZE);
1124 memcpy(pdev->vk.properties.shaderBinaryUUID, blake3, VK_UUID_SIZE);
1125
1126 #ifdef ENABLE_SHADER_CACHE
1127 char renderer[10];
1128 ASSERTED int len =
1129 snprintf(renderer, sizeof(renderer), "HK_G%u%c_",
1130 pdev->dev.params.gpu_generation, pdev->dev.params.gpu_variant);
1131
1132 assert(len == sizeof(renderer) - 2);
1133
1134 char timestamp[BLAKE3_HEX_LEN];
1135 _mesa_blake3_format(timestamp, instance->driver_build_sha);
1136
1137 const uint64_t driver_flags = hk_physical_device_compiler_flags(pdev);
1138 pdev->vk.disk_cache = disk_cache_create(renderer, timestamp, driver_flags);
1139 if (pdev->vk.disk_cache != NULL) {
1140 pdev->vk.properties.pipelineBinaryInternalCache = true;
1141 pdev->vk.properties.pipelineBinaryInternalCacheControl = true;
1142 pdev->vk.properties.pipelineBinaryPrefersInternalCache = true;
1143 pdev->vk.properties.pipelineBinaryPrecompiledInternalCache = true;
1144 }
1145 #endif
1146 }
1147
1148 static void
1149 hk_physical_device_free_disk_cache(struct hk_physical_device *pdev)
1150 {
1151 #ifdef ENABLE_SHADER_CACHE
1152 if (pdev->vk.disk_cache) {
1153 disk_cache_destroy(pdev->vk.disk_cache);
1154 pdev->vk.disk_cache = NULL;
1155 }
1156 #else
1157 assert(pdev->vk.disk_cache == NULL);
1158 #endif
1159 }
1160
1161 /* Use 1/2 of total size to avoid swapping */
1162 #define SYSMEM_HEAP_FRACTION(x) (x * 1 / 2)
1163
1164 static uint64_t
1165 hk_get_sysmem_heap_size(struct hk_physical_device *pdev)
1166 {
1167 if (pdev->sysmem)
1168 return pdev->sysmem;
1169
1170 uint64_t sysmem_size_B = 0;
1171 if (!os_get_total_physical_memory(&sysmem_size_B))
1172 return 0;
1173
1174 return ROUND_DOWN_TO(SYSMEM_HEAP_FRACTION(sysmem_size_B), 1 << 20);
1175 }
1176
1177 static uint64_t
1178 hk_get_sysmem_heap_available(struct hk_physical_device *pdev)
1179 {
1180 if (pdev->sysmem) {
1181 uint64_t total_used = 0;
1182 for (unsigned i = 0; i < pdev->mem_heap_count; i++) {
1183 const struct hk_memory_heap *heap = &pdev->mem_heaps[i];
1184 uint64_t used = p_atomic_read(&heap->used);
1185 total_used += used;
1186 }
1187 return pdev->sysmem - total_used;
1188 }
1189
1190 uint64_t sysmem_size_B = 0;
1191 if (!os_get_available_system_memory(&sysmem_size_B)) {
1192 vk_loge(VK_LOG_OBJS(pdev), "Failed to query available system memory");
1193 return 0;
1194 }
1195
1196 return ROUND_DOWN_TO(SYSMEM_HEAP_FRACTION(sysmem_size_B), 1 << 20);
1197 }
1198
1199 VkResult
1200 hk_create_drm_physical_device(struct vk_instance *_instance,
1201 drmDevicePtr drm_device,
1202 struct vk_physical_device **pdev_out)
1203 {
1204 struct hk_instance *instance = (struct hk_instance *)_instance;
1205 VkResult result;
1206
1207 if (!(drm_device->available_nodes & (1 << DRM_NODE_RENDER)) ||
1208 drm_device->bustype != DRM_BUS_PLATFORM)
1209 return VK_ERROR_INCOMPATIBLE_DRIVER;
1210
1211 const char *path = drm_device->nodes[DRM_NODE_RENDER];
1212 int fd = open(path, O_RDWR | O_CLOEXEC);
1213 if (fd < 0) {
1214 return vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
1215 "failed to open device %s", path);
1216 }
1217
1218 drmVersionPtr version = drmGetVersion(fd);
1219 if (!version) {
1220 result =
1221 vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
1222 "failed to query kernel driver version for device %s", path);
1223 goto fail_fd;
1224 }
1225
1226 bool is_asahi = (strcmp(version->name, "asahi") == 0);
1227 is_asahi |= strcmp(version->name, "virtio_gpu") == 0;
1228 drmFreeVersion(version);
1229
1230 if (!is_asahi) {
1231 /* Fail silently */
1232 result = VK_ERROR_INCOMPATIBLE_DRIVER;
1233 goto fail_fd;
1234 }
1235
1236 struct stat st;
1237 if (stat(drm_device->nodes[DRM_NODE_RENDER], &st)) {
1238 result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
1239 "fstat() failed on %s: %m",
1240 drm_device->nodes[DRM_NODE_RENDER]);
1241 goto fail_fd;
1242 }
1243 const dev_t render_dev = st.st_rdev;
1244
1245 struct hk_physical_device *pdev =
1246 vk_zalloc(&instance->vk.alloc, sizeof(*pdev), 8,
1247 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
1248
1249 if (pdev == NULL) {
1250 result = vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
1251 goto fail_fd;
1252 }
1253
1254 /* We're render-only */
1255 pdev->master_fd = -1;
1256 pdev->render_dev = render_dev;
1257 pdev->dev.fd = fd;
1258
1259 if (!agx_open_device(NULL, &pdev->dev)) {
1260 /* Fail silently, for virtgpu */
1261 result = VK_ERROR_INCOMPATIBLE_DRIVER;
1262 goto fail_pdev_alloc;
1263 }
1264
1265 struct vk_physical_device_dispatch_table dispatch_table;
1266 vk_physical_device_dispatch_table_from_entrypoints(
1267 &dispatch_table, &hk_physical_device_entrypoints, true);
1268 vk_physical_device_dispatch_table_from_entrypoints(
1269 &dispatch_table, &wsi_physical_device_entrypoints, false);
1270
1271 struct vk_device_extension_table supported_extensions;
1272 hk_get_device_extensions(instance, &supported_extensions);
1273
1274 struct vk_features supported_features;
1275 hk_get_device_features(&pdev->dev, instance, &supported_extensions,
1276 &supported_features);
1277
1278 struct vk_properties properties;
1279 hk_get_device_properties(&pdev->dev, instance, &properties);
1280
1281 properties.drmHasRender = true;
1282 properties.drmRenderMajor = major(render_dev);
1283 properties.drmRenderMinor = minor(render_dev);
1284
1285 result = vk_physical_device_init(&pdev->vk, &instance->vk,
1286 &supported_extensions, &supported_features,
1287 &properties, &dispatch_table);
1288 if (result != VK_SUCCESS)
1289 goto fail_agx_device;
1290
1291 hk_physical_device_init_pipeline_cache(pdev);
1292
1293 const char *hk_sysmem = os_get_option("HK_SYSMEM");
1294 if (hk_sysmem) {
1295 uint64_t sysmem = strtoll(hk_sysmem, NULL, 10);
1296 if (sysmem != LLONG_MIN && sysmem != LLONG_MAX) {
1297 pdev->sysmem = sysmem;
1298 }
1299 }
1300
1301 uint64_t sysmem_size_B = hk_get_sysmem_heap_size(pdev);
1302 if (sysmem_size_B == 0) {
1303 result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
1304 "Failed to query total system memory");
1305 goto fail_disk_cache;
1306 }
1307
1308 uint32_t sysmem_heap_idx = pdev->mem_heap_count++;
1309 pdev->mem_heaps[sysmem_heap_idx] = (struct hk_memory_heap){
1310 .size = sysmem_size_B,
1311 .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
1312 .available = hk_get_sysmem_heap_available,
1313 };
1314
1315 pdev->mem_types[pdev->mem_type_count++] = (VkMemoryType){
1316 .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
1317 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
1318 VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
1319 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
1320 .heapIndex = sysmem_heap_idx,
1321 };
1322
1323 pdev->mem_types[pdev->mem_type_count++] = (VkMemoryType){
1324 .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
1325 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
1326 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
1327 .heapIndex = sysmem_heap_idx,
1328 };
1329
1330 assert(pdev->mem_heap_count <= ARRAY_SIZE(pdev->mem_heaps));
1331 assert(pdev->mem_type_count <= ARRAY_SIZE(pdev->mem_types));
1332
1333 pdev->queue_families[pdev->queue_family_count++] = (struct hk_queue_family){
1334 .queue_flags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT |
1335 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_SPARSE_BINDING_BIT,
1336
1337 .queue_count = 1,
1338 };
1339 assert(pdev->queue_family_count <= ARRAY_SIZE(pdev->queue_families));
1340
1341 unsigned st_idx = 0;
1342 pdev->syncobj_sync_type = vk_drm_syncobj_get_type(fd);
1343 pdev->sync_types[st_idx++] = &pdev->syncobj_sync_type;
1344 pdev->sync_types[st_idx++] = NULL;
1345 assert(st_idx <= ARRAY_SIZE(pdev->sync_types));
1346 pdev->vk.supported_sync_types = pdev->sync_types;
1347
1348 result = hk_init_wsi(pdev);
1349 if (result != VK_SUCCESS)
1350 goto fail_disk_cache;
1351
1352 simple_mtx_init(&pdev->debug_compile_lock, mtx_plain);
1353 *pdev_out = &pdev->vk;
1354
1355 return VK_SUCCESS;
1356
1357 fail_disk_cache:
1358 hk_physical_device_free_disk_cache(pdev);
1359 vk_physical_device_finish(&pdev->vk);
1360 fail_agx_device:
1361 agx_close_device(&pdev->dev);
1362 fail_pdev_alloc:
1363 if (pdev->master_fd)
1364 close(pdev->master_fd);
1365
1366 vk_free(&instance->vk.alloc, pdev);
1367 fail_fd:
1368 close(fd);
1369 return result;
1370 }
1371
1372 void
1373 hk_physical_device_destroy(struct vk_physical_device *vk_pdev)
1374 {
1375 struct hk_physical_device *pdev =
1376 container_of(vk_pdev, struct hk_physical_device, vk);
1377
1378 hk_finish_wsi(pdev);
1379
1380 if (pdev->master_fd >= 0)
1381 close(pdev->master_fd);
1382
1383 simple_mtx_destroy(&pdev->debug_compile_lock);
1384 hk_physical_device_free_disk_cache(pdev);
1385 agx_close_device(&pdev->dev);
1386 vk_physical_device_finish(&pdev->vk);
1387 vk_free(&pdev->vk.instance->alloc, pdev);
1388 }
1389
1390 VKAPI_ATTR void VKAPI_CALL
1391 hk_GetPhysicalDeviceMemoryProperties2(
1392 VkPhysicalDevice physicalDevice,
1393 VkPhysicalDeviceMemoryProperties2 *pMemoryProperties)
1394 {
1395 VK_FROM_HANDLE(hk_physical_device, pdev, physicalDevice);
1396
1397 pMemoryProperties->memoryProperties.memoryHeapCount = pdev->mem_heap_count;
1398 for (int i = 0; i < pdev->mem_heap_count; i++) {
1399 pMemoryProperties->memoryProperties.memoryHeaps[i] = (VkMemoryHeap){
1400 .size = pdev->mem_heaps[i].size,
1401 .flags = pdev->mem_heaps[i].flags,
1402 };
1403 }
1404
1405 pMemoryProperties->memoryProperties.memoryTypeCount = pdev->mem_type_count;
1406 for (int i = 0; i < pdev->mem_type_count; i++) {
1407 pMemoryProperties->memoryProperties.memoryTypes[i] = pdev->mem_types[i];
1408 }
1409
1410 vk_foreach_struct(ext, pMemoryProperties->pNext) {
1411 switch (ext->sType) {
1412 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT: {
1413 VkPhysicalDeviceMemoryBudgetPropertiesEXT *p = (void *)ext;
1414
1415 for (unsigned i = 0; i < pdev->mem_heap_count; i++) {
1416 const struct hk_memory_heap *heap = &pdev->mem_heaps[i];
1417 uint64_t used = p_atomic_read(&heap->used);
1418
1419 /* From the Vulkan 1.3.278 spec:
1420 *
1421 * "heapUsage is an array of VK_MAX_MEMORY_HEAPS VkDeviceSize
1422 * values in which memory usages are returned, with one element
1423 * for each memory heap. A heap’s usage is an estimate of how
1424 * much memory the process is currently using in that heap."
1425 *
1426 * TODO: Include internal allocations?
1427 */
1428 p->heapUsage[i] = used;
1429
1430 uint64_t available = heap->size;
1431 if (heap->available)
1432 available = heap->available(pdev);
1433
1434 /* From the Vulkan 1.3.278 spec:
1435 *
1436 * "heapBudget is an array of VK_MAX_MEMORY_HEAPS VkDeviceSize
1437 * values in which memory budgets are returned, with one
1438 * element for each memory heap. A heap’s budget is a rough
1439 * estimate of how much memory the process can allocate from
1440 * that heap before allocations may fail or cause performance
1441 * degradation. The budget includes any currently allocated
1442 * device memory."
1443 *
1444 * and
1445 *
1446 * "The heapBudget value must be less than or equal to
1447 * VkMemoryHeap::size for each heap."
1448 *
1449 * available (queried above) is the total amount free memory
1450 * system-wide and does not include our allocations so we need
1451 * to add that in.
1452 */
1453 uint64_t budget = MIN2(available + used, heap->size);
1454
1455 /* Set the budget at 90% of available to avoid thrashing */
1456 p->heapBudget[i] = ROUND_DOWN_TO(budget * 9 / 10, 1 << 20);
1457 }
1458
1459 /* From the Vulkan 1.3.278 spec:
1460 *
1461 * "The heapBudget and heapUsage values must be zero for array
1462 * elements greater than or equal to
1463 * VkPhysicalDeviceMemoryProperties::memoryHeapCount. The
1464 * heapBudget value must be non-zero for array elements less than
1465 * VkPhysicalDeviceMemoryProperties::memoryHeapCount."
1466 */
1467 for (unsigned i = pdev->mem_heap_count; i < VK_MAX_MEMORY_HEAPS; i++) {
1468 p->heapBudget[i] = 0u;
1469 p->heapUsage[i] = 0u;
1470 }
1471 break;
1472 }
1473 default:
1474 vk_debug_ignored_stype(ext->sType);
1475 break;
1476 }
1477 }
1478 }
1479
1480 static const VkQueueGlobalPriorityKHR hk_global_queue_priorities[] = {
1481 VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR,
1482 VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR,
1483 VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR,
1484 VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR,
1485 };
1486
1487 VKAPI_ATTR void VKAPI_CALL
1488 hk_GetPhysicalDeviceQueueFamilyProperties2(
1489 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount,
1490 VkQueueFamilyProperties2 *pQueueFamilyProperties)
1491 {
1492 VK_FROM_HANDLE(hk_physical_device, pdev, physicalDevice);
1493 VK_OUTARRAY_MAKE_TYPED(VkQueueFamilyProperties2, out, pQueueFamilyProperties,
1494 pQueueFamilyPropertyCount);
1495
1496 for (uint8_t i = 0; i < pdev->queue_family_count; i++) {
1497 const struct hk_queue_family *queue_family = &pdev->queue_families[i];
1498
1499 vk_outarray_append_typed(VkQueueFamilyProperties2, &out, p)
1500 {
1501 p->queueFamilyProperties.queueFlags = queue_family->queue_flags;
1502 p->queueFamilyProperties.queueCount = queue_family->queue_count;
1503 p->queueFamilyProperties.timestampValidBits = 64;
1504 p->queueFamilyProperties.minImageTransferGranularity =
1505 (VkExtent3D){1, 1, 1};
1506
1507 VkQueueFamilyGlobalPriorityPropertiesKHR *prio = vk_find_struct(
1508 p->pNext, QUEUE_FAMILY_GLOBAL_PRIORITY_PROPERTIES_KHR);
1509 if (prio) {
1510 STATIC_ASSERT(ARRAY_SIZE(hk_global_queue_priorities) <=
1511 VK_MAX_GLOBAL_PRIORITY_SIZE_KHR);
1512 prio->priorityCount = ARRAY_SIZE(hk_global_queue_priorities);
1513 memcpy(&prio->priorities, hk_global_queue_priorities,
1514 sizeof(hk_global_queue_priorities));
1515 }
1516 }
1517 }
1518 }
1519
1520 VKAPI_ATTR void VKAPI_CALL
1521 hk_GetPhysicalDeviceMultisamplePropertiesEXT(
1522 VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples,
1523 VkMultisamplePropertiesEXT *pMultisampleProperties)
1524 {
1525 VK_FROM_HANDLE(hk_physical_device, pdev, physicalDevice);
1526
1527 if (samples & pdev->vk.properties.sampleLocationSampleCounts) {
1528 pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){1, 1};
1529 } else {
1530 pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){0, 0};
1531 }
1532 }