3 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "vkelementutils.h"
28 fill_vulkan_image_view_info (VkImage image, VkFormat format,
29 VkImageViewCreateInfo * info)
32 *info = (VkImageViewCreateInfo) {
33 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
37 .viewType = VK_IMAGE_VIEW_TYPE_2D,
39 .components = (VkComponentMapping) {
40 VK_COMPONENT_SWIZZLE_R,
41 VK_COMPONENT_SWIZZLE_G,
42 VK_COMPONENT_SWIZZLE_B,
43 VK_COMPONENT_SWIZZLE_A
45 .subresourceRange = (VkImageSubresourceRange) {
46 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
57 find_compatible_view (GstVulkanImageView * view, VkImageViewCreateInfo * info)
59 return view->create_info.image == info->image
60 && view->create_info.format == info->format
61 && view->create_info.viewType == info->viewType
62 && view->create_info.flags == info->flags
63 && view->create_info.components.r == info->components.r
64 && view->create_info.components.g == info->components.g
65 && view->create_info.components.b == info->components.b
66 && view->create_info.components.a == info->components.a
67 && view->create_info.subresourceRange.aspectMask ==
68 info->subresourceRange.aspectMask
69 && view->create_info.subresourceRange.baseMipLevel ==
70 info->subresourceRange.baseMipLevel
71 && view->create_info.subresourceRange.levelCount ==
72 info->subresourceRange.levelCount
73 && view->create_info.subresourceRange.levelCount ==
74 info->subresourceRange.levelCount
75 && view->create_info.subresourceRange.baseArrayLayer ==
76 info->subresourceRange.baseArrayLayer
77 && view->create_info.subresourceRange.layerCount ==
78 info->subresourceRange.layerCount;
82 get_or_create_image_view (GstVulkanImageMemory * image)
84 VkImageViewCreateInfo create_info;
85 GstVulkanImageView *ret = NULL;
87 fill_vulkan_image_view_info (image->image, image->create_info.format,
90 ret = gst_vulkan_image_memory_find_view (image,
91 (GstVulkanImageMemoryFindViewFunc) find_compatible_view, &create_info);
93 ret = gst_vulkan_image_view_new (image, &create_info);
94 gst_vulkan_image_memory_add_view (image, ret);