Skip to content

Commit

Permalink
WebGPU: Enabled depth clip in the pipeline state (close #585)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets authored and TheMostDiligent committed Jul 29, 2024
1 parent 0ba829c commit e77589e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Graphics/GraphicsEngineWebGPU/src/EngineFactoryWebGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ GraphicsAdapterInfo GetGraphicsAdapterInfo(WGPUAdapter wgpuAdapter, WGPUDevice w
Features.MultiViewport = DEVICE_FEATURE_STATE_ENABLED;
Features.PixelUAVWritesAndAtomics = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureUAVExtendedFormats = DEVICE_FEATURE_STATE_ENABLED;
Features.DepthClamp = DEVICE_FEATURE_STATE_ENABLED;
Features.AsyncShaderCompilation = DEVICE_FEATURE_STATE_ENABLED;

Features.WireframeFill = DEVICE_FEATURE_STATE_DISABLED;
Expand All @@ -302,7 +301,7 @@ GraphicsAdapterInfo GetGraphicsAdapterInfo(WGPUAdapter wgpuAdapter, WGPUDevice w
Features.ShaderResourceRuntimeArrays = DEVICE_FEATURE_STATE_DISABLED;

if (CheckWebGPUFeature(WGPUFeatureName_DepthClipControl))
Features.DepthBiasClamp = DEVICE_FEATURE_STATE_ENABLED;
Features.DepthClamp = DEVICE_FEATURE_STATE_ENABLED;

if (CheckWebGPUFeature(WGPUFeatureName_TimestampQuery))
Features.TimestampQueries = DEVICE_FEATURE_STATE_ENABLED;
Expand Down
15 changes: 13 additions & 2 deletions Graphics/GraphicsEngineWebGPU/src/PipelineStateWebGPUImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ void PipelineStateWebGPUImpl::InitializeWebGPURenderPipeline(const TShaderStages
using WebGPUVertexAttributeArray = std::array<std::vector<WGPUVertexAttribute>, MAX_LAYOUT_ELEMENTS>;
using WebGPUVertexBufferLayouts = std::array<WGPUVertexBufferLayout, MAX_LAYOUT_ELEMENTS>;

WebGPUVertexAttributeArray wgpuVertexAttributes{};
WebGPUVertexBufferLayouts wgpuVertexBufferLayouts{};
WebGPUVertexAttributeArray wgpuVertexAttributes{};
WebGPUVertexBufferLayouts wgpuVertexBufferLayouts{};
WGPUPrimitiveDepthClipControl wgpuDepthClipControl{};

std::vector<WGPUColorTargetState> wgpuColorTargetStates{};
std::vector<WGPUBlendState> wgpuBlendStates{};
Expand Down Expand Up @@ -504,6 +505,16 @@ void PipelineStateWebGPUImpl::InitializeWebGPURenderPipeline(const TShaderStages
GraphicsPipeline.PrimitiveTopology == PRIMITIVE_TOPOLOGY_LINE_STRIP) ?
WGPUIndexFormat_Uint32 :
WGPUIndexFormat_Undefined;

if (!GraphicsPipeline.RasterizerDesc.DepthClipEnable)
{
wgpuDepthClipControl.chain.sType = WGPUSType_PrimitiveDepthClipControl;
wgpuDepthClipControl.unclippedDepth = !GraphicsPipeline.RasterizerDesc.DepthClipEnable;
if (m_pDevice->GetDeviceInfo().Features.DepthClamp)
wgpuPrimitiveState.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgpuDepthClipControl);
else
LOG_WARNING_MESSAGE("Depth clamping is not supported by the device. The depth clip control will be ignored.");
}
}

{
Expand Down

0 comments on commit e77589e

Please sign in to comment.