Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
vkTexture.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef VK_TEXTURE_H
34#define VK_TEXTURE_H
35
38
39namespace Divide
40{
41 struct AllocatedImage : private NonCopyable
42 {
44
45 VkImage _image{ VK_NULL_HANDLE };
46 VmaAllocation _allocation{ VK_NULL_HANDLE };
47 VmaAllocationInfo _allocInfo{};
48 };
49
52
53 class vkTexture final : public Texture
54 {
55 public:
56 enum class TransitionType : U8
57 {
64
71
78
82
86
89
91
94
98
101
104
109
114
117
120
123
126
128
133
135
136 COUNT
137 };
139 {
140 struct Descriptor final : Hashable
141 {
143 VkFormat _format{ VK_FORMAT_MAX_ENUM };
146 bool _resolveTarget{false};
147 [[nodiscard]] size_t getHash() const noexcept override;
148
150 VkImageView _view{VK_NULL_HANDLE};
151 };
152
154
155 virtual ~vkTexture() override;
156
157 bool unload() override;
158
159 void clearData( VkCommandBuffer cmdBuffer, const UColour4& clearColour, SubRange layerRange, U8 mipLevel ) const noexcept;
160 void generateMipmaps( VkCommandBuffer cmdBuffer, U16 baseLevel, U16 baseLayer, U16 layerCount, ImageUsage crtUsage);
161
162 PROPERTY_R( AllocatedImage_uptr, image, nullptr );
163 PROPERTY_R_IW( VkImageType, vkType, VK_IMAGE_TYPE_MAX_ENUM );
164 PROPERTY_R_IW( VkFormat, vkFormat, VK_FORMAT_MAX_ENUM );
165 PROPERTY_R_IW( VkSampleCountFlagBits, sampleFlagBits, VK_SAMPLE_COUNT_1_BIT );
166
167 [[nodiscard]] ImageReadbackData readData(U8 mipLevel, const PixelAlignment& pixelPackAlignment) const noexcept override;
168 [[nodiscard]] ImageReadbackData readData( VkCommandBuffer cmdBuffer, U8 mipLevel, const PixelAlignment& pixelPackAlignment) const noexcept;
169 [[nodiscard]] VkImageView getImageView( const CachedImageView::Descriptor& descriptor ) const;
170
171 [[nodiscard]] static VkImageAspectFlags GetAspectFlags( const TextureDescriptor& descriptor ) noexcept;
172
173 static void Copy( VkCommandBuffer cmdBuffer, const vkTexture* source, const U8 sourceSamples, const vkTexture* destination, const U8 destinationSamples, CopyTexParams params );
174
175 static void TransitionTexture( TransitionType type, const VkImageSubresourceRange& subresourceRange, VkImage image, VkImageMemoryBarrier2& memBarrier );
176
177 private:
178 void loadDataInternal( const ImageTools::ImageData& imageData, const vec3<U16>& offset, const PixelAlignment& pixelUnpackAlignment ) override;
179 void loadDataInternal( const Byte* data, size_t size, U8 targetMip, const vec3<U16>& offset, const vec3<U16>& dimensions, const PixelAlignment& pixelUnpackAlignment ) override;
180 void prepareTextureData( U16 width, U16 height, U16 depth, bool emptyAllocation ) override;
181 void clearDataInternal( const UColour4& clearColour, U8 level, bool clearRect, const vec4<I32>& rectToClear, vec2<I32> depthRange ) const;
182 void clearImageViewCache();
183
184 void loadDataInternal( const Byte* data, size_t size, U8 targetMip, const vec3<U16>& offset, const vec3<U16>& dimensions, const PixelAlignment& pixelUnpackAlignment, bool emptyAllocation );
185 private:
186 struct Mip
187 {
188 vec3<U16> _dimensions{};
189 size_t _size{0u};
190 };
191
193 VMABuffer_uptr _stagingBuffer;
194 VkDeviceSize _stagingBufferSize{ 0u };
197 };
198
199} //namespace Divide
200
201#endif //VK_TEXTURE_H
#define FWD_DECLARE_MANAGED_STRUCT(T)
GFXDevice & context() const noexcept
An API-independent representation of a texture.
Definition: Texture.h:83
static void TransitionTexture(TransitionType type, const VkImageSubresourceRange &subresourceRange, VkImage image, VkImageMemoryBarrier2 &memBarrier)
Definition: vkTexture.cpp:1011
VkDeviceSize _stagingBufferSize
Definition: vkTexture.h:194
bool unload() override
Definition: vkTexture.cpp:211
PROPERTY_R(AllocatedImage_uptr, image, nullptr)
void clearData(VkCommandBuffer cmdBuffer, const UColour4 &clearColour, SubRange layerRange, U8 mipLevel) const noexcept
Definition: vkTexture.cpp:722
static void Copy(VkCommandBuffer cmdBuffer, const vkTexture *source, const U8 sourceSamples, const vkTexture *destination, const U8 destinationSamples, CopyTexParams params)
Definition: vkTexture.cpp:969
ImageReadbackData readData(U8 mipLevel, const PixelAlignment &pixelPackAlignment) const noexcept override
Definition: vkTexture.cpp:770
VkImageView getImageView(const CachedImageView::Descriptor &descriptor) const
Definition: vkTexture.cpp:914
void clearDataInternal(const UColour4 &clearColour, U8 level, bool clearRect, const vec4< I32 > &rectToClear, vec2< I32 > depthRange) const
vector< Mip > _mipData
Definition: vkTexture.h:195
void loadDataInternal(const ImageTools::ImageData &imageData, const vec3< U16 > &offset, const PixelAlignment &pixelUnpackAlignment) override
Definition: vkTexture.cpp:593
virtual ~vkTexture() override
Definition: vkTexture.cpp:191
static VkImageAspectFlags GetAspectFlags(const TextureDescriptor &descriptor) noexcept
Definition: vkTexture.cpp:177
PROPERTY_R_IW(VkSampleCountFlagBits, sampleFlagBits, VK_SAMPLE_COUNT_1_BIT)
void prepareTextureData(U16 width, U16 height, U16 depth, bool emptyAllocation) override
Definition: vkTexture.cpp:348
hashMap< size_t, CachedImageView > _imageViewCache
Definition: vkTexture.h:192
void generateMipmaps(VkCommandBuffer cmdBuffer, U16 baseLevel, U16 baseLayer, U16 layerCount, ImageUsage crtUsage)
Definition: vkTexture.cpp:217
PROPERTY_R_IW(VkImageType, vkType, VK_IMAGE_TYPE_MAX_ENUM)
void clearImageViewCache()
Definition: vkTexture.cpp:196
PROPERTY_R_IW(VkFormat, vkFormat, VK_FORMAT_MAX_ENUM)
VMABuffer_uptr _stagingBuffer
Definition: vkTexture.h:193
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::byte Byte
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
uint16_t U16
VmaAllocationInfo _allocInfo
Definition: vkTexture.h:47
VmaAllocation _allocation
Definition: vkTexture.h:46
size_t getHash() const noexcept override
Definition: vkTexture.cpp:161
Divide::vkTexture::CachedImageView::Descriptor _descriptor