| @@ -1560,6 +1560,57 @@ static VkFormat map_fmt_to_rep(VkFormat fmt, enum FFVkShaderRepFormat rep_fmt) · 1559 unmodified lines |
| 1560 | return VK_FORMAT_UNDEFINED; | 1560 | return VK_FORMAT_UNDEFINED; |
| 1561 | } | 1561 | } |
| 1562 | | 1562 | |
| | 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 | |
| 1563 | int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, | 1614 | int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, |
| 1564 | VkImageView views[AV_NUM_DATA_POINTERS], | 1615 | VkImageView views[AV_NUM_DATA_POINTERS], |
| 1565 | AVFrame *f, enum FFVkShaderRepFormat rep_fmt) | 1616 | AVFrame *f, enum FFVkShaderRepFormat rep_fmt) |