Skip to content

Commit 9645154

Browse files
committed
Merge branch 'erfan_image_upload_utils'
2 parents da32613 + 89b4bd0 commit 9645154

File tree

84 files changed

+4612
-3235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4612
-3235
lines changed

include/nbl/asset/ECommonEnums.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __NBL_E_COMMON_ENUMS_H_INCLUDED__
2-
#define __NBL_E_COMMON_ENUMS_H_INCLUDED__
1+
#ifndef __NBL_ASSET_E_COMMON_ENUMS_H_INCLUDED__
2+
#define __NBL_ASSET_E_COMMON_ENUMS_H_INCLUDED__
33

44
#include "nbl/core/declarations.h"
55

@@ -66,6 +66,7 @@ enum E_PIPELINE_STAGE_FLAGS : uint32_t
6666

6767
enum E_ACCESS_FLAGS : uint32_t
6868
{
69+
EAF_NONE = 0,
6970
EAF_INDIRECT_COMMAND_READ_BIT = 0x00000001,
7071
EAF_INDEX_READ_BIT = 0x00000002,
7172
EAF_VERTEX_ATTRIBUTE_READ_BIT = 0x00000004,

include/nbl/asset/ICPUBuffer.h

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace nbl::asset
1919

2020
//! One of CPU class-object representing an Asset
2121
/**
22-
One of Assets used for storage of large arrays, so that storage can be decoupled
23-
from other objects such as meshbuffers, images, animations and shader source/bytecode.
22+
One of Assets used for storage of large arrays, so that storage can be decoupled
23+
from other objects such as meshbuffers, images, animations and shader source/bytecode.
2424
25-
@see IAsset
25+
@see IAsset
2626
*/
2727
class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
2828
{
@@ -35,12 +35,12 @@ class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
3535
//! Non-allocating constructor for CCustormAllocatorCPUBuffer derivative
3636
ICPUBuffer(size_t sizeInBytes, void* dat) : asset::IBuffer({dat ? sizeInBytes:0,EUF_TRANSFER_DST_BIT}), data(dat) {}
3737
public:
38-
//! Constructor. TODO: remove, alloc can fail, should be a static create method instead!
39-
/** @param sizeInBytes Size in bytes. If `dat` argument is present, it denotes size of data pointed by `dat`, otherwise - size of data to be allocated.
40-
*/
38+
//! Constructor. TODO: remove, alloc can fail, should be a static create method instead!
39+
/** @param sizeInBytes Size in bytes. If `dat` argument is present, it denotes size of data pointed by `dat`, otherwise - size of data to be allocated.
40+
*/
4141
ICPUBuffer(size_t sizeInBytes) : asset::IBuffer({0,EUF_TRANSFER_DST_BIT})
4242
{
43-
data = _NBL_ALIGNED_MALLOC(sizeInBytes,_NBL_SIMD_ALIGNMENT);
43+
data = _NBL_ALIGNED_MALLOC(sizeInBytes,_NBL_SIMD_ALIGNMENT);
4444
if (!data)
4545
return;
4646

@@ -74,7 +74,7 @@ class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
7474

7575
virtual size_t conservativeSizeEstimate() const override { return getSize(); }
7676

77-
//! Returns pointer to data.
77+
//! Returns pointer to data.
7878
virtual const void* getPointer() const {return data;}
7979
virtual void* getPointer()
8080
{
@@ -90,22 +90,22 @@ class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
9090
return true;
9191
}
9292

93-
inline core::bitflag<E_USAGE_FLAGS> getUsageFlags() const
94-
{
95-
return m_creationParams.usage;
96-
}
97-
inline bool setUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
98-
{
99-
assert(!isImmutable_debug());
93+
inline core::bitflag<E_USAGE_FLAGS> getUsageFlags() const
94+
{
95+
return m_creationParams.usage;
96+
}
97+
inline bool setUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
98+
{
99+
assert(!isImmutable_debug());
100100
m_creationParams.usage = _usage;
101-
return true;
102-
}
103-
inline bool addUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
104-
{
105-
assert(!isImmutable_debug());
101+
return true;
102+
}
103+
inline bool addUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
104+
{
105+
assert(!isImmutable_debug());
106106
m_creationParams.usage |= _usage;
107-
return true;
108-
}
107+
return true;
108+
}
109109

110110
protected:
111111
void restoreFromDummy_impl(IAsset* _other, uint32_t _levelsBelow) override
@@ -140,51 +140,51 @@ class NBL_API CCustomAllocatorCPUBuffer;
140140
template<typename Allocator>
141141
class NBL_API CCustomAllocatorCPUBuffer<Allocator, true> : public ICPUBuffer
142142
{
143-
static_assert(sizeof(typename Allocator::value_type) == 1u, "Allocator::value_type must be of size 1");
144-
protected:
145-
Allocator m_allocator;
143+
static_assert(sizeof(typename Allocator::value_type) == 1u, "Allocator::value_type must be of size 1");
144+
protected:
145+
Allocator m_allocator;
146146

147147
virtual ~CCustomAllocatorCPUBuffer()
148148
{
149149
this->convertToDummyObject();
150150
}
151151

152-
public:
153-
CCustomAllocatorCPUBuffer(size_t sizeInBytes, void* dat, core::adopt_memory_t, Allocator&& alctr = Allocator()) : ICPUBuffer(sizeInBytes, dat), m_allocator(std::move(alctr))
154-
{
155-
}
152+
public:
153+
CCustomAllocatorCPUBuffer(size_t sizeInBytes, void* dat, core::adopt_memory_t, Allocator&& alctr = Allocator()) : ICPUBuffer(sizeInBytes, dat), m_allocator(std::move(alctr))
154+
{
155+
}
156156

157-
virtual void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override
158-
{
157+
virtual void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override
158+
{
159159
if (isDummyObjectForCacheAliasing)
160160
return;
161161
convertToDummyObject_common(referenceLevelsBelowToConvert);
162162
if (!canBeConvertedToDummy())
163163
return;
164164

165-
if (ICPUBuffer::data)
166-
m_allocator.deallocate(reinterpret_cast<typename Allocator::pointer>(ICPUBuffer::data), ICPUBuffer::size);
167-
ICPUBuffer::data = nullptr; // so that ICPUBuffer won't try deallocating
168-
}
165+
if (ICPUBuffer::data)
166+
m_allocator.deallocate(reinterpret_cast<typename Allocator::pointer>(ICPUBuffer::data), ICPUBuffer::m_creationParams.size);
167+
ICPUBuffer::data = nullptr; // so that ICPUBuffer won't try deallocating
168+
}
169169
};
170170

171171
template<typename Allocator>
172172
class NBL_API CCustomAllocatorCPUBuffer<Allocator, false> : public CCustomAllocatorCPUBuffer<Allocator, true>
173173
{
174-
using Base = CCustomAllocatorCPUBuffer<Allocator, true>;
175-
protected:
176-
virtual ~CCustomAllocatorCPUBuffer() = default;
174+
using Base = CCustomAllocatorCPUBuffer<Allocator, true>;
175+
protected:
176+
virtual ~CCustomAllocatorCPUBuffer() = default;
177177

178-
public:
179-
using Base::Base;
178+
public:
179+
using Base::Base;
180180

181181
// TODO: remove, alloc can fail, should be a static create method instead!
182-
CCustomAllocatorCPUBuffer(size_t sizeInBytes, const void* dat, Allocator&& alctr = Allocator()) : Base(sizeInBytes, alctr.allocate(sizeInBytes), core::adopt_memory, std::move(alctr))
183-
{
184-
memcpy(Base::data,dat,sizeInBytes);
185-
}
182+
CCustomAllocatorCPUBuffer(size_t sizeInBytes, const void* dat, Allocator&& alctr = Allocator()) : Base(sizeInBytes, alctr.allocate(sizeInBytes), core::adopt_memory, std::move(alctr))
183+
{
184+
memcpy(Base::data,dat,sizeInBytes);
185+
}
186186
};
187187

188188
} // end namespace nbl::asset
189189

190-
#endif
190+
#endif

include/nbl/asset/ICPUImage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ class NBL_API ICPUImage final : public IImage, public IAsset
176176
assert(!isImmutable_debug());
177177

178178
if (!IImage::validateCopies(_regions->begin(),_regions->end(),_buffer.get()))
179+
{
180+
assert(false);
179181
return false;
182+
}
180183

181184
buffer = std::move(_buffer);
182185
regions = _regions;

include/nbl/asset/ICommandBuffer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct NBL_API SImageResolve
4646

4747
struct NBL_API SMemoryBarrier
4848
{
49-
core::bitflag<asset::E_ACCESS_FLAGS> srcAccessMask = static_cast<asset::E_ACCESS_FLAGS>(0u);
50-
core::bitflag<asset::E_ACCESS_FLAGS> dstAccessMask = static_cast<asset::E_ACCESS_FLAGS>(0u);
49+
core::bitflag<asset::E_ACCESS_FLAGS> srcAccessMask = asset::EAF_NONE;
50+
core::bitflag<asset::E_ACCESS_FLAGS> dstAccessMask = asset::EAF_NONE;
5151
};
5252

5353
union SClearColorValue
@@ -352,9 +352,6 @@ class NBL_API ICommandBuffer
352352
return true;
353353
}
354354

355-
virtual bool regenerateMipmaps(image_t* imgview, uint32_t lastReadyMip, asset::IImage::E_ASPECT_FLAGS aspect) = 0;
356-
357-
358355

359356
protected:
360357
ICommandBuffer(E_LEVEL lvl) : m_level(lvl) {}

include/nbl/asset/IImage.h

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class NBL_API IImage : public IDescriptor
6262
public:
6363
enum E_ASPECT_FLAGS : uint16_t
6464
{
65+
EAF_NONE = 0u,
6566
EAF_COLOR_BIT = 0x1u << 0u,
6667
EAF_DEPTH_BIT = 0x1u << 1u,
6768
EAF_STENCIL_BIT = 0x1u << 2u,
@@ -122,7 +123,7 @@ class NBL_API IImage : public IDescriptor
122123
};
123124
enum E_USAGE_FLAGS : uint16_t
124125
{
125-
EUF_NONE = 0x00000000,
126+
EUF_NONE = 0x00000000,
126127
EUF_TRANSFER_SRC_BIT = 0x00000001,
127128
EUF_TRANSFER_DST_BIT = 0x00000002,
128129
EUF_SAMPLED_BIT = 0x00000004,
@@ -136,15 +137,15 @@ class NBL_API IImage : public IDescriptor
136137
};
137138
struct SSubresourceRange
138139
{
139-
E_ASPECT_FLAGS aspectMask = static_cast<E_ASPECT_FLAGS>(0u); // waits for vulkan
140+
E_ASPECT_FLAGS aspectMask = E_ASPECT_FLAGS::EAF_NONE;
140141
uint32_t baseMipLevel = 0u;
141142
uint32_t levelCount = 0u;
142143
uint32_t baseArrayLayer = 0u;
143144
uint32_t layerCount = 0u;
144145
};
145146
struct SSubresourceLayers
146147
{
147-
E_ASPECT_FLAGS aspectMask = static_cast<E_ASPECT_FLAGS>(0u); // waits for vulkan
148+
E_ASPECT_FLAGS aspectMask = E_ASPECT_FLAGS::EAF_NONE;
148149
uint32_t mipLevel = 0u;
149150
uint32_t baseArrayLayer = 0u;
150151
uint32_t layerCount = 0u;
@@ -157,7 +158,7 @@ class NBL_API IImage : public IDescriptor
157158
{
158159
// TODO: more complex check of compatible aspects
159160
// Image Extent must be a mutiple of texel block dims OR offset + extent = image subresourceDims
160-
// bufferOffset must be multiple of the compressed texel block size in bytes (matters in IGPU?)
161+
// bufferOffset must be multiple of the compressed texel block size in bytes (matters in IGPU?)
161162
// If planar subresource aspectMask should be PLANE_{0,1,2}
162163
if (false)
163164
return false;
@@ -189,7 +190,7 @@ class NBL_API IImage : public IDescriptor
189190
{
190191
return info.convert3DTexelStridesTo1DByteStrides(getTexelStrides());
191192
}
192-
static inline uint64_t getLocalByteOffset(const core::vector3du32_SIMD& localXYZLayerOffset, const core::vector3du32_SIMD& byteStrides)
193+
static inline uint64_t getLocalByteOffset(const core::vector3du32_SIMD& localXYZLayerOffset, const core::vector3du32_SIMD& byteStrides)
193194
{
194195
return core::dot(localXYZLayerOffset,byteStrides)[0];
195196
}
@@ -198,7 +199,6 @@ class NBL_API IImage : public IDescriptor
198199
return bufferOffset+getLocalByteOffset(localXYZLayerOffset,byteStrides);
199200
}
200201

201-
202202
size_t bufferOffset = 0ull;
203203
// setting this to different from 0 can fail an image copy on OpenGL
204204
uint32_t bufferRowLength = 0u;
@@ -242,7 +242,7 @@ class NBL_API IImage : public IDescriptor
242242
VkExtent3D extent;
243243
uint32_t mipLevels;
244244
uint32_t arrayLayers;
245-
E_CREATE_FLAGS flags = ECF_NONE;
245+
core::bitflag<E_CREATE_FLAGS> flags = ECF_NONE;
246246
core::bitflag<E_USAGE_FLAGS> usage = EUF_NONE;
247247

248248
inline bool operator==(const SCreationParams& rhs) const
@@ -257,7 +257,7 @@ class NBL_API IImage : public IDescriptor
257257
extent!=rhs.extent ||
258258
mipLevels!=rhs.mipLevels ||
259259
arrayLayers!=rhs.arrayLayers ||
260-
flags!=rhs.flags ||
260+
flags.value!=rhs.flags.value ||
261261
usage.value!=rhs.usage.value;
262262
}
263263
};
@@ -283,7 +283,12 @@ class NBL_API IImage : public IDescriptor
283283
default:
284284
break;
285285
}
286-
return 1u + uint32_t(floorf(log2(float(maxSideLen))));
286+
const uint32_t round = core::roundUpToPoT<uint32_t>(maxSideLen);
287+
return core::findLSB(round);
288+
}
289+
inline static uint32_t calculateFullMipPyramidLevelCount(const VkExtent3D& extent, E_TYPE type)
290+
{
291+
return calculateMaxMipLevel(extent,type)+1u;
287292
}
288293

289294
//!
@@ -319,7 +324,7 @@ class NBL_API IImage : public IDescriptor
319324
if (core::bitCount(static_cast<uint32_t>(_params.samples))!=1u)
320325
return false;
321326

322-
if (_params.flags & ECF_CUBE_COMPATIBLE_BIT)
327+
if (_params.flags.hasFlags(ECF_CUBE_COMPATIBLE_BIT))
323328
{
324329
if (_params.type != ET_2D)
325330
return false;
@@ -330,28 +335,28 @@ class NBL_API IImage : public IDescriptor
330335
if (_params.samples != ESCF_1_BIT)
331336
return false;
332337
}
333-
if ((_params.flags & ECF_2D_ARRAY_COMPATIBLE_BIT) && _params.type != ET_3D)
338+
if (_params.flags.hasFlags(ECF_2D_ARRAY_COMPATIBLE_BIT) && _params.type != ET_3D)
334339
return false;
335-
if ((_params.flags & ECF_SPARSE_RESIDENCY_BIT) || (_params.flags & ECF_SPARSE_ALIASED_BIT))
340+
if (_params.flags.hasFlags(ECF_SPARSE_RESIDENCY_BIT) || _params.flags.hasFlags(ECF_SPARSE_ALIASED_BIT))
336341
{
337-
if (!(_params.flags & ECF_SPARSE_BINDING_BIT))
342+
if (!_params.flags.hasFlags(ECF_SPARSE_BINDING_BIT))
338343
return false;
339-
if (_params.flags & ECF_PROTECTED_BIT)
344+
if (_params.flags.hasFlags(ECF_PROTECTED_BIT))
340345
return false;
341346
}
342-
if ((_params.flags & ECF_SPARSE_BINDING_BIT) && (_params.flags & ECF_PROTECTED_BIT))
347+
if (_params.flags.hasFlags(ECF_SPARSE_BINDING_BIT) && _params.flags.hasFlags(ECF_PROTECTED_BIT))
343348
return false;
344-
if (_params.flags & ECF_SPLIT_INSTANCE_BIND_REGIONS_BIT)
349+
if (_params.flags.hasFlags(ECF_SPLIT_INSTANCE_BIND_REGIONS_BIT))
345350
{
346351
if (_params.mipLevels > 1u || _params.arrayLayers > 1u || _params.type != ET_2D)
347352
return false;
348353
}
349-
if (_params.flags & ECF_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT)
354+
if (_params.flags.hasFlags(ECF_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT))
350355
{
351-
if (!isBlockCompressionFormat(_params.format) || !(_params.flags & ECF_MUTABLE_FORMAT_BIT))
356+
if (!isBlockCompressionFormat(_params.format) || !_params.flags.hasFlags(ECF_MUTABLE_FORMAT_BIT))
352357
return false;
353358
}
354-
if ((_params.flags & ECF_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT) && (!isDepthOrStencilFormat(_params.format) || _params.format == EF_S8_UINT))
359+
if (_params.flags.hasFlags(ECF_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT) && (!isDepthOrStencilFormat(_params.format) || _params.format == EF_S8_UINT))
355360
return false;
356361

357362
if (_params.samples != ESCF_1_BIT && _params.type != ET_2D)
@@ -380,11 +385,11 @@ class NBL_API IImage : public IDescriptor
380385
}
381386
else
382387
{
383-
if (!(_params.flags & ECF_ALIAS_BIT) && (_params.flags & ECF_DISJOINT_BIT))
388+
if (!_params.flags.hasFlags(ECF_ALIAS_BIT) && _params.flags.hasFlags(ECF_DISJOINT_BIT))
384389
return false;
385390
}
386391

387-
if (_params.mipLevels > calculateMaxMipLevel(_params.extent, _params.type))
392+
if (_params.mipLevels > calculateFullMipPyramidLevelCount(_params.extent, _params.type))
388393
return false;
389394

390395
return true;
@@ -538,7 +543,7 @@ class NBL_API IImage : public IDescriptor
538543
EL_SHADING_RATE_OPTIMAL_NV = 1000164003,
539544
EL_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT = 1000218000
540545
};
541-
protected:
546+
protected:
542547
IImage(const SCreationParams& _params) : m_creationParams(_params), info(_params.format) {}
543548

544549
virtual ~IImage() {}
@@ -582,6 +587,9 @@ class NBL_API IImage : public IDescriptor
582587
const auto& subresource = it->getDstSubresource();
583588
//if (!formatHasAspects(m_creationParams.format,subresource.aspectMask))
584589
//return false;
590+
// The aspectMask member of imageSubresource must only have a single bit set
591+
if (!core::bitCount(static_cast<uint32_t>(subresource.aspectMask)) == 1u)
592+
return false;
585593
if (subresource.mipLevel >= m_creationParams.mipLevels)
586594
return false;
587595
if (subresource.baseArrayLayer+subresource.layerCount > m_creationParams.arrayLayers)

0 commit comments

Comments
 (0)