-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove DescriptorSetLayouts and DescriptorSets. Use singular version …
…instead (less overhead, template-based strong type constraint.)
- Loading branch information
1 parent
49cbad7
commit f7c245f
Showing
9 changed files
with
162 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module; | ||
|
||
#ifndef VKU_USE_STD_MODULE | ||
#include <cstdint> | ||
#include <compare> | ||
#include <tuple> | ||
#include <utility> | ||
#endif | ||
|
||
#include <vulkan/vulkan_hpp_macros.hpp> | ||
|
||
export module vku:descriptors.DescriptorSet; | ||
|
||
#ifdef VKU_USE_STD_MODULE | ||
import std; | ||
#endif | ||
export import :descriptors.DescriptorSetLayout; | ||
import :details; | ||
import :utils; | ||
|
||
template <vk::DescriptorType> struct WriteDescriptorInfo; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eSampler> { using type = vk::DescriptorImageInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eCombinedImageSampler> { using type = vk::DescriptorImageInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eSampledImage> { using type = vk::DescriptorImageInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eStorageImage> { using type = vk::DescriptorImageInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eUniformTexelBuffer> { using type = vk::BufferView; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eStorageTexelBuffer> { using type = vk::BufferView; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eUniformBuffer> { using type = vk::DescriptorBufferInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eStorageBuffer> { using type = vk::DescriptorBufferInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eUniformBufferDynamic> { using type = vk::DescriptorBufferInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eStorageBufferDynamic> { using type = vk::DescriptorBufferInfo; }; | ||
template <> struct WriteDescriptorInfo<vk::DescriptorType::eInputAttachment> { using type = vk::DescriptorImageInfo; }; | ||
template <vk::DescriptorType Type> using WriteDescriptorInfo_t = typename WriteDescriptorInfo<Type>::type; | ||
|
||
namespace vku { | ||
export template <concepts::derived_from_value_specialization_of<DescriptorSetLayout> Layout> | ||
class DescriptorSet : public vk::DescriptorSet { | ||
public: | ||
DescriptorSet() noexcept = default; | ||
DescriptorSet(const DescriptorSet&) noexcept = default; | ||
DescriptorSet(DescriptorSet&&) noexcept = default; | ||
DescriptorSet& operator=(const DescriptorSet&) noexcept = default; | ||
DescriptorSet& operator=(DescriptorSet&&) noexcept = default; | ||
|
||
template <std::uint32_t Binding> | ||
[[nodiscard]] auto getWrite(const vk::ArrayProxyNoTemporaries<const WriteDescriptorInfo_t<get<Binding>(Layout::bindingTypes)>> &descriptorInfos) const noexcept -> vk::WriteDescriptorSet { | ||
constexpr auto attachInfo = multilambda { | ||
[](vk::WriteDescriptorSet writeDescriptorSet, const vk::ArrayProxyNoTemporaries<const vk::DescriptorImageInfo> &descriptorInfos) { | ||
return writeDescriptorSet.setImageInfo(descriptorInfos); | ||
}, | ||
[](vk::WriteDescriptorSet writeDescriptorSet, const vk::ArrayProxyNoTemporaries<const vk::BufferView> &descriptorInfos) { | ||
return writeDescriptorSet.setTexelBufferView(descriptorInfos); | ||
}, | ||
[](vk::WriteDescriptorSet writeDescriptorSet, const vk::ArrayProxyNoTemporaries<const vk::DescriptorBufferInfo> &descriptorInfos) { | ||
return writeDescriptorSet.setBufferInfo(descriptorInfos); | ||
}, | ||
}; | ||
|
||
return attachInfo(vk::WriteDescriptorSet { *this, Binding, 0, {}, get<Binding>(Layout::bindingTypes) }, descriptorInfos); | ||
} | ||
|
||
template <concepts::derived_from_value_specialization_of<DescriptorSetLayout>... Layouts> | ||
friend auto allocateDescriptorSets(vk::Device, vk::DescriptorPool, std::tuple<const Layouts&...>) -> std::tuple<DescriptorSet<Layouts>...>; | ||
|
||
private: | ||
explicit DescriptorSet(vk::DescriptorSet descriptorSet) noexcept : vk::DescriptorSet { descriptorSet } {} | ||
}; | ||
|
||
export template <concepts::derived_from_value_specialization_of<DescriptorSetLayout>... Layouts> | ||
[[nodiscard]] auto allocateDescriptorSets( | ||
vk::Device device, | ||
vk::DescriptorPool pool, | ||
std::tuple<const Layouts&...> layouts | ||
) -> std::tuple<DescriptorSet<Layouts>...> { | ||
return std::apply([&](const auto &...layout) { | ||
return std::apply([&](auto... rawSet) { | ||
return std::tuple { DescriptorSet<Layouts> { rawSet }... }; | ||
}, device.allocateDescriptorSets({ pool, unsafeProxy({ *layout... }) }) | ranges::to_array<sizeof...(Layouts)>()); | ||
}, layouts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module; | ||
|
||
#include <cassert> | ||
#ifndef VKU_USE_STD_MODULE | ||
#include <cstdint> | ||
#include <array> | ||
#include <compare> | ||
#endif | ||
|
||
export module vku:descriptors.DescriptorSetLayout; | ||
|
||
#ifdef VKU_USE_STD_MODULE | ||
import std; | ||
#endif | ||
export import vulkan_hpp; | ||
export import :descriptors.PoolSizes; | ||
import :details; | ||
|
||
#define INDEX_SEQ(Is, N, ...) [&]<std::size_t ...Is>(std::index_sequence<Is...>) __VA_ARGS__ (std::make_index_sequence<N>{}) | ||
|
||
namespace vku { | ||
export template <vk::DescriptorType... BindingTypes> | ||
struct DescriptorSetLayout : vk::raii::DescriptorSetLayout { | ||
static constexpr std::uint32_t bindingCount = sizeof...(BindingTypes); | ||
static constexpr std::array bindingTypes = { BindingTypes... }; | ||
|
||
DescriptorSetLayout( | ||
const vk::raii::Device &device [[clang::lifetimebound]], | ||
const vk::DescriptorSetLayoutCreateInfo &createInfo | ||
) : vk::raii::DescriptorSetLayout { device, createInfo } { | ||
assert(createInfo.bindingCount == bindingCount && "The binding count must match the template parameter count."); | ||
INDEX_SEQ(Is, bindingCount, { | ||
assert(((createInfo.pBindings[Is].descriptorType == BindingTypes) && ...) && "The descriptor types must match the template parameter."); | ||
}); | ||
} | ||
|
||
[[nodiscard]] static auto getPoolSize() noexcept -> PoolSizes { | ||
PoolSizes poolSizes; | ||
poolSizes.setCount = 1; | ||
(++poolSizes.typeCounts[BindingTypes], ...); | ||
return poolSizes; | ||
} | ||
}; | ||
|
||
export template <concepts::derived_from_value_specialization_of<DescriptorSetLayout>... Layouts> | ||
[[nodiscard]] auto getPoolSizes() noexcept -> PoolSizes { | ||
return (Layouts::getPoolSize() + ...); | ||
} | ||
|
||
export template <concepts::derived_from_value_specialization_of<DescriptorSetLayout>... Layouts> | ||
[[nodiscard]] auto getPoolSizes(const Layouts &...) noexcept -> PoolSizes { | ||
return (Layouts::getPoolSize() + ...); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export module vku:details.functional; | ||
|
||
namespace vku::inline functional { | ||
export template <typename ...Fs> | ||
struct multilambda : Fs... { | ||
using Fs::operator()...; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export module vku:details; | ||
export import :details.concepts; | ||
export import :details.functional; | ||
export import :details.ranges; |