void FD3D11DynamicRHI::CleanupD3DDevice() { if(GIsRHIInitialized) { check(Direct3DDevice); check(Direct3DDeviceIMContext); // Reset the RHI initialized flag. GIsRHIInitialized = false; check(!GIsCriticalError); // Ask all initialized FRenderResources to release their RHI resources. for(TLinkedList<FRenderResource*>::TIterator ResourceIt(FRenderResource::GetResourceList());ResourceIt;ResourceIt.Next()) { FRenderResource* Resource = *ResourceIt; check(Resource->IsInitialized()); Resource->ReleaseRHI(); } for(TLinkedList<FRenderResource*>::TIterator ResourceIt(FRenderResource::GetResourceList());ResourceIt;ResourceIt.Next()) { ResourceIt->ReleaseDynamicRHI(); } extern void EmptyD3DSamplerStateCache(); EmptyD3DSamplerStateCache(); // release our dynamic VB and IB buffers DynamicVB = NULL; DynamicIB = NULL; ReleasePooledUniformBuffers(); ReleasePooledTextures(); // Release the device and its IC StateCache.SetContext(nullptr); Direct3DDeviceIMContext = NULL; Direct3DDevice = NULL; } }
void FD3D11DynamicRHI::CleanupD3DDevice() { if(GIsRHIInitialized) { check(Direct3DDevice); check(Direct3DDeviceIMContext); // Reset the RHI initialized flag. GIsRHIInitialized = false; check(!GIsCriticalError); // Ask all initialized FRenderResources to release their RHI resources. for(TLinkedList<FRenderResource*>::TIterator ResourceIt(FRenderResource::GetResourceList());ResourceIt;ResourceIt.Next()) { FRenderResource* Resource = *ResourceIt; check(Resource->IsInitialized()); Resource->ReleaseRHI(); } for(TLinkedList<FRenderResource*>::TIterator ResourceIt(FRenderResource::GetResourceList());ResourceIt;ResourceIt.Next()) { ResourceIt->ReleaseDynamicRHI(); } extern void EmptyD3DSamplerStateCache(); EmptyD3DSamplerStateCache(); // release our dynamic VB and IB buffers DynamicVB = NULL; DynamicIB = NULL; // Release references to bound uniform buffers. for (int32 Frequency = 0; Frequency < SF_NumFrequencies; ++Frequency) { for (int32 BindIndex = 0; BindIndex < MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE; ++BindIndex) { BoundUniformBuffers[Frequency][BindIndex].SafeRelease(); } } // Release the device and its IC StateCache.SetContext(nullptr); // Flush all pending deletes before destroying the device. FRHIResource::FlushPendingDeletes(); ReleasePooledUniformBuffers(); ReleasePooledTextures(); // When running with D3D debug, clear state and flush the device to get rid of spurious live objects in D3D11's report. if (D3D11RHI_ShouldCreateWithD3DDebug()) { Direct3DDeviceIMContext->ClearState(); Direct3DDeviceIMContext->Flush(); } Direct3DDeviceIMContext = NULL; Direct3DDevice = NULL; } }