-
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.
- Loading branch information
Showing
14 changed files
with
440 additions
and
43 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
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,140 @@ | ||
|
||
#include <imgui/imgui.h> | ||
|
||
#include "descriptors.h" | ||
#include "device.h" | ||
|
||
namespace rvk::impl { | ||
|
||
using namespace rpp; | ||
|
||
Descriptor_Pool::Descriptor_Pool(Arc<Device, Alloc> D, u32 bindings_per_type, bool ray_tracing) | ||
: device(move(D)) { | ||
|
||
Profile::Time_Point start = Profile::timestamp(); | ||
|
||
Region(R) { | ||
Vec<VkDescriptorPoolSize, Mregion<R>> sizes{ | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_SAMPLER, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, bindings_per_type}, | ||
VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, bindings_per_type}}; | ||
|
||
if(ray_tracing) | ||
sizes.push(VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, | ||
bindings_per_type}); | ||
|
||
VkDescriptorPoolCreateInfo pool_info = {}; | ||
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; | ||
pool_info.poolSizeCount = static_cast<u32>(sizes.length()); | ||
pool_info.pPoolSizes = sizes.data(); | ||
pool_info.maxSets = static_cast<u32>(sizes.length()) * bindings_per_type; | ||
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; | ||
|
||
Thread::Lock lock(mutex); | ||
RVK_CHECK(vkCreateDescriptorPool(*device, &pool_info, null, &pool)); | ||
} | ||
|
||
Profile::Time_Point end = Profile::timestamp(); | ||
info("[rvk] Created descriptor pool in %ms.", Profile::ms(end - start)); | ||
} | ||
|
||
Descriptor_Pool::~Descriptor_Pool() { | ||
Thread::Lock lock(mutex); | ||
if(pool) { | ||
vkDestroyDescriptorPool(*device, pool, null); | ||
info("[rvk] Destroyed descriptor pool."); | ||
} | ||
pool = null; | ||
} | ||
|
||
void Descriptor_Pool::release(Descriptor_Set& set) { | ||
Thread::Lock lock(mutex); | ||
vkFreeDescriptorSets(*device, pool, static_cast<u32>(set.sets.length()), set.sets.data()); | ||
} | ||
|
||
Descriptor_Set Descriptor_Pool::make(Descriptor_Set_Layout& layout, u64 frames_in_flight) { | ||
|
||
Vec<VkDescriptorSet, Alloc> sets; | ||
|
||
Region(R) { | ||
|
||
Vec<VkDescriptorSetLayout, Mregion<R>> layouts(frames_in_flight); | ||
for(u64 i = 0; i < frames_in_flight; ++i) layouts.push(layout); | ||
|
||
sets.resize(frames_in_flight); | ||
|
||
VkDescriptorSetAllocateInfo alloc_info = {}; | ||
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; | ||
alloc_info.descriptorPool = pool; | ||
alloc_info.descriptorSetCount = static_cast<u32>(frames_in_flight); | ||
alloc_info.pSetLayouts = layouts.data(); | ||
|
||
{ | ||
Thread::Lock lock(mutex); | ||
RVK_CHECK(vkAllocateDescriptorSets(*device, &alloc_info, sets.data())); | ||
} | ||
} | ||
|
||
return Descriptor_Set{Arc<Descriptor_Pool, Alloc>::from_this(this), move(sets)}; | ||
} | ||
|
||
Descriptor_Set::Descriptor_Set(Arc<Descriptor_Pool, Alloc> pool, Vec<VkDescriptorSet, Alloc> sets) | ||
: pool(move(pool)), sets(move(sets)) { | ||
} | ||
|
||
Descriptor_Set::~Descriptor_Set() { | ||
if(sets.length()) { | ||
pool->release(*this); | ||
} | ||
} | ||
|
||
void Descriptor_Set::write(u64 frame_index, Slice<VkWriteDescriptorSet> writes) { | ||
assert(frame_index < sets.length()); | ||
|
||
Region(R) { | ||
Vec<VkWriteDescriptorSet, Mregion<R>> vk_writes; | ||
for(auto& write : writes) { | ||
vk_writes.push(write).dstSet = sets[frame_index]; | ||
} | ||
vkUpdateDescriptorSets(*pool->device, static_cast<u32>(vk_writes.length()), | ||
vk_writes.data(), 0, null); | ||
} | ||
} | ||
|
||
Descriptor_Set_Layout::Descriptor_Set_Layout(Arc<Device, Alloc> D, | ||
Slice<VkDescriptorSetLayoutBinding> bindings) | ||
: device(move(D)) { | ||
|
||
VkDescriptorSetLayoutCreateInfo info = {}; | ||
info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; | ||
info.bindingCount = static_cast<u32>(bindings.length()); | ||
info.pBindings = bindings.data(); | ||
|
||
RVK_CHECK(vkCreateDescriptorSetLayout(*device, &info, null, &layout)); | ||
} | ||
|
||
Descriptor_Set_Layout::~Descriptor_Set_Layout() { | ||
if(layout) vkDestroyDescriptorSetLayout(*device, layout, null); | ||
layout = null; | ||
} | ||
|
||
Descriptor_Set_Layout::Descriptor_Set_Layout(Descriptor_Set_Layout&& src) { | ||
*this = move(src); | ||
} | ||
|
||
Descriptor_Set_Layout& Descriptor_Set_Layout::operator=(Descriptor_Set_Layout&& src) { | ||
assert(this != &src); | ||
this->~Descriptor_Set_Layout(); | ||
device = move(src.device); | ||
layout = src.layout; | ||
src.layout = null; | ||
return *this; | ||
} | ||
|
||
} // namespace rvk::impl |
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,84 @@ | ||
|
||
#pragma once | ||
|
||
#include <rpp/base.h> | ||
#include <rpp/rc.h> | ||
|
||
#include "fwd.h" | ||
|
||
namespace rvk::impl { | ||
|
||
using namespace rpp; | ||
|
||
struct Descriptor_Set_Layout { | ||
|
||
explicit Descriptor_Set_Layout(Arc<Device, Alloc> device, | ||
Slice<VkDescriptorSetLayoutBinding> bindings); | ||
~Descriptor_Set_Layout(); | ||
|
||
Descriptor_Set_Layout(const Descriptor_Set_Layout&) = delete; | ||
Descriptor_Set_Layout& operator=(const Descriptor_Set_Layout&) = delete; | ||
Descriptor_Set_Layout(Descriptor_Set_Layout&&); | ||
Descriptor_Set_Layout& operator=(Descriptor_Set_Layout&&); | ||
|
||
operator VkDescriptorSetLayout() { | ||
return layout; | ||
} | ||
|
||
private: | ||
Arc<Device, Alloc> device; | ||
VkDescriptorSetLayout layout = null; | ||
}; | ||
|
||
struct Descriptor_Set { | ||
|
||
explicit Descriptor_Set(Arc<Descriptor_Pool, Alloc> pool, Vec<VkDescriptorSet, Alloc> sets); | ||
~Descriptor_Set(); | ||
|
||
Descriptor_Set(const Descriptor_Set&) = delete; | ||
Descriptor_Set& operator=(const Descriptor_Set&) = delete; | ||
Descriptor_Set(Descriptor_Set&& src) = default; | ||
Descriptor_Set& operator=(Descriptor_Set&& src) = default; | ||
|
||
void write(u64 frame_index, Slice<VkWriteDescriptorSet> writes); | ||
|
||
VkDescriptorSet get(u64 frame_index) { | ||
return sets[frame_index]; | ||
} | ||
|
||
private: | ||
Arc<Descriptor_Pool, Alloc> pool; | ||
Vec<VkDescriptorSet, Alloc> sets; | ||
|
||
friend struct Descriptor_Pool; | ||
}; | ||
|
||
struct Descriptor_Pool { | ||
|
||
~Descriptor_Pool(); | ||
|
||
Descriptor_Pool(const Descriptor_Pool&) = delete; | ||
Descriptor_Pool& operator=(const Descriptor_Pool&) = delete; | ||
Descriptor_Pool(Descriptor_Pool&&) = delete; | ||
Descriptor_Pool& operator=(Descriptor_Pool&&) = delete; | ||
|
||
operator VkDescriptorPool() { | ||
return pool; | ||
} | ||
|
||
Descriptor_Set make(Descriptor_Set_Layout& layout, u64 frames_in_flight); | ||
|
||
private: | ||
explicit Descriptor_Pool(Arc<Device, Alloc> device, u32 bindings_per_type, bool ray_tracing); | ||
friend struct Arc<Descriptor_Pool, Alloc>; | ||
|
||
void release(Descriptor_Set& set); | ||
|
||
Arc<Device, Alloc> device; | ||
VkDescriptorPool pool = null; | ||
Thread::Mutex mutex; | ||
|
||
friend struct Descriptor_Set; | ||
}; | ||
|
||
} // namespace rvk::impl |
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
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
Oops, something went wrong.