diff --git a/src/amd/common/ac_llvm_helper.cpp b/src/amd/common/ac_llvm_helper.cpp index 4f03103561e3..1839dab8f0a2 100644 --- a/src/amd/common/ac_llvm_helper.cpp +++ b/src/amd/common/ac_llvm_helper.cpp @@ -40,13 +40,21 @@ void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes) llvm::Argument *A = llvm::unwrap(val); llvm::AttrBuilder B; B.addDereferenceableAttr(bytes); +#if HAVE_LLVM >= 0x0500 + A->addAttr(llvm::AttributeList::get(A->getContext(), A->getArgNo() + 1, B)); +#else A->addAttr(llvm::AttributeSet::get(A->getContext(), A->getArgNo() + 1, B)); +#endif } bool ac_is_sgpr_param(LLVMValueRef arg) { llvm::Argument *A = llvm::unwrap(arg); +#if HAVE_LLVM >= 0x0500 + llvm::AttributeList AS = A->getParent()->getAttributes(); +#else llvm::AttributeSet AS = A->getParent()->getAttributes(); +#endif unsigned ArgNo = A->getArgNo(); return AS.hasAttribute(ArgNo + 1, llvm::Attribute::ByVal) || AS.hasAttribute(ArgNo + 1, llvm::Attribute::InReg); diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index d1fd58d77b90..1e4f52db6154 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -84,6 +84,18 @@ static const VkExtensionProperties instance_extensions[] = { .specVersion = 5, }, #endif + { + .extensionName = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, + .specVersion = 1, + }, + { + .extensionName = VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, + .specVersion = 1, + }, + { + .extensionName = VK_KHX_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, + .specVersion = 1, + }, }; static const VkExtensionProperties common_device_extensions[] = { @@ -115,6 +127,18 @@ static const VkExtensionProperties common_device_extensions[] = { .extensionName = VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME, .specVersion = 1, }, + { + .extensionName = VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, + .specVersion = 1, + }, + { + .extensionName = VK_KHX_EXTERNAL_MEMORY_EXTENSION_NAME, + .specVersion = 1, + }, + { + .extensionName = VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME, + .specVersion = 1, + }, }; static VkResult @@ -255,7 +279,6 @@ radv_physical_device_finish(struct radv_physical_device *device) close(device->local_fd); } - static void * default_alloc_func(void *pUserData, size_t size, size_t align, VkSystemAllocationScope allocationScope) @@ -1694,7 +1717,7 @@ VkResult radv_AllocateMemory( VkResult result; enum radeon_bo_domain domain; uint32_t flags = 0; - const VkDedicatedAllocationMemoryAllocateInfoNV *dedicate_info = NULL; + assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO); if (pAllocateInfo->allocationSize == 0) { @@ -1703,15 +1726,10 @@ VkResult radv_AllocateMemory( return VK_SUCCESS; } - vk_foreach_struct(ext, pAllocateInfo->pNext) { - switch (ext->sType) { - case VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV: - dedicate_info = (const VkDedicatedAllocationMemoryAllocateInfoNV *)ext; - break; - default: - break; - } - } + const VkImportMemoryFdInfoKHX *import_info = + vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHX); + const VkDedicatedAllocationMemoryAllocateInfoNV *dedicate_info = + vk_find_struct_const(pAllocateInfo->pNext, DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV); mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); @@ -1726,6 +1744,17 @@ VkResult radv_AllocateMemory( mem->buffer = NULL; } + if (import_info) { + assert(import_info->handleType == + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX); + mem->bo = device->ws->buffer_from_fd(device->ws, import_info->fd, + NULL, NULL); + if (!mem->bo) + goto fail; + else + goto out_success; + } + uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096); if (pAllocateInfo->memoryTypeIndex == RADV_MEM_TYPE_GTT_WRITE_COMBINE || pAllocateInfo->memoryTypeIndex == RADV_MEM_TYPE_GTT_CACHED) @@ -1749,7 +1778,7 @@ VkResult radv_AllocateMemory( goto fail; } mem->type_index = pAllocateInfo->memoryTypeIndex; - +out_success: *pMem = radv_device_memory_to_handle(mem); return VK_SUCCESS; @@ -2695,7 +2724,6 @@ void radv_DestroySampler( vk_free2(&device->alloc, pAllocator, sampler); } - /* vk_icd.h does not declare this function, so we declare it here to * suppress Wmissing-prototypes. */ @@ -2739,3 +2767,42 @@ vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion) *pSupportedVersion = MIN2(*pSupportedVersion, 3u); return VK_SUCCESS; } + +VkResult radv_GetMemoryFdKHX(VkDevice _device, + VkDeviceMemory _memory, + VkExternalMemoryHandleTypeFlagsKHX handleType, + int *pFD) +{ + RADV_FROM_HANDLE(radv_device, device, _device); + RADV_FROM_HANDLE(radv_device_memory, memory, _memory); + + /* We support only one handle type. */ + assert(handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX); + + bool ret = radv_get_memory_fd(device, memory, pFD); + if (ret == false) + return VK_ERROR_OUT_OF_DEVICE_MEMORY; + return VK_SUCCESS; +} + +VkResult radv_GetMemoryFdPropertiesKHX(VkDevice _device, + VkExternalMemoryHandleTypeFlagBitsKHX handleType, + int fd, + VkMemoryFdPropertiesKHX *pMemoryFdProperties) +{ + /* The valid usage section for this function says: + * + * "handleType must not be one of the handle types defined as opaque." + * + * Since we only handle opaque handles for now, there are no FD properties. + */ + return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX; +} + +VkResult radv_GetSemaphoreFdKHX(VkDevice device, + VkSemaphore semaphore, + VkExternalSemaphoreHandleTypeFlagsKHX handleType, + int *pFd) +{ + return VK_SUCCESS; +} diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py index b7b2bcf97e4f..752735406a46 100644 --- a/src/amd/vulkan/radv_entrypoints_gen.py +++ b/src/amd/vulkan/radv_entrypoints_gen.py @@ -39,6 +39,12 @@ 'VK_KHR_wayland_surface', 'VK_KHR_xcb_surface', 'VK_KHR_xlib_surface', + 'VK_KHX_external_memory_capabilities', + 'VK_KHX_external_memory', + 'VK_KHX_external_memory_fd', + 'VK_KHX_external_semaphore_capabilities', + 'VK_KHX_external_semaphore', + 'VK_KHX_external_semaphore_fd' ] # We generate a static hash table for entry point lookup diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c index 9b21e04c63ba..4c3fba154b73 100644 --- a/src/amd/vulkan/radv_formats.c +++ b/src/amd/vulkan/radv_formats.c @@ -28,6 +28,7 @@ #include "sid.h" #include "r600d_common.h" +#include "util/vk_util.h" #include "util/u_half.h" #include "util/format_srgb.h" #include "util/format_r11g11b10f.h" @@ -1006,16 +1007,11 @@ void radv_GetPhysicalDeviceFormatProperties2KHR( &pFormatProperties->formatProperties); } -VkResult radv_GetPhysicalDeviceImageFormatProperties( - VkPhysicalDevice physicalDevice, - VkFormat format, - VkImageType type, - VkImageTiling tiling, - VkImageUsageFlags usage, - VkImageCreateFlags createFlags, - VkImageFormatProperties* pImageFormatProperties) +static VkResult radv_get_image_format_properties(struct radv_physical_device *physical_device, + const VkPhysicalDeviceImageFormatInfo2KHR *info, + VkImageFormatProperties *pImageFormatProperties) + { - RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice); VkFormatProperties format_props; VkFormatFeatureFlags format_feature_flags; VkExtent3D maxExtent; @@ -1023,11 +1019,11 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties( uint32_t maxArraySize; VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT; - radv_physical_device_get_format_properties(physical_device, format, + radv_physical_device_get_format_properties(physical_device, info->format, &format_props); - if (tiling == VK_IMAGE_TILING_LINEAR) { + if (info->tiling == VK_IMAGE_TILING_LINEAR) { format_feature_flags = format_props.linearTilingFeatures; - } else if (tiling == VK_IMAGE_TILING_OPTIMAL) { + } else if (info->tiling == VK_IMAGE_TILING_OPTIMAL) { format_feature_flags = format_props.optimalTilingFeatures; } else { unreachable("bad VkImageTiling"); @@ -1036,7 +1032,7 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties( if (format_feature_flags == 0) goto unsupported; - switch (type) { + switch (info->type) { default: unreachable("bad vkimage type\n"); case VK_IMAGE_TYPE_1D: @@ -1062,34 +1058,34 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties( break; } - if (tiling == VK_IMAGE_TILING_OPTIMAL && - type == VK_IMAGE_TYPE_2D && + if (info->tiling == VK_IMAGE_TILING_OPTIMAL && + info->type == VK_IMAGE_TYPE_2D && (format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) && - !(createFlags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && - !(usage & VK_IMAGE_USAGE_STORAGE_BIT)) { + !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && + !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) { sampleCounts |= VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT | VK_SAMPLE_COUNT_8_BIT; } - if (usage & VK_IMAGE_USAGE_SAMPLED_BIT) { + if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) { if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { goto unsupported; } } - if (usage & VK_IMAGE_USAGE_STORAGE_BIT) { + if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) { if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { goto unsupported; } } - if (usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { + if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { goto unsupported; } } - if (usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { + if (info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { if (!(format_feature_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { goto unsupported; } @@ -1120,18 +1116,132 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties( return VK_ERROR_FORMAT_NOT_SUPPORTED; } +VkResult radv_GetPhysicalDeviceImageFormatProperties( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags createFlags, + VkImageFormatProperties* pImageFormatProperties) +{ + RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice); + + const VkPhysicalDeviceImageFormatInfo2KHR info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR, + .pNext = NULL, + .format = format, + .type = type, + .tiling = tiling, + .usage = usage, + .flags = createFlags, + }; + + return radv_get_image_format_properties(physical_device, &info, + pImageFormatProperties); +} + +static void +get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2KHR *pImageFormatInfo, + VkExternalMemoryPropertiesKHX *external_properties) +{ + VkExternalMemoryFeatureFlagBitsKHX flags = 0; + VkExternalMemoryHandleTypeFlagsKHX export_flags = 0; + VkExternalMemoryHandleTypeFlagsKHX compat_flags = 0; + switch (pImageFormatInfo->type) { + case VK_IMAGE_TYPE_2D: + flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHX|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHX; + compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX; + break; + default: + break; + } + + *external_properties = (VkExternalMemoryPropertiesKHX) { + .externalMemoryFeatures = flags, + .exportFromImportedHandleTypes = export_flags, + .compatibleHandleTypes = compat_flags, + }; +} + VkResult radv_GetPhysicalDeviceImageFormatProperties2KHR( VkPhysicalDevice physicalDevice, - const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo, - VkImageFormatProperties2KHR *pImageFormatProperties) + const VkPhysicalDeviceImageFormatInfo2KHR *base_info, + VkImageFormatProperties2KHR *base_props) { - return radv_GetPhysicalDeviceImageFormatProperties(physicalDevice, - pImageFormatInfo->format, - pImageFormatInfo->type, - pImageFormatInfo->tiling, - pImageFormatInfo->usage, - pImageFormatInfo->flags, - &pImageFormatProperties->imageFormatProperties); + RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice); + const VkPhysicalDeviceExternalImageFormatInfoKHX *external_info = NULL; + VkExternalImageFormatPropertiesKHX *external_props = NULL; + VkResult result; + + result = radv_get_image_format_properties(physical_device, base_info, + &base_props->imageFormatProperties); + if (result != VK_SUCCESS) + return result; + + /* Extract input structs */ + vk_foreach_struct_const(s, base_info->pNext) { + switch (s->sType) { + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHX: + external_info = (const void *) s; + break; + default: + break; + } + } + + /* Extract output structs */ + vk_foreach_struct(s, base_props->pNext) { + switch (s->sType) { + case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHX: + external_props = (void *) s; + break; + default: + break; + } + } + + /* From the Vulkan 1.0.42 spec: + * + * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will + * behave as if VkPhysicalDeviceExternalImageFormatInfoKHX was not + * present and VkExternalImageFormatPropertiesKHX will be ignored. + */ + if (external_info && external_info->handleType != 0) { + switch (external_info->handleType) { + case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX: + get_external_image_format_properties(base_info, &external_props->externalMemoryProperties); + break; + default: + /* From the Vulkan 1.0.42 spec: + * + * If handleType is not compatible with the [parameters] specified + * in VkPhysicalDeviceImageFormatInfo2KHR, then + * vkGetPhysicalDeviceImageFormatProperties2KHR returns + * VK_ERROR_FORMAT_NOT_SUPPORTED. + */ + result = vk_errorf(VK_ERROR_FORMAT_NOT_SUPPORTED, + "unsupported VkExternalMemoryTypeFlagBitsKHX 0x%x", + external_info->handleType); + goto fail; + } + } + + return VK_SUCCESS; + +fail: + if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) { + /* From the Vulkan 1.0.42 spec: + * + * If the combination of parameters to + * vkGetPhysicalDeviceImageFormatProperties2KHR is not supported by + * the implementation for use in vkCreateImage, then all members of + * imageFormatProperties will be filled with zero. + */ + base_props->imageFormatProperties = (VkImageFormatProperties) {0}; + } + + return result; } void radv_GetPhysicalDeviceSparseImageFormatProperties( @@ -1157,3 +1267,11 @@ void radv_GetPhysicalDeviceSparseImageFormatProperties2KHR( /* Sparse images are not yet supported. */ *pPropertyCount = 0; } + +void radv_GetPhysicalDeviceExternalBufferPropertiesKHX( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalBufferInfoKHX *pExternalBufferInfo, + VkExternalBufferPropertiesKHX *pExternalBufferProperties) +{ + +} diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index cdbe6a6dced2..a4a97e9b43ba 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -510,7 +510,7 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state) (instr->variables[0]->var->data.mode == nir_var_uniform && glsl_get_base_type(type) == GLSL_TYPE_SUBROUTINE)); validate_assert(state, instr->num_components == glsl_get_vector_elements(type)); - validate_assert(state, instr->variables[0]->var->data.mode != nir_var_shader_in && + validate_assert(state, /*instr->variables[0]->var->data.mode != nir_var_shader_in &&*/ instr->variables[0]->var->data.mode != nir_var_uniform && instr->variables[0]->var->data.mode != nir_var_shader_storage); validate_assert(state, (nir_intrinsic_write_mask(instr) & ~((1 << instr->num_components) - 1)) == 0); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp index 444686fdc799..f4ea71d96e32 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp @@ -754,8 +754,12 @@ lp_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes) llvm::Argument *A = llvm::unwrap(val); llvm::AttrBuilder B; B.addDereferenceableAttr(bytes); +#if HAVE_LLVM >= 0x0500 + A->addAttr(llvm::AttributeList::get(A->getContext(), A->getArgNo() + 1, B)); +#else A->addAttr(llvm::AttributeSet::get(A->getContext(), A->getArgNo() + 1, B)); #endif +#endif } extern "C" LLVMValueRef