Plasma Engine  2.0
Loading...
Searching...
No Matches
TextureVulkan.h
1#pragma once
2
3#include <RendererFoundation/Resources/Texture.h>
4
5#include <vulkan/vulkan.hpp>
6
9
11{
12public:
13 enum class StagingMode : plUInt8
14 {
15 None,
16 Buffer,
17 Texture,
19 };
21 {
22 PL_DECLARE_POD_TYPE();
23 plUInt32 m_uiOffset;
24 plUInt32 m_uiSize;
25 plUInt32 m_uiRowLength;
26 plUInt32 m_uiImageHeight;
27 };
28
29 PL_ALWAYS_INLINE vk::Image GetImage() const;
30 PL_ALWAYS_INLINE vk::Format GetImageFormat() const { return m_imageFormat; }
31 PL_ALWAYS_INLINE vk::ImageLayout GetPreferredLayout() const;
32 PL_ALWAYS_INLINE vk::ImageLayout GetPreferredLayout(vk::ImageLayout targetLayout) const;
33 PL_ALWAYS_INLINE vk::PipelineStageFlags GetUsedByPipelineStage() const;
34 PL_ALWAYS_INLINE vk::AccessFlags GetAccessMask() const;
35
36 PL_ALWAYS_INLINE plVulkanAllocation GetAllocation() const;
37 PL_ALWAYS_INLINE const plVulkanAllocationInfo& GetAllocationInfo() const;
38
39 PL_ALWAYS_INLINE bool IsLinearLayout() const;
40
41 vk::Extent3D GetMipLevelSize(plUInt32 uiMipLevel) const;
42 vk::ImageSubresourceRange GetFullRange() const;
43 vk::ImageAspectFlags GetAspectMask() const;
44
45 // Read-back staging resources
46 PL_ALWAYS_INLINE StagingMode GetStagingMode() const;
47 PL_ALWAYS_INLINE plGALTextureHandle GetStagingTexture() const;
48 PL_ALWAYS_INLINE plGALBufferHandle GetStagingBuffer() const;
49 plUInt32 ComputeSubResourceOffsets(plDynamicArray<SubResourceOffset>& out_subResourceOffsets) const;
50
51protected:
52 friend class plGALDeviceVulkan;
53 friend class plMemoryUtils;
54
55 plGALTextureVulkan(const plGALTextureCreationDescription& Description, bool bLinearCPU, bool bStaging);
56
58
59 virtual plResult InitPlatform(plGALDevice* pDevice, plArrayPtr<plGALSystemMemoryDescription> pInitialData) override;
60 virtual plResult DeInitPlatform(plGALDevice* pDevice) override;
61 virtual void SetDebugNamePlatform(const char* szName) const override;
62
63 static vk::Format ComputeImageFormat(plGALDeviceVulkan* pDevice, plEnum<plGALResourceFormat> galFormat, vk::ImageCreateInfo& ref_createInfo, vk::ImageFormatListCreateInfo& ref_imageFormats, bool bStaging);
64 static void ComputeCreateInfo(plGALDeviceVulkan* pDevice, const plGALTextureCreationDescription& description, vk::ImageCreateInfo& ref_createInfo, vk::PipelineStageFlags& ref_stages, vk::AccessFlags& ref_access, vk::ImageLayout& ref_preferredLayout);
65 static void ComputeCreateInfoLinear(vk::ImageCreateInfo& ref_createInfo, vk::PipelineStageFlags& ref_stages, vk::AccessFlags& ref_access);
66 static void ComputeAllocInfo(bool bLinearCPU, plVulkanAllocationCreateInfo& ref_allocInfo);
67 static StagingMode ComputeStagingMode(plGALDeviceVulkan* pDevice, const plGALTextureCreationDescription& description, const vk::ImageCreateInfo& createInfo);
68
69 plResult CreateStagingBuffer(const vk::ImageCreateInfo& createInfo);
70
71 vk::Image m_image;
72 vk::Format m_imageFormat = vk::Format::eUndefined;
73 vk::ImageLayout m_preferredLayout = vk::ImageLayout::eUndefined;
74 vk::PipelineStageFlags m_stages = {};
75 vk::AccessFlags m_access = {};
76
77 plVulkanAllocation m_alloc = nullptr;
78 plVulkanAllocationInfo m_allocInfo;
79
80 plGALDeviceVulkan* m_pDevice = nullptr;
81
82 bool m_bLinearCPU = false;
83 bool m_bStaging = false;
84
85 StagingMode m_stagingMode = StagingMode::None;
86 plGALTextureHandle m_hStagingTexture;
87 plGALBufferHandle m_hStagingBuffer;
88};
89
90
91
92#include <RendererVulkan/Resources/Implementation/TextureVulkan_inl.h>
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition DynamicArray.h:81
Definition RendererFoundationDLL.h:418
Definition BufferVulkan.h:11
The plRenderDevice class is the primary interface for interactions with rendering APIs It contains a ...
Definition Device.h:19
The Vulkan device implementation of the graphics abstraction layer.
Definition DeviceVulkan.h:58
Definition RendererFoundationDLL.h:411
Definition Texture.h:8
Definition TextureVulkan.h:11
StagingMode
Definition TextureVulkan.h:14
@ TextureAndBuffer
Formats differ and linear texture can't be rendered to. Render to optimal layout GPU texture and then...
@ Buffer
We can use vkCopyImageToBuffer to a CPU buffer.
@ Texture
Formats differ and we need to render to a linear CPU texture to do the conversion.
This class provides functions to work on raw memory.
Definition MemoryUtils.h:26
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition Descriptors.h:177
Definition TextureVulkan.h:21
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Subset of VmaAllocationCreateInfo. Duplicated for abstraction purposes.
Definition MemoryAllocatorVulkan.h:69
Subset of VmaAllocationInfo. Duplicated for abstraction purposes.
Definition MemoryAllocatorVulkan.h:78