From cbdd6c49641019d425737a1db6e7dc5d61b12845 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 11 Oct 2023 10:15:44 +0200 Subject: [PATCH] Add `HasDepthClip` to GPU Device limits --- Source/Engine/Graphics/GPULimits.h | 5 +++++ .../DirectX/DX11/GPUDeviceDX11.cpp | 2 ++ .../DirectX/DX12/GPUDeviceDX12.cpp | 1 + .../Engine/GraphicsDevice/Null/GPUDeviceNull.cpp | 16 +--------------- .../GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp | 1 + .../Vulkan/GPUPipelineStateVulkan.cpp | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Source/Engine/Graphics/GPULimits.h b/Source/Engine/Graphics/GPULimits.h index 11da5aca3..0cae4fdfd 100644 --- a/Source/Engine/Graphics/GPULimits.h +++ b/Source/Engine/Graphics/GPULimits.h @@ -259,6 +259,11 @@ API_STRUCT() struct GPULimits /// API_FIELD() bool HasDepthAsSRV; + /// + /// True if device supports depth buffer clipping (see GPUPipelineState::Description::DepthClipEnable). + /// + API_FIELD() bool HasDepthClip; + /// /// True if device supports depth buffer texture as a readonly depth buffer (can be sampled in the shader while performing depth-test). /// diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp index c29c6254d..026422799 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp @@ -359,6 +359,7 @@ bool GPUDeviceDX11::Init() limits.HasAppendConsumeBuffers = true; limits.HasSeparateRenderTargetBlendState = true; limits.HasDepthAsSRV = true; + limits.HasDepthClip = true; limits.HasReadOnlyDepth = true; limits.HasMultisampleDepthAsSRV = true; limits.HasTypedUAVLoad = featureDataD3D11Options2.TypedUAVLoadAdditionalFormats != 0; @@ -382,6 +383,7 @@ bool GPUDeviceDX11::Init() limits.HasAppendConsumeBuffers = false; limits.HasSeparateRenderTargetBlendState = false; limits.HasDepthAsSRV = false; + limits.HasDepthClip = true; limits.HasReadOnlyDepth = createdFeatureLevel == D3D_FEATURE_LEVEL_10_1; limits.HasMultisampleDepthAsSRV = false; limits.HasTypedUAVLoad = false; diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.cpp index e2266f551..d9dc54f97 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.cpp @@ -381,6 +381,7 @@ bool GPUDeviceDX12::Init() limits.HasAppendConsumeBuffers = true; limits.HasSeparateRenderTargetBlendState = true; limits.HasDepthAsSRV = true; + limits.HasDepthClip = true; limits.HasReadOnlyDepth = true; limits.HasMultisampleDepthAsSRV = true; limits.HasTypedUAVLoad = options.TypedUAVLoadAdditionalFormats != 0; diff --git a/Source/Engine/GraphicsDevice/Null/GPUDeviceNull.cpp b/Source/Engine/GraphicsDevice/Null/GPUDeviceNull.cpp index 7869ef312..fa390ccab 100644 --- a/Source/Engine/GraphicsDevice/Null/GPUDeviceNull.cpp +++ b/Source/Engine/GraphicsDevice/Null/GPUDeviceNull.cpp @@ -50,18 +50,7 @@ bool GPUDeviceNull::Init() // Init device limits { auto& limits = Limits; - limits.HasCompute = false; - limits.HasTessellation = false; - limits.HasGeometryShaders = false; - limits.HasInstancing = false; - limits.HasVolumeTextureRendering = false; - limits.HasDrawIndirect = false; - limits.HasAppendConsumeBuffers = false; - limits.HasSeparateRenderTargetBlendState = false; - limits.HasDepthAsSRV = false; - limits.HasReadOnlyDepth = false; - limits.HasMultisampleDepthAsSRV = false; - limits.HasTypedUAVLoad = false; + Platform::MemoryClear(&limits, sizeof(limits)); limits.MaximumMipLevelsCount = 14; limits.MaximumTexture1DSize = 8192; limits.MaximumTexture1DArraySize = 512; @@ -70,11 +59,8 @@ bool GPUDeviceNull::Init() limits.MaximumTexture3DSize = 2048; limits.MaximumTextureCubeSize = 16384; limits.MaximumSamplerAnisotropy = 1; - for (int32 i = 0; i < static_cast(PixelFormat::MAX); i++) - { FeaturesPerFormat[i] = FormatFeatures(static_cast(i), MSAALevel::None, FormatSupport::None); - } } // Create main context diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index b4a6112a9..9c553060f 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -1704,6 +1704,7 @@ bool GPUDeviceVulkan::Init() limits.HasDrawIndirect = PhysicalDeviceLimits.maxDrawIndirectCount >= 1; limits.HasAppendConsumeBuffers = false; // TODO: add Append Consume buffers support for Vulkan limits.HasSeparateRenderTargetBlendState = true; + limits.HasDepthClip = PhysicalDeviceFeatures.depthClamp; limits.HasDepthAsSRV = true; limits.HasReadOnlyDepth = true; limits.HasMultisampleDepthAsSRV = !!PhysicalDeviceFeatures.sampleRateShading; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp index 136a7c6e5..c5c1970e0 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp @@ -340,7 +340,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc) break; } _descRasterization.frontFace = VK_FRONT_FACE_CLOCKWISE; - _descRasterization.depthClampEnable = !desc.DepthClipEnable; + _descRasterization.depthClampEnable = !desc.DepthClipEnable && _device->Limits.HasDepthClip; _descRasterization.lineWidth = 1.0f; _desc.pRasterizationState = &_descRasterization;