History

vulkan: workaround BGR storage image undefined behaviour

Lynne committed 1 year ago

Commit bbb06f11 parent 3c09aad1 file · +25 −0Browse files

Unified · Split

libavutil/vulkan.c+25−0
@@ -1719,6 +1719,29 @@ static VkFormat map_fmt_to_rep(VkFormat fmt, enum FFVkShaderRepFormat rep_fmt) · 1718 unmodified lines
1719 return VK_FORMAT_UNDEFINED;1719 return VK_FORMAT_UNDEFINED;
1720}1720}
1721 1721
1722static void bgr_workaround(AVVulkanFramesContext *vkfc,
1723 VkImageViewCreateInfo *ci)
1724{
1725 if (!(vkfc->usage & VK_IMAGE_USAGE_STORAGE_BIT))
1726 return;
1727 switch (ci->format) {
1728#define REMAP(src, dst) \
1729 case src: \
1730 ci->format = dst; \
1731 return;
1732 REMAP(VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM)
1733 REMAP(VK_FORMAT_B8G8R8A8_SINT, VK_FORMAT_R8G8B8A8_SINT)
1734 REMAP(VK_FORMAT_B8G8R8A8_UINT, VK_FORMAT_R8G8B8A8_UINT)
1735 REMAP(VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM)
1736 REMAP(VK_FORMAT_B8G8R8_SINT, VK_FORMAT_R8G8B8_SINT)
1737 REMAP(VK_FORMAT_B8G8R8_UINT, VK_FORMAT_R8G8B8_UINT)
1738 REMAP(VK_FORMAT_A2B10G10R10_UNORM_PACK32, VK_FORMAT_A2R10G10B10_UNORM_PACK32)
1739#undef REMAP
1740 default:
1741 return;
1742 }
1743}
1744
1722int ff_vk_create_imageview(FFVulkanContext *s,1745int ff_vk_create_imageview(FFVulkanContext *s,
1723 VkImageView *img_view, VkImageAspectFlags *aspect,1746 VkImageView *img_view, VkImageAspectFlags *aspect,
1724 AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt)1747 AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt)
@@ -1750,6 +1773,7 @@ int ff_vk_create_imageview(FFVulkanContext *s, · 25 unmodified lines
1750 .layerCount = 1,1773 .layerCount = 1,
1751 },1774 },
1752 };1775 };
1776 bgr_workaround(vkfc, &view_create_info);
1753 if (view_create_info.format == VK_FORMAT_UNDEFINED) {1777 if (view_create_info.format == VK_FORMAT_UNDEFINED) {
1754 av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "1778 av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
1755 "of format %i and mode %i\n",1779 "of format %i and mode %i\n",
@@ -1811,6 +1835,7 @@ int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, · 55 unmodified lines
1811 .layerCount = 1,1835 .layerCount = 1,
1812 },1836 },
1813 };1837 };
1838 bgr_workaround(vkfc, &view_create_info);
1814 if (view_create_info.format == VK_FORMAT_UNDEFINED) {1839 if (view_create_info.format == VK_FORMAT_UNDEFINED) {
1815 av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "1840 av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
1816 "of format %i and mode %i\n",1841 "of format %i and mode %i\n",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t