Add clamping for AA and shadows quality to prevent crashes on invalid usage

This commit is contained in:
Wojtek Figat
2021-09-03 19:58:14 +02:00
parent 6e08c1aac9
commit 9c76d0c3cb
3 changed files with 4 additions and 3 deletions

View File

@@ -64,6 +64,7 @@ void FXAA::Dispose()
void FXAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output) void FXAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)
{ {
auto context = GPUDevice::Instance->GetMainContext(); auto context = GPUDevice::Instance->GetMainContext();
const auto qualityLevel = Math::Clamp(static_cast<int32>(Graphics::AAQuality), 0, static_cast<int32>(Quality::MAX));
// Ensure to have valid data // Ensure to have valid data
if (checkIfSkipPass()) if (checkIfSkipPass())
@@ -86,6 +87,6 @@ void FXAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureVie
// Render // Render
context->SetRenderTarget(output); context->SetRenderTarget(output);
context->SetState(_psFXAA.Get(static_cast<int32>(Graphics::AAQuality))); context->SetState(_psFXAA.Get(qualityLevel));
context->DrawFullscreenTriangle(); context->DrawFullscreenTriangle();
} }

View File

@@ -95,7 +95,7 @@ void SMAA::Dispose()
void SMAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output) void SMAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)
{ {
auto context = GPUDevice::Instance->GetMainContext(); auto context = GPUDevice::Instance->GetMainContext();
const auto qualityLevel = static_cast<int32>(Graphics::AAQuality); const auto qualityLevel = Math::Clamp(static_cast<int32>(Graphics::AAQuality), 0, static_cast<int32>(Quality::MAX));
// Ensure to have valid data // Ensure to have valid data
if (checkIfSkipPass()) if (checkIfSkipPass())

View File

@@ -243,7 +243,7 @@ void ShadowsPass::Prepare(RenderContext& renderContext, GPUContext* context)
if (shadowMapsQuality != _currentShadowMapsQuality) if (shadowMapsQuality != _currentShadowMapsQuality)
updateShadowMapSize(); updateShadowMapSize();
auto shadowsQuality = Graphics::ShadowsQuality; auto shadowsQuality = Graphics::ShadowsQuality;
maxShadowsQuality = Math::Min<int32>(static_cast<int32>(shadowsQuality), static_cast<int32>(view.MaxShadowsQuality)); maxShadowsQuality = Math::Clamp(Math::Min<int32>(static_cast<int32>(shadowsQuality), static_cast<int32>(view.MaxShadowsQuality)), 0, static_cast<int32>(Quality::MAX));
// Use the current render view to sync model LODs with the shadow maps rendering stage // Use the current render view to sync model LODs with the shadow maps rendering stage
_shadowContext.LodProxyView = &renderContext.View; _shadowContext.LodProxyView = &renderContext.View;