Diligent Engine  v.2.4.g
TextureVkImpl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
32 
33 #include "EngineVkImplTraits.hpp"
34 #include "TextureBase.hpp"
35 #include "TextureViewVkImpl.hpp"
37 
38 namespace Diligent
39 {
40 
42 class TextureVkImpl final : public TextureBase<EngineVkImplTraits>
43 {
44 public:
47 
48  // Creates a new Vk resource
49  TextureVkImpl(IReferenceCounters* pRefCounters,
50  FixedBlockMemoryAllocator& TexViewObjAllocator,
51  RenderDeviceVkImpl* pDeviceVk,
52  const TextureDesc& TexDesc,
53  const TextureData* pInitData = nullptr);
54 
55  // Attaches to an existing Vk resource
56  TextureVkImpl(IReferenceCounters* pRefCounters,
57  FixedBlockMemoryAllocator& TexViewObjAllocator,
58  class RenderDeviceVkImpl* pDeviceVk,
59  const TextureDesc& TexDesc,
60  RESOURCE_STATE InitialState,
61  VkImage VkImageHandle);
62 
64 
66 
67 
68  virtual VkImage DILIGENT_CALL_TYPE GetVkImage() const override final { return m_VulkanImage; }
69 
71  virtual void* DILIGENT_CALL_TYPE GetNativeHandle() override final
72  {
73  auto vkImage = GetVkImage();
74  return reinterpret_cast<void*>(vkImage);
75  }
76 
78  virtual void DILIGENT_CALL_TYPE SetLayout(VkImageLayout Layout) override final;
79 
81  virtual VkImageLayout DILIGENT_CALL_TYPE GetLayout() const override final;
82 
83  VkBuffer GetVkStagingBuffer() const
84  {
85  return m_StagingBuffer;
86  }
87 
88  uint8_t* GetStagingDataCPUAddress() const
89  {
90  auto* StagingDataCPUAddress = reinterpret_cast<uint8_t*>(m_MemoryAllocation.Page->GetCPUMemory());
91  VERIFY_EXPR(StagingDataCPUAddress != nullptr);
92  StagingDataCPUAddress += m_StagingDataAlignedOffset;
93  return StagingDataCPUAddress;
94  }
95 
96  void InvalidateStagingRange(VkDeviceSize Offset, VkDeviceSize Size);
97 
98  // Buffer offset must be a multiple of 4 (18.4)
99  static constexpr Uint32 StagingBufferOffsetAlignment = 4;
100 
101 protected:
102  void CreateViewInternal(const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView) override;
103  //void PrepareVkInitData(const TextureData &InitData, Uint32 NumSubresources, std::vector<Vk_SUBRESOURCE_DATA> &VkInitData);
104 
105  bool CheckCSBasedMipGenerationSupport(VkFormat vkFmt) const;
106 
108 
114 };
115 
116 } // namespace Diligent
Diligent::TextureVkImpl::CreateImageView
VulkanUtilities::ImageViewWrapper CreateImageView(TextureViewDesc &ViewDesc)
Definition: TextureVkImpl.cpp:609
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::TextureVkImpl::InvalidateStagingRange
void InvalidateStagingRange(VkDeviceSize Offset, VkDeviceSize Size)
Definition: TextureVkImpl.cpp:789
Diligent::RenderDeviceVkImpl
Render device implementation in Vulkan backend.
Definition: RenderDeviceVkImpl.hpp:58
VulkanUtilities::ImageViewWrapper
DEFINE_VULKAN_OBJECT_WRAPPER(ImageView) ImageViewWrapper
Definition: VulkanLogicalDevice.hpp:72
VulkanUtilities::ImageWrapper
DEFINE_VULKAN_OBJECT_WRAPPER(Image) ImageWrapper
Definition: VulkanLogicalDevice.hpp:71
Diligent::ITextureView
Texture view interface.
Definition: TextureView.h:202
Diligent::TextureViewVkImpl
Texture view implementation in Vulkan backend.
Definition: TextureViewVkImpl.hpp:41
Diligent::TextureVkImpl::m_MemoryAllocation
VulkanUtilities::VulkanMemoryAllocation m_MemoryAllocation
Definition: TextureVkImpl.hpp:111
Diligent::TextureVkImpl::GetVkImage
virtual VkImage GetVkImage() const override final
Implementation of ITextureVk::GetVkImage().
Definition: TextureVkImpl.hpp:68
VulkanUtilities::BufferWrapper
DEFINE_VULKAN_OBJECT_WRAPPER(Buffer) BufferWrapper
Definition: VulkanLogicalDevice.hpp:69
Diligent::TextureVkImpl::m_StagingBuffer
VulkanUtilities::BufferWrapper m_StagingBuffer
Definition: TextureVkImpl.hpp:110
Diligent::TextureVkImpl::TextureVkImpl
TextureVkImpl(IReferenceCounters *pRefCounters, FixedBlockMemoryAllocator &TexViewObjAllocator, RenderDeviceVkImpl *pDeviceVk, const TextureDesc &TexDesc, const TextureData *pInitData=nullptr)
Definition: TextureVkImpl.cpp:41
Diligent::TextureDesc
Texture description.
Definition: Texture.h:47
Diligent::TextureVkImpl::GetStagingDataCPUAddress
uint8_t * GetStagingDataCPUAddress() const
Definition: TextureVkImpl.hpp:88
Diligent::TextureVkImpl::GetLayout
virtual VkImageLayout GetLayout() const override final
Implementation of ITextureVk::GetLayout().
Definition: TextureVkImpl.cpp:784
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::TextureData
Describes the initial data to store in the texture.
Definition: Texture.h:221
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::TextureBase
Base implementation of the ITexture interface.
Definition: TextureBase.hpp:71
Diligent::TextureVkImpl::GetVkStagingBuffer
VkBuffer GetVkStagingBuffer() const
Definition: TextureVkImpl.hpp:83
Diligent::TextureVkImpl::GetNativeHandle
virtual void * GetNativeHandle() override final
Implementation of ITexture::GetNativeHandle() in Vulkan backend.
Definition: TextureVkImpl.hpp:71
Diligent::TextureVkImpl
Texture object implementation in Vulkan backend.
Definition: TextureVkImpl.hpp:42
Diligent::TextureVkImpl::StagingBufferOffsetAlignment
static constexpr Uint32 StagingBufferOffsetAlignment
Definition: TextureVkImpl.hpp:99
Diligent::TextureVkImpl::m_StagingDataAlignedOffset
VkDeviceSize m_StagingDataAlignedOffset
Definition: TextureVkImpl.hpp:112
VERIFY_EXPR
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
VulkanUtilities::VulkanMemoryAllocation::Page
VulkanMemoryPage * Page
Definition: VulkanMemoryManager.hpp:90
Diligent::TextureVkImpl::CheckCSBasedMipGenerationSupport
bool CheckCSBasedMipGenerationSupport(VkFormat vkFmt) const
Definition: TextureVkImpl.cpp:761
Diligent::TextureVkImpl::~TextureVkImpl
~TextureVkImpl()
Definition: TextureVkImpl.cpp:598
Diligent::FixedBlockMemoryAllocator
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.hpp:56
EngineVkImplTraits.hpp
Diligent::RESOURCE_STATE
RESOURCE_STATE
Resource usage state.
Definition: GraphicsTypes.h:2814
VulkanUtilities::VulkanMemoryPage::GetCPUMemory
void * GetCPUMemory() const
Definition: VulkanMemoryManager.hpp:129
Diligent::TextureVkImpl::m_VulkanImage
VulkanUtilities::ImageWrapper m_VulkanImage
Definition: TextureVkImpl.hpp:109
Diligent::TextureViewDesc
Texture view description.
Definition: TextureView.h:80
Diligent::TextureVkImpl::SetLayout
virtual void SetLayout(VkImageLayout Layout) override final
Implementation of ITextureVk::SetLayout().
Definition: TextureVkImpl.cpp:779
TextureBase.hpp
Diligent::TextureVkImpl::m_bCSBasedMipGenerationSupported
bool m_bCSBasedMipGenerationSupported
Definition: TextureVkImpl.hpp:113
TextureViewVkImpl.hpp
VulkanUtilities::VulkanMemoryAllocation
Definition: VulkanMemoryManager.hpp:48
VulkanMemoryManager.hpp
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::TextureVkImpl::CreateViewInternal
void CreateViewInternal(const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView) override
Definition: TextureVkImpl.cpp:520