History

vulkan: add ff_vk_create_imageview

Lynne committed 1 year ago

Commit ed6ee321 parent 7046e652 files · +58 −0Browse files

Unified · Split

2 files
  1. libavutil/vulkan.c +51 −0
  2. libavutil/vulkan.h +7 −0
libavutil/vulkan.c+51−0
@@ -1560,6 +1560,57 @@ static VkFormat map_fmt_to_rep(VkFormat fmt, enum FFVkShaderRepFormat rep_fmt) · 1559 unmodified lines
15601560 return VK_FORMAT_UNDEFINED;
15611561 }
15621562
1563+int ff_vk_create_imageview(FFVulkanContext *s,
1564+ VkImageView *img_view, VkImageAspectFlags *aspect,
1565+ AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt)
1566+{
1567+ VkResult ret;
1568+ FFVulkanFunctions *vk = &s->vkfn;
1569+ AVHWFramesContext *hwfc = (AVHWFramesContext *)f->hw_frames_ctx->data;
1570+ AVVulkanFramesContext *vkfc = hwfc->hwctx;
1571+ const VkFormat *rep_fmts = av_vkfmt_from_pixfmt(hwfc->sw_format);
1572+ AVVkFrame *vkf = (AVVkFrame *)f->data[0];
1573+ const int nb_images = ff_vk_count_images(vkf);
1574+
1575+ VkImageViewUsageCreateInfo view_usage_info = {
1576+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO,
1577+ .usage = vkfc->usage &
1578+ (~(VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR |
1579+ VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)),
1580+ };
1581+ VkImageViewCreateInfo view_create_info = {
1582+ .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1583+ .pNext = &view_usage_info,
1584+ .image = vkf->img[FFMIN(plane, nb_images - 1)],
1585+ .viewType = VK_IMAGE_VIEW_TYPE_2D,
1586+ .format = map_fmt_to_rep(rep_fmts[plane], rep_fmt),
1587+ .components = ff_comp_identity_map,
1588+ .subresourceRange = {
1589+ .aspectMask = ff_vk_aspect_flag(f, plane),
1590+ .levelCount = 1,
1591+ .layerCount = 1,
1592+ },
1593+ };
1594+ if (view_create_info.format == VK_FORMAT_UNDEFINED) {
1595+ av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
1596+ "of format %i and mode %i\n",
1597+ rep_fmts[plane], rep_fmt);
1598+ return AVERROR(EINVAL);
1599+ }
1600+
1601+ ret = vk->CreateImageView(s->hwctx->act_dev, &view_create_info,
1602+ s->hwctx->alloc, img_view);
1603+ if (ret != VK_SUCCESS) {
1604+ av_log(s, AV_LOG_ERROR, "Failed to create imageview: %s\n",
1605+ ff_vk_ret2str(ret));
1606+ return AVERROR_EXTERNAL;
1607+ }
1608+
1609+ *aspect = view_create_info.subresourceRange.aspectMask;
1610+
1611+ return 0;
1612+}
1613+
15631614 int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
15641615 VkImageView views[AV_NUM_DATA_POINTERS],
15651616 AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
libavutil/vulkan.h+7−0
@@ -457,6 +457,13 @@ int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, · 456 unmodified lines
457457 AVFrame *f);
458458 void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e);
459459
460+/**
461+ * Create a single imageview for a given plane.
462+ */
463+int ff_vk_create_imageview(FFVulkanContext *s,
464+ VkImageView *img_view, VkImageAspectFlags *aspect,
465+ AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt);
466+
460467 /**
461468 * Create an imageview and add it as a dependency to an execution.
462469 */

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