| 1 |
|
| 2 |
. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "kk_physical_device.h" |
| 9 |
|
| 10 |
#include "kk_entrypoints.h" |
| 11 |
#include "kk_image.h" |
| 12 |
#include "kk_instance.h" |
| 13 |
#include "kk_nir_lower_vbo.h" |
| 14 |
#include "kk_sync.h" |
| 15 |
#include "kk_wsi.h" |
| 16 |
|
| 17 |
#include "kosmickrisp/bridge/mtl_bridge.h" |
| 18 |
|
| 19 |
#include "util/disk_cache.h" |
| 20 |
#include "util/mesa-blake3.h" |
| 21 |
#include "git_sha1.h" |
| 22 |
|
| 23 |
#include "vulkan/wsi/wsi_common.h" |
| 24 |
#include "vk_device.h" |
| 25 |
#include "vk_drm_syncobj.h" |
| 26 |
#include "vk_shader_module.h" |
| 27 |
|
| 28 |
static uint32_t |
| 29 |
kk_get_vk_version() |
| 30 |
{ |
| 31 |
|
| 32 |
const uint32_t version_override = vk_get_version_override(); |
| 33 |
if (version_override) |
| 34 |
return version_override; |
| 35 |
|
| 36 |
return VK_MAKE_VERSION(1, 3, VK_HEADER_VERSION); |
| 37 |
} |
| 38 |
|
| 39 |
static void |
| 40 |
kk_get_device_extensions(const struct kk_instance *instance, |
| 41 |
struct vk_device_extension_table *ext) |
| 42 |
{ |
| 43 |
*ext = (struct vk_device_extension_table){ |
| 44 |
|
| 45 |
.KHR_16bit_storage = true, |
| 46 |
.KHR_bind_memory2 = true, |
| 47 |
.KHR_dedicated_allocation = true, |
| 48 |
.KHR_descriptor_update_template = true, |
| 49 |
.KHR_device_group = true, |
| 50 |
.KHR_external_fence = true, |
| 51 |
.KHR_external_memory = true, |
| 52 |
.KHR_external_semaphore = true, |
| 53 |
.KHR_get_memory_requirements2 = true, |
| 54 |
.KHR_maintenance1 = true, |
| 55 |
.KHR_maintenance2 = true, |
| 56 |
.KHR_maintenance3 = true, |
| 57 |
.KHR_multiview = true, |
| 58 |
.KHR_relaxed_block_layout = true, |
| 59 |
.KHR_sampler_ycbcr_conversion = true, |
| 60 |
.KHR_shader_draw_parameters = true, |
| 61 |
.KHR_storage_buffer_storage_class = true, |
| 62 |
.KHR_variable_pointers = true, |
| 63 |
|
| 64 |
|
| 65 |
.KHR_8bit_storage = true, |
| 66 |
.KHR_buffer_device_address = true, |
| 67 |
.KHR_create_renderpass2 = true, |
| 68 |
.KHR_depth_stencil_resolve = true, |
| 69 |
.KHR_draw_indirect_count = true, |
| 70 |
.KHR_driver_properties = true, |
| 71 |
.KHR_image_format_list = true, |
| 72 |
.KHR_imageless_framebuffer = true, |
| 73 |
.KHR_sampler_mirror_clamp_to_edge = true, |
| 74 |
.KHR_separate_depth_stencil_layouts = true, |
| 75 |
.KHR_shader_atomic_int64 = false, |
| 76 |
.KHR_shader_float_controls = true, |
| 77 |
.KHR_shader_float16_int8 = true, |
| 78 |
.KHR_shader_subgroup_extended_types = true, |
| 79 |
.KHR_spirv_1_4 = true, |
| 80 |
.KHR_timeline_semaphore = true, |
| 81 |
.KHR_uniform_buffer_standard_layout = true, |
| 82 |
.KHR_vulkan_memory_model = true, |
| 83 |
.EXT_descriptor_indexing = true, |
| 84 |
.EXT_host_query_reset = true, |
| 85 |
.EXT_sampler_filter_minmax = false, |
| 86 |
.EXT_scalar_block_layout = true, |
| 87 |
.EXT_separate_stencil_usage = true, |
| 88 |
.EXT_shader_viewport_index_layer = true, |
| 89 |
|
| 90 |
|
| 91 |
.KHR_copy_commands2 = true, |
| 92 |
.KHR_dynamic_rendering = true, |
| 93 |
.KHR_format_feature_flags2 = true, |
| 94 |
.KHR_maintenance4 = true, |
| 95 |
.KHR_shader_integer_dot_product = true, |
| 96 |
.KHR_shader_non_semantic_info = true, |
| 97 |
.KHR_shader_terminate_invocation = true, |
| 98 |
.KHR_synchronization2 = true, |
| 99 |
.KHR_zero_initialize_workgroup_memory = true, |
| 100 |
.EXT_4444_formats = true, |
| 101 |
.EXT_extended_dynamic_state = true, |
| 102 |
.EXT_extended_dynamic_state2 = true, |
| 103 |
.EXT_image_robustness = true, |
| 104 |
.EXT_inline_uniform_block = true, |
| 105 |
.EXT_pipeline_creation_cache_control = true, |
| 106 |
.EXT_pipeline_creation_feedback = true, |
| 107 |
.EXT_private_data = true, |
| 108 |
.EXT_shader_demote_to_helper_invocation = true, |
| 109 |
.EXT_shader_stencil_export = true, |
| 110 |
.EXT_subgroup_size_control = true, |
| 111 |
.EXT_texel_buffer_alignment = true, |
| 112 |
.EXT_texture_compression_astc_hdr = true, |
| 113 |
.EXT_tooling_info = true, |
| 114 |
.EXT_ycbcr_2plane_444_formats = true, |
| 115 |
|
| 116 |
|
| 117 |
.KHR_load_store_op_none = true, |
| 118 |
.KHR_map_memory2 = true, |
| 119 |
.KHR_push_descriptor = true, |
| 120 |
.KHR_shader_expect_assume = true, |
| 121 |
.KHR_vertex_attribute_divisor = true, |
| 122 |
.EXT_vertex_attribute_divisor = true, |
| 123 |
|
| 124 |
|
| 125 |
.KHR_calibrated_timestamps = true, |
| 126 |
|
| 127 |
|
| 128 |
.KHR_shader_maximal_reconvergence = false, |
| 129 |
.KHR_shader_relaxed_extended_instruction = true, |
| 130 |
.KHR_shader_subgroup_uniform_control_flow = true, |
| 131 |
#ifdef KK_USE_WSI_PLATFORM |
| 132 |
.KHR_swapchain = true, |
| 133 |
.KHR_swapchain_mutable_format = true, |
| 134 |
#endif |
| 135 |
.KHR_workgroup_memory_explicit_layout = true, |
| 136 |
|
| 137 |
.EXT_calibrated_timestamps = true, |
| 138 |
.EXT_external_memory_metal = true, |
| 139 |
.EXT_image_2d_view_of_3d = true, |
| 140 |
.EXT_load_store_op_none = true, |
| 141 |
.EXT_mutable_descriptor_type = true, |
| 142 |
.EXT_shader_atomic_float = true, |
| 143 |
.EXT_shader_replicated_composites = true, |
| 144 |
|
| 145 |
.GOOGLE_decorate_string = true, |
| 146 |
.GOOGLE_hlsl_functionality1 = true, |
| 147 |
.GOOGLE_user_type = true, |
| 148 |
.KHR_external_fence_fd = true, |
| 149 |
.KHR_external_semaphore_fd = true, |
| 150 |
}; |
| 151 |
} |
| 152 |
|
| 153 |
static void |
| 154 |
kk_get_device_features( |
| 155 |
const struct vk_device_extension_table *supported_extensions, |
| 156 |
struct vk_features *features) |
| 157 |
{ |
| 158 |
*features = (struct vk_features){ |
| 159 |
|
| 160 |
.alphaToOne = true, |
| 161 |
.depthBiasClamp = true, |
| 162 |
.depthClamp = true, |
| 163 |
.drawIndirectFirstInstance = true, |
| 164 |
.dualSrcBlend = true, |
| 165 |
.fragmentStoresAndAtomics = true, |
| 166 |
.fullDrawIndexUint32 = true, |
| 167 |
.imageCubeArray = true, |
| 168 |
.independentBlend = true, |
| 169 |
.inheritedQueries = true, |
| 170 |
.largePoints = true, |
| 171 |
.logicOp = true, |
| 172 |
.multiViewport = true, |
| 173 |
.occlusionQueryPrecise = true, |
| 174 |
.robustBufferAccess = true, |
| 175 |
.samplerAnisotropy = true, |
| 176 |
.sampleRateShading = true, |
| 177 |
.shaderClipDistance = true, |
| 178 |
.shaderImageGatherExtended = true, |
| 179 |
.shaderInt16 = true, |
| 180 |
.shaderInt64 = true, |
| 181 |
.shaderResourceMinLod = true, |
| 182 |
.shaderSampledImageArrayDynamicIndexing = true, |
| 183 |
.shaderStorageBufferArrayDynamicIndexing = true, |
| 184 |
.shaderStorageImageArrayDynamicIndexing = true, |
| 185 |
.shaderStorageImageExtendedFormats = true, |
| 186 |
.shaderStorageImageReadWithoutFormat = true, |
| 187 |
.shaderStorageImageWriteWithoutFormat = true, |
| 188 |
.shaderUniformBufferArrayDynamicIndexing = true, |
| 189 |
.textureCompressionASTC_LDR = true, |
| 190 |
.textureCompressionBC = true, |
| 191 |
.textureCompressionETC2 = true, |
| 192 |
.vertexPipelineStoresAndAtomics = true, |
| 193 |
|
| 194 |
|
| 195 |
.multiview = true, |
| 196 |
.samplerYcbcrConversion = true, |
| 197 |
.shaderDrawParameters = true, |
| 198 |
.storageBuffer16BitAccess = true, |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
.storageInputOutput16 = false, |
| 204 |
.storagePushConstant16 = true, |
| 205 |
.uniformAndStorageBuffer16BitAccess = true, |
| 206 |
.variablePointers = true, |
| 207 |
.variablePointersStorageBuffer = true, |
| 208 |
|
| 209 |
|
| 210 |
.descriptorBindingInlineUniformBlockUpdateAfterBind = true, |
| 211 |
.descriptorBindingPartiallyBound = true, |
| 212 |
.descriptorBindingSampledImageUpdateAfterBind = true, |
| 213 |
.descriptorBindingStorageBufferUpdateAfterBind = true, |
| 214 |
.descriptorBindingStorageImageUpdateAfterBind = true, |
| 215 |
.descriptorBindingStorageTexelBufferUpdateAfterBind = true, |
| 216 |
.descriptorBindingUniformBufferUpdateAfterBind = true, |
| 217 |
.descriptorBindingUniformTexelBufferUpdateAfterBind = true, |
| 218 |
.descriptorBindingUpdateUnusedWhilePending = true, |
| 219 |
.descriptorBindingVariableDescriptorCount = true, |
| 220 |
.descriptorIndexing = true, |
| 221 |
.drawIndirectCount = true, |
| 222 |
.hostQueryReset = true, |
| 223 |
.imagelessFramebuffer = true, |
| 224 |
.multiDrawIndirect = true, |
| 225 |
.runtimeDescriptorArray = true, |
| 226 |
.samplerMirrorClampToEdge = true, |
| 227 |
.scalarBlockLayout = true, |
| 228 |
.separateDepthStencilLayouts = true, |
| 229 |
.shaderFloat16 = true, |
| 230 |
.shaderInputAttachmentArrayDynamicIndexing = true, |
| 231 |
.shaderInputAttachmentArrayNonUniformIndexing = true, |
| 232 |
.shaderInt8 = true, |
| 233 |
.shaderOutputLayer = true, |
| 234 |
.shaderOutputViewportIndex = true, |
| 235 |
.shaderSampledImageArrayNonUniformIndexing = true, |
| 236 |
.shaderStorageBufferArrayNonUniformIndexing = true, |
| 237 |
.shaderStorageImageArrayNonUniformIndexing = true, |
| 238 |
.shaderStorageTexelBufferArrayDynamicIndexing = true, |
| 239 |
.shaderStorageTexelBufferArrayNonUniformIndexing = true, |
| 240 |
.shaderSubgroupExtendedTypes = true, |
| 241 |
.shaderUniformBufferArrayNonUniformIndexing = true, |
| 242 |
.shaderUniformTexelBufferArrayDynamicIndexing = true, |
| 243 |
.shaderUniformTexelBufferArrayNonUniformIndexing = true, |
| 244 |
.storageBuffer8BitAccess = true, |
| 245 |
.storagePushConstant8 = true, |
| 246 |
.subgroupBroadcastDynamicId = true, |
| 247 |
.timelineSemaphore = true, |
| 248 |
.uniformAndStorageBuffer8BitAccess = true, |
| 249 |
.uniformBufferStandardLayout = true, |
| 250 |
|
| 251 |
|
| 252 |
.bufferDeviceAddress = true, |
| 253 |
.computeFullSubgroups = true, |
| 254 |
.dynamicRendering = true, |
| 255 |
.extendedDynamicState = true, |
| 256 |
.extendedDynamicState2 = true, |
| 257 |
.extendedDynamicState2LogicOp = false, |
| 258 |
.extendedDynamicState2PatchControlPoints = false, |
| 259 |
.inlineUniformBlock = true, |
| 260 |
.maintenance4 = true, |
| 261 |
.pipelineCreationCacheControl = true, |
| 262 |
.privateData = true, |
| 263 |
.robustImageAccess = true, |
| 264 |
.shaderDemoteToHelperInvocation = true, |
| 265 |
.shaderIntegerDotProduct = true, |
| 266 |
.shaderTerminateInvocation = true, |
| 267 |
.shaderZeroInitializeWorkgroupMemory = true, |
| 268 |
.subgroupSizeControl = true, |
| 269 |
.synchronization2 = true, |
| 270 |
.texelBufferAlignment = true, |
| 271 |
.textureCompressionASTC_HDR = true, |
| 272 |
.vulkanMemoryModel = true, |
| 273 |
.vulkanMemoryModelDeviceScope = true, |
| 274 |
|
| 275 |
|
| 276 |
.pushDescriptor = true, |
| 277 |
.vertexAttributeInstanceRateDivisor = true, |
| 278 |
.vertexAttributeInstanceRateZeroDivisor = true, |
| 279 |
|
| 280 |
|
| 281 |
.mutableDescriptorType = true, |
| 282 |
|
| 283 |
|
| 284 |
.shaderExpectAssume = true, |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
.shaderMaximalReconvergence = false, |
| 290 |
|
| 291 |
|
| 292 |
.shaderRelaxedExtendedInstruction = true, |
| 293 |
|
| 294 |
|
| 295 |
.workgroupMemoryExplicitLayout = true, |
| 296 |
.workgroupMemoryExplicitLayoutScalarBlockLayout = true, |
| 297 |
.workgroupMemoryExplicitLayout8BitAccess = true, |
| 298 |
.workgroupMemoryExplicitLayout16BitAccess = true, |
| 299 |
|
| 300 |
|
| 301 |
.formatA4R4G4B4 = true, |
| 302 |
.formatA4B4G4R4 = true, |
| 303 |
|
| 304 |
|
| 305 |
.image2DViewOf3D = true, |
| 306 |
.sampler2DViewOf3D = true, |
| 307 |
|
| 308 |
|
| 309 |
.shaderReplicatedComposites = true, |
| 310 |
|
| 311 |
|
| 312 |
.shaderSubgroupUniformControlFlow = true, |
| 313 |
|
| 314 |
|
| 315 |
.shaderBufferFloat32Atomics = true, |
| 316 |
.shaderBufferFloat32AtomicAdd = true, |
| 317 |
.shaderSharedFloat32Atomics = true, |
| 318 |
|
| 319 |
|
| 320 |
.ycbcr2plane444Formats = true, |
| 321 |
}; |
| 322 |
} |
| 323 |
|
| 324 |
static void |
| 325 |
kk_get_device_properties(const struct kk_physical_device *pdev, |
| 326 |
const struct kk_instance *instance, |
| 327 |
struct vk_properties *properties) |
| 328 |
{ |
| 329 |
const VkSampleCountFlagBits sample_counts = |
| 330 |
VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | |
| 331 |
|
| 332 |
VK_SAMPLE_COUNT_4_BIT |
| 333 |
|
| 334 |
; |
| 335 |
|
| 336 |
assert(sample_counts <= (KK_MAX_SAMPLES << 1) - 1); |
| 337 |
|
| 338 |
uint64_t os_page_size = 4096; |
| 339 |
os_get_page_size(&os_page_size); |
| 340 |
|
| 341 |
*properties = (struct vk_properties){ |
| 342 |
.apiVersion = kk_get_vk_version(), |
| 343 |
.driverVersion = vk_get_driver_version(), |
| 344 |
.vendorID = |
| 345 |
instance->force_vk_vendor != 0 ? instance->force_vk_vendor : 0x106b, |
| 346 |
.deviceID = 100, |
| 347 |
.deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
.maxImageDimension1D = kk_image_max_dimension(VK_IMAGE_TYPE_2D), |
| 353 |
.maxImageDimension2D = kk_image_max_dimension(VK_IMAGE_TYPE_2D), |
| 354 |
.maxImageDimension3D = kk_image_max_dimension(VK_IMAGE_TYPE_3D), |
| 355 |
.maxImageDimensionCube = 16384, |
| 356 |
.maxImageArrayLayers = 2048, |
| 357 |
.maxTexelBufferElements = 16384 * 16384, |
| 358 |
.maxUniformBufferRange = 65536, |
| 359 |
.maxStorageBufferRange = UINT32_MAX, |
| 360 |
.maxPushConstantsSize = KK_MAX_PUSH_SIZE, |
| 361 |
.maxMemoryAllocationCount = 4096, |
| 362 |
.maxSamplerAllocationCount = 4000, |
| 363 |
.bufferImageGranularity = 16, |
| 364 |
.sparseAddressSpaceSize = KK_SPARSE_ADDR_SPACE_SIZE, |
| 365 |
.maxBoundDescriptorSets = KK_MAX_SETS, |
| 366 |
.maxPerStageDescriptorSamplers = KK_MAX_DESCRIPTORS, |
| 367 |
.maxPerStageDescriptorUniformBuffers = KK_MAX_DESCRIPTORS, |
| 368 |
.maxPerStageDescriptorStorageBuffers = KK_MAX_DESCRIPTORS, |
| 369 |
.maxPerStageDescriptorSampledImages = KK_MAX_DESCRIPTORS, |
| 370 |
.maxPerStageDescriptorStorageImages = KK_MAX_DESCRIPTORS, |
| 371 |
.maxPerStageDescriptorInputAttachments = KK_MAX_DESCRIPTORS, |
| 372 |
.maxPerStageResources = UINT32_MAX, |
| 373 |
.maxDescriptorSetSamplers = KK_MAX_DESCRIPTORS, |
| 374 |
.maxDescriptorSetUniformBuffers = KK_MAX_DESCRIPTORS, |
| 375 |
.maxDescriptorSetUniformBuffersDynamic = KK_MAX_DYNAMIC_BUFFERS / 2, |
| 376 |
.maxDescriptorSetStorageBuffers = KK_MAX_DESCRIPTORS, |
| 377 |
.maxDescriptorSetStorageBuffersDynamic = KK_MAX_DYNAMIC_BUFFERS / 2, |
| 378 |
.maxDescriptorSetSampledImages = KK_MAX_DESCRIPTORS, |
| 379 |
.maxDescriptorSetStorageImages = KK_MAX_DESCRIPTORS, |
| 380 |
.maxDescriptorSetInputAttachments = KK_MAX_DESCRIPTORS, |
| 381 |
.maxVertexInputAttributes = KK_MAX_ATTRIBS, |
| 382 |
.maxVertexInputBindings = KK_MAX_VBUFS, |
| 383 |
.maxVertexInputAttributeOffset = 2047, |
| 384 |
.maxVertexInputBindingStride = 2048, |
| 385 |
.maxVertexOutputComponents = 128, |
| 386 |
.maxTessellationGenerationLevel = 64, |
| 387 |
.maxTessellationPatchSize = 32, |
| 388 |
.maxTessellationControlPerVertexInputComponents = 128, |
| 389 |
.maxTessellationControlPerVertexOutputComponents = 128, |
| 390 |
.maxTessellationControlPerPatchOutputComponents = 120, |
| 391 |
.maxTessellationControlTotalOutputComponents = 4216, |
| 392 |
.maxTessellationEvaluationInputComponents = 128, |
| 393 |
.maxTessellationEvaluationOutputComponents = 128, |
| 394 |
.maxGeometryShaderInvocations = 32, |
| 395 |
.maxGeometryInputComponents = 128, |
| 396 |
.maxGeometryOutputComponents = 128, |
| 397 |
.maxGeometryOutputVertices = 1024, |
| 398 |
.maxGeometryTotalOutputComponents = 1024, |
| 399 |
.maxFragmentInputComponents = 128, |
| 400 |
.maxFragmentOutputAttachments = KK_MAX_RTS, |
| 401 |
.maxFragmentDualSrcAttachments = 1, |
| 402 |
.maxFragmentCombinedOutputResources = 16, |
| 403 |
.maxComputeSharedMemorySize = KK_MAX_SHARED_SIZE, |
| 404 |
.maxComputeWorkGroupCount = {0x7fffffff, 65535, 65535}, |
| 405 |
.maxComputeWorkGroupInvocations = pdev->info.max_workgroup_invocations, |
| 406 |
.maxComputeWorkGroupSize = {pdev->info.max_workgroup_count[0], |
| 407 |
pdev->info.max_workgroup_count[1], |
| 408 |
pdev->info.max_workgroup_count[2]}, |
| 409 |
.subPixelPrecisionBits = 8, |
| 410 |
.subTexelPrecisionBits = 8, |
| 411 |
.mipmapPrecisionBits = 8, |
| 412 |
.maxDrawIndexedIndexValue = UINT32_MAX, |
| 413 |
.maxDrawIndirectCount = UINT16_MAX, |
| 414 |
.maxSamplerLodBias = 15, |
| 415 |
.maxSamplerAnisotropy = 16, |
| 416 |
.maxViewports = KK_MAX_VIEWPORTS, |
| 417 |
.maxViewportDimensions = {32768, 32768}, |
| 418 |
.viewportBoundsRange = {-65536, 65536}, |
| 419 |
.viewportSubPixelBits = 8, |
| 420 |
.minMemoryMapAlignment = os_page_size, |
| 421 |
.minTexelBufferOffsetAlignment = KK_MIN_TEXEL_BUFFER_ALIGNMENT, |
| 422 |
.minUniformBufferOffsetAlignment = KK_MIN_UBO_ALIGNMENT, |
| 423 |
.minStorageBufferOffsetAlignment = KK_MIN_SSBO_ALIGNMENT, |
| 424 |
.minTexelOffset = -8, |
| 425 |
.maxTexelOffset = 7, |
| 426 |
.minTexelGatherOffset = -8, |
| 427 |
.maxTexelGatherOffset = 7, |
| 428 |
.minInterpolationOffset = -0.5, |
| 429 |
.maxInterpolationOffset = 0.4375, |
| 430 |
.subPixelInterpolationOffsetBits = 4, |
| 431 |
.maxFramebufferHeight = 16384, |
| 432 |
.maxFramebufferWidth = 16384, |
| 433 |
.maxFramebufferLayers = 2048, |
| 434 |
.framebufferColorSampleCounts = sample_counts, |
| 435 |
.framebufferDepthSampleCounts = sample_counts, |
| 436 |
.framebufferNoAttachmentsSampleCounts = sample_counts, |
| 437 |
.framebufferStencilSampleCounts = sample_counts, |
| 438 |
.maxColorAttachments = KK_MAX_RTS, |
| 439 |
.sampledImageColorSampleCounts = sample_counts, |
| 440 |
.sampledImageIntegerSampleCounts = sample_counts, |
| 441 |
.sampledImageDepthSampleCounts = sample_counts, |
| 442 |
.sampledImageStencilSampleCounts = sample_counts, |
| 443 |
.storageImageSampleCounts = sample_counts, |
| 444 |
.maxSampleMaskWords = 1, |
| 445 |
.timestampComputeAndGraphics = false, |
| 446 |
.timestampPeriod = 1, |
| 447 |
.maxClipDistances = 8, |
| 448 |
.maxCullDistances = 8, |
| 449 |
.maxCombinedClipAndCullDistances = 8, |
| 450 |
.discreteQueuePriorities = 2, |
| 451 |
.pointSizeRange = {1.0f, 511.0f}, |
| 452 |
.lineWidthRange = {1.0f, 1.0f}, |
| 453 |
.pointSizeGranularity = 0.0625f, |
| 454 |
.lineWidthGranularity = 0.0f, |
| 455 |
.strictLines = false, |
| 456 |
.standardSampleLocations = true, |
| 457 |
.optimalBufferCopyOffsetAlignment = 1, |
| 458 |
.optimalBufferCopyRowPitchAlignment = 1, |
| 459 |
.nonCoherentAtomSize = 64, |
| 460 |
|
| 461 |
|
| 462 |
.sparseResidencyNonResidentStrict = false, |
| 463 |
.sparseResidencyAlignedMipSize = false, |
| 464 |
.sparseResidencyStandard2DBlockShape = false, |
| 465 |
.sparseResidencyStandard2DMultisampleBlockShape = false, |
| 466 |
.sparseResidencyStandard3DBlockShape = false, |
| 467 |
|
| 468 |
|
| 469 |
.subgroupSize = 32, |
| 470 |
.subgroupSupportedStages = |
| 471 |
VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 472 |
.subgroupSupportedOperations = |
| 473 |
VK_SUBGROUP_FEATURE_BASIC_BIT | VK_SUBGROUP_FEATURE_BALLOT_BIT | |
| 474 |
VK_SUBGROUP_FEATURE_VOTE_BIT | VK_SUBGROUP_FEATURE_QUAD_BIT | |
| 475 |
VK_SUBGROUP_FEATURE_SHUFFLE_BIT | |
| 476 |
VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT | |
| 477 |
VK_SUBGROUP_FEATURE_ROTATE_BIT_KHR, |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
.subgroupQuadOperationsInAllStages = true, |
| 482 |
.pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY, |
| 483 |
.maxMultiviewViewCount = KK_MAX_MULTIVIEW_VIEW_COUNT, |
| 484 |
.maxMultiviewInstanceIndex = UINT32_MAX, |
| 485 |
.maxPerSetDescriptors = UINT32_MAX, |
| 486 |
.maxMemoryAllocationSize = (1u << 31), |
| 487 |
|
| 488 |
|
| 489 |
.supportedDepthResolveModes = |
| 490 |
VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_AVERAGE_BIT | |
| 491 |
VK_RESOLVE_MODE_MIN_BIT | VK_RESOLVE_MODE_MAX_BIT, |
| 492 |
.supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | |
| 493 |
VK_RESOLVE_MODE_MIN_BIT | |
| 494 |
VK_RESOLVE_MODE_MAX_BIT, |
| 495 |
.independentResolveNone = true, |
| 496 |
.independentResolve = true, |
| 497 |
.driverID = VK_DRIVER_ID_MESA_KOSMICKRISP, |
| 498 |
.conformanceVersion = (VkConformanceVersion){1, 4, 3, 2}, |
| 499 |
.denormBehaviorIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE, |
| 500 |
.roundingModeIndependence = VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE, |
| 501 |
.shaderSignedZeroInfNanPreserveFloat16 = false, |
| 502 |
.shaderSignedZeroInfNanPreserveFloat32 = false, |
| 503 |
.shaderSignedZeroInfNanPreserveFloat64 = false, |
| 504 |
.shaderDenormPreserveFloat16 = false, |
| 505 |
.shaderDenormPreserveFloat32 = false, |
| 506 |
.shaderDenormPreserveFloat64 = false, |
| 507 |
.shaderDenormFlushToZeroFloat16 = false, |
| 508 |
.shaderDenormFlushToZeroFloat32 = false, |
| 509 |
.shaderDenormFlushToZeroFloat64 = false, |
| 510 |
.shaderRoundingModeRTEFloat16 = false, |
| 511 |
.shaderRoundingModeRTEFloat32 = false, |
| 512 |
.shaderRoundingModeRTEFloat64 = false, |
| 513 |
.shaderRoundingModeRTZFloat16 = false, |
| 514 |
.shaderRoundingModeRTZFloat32 = false, |
| 515 |
.shaderRoundingModeRTZFloat64 = false, |
| 516 |
.maxUpdateAfterBindDescriptorsInAllPools = UINT32_MAX, |
| 517 |
.shaderUniformBufferArrayNonUniformIndexingNative = true, |
| 518 |
.shaderSampledImageArrayNonUniformIndexingNative = true, |
| 519 |
.shaderStorageBufferArrayNonUniformIndexingNative = true, |
| 520 |
.shaderStorageImageArrayNonUniformIndexingNative = true, |
| 521 |
.shaderInputAttachmentArrayNonUniformIndexingNative = true, |
| 522 |
.robustBufferAccessUpdateAfterBind = true, |
| 523 |
.quadDivergentImplicitLod = false, |
| 524 |
.maxPerStageDescriptorUpdateAfterBindSamplers = KK_MAX_DESCRIPTORS, |
| 525 |
.maxPerStageDescriptorUpdateAfterBindUniformBuffers = KK_MAX_DESCRIPTORS, |
| 526 |
.maxPerStageDescriptorUpdateAfterBindStorageBuffers = KK_MAX_DESCRIPTORS, |
| 527 |
.maxPerStageDescriptorUpdateAfterBindSampledImages = KK_MAX_DESCRIPTORS, |
| 528 |
.maxPerStageDescriptorUpdateAfterBindStorageImages = KK_MAX_DESCRIPTORS, |
| 529 |
.maxPerStageDescriptorUpdateAfterBindInputAttachments = |
| 530 |
KK_MAX_DESCRIPTORS, |
| 531 |
.maxPerStageUpdateAfterBindResources = UINT32_MAX, |
| 532 |
.maxDescriptorSetUpdateAfterBindSamplers = KK_MAX_DESCRIPTORS, |
| 533 |
.maxDescriptorSetUpdateAfterBindUniformBuffers = KK_MAX_DESCRIPTORS, |
| 534 |
.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = |
| 535 |
KK_MAX_DYNAMIC_BUFFERS / 2, |
| 536 |
.maxDescriptorSetUpdateAfterBindStorageBuffers = KK_MAX_DESCRIPTORS, |
| 537 |
.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = |
| 538 |
KK_MAX_DYNAMIC_BUFFERS / 2, |
| 539 |
.maxDescriptorSetUpdateAfterBindSampledImages = KK_MAX_DESCRIPTORS, |
| 540 |
.maxDescriptorSetUpdateAfterBindStorageImages = KK_MAX_DESCRIPTORS, |
| 541 |
.maxDescriptorSetUpdateAfterBindInputAttachments = KK_MAX_DESCRIPTORS, |
| 542 |
.filterMinmaxSingleComponentFormats = false, |
| 543 |
.filterMinmaxImageComponentMapping = false, |
| 544 |
.maxTimelineSemaphoreValueDifference = UINT64_MAX, |
| 545 |
.framebufferIntegerColorSampleCounts = sample_counts, |
| 546 |
|
| 547 |
|
| 548 |
.minSubgroupSize = 32, |
| 549 |
.maxSubgroupSize = 32, |
| 550 |
.maxComputeWorkgroupSubgroups = pdev->info.max_workgroup_invocations / 32, |
| 551 |
.requiredSubgroupSizeStages = 0, |
| 552 |
.maxInlineUniformBlockSize = KK_MAX_INLINE_UNIFORM_BLOCK_SIZE, |
| 553 |
.maxPerStageDescriptorInlineUniformBlocks = 32, |
| 554 |
.maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = 32, |
| 555 |
.maxDescriptorSetInlineUniformBlocks = 6 * 32, |
| 556 |
.maxDescriptorSetUpdateAfterBindInlineUniformBlocks = 6 * 32, |
| 557 |
.maxInlineUniformTotalSize = 1 << 16, |
| 558 |
.integerDotProduct4x8BitPackedUnsignedAccelerated = false, |
| 559 |
.integerDotProduct4x8BitPackedSignedAccelerated = false, |
| 560 |
.integerDotProduct4x8BitPackedMixedSignednessAccelerated = false, |
| 561 |
.storageTexelBufferOffsetAlignmentBytes = KK_MIN_TEXEL_BUFFER_ALIGNMENT, |
| 562 |
.storageTexelBufferOffsetSingleTexelAlignment = false, |
| 563 |
.uniformTexelBufferOffsetAlignmentBytes = KK_MIN_TEXEL_BUFFER_ALIGNMENT, |
| 564 |
.uniformTexelBufferOffsetSingleTexelAlignment = false, |
| 565 |
.maxBufferSize = KK_MAX_BUFFER_SIZE, |
| 566 |
|
| 567 |
|
| 568 |
.maxPushDescriptors = KK_MAX_PUSH_DESCRIPTORS, |
| 569 |
|
| 570 |
|
| 571 |
.maxCustomBorderColorSamplers = 4000, |
| 572 |
|
| 573 |
|
| 574 |
.dynamicPrimitiveTopologyUnrestricted = false, |
| 575 |
|
| 576 |
|
| 577 |
.graphicsPipelineLibraryFastLinking = true, |
| 578 |
.graphicsPipelineLibraryIndependentInterpolationDecoration = true, |
| 579 |
|
| 580 |
|
| 581 |
.lineSubPixelPrecisionBits = 8, |
| 582 |
|
| 583 |
|
| 584 |
.earlyFragmentMultisampleCoverageAfterSampleCounting = false, |
| 585 |
.earlyFragmentSampleMaskTestBeforeSampleCounting = true, |
| 586 |
.depthStencilSwizzleOneSupport = false, |
| 587 |
.polygonModePointSize = false, |
| 588 |
.nonStrictSinglePixelWideLinesUseParallelogram = false, |
| 589 |
.nonStrictWideLinesUseParallelogram = false, |
| 590 |
|
| 591 |
|
| 592 |
.blockTexelViewCompatibleMultipleLayers = false, |
| 593 |
.maxCombinedImageSamplerDescriptorCount = 3, |
| 594 |
.fragmentShadingRateClampCombinerInputs = false, |
| 595 |
|
| 596 |
|
| 597 |
.robustFragmentShadingRateAttachmentAccess = false, |
| 598 |
.separateDepthStencilAttachmentAccess = false, |
| 599 |
.maxDescriptorSetTotalUniformBuffersDynamic = KK_MAX_DYNAMIC_BUFFERS / 2, |
| 600 |
.maxDescriptorSetTotalStorageBuffersDynamic = KK_MAX_DYNAMIC_BUFFERS / 2, |
| 601 |
.maxDescriptorSetTotalBuffersDynamic = KK_MAX_DYNAMIC_BUFFERS, |
| 602 |
.maxDescriptorSetUpdateAfterBindTotalUniformBuffersDynamic = |
| 603 |
KK_MAX_DYNAMIC_BUFFERS / 2, |
| 604 |
.maxDescriptorSetUpdateAfterBindTotalStorageBuffersDynamic = |
| 605 |
KK_MAX_DYNAMIC_BUFFERS / 2, |
| 606 |
.maxDescriptorSetUpdateAfterBindTotalBuffersDynamic = |
| 607 |
KK_MAX_DYNAMIC_BUFFERS, |
| 608 |
|
| 609 |
|
| 610 |
.nativeUnalignedPerformance = true, |
| 611 |
|
| 612 |
|
| 613 |
.minPlacedMemoryMapAlignment = os_page_size, |
| 614 |
|
| 615 |
|
| 616 |
.maxMultiDrawCount = UINT32_MAX, |
| 617 |
|
| 618 |
|
| 619 |
.maxCommandBufferNestingLevel = UINT32_MAX, |
| 620 |
|
| 621 |
|
| 622 |
.defaultRobustnessStorageBuffers = |
| 623 |
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT, |
| 624 |
.defaultRobustnessUniformBuffers = |
| 625 |
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT, |
| 626 |
.defaultRobustnessVertexInputs = |
| 627 |
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT, |
| 628 |
.defaultRobustnessImages = |
| 629 |
VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_2_EXT, |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
.provokingVertexModePerPipeline = true, |
| 635 |
.transformFeedbackPreservesTriangleFanProvokingVertex = true, |
| 636 |
|
| 637 |
|
| 638 |
.robustStorageBufferAccessSizeAlignment = KK_SSBO_BOUNDS_CHECK_ALIGNMENT, |
| 639 |
.robustUniformBufferAccessSizeAlignment = KK_MIN_UBO_ALIGNMENT, |
| 640 |
|
| 641 |
|
| 642 |
.sampleLocationSampleCounts = sample_counts, |
| 643 |
.maxSampleLocationGridSize = (VkExtent2D){1, 1}, |
| 644 |
.sampleLocationCoordinateRange[0] = 0.0f, |
| 645 |
.sampleLocationCoordinateRange[1] = 0.9375f, |
| 646 |
.sampleLocationSubPixelBits = 4, |
| 647 |
.variableSampleLocations = false, |
| 648 |
|
| 649 |
|
| 650 |
.shaderBinaryVersion = 0, |
| 651 |
|
| 652 |
|
| 653 |
.maxTransformFeedbackStreams = 4, |
| 654 |
.maxTransformFeedbackBuffers = 4, |
| 655 |
.maxTransformFeedbackBufferSize = UINT32_MAX, |
| 656 |
.maxTransformFeedbackStreamDataSize = 2048, |
| 657 |
.maxTransformFeedbackBufferDataSize = 512, |
| 658 |
.maxTransformFeedbackBufferDataStride = 2048, |
| 659 |
.transformFeedbackQueries = true, |
| 660 |
.transformFeedbackStreamsLinesTriangles = false, |
| 661 |
.transformFeedbackRasterizationStreamSelect = true, |
| 662 |
.transformFeedbackDraw = true, |
| 663 |
|
| 664 |
|
| 665 |
.maxVertexAttribDivisor = UINT32_MAX, |
| 666 |
.supportsNonZeroFirstInstance = true, |
| 667 |
|
| 668 |
|
| 669 |
.triStripVertexOrderIndependentOfProvokingVertex = false, |
| 670 |
}; |
| 671 |
|
| 672 |
char gpu_name[256u]; |
| 673 |
mtl_device_get_name(pdev->mtl_dev_handle, gpu_name); |
| 674 |
snprintf(properties->deviceName, sizeof(properties->deviceName), "%s", |
| 675 |
gpu_name); |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
static const VkImageLayout supported_layouts[] = { |
| 681 |
VK_IMAGE_LAYOUT_GENERAL, |
| 682 |
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 683 |
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
| 684 |
VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, |
| 685 |
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, |
| 686 |
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, |
| 687 |
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 688 |
VK_IMAGE_LAYOUT_PREINITIALIZED, |
| 689 |
VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, |
| 690 |
VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, |
| 691 |
VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, |
| 692 |
VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL, |
| 693 |
VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL, |
| 694 |
VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL, |
| 695 |
VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL, |
| 696 |
VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL, |
| 697 |
VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT, |
| 698 |
VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT, |
| 699 |
}; |
| 700 |
|
| 701 |
properties->pCopySrcLayouts = (VkImageLayout *)supported_layouts; |
| 702 |
properties->copySrcLayoutCount = ARRAY_SIZE(supported_layouts); |
| 703 |
properties->pCopyDstLayouts = (VkImageLayout *)supported_layouts; |
| 704 |
properties->copyDstLayoutCount = ARRAY_SIZE(supported_layouts); |
| 705 |
|
| 706 |
STATIC_ASSERT(sizeof(instance->driver_build_sha) >= VK_UUID_SIZE); |
| 707 |
memcpy(properties->optimalTilingLayoutUUID, instance->driver_build_sha, |
| 708 |
VK_UUID_SIZE); |
| 709 |
|
| 710 |
properties->identicalMemoryTypeRequirements = false; |
| 711 |
|
| 712 |
|
| 713 |
STATIC_ASSERT(sizeof(vk_shaderModuleIdentifierAlgorithmUUID) == |
| 714 |
sizeof(properties->shaderModuleIdentifierAlgorithmUUID)); |
| 715 |
memcpy(properties->shaderModuleIdentifierAlgorithmUUID, |
| 716 |
vk_shaderModuleIdentifierAlgorithmUUID, |
| 717 |
sizeof(properties->shaderModuleIdentifierAlgorithmUUID)); |
| 718 |
|
| 719 |
const struct { |
| 720 |
uint64_t registry_id; |
| 721 |
uint64_t pad; |
| 722 |
} dev_uuid = { |
| 723 |
.registry_id = mtl_device_get_registry_id(pdev->mtl_dev_handle), |
| 724 |
}; |
| 725 |
STATIC_ASSERT(sizeof(dev_uuid) == VK_UUID_SIZE); |
| 726 |
memcpy(properties->deviceUUID, &dev_uuid, VK_UUID_SIZE); |
| 727 |
STATIC_ASSERT(sizeof(instance->driver_build_sha) >= VK_UUID_SIZE); |
| 728 |
memcpy(properties->driverUUID, instance->driver_build_sha, VK_UUID_SIZE); |
| 729 |
|
| 730 |
snprintf(properties->driverName, VK_MAX_DRIVER_NAME_SIZE, "KosmicKrisp"); |
| 731 |
snprintf(properties->driverInfo, VK_MAX_DRIVER_INFO_SIZE, |
| 732 |
"Mesa " PACKAGE_VERSION MESA_GIT_SHA1); |
| 733 |
} |
| 734 |
|
| 735 |
static void |
| 736 |
kk_physical_device_init_pipeline_cache(struct kk_physical_device *pdev) |
| 737 |
{ |
| 738 |
struct kk_instance *instance = kk_physical_device_instance(pdev); |
| 739 |
|
| 740 |
blake3_hasher blake3_ctx; |
| 741 |
_mesa_blake3_init(&blake3_ctx); |
| 742 |
|
| 743 |
_mesa_blake3_update(&blake3_ctx, instance->driver_build_sha, |
| 744 |
sizeof(instance->driver_build_sha)); |
| 745 |
|
| 746 |
unsigned char blake3[BLAKE3_KEY_LEN]; |
| 747 |
_mesa_blake3_final(&blake3_ctx, blake3); |
| 748 |
|
| 749 |
STATIC_ASSERT(BLAKE3_KEY_LEN >= VK_UUID_SIZE); |
| 750 |
memcpy(pdev->vk.properties.pipelineCacheUUID, blake3, VK_UUID_SIZE); |
| 751 |
memcpy(pdev->vk.properties.shaderBinaryUUID, blake3, VK_UUID_SIZE); |
| 752 |
} |
| 753 |
|
| 754 |
static void |
| 755 |
kk_physical_device_free_disk_cache(struct kk_physical_device *pdev) |
| 756 |
{ |
| 757 |
#ifdef ENABLE_SHADER_CACHE |
| 758 |
if (pdev->vk.disk_cache) { |
| 759 |
disk_cache_destroy(pdev->vk.disk_cache); |
| 760 |
pdev->vk.disk_cache = NULL; |
| 761 |
} |
| 762 |
#else |
| 763 |
assert(pdev->vk.disk_cache == NULL); |
| 764 |
#endif |
| 765 |
} |
| 766 |
|
| 767 |
static uint64_t |
| 768 |
kk_get_sysmem_heap_size(void) |
| 769 |
{ |
| 770 |
uint64_t sysmem_size_B = 0; |
| 771 |
if (!os_get_total_physical_memory(&sysmem_size_B)) |
| 772 |
return 0; |
| 773 |
|
| 774 |
|
| 775 |
return ROUND_DOWN_TO(sysmem_size_B * 3 / 4, 1 << 20); |
| 776 |
} |
| 777 |
|
| 778 |
static uint64_t |
| 779 |
kk_get_sysmem_heap_available(struct kk_physical_device *pdev) |
| 780 |
{ |
| 781 |
uint64_t sysmem_size_B = 0; |
| 782 |
if (!os_get_available_system_memory(&sysmem_size_B)) { |
| 783 |
vk_loge(VK_LOG_OBJS(pdev), "Failed to query available system memory"); |
| 784 |
return 0; |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
return ROUND_DOWN_TO(sysmem_size_B * 3 / 4, 1 << 20); |
| 789 |
} |
| 790 |
|
| 791 |
static void |
| 792 |
get_metal_limits(struct kk_physical_device *pdev) |
| 793 |
{ |
| 794 |
struct mtl_size workgroup_size = |
| 795 |
mtl_device_max_threads_per_threadgroup(pdev->mtl_dev_handle); |
| 796 |
pdev->info.max_workgroup_count[0] = workgroup_size.x; |
| 797 |
pdev->info.max_workgroup_count[1] = workgroup_size.y; |
| 798 |
pdev->info.max_workgroup_count[2] = workgroup_size.z; |
| 799 |
pdev->info.max_workgroup_invocations = |
| 800 |
MAX3(workgroup_size.x, workgroup_size.y, workgroup_size.z); |
| 801 |
} |
| 802 |
|
| 803 |
VkResult |
| 804 |
kk_enumerate_physical_devices(struct vk_instance *_instance) |
| 805 |
{ |
| 806 |
struct kk_instance *instance = (struct kk_instance *)_instance; |
| 807 |
VkResult result; |
| 808 |
|
| 809 |
struct kk_physical_device *pdev = |
| 810 |
vk_zalloc(&instance->vk.alloc, sizeof(*pdev), 8, |
| 811 |
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 812 |
|
| 813 |
if (pdev == NULL) { |
| 814 |
return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 815 |
} |
| 816 |
|
| 817 |
pdev->mtl_dev_handle = mtl_device_create(); |
| 818 |
if (!pdev->mtl_dev_handle) { |
| 819 |
result = VK_SUCCESS; |
| 820 |
goto fail_alloc; |
| 821 |
} |
| 822 |
get_metal_limits(pdev); |
| 823 |
|
| 824 |
struct vk_physical_device_dispatch_table dispatch_table; |
| 825 |
vk_physical_device_dispatch_table_from_entrypoints( |
| 826 |
&dispatch_table, &kk_physical_device_entrypoints, true); |
| 827 |
vk_physical_device_dispatch_table_from_entrypoints( |
| 828 |
&dispatch_table, &wsi_physical_device_entrypoints, false); |
| 829 |
|
| 830 |
struct vk_device_extension_table supported_extensions; |
| 831 |
kk_get_device_extensions(instance, &supported_extensions); |
| 832 |
|
| 833 |
struct vk_features supported_features; |
| 834 |
kk_get_device_features(&supported_extensions, &supported_features); |
| 835 |
|
| 836 |
struct vk_properties properties; |
| 837 |
kk_get_device_properties(pdev, instance, &properties); |
| 838 |
|
| 839 |
properties.drmHasRender = false; |
| 840 |
|
| 841 |
result = vk_physical_device_init(&pdev->vk, &instance->vk, |
| 842 |
&supported_extensions, &supported_features, |
| 843 |
&properties, &dispatch_table); |
| 844 |
if (result != VK_SUCCESS) |
| 845 |
goto fail_mtl_dev; |
| 846 |
|
| 847 |
kk_physical_device_init_pipeline_cache(pdev); |
| 848 |
|
| 849 |
uint64_t sysmem_size_B = kk_get_sysmem_heap_size(); |
| 850 |
if (sysmem_size_B == 0) { |
| 851 |
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED, |
| 852 |
"Failed to query total system memory"); |
| 853 |
goto fail_disk_cache; |
| 854 |
} |
| 855 |
|
| 856 |
uint32_t sysmem_heap_idx = pdev->mem_heap_count++; |
| 857 |
pdev->mem_heaps[sysmem_heap_idx] = (struct kk_memory_heap){ |
| 858 |
.size = sysmem_size_B, |
| 859 |
.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, |
| 860 |
.available = kk_get_sysmem_heap_available, |
| 861 |
}; |
| 862 |
|
| 863 |
pdev->mem_types[pdev->mem_type_count++] = (VkMemoryType){ |
| 864 |
.propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 865 |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | |
| 866 |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT | |
| 867 |
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, |
| 868 |
.heapIndex = sysmem_heap_idx, |
| 869 |
}; |
| 870 |
|
| 871 |
assert(pdev->mem_heap_count <= ARRAY_SIZE(pdev->mem_heaps)); |
| 872 |
assert(pdev->mem_type_count <= ARRAY_SIZE(pdev->mem_types)); |
| 873 |
|
| 874 |
pdev->queue_families[pdev->queue_family_count++] = (struct kk_queue_family){ |
| 875 |
.queue_flags = |
| 876 |
VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT, |
| 877 |
.queue_count = 1, |
| 878 |
}; |
| 879 |
assert(pdev->queue_family_count <= ARRAY_SIZE(pdev->queue_families)); |
| 880 |
|
| 881 |
pdev->sync_binary_type = vk_sync_binary_get_type(&kk_sync_type); |
| 882 |
unsigned st_idx = 0; |
| 883 |
pdev->sync_types[st_idx++] = &kk_sync_type; |
| 884 |
pdev->sync_types[st_idx++] = &pdev->sync_binary_type.sync; |
| 885 |
pdev->sync_types[st_idx++] = NULL; |
| 886 |
assert(st_idx <= ARRAY_SIZE(pdev->sync_types)); |
| 887 |
pdev->vk.supported_sync_types = pdev->sync_types; |
| 888 |
|
| 889 |
result = kk_init_wsi(pdev); |
| 890 |
if (result != VK_SUCCESS) |
| 891 |
goto fail_disk_cache; |
| 892 |
|
| 893 |
list_add(&pdev->vk.link, &instance->vk.physical_devices.list); |
| 894 |
|
| 895 |
return VK_SUCCESS; |
| 896 |
|
| 897 |
fail_disk_cache: |
| 898 |
vk_physical_device_finish(&pdev->vk); |
| 899 |
fail_mtl_dev: |
| 900 |
mtl_release(pdev->mtl_dev_handle); |
| 901 |
fail_alloc: |
| 902 |
vk_free(&instance->vk.alloc, pdev); |
| 903 |
return result; |
| 904 |
} |
| 905 |
|
| 906 |
void |
| 907 |
kk_physical_device_destroy(struct vk_physical_device *vk_pdev) |
| 908 |
{ |
| 909 |
struct kk_physical_device *pdev = |
| 910 |
container_of(vk_pdev, struct kk_physical_device, vk); |
| 911 |
|
| 912 |
kk_finish_wsi(pdev); |
| 913 |
kk_physical_device_free_disk_cache(pdev); |
| 914 |
vk_physical_device_finish(&pdev->vk); |
| 915 |
mtl_release(pdev->mtl_dev_handle); |
| 916 |
vk_free(&pdev->vk.instance->alloc, pdev); |
| 917 |
} |
| 918 |
|
| 919 |
VKAPI_ATTR void VKAPI_CALL |
| 920 |
kk_GetPhysicalDeviceMemoryProperties2( |
| 921 |
VkPhysicalDevice physicalDevice, |
| 922 |
VkPhysicalDeviceMemoryProperties2 *pMemoryProperties) |
| 923 |
{ |
| 924 |
VK_FROM_HANDLE(kk_physical_device, pdev, physicalDevice); |
| 925 |
|
| 926 |
pMemoryProperties->memoryProperties.memoryHeapCount = pdev->mem_heap_count; |
| 927 |
for (int i = 0; i < pdev->mem_heap_count; i++) { |
| 928 |
pMemoryProperties->memoryProperties.memoryHeaps[i] = (VkMemoryHeap){ |
| 929 |
.size = pdev->mem_heaps[i].size, |
| 930 |
.flags = pdev->mem_heaps[i].flags, |
| 931 |
}; |
| 932 |
} |
| 933 |
|
| 934 |
pMemoryProperties->memoryProperties.memoryTypeCount = pdev->mem_type_count; |
| 935 |
for (int i = 0; i < pdev->mem_type_count; i++) { |
| 936 |
pMemoryProperties->memoryProperties.memoryTypes[i] = pdev->mem_types[i]; |
| 937 |
} |
| 938 |
|
| 939 |
vk_foreach_struct(ext, pMemoryProperties->pNext) { |
| 940 |
switch (ext->sType) { |
| 941 |
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT: { |
| 942 |
VkPhysicalDeviceMemoryBudgetPropertiesEXT *p = (void *)ext; |
| 943 |
|
| 944 |
for (unsigned i = 0; i < pdev->mem_heap_count; i++) { |
| 945 |
const struct kk_memory_heap *heap = &pdev->mem_heaps[i]; |
| 946 |
uint64_t used = p_atomic_read(&heap->used); |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
ow |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
p->heapUsage[i] = used; |
| 958 |
|
| 959 |
uint64_t available = heap->size; |
| 960 |
if (heap->available) |
| 961 |
available = heap->available(pdev); |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
gh |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
uint64_t budget = MIN2(available + used, heap->size); |
| 983 |
|
| 984 |
|
| 985 |
p->heapBudget[i] = ROUND_DOWN_TO(budget * 9 / 10, 1 << 20); |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
for (unsigned i = pdev->mem_heap_count; i < VK_MAX_MEMORY_HEAPS; i++) { |
| 997 |
p->heapBudget[i] = 0u; |
| 998 |
p->heapUsage[i] = 0u; |
| 999 |
} |
| 1000 |
break; |
| 1001 |
} |
| 1002 |
default: |
| 1003 |
vk_debug_ignored_stype(ext->sType); |
| 1004 |
break; |
| 1005 |
} |
| 1006 |
} |
| 1007 |
} |
| 1008 |
|
| 1009 |
VKAPI_ATTR void VKAPI_CALL |
| 1010 |
kk_GetPhysicalDeviceQueueFamilyProperties2( |
| 1011 |
VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, |
| 1012 |
VkQueueFamilyProperties2 *pQueueFamilyProperties) |
| 1013 |
{ |
| 1014 |
VK_FROM_HANDLE(kk_physical_device, pdev, physicalDevice); |
| 1015 |
VK_OUTARRAY_MAKE_TYPED(VkQueueFamilyProperties2, out, pQueueFamilyProperties, |
| 1016 |
pQueueFamilyPropertyCount); |
| 1017 |
|
| 1018 |
for (uint8_t i = 0; i < pdev->queue_family_count; i++) { |
| 1019 |
const struct kk_queue_family *queue_family = &pdev->queue_families[i]; |
| 1020 |
|
| 1021 |
vk_outarray_append_typed(VkQueueFamilyProperties2, &out, p) |
| 1022 |
{ |
| 1023 |
p->queueFamilyProperties.queueFlags = queue_family->queue_flags; |
| 1024 |
p->queueFamilyProperties.queueCount = queue_family->queue_count; |
| 1025 |
p->queueFamilyProperties.timestampValidBits = |
| 1026 |
0; |
| 1027 |
p->queueFamilyProperties.minImageTransferGranularity = |
| 1028 |
(VkExtent3D){1, 1, 1}; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
} |
| 1032 |
|
| 1033 |
VKAPI_ATTR void VKAPI_CALL |
| 1034 |
kk_GetPhysicalDeviceMultisamplePropertiesEXT( |
| 1035 |
VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples, |
| 1036 |
VkMultisamplePropertiesEXT *pMultisampleProperties) |
| 1037 |
{ |
| 1038 |
VK_FROM_HANDLE(kk_physical_device, pdev, physicalDevice); |
| 1039 |
|
| 1040 |
if (samples & pdev->vk.properties.sampleLocationSampleCounts) { |
| 1041 |
pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){1, 1}; |
| 1042 |
} else { |
| 1043 |
pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){0, 0}; |
| 1044 |
} |
| 1045 |
} |