Blender V5.3
vk_image_view.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "vk_image_view.hh"
10#include "vk_backend.hh"
11#include "vk_common.hh"
12#include "vk_debug.hh"
13#include "vk_device.hh"
14#include "vk_texture.hh"
15
16namespace blender::gpu {
17
19 : info(info)
20{
21 VkImageViewCreateInfo image_view_info = {};
22 image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
23 image_view_info.image = texture.vk_image_handle();
24 image_view_info.viewType = to_vk_image_view_type(texture.type_get(), info.usage, info.arrayed);
25 image_view_info.format = info.vk_format;
26 image_view_info.components.r = to_vk_component_swizzle(info.swizzle[0]);
27 image_view_info.components.g = to_vk_component_swizzle(info.swizzle[1]);
28 image_view_info.components.b = to_vk_component_swizzle(info.swizzle[2]);
29 image_view_info.components.a = to_vk_component_swizzle(info.swizzle[3]);
30 image_view_info.subresourceRange.aspectMask = info.vk_image_aspects;
31 image_view_info.subresourceRange.baseMipLevel = info.mip_range.first();
32 image_view_info.subresourceRange.levelCount = info.mip_range.size();
33 image_view_info.subresourceRange.baseArrayLayer = info.layer_range.first();
34 image_view_info.subresourceRange.layerCount = info.layer_range.size();
35
36 /* When extended usage is enabled for storage images, it means the original format
37 * is not supported. So we must strip USAGE_STORAGE for the image view that has the
38 * same format as the image, and only leave it for the other image view with the
39 * format that will be used for storage. */
40 VkImageViewUsageCreateInfo view_usage_info = {VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO};
41 if (vk_need_extended_usage_for_storage_image(texture.usage_get(), texture.format_flag_get()) &&
42 info.vk_format == to_vk_format(texture.device_format_get()))
43 {
44 view_usage_info.usage = texture.vk_image_usage_get() & ~VK_IMAGE_USAGE_STORAGE_BIT;
45 BLI_assert(view_usage_info.usage != 0);
46 view_usage_info.pNext = image_view_info.pNext;
47 image_view_info.pNext = &view_usage_info;
48 }
49
50 VKDevice &device = VKBackend::get().device;
51 device.functions.vkCreateImageView(
52 device.vk_handle(), &image_view_info, nullptr, &vk_image_view_);
53 debug::object_label(vk_image_view_, name.c_str());
54
55 BLI_assert(texture.resource_handle() != 0);
56 device.resources.register_view(texture.resource_handle(), vk_image_view_);
57}
58
60{
61 vk_image_view_ = other.vk_image_view_;
62 other.vk_image_view_ = VK_NULL_HANDLE;
63 vk_format_ = other.vk_format_;
64 other.vk_format_ = VK_FORMAT_UNDEFINED;
65}
66
67} // namespace blender::gpu
constexpr int64_t first() const
constexpr int64_t size() const
constexpr const char * c_str() const
static VKBackend & get()
render_graph::VKResourceStateTracker resources
Definition vk_device.hh:270
VkDevice vk_handle() const
Definition vk_device.hh:338
VolkDeviceTable functions
Definition vk_device.hh:280
VKImageView(VKTexture &texture, const VKImageViewInfo &info, StringRefNull name)
const VKImageViewInfo info
void register_view(ResourceHandle resource_handle, VkView vk_view)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
void object_label(GLenum type, GLuint object, const char *name)
Definition gl_debug.cc:331
VkImageViewType to_vk_image_view_type(const GPUTextureType type, const eImageViewUsage view_type, VKImageViewArrayed arrayed)
Definition vk_common.cc:525
bool vk_need_extended_usage_for_storage_image(const eGPUTextureUsage usage, const GPUTextureFormatFlag format_flag)
Definition vk_common.cc:841
VkFormat to_vk_format(const TextureFormat format)
Definition vk_common.cc:157
VkComponentSwizzle to_vk_component_swizzle(const char swizzle)
Definition vk_common.cc:588
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VkImageAspectFlags vk_image_aspects