Skip to content

Commit

Permalink
configure layout array lengths and robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNumbat committed Mar 18, 2024
1 parent 10533e0 commit 5e608b9
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 35 deletions.
16 changes: 10 additions & 6 deletions rvk/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,19 @@ template<Region R>
struct Make {
template<Binding B>
void apply() {
u64 idx = bindings.length();
bindings.push(VkDescriptorSetLayoutBinding{
.binding = static_cast<u32>(bindings.length()),
.binding = static_cast<u32>(idx),
.descriptorType = B::type,
.descriptorCount = 1,
.descriptorCount = counts.length() ? counts[idx] : 1,
.stageFlags = B::stages,
.pImmutableSamplers = null,
});
flags.push(B::flags);
}
Vec<VkDescriptorSetLayoutBinding, Mregion<R>>& bindings;
Vec<VkDescriptorBindingFlags, Mregion<R>>& flags;
Slice<u32> counts;
};

template<Region R, Binding... Binds>
Expand All @@ -293,11 +295,13 @@ struct Write {
struct Binder {
template<Type_List L>
requires(Reflect::All<rvk::Is_Binding, L>)
static Descriptor_Set_Layout make(Arc<rvk::impl::Device, Alloc> device) {
static Descriptor_Set_Layout make(Arc<rvk::impl::Device, Alloc> device, Slice<u32> counts) {
constexpr u64 N = Reflect::List_Length<L>;
assert(counts.length() == N || counts.length() == 0);
Region(R) {
Vec<VkDescriptorSetLayoutBinding, Mregion<R>> bindings(Reflect::List_Length<L>);
Vec<VkDescriptorBindingFlags, Mregion<R>> flags(Reflect::List_Length<L>);
Reflect::Iter<Make<R>, L>::apply(Make<R>{bindings, flags});
Vec<VkDescriptorSetLayoutBinding, Mregion<R>> bindings(N);
Vec<VkDescriptorBindingFlags, Mregion<R>> flags(N);
Reflect::Iter<Make<R>, L>::apply(Make<R>{bindings, flags, counts});
return Descriptor_Set_Layout{move(device), bindings.slice(), flags.slice()};
}
}
Expand Down
19 changes: 9 additions & 10 deletions rvk/descriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ void Descriptor_Pool::release(Descriptor_Set& set) {
}

Descriptor_Set Descriptor_Pool::make(Descriptor_Set_Layout& layout, u64 frames_in_flight,
Slice<u32> counts) {
assert(counts.length() == 0 || counts.length() == layout.flag_count);
u32 variable_count) {

Vec<VkDescriptorSet, Alloc> sets;
auto sets = Vec<VkDescriptorSet, Alloc>::make(frames_in_flight);

Region(R) {

Vec<u32, Mregion<R>> counts(frames_in_flight);
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);
for(u64 i = 0; i < frames_in_flight; ++i) {
counts.push(variable_count);
layouts.push(layout);
}

VkDescriptorSetVariableDescriptorCountAllocateInfo variable_count_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO,
Expand All @@ -79,7 +80,7 @@ Descriptor_Set Descriptor_Pool::make(Descriptor_Set_Layout& layout, u64 frames_i

VkDescriptorSetAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.pNext = counts.length() ? &variable_count_info : null,
.pNext = &variable_count_info,
.descriptorPool = pool,
.descriptorSetCount = static_cast<u32>(frames_in_flight),
.pSetLayouts = layouts.data(),
Expand Down Expand Up @@ -121,7 +122,7 @@ void Descriptor_Set::write(u64 frame_index, Slice<VkWriteDescriptorSet> writes)
Descriptor_Set_Layout::Descriptor_Set_Layout(Arc<Device, Alloc> D,
Slice<VkDescriptorSetLayoutBinding> bindings,
Slice<VkDescriptorBindingFlags> flags)
: device(move(D)), flag_count(flags.length()) {
: device(move(D)) {

assert(bindings.length() == flags.length() || flags.length() == 0);

Expand Down Expand Up @@ -158,8 +159,6 @@ Descriptor_Set_Layout& Descriptor_Set_Layout::operator=(Descriptor_Set_Layout&&
device = move(src.device);
layout = src.layout;
src.layout = null;
flag_count = src.flag_count;
src.flag_count = 0;
return *this;
}

Expand Down
3 changes: 1 addition & 2 deletions rvk/descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct Descriptor_Set_Layout {

Arc<Device, Alloc> device;
VkDescriptorSetLayout layout = null;
u64 flag_count = 0;

friend struct Compositor;
friend struct Binder;
Expand Down Expand Up @@ -78,7 +77,7 @@ struct Descriptor_Pool {
return pool;
}

Descriptor_Set make(Descriptor_Set_Layout& layout, u64 frames_in_flight, Slice<u32> counts);
Descriptor_Set make(Descriptor_Set_Layout& layout, u64 frames_in_flight, u32 variable_count);

private:
explicit Descriptor_Pool(Arc<Device, Alloc> device, u32 bindings_per_type, bool ray_tracing);
Expand Down
15 changes: 8 additions & 7 deletions rvk/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "commands.h"
#include "device.h"

static VkPhysicalDeviceFeatures2* baseline_features(bool ray_tracing) {
static VkPhysicalDeviceFeatures2* baseline_features(bool ray_tracing, bool robustness) {

static VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR ray_position_fetch_features = {};
ray_position_fetch_features.sType =
Expand Down Expand Up @@ -49,7 +49,7 @@ static VkPhysicalDeviceFeatures2* baseline_features(bool ray_tracing) {
static VkPhysicalDeviceVulkan13Features vk13_features = {};
vk13_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
vk13_features.pNext = &shader_clock_features;
vk13_features.robustImageAccess = VK_TRUE;
vk13_features.robustImageAccess = robustness;
vk13_features.synchronization2 = VK_TRUE;
vk13_features.dynamicRendering = VK_TRUE;
vk13_features.maintenance4 = VK_TRUE;
Expand Down Expand Up @@ -97,8 +97,8 @@ static VkPhysicalDeviceFeatures2* baseline_features(bool ray_tracing) {
static VkPhysicalDeviceRobustness2FeaturesEXT robust_features = {};
robust_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
robust_features.pNext = &vk11_features;
robust_features.robustBufferAccess2 = VK_TRUE;
robust_features.robustImageAccess2 = VK_TRUE;
robust_features.robustBufferAccess2 = robustness;
robust_features.robustImageAccess2 = robustness;
robust_features.nullDescriptor = VK_TRUE;

static VkPhysicalDeviceMemoryPriorityFeaturesEXT memory_features = {};
Expand All @@ -109,7 +109,7 @@ static VkPhysicalDeviceFeatures2* baseline_features(bool ray_tracing) {
static VkPhysicalDeviceFeatures2 features2 = {};
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features2.pNext = &memory_features;
features2.features.robustBufferAccess = VK_TRUE;
features2.features.robustBufferAccess = robustness;
features2.features.imageCubeArray = VK_TRUE;
features2.features.geometryShader = VK_TRUE;
features2.features.tessellationShader = VK_TRUE;
Expand Down Expand Up @@ -338,7 +338,8 @@ void Physical_Device::imgui() {
}
}

Device::Device(Arc<Physical_Device, Alloc> P, VkSurfaceKHR surface, bool ray_tracing)
Device::Device(Arc<Physical_Device, Alloc> P, VkSurfaceKHR surface, bool ray_tracing,
bool robustness)
: physical_device(move(P)) {

Profile::Time_Point start = Profile::timestamp();
Expand Down Expand Up @@ -450,7 +451,7 @@ Device::Device(Arc<Physical_Device, Alloc> P, VkSurfaceKHR surface, bool ray_tra

{
VkDeviceCreateInfo dev_info = {};
dev_info.pNext = baseline_features(ray_tracing);
dev_info.pNext = baseline_features(ray_tracing, robustness);
dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
dev_info.queueCreateInfoCount = static_cast<u32>(queue_infos.length());
dev_info.pQueueCreateInfos = queue_infos.data();
Expand Down
2 changes: 1 addition & 1 deletion rvk/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct Device {

private:
explicit Device(Arc<Physical_Device, Alloc> physical_device, VkSurfaceKHR surface,
bool ray_tracing);
bool ray_tracing, bool robustness);
friend struct Arc<Device, Alloc>;
friend struct Vk;
friend struct Compositor;
Expand Down
4 changes: 2 additions & 2 deletions rvk/execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using namespace rpp;

template<Type_List L>
requires(Reflect::All<Is_Binding, L>)
Descriptor_Set_Layout make_layout() {
return impl::Binder::template make<L>(impl::get_device());
Descriptor_Set_Layout make_layout(Slice<u32> counts) {
return impl::Binder::template make<L>(impl::get_device(), counts);
}

template<Type_List L, Binding... Binds>
Expand Down
8 changes: 4 additions & 4 deletions rvk/rvk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Vk::Vk(Config config) {

physical_device = instance->physical_device(instance->surface(), config.ray_tracing);

device =
Arc<Device, Alloc>::make(physical_device.dup(), instance->surface(), config.ray_tracing);
device = Arc<Device, Alloc>::make(physical_device.dup(), instance->surface(),
config.ray_tracing, config.robust_accesses);

host_memory = Arc<Device_Memory, Alloc>::make(physical_device, device.dup(), Heap::host,
config.host_heap);
Expand Down Expand Up @@ -595,9 +595,9 @@ Opt<Binding_Table> make_table(Commands& cmds, impl::Pipeline& pipeline,
return impl::singleton->make_table(cmds, pipeline, mapping);
}

Descriptor_Set make_set(Descriptor_Set_Layout& layout, Slice<u32> counts) {
Descriptor_Set make_set(Descriptor_Set_Layout& layout, u32 variable_count) {
return impl::singleton->descriptor_pool->make(layout, impl::singleton->state.frames_in_flight,
counts);
variable_count);
}

Box<Shader_Loader, Alloc> make_shader_loader() {
Expand Down
6 changes: 4 additions & 2 deletions rvk/rvk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ using Finalizer = FunctionN<16, void()>;

struct Config {
bool validation = true;
bool robust_accesses = true;
bool ray_tracing = false;
bool imgui = false;

u32 frames_in_flight = 2;
u32 descriptors_per_type = 128;

Expand Down Expand Up @@ -77,9 +79,9 @@ Opt<BLAS::Staged> make_blas(Buffer geometry, Vec<BLAS::Offsets, Alloc> offsets);

template<Type_List L>
requires(Reflect::All<Is_Binding, L>)
Descriptor_Set_Layout make_layout();
Descriptor_Set_Layout make_layout(Slice<u32> counts = Slice<u32>{});

Descriptor_Set make_set(Descriptor_Set_Layout& layout, Slice<u32> counts = Slice<u32>{});
Descriptor_Set make_set(Descriptor_Set_Layout& layout, u32 variable_count = 0);

template<Type_List L, Binding... Binds>
requires(Same<L, List<Binds...>>)
Expand Down
6 changes: 6 additions & 0 deletions rvk/shader_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ void Shader_Loader::try_reload() {
}
}

void Shader_Loader::trigger(Token token) {
assert(device.ok());
Thread::Lock lock{mutex};
callbacks.get(reloads.get(token))(*this);
}

void Shader_Loader::on_reload(Slice<Shader_Loader::Token> tokens,
FunctionN<16, void(Shader_Loader&)> callback) {
assert(device.ok());
Expand Down
1 change: 1 addition & 0 deletions rvk/shader_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct Shader_Loader {

void try_reload();
void on_reload(Slice<Token> shaders, FunctionN<16, void(Shader_Loader&)> callback);
void trigger(Token token);

private:
using Device = impl::Device;
Expand Down
2 changes: 1 addition & 1 deletion rvk/swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Compositor::Compositor(Arc<Device, Alloc> D, Arc<Swapchain, Alloc> S,
Arc<Descriptor_Pool, Alloc>& pool)
: swapchain(move(S)), device(move(D)), v(compositor_v(device.dup())),
f(compositor_f(device.dup())), ds_layout(device.dup(), compositor_ds_layout(), Slice<u32>{}),
ds(pool->make(ds_layout, swapchain->frame_count(), Slice<u32>{})),
ds(pool->make(ds_layout, swapchain->frame_count(), 0)),
sampler(device.dup(), VK_FILTER_NEAREST, VK_FILTER_NEAREST),
pipeline(Pipeline{device.dup(), compositor_pipeline_info(swapchain, ds_layout, v, f)}) {
info("[rvk] Created compositor.");
Expand Down

0 comments on commit 5e608b9

Please sign in to comment.