MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Init

Method Init

Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.cpp:14–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "Engine/Scripting/Enums.h"
13
14void GPUTextureViewVulkan::Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* owner, VkImage image, int32 totalMipLevels, PixelFormat format, MSAALevel msaa, VkExtent3D extent, VkImageViewType viewType, int32 mipLevels, int32 firstMipIndex, int32 arraySize, int32 firstArraySlice, bool readOnlyDepth, bool stencilView)
15{
16 ASSERT(View == VK_NULL_HANDLE);
17
18 GPUTextureView::Init(owner->AsGPUResource(), format, msaa);
19
20 Device = device;
21 Owner = owner;
22 Image = image;
23 Extent.width = Math::Max<uint32_t>(1, extent.width >> firstMipIndex);
24 Extent.height = Math::Max<uint32_t>(1, extent.height >> firstMipIndex);
25 Extent.depth = Math::Max<uint32_t>(1, extent.depth >> firstMipIndex);
26 Layers = arraySize;
27#if VULKAN_USE_DEBUG_DATA
28 Format = format;
29 ReadOnlyDepth = readOnlyDepth;
30#endif
31
32 RenderToolsVulkan::ZeroStruct(Info, VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO);
33 Info.image = image;
34 Info.viewType = viewType;
35 Info.format = RenderToolsVulkan::ToVulkanFormat(format);
36 Info.components =
37 {
38 VK_COMPONENT_SWIZZLE_R,
39 VK_COMPONENT_SWIZZLE_G,
40 VK_COMPONENT_SWIZZLE_B,
41 VK_COMPONENT_SWIZZLE_A
42 };
43
44 auto& range = Info.subresourceRange;
45 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
46 range.baseMipLevel = firstMipIndex;
47 range.levelCount = mipLevels;
48 range.baseArrayLayer = firstArraySlice;
49 range.layerCount = arraySize;
50
51 if (mipLevels != 1 || arraySize != 1)
52 {
53 SubresourceIndex = -1;
54 }
55 else
56 {
57 SubresourceIndex = RenderTools::CalcSubresourceIndex(firstMipIndex, firstArraySlice, totalMipLevels);
58 }
59
60 if (stencilView)
61 {
62 range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
63 LayoutRTV = readOnlyDepth ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
64 LayoutSRV = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
65 }
66 else if (PixelFormatExtensions::IsDepthStencil(format))
67 {
68 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
69#if 0
70 // TODO: enable extension and use separateDepthStencilLayouts from Vulkan 1.2
71 if (PixelFormatExtensions::HasStencil(format))

Callers 3

OnInitMethod · 0.45
initHandlesMethod · 0.45
OnResidentMipsChangedMethod · 0.45

Calls 5

CalcSubresourceIndexFunction · 0.85
HasStencilFunction · 0.85
InitFunction · 0.50
IsDepthStencilFunction · 0.50
AsGPUResourceMethod · 0.45

Tested by

no test coverage detected