Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Feature cleanup memory leaks #390

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/d3d12/d3d12_render_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,9 @@ namespace wr::d3d12

void Resize(RenderTarget** render_target, Device* device, unsigned int width, unsigned int height)
{
(*render_target)->m_width = width;
(*render_target)->m_height = height;

if ((*render_target)->m_create_info.m_dsv_format == Format::D32_FLOAT && (*render_target)->m_create_info.m_create_dsv_buffer)
{
DestroyDepthStencilBuffer((*render_target));
}
DestroyRenderTargetViews((*render_target));

(*render_target) = CreateRenderTarget(device, width, height, (*render_target)->m_create_info);
auto create_info = (*render_target)->m_create_info;
Destroy(*render_target);
(*render_target) = CreateRenderTarget(device, width, height, create_info);
}

void IncrementFrameIdx(RenderTarget* render_target)
Expand Down
10 changes: 7 additions & 3 deletions src/frame_graph/frame_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ namespace wr
}

// Make sure we free the data objects we allocated.
for (auto& data : m_data)
for (void *data : m_data)
{
delete data;
free(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer delete over free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to std::shared_ptrlike suggested

}

for (auto& cmd_list : m_cmd_lists)
Expand Down Expand Up @@ -643,7 +643,11 @@ namespace wr
m_settings.resize(m_num_tasks + 1ull);
m_types.emplace_back(desc.m_type);
m_rt_properties.emplace_back(desc.m_properties);
m_data.emplace_back(new (std::nothrow) T());

void *data = malloc(sizeof(T));
m_data.emplace_back(data);
::new (data) T(); //TODO: This destructor can't be called, because of how it is stored in m_data

m_data_type_info.emplace_back(typeid(T));

// If we are allowed to do multithreading place the task in the appropriate vector
Expand Down
11 changes: 6 additions & 5 deletions src/render_tasks/d3d12_accumulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ namespace wr
1);
}

inline void DestroyAccumulation(FrameGraph& fg, RenderTaskHandle handle, bool)
inline void DestroyAccumulation(FrameGraph& fg, RenderTaskHandle handle, bool resize)
{
auto& data = fg.GetData<AccumulationData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the texture pool to free them
DescriptorAllocation temp = std::move(data.out_allocation);
if(!resize)
{
auto& data = fg.GetData<AccumulationData>(handle);
data.~AccumulationData();
}
}

} /* internal */
Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_bloom_composition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<BloomCompostionData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~BloomCompostionData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_bloom_extract_bright.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<BloomExtractBrightData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~BloomExtractBrightData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_bloom_horizontal_blur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<BloomBlurHorizontalData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~BloomBlurHorizontalData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_bloom_vertical_blur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<BloomBlurVerticalData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~BloomBlurVerticalData();
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/render_tasks/d3d12_build_acceleration_structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,7 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<ASBuildData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_scene_ib_alloc);
DescriptorAllocation temp2 = std::move(data.out_scene_mat_alloc);
DescriptorAllocation temp3 = std::move(data.out_scene_offset_alloc);
data.~ASBuildData();
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/render_tasks/d3d12_cubemap_convolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ namespace wr
desc.m_execute_func = [](RenderSystem& rs, FrameGraph& fg, SceneGraph& sg, RenderTaskHandle handle) {
internal::ExecuteCubemapConvolutionTask(rs, fg, sg, handle);
};
desc.m_destroy_func = [](FrameGraph&, RenderTaskHandle, bool) {
desc.m_destroy_func = [](FrameGraph& fg, RenderTaskHandle handle, bool resize) {
if(!resize)
{
fg.GetData<CubemapConvolutionTaskData>(handle).~CubemapConvolutionTaskData();
}
};

desc.m_properties = rt_properties;
Expand Down
13 changes: 1 addition & 12 deletions src/render_tasks/d3d12_deferred_composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,7 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DeferredCompositionTaskData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the texture pool to free them
std::move(data.out_gbuffer_albedo_alloc);
std::move(data.out_gbuffer_normal_alloc);
std::move(data.out_gbuffer_emissive_alloc);
std::move(data.out_gbuffer_depth_alloc);
std::move(data.out_lights_alloc);
std::move(data.out_buffer_refl_alloc);
std::move(data.out_buffer_shadow_alloc);
std::move(data.out_screen_space_irradiance_alloc);
std::move(data.out_screen_space_ao_alloc);
std::move(data.out_output_alloc);
data.~DeferredCompositionTaskData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_bokeh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFBokehData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
data.camera_cb_pool->Destroy(data.cb_handle);
delete data.out_allocator;
data.~DoFBokehData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_bokeh_postfilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFBokehPostFilterData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~DoFBokehPostFilterData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_coc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFCoCData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
data.camera_cb_pool->Destroy(data.cb_handle);
delete data.out_allocator;
data.~DoFCoCData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_composition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFCompositionData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~DoFCompositionData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_dilate_flatten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFDilateFlattenData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~DoFDilateFlattenData();
}
}
} /* internal */
Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_dilate_flatten_second_pass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFDilateFlattenHData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~DoFDilateFlattenHData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_dof_dilate_near.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DoFDilateData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~DoFDilateData();
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_down_scale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<DownScaleData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_allocation);
delete data.out_allocator;
data.~DownScaleData();
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/render_tasks/d3d12_equirect_to_cubemap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ namespace wr
desc.m_execute_func = [](RenderSystem& rs, FrameGraph& fg, SceneGraph& sg, RenderTaskHandle handle) {
internal::ExecuteEquirectToCubemapTask(rs, fg, sg, handle);
};
desc.m_destroy_func = [](FrameGraph&, RenderTaskHandle, bool) {
desc.m_destroy_func = [](FrameGraph& fg, RenderTaskHandle handle, bool resize) {
if(!resize)
{
fg.GetData<EquirectToCubemapTaskData>(handle).~EquirectToCubemapTaskData();
}
};

desc.m_properties = rt_properties;
Expand Down
11 changes: 6 additions & 5 deletions src/render_tasks/d3d12_hbao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ namespace wr
GFSDK_SSAO_InputData_D3D12 ssao_input_data;
#endif

d3d12::DescHeapCPUHandle cpu_depth_handle = d3d12::DescHeapCPUHandle();
d3d12::DescHeapGPUHandle gpu_depth_handle = d3d12::DescHeapGPUHandle();
d3d12::DescHeapCPUHandle cpu_normal_handle = d3d12::DescHeapCPUHandle();
d3d12::DescHeapGPUHandle gpu_normal_handle = d3d12::DescHeapGPUHandle();
d3d12::DescHeapCPUHandle cpu_target_handle = d3d12::DescHeapCPUHandle();
d3d12::DescHeapCPUHandle cpu_depth_handle{};
d3d12::DescHeapGPUHandle gpu_depth_handle{};
d3d12::DescHeapCPUHandle cpu_normal_handle{};
d3d12::DescHeapGPUHandle gpu_normal_handle{};
d3d12::DescHeapCPUHandle cpu_target_handle{};
};

namespace internal
Expand Down Expand Up @@ -189,6 +189,7 @@ namespace wr
d3d12::Destroy(data.out_descriptor_heap_rtv);

delete data.ssao_context;
data.~HBAOData();
#endif
}

Expand Down
7 changes: 1 addition & 6 deletions src/render_tasks/d3d12_path_tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,7 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<PathTracerData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
std::move(data.out_output_alloc);
std::move(data.out_gbuffer_albedo_alloc);
std::move(data.out_gbuffer_normal_alloc);
std::move(data.out_gbuffer_depth_alloc);
data.~PathTracerData();
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/render_tasks/d3d12_post_processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ namespace wr
1);
}

inline void DestroyPostProcessing(FrameGraph& fg, RenderTaskHandle handle, bool)
inline void DestroyPostProcessing(FrameGraph& fg, RenderTaskHandle handle, bool resize)
{
auto& data = fg.GetData<PostProcessingData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the texture pool to free them
DescriptorAllocation temp = std::move(data.out_allocation);
if (!resize)
{
auto &data = fg.GetData<PostProcessingData>(handle);
data.~PostProcessingData();
}
}

} /* internal */
Expand Down
4 changes: 1 addition & 3 deletions src/render_tasks/d3d12_raytracing_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ namespace wr
if (!resize)
{
auto& data = fg.GetData<RaytracingData>(handle);

// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_uav_from_rtv);
data.~RaytracingData();
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/render_tasks/d3d12_rt_reflection_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,10 @@ namespace wr

inline void DestroyRTReflectionTask(FrameGraph& fg, RenderTaskHandle handle, bool resize)
{
auto& data = fg.GetData<RTReflectionData>(handle);

if (!resize)
{
// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
std::move(data.base_data.out_output_alloc);
std::move(data.base_data.out_gbuffer_albedo_alloc);
std::move(data.base_data.out_gbuffer_normal_alloc);
std::move(data.base_data.out_gbuffer_depth_alloc);
auto& data = fg.GetData<RTReflectionData>(handle);
data.~RTReflectionData();
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/render_tasks/d3d12_rt_shadow_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,10 @@ namespace wr

inline void DestroyRTShadowTask(FrameGraph& fg, RenderTaskHandle handle, bool resize)
{
auto& data = fg.GetData<RTShadowData>(handle);

if (!resize)
{
// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
std::move(data.base_data.out_output_alloc);
std::move(data.base_data.out_gbuffer_albedo_alloc);
std::move(data.base_data.out_gbuffer_normal_alloc);
std::move(data.base_data.out_gbuffer_depth_alloc);
auto& data = fg.GetData<RTShadowData>(handle);
data.~RTShadowData();
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/render_tasks/d3d12_rtao_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace wr
DescriptorAllocation in_depthbuffer;

bool tlas_requires_init = false;

};

namespace internal
Expand Down Expand Up @@ -243,14 +244,10 @@ namespace wr

inline void DestroyAOTask(FrameGraph& fg, RenderTaskHandle handle, bool resize)
{
auto& data = fg.GetData<RTAOData>(handle);

if (!resize)
{
// Small hack to force the allocations to go out of scope, which will tell the allocator to free them
DescriptorAllocation temp1 = std::move(data.out_uav_from_rtv);
DescriptorAllocation temp2 = std::move(data.in_gbuffers);
DescriptorAllocation temp3 = std::move(data.in_depthbuffer);
auto& data = fg.GetData<RTAOData>(handle);
data.~RTAOData();
}
}
}
Expand Down
Loading