Skip to content

Commit 25f130a

Browse files
Merge pull request #476 from Devsh-Graphics-Programming/async_queues
Async Queue Refactor
2 parents 6a17dc8 + 1b91f2d commit 25f130a

File tree

72 files changed

+2317
-3007
lines changed

Some content is hidden

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

72 files changed

+2317
-3007
lines changed

3rdparty/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
5151
endif()
5252

5353

54-
# TODO: redo
55-
# find_package(Wayland) # TODO: remove, load Wayland dynamically
56-
57-
5854
# zlib (target is zlibstatic)
5955
set(_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
6056
set(_OLD_SKIP_INSTALL_ALL ${SKIP_INSTALL_ALL})

include/nbl/asset/IAssetManager.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,12 @@ class NBL_API2 IAssetManager : public core::IReferenceCounted, public core::Quit
330330
filePath = _params.workingDirectory/filePath;
331331
_override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel);
332332
}
333-
333+
334334
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
335335
m_system->createFile(future, filePath, system::IFile::ECF_READ);
336-
auto file = future.get();
337-
if (!file)
338-
return SAssetBundle(0);
339-
340-
return getAssetInHierarchy_impl<RestoreWholeBundle>(file.get(), filePath.string(), ctx.params, _hierarchyLevel, _override);
336+
if (auto file=future.acquire())
337+
return getAssetInHierarchy_impl<RestoreWholeBundle>(file->get(), filePath.string(), ctx.params, _hierarchyLevel, _override);
338+
return SAssetBundle(0);
341339
}
342340

343341
//TODO change name
@@ -652,15 +650,10 @@ class NBL_API2 IAssetManager : public core::IReferenceCounted, public core::Quit
652650
_override = &defOverride;
653651

654652
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
655-
m_system->createFile(future, (_params.workingDirectory.generic_string() + _filename).c_str(), system::IFile::ECF_WRITE);
656-
auto file = future.get();
657-
if (file) // could fail creating file (lack of permissions)
658-
{
659-
bool res = writeAsset(file.get(), _params, _override);
660-
return res;
661-
}
662-
else
663-
return false;
653+
m_system->createFile(future, (_params.workingDirectory.generic_string()+_filename).c_str(), system::IFile::ECF_WRITE);
654+
if (auto file=future.acquire())
655+
return writeAsset(file->get(), _params, _override);
656+
return false;
664657
}
665658
bool writeAsset(system::IFile* _file, const IAssetWriter::SAssetWriteParams& _params, IAssetWriter::IAssetWriterOverride* _override)
666659
{

include/nbl/asset/ICPUBuffer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ class ICPUBuffer : public asset::IBuffer, public asset::IAsset
117117
}
118118

119119
void* data;
120-
};
120+
};
121121

122-
template<
123-
typename Allocator = _NBL_DEFAULT_ALLOCATOR_METATYPE<uint8_t>,
124-
bool = std::is_same<Allocator, core::null_allocator<typename Allocator::value_type> >::value
125-
>
126-
class CCustomAllocatorCPUBuffer;
122+
template<
123+
typename Allocator = _NBL_DEFAULT_ALLOCATOR_METATYPE<uint8_t>,
124+
bool = std::is_same<Allocator, core::null_allocator<typename Allocator::value_type> >::value
125+
>
126+
class CCustomAllocatorCPUBuffer;
127127

128128
using CDummyCPUBuffer = CCustomAllocatorCPUBuffer<core::null_allocator<uint8_t>, true>;
129129

include/nbl/asset/ICPUDescriptorSet.h

Lines changed: 101 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (C) 2018-2022 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
54
#ifndef _NBL_ASSET_I_CPU_DESCRIPTOR_SET_H_INCLUDED_
65
#define _NBL_ASSET_I_CPU_DESCRIPTOR_SET_H_INCLUDED_
76

@@ -25,115 +24,115 @@ namespace nbl::asset
2524
@see IDescriptorSet
2625
*/
2726

28-
class ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetLayout>, public IAsset
27+
class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetLayout>, public IAsset
2928
{
30-
using base_t = IDescriptorSet<ICPUDescriptorSetLayout>;
31-
32-
public:
33-
//! Contructor preallocating memory for SDescriptorInfos which user can fill later (using non-const getDescriptorInfos()).
34-
//! @see getDescriptorInfos()
35-
ICPUDescriptorSet(core::smart_refctd_ptr<ICPUDescriptorSetLayout>&& _layout) : base_t(std::move(_layout)), IAsset()
36-
{
37-
for (uint32_t t = 0u; t < static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT); ++t)
29+
using base_t = IDescriptorSet<ICPUDescriptorSetLayout>;
30+
31+
public:
32+
//! Contructor preallocating memory for SDescriptorInfos which user can fill later (using non-const getDescriptorInfos()).
33+
//! @see getDescriptorInfos()
34+
inline ICPUDescriptorSet(core::smart_refctd_ptr<ICPUDescriptorSetLayout>&& _layout) : base_t(std::move(_layout)), IAsset()
35+
{
36+
for (uint32_t t = 0u; t < static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT); ++t)
37+
{
38+
const auto type = static_cast<IDescriptor::E_TYPE>(t);
39+
const uint32_t count = m_layout->getTotalDescriptorCount(type);
40+
if (count == 0u)
41+
continue;
42+
43+
m_descriptorInfos[t] = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo>>(count);
44+
}
45+
}
46+
47+
_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_DESCRIPTOR_SET;
48+
inline E_TYPE getAssetType() const override { return AssetType; }
49+
50+
inline ICPUDescriptorSetLayout* getLayout()
3851
{
39-
const auto type = static_cast<IDescriptor::E_TYPE>(t);
40-
const uint32_t count = m_layout->getTotalDescriptorCount(type);
41-
if (count == 0u)
42-
continue;
52+
assert(!isImmutable_debug());
53+
return m_layout.get();
54+
}
55+
56+
inline const ICPUDescriptorSetLayout* getLayout() const { return m_layout.get(); }
4357

44-
m_descriptorInfos[t] = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo>>(count);
58+
inline bool canBeRestoredFrom(const IAsset* _other) const override
59+
{
60+
auto* other = static_cast<const ICPUDescriptorSet*>(_other);
61+
return m_layout->canBeRestoredFrom(other->m_layout.get());
4562
}
46-
}
47-
48-
_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_DESCRIPTOR_SET;
49-
inline E_TYPE getAssetType() const override { return AssetType; }
50-
51-
inline ICPUDescriptorSetLayout* getLayout()
52-
{
53-
assert(!isImmutable_debug());
54-
return m_layout.get();
55-
}
56-
57-
inline const ICPUDescriptorSetLayout* getLayout() const { return m_layout.get(); }
58-
59-
inline bool canBeRestoredFrom(const IAsset* _other) const override
60-
{
61-
auto* other = static_cast<const ICPUDescriptorSet*>(_other);
62-
return m_layout->canBeRestoredFrom(other->m_layout.get());
63-
}
64-
65-
inline size_t conservativeSizeEstimate() const override
66-
{
67-
assert(!"Invalid code path.");
68-
return 0xdeadbeefull;
69-
}
70-
71-
inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const
72-
{
73-
// TODO: @Hazardu
74-
// Cannot do the mutability check here because it requires the function to be non-const, but the function cannot be non-const because it's called
75-
// from const functions in the asset converter.
76-
// Relevant comments/conversations:
77-
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1054258384
78-
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1056289599
79-
//
80-
// assert(!isImmutable_debug());
81-
if (!m_descriptorInfos[static_cast<uint32_t>(type)])
82-
return { nullptr, nullptr };
83-
else
84-
return { m_descriptorInfos[static_cast<uint32_t>(type)]->begin(), m_descriptorInfos[static_cast<uint32_t>(type)]->end() };
85-
}
86-
87-
core::SRange<SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);
88-
89-
core::SRange<const SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT) const;
90-
91-
core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override;
92-
93-
void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override;
94-
95-
protected:
96-
void restoreFromDummy_impl(IAsset* _other, uint32_t _levelsBelow) override;
97-
98-
bool isAnyDependencyDummy_impl(uint32_t _levelsBelow) const override;
99-
100-
virtual ~ICPUDescriptorSet() = default;
101-
102-
private:
103-
static inline IDescriptor::E_CATEGORY getCategoryFromType(const IDescriptor::E_TYPE type)
104-
{
105-
auto category = IDescriptor::E_CATEGORY::EC_COUNT;
106-
switch (type)
63+
64+
inline size_t conservativeSizeEstimate() const override
10765
{
108-
case IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER: [[fallthrough]];
109-
case IDescriptor::E_TYPE::ET_STORAGE_IMAGE: [[fallthrough]];
110-
case IDescriptor::E_TYPE::ET_INPUT_ATTACHMENT:
111-
category = IDescriptor::E_CATEGORY::EC_IMAGE;
112-
break;
113-
114-
case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER: [[fallthrough]];
115-
case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC: [[fallthrough]];
116-
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER: [[fallthrough]];
117-
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
118-
category = IDescriptor::E_CATEGORY::EC_BUFFER;
119-
break;
120-
121-
case IDescriptor::E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
122-
case IDescriptor::E_TYPE::ET_STORAGE_TEXEL_BUFFER:
123-
category = IDescriptor::E_CATEGORY::EC_BUFFER_VIEW;
124-
break;
125-
126-
case IDescriptor::E_TYPE::ET_ACCELERATION_STRUCTURE:
127-
category = IDescriptor::E_CATEGORY::EC_ACCELERATION_STRUCTURE;
128-
break;
129-
130-
default:
13166
assert(!"Invalid code path.");
67+
return 0xdeadbeefull;
68+
}
69+
70+
inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const
71+
{
72+
// TODO: @Hazardu
73+
// Cannot do the mutability check here because it requires the function to be non-const, but the function cannot be non-const because it's called
74+
// from const functions in the asset converter.
75+
// Relevant comments/conversations:
76+
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1054258384
77+
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1056289599
78+
//
79+
// assert(!isImmutable_debug());
80+
if (!m_descriptorInfos[static_cast<uint32_t>(type)])
81+
return { nullptr, nullptr };
82+
else
83+
return { m_descriptorInfos[static_cast<uint32_t>(type)]->begin(), m_descriptorInfos[static_cast<uint32_t>(type)]->end() };
84+
}
85+
86+
core::SRange<SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);
87+
88+
core::SRange<const SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT) const;
89+
90+
core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override;
91+
92+
void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override;
93+
94+
protected:
95+
void restoreFromDummy_impl(IAsset* _other, uint32_t _levelsBelow) override;
96+
97+
bool isAnyDependencyDummy_impl(uint32_t _levelsBelow) const override;
98+
99+
virtual ~ICPUDescriptorSet() = default;
100+
101+
private:
102+
static inline IDescriptor::E_CATEGORY getCategoryFromType(const IDescriptor::E_TYPE type)
103+
{
104+
auto category = IDescriptor::E_CATEGORY::EC_COUNT;
105+
switch (type)
106+
{
107+
case IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER: [[fallthrough]];
108+
case IDescriptor::E_TYPE::ET_STORAGE_IMAGE: [[fallthrough]];
109+
case IDescriptor::E_TYPE::ET_INPUT_ATTACHMENT:
110+
category = IDescriptor::E_CATEGORY::EC_IMAGE;
111+
break;
112+
113+
case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER: [[fallthrough]];
114+
case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC: [[fallthrough]];
115+
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER: [[fallthrough]];
116+
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
117+
category = IDescriptor::E_CATEGORY::EC_BUFFER;
118+
break;
119+
120+
case IDescriptor::E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
121+
case IDescriptor::E_TYPE::ET_STORAGE_TEXEL_BUFFER:
122+
category = IDescriptor::E_CATEGORY::EC_BUFFER_VIEW;
123+
break;
124+
125+
case IDescriptor::E_TYPE::ET_ACCELERATION_STRUCTURE:
126+
category = IDescriptor::E_CATEGORY::EC_ACCELERATION_STRUCTURE;
127+
break;
128+
129+
default:
130+
assert(!"Invalid code path.");
131+
}
132+
return category;
132133
}
133-
return category;
134-
}
135134

136-
core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT)];
135+
core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT)];
137136
};
138137

139138
}

include/nbl/asset/IDescriptorSetLayout.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED_
5+
#define _NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED_
46

5-
#ifndef __NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED__
6-
#define __NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED__
77

88
#include "nbl/core/declarations.h"
99
#include "nbl/core/SRange.h"
10+
1011
#include "nbl/asset/ISpecializedShader.h"
1112
#include "nbl/asset/IShader.h"
1213

13-
namespace nbl
14-
{
15-
namespace asset
14+
15+
namespace nbl::asset
1616
{
1717

1818
//! Interface class for Descriptor Set Layouts
@@ -395,6 +395,4 @@ class IDescriptorSetLayout : public virtual core::IReferenceCounted
395395
};
396396

397397
}
398-
}
399-
400398
#endif

include/nbl/asset/utils/CDirQuantCacheBase.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,9 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
317317
{
318318
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
319319
system->createFile(future,path,nbl::system::IFile::ECF_READ);
320-
auto file = future.get();
321-
if (!file)
322-
return false;
323-
324-
return loadCacheFromFile<CacheFormat>(file.get(),replaceCurrentContents);
320+
if (auto file=future.acquire())
321+
return loadCacheFromFile<CacheFormat>(file->get(),replaceCurrentContents);
322+
return false;
325323
}
326324

327325
//!
@@ -363,11 +361,9 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
363361
{
364362
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
365363
system->createFile(future, path, nbl::system::IFile::ECF_WRITE);
366-
auto file = future.get();
367-
if (!file)
368-
return false;
369-
370-
return bool(saveCacheToFile<CacheFormat>(file.get()));
364+
if (auto file=future.acquire())
365+
return bool(saveCacheToFile<CacheFormat>(file->get()));
366+
return false;
371367
}
372368

373369
//!

0 commit comments

Comments
 (0)