Skip to content
Snippets Groups Projects
Commit ab094dcf authored by David Gilbert's avatar David Gilbert :bug:
Browse files

- fixed cuda intersection resource not correctly allocated, leading to a crash when cleaning

- fixed memory leak when textures weren't cleaned up properly due to not being removed from root
parent f102f0e1
Branches
No related tags found
No related merge requests found
...@@ -495,7 +495,6 @@ void FOptiXContextManager::InitContext() ...@@ -495,7 +495,6 @@ void FOptiXContextManager::InitContext()
TopObject = NativeContext->createGroup(); TopObject = NativeContext->createGroup();
TopAcceleration = NativeContext->createAcceleration("Trbvh"); // Here the accel structure seems to be actually needed TopAcceleration = NativeContext->createAcceleration("Trbvh"); // Here the accel structure seems to be actually needed
//TopAcceleration->AddToRoot();
TopAcceleration->setProperty("refit", "1"); TopAcceleration->setProperty("refit", "1");
TopObject->setAcceleration(TopAcceleration); TopObject->setAcceleration(TopAcceleration);
...@@ -746,7 +745,6 @@ void FOptiXContextManager::InitCubemap() ...@@ -746,7 +745,6 @@ void FOptiXContextManager::InitCubemap()
NativeContext["skyboxBuffer"]->setBuffer(CubemapsInputBuffer); NativeContext["skyboxBuffer"]->setBuffer(CubemapsInputBuffer);
CubemapSampler = NativeContext->createTextureSampler(); CubemapSampler = NativeContext->createTextureSampler();
//CubemapSampler->AddToRoot();
CubemapSampler->setWrapMode(0, RT_WRAP_CLAMP_TO_EDGE); CubemapSampler->setWrapMode(0, RT_WRAP_CLAMP_TO_EDGE);
CubemapSampler->setWrapMode(1, RT_WRAP_CLAMP_TO_EDGE); CubemapSampler->setWrapMode(1, RT_WRAP_CLAMP_TO_EDGE);
CubemapSampler->setWrapMode(2, RT_WRAP_CLAMP_TO_EDGE); CubemapSampler->setWrapMode(2, RT_WRAP_CLAMP_TO_EDGE);
...@@ -886,6 +884,14 @@ void FOptiXContextManager::InitCUDADX() ...@@ -886,6 +884,14 @@ void FOptiXContextManager::InitCUDADX()
cudaGraphicsD3D11RegisterResource(&CudaResourceColorRight, D3D11TextureColorRight->GetResource(), cudaGraphicsRegisterFlagsNone); cudaGraphicsD3D11RegisterResource(&CudaResourceColorRight, D3D11TextureColorRight->GetResource(), cudaGraphicsRegisterFlagsNone);
PrintLastCudaError("cudaGraphicsD3D11RegisterResource"); PrintLastCudaError("cudaGraphicsD3D11RegisterResource");
} }
// Intersection
{
FD3D11TextureBase* D3D11TextureIntersections = GetD3D11TextureFromRHITexture(LaserIntersectionTexture->Resource->TextureRHI);
cudaGraphicsD3D11RegisterResource(&CudaResourceIntersections, D3D11TextureIntersections->GetResource(), cudaGraphicsRegisterFlagsNone);
PrintLastCudaError("cudaGraphicsD3D11RegisterResource");
}
// Ortho // Ortho
{ {
FD3D11TextureBase* D3D11TextureOrthoDepth = GetD3D11TextureFromRHITexture(DepthTextureOrtho->Resource->TextureRHI); FD3D11TextureBase* D3D11TextureOrthoDepth = GetD3D11TextureFromRHITexture(DepthTextureOrtho->Resource->TextureRHI);
...@@ -1324,20 +1330,32 @@ void FOptiXContextManager::CleanupCuda() ...@@ -1324,20 +1330,32 @@ void FOptiXContextManager::CleanupCuda()
if (CudaResourceDepthLeft != NULL) if (CudaResourceDepthLeft != NULL)
cudaGraphicsUnregisterResource(CudaResourceDepthLeft); cudaGraphicsUnregisterResource(CudaResourceDepthLeft);
PrintLastCudaError("cudaGraphicsUnregisterResource");
if (CudaResourceDepthRight != NULL) if (CudaResourceDepthRight != NULL)
cudaGraphicsUnregisterResource(CudaResourceDepthRight); cudaGraphicsUnregisterResource(CudaResourceDepthRight);
PrintLastCudaError("cudaGraphicsUnregisterResource");
if (CudaResourceColorLeft != NULL) if (CudaResourceColorLeft != NULL)
cudaGraphicsUnregisterResource(CudaResourceColorLeft); cudaGraphicsUnregisterResource(CudaResourceColorLeft);
PrintLastCudaError("cudaGraphicsUnregisterResource");
if (CudaResourceColorRight != NULL) if (CudaResourceColorRight != NULL)
cudaGraphicsUnregisterResource(CudaResourceColorRight); cudaGraphicsUnregisterResource(CudaResourceColorRight);
if (CudaResourceIntersections != NULL) PrintLastCudaError("cudaGraphicsUnregisterResource");
cudaGraphicsUnregisterResource(CudaResourceIntersections);
if (CudaResourceDepthOrtho != NULL) if (CudaResourceDepthOrtho != NULL)
cudaGraphicsUnregisterResource(CudaResourceDepthOrtho); cudaGraphicsUnregisterResource(CudaResourceDepthOrtho);
PrintLastCudaError("cudaGraphicsUnregisterResource");
if (CudaResourceColorOrtho != NULL) if (CudaResourceColorOrtho != NULL)
cudaGraphicsUnregisterResource(CudaResourceColorOrtho); cudaGraphicsUnregisterResource(CudaResourceColorOrtho);
PrintLastCudaError("cudaGraphicsUnregisterResource"); PrintLastCudaError("cudaGraphicsUnregisterResource");
if (CudaResourceIntersections != NULL)
cudaGraphicsUnregisterResource(CudaResourceIntersections);
PrintLastCudaError("cudaGraphicsUnregisterResource");
if (CudaLinearMemoryDepth != NULL) if (CudaLinearMemoryDepth != NULL)
cudaFree(CudaLinearMemoryDepth); cudaFree(CudaLinearMemoryDepth);
if (CudaLinearMemoryColor != NULL) if (CudaLinearMemoryColor != NULL)
...@@ -1436,6 +1454,9 @@ void FOptiXContextManager::Cleanup_RenderThread() ...@@ -1436,6 +1454,9 @@ void FOptiXContextManager::Cleanup_RenderThread()
{ {
bIsInitializedAll.AtomicSet(false); bIsInitializedAll.AtomicSet(false);
CleanupCuda();
for (auto& Pair : OptiXBuffers) for (auto& Pair : OptiXBuffers)
{ {
for (TPair<FString, optix::Buffer>& BufferPair : Pair.Value) for (TPair<FString, optix::Buffer>& BufferPair : Pair.Value)
...@@ -1512,20 +1533,48 @@ void FOptiXContextManager::Cleanup_RenderThread() ...@@ -1512,20 +1533,48 @@ void FOptiXContextManager::Cleanup_RenderThread()
void FOptiXContextManager::Cleanup_GameThread() void FOptiXContextManager::Cleanup_GameThread()
{ {
CleanupCuda();
// Laser stuff // Laser stuff
IntersectionData.Empty(); IntersectionData.Empty();
OldIntersectionData.Empty(); OldIntersectionData.Empty();
LaserIntersectionQueue.Empty(); LaserIntersectionQueue.Empty();
PreviousLaserResults.Empty(); PreviousLaserResults.Empty();
LaserIntersectionTexture->RemoveFromRoot();
LaserMaterialDynamic->RemoveFromRoot();
LaserMaterial->RemoveFromRoot();
LaserIntersectionTexture->ConditionalBeginDestroy();
//LaserMaterialDynamic->ConditionalBeginDestroy();
//LaserMaterial->ConditionalBeginDestroy();
LaserIntersectionTexture.Reset(); LaserIntersectionTexture.Reset();
LaserMaterialDynamic.Reset(); LaserMaterialDynamic.Reset();
LaserMaterial.Reset(); LaserMaterial.Reset();
// Rendering // Rendering
OutputTexture->RemoveFromRoot();
DepthTexture->RemoveFromRoot();
OutputTexture2->RemoveFromRoot();
DepthTexture2->RemoveFromRoot();
OutputTextureOrtho->RemoveFromRoot();
DepthTextureOrtho->RemoveFromRoot();
DynamicMaterial->RemoveFromRoot();
DynamicMaterialOrtho->RemoveFromRoot();
RegularMaterial->RemoveFromRoot();
VRMaterial->RemoveFromRoot();
OutputTexture->ConditionalBeginDestroy();
DepthTexture->ConditionalBeginDestroy();
OutputTexture2->ConditionalBeginDestroy();
DepthTexture2->ConditionalBeginDestroy();
OutputTextureOrtho->ConditionalBeginDestroy();
DepthTextureOrtho->ConditionalBeginDestroy();
//DynamicMaterial->ConditionalBeginDestroy();
//DynamicMaterialOrtho->ConditionalBeginDestroy();
//RegularMaterial->ConditionalBeginDestroy();
//VRMaterial->ConditionalBeginDestroy();
OutputTexture.Reset(); OutputTexture.Reset();
DepthTexture.Reset(); DepthTexture.Reset();
OutputTexture2.Reset(); OutputTexture2.Reset();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment