Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
On 14 February 2018 at 17:58, Jason Ekstrandwrote: > I've added the following to the top of wsi_create_native_image: > > + /* If we don't support modifiers, the winsys code shouldn't be asking > for > +* an image with modifiers. > +*/ > + assert(wsi->supports_modifiers || num_modifier_lists == 0); > >> >> Yeah, it was mostly based on missing the wsi->has_modifiers check in >> the Wayland > > > Wayland definitely has the check. I'll double-check on X11. It didn't. I've added it in my branch, which I've been holding off on sending out whilst we try to converge here. I'm currently doing a last sweep through the X11 modifiers support from Louis-Francis as well. https://gitlab.collabora.com/daniels/mesa # wip/dri3-v1.1 Cheers, Daniel ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
On Wed, Feb 14, 2018 at 8:35 AM, Daniel Stonewrote: > On 14 February 2018 at 16:21, Jason Ekstrand wrote: > > On Wed, Feb 14, 2018 at 4:13 AM, Daniel Stone > wrote: > >> Suggested fixup: https://hastebin.com/zaheyoriwa > >> > >> This makes sure we only try to allocate with modifiers when _both_ > >> winsys and driver support it. > > > > Ok, we clearly have different philosophies here so we should get that > > sorted. My philosophy is that the winsys code will look at the > > wsi_device::supports_modifiers flag and not ask for modifiers if it's > false. > > You seem to think that the winsys code should just go ahead and ask for > > modifiers all the time and we will try to deal with it in > wsi_create_native. > > Thoughts? Arguments? Strong opinions? > > > > If we keep my philosophy, we should add asserts to better document and > > enforce it. > I've added the following to the top of wsi_create_native_image: + /* If we don't support modifiers, the winsys code shouldn't be asking for +* an image with modifiers. +*/ + assert(wsi->supports_modifiers || num_modifier_lists == 0); > Yeah, it was mostly based on missing the wsi->has_modifiers check in > the Wayland Wayland definitely has the check. I'll double-check on X11. > code, and it being totally absent in the X11/DRI3 code > (trivial to add). So my philosophy was mostly about avoiding asserts, > rather than strong feelings about who should do the filtering. > > I'm happy to stick with how you have it, plus asserts. Thanks for the > explanation! > > Cheers, > Daniel > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
On 14 February 2018 at 16:21, Jason Ekstrandwrote: > On Wed, Feb 14, 2018 at 4:13 AM, Daniel Stone wrote: >> Suggested fixup: https://hastebin.com/zaheyoriwa >> >> This makes sure we only try to allocate with modifiers when _both_ >> winsys and driver support it. > > Ok, we clearly have different philosophies here so we should get that > sorted. My philosophy is that the winsys code will look at the > wsi_device::supports_modifiers flag and not ask for modifiers if it's false. > You seem to think that the winsys code should just go ahead and ask for > modifiers all the time and we will try to deal with it in wsi_create_native. > Thoughts? Arguments? Strong opinions? > > If we keep my philosophy, we should add asserts to better document and > enforce it. Yeah, it was mostly based on missing the wsi->has_modifiers check in the Wayland code, and it being totally absent in the X11/DRI3 code (trivial to add). So my philosophy was mostly about avoiding asserts, rather than strong feelings about who should do the filtering. I'm happy to stick with how you have it, plus asserts. Thanks for the explanation! Cheers, Daniel ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
On Wed, Feb 14, 2018 at 4:13 AM, Daniel Stonewrote: > Hi, > > On 13 February 2018 at 22:29, Jason Ekstrand wrote: > > On Tue, Feb 13, 2018 at 10:55 AM, Daniel Stone > wrote: > >> > + uint64_t modifiers[] = { > >> > + DRM_FORMAT_MOD_LINEAR, > >> > + I915_FORMAT_MOD_X_TILED, > >> > + I915_FORMAT_MOD_Y_TILED, > >> > + I915_FORMAT_MOD_Y_TILED_CCS, > >> > + }; > >> > >> Can this please be inverted to preferred-first? Most of the other APIs > >> do this, so you can pop the head off the list. > > > > If someone is popping the head of the list, they're using modifiers > wrong. > > When we get Chad's extension in full, they're going to have to also call > > vkGetPhysicalDeviceImageFormatProperties to verify that your parameters > > actually work with the modifier. There may be other restrictions. For > > instance, we're likely to disallow CCS for storage images. > > Yeah, that makes sense. > > >> > +static uint32_t > >> > +score_drm_format_mod(uint64_t modifier) > >> > +{ > >> > + switch (modifier) { > >> > + case DRM_FORMAT_MOD_LINEAR: return 1; > >> > + case I915_FORMAT_MOD_X_TILED: return 2; > >> > + case I915_FORMAT_MOD_Y_TILED: return 3; > >> > + case I915_FORMAT_MOD_Y_TILED_CCS: return 4; > >> > + default: unreachable("bad DRM format modifier"); > >> > + } > >> > +} > >> > >> If the array previously could be shared, you could just score based on > >> the modifier's index in the array, rather than explicit scoring as > >> here. > > > > True. It's really too bad that they're in different files. I'm not > > entirely happy that anv_image and anv_format are split up. I've also > > thought about trying to move some of it into ISL but that's a bit sticky > > because the list of supported modifiers needs to be per-driver since > things > > like Y_TILED_CCS takes a little extra work in each driver. All in all, > it's > > not a lot of code duplication so meh? > > Yeah, I don't actually really feel at all strongly about it tbh. > > >> > @@ -367,13 +367,9 @@ wsi_create_native_image(const struct > wsi_swapchain > >> > *chain, > >> > if (result != VK_SUCCESS) > >> >goto fail; > >> > > >> > - if (wsi->supports_modifiers) > >> > + if (image_modifier_count > 0) { > >> >image->drm_modifier = wsi->image_get_modifier(image->image); > >> > - else > >> > - image->drm_modifier = DRM_FORMAT_MOD_INVALID; > >> > >> Belongs in a previous patch, and also going along the right lines but > >> not quite correct. ;) The other hunks also need to be squashed into > >> some other patch. > > > > I'm not sure what you mean by "not quite correct". I've moved it into > > "vulkan/wsi: Add modifiers support to wsi_create_native_image" > > Suggested fixup: https://hastebin.com/zaheyoriwa > > This makes sure we only try to allocate with modifiers when _both_ > winsys and driver support it. > Ok, we clearly have different philosophies here so we should get that sorted. My philosophy is that the winsys code will look at the wsi_device::supports_modifiers flag and not ask for modifiers if it's false. You seem to think that the winsys code should just go ahead and ask for modifiers all the time and we will try to deal with it in wsi_create_native. Thoughts? Arguments? Strong opinions? If we keep my philosophy, we should add asserts to better document and enforce it. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
Hi, On 13 February 2018 at 22:29, Jason Ekstrandwrote: > On Tue, Feb 13, 2018 at 10:55 AM, Daniel Stone wrote: >> > + uint64_t modifiers[] = { >> > + DRM_FORMAT_MOD_LINEAR, >> > + I915_FORMAT_MOD_X_TILED, >> > + I915_FORMAT_MOD_Y_TILED, >> > + I915_FORMAT_MOD_Y_TILED_CCS, >> > + }; >> >> Can this please be inverted to preferred-first? Most of the other APIs >> do this, so you can pop the head off the list. > > If someone is popping the head of the list, they're using modifiers wrong. > When we get Chad's extension in full, they're going to have to also call > vkGetPhysicalDeviceImageFormatProperties to verify that your parameters > actually work with the modifier. There may be other restrictions. For > instance, we're likely to disallow CCS for storage images. Yeah, that makes sense. >> > +static uint32_t >> > +score_drm_format_mod(uint64_t modifier) >> > +{ >> > + switch (modifier) { >> > + case DRM_FORMAT_MOD_LINEAR: return 1; >> > + case I915_FORMAT_MOD_X_TILED: return 2; >> > + case I915_FORMAT_MOD_Y_TILED: return 3; >> > + case I915_FORMAT_MOD_Y_TILED_CCS: return 4; >> > + default: unreachable("bad DRM format modifier"); >> > + } >> > +} >> >> If the array previously could be shared, you could just score based on >> the modifier's index in the array, rather than explicit scoring as >> here. > > True. It's really too bad that they're in different files. I'm not > entirely happy that anv_image and anv_format are split up. I've also > thought about trying to move some of it into ISL but that's a bit sticky > because the list of supported modifiers needs to be per-driver since things > like Y_TILED_CCS takes a little extra work in each driver. All in all, it's > not a lot of code duplication so meh? Yeah, I don't actually really feel at all strongly about it tbh. >> > @@ -367,13 +367,9 @@ wsi_create_native_image(const struct wsi_swapchain >> > *chain, >> > if (result != VK_SUCCESS) >> >goto fail; >> > >> > - if (wsi->supports_modifiers) >> > + if (image_modifier_count > 0) { >> >image->drm_modifier = wsi->image_get_modifier(image->image); >> > - else >> > - image->drm_modifier = DRM_FORMAT_MOD_INVALID; >> >> Belongs in a previous patch, and also going along the right lines but >> not quite correct. ;) The other hunks also need to be squashed into >> some other patch. > > I'm not sure what you mean by "not quite correct". I've moved it into > "vulkan/wsi: Add modifiers support to wsi_create_native_image" Suggested fixup: https://hastebin.com/zaheyoriwa This makes sure we only try to allocate with modifiers when _both_ winsys and driver support it. Cheers, Daniel ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
On Tue, Feb 13, 2018 at 10:55 AM, Daniel Stonewrote: > Hi Jason, > > On 9 February 2018 at 23:43, Jason Ekstrand wrote: > > +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) > > +{ > > + const struct anv_format *anv_format = anv_get_format(vk_format); > > + > > + VK_OUTARRAY_MAKE(out, list->modifier_properties, > >modifier_count); > > + > > + /* This is a simplified list where all the modifiers are available */ > > + assert(vk_format == VK_FORMAT_B8G8R8_SRGB || > > + vk_format == VK_FORMAT_B8G8R8_UNORM || > > + vk_format == VK_FORMAT_B8G8R8A8_SRGB || > > + vk_format == VK_FORMAT_B8G8R8A8_UNORM); > > + > > + uint64_t modifiers[] = { > > + DRM_FORMAT_MOD_LINEAR, > > + I915_FORMAT_MOD_X_TILED, > > + I915_FORMAT_MOD_Y_TILED, > > + I915_FORMAT_MOD_Y_TILED_CCS, > > + }; > > Can this please be inverted to preferred-first? Most of the other APIs > do this, so you can pop the head off the list. > If someone is popping the head of the list, they're using modifiers wrong. When we get Chad's extension in full, they're going to have to also call vkGetPhysicalDeviceImageFormatProperties to verify that your parameters actually work with the modifier. There may be other restrictions. For instance, we're likely to disallow CCS for storage images. > > +static uint32_t > > +score_drm_format_mod(uint64_t modifier) > > +{ > > + switch (modifier) { > > + case DRM_FORMAT_MOD_LINEAR: return 1; > > + case I915_FORMAT_MOD_X_TILED: return 2; > > + case I915_FORMAT_MOD_Y_TILED: return 3; > > + case I915_FORMAT_MOD_Y_TILED_CCS: return 4; > > + default: unreachable("bad DRM format modifier"); > > + } > > +} > > If the array previously could be shared, you could just score based on > the modifier's index in the array, rather than explicit scoring as > here. > True. It's really too bad that they're in different files. I'm not entirely happy that anv_image and anv_format are split up. I've also thought about trying to move some of it into ISL but that's a bit sticky because the list of supported modifiers needs to be per-driver since things like Y_TILED_CCS takes a little extra work in each driver. All in all, it's not a lot of code duplication so meh? > > @@ -706,8 +747,13 @@ void anv_GetImageSubresourceLayout( > > VkSubresourceLayout*layout) > > { > > ANV_FROM_HANDLE(anv_image, image, _image); > > - const struct anv_surface *surface = > > - get_surface(image, subresource->aspectMask); > > + > > + const struct anv_surface *surface; > > + if (subresource->aspectMask == VK_IMAGE_ASPECT_PLANE_1_BIT_KHR && > > + isl_drm_modifier_has_aux(image->drm_format_mod)) > > + surface = >planes[0].aux_surface; > > + else > > + surface = get_surface(image, subresource->aspectMask); > > It would probably be easier to split this up: just core modifier (and > Y-tiling) support in this patch, and CCS/aux support in a follow-up > one. Ditto the next two hunks. > > > @@ -367,13 +367,9 @@ wsi_create_native_image(const struct wsi_swapchain > *chain, > > if (result != VK_SUCCESS) > >goto fail; > > > > - if (wsi->supports_modifiers) > > + if (image_modifier_count > 0) { > >image->drm_modifier = wsi->image_get_modifier(image->image); > > - else > > - image->drm_modifier = DRM_FORMAT_MOD_INVALID; > > Belongs in a previous patch, and also going along the right lines but > not quite correct. ;) The other hunks also need to be squashed into > some other patch. > I'm not sure what you mean by "not quite correct". I've moved it into "vulkan/wsi: Add modifiers support to wsi_create_native_image" > I'm happy with the rest though; looks good from what I can see, and > the new WSI bits have made life much easier! > > Cheers, > Daniel > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
Hi Jason, On 9 February 2018 at 23:43, Jason Ekstrandwrote: > +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) > +{ > + const struct anv_format *anv_format = anv_get_format(vk_format); > + > + VK_OUTARRAY_MAKE(out, list->modifier_properties, >modifier_count); > + > + /* This is a simplified list where all the modifiers are available */ > + assert(vk_format == VK_FORMAT_B8G8R8_SRGB || > + vk_format == VK_FORMAT_B8G8R8_UNORM || > + vk_format == VK_FORMAT_B8G8R8A8_SRGB || > + vk_format == VK_FORMAT_B8G8R8A8_UNORM); > + > + uint64_t modifiers[] = { > + DRM_FORMAT_MOD_LINEAR, > + I915_FORMAT_MOD_X_TILED, > + I915_FORMAT_MOD_Y_TILED, > + I915_FORMAT_MOD_Y_TILED_CCS, > + }; Can this please be inverted to preferred-first? Most of the other APIs do this, so you can pop the head off the list. > +static uint32_t > +score_drm_format_mod(uint64_t modifier) > +{ > + switch (modifier) { > + case DRM_FORMAT_MOD_LINEAR: return 1; > + case I915_FORMAT_MOD_X_TILED: return 2; > + case I915_FORMAT_MOD_Y_TILED: return 3; > + case I915_FORMAT_MOD_Y_TILED_CCS: return 4; > + default: unreachable("bad DRM format modifier"); > + } > +} If the array previously could be shared, you could just score based on the modifier's index in the array, rather than explicit scoring as here. > @@ -706,8 +747,13 @@ void anv_GetImageSubresourceLayout( > VkSubresourceLayout*layout) > { > ANV_FROM_HANDLE(anv_image, image, _image); > - const struct anv_surface *surface = > - get_surface(image, subresource->aspectMask); > + > + const struct anv_surface *surface; > + if (subresource->aspectMask == VK_IMAGE_ASPECT_PLANE_1_BIT_KHR && > + isl_drm_modifier_has_aux(image->drm_format_mod)) > + surface = >planes[0].aux_surface; > + else > + surface = get_surface(image, subresource->aspectMask); It would probably be easier to split this up: just core modifier (and Y-tiling) support in this patch, and CCS/aux support in a follow-up one. Ditto the next two hunks. > @@ -367,13 +367,9 @@ wsi_create_native_image(const struct wsi_swapchain > *chain, > if (result != VK_SUCCESS) >goto fail; > > - if (wsi->supports_modifiers) > + if (image_modifier_count > 0) { >image->drm_modifier = wsi->image_get_modifier(image->image); > - else > - image->drm_modifier = DRM_FORMAT_MOD_INVALID; Belongs in a previous patch, and also going along the right lines but not quite correct. ;) The other hunks also need to be squashed into some other patch. I'm happy with the rest though; looks good from what I can see, and the new WSI bits have made life much easier! Cheers, Daniel ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 13/16] anv/image: Add support for modifiers for WSI
This adds support for the modifiers portion of the WSI "extension". --- src/intel/vulkan/anv_formats.c | 39 ++ src/intel/vulkan/anv_image.c | 93 +- src/intel/vulkan/anv_private.h | 6 +++ src/intel/vulkan/anv_wsi.c | 24 +-- src/vulkan/wsi/wsi_common.c| 9 ++-- 5 files changed, 142 insertions(+), 29 deletions(-) diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 4075ae8..cd63879 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -22,6 +22,7 @@ */ #include "anv_private.h" +#include "drm_fourcc.h" #include "vk_enum_to_str.h" #include "vk_format_info.h" #include "vk_util.h" @@ -651,6 +652,39 @@ get_buffer_format_features(const struct gen_device_info *devinfo, return flags; } +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) +{ + const struct anv_format *anv_format = anv_get_format(vk_format); + + VK_OUTARRAY_MAKE(out, list->modifier_properties, >modifier_count); + + /* This is a simplified list where all the modifiers are available */ + assert(vk_format == VK_FORMAT_B8G8R8_SRGB || + vk_format == VK_FORMAT_B8G8R8_UNORM || + vk_format == VK_FORMAT_B8G8R8A8_SRGB || + vk_format == VK_FORMAT_B8G8R8A8_UNORM); + + uint64_t modifiers[] = { + DRM_FORMAT_MOD_LINEAR, + I915_FORMAT_MOD_X_TILED, + I915_FORMAT_MOD_Y_TILED, + I915_FORMAT_MOD_Y_TILED_CCS, + }; + + for (uint32_t i = 0; i < ARRAY_SIZE(modifiers); i++) { + vk_outarray_append(, mod_props) { + mod_props->modifier = modifiers[i]; + if (isl_drm_modifier_has_aux(modifiers[i])) +mod_props->modifier_plane_count = 2; + else +mod_props->modifier_plane_count = anv_format->n_planes; + } + } +} + void anv_GetPhysicalDeviceFormatProperties( VkPhysicalDevicephysicalDevice, VkFormatvk_format, @@ -677,11 +711,16 @@ void anv_GetPhysicalDeviceFormatProperties2KHR( VkFormatformat, VkFormatProperties2KHR* pFormatProperties) { + ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); anv_GetPhysicalDeviceFormatProperties(physicalDevice, format, >formatProperties); vk_foreach_struct(ext, pFormatProperties->pNext) { switch (ext->sType) { + case VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA: + get_wsi_format_modifier_properties_list(physical_device, format, + (void *)ext); + break; default: anv_debug_ignored_stype(ext->sType); break; diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 355aff0..9bb0cad 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -508,6 +508,39 @@ make_surface(const struct anv_device *dev, return VK_SUCCESS; } +static uint32_t +score_drm_format_mod(uint64_t modifier) +{ + switch (modifier) { + case DRM_FORMAT_MOD_LINEAR: return 1; + case I915_FORMAT_MOD_X_TILED: return 2; + case I915_FORMAT_MOD_Y_TILED: return 3; + case I915_FORMAT_MOD_Y_TILED_CCS: return 4; + default: unreachable("bad DRM format modifier"); + } +} + +static const struct isl_drm_modifier_info * +choose_drm_format_mod(const struct anv_physical_device *device, + uint32_t modifier_count, const uint64_t *modifiers) +{ + uint64_t best_mod = UINT64_MAX; + uint32_t best_score = 0; + + for (uint32_t i = 0; i < modifier_count; ++i) { + uint32_t score = score_drm_format_mod(modifiers[i]); + if (score > best_score) { + best_mod = modifiers[i]; + best_score = score; + } + } + + if (best_score > 0) + return isl_drm_modifier_get_info(best_mod); + else + return NULL; +} + VkResult anv_image_create(VkDevice _device, const struct anv_image_create_info *create_info, @@ -524,6 +557,12 @@ 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) { + isl_mod_info = choose_drm_format_mod(>instance->physicalDevice, + wsi_info->modifier_count, + wsi_info->modifiers); + assert(isl_mod_info); + } anv_assert(pCreateInfo->mipLevels > 0); anv_assert(pCreateInfo->arrayLayers > 0); @@ -549,6 +588,8 @@ anv_image_create(VkDevice _device, image->tiling = pCreateInfo->tiling; image->disjoint =