Skip to content

Commit fb5bd47

Browse files
author
devsh
committed
Cleaned up the IDeviceMemoryBacked SCreationParams and placed a limit on total Queue Familiy counts
Also added some getters to `IDeviceMemoryAllocator`
1 parent d980fa2 commit fb5bd47

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

include/nbl/video/IDeviceMemoryAllocator.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
namespace nbl::video
1010
{
1111

12-
class IDeviceMemoryAllocator
12+
class NBL_API2 IDeviceMemoryAllocator
1313
{
1414
public:
15+
// right now we only support this interface handing out memory for one device or group
16+
virtual ILogicalDevice* getDeviceForAllocations() const = 0;
17+
1518
struct SAllocateInfo
1619
{
1720
size_t size : 54 = 0ull;
@@ -21,6 +24,21 @@ class IDeviceMemoryAllocator
2124
// size_t opaqueCaptureAddress = 0u; Note that this mechanism is intended only to support capture/replay tools, and is not recommended for use in other applications.
2225
};
2326

27+
struct SAllocation
28+
{
29+
static constexpr size_t InvalidMemoryOffset = 0xdeadbeefBadC0ffeull;
30+
bool isValid() const
31+
{
32+
return memory && (offset!=InvalidMemoryOffset);
33+
}
34+
35+
core::smart_refctd_ptr<IDeviceMemoryAllocation> memory = nullptr;
36+
size_t offset = InvalidMemoryOffset;
37+
};
38+
39+
virtual SAllocation allocate(const SAllocateInfo& info) = 0;
40+
41+
2442
//! IMemoryTypeIterator extracts memoryType indices from memoryTypeBits in arbitrary order
2543
//! which is used to give priority to memoryTypes in try-allocate usages where allocations may fail with some memoryTypes
2644
//! IMemoryTypeIterator will construct SAllocateInfo from object's memory requirements, allocateFlags and dedication using operator()
@@ -85,20 +103,6 @@ class IDeviceMemoryAllocator
85103

86104
uint32_t currentIndex = 0u;
87105
};
88-
89-
90-
struct SAllocation
91-
{
92-
static constexpr size_t InvalidMemoryOffset = 0xdeadbeefBadC0ffeull;
93-
bool isValid() const
94-
{
95-
return memory && (offset!=InvalidMemoryOffset);
96-
}
97-
98-
core::smart_refctd_ptr<IDeviceMemoryAllocation> memory = nullptr;
99-
size_t offset = InvalidMemoryOffset;
100-
};
101-
virtual SAllocation allocate(const SAllocateInfo& info) = 0;
102106

103107
template<class memory_type_iterator_t=DefaultMemoryTypeIterator>
104108
inline SAllocation allocate(

include/nbl/video/IDeviceMemoryBacked.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ class IDeviceMemoryBacked : public IBackendObject
2626
{
2727
public:
2828
//!
29-
struct SCachedCreationParams
29+
constexpr static inline uint8_t MaxQueueFamilies = 7;
30+
struct SCreationParams
3031
{
3132
// A Pre-Destroy-Step is called out just before a `vkDestory` or `glDelete`, this is only useful for "imported" resources
3233
std::unique_ptr<ICleanup> preDestroyCleanup = nullptr;
3334
// A Post-Destroy-Step is called in this class' destructor, this is only useful for "imported" resources
3435
std::unique_ptr<ICleanup> postDestroyCleanup = nullptr;
3536
// If more than one, then we're doing concurrent resource sharing
3637
uint8_t queueFamilyIndexCount = 0u;
38+
const uint32_t* queueFamilyIndices = nullptr;
3739
// Thus the destructor will skip the call to `vkDestroy` or `glDelete` on the handle, this is only useful for "imported" objects
3840
bool skipHandleDestroy = false;
3941

@@ -43,7 +45,8 @@ class IDeviceMemoryBacked : public IBackendObject
4345
return queueFamilyIndexCount>1u;
4446
}
4547
};
46-
inline const SCachedCreationParams& getCachedCreationParams() const {return m_cachedCreationParams;}
48+
// TODO: change name later on, but right now too much code to refactor
49+
inline const SCreationParams& getCachedCreationParams() const {return m_cachedCreationParams;}
4750

4851
//! We need to know to cast to `IGPUBuffer` or `IGPUImage`
4952
enum E_OBJECT_TYPE : bool
@@ -87,15 +90,14 @@ class IDeviceMemoryBacked : public IBackendObject
8790
//! Returns the allocation which is bound to the resource
8891
virtual SMemoryBinding getBoundMemory() const = 0;
8992

90-
//! For constructor parameter only
91-
struct SCreationParams : SCachedCreationParams
92-
{
93-
const uint32_t* queueFamilyIndices = nullptr;
94-
};
95-
9693
protected:
9794
inline IDeviceMemoryBacked(core::smart_refctd_ptr<const ILogicalDevice>&& originDevice, SCreationParams&& creationParams, const SDeviceMemoryRequirements& reqs)
98-
: IBackendObject(std::move(originDevice)), m_cachedCreationParams(std::move(creationParams)), m_cachedMemoryReqs(reqs) {}
95+
: IBackendObject(std::move(originDevice)), m_cachedCreationParams(std::move(creationParams)), m_cachedMemoryReqs(reqs)
96+
{
97+
std::fill_n(m_queueFamilies,MaxQueueFamilies,~0u);
98+
std::copy_n(m_cachedCreationParams.queueFamilyIndices,m_cachedCreationParams.queueFamilyIndexCount,m_queueFamilies);
99+
m_cachedCreationParams.queueFamilyIndices = m_queueFamilies;
100+
}
99101
inline virtual ~IDeviceMemoryBacked()
100102
{
101103
assert(!m_cachedCreationParams.preDestroyCleanup); // derived class should have already cleared this out
@@ -109,8 +111,9 @@ class IDeviceMemoryBacked : public IBackendObject
109111

110112

111113
//! members
112-
SCachedCreationParams m_cachedCreationParams;
114+
SCreationParams m_cachedCreationParams;
113115
SDeviceMemoryRequirements m_cachedMemoryReqs;
116+
uint32_t m_queueFamilies[MaxQueueFamilies];
114117
};
115118

116119
template<typename T>

include/nbl/video/ILogicalDevice.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class IPhysicalDevice;
2626
class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMemoryAllocator
2727
{
2828
public:
29-
constexpr static inline uint8_t MaxQueueFamilies = 7;
29+
inline ILogicalDevice* getDeviceForAllocations() const override {return const_cast<ILogicalDevice*>(this);}
30+
31+
constexpr static inline uint8_t MaxQueueFamilies = IDeviceMemoryBacked::MaxQueueFamilies;
3032
struct SQueueCreationParams
3133
{
3234
constexpr static inline uint8_t MaxQueuesInFamily = 15;
@@ -331,6 +333,11 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
331333
m_logger.log("Failed to create Buffer, size %d larger than Device %p's limit (%u)!",system::ILogger::ELL_ERROR,creationParams.size,this,maxSize);
332334
return nullptr;
333335
}
336+
if (creationParams.queueFamilyIndexCount>MaxQueueFamilies)
337+
{
338+
m_logger.log("Failed to create Buffer, queue family count %d for concurrent sharing larger than our max %d!",system::ILogger::ELL_ERROR,creationParams.queueFamilyIndexCount,MaxQueueFamilies);
339+
return nullptr;
340+
}
334341
return createBuffer_impl(std::move(creationParams));
335342
}
336343
// Create a BufferView, to a shader; a fake 1D-like texture with no interpolation (@see ICPUBufferView)
@@ -343,7 +350,12 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
343350
m_logger.log("Failed to create Image, invalid creation parameters!",system::ILogger::ELL_ERROR);
344351
return nullptr;
345352
}
346-
// TODO: @Cyprian validation of creationParams against the device's limits (sample counts, etc.) see vkCreateImage
353+
if (creationParams.queueFamilyIndexCount>MaxQueueFamilies)
354+
{
355+
m_logger.log("Failed to create Image, queue family count %d for concurrent sharing larger than our max %d!",system::ILogger::ELL_ERROR,creationParams.queueFamilyIndexCount,MaxQueueFamilies);
356+
return nullptr;
357+
}
358+
// TODO: validation of creationParams against the device's limits (sample counts, etc.) see vkCreateImage docs
347359
return createImage_impl(std::move(creationParams));
348360
}
349361
// Create an ImageView that can actually be used by shaders (@see ICPUImageView)

0 commit comments

Comments
 (0)