Nameless Engine
Loading...
Searching...
No Matches
DirectXResource.h
1#pragma once
2
3// Standard.
4#include <variant>
5#include <memory>
6#include <array>
7#include <optional>
8#include <mutex>
9
10// Custom.
11#include "misc/Error.h"
12#include "render/general/resource/GpuResource.h"
13#include "render/directx/descriptors/DirectXDescriptor.h"
14#include "render/directx/descriptors/DirectXDescriptorType.hpp"
15#include "material/TextureFilteringPreference.h"
16
17// External.
18#include "directx/d3dx12.h"
19#include "D3D12MemoryAllocator/include/D3D12MemAlloc.h"
20
21// OS.
22#include <wrl.h>
23
24namespace ne {
25 using namespace Microsoft::WRL;
26
27 class DirectXRenderer;
28 class DirectXDescriptorHeap;
29 class DirectXResourceManager;
30 class ContinuousDirectXDescriptorRange;
31
34 // If descriptor heap of a used descriptor (see field of this class) was recreated
35 // then descriptor heap will update our descriptors with new descriptor information.
36 friend class DirectXDescriptorHeap;
37
38 // Only resource manager can create this resource
39 // (simply because only manager has a memory allocator object).
40 friend class DirectXResourceManager;
41
42 public:
43 DirectXResource() = delete;
44 DirectXResource(const DirectXResource&) = delete;
45 DirectXResource& operator=(const DirectXResource&) = delete;
46
47 virtual ~DirectXResource() override;
48
64 [[nodiscard]] std::optional<Error> bindDescriptor(
65 DirectXDescriptorType descriptorType,
66 const std::shared_ptr<ContinuousDirectXDescriptorRange>& pRange = nullptr,
67 bool bBindDescriptorsToCubemapFaces = true);
68
77 std::optional<D3D12_CPU_DESCRIPTOR_HANDLE>
78 getBindedDescriptorCpuHandle(DirectXDescriptorType descriptorType);
79
90 std::optional<D3D12_CPU_DESCRIPTOR_HANDLE> getBindedCubemapFaceDescriptorCpuHandle(
91 DirectXDescriptorType descriptorType, size_t iCubemapFaceIndex);
92
101 std::optional<D3D12_GPU_DESCRIPTOR_HANDLE>
102 getBindedDescriptorGpuHandle(DirectXDescriptorType descriptorType);
103
113 ID3D12Resource* getInternalResource() const { return pInternalResource; }
114
125 DirectXDescriptor* getDescriptor(DirectXDescriptorType descriptorType);
126
132 TextureFilteringPreference getTextureFilteringPreference() const {
134 }
135
136 private:
143 std::unique_ptr<DirectXDescriptor> pResource;
144
149 std::array<std::unique_ptr<DirectXDescriptor>, 6> // NOLINT: 1 per cubemap face (if cubemap)
151 };
152
166 DirectXResourceManager* pResourceManager,
167 const std::string& sResourceName,
169 UINT iElementCount,
170 TextureFilteringPreference filteringPreference =
171 TextureFilteringPreference::FROM_RENDER_SETTINGS);
172
193 static std::variant<std::unique_ptr<DirectXResource>, Error> create(
194 DirectXResourceManager* pResourceManager,
195 const std::string& sResourceName,
196 D3D12MA::Allocator* pMemoryAllocator,
197 const D3D12MA::ALLOCATION_DESC& allocationDesc,
198 const D3D12_RESOURCE_DESC& resourceDesc,
199 const D3D12_RESOURCE_STATES& initialResourceState,
200 std::optional<D3D12_CLEAR_VALUE> resourceClearValue,
201 size_t iElementSizeInBytes = 0,
202 size_t iElementCount = 0,
203 TextureFilteringPreference filteringPreference =
204 TextureFilteringPreference::FROM_RENDER_SETTINGS);
205
216 static std::variant<std::unique_ptr<DirectXResource>, Error> createResourceFromSwapChainBuffer(
217 DirectXResourceManager* pResourceManager,
218 DirectXDescriptorHeap* pRtvHeap,
219 const ComPtr<ID3D12Resource>& pSwapChainBuffer);
220
231 std::pair<
232 std::recursive_mutex,
233 std::array<DescriptorsSameType, static_cast<size_t>(DirectXDescriptorType::END)>>
235
237 ComPtr<D3D12MA::Allocation> pAllocatedResource;
238
243 ComPtr<ID3D12Resource> pSwapChainBuffer;
244
249 ID3D12Resource* pInternalResource = nullptr;
250
252 const TextureFilteringPreference textureFilteringPreference;
253 };
254} // namespace ne
Definition: DirectXDescriptorHeap.h:206
Definition: DirectXDescriptor.h:21
Definition: DirectXResourceManager.h:28
Definition: DirectXResource.h:33
ComPtr< D3D12MA::Allocation > pAllocatedResource
Definition: DirectXResource.h:237
std::optional< D3D12_GPU_DESCRIPTOR_HANDLE > getBindedDescriptorGpuHandle(DirectXDescriptorType descriptorType)
Definition: DirectXResource.cpp:160
ComPtr< ID3D12Resource > pSwapChainBuffer
Definition: DirectXResource.h:243
static std::variant< std::unique_ptr< DirectXResource >, Error > create(DirectXResourceManager *pResourceManager, const std::string &sResourceName, D3D12MA::Allocator *pMemoryAllocator, const D3D12MA::ALLOCATION_DESC &allocationDesc, const D3D12_RESOURCE_DESC &resourceDesc, const D3D12_RESOURCE_STATES &initialResourceState, std::optional< D3D12_CLEAR_VALUE > resourceClearValue, size_t iElementSizeInBytes=0, size_t iElementCount=0, TextureFilteringPreference filteringPreference=TextureFilteringPreference::FROM_RENDER_SETTINGS)
Definition: DirectXResource.cpp:11
std::optional< D3D12_CPU_DESCRIPTOR_HANDLE > getBindedDescriptorCpuHandle(DirectXDescriptorType descriptorType)
Definition: DirectXResource.cpp:101
std::optional< D3D12_CPU_DESCRIPTOR_HANDLE > getBindedCubemapFaceDescriptorCpuHandle(DirectXDescriptorType descriptorType, size_t iCubemapFaceIndex)
Definition: DirectXResource.cpp:125
TextureFilteringPreference getTextureFilteringPreference() const
Definition: DirectXResource.h:132
DirectXDescriptor * getDescriptor(DirectXDescriptorType descriptorType)
Definition: DirectXResource.cpp:184
const TextureFilteringPreference textureFilteringPreference
Definition: DirectXResource.h:252
ID3D12Resource * pInternalResource
Definition: DirectXResource.h:249
std::optional< Error > bindDescriptor(DirectXDescriptorType descriptorType, const std::shared_ptr< ContinuousDirectXDescriptorRange > &pRange=nullptr, bool bBindDescriptorsToCubemapFaces=true)
Definition: DirectXResource.cpp:217
static std::variant< std::unique_ptr< DirectXResource >, Error > createResourceFromSwapChainBuffer(DirectXResourceManager *pResourceManager, DirectXDescriptorHeap *pRtvHeap, const ComPtr< ID3D12Resource > &pSwapChainBuffer)
Definition: DirectXResource.cpp:78
std::pair< std::recursive_mutex, std::array< DescriptorsSameType, static_cast< size_t >(DirectXDescriptorType::END)> > mtxHeapDescriptors
Definition: DirectXResource.h:234
ID3D12Resource * getInternalResource() const
Definition: DirectXResource.h:113
Definition: Error.h:27
Definition: GpuResource.h:16
const std::string sResourceName
Definition: GpuResource.h:97
const unsigned int iElementCount
Definition: GpuResource.h:94
const unsigned int iElementSizeInBytes
Definition: GpuResource.h:91
Definition: DirectXResource.h:141
std::unique_ptr< DirectXDescriptor > pResource
Definition: DirectXResource.h:143
std::array< std::unique_ptr< DirectXDescriptor >, 6 > vCubemapFaces
Definition: DirectXResource.h:150