"Fixed" crash from ResourceHub on engine exit #446

Merged
Pycorax merged 1 commits from Fix-ResourceHubCrashOnExit into main 2023-03-30 14:24:21 +08:00
2 changed files with 29 additions and 26 deletions
Showing only changes of commit 6cf20d414e - Show all commits

View File

@ -216,13 +216,13 @@ namespace SHADE
} }
// Get render graph from default viewport world renderer // Get render graph from default viewport world renderer
renderGraph = resourceManager.Create<SHRenderGraph>(); renderGraph = resourceManager->Create<SHRenderGraph>();
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* WORLD RENDER GRAPH RESOURCES */ /* WORLD RENDER GRAPH RESOURCES */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
// Initialize world render graph // Initialize world render graph
renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); renderGraph->Init("World Render Graph", device, swapchain, resourceManager, renderContextCmdPools);
renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
renderGraph->AddResource("Position World Space", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Position World Space", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
renderGraph->AddResource("Object VFX", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Object VFX", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat);
@ -292,7 +292,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* SSAO PASS AND DATA INIT */ /* SSAO PASS AND DATA INIT */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
ssaoStorage = resourceManager.Create<SHSSAO>(); ssaoStorage = resourceManager->Create<SHSSAO>();
// command buffer operation to transfer data for ssao // command buffer operation to transfer data for ssao
ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
@ -475,7 +475,7 @@ namespace SHADE
void SHGraphicsSystem::InitSubsystems(void) noexcept void SHGraphicsSystem::InitSubsystems(void) noexcept
{ {
mousePickSubSystem = resourceManager.Create<SHMousePickSystem>(); mousePickSubSystem = resourceManager->Create<SHMousePickSystem>();
std::vector<Handle<SHVkCommandPool>> cmdPools; std::vector<Handle<SHVkCommandPool>> cmdPools;
cmdPools.reserve(swapchain->GetNumImages()); cmdPools.reserve(swapchain->GetNumImages());
@ -486,28 +486,28 @@ namespace SHADE
mousePickSubSystem->Init(device, cmdPools, renderGraph->GetRenderGraphResource("Entity ID")); mousePickSubSystem->Init(device, cmdPools, renderGraph->GetRenderGraphResource("Entity ID"));
// Register the post offscreen render to the system // Register the post offscreen render to the system
postOffscreenRenderSubSystem = resourceManager.Create<SHPostOffscreenRenderSystem>(); postOffscreenRenderSubSystem = resourceManager->Create<SHPostOffscreenRenderSystem>();
postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool); postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool);
lightingSubSystem = resourceManager.Create<SHLightingSubSystem>(); lightingSubSystem = resourceManager->Create<SHLightingSubSystem>();
lightingSubSystem->Init(device, descPool, &resourceManager, samplerCache.GetSampler (device, SHVkSamplerParams lightingSubSystem->Init(device, descPool, resourceManager, samplerCache.GetSampler (device, SHVkSamplerParams
{ {
.addressMode = vk::SamplerAddressMode::eClampToBorder, .addressMode = vk::SamplerAddressMode::eClampToBorder,
}) })
); );
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>(); textRenderingSubSystem = resourceManager->Create<SHTextRenderingSubSystem>();
// initialize the text renderer // initialize the text renderer
auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data()); auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data());
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_TRANSLUCENT_SUBPASS), descPool, textVS, textFS); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_TRANSLUCENT_SUBPASS), descPool, textVS, textFS);
trajectoryRenderingSubSystem = resourceManager.Create<SHTrajectoryRenderingSubSystem>(); trajectoryRenderingSubSystem = resourceManager->Create<SHTrajectoryRenderingSubSystem>();
auto vfxPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data()); auto vfxPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data());
// particle sub system initialization // particle sub system initialization
particleSubSystem = resourceManager.Create<SHParticleSubSystem>(); particleSubSystem = resourceManager->Create<SHParticleSubSystem>();
particleSubSystem->Init(device, descPool, vfxPass->GetRenderpass(), vfxPass->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS), particleVS, particleFS, particleEmitCS, particleUpdateCS); particleSubSystem->Init(device, descPool, vfxPass->GetRenderpass(), vfxPass->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS), particleVS, particleFS, particleEmitCS, particleUpdateCS);
auto vfxNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data()); auto vfxNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data());
@ -608,6 +608,9 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void SHGraphicsSystem::Init(void) void SHGraphicsSystem::Init(void)
{ {
// Create resource manager
resourceManager = new SHResourceHub();
InitBoilerplate(); InitBoilerplate();
InitMiddleEnd(); InitMiddleEnd();
InitSubsystems(); InitSubsystems();
@ -867,7 +870,7 @@ namespace SHADE
} }
// Create the renderer // Create the renderer
auto renderer = resourceManager.Create<SHRenderer>(device, swapchain->GetNumImages(), descPool, projectionType); auto renderer = resourceManager->Create<SHRenderer>(device, swapchain->GetNumImages(), descPool, projectionType);
// Store // Store
renderers.emplace_back(renderer); renderers.emplace_back(renderer);
@ -911,7 +914,7 @@ namespace SHADE
// Create new renderer for the light component and give it to the light component // Create new renderer for the light component and give it to the light component
Handle<SHRenderer> newRenderer = resourceManager.Create<SHRenderer>(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); Handle<SHRenderer> newRenderer = resourceManager->Create<SHRenderer>(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC);
lightComp->SetRenderer(newRenderer); lightComp->SetRenderer(newRenderer);
// Add the shadow map resource to the graph // Add the shadow map resource to the graph
@ -1058,7 +1061,7 @@ namespace SHADE
auto shaderPair = std::make_pair(vertShader, fragShader); auto shaderPair = std::make_pair(vertShader, fragShader);
// Create material // Create material
auto mat = resourceManager.Create<SHMaterial>(); auto mat = resourceManager->Create<SHMaterial>();
auto renderGraphNode = subpass->GetParentNode(); auto renderGraphNode = subpass->GetParentNode();
auto pipeline = renderGraphNode->GetOrCreatePipeline(std::make_pair(vertShader, fragShader), subpass); auto pipeline = renderGraphNode->GetOrCreatePipeline(std::make_pair(vertShader, fragShader), subpass);
@ -1072,12 +1075,12 @@ namespace SHADE
void SHGraphicsSystem::RemoveMaterial(Handle<SHMaterial> material) void SHGraphicsSystem::RemoveMaterial(Handle<SHMaterial> material)
{ {
resourceManager.Free(material); resourceManager->Free(material);
} }
Handle<SHMaterialInstance> SHGraphicsSystem::AddOrGetBaseMaterialInstance(Handle<SHMaterial> material) Handle<SHMaterialInstance> SHGraphicsSystem::AddOrGetBaseMaterialInstance(Handle<SHMaterial> material)
{ {
return materialInstanceCache.CreateOrGet(resourceManager, material); return materialInstanceCache.CreateOrGet(*resourceManager, material);
} }
SHADE::Handle<SHADE::SHMaterialInstance> SHGraphicsSystem::AddOrGetBaseMaterialInstance() SHADE::Handle<SHADE::SHMaterialInstance> SHGraphicsSystem::AddOrGetBaseMaterialInstance()
@ -1087,17 +1090,17 @@ namespace SHADE
SHADE::Handle<SHADE::SHMaterialInstance> SHGraphicsSystem::AddMaterialInstanceCopy(Handle<SHMaterialInstance> materialInst) SHADE::Handle<SHADE::SHMaterialInstance> SHGraphicsSystem::AddMaterialInstanceCopy(Handle<SHMaterialInstance> materialInst)
{ {
return resourceManager.Create<SHMaterialInstance>(materialInst->GetBaseMaterial()); return resourceManager->Create<SHMaterialInstance>(materialInst->GetBaseMaterial());
} }
std::pair<typename SHResourceHub::dense_iterator<SHMaterialInstance>, typename SHResourceHub::dense_iterator<SHMaterialInstance>> SHGraphicsSystem::GetAllMaterialInstances() std::pair<typename SHResourceHub::dense_iterator<SHMaterialInstance>, typename SHResourceHub::dense_iterator<SHMaterialInstance>> SHGraphicsSystem::GetAllMaterialInstances()
{ {
return resourceManager.GetDenseAccess<SHMaterialInstance>(); return resourceManager->GetDenseAccess<SHMaterialInstance>();
} }
void SHGraphicsSystem::RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance) void SHGraphicsSystem::RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance)
{ {
resourceManager.Free(materialInstance); resourceManager->Free(materialInstance);
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -1189,12 +1192,12 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
Handle<SHFont> SHGraphicsSystem::AddFont(SHFontAsset const& fontAsset) noexcept Handle<SHFont> SHGraphicsSystem::AddFont(SHFontAsset const& fontAsset) noexcept
{ {
return fontLibrary.AddFont(device, resourceManager, fontAsset); return fontLibrary.AddFont(device, *resourceManager, fontAsset);
} }
void SHGraphicsSystem::BuildFonts(void) noexcept void SHGraphicsSystem::BuildFonts(void) noexcept
{ {
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::FONT)[0], *resourceManager);
} }
#pragma endregion ADD_REMOVE #pragma endregion ADD_REMOVE
@ -1238,7 +1241,7 @@ namespace SHADE
// Reset all material isDirty // Reset all material isDirty
auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system); auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system);
auto [matBegin, matEnd] = gfxSystem->resourceManager.GetDenseAccess<SHMaterial>(); auto [matBegin, matEnd] = gfxSystem->resourceManager->GetDenseAccess<SHMaterial>();
for (auto iter = matBegin; iter != matEnd; ++iter) for (auto iter = matBegin; iter != matEnd; ++iter)
{ {
iter->ClearChangeFlag(); iter->ClearChangeFlag();
@ -1256,7 +1259,7 @@ namespace SHADE
// Clean up and update all materials // Clean up and update all materials
auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system); auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system);
auto [matInstBegin, matInstEnd] = gfxSystem->resourceManager.GetDenseAccess<SHMaterialInstance>(); auto [matInstBegin, matInstEnd] = gfxSystem->resourceManager->GetDenseAccess<SHMaterialInstance>();
for (auto iter = matInstBegin; iter != matInstEnd; ++iter) for (auto iter = matInstBegin; iter != matInstEnd; ++iter)
{ {
auto baseMat = iter->GetBaseMaterial(); auto baseMat = iter->GetBaseMaterial();
@ -1309,7 +1312,7 @@ namespace SHADE
// Unset all material old pipeline since we would have finished processing // Unset all material old pipeline since we would have finished processing
auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system); auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system);
auto [matBegin, matEnd] = gfxSystem->resourceManager.GetDenseAccess<SHMaterial>(); auto [matBegin, matEnd] = gfxSystem->resourceManager->GetDenseAccess<SHMaterial>();
for (auto iter = matBegin; iter != matEnd; ++iter) for (auto iter = matBegin; iter != matEnd; ++iter)
{ {
iter->ForgetOldPipeline(); iter->ForgetOldPipeline();
@ -1449,7 +1452,7 @@ namespace SHADE
Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass, bool filled, bool triMesh, bool instanced) Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass, bool filled, bool triMesh, bool instanced)
{ {
auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout> auto pipelineLayout = resourceManager->Create<SHVkPipelineLayout>
( (
device, SHPipelineLayoutParams device, SHPipelineLayoutParams
{ {
@ -1457,7 +1460,7 @@ namespace SHADE
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts
} }
); );
auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass); auto pipeline = resourceManager->Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass);
pipeline->GetPipelineState().SetRasterizationState(SHRasterizationState pipeline->GetPipelineState().SetRasterizationState(SHRasterizationState
{ {
.polygonMode = filled ? vk::PolygonMode::eFill : vk::PolygonMode::eLine, .polygonMode = filled ? vk::PolygonMode::eFill : vk::PolygonMode::eLine,

View File

@ -440,7 +440,7 @@ namespace SHADE
SHWindow* window = nullptr; SHWindow* window = nullptr;
// Middle End Resources // Middle End Resources
SHResourceHub resourceManager; SHResourceHub* resourceManager;
SHMeshLibrary meshLibrary; SHMeshLibrary meshLibrary;
SHTextureLibrary texLibrary; SHTextureLibrary texLibrary;
SHGraphicsGenericData graphicsGenericData; SHGraphicsGenericData graphicsGenericData;