Skip to content

Commit

Permalink
[memory] fixed an issue where the deletion queue wouldn't parse, this…
Browse files Browse the repository at this point in the history
… could resolve out of memory issues when loading memory heavy worlds like Sponza
  • Loading branch information
PanosK92 committed Oct 24, 2024
1 parent f58f333 commit 3d83fc6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 48 deletions.
8 changes: 7 additions & 1 deletion runtime/RHI/Vulkan/Vulkan_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,13 @@ namespace Spartan

bool RHI_Device::DeletionQueueNeedsToParse()
{
return deletion_queue.size() > 5;
uint32_t objects_to_delete = 0;
for (uint32_t i = 0; i < static_cast<uint32_t>(RHI_Resource_Type::Max); i++)
{
objects_to_delete += static_cast<uint32_t>(deletion_queue[static_cast<RHI_Resource_Type>(i)].size());
}

return objects_to_delete > 0;
}

// descriptors
Expand Down
1 change: 1 addition & 0 deletions runtime/Rendering/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ namespace Spartan
{
return
static_cast<uint32_t>(MeshFlags::ImportRemoveRedundantData) |
//static_cast<uint32_t>(MeshFlags::ImportLights) |
static_cast<uint32_t>(MeshFlags::PostProcessNormalizeScale) |
static_cast<uint32_t>(MeshFlags::PostProcessOptimize);
}
Expand Down
14 changes: 0 additions & 14 deletions runtime/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ namespace Spartan
{
RHI_Device::QueueWaitAll();
RHI_Device::DeletionQueueParse();
SP_LOG_INFO("Parsed deletion queue");
}

// reset dynamic buffer offsets
Expand Down Expand Up @@ -737,19 +736,6 @@ namespace Spartan
}
}
}
// shadow resolution
else if (option == Renderer_Option::ShadowResolution)
{
const auto& light_entities = m_renderables[Renderer_Entity::Light];
for (const auto& light_entity : light_entities)
{
auto light = light_entity->GetComponent<Light>();
if (light->IsFlagSet(LightFlags::Shadows))
{
light->RefreshShadowMap();
}
}
}
else if (option == Renderer_Option::Hdr)
{
if (swap_chain)
Expand Down
64 changes: 32 additions & 32 deletions runtime/World/Components/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ namespace Spartan
{
UpdateMatrices();
}

// create shadow maps
{
uint32_t resolution = Renderer::GetOption<uint32_t>(Renderer_Option::ShadowResolution);
RHI_Format format_depth = RHI_Format::D32_Float;
RHI_Format format_color = RHI_Format::R8G8B8A8_Unorm;
uint32_t flags = RHI_Texture_Rtv | RHI_Texture_Srv | RHI_Texture_ClearBlit;
uint32_t array_length = GetLightType() == LightType::Spot ? 1 : 2;
bool resolution_dirty = (m_texture_depth ? m_texture_depth->GetWidth() : resolution) != resolution;

// spot light: 1 slice
// directional light: 2 slices for cascades
// point light: 2 slices for front and back paraboloid

if ((IsFlagSet(LightFlags::Shadows) && !m_texture_depth) || resolution_dirty)
{
m_texture_depth = make_unique<RHI_Texture>(RHI_Texture_Type::Type2DArray, resolution, resolution, array_length, 1, format_depth, flags, "light_depth");
}
else if (!IsFlagSet(LightFlags::Shadows) && m_texture_depth)
{
m_texture_depth = nullptr;
}

if ((IsFlagSet(LightFlags::ShadowsTransparent) && !m_texture_depth) || resolution_dirty)
{
m_texture_color = make_unique<RHI_Texture>(RHI_Texture_Type::Type2DArray, resolution, resolution, array_length, 1, format_color, flags, "light_color");
}
else if (!IsFlagSet(LightFlags::ShadowsTransparent) && m_texture_color)
{
m_texture_color = nullptr;
}
}
}

void Light::Serialize(FileStream* stream)
Expand Down Expand Up @@ -172,7 +204,6 @@ namespace Spartan
{
m_flags |= static_cast<uint32_t>(flag);
enabled = true;

}
else if (!enable && flag_present)
{
Expand All @@ -193,11 +224,6 @@ namespace Spartan
}
}

if (flag & LightFlags::Shadows || flag & LightFlags::ShadowsTransparent)
{
RefreshShadowMap();
}

SP_FIRE_EVENT(EventType::LightOnChanged);
}
}
Expand All @@ -213,11 +239,6 @@ namespace Spartan
SetRange(get_sensible_range(m_light_type));
SetIntensity(get_sensible_intensity(m_light_type));

if (IsFlagSet(Shadows) || IsFlagSet(ShadowsTransparent))
{
RefreshShadowMap();
}

UpdateMatrices();
World::Resolve();
}
Expand Down Expand Up @@ -480,25 +501,4 @@ namespace Spartan

return IsInViewFrustum(box, index);
}

void Light::RefreshShadowMap()
{
uint32_t resolution = Renderer::GetOption<uint32_t>(Renderer_Option::ShadowResolution);
RHI_Format format_depth = RHI_Format::D32_Float;
RHI_Format format_color = RHI_Format::R8G8B8A8_Unorm;
uint32_t flags = RHI_Texture_Rtv | RHI_Texture_Srv | RHI_Texture_ClearBlit;
m_texture_depth = nullptr;
m_texture_color = nullptr;
uint32_t array_length = GetLightType() == LightType::Spot ? 1 : 2;

// spot light: 1 slice
// directional light: 2 slices for cascades
// point light: 2 slices for front and back paraboloid

m_texture_depth = make_unique<RHI_Texture>(RHI_Texture_Type::Type2DArray, resolution, resolution, array_length, 1, format_depth, flags, "light_depth");
if (IsFlagSet(LightFlags::ShadowsTransparent))
{
m_texture_color = make_unique<RHI_Texture>(RHI_Texture_Type::Type2DArray, resolution, resolution, array_length, 1, format_color, flags, "light_color");
}
}
}
1 change: 0 additions & 1 deletion runtime/World/Components/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ namespace Spartan
// textures
RHI_Texture* GetDepthTexture() const { return m_texture_depth.get(); }
RHI_Texture* GetColorTexture() const { return m_texture_color.get(); }
void RefreshShadowMap();

// frustum
bool IsInViewFrustum(const Math::BoundingBox& bounding_box, const uint32_t index) const;
Expand Down

0 comments on commit 3d83fc6

Please sign in to comment.