diff --git a/runtime/RHI/RHI_Device.h b/runtime/RHI/RHI_Device.h index a9d9b4d44..6ad55a116 100644 --- a/runtime/RHI/RHI_Device.h +++ b/runtime/RHI/RHI_Device.h @@ -46,7 +46,6 @@ namespace spartan static void* GetQueueRhiResource(const RHI_Queue_Type type); // descriptors - static void CreateDescriptorPool(); static void AllocateDescriptorSet(void*& resource, RHI_DescriptorSetLayout* descriptor_set_layout, const std::vector& descriptors); static std::unordered_map& GetDescriptorSets(); static void* GetDescriptorSet(const RHI_Device_Bindless_Resource resource_type); diff --git a/runtime/RHI/Vulkan/Vulkan_Device.cpp b/runtime/RHI/Vulkan/Vulkan_Device.cpp index 6100715c1..628c004a4 100644 --- a/runtime/RHI/Vulkan/Vulkan_Device.cpp +++ b/runtime/RHI/Vulkan/Vulkan_Device.cpp @@ -757,6 +757,32 @@ namespace spartan unordered_map> pipelines; unordered_map> descriptor_cache; + void create_pool() + { + static array pool_sizes = + { + VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_SAMPLER, rhi_max_array_size * rhi_max_descriptor_set_count }, + VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, rhi_max_array_size * rhi_max_descriptor_set_count }, + VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, rhi_max_array_size * rhi_max_descriptor_set_count }, + VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, rhi_max_array_size * rhi_max_descriptor_set_count }, + VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rhi_max_array_size * rhi_max_descriptor_set_count } + }; + + // describe + VkDescriptorPoolCreateInfo pool_create_info = {}; + pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT; + pool_create_info.poolSizeCount = static_cast(pool_sizes.size()); + pool_create_info.pPoolSizes = pool_sizes.data(); + pool_create_info.maxSets = rhi_max_descriptor_set_count; + + // create + SP_ASSERT(descriptors::descriptor_pool == nullptr); + SP_ASSERT_VK(vkCreateDescriptorPool(RHI_Context::device, &pool_create_info, nullptr, &descriptors::descriptor_pool)); + + Profiler::m_descriptor_set_count = 0; + } + void merge_descriptors(vector& base_descriptors, const std::vector& additional_descriptors) { for (const RHI_Descriptor& descriptor_additional : additional_descriptors) @@ -1445,7 +1471,7 @@ namespace spartan } vulkan_memory_allocator::initialize(); - CreateDescriptorPool(); + descriptors::create_pool(); // gpu dependent actions { @@ -1579,7 +1605,7 @@ namespace spartan void RHI_Device::DeletionQueueParse() { lock_guard guard(mutex_deletion_queue); - + for (auto& it : deletion_queue) { RHI_Resource_Type resource_type = it.first; @@ -1605,7 +1631,7 @@ namespace spartan } // delete descriptor sets which are now invalid (because they are referring to a deleted resource) - if (resource_type == RHI_Resource_Type::TextureView || resource_type == RHI_Resource_Type::Buffer || resource_type == RHI_Resource_Type::Sampler) + if (resource_type == RHI_Resource_Type::TextureView || resource_type == RHI_Resource_Type::Buffer) { for (auto it = descriptors::sets.begin(); it != descriptors::sets.end();) { @@ -1621,6 +1647,8 @@ namespace spartan } } } + + // samplers are bindless so they just update the set again } } @@ -1666,32 +1694,6 @@ namespace spartan // descriptors - void RHI_Device::CreateDescriptorPool() - { - static array pool_sizes = - { - VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_SAMPLER, rhi_max_array_size * rhi_max_descriptor_set_count }, - VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, rhi_max_array_size * rhi_max_descriptor_set_count }, - VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, rhi_max_array_size * rhi_max_descriptor_set_count }, - VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, rhi_max_array_size * rhi_max_descriptor_set_count }, - VkDescriptorPoolSize{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rhi_max_array_size * rhi_max_descriptor_set_count } - }; - - // describe - VkDescriptorPoolCreateInfo pool_create_info = {}; - pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; - pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT; - pool_create_info.poolSizeCount = static_cast(pool_sizes.size()); - pool_create_info.pPoolSizes = pool_sizes.data(); - pool_create_info.maxSets = rhi_max_descriptor_set_count; - - // create - SP_ASSERT(descriptors::descriptor_pool == nullptr); - SP_ASSERT_VK(vkCreateDescriptorPool(RHI_Context::device, &pool_create_info, nullptr, &descriptors::descriptor_pool)); - - Profiler::m_descriptor_set_count = 0; - } - void RHI_Device::AllocateDescriptorSet(void*& resource, RHI_DescriptorSetLayout* descriptor_set_layout, const vector& descriptors_) { // describe @@ -1748,7 +1750,7 @@ namespace spartan array* material_textures, RHI_Buffer* material_parameters, RHI_Buffer* light_parameters, - const std::array, static_cast(Renderer_Sampler::Max)>* samplers + const array, static_cast(Renderer_Sampler::Max)>* samplers ) { if (samplers) diff --git a/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp b/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp index f89590412..b62387a4b 100644 --- a/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp +++ b/runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp @@ -367,8 +367,6 @@ namespace spartan { if (context_created) { - RHI_Device::QueueWaitAll(); - SP_ASSERT(ffxFsr3UpscalerContextDestroy(&context) == FFX_OK); context_created = false; @@ -994,6 +992,8 @@ namespace spartan void RHI_FidelityFX::Resize(const Vector2& resolution_render, const Vector2& resolution_output) { #ifdef _WIN32 + RHI_Device::QueueWaitAll(); + bool resolution_render_changed = resolution_render.x != resolution_render_width || resolution_render.y != resolution_render_height; bool resolution_output_changed = resolution_output.x != resolution_output_width || resolution_output.y != resolution_output_height; diff --git a/runtime/Rendering/Renderer.cpp b/runtime/Rendering/Renderer.cpp index 121dae8a6..a1b20c89f 100644 --- a/runtime/Rendering/Renderer.cpp +++ b/runtime/Rendering/Renderer.cpp @@ -84,6 +84,7 @@ namespace spartan array binldess_lights; bool bindless_materials_dirty = true; bool bindless_lights_dirty = true; + bool bindless_samplers_dirty = true; // misc unordered_map m_options; @@ -627,6 +628,13 @@ namespace spartan } } + if (bindless_samplers_dirty) + { + RHI_Device::UpdateBindlessResources(nullptr, nullptr, nullptr, &Renderer::GetSamplers()); + + bindless_samplers_dirty = false; + } + if (bindless_materials_dirty) { // update parameters buffer @@ -1080,6 +1088,11 @@ namespace spartan buffer->Update(cmd_list, &binldess_lights[0], update_size); } + void Renderer::BindlessUpdateSamplers() + { + bindless_samplers_dirty = true; + } + void Renderer::Screenshot(const string& file_path) { GetRenderTarget(Renderer_RenderTarget::frame_output)->SaveAsImage(file_path); diff --git a/runtime/Rendering/Renderer.h b/runtime/Rendering/Renderer.h index e17e76942..507ff6c8a 100644 --- a/runtime/Rendering/Renderer.h +++ b/runtime/Rendering/Renderer.h @@ -109,6 +109,7 @@ namespace spartan static std::array, static_cast(Renderer_RenderTarget::max)>& GetRenderTargets(); static std::array, static_cast(Renderer_Shader::max)>& GetShaders(); static std::array, static_cast(Renderer_Buffer::Max)>& GetStructuredBuffers(); + static std::array, static_cast(Renderer_Sampler::Max)>& GetSamplers(); // get individual static RHI_RasterizerState* GetRasterizerState(const Renderer_RasterizerState type); @@ -116,7 +117,6 @@ namespace spartan static RHI_BlendState* GetBlendState(const Renderer_BlendState type); static RHI_Texture* GetRenderTarget(const Renderer_RenderTarget type); static RHI_Shader* GetShader(const Renderer_Shader type); - static RHI_Sampler* GetSampler(const Renderer_Sampler type); static RHI_Buffer* GetBuffer(const Renderer_Buffer type); static RHI_Texture* GetStandardTexture(const Renderer_StandardTexture type); static std::shared_ptr& GetStandardMesh(const MeshType type); @@ -193,6 +193,7 @@ namespace spartan // bindless static void BindlessUpdateMaterialsParameters(RHI_CommandList* cmd_list); static void BindlessUpdateLights(RHI_CommandList* cmd_lis); + static void BindlessUpdateSamplers(); // misc static std::unordered_map>> m_renderables; diff --git a/runtime/Rendering/Renderer_Resources.cpp b/runtime/Rendering/Renderer_Resources.cpp index 85409ef94..b9a345781 100644 --- a/runtime/Rendering/Renderer_Resources.cpp +++ b/runtime/Rendering/Renderer_Resources.cpp @@ -167,7 +167,7 @@ namespace spartan } } - RHI_Device::UpdateBindlessResources(nullptr, nullptr, nullptr, &samplers); + Renderer::BindlessUpdateSamplers(); } void Renderer::CreateRenderTargets(const bool create_render, const bool create_output, const bool create_dynamic) @@ -266,7 +266,6 @@ namespace spartan render_target(Renderer_RenderTarget::skysphere) = make_shared(RHI_Texture_Type::Type2D, 4096, 4096, 1, mip_count, RHI_Format::R11G11B10_Float, flags | RHI_Texture_PerMipViews, "skysphere"); } - RHI_Device::QueueWaitAll(); RHI_FidelityFX::Resize(GetResolutionRender(), GetResolutionOutput()); } @@ -622,6 +621,11 @@ namespace spartan return buffers; } + array, static_cast(Renderer_Sampler::Max)>& Renderer::GetSamplers() + { + return samplers; + } + RHI_RasterizerState* Renderer::GetRasterizerState(const Renderer_RasterizerState type) { return rasterizer_states[static_cast(type)].get(); @@ -647,11 +651,6 @@ namespace spartan return shaders[static_cast(type)].get(); } - RHI_Sampler* Renderer::GetSampler(const Renderer_Sampler type) - { - return samplers[static_cast(type)].get(); - } - RHI_Buffer* Renderer::GetBuffer(const Renderer_Buffer type) { return buffers[static_cast(type)].get(); @@ -676,4 +675,6 @@ namespace spartan { return standard_material; } + + }