From f5a6a1823295d41aaad32d70f9f5ae61318ad760 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 18 Jun 2021 15:20:39 +0200 Subject: [PATCH] Fix stability on exit or when doing heavy resources streaming stress tests --- .../Graphics/Materials/MaterialShader.cpp | 2 +- .../DirectX/DX11/GPUContextDX11.cpp | 17 +++++++++++++++-- Source/Engine/Render2D/Font.cpp | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Graphics/Materials/MaterialShader.cpp b/Source/Engine/Graphics/Materials/MaterialShader.cpp index e897c6258..1c332641d 100644 --- a/Source/Engine/Graphics/Materials/MaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/MaterialShader.cpp @@ -64,7 +64,7 @@ MaterialShader::MaterialShader(const StringView& name) MaterialShader::~MaterialShader() { - ASSERT(!_isLoaded); + ASSERT(!_isLoaded && _shader); SAFE_DELETE_GPU_RESOURCE(_shader); } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp index b283c7a5f..b0cc5cb63 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp @@ -118,7 +118,7 @@ void GPUContextDX11::FrameBegin() _context->VSSetSamplers(0, ARRAY_COUNT(samplers), samplers); _context->DSSetSamplers(0, ARRAY_COUNT(samplers), samplers); _context->PSSetSamplers(0, ARRAY_COUNT(samplers), samplers); - _context->CSSetSamplers(0, ARRAY_COUNT(samplers), samplers); // TODO: maybe we don't want to bind those static sampler always? + _context->CSSetSamplers(0, ARRAY_COUNT(samplers), samplers); } #if GPU_ALLOW_PROFILE_EVENTS @@ -637,7 +637,20 @@ void GPUContextDX11::ClearState() FlushState(); - //_context->ClearState(); + _context->ClearState(); + ID3D11SamplerState* samplers[] = + { + _device->_samplerLinearClamp, + _device->_samplerPointClamp, + _device->_samplerLinearWrap, + _device->_samplerPointWrap, + _device->_samplerShadow, + _device->_samplerShadowPCF + }; + _context->VSSetSamplers(0, ARRAY_COUNT(samplers), samplers); + _context->DSSetSamplers(0, ARRAY_COUNT(samplers), samplers); + _context->PSSetSamplers(0, ARRAY_COUNT(samplers), samplers); + _context->CSSetSamplers(0, ARRAY_COUNT(samplers), samplers); } void GPUContextDX11::FlushState() diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index 537c604d9..26b652de8 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -440,5 +440,5 @@ void Font::FlushFaceSize() const String Font::ToString() const { - return String::Format(TEXT("Font {0} {1}"), _asset->GetFamilyName(), _size); + return String::Format(TEXT("Font {0} {1}"), _asset ? _asset->GetFamilyName() : String::Empty, _size); }