summaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan/radv_formats.c
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2016-11-03 04:16:43 +0000
committerBas Nieuwenhuizen <[email protected]>2017-06-05 02:26:43 +0200
commit4ba2e6cbfab2ac5adc3d4fe1d35a32cc582781dc (patch)
tree7a319495088a8f8fcc8ae16ccec34b4857c03823 /src/amd/vulkan/radv_formats.c
parentd515b420ddaa3b83cc565567d0c229e717aab06a (diff)
radv: add external memory support.
This adds support for exporting 2D images, to an opaque fd. This implements the: VK_KHX_external_memory_capabilities VK_KHX_external_memory VK_KHX_external_memory_fd extensions. These are used by SteamVR, we should work with anv to decide if we should ship these under an env var or something. v2 (Bas): - Don't expose the semaphore ext without implementing it. - Only export the capabilities ext as instance ext. - Implement radv_GetPhysicalDeviceExternalBufferPropertiesKHX. Signed-off-by: Dave Airlie <[email protected]> Signed-off-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src/amd/vulkan/radv_formats.c')
-rw-r--r--src/amd/vulkan/radv_formats.c121
1 files changed, 120 insertions, 1 deletions
diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c
index 8da18189df0..6cff0a5384e 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"
@@ -1140,14 +1141,107 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties(
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 *base_info,
VkImageFormatProperties2KHR *base_props)
{
RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
- return radv_get_image_format_properties(physical_device, base_info,
+ 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(
@@ -1173,3 +1267,28 @@ void radv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
/* Sparse images are not yet supported. */
*pPropertyCount = 0;
}
+
+void radv_GetPhysicalDeviceExternalBufferPropertiesKHX(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceExternalBufferInfoKHX *pExternalBufferInfo,
+ VkExternalBufferPropertiesKHX *pExternalBufferProperties)
+{
+ VkExternalMemoryFeatureFlagBitsKHX flags = 0;
+ VkExternalMemoryHandleTypeFlagsKHX export_flags = 0;
+ VkExternalMemoryHandleTypeFlagsKHX compat_flags = 0;
+ switch(pExternalBufferInfo->handleType) {
+ case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX:
+ 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;
+ }
+ pExternalBufferProperties->externalMemoryProperties = (VkExternalMemoryPropertiesKHX) {
+ .externalMemoryFeatures = flags,
+ .exportFromImportedHandleTypes = export_flags,
+ .compatibleHandleTypes = compat_flags,
+ };
+}