diff --git a/rvk/bindings.h b/rvk/bindings.h index 29e699e..2b49cf1 100644 --- a/rvk/bindings.h +++ b/rvk/bindings.h @@ -266,10 +266,11 @@ template struct Make { template void apply() { + u64 idx = bindings.length(); bindings.push(VkDescriptorSetLayoutBinding{ - .binding = static_cast(bindings.length()), + .binding = static_cast(idx), .descriptorType = B::type, - .descriptorCount = 1, + .descriptorCount = counts.length() ? counts[idx] : 1, .stageFlags = B::stages, .pImmutableSamplers = null, }); @@ -277,6 +278,7 @@ struct Make { } Vec>& bindings; Vec>& flags; + Slice counts; }; template @@ -293,11 +295,13 @@ struct Write { struct Binder { template requires(Reflect::All) - static Descriptor_Set_Layout make(Arc device) { + static Descriptor_Set_Layout make(Arc device, Slice counts) { + constexpr u64 N = Reflect::List_Length; + assert(counts.length() == N || counts.length() == 0); Region(R) { - Vec> bindings(Reflect::List_Length); - Vec> flags(Reflect::List_Length); - Reflect::Iter, L>::apply(Make{bindings, flags}); + Vec> bindings(N); + Vec> flags(N); + Reflect::Iter, L>::apply(Make{bindings, flags, counts}); return Descriptor_Set_Layout{move(device), bindings.slice(), flags.slice()}; } } diff --git a/rvk/descriptors.cpp b/rvk/descriptors.cpp index 1f3e890..4ee3911 100644 --- a/rvk/descriptors.cpp +++ b/rvk/descriptors.cpp @@ -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 counts) { - assert(counts.length() == 0 || counts.length() == layout.flag_count); + u32 variable_count) { - Vec sets; + auto sets = Vec::make(frames_in_flight); Region(R) { - + Vec> counts(frames_in_flight); Vec> 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, @@ -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(frames_in_flight), .pSetLayouts = layouts.data(), @@ -121,7 +122,7 @@ void Descriptor_Set::write(u64 frame_index, Slice writes) Descriptor_Set_Layout::Descriptor_Set_Layout(Arc D, Slice bindings, Slice flags) - : device(move(D)), flag_count(flags.length()) { + : device(move(D)) { assert(bindings.length() == flags.length() || flags.length() == 0); @@ -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; } diff --git a/rvk/descriptors.h b/rvk/descriptors.h index 74347b6..f92820b 100644 --- a/rvk/descriptors.h +++ b/rvk/descriptors.h @@ -32,7 +32,6 @@ struct Descriptor_Set_Layout { Arc device; VkDescriptorSetLayout layout = null; - u64 flag_count = 0; friend struct Compositor; friend struct Binder; @@ -78,7 +77,7 @@ struct Descriptor_Pool { return pool; } - Descriptor_Set make(Descriptor_Set_Layout& layout, u64 frames_in_flight, Slice counts); + Descriptor_Set make(Descriptor_Set_Layout& layout, u64 frames_in_flight, u32 variable_count); private: explicit Descriptor_Pool(Arc device, u32 bindings_per_type, bool ray_tracing); diff --git a/rvk/device.cpp b/rvk/device.cpp index 8bcbcb6..84a48a6 100644 --- a/rvk/device.cpp +++ b/rvk/device.cpp @@ -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 = @@ -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; @@ -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 = {}; @@ -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; @@ -338,7 +338,8 @@ void Physical_Device::imgui() { } } -Device::Device(Arc P, VkSurfaceKHR surface, bool ray_tracing) +Device::Device(Arc P, VkSurfaceKHR surface, bool ray_tracing, + bool robustness) : physical_device(move(P)) { Profile::Time_Point start = Profile::timestamp(); @@ -450,7 +451,7 @@ Device::Device(Arc 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(queue_infos.length()); dev_info.pQueueCreateInfos = queue_infos.data(); diff --git a/rvk/device.h b/rvk/device.h index 7cacdeb..330d359 100644 --- a/rvk/device.h +++ b/rvk/device.h @@ -120,7 +120,7 @@ struct Device { private: explicit Device(Arc physical_device, VkSurfaceKHR surface, - bool ray_tracing); + bool ray_tracing, bool robustness); friend struct Arc; friend struct Vk; friend struct Compositor; diff --git a/rvk/execute.h b/rvk/execute.h index 432a4c6..ddcd230 100644 --- a/rvk/execute.h +++ b/rvk/execute.h @@ -17,8 +17,8 @@ using namespace rpp; template requires(Reflect::All) -Descriptor_Set_Layout make_layout() { - return impl::Binder::template make(impl::get_device()); +Descriptor_Set_Layout make_layout(Slice counts) { + return impl::Binder::template make(impl::get_device(), counts); } template diff --git a/rvk/rvk.cpp b/rvk/rvk.cpp index 81e51b0..c224a70 100644 --- a/rvk/rvk.cpp +++ b/rvk/rvk.cpp @@ -159,8 +159,8 @@ Vk::Vk(Config config) { physical_device = instance->physical_device(instance->surface(), config.ray_tracing); - device = - Arc::make(physical_device.dup(), instance->surface(), config.ray_tracing); + device = Arc::make(physical_device.dup(), instance->surface(), + config.ray_tracing, config.robust_accesses); host_memory = Arc::make(physical_device, device.dup(), Heap::host, config.host_heap); @@ -595,9 +595,9 @@ Opt make_table(Commands& cmds, impl::Pipeline& pipeline, return impl::singleton->make_table(cmds, pipeline, mapping); } -Descriptor_Set make_set(Descriptor_Set_Layout& layout, Slice 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 make_shader_loader() { diff --git a/rvk/rvk.h b/rvk/rvk.h index bf3dcda..9bdb50b 100644 --- a/rvk/rvk.h +++ b/rvk/rvk.h @@ -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; @@ -77,9 +79,9 @@ Opt make_blas(Buffer geometry, Vec offsets); template requires(Reflect::All) -Descriptor_Set_Layout make_layout(); +Descriptor_Set_Layout make_layout(Slice counts = Slice{}); -Descriptor_Set make_set(Descriptor_Set_Layout& layout, Slice counts = Slice{}); +Descriptor_Set make_set(Descriptor_Set_Layout& layout, u32 variable_count = 0); template requires(Same>) diff --git a/rvk/shader_loader.cpp b/rvk/shader_loader.cpp index ca71e5b..7ea5804 100644 --- a/rvk/shader_loader.cpp +++ b/rvk/shader_loader.cpp @@ -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 tokens, FunctionN<16, void(Shader_Loader&)> callback) { assert(device.ok()); diff --git a/rvk/shader_loader.h b/rvk/shader_loader.h index 404750e..96538cd 100644 --- a/rvk/shader_loader.h +++ b/rvk/shader_loader.h @@ -32,6 +32,7 @@ struct Shader_Loader { void try_reload(); void on_reload(Slice shaders, FunctionN<16, void(Shader_Loader&)> callback); + void trigger(Token token); private: using Device = impl::Device; diff --git a/rvk/swapchain.cpp b/rvk/swapchain.cpp index 5052ecf..e019dd8 100644 --- a/rvk/swapchain.cpp +++ b/rvk/swapchain.cpp @@ -194,7 +194,7 @@ Compositor::Compositor(Arc D, Arc S, Arc& 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{}), - ds(pool->make(ds_layout, swapchain->frame_count(), Slice{})), + 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.");