Skip to content

Commit

Permalink
Merge pull request #476 from Devsh-Graphics-Programming/async_queues
Browse files Browse the repository at this point in the history
Async Queue Refactor
  • Loading branch information
devshgraphicsprogramming authored Mar 22, 2023
2 parents 6a17dc8 + 1b91f2d commit 25f130a
Show file tree
Hide file tree
Showing 72 changed files with 2,317 additions and 3,007 deletions.
4 changes: 0 additions & 4 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif()


# TODO: redo
# find_package(Wayland) # TODO: remove, load Wayland dynamically


# zlib (target is zlibstatic)
set(_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(_OLD_SKIP_INSTALL_ALL ${SKIP_INSTALL_ALL})
Expand Down
2 changes: 1 addition & 1 deletion examples_tests
23 changes: 8 additions & 15 deletions include/nbl/asset/IAssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,12 @@ class NBL_API2 IAssetManager : public core::IReferenceCounted, public core::Quit
filePath = _params.workingDirectory/filePath;
_override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel);
}

system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
m_system->createFile(future, filePath, system::IFile::ECF_READ);
auto file = future.get();
if (!file)
return SAssetBundle(0);

return getAssetInHierarchy_impl<RestoreWholeBundle>(file.get(), filePath.string(), ctx.params, _hierarchyLevel, _override);
if (auto file=future.acquire())
return getAssetInHierarchy_impl<RestoreWholeBundle>(file->get(), filePath.string(), ctx.params, _hierarchyLevel, _override);
return SAssetBundle(0);
}

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

system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
m_system->createFile(future, (_params.workingDirectory.generic_string() + _filename).c_str(), system::IFile::ECF_WRITE);
auto file = future.get();
if (file) // could fail creating file (lack of permissions)
{
bool res = writeAsset(file.get(), _params, _override);
return res;
}
else
return false;
m_system->createFile(future, (_params.workingDirectory.generic_string()+_filename).c_str(), system::IFile::ECF_WRITE);
if (auto file=future.acquire())
return writeAsset(file->get(), _params, _override);
return false;
}
bool writeAsset(system::IFile* _file, const IAssetWriter::SAssetWriteParams& _params, IAssetWriter::IAssetWriterOverride* _override)
{
Expand Down
12 changes: 6 additions & 6 deletions include/nbl/asset/ICPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ class ICPUBuffer : public asset::IBuffer, public asset::IAsset
}

void* data;
};
};

template<
typename Allocator = _NBL_DEFAULT_ALLOCATOR_METATYPE<uint8_t>,
bool = std::is_same<Allocator, core::null_allocator<typename Allocator::value_type> >::value
>
class CCustomAllocatorCPUBuffer;
template<
typename Allocator = _NBL_DEFAULT_ALLOCATOR_METATYPE<uint8_t>,
bool = std::is_same<Allocator, core::null_allocator<typename Allocator::value_type> >::value
>
class CCustomAllocatorCPUBuffer;

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

Expand Down
203 changes: 101 additions & 102 deletions include/nbl/asset/ICPUDescriptorSet.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (C) 2018-2022 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h

#ifndef _NBL_ASSET_I_CPU_DESCRIPTOR_SET_H_INCLUDED_
#define _NBL_ASSET_I_CPU_DESCRIPTOR_SET_H_INCLUDED_

Expand All @@ -25,115 +24,115 @@ namespace nbl::asset
@see IDescriptorSet
*/

class ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetLayout>, public IAsset
class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetLayout>, public IAsset
{
using base_t = IDescriptorSet<ICPUDescriptorSetLayout>;

public:
//! Contructor preallocating memory for SDescriptorInfos which user can fill later (using non-const getDescriptorInfos()).
//! @see getDescriptorInfos()
ICPUDescriptorSet(core::smart_refctd_ptr<ICPUDescriptorSetLayout>&& _layout) : base_t(std::move(_layout)), IAsset()
{
for (uint32_t t = 0u; t < static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT); ++t)
using base_t = IDescriptorSet<ICPUDescriptorSetLayout>;

public:
//! Contructor preallocating memory for SDescriptorInfos which user can fill later (using non-const getDescriptorInfos()).
//! @see getDescriptorInfos()
inline ICPUDescriptorSet(core::smart_refctd_ptr<ICPUDescriptorSetLayout>&& _layout) : base_t(std::move(_layout)), IAsset()
{
for (uint32_t t = 0u; t < static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT); ++t)
{
const auto type = static_cast<IDescriptor::E_TYPE>(t);
const uint32_t count = m_layout->getTotalDescriptorCount(type);
if (count == 0u)
continue;

m_descriptorInfos[t] = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo>>(count);
}
}

_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_DESCRIPTOR_SET;
inline E_TYPE getAssetType() const override { return AssetType; }

inline ICPUDescriptorSetLayout* getLayout()
{
const auto type = static_cast<IDescriptor::E_TYPE>(t);
const uint32_t count = m_layout->getTotalDescriptorCount(type);
if (count == 0u)
continue;
assert(!isImmutable_debug());
return m_layout.get();
}

inline const ICPUDescriptorSetLayout* getLayout() const { return m_layout.get(); }

m_descriptorInfos[t] = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo>>(count);
inline bool canBeRestoredFrom(const IAsset* _other) const override
{
auto* other = static_cast<const ICPUDescriptorSet*>(_other);
return m_layout->canBeRestoredFrom(other->m_layout.get());
}
}

_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_DESCRIPTOR_SET;
inline E_TYPE getAssetType() const override { return AssetType; }

inline ICPUDescriptorSetLayout* getLayout()
{
assert(!isImmutable_debug());
return m_layout.get();
}

inline const ICPUDescriptorSetLayout* getLayout() const { return m_layout.get(); }

inline bool canBeRestoredFrom(const IAsset* _other) const override
{
auto* other = static_cast<const ICPUDescriptorSet*>(_other);
return m_layout->canBeRestoredFrom(other->m_layout.get());
}

inline size_t conservativeSizeEstimate() const override
{
assert(!"Invalid code path.");
return 0xdeadbeefull;
}

inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const
{
// TODO: @Hazardu
// 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
// from const functions in the asset converter.
// Relevant comments/conversations:
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1054258384
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1056289599
//
// assert(!isImmutable_debug());
if (!m_descriptorInfos[static_cast<uint32_t>(type)])
return { nullptr, nullptr };
else
return { m_descriptorInfos[static_cast<uint32_t>(type)]->begin(), m_descriptorInfos[static_cast<uint32_t>(type)]->end() };
}

core::SRange<SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);

core::SRange<const SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT) const;

core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override;

void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override;

protected:
void restoreFromDummy_impl(IAsset* _other, uint32_t _levelsBelow) override;

bool isAnyDependencyDummy_impl(uint32_t _levelsBelow) const override;

virtual ~ICPUDescriptorSet() = default;

private:
static inline IDescriptor::E_CATEGORY getCategoryFromType(const IDescriptor::E_TYPE type)
{
auto category = IDescriptor::E_CATEGORY::EC_COUNT;
switch (type)

inline size_t conservativeSizeEstimate() const override
{
case IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER: [[fallthrough]];
case IDescriptor::E_TYPE::ET_STORAGE_IMAGE: [[fallthrough]];
case IDescriptor::E_TYPE::ET_INPUT_ATTACHMENT:
category = IDescriptor::E_CATEGORY::EC_IMAGE;
break;

case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER: [[fallthrough]];
case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC: [[fallthrough]];
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER: [[fallthrough]];
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
category = IDescriptor::E_CATEGORY::EC_BUFFER;
break;

case IDescriptor::E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
case IDescriptor::E_TYPE::ET_STORAGE_TEXEL_BUFFER:
category = IDescriptor::E_CATEGORY::EC_BUFFER_VIEW;
break;

case IDescriptor::E_TYPE::ET_ACCELERATION_STRUCTURE:
category = IDescriptor::E_CATEGORY::EC_ACCELERATION_STRUCTURE;
break;

default:
assert(!"Invalid code path.");
return 0xdeadbeefull;
}

inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const
{
// TODO: @Hazardu
// 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
// from const functions in the asset converter.
// Relevant comments/conversations:
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1054258384
// https://github.com/Devsh-Graphics-Programming/Nabla/pull/345#discussion_r1056289599
//
// assert(!isImmutable_debug());
if (!m_descriptorInfos[static_cast<uint32_t>(type)])
return { nullptr, nullptr };
else
return { m_descriptorInfos[static_cast<uint32_t>(type)]->begin(), m_descriptorInfos[static_cast<uint32_t>(type)]->end() };
}

core::SRange<SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);

core::SRange<const SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT) const;

core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override;

void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override;

protected:
void restoreFromDummy_impl(IAsset* _other, uint32_t _levelsBelow) override;

bool isAnyDependencyDummy_impl(uint32_t _levelsBelow) const override;

virtual ~ICPUDescriptorSet() = default;

private:
static inline IDescriptor::E_CATEGORY getCategoryFromType(const IDescriptor::E_TYPE type)
{
auto category = IDescriptor::E_CATEGORY::EC_COUNT;
switch (type)
{
case IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER: [[fallthrough]];
case IDescriptor::E_TYPE::ET_STORAGE_IMAGE: [[fallthrough]];
case IDescriptor::E_TYPE::ET_INPUT_ATTACHMENT:
category = IDescriptor::E_CATEGORY::EC_IMAGE;
break;

case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER: [[fallthrough]];
case IDescriptor::E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC: [[fallthrough]];
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER: [[fallthrough]];
case IDescriptor::E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
category = IDescriptor::E_CATEGORY::EC_BUFFER;
break;

case IDescriptor::E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
case IDescriptor::E_TYPE::ET_STORAGE_TEXEL_BUFFER:
category = IDescriptor::E_CATEGORY::EC_BUFFER_VIEW;
break;

case IDescriptor::E_TYPE::ET_ACCELERATION_STRUCTURE:
category = IDescriptor::E_CATEGORY::EC_ACCELERATION_STRUCTURE;
break;

default:
assert(!"Invalid code path.");
}
return category;
}
return category;
}

core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT)];
core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT)];
};

}
Expand Down
12 changes: 5 additions & 7 deletions include/nbl/asset/IDescriptorSetLayout.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED_
#define _NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED_

#ifndef __NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED__
#define __NBL_ASSET_I_DESCRIPTOR_SET_LAYOUT_H_INCLUDED__

#include "nbl/core/declarations.h"
#include "nbl/core/SRange.h"

#include "nbl/asset/ISpecializedShader.h"
#include "nbl/asset/IShader.h"

namespace nbl
{
namespace asset

namespace nbl::asset
{

//! Interface class for Descriptor Set Layouts
Expand Down Expand Up @@ -395,6 +395,4 @@ class IDescriptorSetLayout : public virtual core::IReferenceCounted
};

}
}

#endif
16 changes: 6 additions & 10 deletions include/nbl/asset/utils/CDirQuantCacheBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,9 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
{
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
system->createFile(future,path,nbl::system::IFile::ECF_READ);
auto file = future.get();
if (!file)
return false;

return loadCacheFromFile<CacheFormat>(file.get(),replaceCurrentContents);
if (auto file=future.acquire())
return loadCacheFromFile<CacheFormat>(file->get(),replaceCurrentContents);
return false;
}

//!
Expand Down Expand Up @@ -363,11 +361,9 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
{
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
system->createFile(future, path, nbl::system::IFile::ECF_WRITE);
auto file = future.get();
if (!file)
return false;

return bool(saveCacheToFile<CacheFormat>(file.get()));
if (auto file=future.acquire())
return bool(saveCacheToFile<CacheFormat>(file->get()));
return false;
}

//!
Expand Down
Loading

0 comments on commit 25f130a

Please sign in to comment.