diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 49c812125b3..4117481006c 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -1385,7 +1385,7 @@ anv_queue_submit_sparse_bind_locked(struct anv_queue *queue, * supposed to be used by applications that request sparse to be enabled * but don't actually *use* it. */ - if (!device->physical->has_sparse) { + if (device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) { if (INTEL_DEBUG(DEBUG_SPARSE)) fprintf(stderr, "=== application submitting sparse operations: " "buffer_bind:%d image_opaque_bind:%d image_bind:%d\n", diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index bb5c87ec850..146ef728555 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -439,8 +439,7 @@ get_features(const struct anv_physical_device *pdevice, const bool mesh_shader = pdevice->vk.supported_extensions.EXT_mesh_shader; - const bool has_sparse_or_fake = pdevice->instance->has_fake_sparse || - pdevice->has_sparse; + const bool has_sparse_or_fake = pdevice->sparse_type != ANV_SPARSE_TYPE_NOT_SUPPORTED; *features = (struct vk_features) { /* Vulkan 1.0 */ @@ -1209,12 +1208,12 @@ get_properties(const struct anv_physical_device *pdevice, const uint32_t max_workgroup_size = MIN2(1024, 32 * devinfo->max_cs_workgroup_threads); - const bool has_sparse_or_fake = pdevice->instance->has_fake_sparse || - pdevice->has_sparse; + const bool has_sparse_or_fake = pdevice->sparse_type != ANV_SPARSE_TYPE_NOT_SUPPORTED; + const bool sparse_uses_trtt = pdevice->sparse_type == ANV_SPARSE_TYPE_TRTT; uint64_t sparse_addr_space_size = !has_sparse_or_fake ? 0 : - pdevice->sparse_uses_trtt ? pdevice->va.trtt.size : + sparse_uses_trtt ? pdevice->va.trtt.size : pdevice->va.high_heap.size; VkSampleCountFlags sample_counts = @@ -2095,8 +2094,7 @@ static void anv_physical_device_init_queue_families(struct anv_physical_device *pdevice) { uint32_t family_count = 0; - VkQueueFlags sparse_flags = (pdevice->instance->has_fake_sparse || - pdevice->has_sparse) ? + VkQueueFlags sparse_flags = pdevice->sparse_type != ANV_SPARSE_TYPE_NOT_SUPPORTED ? VK_QUEUE_SPARSE_BINDING_BIT : 0; if (pdevice->engine_info) { @@ -2110,7 +2108,7 @@ anv_physical_device_init_queue_families(struct anv_physical_device *pdevice) const bool kernel_supports_non_render_engines = pdevice->info.kmd_type == INTEL_KMD_TYPE_XE || pdevice->has_vm_control; const bool sparse_supports_non_render_engines = - !pdevice->has_sparse || !pdevice->sparse_uses_trtt; + pdevice->sparse_type != ANV_SPARSE_TYPE_TRTT; const bool can_use_non_render_engines = kernel_supports_non_render_engines && sparse_supports_non_render_engines; @@ -2408,15 +2406,20 @@ anv_physical_device_try_create(struct vk_instance *vk_instance, /* While xe.ko can use both vm_bind and TR-TT, i915.ko only has TR-TT. */ if (device->info.kmd_type == INTEL_KMD_TYPE_XE) { - device->has_sparse = true; - device->sparse_uses_trtt = - debug_get_bool_option("ANV_SPARSE_USE_TRTT", false); + if (debug_get_bool_option("ANV_SPARSE_USE_TRTT", false)) + device->sparse_type = ANV_SPARSE_TYPE_TRTT; + else + device->sparse_type = ANV_SPARSE_TYPE_VM_BIND; } else { - device->has_sparse = - device->info.ver >= 12 && - device->has_exec_timeline && - debug_get_bool_option("ANV_SPARSE", true); - device->sparse_uses_trtt = true; + if (device->info.ver >= 12 && + device->has_exec_timeline && + debug_get_bool_option("ANV_SPARSE", true)) { + device->sparse_type = ANV_SPARSE_TYPE_TRTT; + } else if (instance->has_fake_sparse) { + device->sparse_type = ANV_SPARSE_TYPE_FAKE; + } else { + device->sparse_type = ANV_SPARSE_TYPE_NOT_SUPPORTED; + } } device->always_flush_cache = INTEL_DEBUG(DEBUG_STALL) || @@ -5001,7 +5004,7 @@ void anv_GetDeviceBufferMemoryRequirements( const bool is_sparse = pInfo->pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT; - if (!device->physical->has_sparse && + if ((device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) && INTEL_DEBUG(DEBUG_SPARSE) && pInfo->pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | @@ -5026,7 +5029,7 @@ VkResult anv_CreateBuffer( ANV_FROM_HANDLE(anv_device, device, _device); struct anv_buffer *buffer; - if (!device->physical->has_sparse && + if ((device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) && INTEL_DEBUG(DEBUG_SPARSE) && pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 72f1fc6ae92..889279ca006 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -1832,7 +1832,7 @@ void anv_GetPhysicalDeviceSparseImageFormatProperties2( VK_OUTARRAY_MAKE_TYPED(VkSparseImageFormatProperties2, props, pProperties, pPropertyCount); - if (!physical_device->has_sparse) { + if (physical_device->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) { if (INTEL_DEBUG(DEBUG_SPARSE)) fprintf(stderr, "=== [%s:%d] [%s]\n", __FILE__, __LINE__, __func__); return; diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 534c154329d..42ff6007f55 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1874,7 +1874,7 @@ VkResult anv_CreateImage( { ANV_FROM_HANDLE(anv_device, device, _device); - if (!device->physical->has_sparse && + if ((device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) && INTEL_DEBUG(DEBUG_SPARSE) && pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | @@ -2084,7 +2084,7 @@ void anv_GetDeviceImageMemoryRequirements( ANV_FROM_HANDLE(anv_device, device, _device); struct anv_image image = { 0 }; - if (!device->physical->has_sparse && + if ((device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) && INTEL_DEBUG(DEBUG_SPARSE) && pInfo->pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | @@ -2194,7 +2194,8 @@ void anv_GetImageSparseMemoryRequirements2( ANV_FROM_HANDLE(anv_image, image, pInfo->image); if (!anv_sparse_residency_is_enabled(device)) { - if (!device->physical->has_sparse && INTEL_DEBUG(DEBUG_SPARSE)) + if ((device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) && + INTEL_DEBUG(DEBUG_SPARSE)) fprintf(stderr, "=== [%s:%d] [%s]\n", __FILE__, __LINE__, __func__); *pSparseMemoryRequirementCount = 0; @@ -2216,7 +2217,8 @@ void anv_GetDeviceImageSparseMemoryRequirements( struct anv_image image = { 0 }; if (!anv_sparse_residency_is_enabled(device)) { - if (!device->physical->has_sparse && INTEL_DEBUG(DEBUG_SPARSE)) + if ((device->physical->sparse_type == ANV_SPARSE_TYPE_NOT_SUPPORTED) && + INTEL_DEBUG(DEBUG_SPARSE)) fprintf(stderr, "=== [%s:%d] [%s]\n", __FILE__, __LINE__, __func__); *pSparseMemoryRequirementCount = 0; diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 50dc8a42150..82eec309404 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -182,7 +182,7 @@ anv_shader_stage_to_nir(struct anv_device *device, .ray_tracing_position_fetch = rt_enabled, .shader_clock = true, .shader_viewport_index_layer = true, - .sparse_residency = pdevice->has_sparse, + .sparse_residency = pdevice->sparse_type != ANV_SPARSE_TYPE_NOT_SUPPORTED, .stencil_export = true, .storage_8bit = true, .storage_16bit = true, diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 425fc9de1bc..52b7d98df54 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1019,8 +1019,12 @@ struct anv_physical_device { /** True if we have the means to do sparse binding (e.g., a Kernel driver * a vm_bind ioctl). */ - bool has_sparse; - bool sparse_uses_trtt; + enum anv_sparse_type { + ANV_SPARSE_TYPE_NOT_SUPPORTED = 0, + ANV_SPARSE_TYPE_VM_BIND, + ANV_SPARSE_TYPE_TRTT, + ANV_SPARSE_TYPE_FAKE, + } sparse_type; /** True if HW supports ASTC LDR */ bool has_astc_ldr; diff --git a/src/intel/vulkan/anv_sparse.c b/src/intel/vulkan/anv_sparse.c index e5fdd042252..65e270be386 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -625,7 +625,7 @@ anv_sparse_bind(struct anv_device *device, dump_anv_vm_bind(device, &submit->binds[b]); } - return device->physical->sparse_uses_trtt ? + return device->physical->sparse_type == ANV_SPARSE_TYPE_TRTT ? anv_sparse_bind_trtt(device, submit) : anv_sparse_bind_vm_bind(device, submit); } @@ -640,7 +640,7 @@ anv_init_sparse_bindings(struct anv_device *device, { uint64_t size = align64(size_, ANV_SPARSE_BLOCK_SIZE); - if (device->physical->sparse_uses_trtt) + if (device->physical->sparse_type == ANV_SPARSE_TYPE_TRTT) alloc_flags |= ANV_BO_ALLOC_TRTT; sparse->address = anv_vma_alloc(device, size, ANV_SPARSE_BLOCK_SIZE,