[Mesa-dev] [PATCH 4/5] vulkan/wsi: Use the interface from the real modifiers extension
Jason Ekstrand
jason at jlekstrand.net
Mon Oct 1 21:24:28 UTC 2018
The anv implementation still isn't quite complete, but we can at least
start using the structs from the real extension.
---
src/intel/vulkan/anv_extensions.py | 1 +
src/intel/vulkan/anv_formats.c | 13 ++++---
src/intel/vulkan/anv_image.c | 29 +++++++++++---
src/intel/vulkan/anv_wsi.c | 8 ----
src/vulkan/wsi/wsi_common.c | 61 ++++++++++++++++++++----------
src/vulkan/wsi/wsi_common.h | 20 +---------
6 files changed, 72 insertions(+), 60 deletions(-)
diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
index d4915c95013..e8d2150e641 100644
--- a/src/intel/vulkan/anv_extensions.py
+++ b/src/intel/vulkan/anv_extensions.py
@@ -121,6 +121,7 @@ EXTENSIONS = [
Extension('VK_EXT_external_memory_dma_buf', 1, True),
Extension('VK_EXT_global_priority', 1,
'device->has_context_priority'),
+ Extension('VK_EXT_image_drm_format_modifier', 1, False),
Extension('VK_EXT_shader_viewport_index_layer', 1, True),
Extension('VK_EXT_shader_stencil_export', 1, 'device->info.gen >= 9'),
Extension('VK_EXT_vertex_attribute_divisor', 3, True),
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index d44aae1c127..89ec4965f9f 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -661,11 +661,12 @@ get_buffer_format_features(const struct gen_device_info *devinfo,
static void
get_wsi_format_modifier_properties_list(const struct anv_physical_device *physical_device,
VkFormat vk_format,
- struct wsi_format_modifier_properties_list *list)
+ struct VkDrmFormatModifierPropertiesListEXT *list)
{
const struct anv_format *anv_format = anv_get_format(vk_format);
- VK_OUTARRAY_MAKE(out, list->modifier_properties, &list->modifier_count);
+ VK_OUTARRAY_MAKE(out, list->pDrmFormatModifierProperties,
+ &list->drmFormatModifierCount);
/* This is a simplified list where all the modifiers are available */
assert(vk_format == VK_FORMAT_B8G8R8_SRGB ||
@@ -690,11 +691,11 @@ get_wsi_format_modifier_properties_list(const struct anv_physical_device *physic
continue;
vk_outarray_append(&out, mod_props) {
- mod_props->modifier = modifiers[i];
+ mod_props->drmFormatModifier = modifiers[i];
if (isl_drm_modifier_has_aux(modifiers[i]))
- mod_props->modifier_plane_count = 2;
+ mod_props->drmFormatModifierPlaneCount = 2;
else
- mod_props->modifier_plane_count = anv_format->n_planes;
+ mod_props->drmFormatModifierPlaneCount = anv_format->n_planes;
}
}
}
@@ -732,7 +733,7 @@ void anv_GetPhysicalDeviceFormatProperties2(
vk_foreach_struct(ext, pFormatProperties->pNext) {
/* Use unsigned since some cases are not in the VkStructureType enum. */
switch ((unsigned)ext->sType) {
- case VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA:
+ case VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT:
get_wsi_format_modifier_properties_list(physical_device, format,
(void *)ext);
break;
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 70594d6c053..2850349a619 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -109,6 +109,8 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
case VK_IMAGE_TILING_LINEAR:
flags = ISL_TILING_LINEAR_BIT;
break;
+ case VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT:
+ flags = 1 << isl_mod_info->tiling;
}
if (anv_info->isl_tiling_flags)
@@ -117,9 +119,6 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
if (legacy_scanout)
flags &= ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT;
- if (isl_mod_info)
- flags &= 1 << isl_mod_info->tiling;
-
assert(flags);
return flags;
@@ -563,10 +562,13 @@ anv_image_create(VkDevice _device,
const struct wsi_image_create_info *wsi_info =
vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
- if (wsi_info && wsi_info->modifier_count > 0) {
+
+ if (pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
+ const VkImageDrmFormatModifierListCreateInfoEXT *mod_info =
+ vk_find_struct_const(pCreateInfo->pNext, IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT);
isl_mod_info = choose_drm_format_mod(&device->instance->physicalDevice,
- wsi_info->modifier_count,
- wsi_info->modifiers);
+ mod_info->drmFormatModifierCount,
+ mod_info->pDrmFormatModifiers);
assert(isl_mod_info);
}
@@ -788,6 +790,21 @@ void anv_GetImageSubresourceLayout(
}
}
+VkResult anv_GetImageDrmFormatModifierPropertiesEXT(
+ VkDevice device,
+ VkImage _image,
+ VkImageDrmFormatModifierPropertiesEXT* pProperties)
+{
+ ANV_FROM_HANDLE(anv_image, image, _image);
+
+ assert(pProperties->sType =
+ VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT);
+
+ pProperties->drmFormatModifier = image->drm_format_mod;
+
+ return VK_SUCCESS;
+}
+
/**
* This function determines the optimal buffer to use for a given
* VkImageLayout and other pieces of information needed to make that
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index 5ed1d711689..77264a5d10c 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -33,13 +33,6 @@ anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
return anv_lookup_entrypoint(&physical_device->info, pName);
}
-static uint64_t
-anv_wsi_image_get_modifier(VkImage _image)
-{
- ANV_FROM_HANDLE(anv_image, image, _image);
- return image->drm_format_mod;
-}
-
VkResult
anv_init_wsi(struct anv_physical_device *physical_device)
{
@@ -54,7 +47,6 @@ anv_init_wsi(struct anv_physical_device *physical_device)
return result;
physical_device->wsi_device.supports_modifiers = true;
- physical_device->wsi_device.image_get_modifier = anv_wsi_image_get_modifier;
return VK_SUCCESS;
}
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index 00d6b5dcaa7..52a91ad9450 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -70,6 +70,7 @@ wsi_device_init(struct wsi_device *wsi,
WSI_GET_CB(FreeMemory);
WSI_GET_CB(FreeCommandBuffers);
WSI_GET_CB(GetBufferMemoryRequirements);
+ WSI_GET_CB(GetImageDrmFormatModifierPropertiesEXT);
WSI_GET_CB(GetImageMemoryRequirements);
WSI_GET_CB(GetImageSubresourceLayout);
WSI_GET_CB(GetMemoryFdKHR);
@@ -223,14 +224,9 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
image->fds[i] = -1;
- struct wsi_image_create_info image_wsi_info = {
- .sType = VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,
- .pNext = NULL,
- };
-
- const VkImageCreateInfo image_info = {
+ VkImageCreateInfo image_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .pNext = &image_wsi_info,
+ .pNext = NULL,
.flags = 0,
.imageType = VK_IMAGE_TYPE_2D,
.format = pCreateInfo->imageFormat,
@@ -250,17 +246,25 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
};
+ struct wsi_image_create_info image_wsi_info;
+ VkImageDrmFormatModifierListCreateInfoEXT image_modifier_list;
+
uint32_t image_modifier_count = 0, modifier_prop_count = 0;
- struct wsi_format_modifier_properties *modifier_props = NULL;
+ struct VkDrmFormatModifierPropertiesEXT *modifier_props = NULL;
uint64_t *image_modifiers = NULL;
if (num_modifier_lists == 0) {
/* If we don't have modifiers, fall back to the legacy "scanout" flag */
- image_wsi_info.scanout = true;
+ image_wsi_info = (struct wsi_image_create_info) {
+ .sType = VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,
+ .pNext = image_info.pNext,
+ .scanout = true,
+ };
+ image_info.pNext = &image_wsi_info;
} else {
/* The winsys can't request modifiers if we don't support them. */
assert(wsi->supports_modifiers);
- struct wsi_format_modifier_properties_list modifier_props_list = {
- .sType = VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA,
+ struct VkDrmFormatModifierPropertiesListEXT modifier_props_list = {
+ .sType = VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
.pNext = NULL,
};
VkFormatProperties2KHR format_props = {
@@ -270,10 +274,10 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
wsi->GetPhysicalDeviceFormatProperties2KHR(wsi->pdevice,
pCreateInfo->imageFormat,
&format_props);
- assert(modifier_props_list.modifier_count > 0);
+ assert(modifier_props_list.drmFormatModifierCount > 0);
modifier_props = vk_alloc(&chain->alloc,
sizeof(*modifier_props) *
- modifier_props_list.modifier_count,
+ modifier_props_list.drmFormatModifierCount,
8,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (!modifier_props) {
@@ -281,11 +285,11 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
goto fail;
}
- modifier_props_list.modifier_properties = modifier_props;
+ modifier_props_list.pDrmFormatModifierProperties = modifier_props;
wsi->GetPhysicalDeviceFormatProperties2KHR(wsi->pdevice,
pCreateInfo->imageFormat,
&format_props);
- modifier_prop_count = modifier_props_list.modifier_count;
+ modifier_prop_count = modifier_props_list.drmFormatModifierCount;
uint32_t max_modifier_count = 0;
for (uint32_t l = 0; l < num_modifier_lists; l++)
@@ -308,7 +312,7 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
*/
for (uint32_t i = 0; i < num_modifiers[l]; i++) {
for (uint32_t j = 0; j < modifier_prop_count; j++) {
- if (modifier_props[j].modifier == modifiers[l][i])
+ if (modifier_props[j].drmFormatModifier == modifiers[l][i])
image_modifiers[image_modifier_count++] = modifiers[l][i];
}
}
@@ -319,8 +323,14 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
}
if (image_modifier_count > 0) {
- image_wsi_info.modifier_count = image_modifier_count;
- image_wsi_info.modifiers = image_modifiers;
+ image_modifier_list = (VkImageDrmFormatModifierListCreateInfoEXT) {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT,
+ .pNext = image_info.pNext,
+ .drmFormatModifierCount = image_modifier_count,
+ .pDrmFormatModifiers = image_modifiers,
+ };
+ image_info.pNext = &image_modifier_list;
+ image_info.tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
} else {
/* TODO: Add a proper error here */
assert(!"Failed to find a supported modifier! This should never "
@@ -383,12 +393,21 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
goto fail;
if (num_modifier_lists > 0) {
- image->drm_modifier = wsi->image_get_modifier(image->image);
+ VkImageDrmFormatModifierPropertiesEXT image_mod_props = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
+ .pNext = NULL,
+ };
+ result = wsi->GetImageDrmFormatModifierPropertiesEXT(chain->device,
+ image->image,
+ &image_mod_props);
+ if (result != VK_SUCCESS)
+ goto fail;
+ image->drm_modifier = image_mod_props.drmFormatModifier;
assert(image->drm_modifier != DRM_FORMAT_MOD_INVALID);
for (uint32_t j = 0; j < modifier_prop_count; j++) {
- if (modifier_props[j].modifier == image->drm_modifier) {
- image->num_planes = modifier_props[j].modifier_plane_count;
+ if (modifier_props[j].drmFormatModifier == image->drm_modifier) {
+ image->num_planes = modifier_props[j].drmFormatModifierPlaneCount;
break;
}
}
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
index 14f65097bb3..69f0a52c3e8 100644
--- a/src/vulkan/wsi/wsi_common.h
+++ b/src/vulkan/wsi/wsi_common.h
@@ -35,16 +35,12 @@
*/
#define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
#define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
-#define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
#define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
struct wsi_image_create_info {
VkStructureType sType;
const void *pNext;
bool scanout;
-
- uint32_t modifier_count;
- const uint64_t *modifiers;
};
struct wsi_memory_allocate_info {
@@ -53,20 +49,6 @@ struct wsi_memory_allocate_info {
bool implicit_sync;
};
-struct wsi_format_modifier_properties {
- uint64_t modifier;
- uint32_t modifier_plane_count;
-};
-
-/* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
-struct wsi_format_modifier_properties_list {
- VkStructureType sType;
- const void *pNext;
-
- uint32_t modifier_count;
- struct wsi_format_modifier_properties *modifier_properties;
-};
-
/* To be chained into VkSurfaceCapabilities2KHR */
struct wsi_surface_supported_counters {
VkStructureType sType;
@@ -95,7 +77,6 @@ struct wsi_device {
uint32_t queue_family_count;
bool supports_modifiers;
- uint64_t (*image_get_modifier)(VkImage image);
#define WSI_CB(cb) PFN_vk##cb cb
WSI_CB(AllocateMemory);
@@ -116,6 +97,7 @@ struct wsi_device {
WSI_CB(FreeMemory);
WSI_CB(FreeCommandBuffers);
WSI_CB(GetBufferMemoryRequirements);
+ WSI_CB(GetImageDrmFormatModifierPropertiesEXT);
WSI_CB(GetImageMemoryRequirements);
WSI_CB(GetImageSubresourceLayout);
WSI_CB(GetMemoryFdKHR);
--
2.17.1
More information about the mesa-dev
mailing list