From 7531b1fdbd4fae021a1a038f847390895d41ef87 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 26 Mar 2026 19:12:58 +0100 Subject: [PATCH] Fix rendering crash when D24_8Stencil format is not supported (lol) --- Source/Editor/Gizmo/EditorPrimitives.cs | 2 +- Source/Engine/Graphics/RenderBuffers.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Gizmo/EditorPrimitives.cs b/Source/Editor/Gizmo/EditorPrimitives.cs index d5fb70906..110107329 100644 --- a/Source/Editor/Gizmo/EditorPrimitives.cs +++ b/Source/Editor/Gizmo/EditorPrimitives.cs @@ -57,7 +57,7 @@ namespace FlaxEditor.Gizmo var height = output.Height; var desc = GPUTextureDescription.New2D(width, height, format, GPUTextureFlags.RenderTarget | GPUTextureFlags.ShaderResource, 1, 1, msaaLevel); var target = RenderTargetPool.Get(ref desc); - desc = GPUTextureDescription.New2D(width, height, PixelFormat.D24_UNorm_S8_UInt, GPUTextureFlags.DepthStencil, 1, 1, msaaLevel); + desc = GPUTextureDescription.New2D(width, height, renderContext.Buffers.DepthBuffer.Format, GPUTextureFlags.DepthStencil, 1, 1, msaaLevel); var targetDepth = RenderTargetPool.Get(ref desc); // Copy frame and clear depth diff --git a/Source/Engine/Graphics/RenderBuffers.cpp b/Source/Engine/Graphics/RenderBuffers.cpp index b660b5564..ba00788c4 100644 --- a/Source/Engine/Graphics/RenderBuffers.cpp +++ b/Source/Engine/Graphics/RenderBuffers.cpp @@ -88,7 +88,7 @@ GPUTexture* RenderBuffers::RequestHalfResDepth(GPUContext* context) if (!MultiScaler::Instance()->IsReady()) return DepthBuffer; - auto format = GPU_DEPTH_BUFFER_PIXEL_FORMAT; + auto format = DepthBuffer->Format(); auto width = RenderTools::GetResolution(_width, ResolutionMode::Half); auto height = RenderTools::GetResolution(_height, ResolutionMode::Half); auto tempDesc = GPUTextureDescription::New2D(width, height, format, DepthBuffer->Flags()); @@ -222,7 +222,9 @@ bool RenderBuffers::Init(int32 width, int32 height) bool result = false; // Depth Buffer - GPUTextureDescription desc = GPUTextureDescription::New2D(width, height, GPU_DEPTH_BUFFER_PIXEL_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::DepthStencil); + auto desc = GPUTextureDescription::New2D(width, height, GPU_DEPTH_BUFFER_PIXEL_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::DepthStencil); + if (!EnumHasAllFlags(GPUDevice::Instance->GetFormatFeatures(desc.Format).Support, FormatSupport::DepthStencil | FormatSupport::Texture2D)) + desc.Format = desc.Format == PixelFormat::D24_UNorm_S8_UInt ? PixelFormat::D32_Float_S8X24_UInt : PixelFormat::D32_Float; if (GPUDevice::Instance->Limits.HasReadOnlyDepth) desc.Flags |= GPUTextureFlags::ReadOnlyDepthView;