Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separable samplers #693

Merged
merged 33 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
378ea89
Got sampled images working. Samplers are next
Fletterio May 3, 2024
14a2a88
Makes ISampler extend from IDescriptor
Fletterio May 6, 2024
c867585
Adding support for samplers, few bugfixes, updated IGPUDescriptorSet
Fletterio May 7, 2024
2f6b88a
That should be all the logic needed to support samplers. Testing
Fletterio May 9, 2024
862a207
Separable image / samplers work!
Fletterio May 10, 2024
d881798
IGPUDescriptorSetLayout constructor to protected, ILogicalDevice's
Fletterio May 13, 2024
3df38a4
Minor IDescriptorSet::SDescriptorInfo QoL update
Fletterio May 15, 2024
e3e5b46
Update submodule for master merge
Fletterio Jun 23, 2024
4717951
Merge branch 'master' into separable_image_sampler
Fletterio Jun 23, 2024
0b3efea
Some changes following PR review
Fletterio Jun 24, 2024
a7cd095
Merge branch 'master' into separable_image_sampler
Fletterio Jun 27, 2024
8aef486
PR review done (excepts perhaps for a suggested name change)
Fletterio Jun 28, 2024
68d1604
Amortizing the double lookup by saving indices between validation and
Fletterio Jun 29, 2024
346f61a
Refactored CBindingRedirect's types to require explicit construction
Fletterio Jul 1, 2024
5f4d103
Merge branch 'separable_image_sampler' into separable_image_sampler_a…
Fletterio Jul 1, 2024
00b4311
Minor refactor
Fletterio Jul 1, 2024
c8f9045
Done!
Fletterio Jul 1, 2024
c2eca84
Merge branch 'master' into separable_image_sampler
Fletterio Jul 3, 2024
23806fc
Merge branch 'master' into separable_image_sampler_amortized_lookups
Fletterio Jul 3, 2024
ff876b9
Merge branch 'separable_image_sampler' into separable_image_sampler_a…
Fletterio Jul 3, 2024
2ed53f0
making dxc point right
Fletterio Jul 4, 2024
90dd99a
Merge branch 'separable_image_sampler' into separable_image_sampler_a…
Fletterio Jul 4, 2024
1e7511e
make examples point back to master
Fletterio Jul 4, 2024
b670a2c
Merge branch 'separable_image_sampler' into separable_image_sampler_a…
Fletterio Jul 4, 2024
d64eff7
Merge branch 'master' into separable_image_sampler
Fletterio Jul 5, 2024
f6c07d6
Merge branch 'master' into separable_image_sampler
Fletterio Jul 5, 2024
bad473b
Refactor following PR review done!
Fletterio Jul 6, 2024
1514b53
Merge branch 'separable_image_sampler' into separable_image_sampler_a…
Fletterio Jul 6, 2024
8eb33e1
Removed senseless comment
Fletterio Jul 6, 2024
7b76bed
Merge branch 'separable_image_sampler' into separable_image_sampler_a…
Fletterio Jul 6, 2024
357829e
Merge pull request #703 from Devsh-Graphics-Programming/separable_ima…
Fletterio Jul 6, 2024
53921b9
Minor bugfix, update examples submodule pointer
Fletterio Jul 10, 2024
ffd16a8
Merge branch 'master' into separable_image_sampler
Fletterio Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions include/nbl/asset/ICPUDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSet
return 0xdeadbeefull;
}

inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const
inline std::span<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
Expand All @@ -78,14 +78,14 @@ class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSet
//
// assert(!isImmutable_debug());
if (!m_descriptorInfos[static_cast<uint32_t>(type)])
return { nullptr, nullptr };
return { };
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);
std::span<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;
std::span<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;

Expand All @@ -99,38 +99,6 @@ class NBL_API2 ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSet
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;
}

core::smart_refctd_dynamic_array<ICPUDescriptorSet::SDescriptorInfo> m_descriptorInfos[static_cast<uint32_t>(IDescriptor::E_TYPE::ET_COUNT)];
};
Expand Down
42 changes: 21 additions & 21 deletions include/nbl/asset/ICPUDescriptorSetLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ class ICPUDescriptorSetLayout : public IDescriptorSetLayout<ICPUSampler>, public
for (uint32_t t = 0; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
cp->m_descriptorRedirects[t] = m_descriptorRedirects[t].clone();
cp->m_immutableSamplerRedirect = m_immutableSamplerRedirect.clone();
cp->m_mutableSamplerRedirect = m_mutableSamplerRedirect.clone();
cp->m_mutableCombinedSamplerRedirect = m_mutableCombinedSamplerRedirect.clone();

if (m_samplers)
if (m_immutableSamplers)
{
cp->m_samplers = core::make_refctd_dynamic_array<decltype(m_samplers)>(m_samplers->size());
cp->m_immutableSamplers = core::make_refctd_dynamic_array<decltype(m_immutableSamplers)>(m_immutableSamplers->size());

if (_depth > 0u)
{
for (size_t i = 0ull; i < m_samplers->size(); ++i)
(*cp->m_samplers)[i] = core::smart_refctd_ptr_static_cast<ICPUSampler>((*m_samplers)[i]->clone(_depth - 1u));
for (size_t i = 0ull; i < m_immutableSamplers->size(); ++i)
(*cp->m_immutableSamplers)[i] = core::smart_refctd_ptr_static_cast<ICPUSampler>((*m_immutableSamplers)[i]->clone(_depth - 1u));
}
else
{
std::copy(m_samplers->begin(), m_samplers->end(), cp->m_samplers->begin());
std::copy(m_immutableSamplers->begin(), m_immutableSamplers->end(), cp->m_immutableSamplers->begin());
}
}

Expand All @@ -60,9 +60,9 @@ class ICPUDescriptorSetLayout : public IDescriptorSetLayout<ICPUSampler>, public
for (uint32_t t = 0; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
result += m_descriptorRedirects[t].conservativeSizeEstimate();
result += m_immutableSamplerRedirect.conservativeSizeEstimate();
result += m_mutableSamplerRedirect.conservativeSizeEstimate();
result += m_mutableCombinedSamplerRedirect.conservativeSizeEstimate();

result += m_samplers->size() * sizeof(void*);
result += m_immutableSamplers->size() * sizeof(void*);

return result;
}
Expand All @@ -74,9 +74,9 @@ class ICPUDescriptorSetLayout : public IDescriptorSetLayout<ICPUSampler>, public
if (referenceLevelsBelowToConvert)
{
--referenceLevelsBelowToConvert;
if (m_samplers)
if (m_immutableSamplers)
{
for (auto it=m_samplers->begin(); it!=m_samplers->end(); it++)
for (auto it=m_immutableSamplers->begin(); it!=m_immutableSamplers->end(); it++)
it->get()->convertToDummyObject(referenceLevelsBelowToConvert);
}
}
Expand All @@ -90,15 +90,15 @@ class ICPUDescriptorSetLayout : public IDescriptorSetLayout<ICPUSampler>, public
auto* other = static_cast<const ICPUDescriptorSetLayout*>(_other);
if (getTotalBindingCount() != other->getTotalBindingCount())
return false;
if ((!m_samplers) != (!other->m_samplers))
if ((!m_immutableSamplers) != (!other->m_immutableSamplers))
return false;
if (m_samplers && m_samplers->size() != other->m_samplers->size())
if (m_immutableSamplers && m_immutableSamplers->size() != other->m_immutableSamplers->size())
return false;
if (m_samplers)
if (m_immutableSamplers)
{
for (uint32_t i = 0u; i < m_samplers->size(); ++i)
for (uint32_t i = 0u; i < m_immutableSamplers->size(); ++i)
{
if (!(*m_samplers)[i]->canBeRestoredFrom((*other->m_samplers)[i].get()))
if (!(*m_immutableSamplers)[i]->canBeRestoredFrom((*other->m_immutableSamplers)[i].get()))
return false;
}
}
Expand All @@ -115,21 +115,21 @@ class ICPUDescriptorSetLayout : public IDescriptorSetLayout<ICPUSampler>, public
return;

--_levelsBelow;
if (m_samplers)
if (m_immutableSamplers)
{
for (uint32_t i = 0u; i < m_samplers->size(); ++i)
restoreFromDummy_impl_call((*m_samplers)[i].get(), (*other->m_samplers)[i].get(), _levelsBelow);
for (uint32_t i = 0u; i < m_immutableSamplers->size(); ++i)
restoreFromDummy_impl_call((*m_immutableSamplers)[i].get(), (*other->m_immutableSamplers)[i].get(), _levelsBelow);
}
}

bool isAnyDependencyDummy_impl(uint32_t _levelsBelow) const override
{
--_levelsBelow;
if (m_samplers)
if (m_immutableSamplers)
{
for (uint32_t i = 0u; i < m_samplers->size(); ++i)
for (uint32_t i = 0u; i < m_immutableSamplers->size(); ++i)
{
if ((*m_samplers)[i]->isAnyDependencyDummy(_levelsBelow))
if ((*m_immutableSamplers)[i]->isAnyDependencyDummy(_levelsBelow))
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/asset/ICPUSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ICPUSampler : public ISampler, public IAsset


_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_SAMPLER;
inline E_TYPE getAssetType() const override { return AssetType; }
inline IAsset::E_TYPE getAssetType() const override { return AssetType; }

bool canBeRestoredFrom(const IAsset* _other) const override
{
Expand Down
12 changes: 7 additions & 5 deletions include/nbl/asset/IDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class IDescriptor : public virtual core::IReferenceCounted
public:
enum class E_TYPE : uint8_t
{
ET_COMBINED_IMAGE_SAMPLER = 0,
ET_SAMPLER = 0,
ET_COMBINED_IMAGE_SAMPLER,
ET_SAMPLED_IMAGE,
ET_STORAGE_IMAGE,
ET_UNIFORM_TEXEL_BUFFER,
ET_STORAGE_TEXEL_BUFFER,
Expand All @@ -39,6 +41,7 @@ class IDescriptor : public virtual core::IReferenceCounted
enum E_CATEGORY : uint8_t
{
EC_BUFFER = 0,
EC_SAMPLER,
EC_IMAGE,
EC_BUFFER_VIEW,
EC_ACCELERATION_STRUCTURE,
Expand All @@ -48,24 +51,23 @@ class IDescriptor : public virtual core::IReferenceCounted
{
switch (type)
{
case E_TYPE::ET_SAMPLER:
return EC_SAMPLER;
case E_TYPE::ET_COMBINED_IMAGE_SAMPLER:
case E_TYPE::ET_SAMPLED_IMAGE:
case E_TYPE::ET_STORAGE_IMAGE:
case E_TYPE::ET_INPUT_ATTACHMENT:
return EC_IMAGE;
break;
case E_TYPE::ET_UNIFORM_TEXEL_BUFFER:
case E_TYPE::ET_STORAGE_TEXEL_BUFFER:
return EC_BUFFER_VIEW;
break;
case E_TYPE::ET_UNIFORM_BUFFER:
case E_TYPE::ET_STORAGE_BUFFER:
case E_TYPE::ET_UNIFORM_BUFFER_DYNAMIC:
case E_TYPE::ET_STORAGE_BUFFER_DYNAMIC:
return EC_BUFFER;
break;
case E_TYPE::ET_ACCELERATION_STRUCTURE:
return EC_ACCELERATION_STRUCTURE;
break;
default:
break;
}
Expand Down
46 changes: 26 additions & 20 deletions include/nbl/asset/IDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,28 @@ class IDescriptorSet : public virtual core::IReferenceCounted // TODO: try to re

auto operator<=>(const SBufferInfo&) const = default;
};
struct SImageInfo
{
// This will be ignored if the DS layout already has an immutable sampler specified for the binding.
core::smart_refctd_ptr<typename layout_t::sampler_type> sampler;
IImage::LAYOUT imageLayout;
};
struct SImageInfo
{
IImage::LAYOUT imageLayout;
};
struct SCombinedImageSamplerInfo : SImageInfo
{
core::smart_refctd_ptr<typename layout_t::sampler_type> sampler;
};

core::smart_refctd_ptr<IDescriptor> desc;
union SBufferImageInfo
{
SBufferImageInfo()
{
memset(&buffer, 0, core::max<size_t>(sizeof(buffer), sizeof(image)));
memset(&buffer, 0, core::max<size_t>(sizeof(buffer), sizeof(combinedImageSampler)));
};

~SBufferImageInfo() {};

SBufferInfo buffer;
SImageInfo image;
SCombinedImageSamplerInfo combinedImageSampler;
} info;

SDescriptorInfo() {}
Expand Down Expand Up @@ -92,41 +95,44 @@ class IDescriptorSet : public virtual core::IReferenceCounted // TODO: try to re
}
~SDescriptorInfo()
{
if (desc && desc->getTypeCategory()==IDescriptor::EC_IMAGE)
info.image.sampler = nullptr;
if (desc && desc->getTypeCategory() == IDescriptor::EC_IMAGE)
info.combinedImageSampler.sampler = nullptr;
}

inline SDescriptorInfo& operator=(const SDescriptorInfo& other)
{
if (desc && desc->getTypeCategory()==IDescriptor::EC_IMAGE)
info.image.sampler = nullptr;
if (desc and desc->getTypeCategory()==IDescriptor::EC_IMAGE)
info.combinedImageSampler.sampler = nullptr;
desc = other.desc;
const auto type = desc->getTypeCategory();
if (type!=IDescriptor::EC_IMAGE)
info.buffer = other.info.buffer;
else
info.image = other.info.image;
if (desc)
{
const auto type = desc->getTypeCategory();
if (type != IDescriptor::EC_IMAGE)
info.buffer = other.info.buffer;
else
info.combinedImageSampler = other.info.combinedImageSampler;
}
return *this;
}
inline SDescriptorInfo& operator=(SDescriptorInfo&& other)
{
if (desc && desc->getTypeCategory()==IDescriptor::EC_IMAGE)
info.image = {nullptr,IImage::LAYOUT::UNDEFINED};
if (desc and desc->getTypeCategory() == IDescriptor::EC_IMAGE)
info.combinedImageSampler = {IImage::LAYOUT::UNDEFINED, nullptr};
desc = std::move(other.desc);
if (desc)
{
const auto type = desc->getTypeCategory();
if (type!=IDescriptor::EC_IMAGE)
info.buffer = other.info.buffer;
else
info.image = other.info.image;
info.combinedImageSampler = other.info.combinedImageSampler;
}
return *this;
}

inline bool operator!=(const SDescriptorInfo& other) const
{
if (desc != desc)
if (desc != other.desc)
return true;
return info.buffer != other.info.buffer;
}
Expand Down
Loading