4 #include "texture_backend.h"
12 VulkanTexture::VulkanTexture(unsigned t):
13 device(Device::get_current()),
17 VulkanTexture::VulkanTexture(VulkanTexture &&other):
20 view_handle(other.view_handle),
21 view_type(other.view_type),
22 debug_name(move(other.debug_name))
25 other.view_handle = 0;
28 VulkanTexture::~VulkanTexture()
31 device.get_destroy_queue().destroy(view_handle);
34 void VulkanTexture::allocate()
36 const Texture &self = *static_cast<const Texture *>(this);
37 const VulkanFunctions &vk = device.get_functions();
40 throw logic_error("Texture image allocation is unimplemented");
42 VkImageViewCreateInfo view_info = { };
43 view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
44 view_info.image = handle_cast<::VkImage>(handle);
45 view_info.viewType = static_cast<VkImageViewType>(view_type);
46 view_info.format = static_cast<VkFormat>(get_vulkan_pixelformat(self.storage_fmt));
48 const unsigned *swizzle_order = get_vulkan_swizzle(self.swizzle);
49 view_info.components.r = static_cast<VkComponentSwizzle>(swizzle_order[0]);
50 view_info.components.g = static_cast<VkComponentSwizzle>(swizzle_order[1]);
51 view_info.components.b = static_cast<VkComponentSwizzle>(swizzle_order[2]);
52 view_info.components.a = static_cast<VkComponentSwizzle>(swizzle_order[3]);
54 view_info.subresourceRange.aspectMask = get_vulkan_aspect(get_components(self.storage_fmt));
55 view_info.subresourceRange.baseMipLevel = 0;
56 view_info.subresourceRange.levelCount = 1;
57 view_info.subresourceRange.baseArrayLayer = 0;
58 view_info.subresourceRange.layerCount = 1;
60 vk.CreateImageView(view_info, view_handle);
62 if(!debug_name.empty())
63 set_vulkan_object_names();
66 void VulkanTexture::generate_mipmap()
68 throw logic_error("VulkanTexture::generate_mipmap is unimplemented");
71 void VulkanTexture::set_debug_name(const string &name)
76 set_vulkan_object_names();
82 void VulkanTexture::set_vulkan_object_names() const
85 const VulkanFunctions &vk = device.get_functions();
87 string view_name = debug_name+"/view";
88 VkDebugUtilsObjectNameInfoEXT name_info = { };
89 name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
90 name_info.objectType = VK_OBJECT_TYPE_IMAGE_VIEW;
91 name_info.objectHandle = reinterpret_cast<uint64_t>(view_handle);
92 name_info.pObjectName = view_name.c_str();
93 vk.SetDebugUtilsObjectName(name_info);