Add depth function to conditional compiling

This commit is contained in:
ExMatics HydrogenC
2024-06-05 23:36:41 +08:00
parent 74750fd604
commit ea749f12a3
13 changed files with 56 additions and 9 deletions
+17 -2
View File
@@ -182,11 +182,26 @@ public:
API_FUNCTION() virtual void Clear(GPUTextureView* rt, const Color& color) = 0; API_FUNCTION() virtual void Clear(GPUTextureView* rt, const Color& color) = 0;
/// <summary> /// <summary>
/// Clears depth buffer. /// Clears depth buffer with custom value.
/// </summary> /// </summary>
/// <param name="depthBuffer">The depth buffer to clear.</param> /// <param name="depthBuffer">The depth buffer to clear.</param>
/// <param name="depthValue">The clear depth value.</param> /// <param name="depthValue">The clear depth value.</param>
API_FUNCTION() virtual void ClearDepth(GPUTextureView* depthBuffer, float depthValue = 0.0f) = 0; API_FUNCTION() virtual void ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue) = 0;
/// <summary>
/// Clears depth buffer with default value.
/// </summary>
/// <param name="depthBuffer">The depth buffer to clear.</param>
/// <param name="depthValue">The clear depth value.</param>
API_FUNCTION() FORCE_INLINE void ClearDepth(GPUTextureView* depthBuffer) {
#if FLAX_REVERSE_Z
ClearDepthCustom(depthBuffer, 0.0f);
#else
ClearDepthCustom(depthBuffer, 0.0f);
#endif
}
/// <summary> /// <summary>
/// Clears an unordered access buffer with a float value. /// Clears an unordered access buffer with a float value.
+12
View File
@@ -130,7 +130,11 @@ GPUPipelineState::Description GPUPipelineState::Description::Default =
true, // DepthEnable true, // DepthEnable
true, // DepthWriteEnable true, // DepthWriteEnable
true, // DepthClipEnable true, // DepthClipEnable
#if FLAX_REVERSE_Z
ComparisonFunc::Greater, // DepthFunc ComparisonFunc::Greater, // DepthFunc
#else
ComparisonFunc::Less, // DepthFunc
#endif
false, // StencilEnable false, // StencilEnable
0xff, // StencilReadMask 0xff, // StencilReadMask
0xff, // StencilWriteMask 0xff, // StencilWriteMask
@@ -154,7 +158,11 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultNoDepth =
false, // DepthEnable false, // DepthEnable
false, // DepthWriteEnable false, // DepthWriteEnable
false, // DepthClipEnable false, // DepthClipEnable
#if FLAX_REVERSE_Z
ComparisonFunc::Greater, // DepthFunc ComparisonFunc::Greater, // DepthFunc
#else
ComparisonFunc::Less, // DepthFunc
#endif
false, // StencilEnable false, // StencilEnable
0xff, // StencilReadMask 0xff, // StencilReadMask
0xff, // StencilWriteMask 0xff, // StencilWriteMask
@@ -178,7 +186,11 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultFullscreenTr
false, // DepthEnable false, // DepthEnable
false, // DepthWriteEnable false, // DepthWriteEnable
false, // DepthClipEnable false, // DepthClipEnable
#if FLAX_REVERSE_Z
ComparisonFunc::Greater, // DepthFunc ComparisonFunc::Greater, // DepthFunc
#else
ComparisonFunc::Less, // DepthFunc
#endif
false, // StencilEnable false, // StencilEnable
0xff, // StencilReadMask 0xff, // StencilReadMask
0xff, // StencilWriteMask 0xff, // StencilWriteMask
@@ -196,7 +196,11 @@ bool DeferredMaterialShader::Load()
// Motion Vectors pass // Motion Vectors pass
psDesc.DepthWriteEnable = false; psDesc.DepthWriteEnable = false;
psDesc.DepthEnable = true; psDesc.DepthEnable = true;
#if FLAX_REVERSE_Z
psDesc.DepthFunc = ComparisonFunc::GreaterEqual; psDesc.DepthFunc = ComparisonFunc::GreaterEqual;
#else
psDesc.DepthFunc = ComparisonFunc::LessEqual;
#endif
psDesc.VS = _shader->GetVS("VS"); psDesc.VS = _shader->GetVS("VS");
psDesc.PS = _shader->GetPS("PS_MotionVectors"); psDesc.PS = _shader->GetPS("PS_MotionVectors");
_cache.MotionVectors.Init(psDesc); _cache.MotionVectors.Init(psDesc);
@@ -214,7 +218,11 @@ bool DeferredMaterialShader::Load()
psDesc.DepthClipEnable = false; psDesc.DepthClipEnable = false;
psDesc.DepthWriteEnable = true; psDesc.DepthWriteEnable = true;
psDesc.DepthEnable = true; psDesc.DepthEnable = true;
#if FLAX_REVERSE_Z
psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.DepthFunc = ComparisonFunc::Greater;
#else
psDesc.DepthFunc = ComparisonFunc::Less;
#endif
psDesc.HS = nullptr; psDesc.HS = nullptr;
psDesc.DS = nullptr; psDesc.DS = nullptr;
GPUShaderProgramVS* instancedDepthPassVS; GPUShaderProgramVS* instancedDepthPassVS;
@@ -173,7 +173,11 @@ bool DeformableMaterialShader::Load()
psDesc.DepthClipEnable = false; psDesc.DepthClipEnable = false;
psDesc.DepthWriteEnable = true; psDesc.DepthWriteEnable = true;
psDesc.DepthEnable = true; psDesc.DepthEnable = true;
#if FLAX_REVERSE_Z
psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.DepthFunc = ComparisonFunc::Greater;
#else
psDesc.DepthFunc = ComparisonFunc::Less;
#endif
psDesc.HS = nullptr; psDesc.HS = nullptr;
psDesc.DS = nullptr; psDesc.DS = nullptr;
_cache.Depth.Init(psDesc); _cache.Depth.Init(psDesc);
@@ -205,7 +205,11 @@ bool ForwardMaterialShader::Load()
psDesc.DepthClipEnable = false; psDesc.DepthClipEnable = false;
psDesc.DepthWriteEnable = true; psDesc.DepthWriteEnable = true;
psDesc.DepthEnable = true; psDesc.DepthEnable = true;
#if FLAX_REVERSE_Z
psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.DepthFunc = ComparisonFunc::Greater;
#else
psDesc.DepthFunc = ComparisonFunc::Less;
#endif
psDesc.HS = nullptr; psDesc.HS = nullptr;
psDesc.DS = nullptr; psDesc.DS = nullptr;
psDesc.VS = _shader->GetVS("VS"); psDesc.VS = _shader->GetVS("VS");
@@ -185,7 +185,11 @@ bool TerrainMaterialShader::Load()
psDesc.DepthClipEnable = false; psDesc.DepthClipEnable = false;
psDesc.DepthWriteEnable = true; psDesc.DepthWriteEnable = true;
psDesc.DepthEnable = true; psDesc.DepthEnable = true;
#if FLAX_REVERSE_Z
psDesc.DepthFunc = ComparisonFunc::Greater; psDesc.DepthFunc = ComparisonFunc::Greater;
#else
psDesc.DepthFunc = ComparisonFunc::Less;
#endif
psDesc.HS = nullptr; psDesc.HS = nullptr;
psDesc.DS = nullptr; psDesc.DS = nullptr;
// TODO: masked terrain materials (depth pass should clip holes) // TODO: masked terrain materials (depth pass should clip holes)
@@ -166,7 +166,7 @@ void GPUContextDX11::Clear(GPUTextureView* rt, const Color& color)
} }
} }
void GPUContextDX11::ClearDepth(GPUTextureView* depthBuffer, float depthValue) void GPUContextDX11::ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue)
{ {
auto depthBufferDX11 = static_cast<GPUTextureViewDX11*>(depthBuffer); auto depthBufferDX11 = static_cast<GPUTextureViewDX11*>(depthBuffer);
@@ -113,7 +113,7 @@ public:
void* GetNativePtr() const override; void* GetNativePtr() const override;
bool IsDepthBufferBinded() override; bool IsDepthBufferBinded() override;
void Clear(GPUTextureView* rt, const Color& color) override; void Clear(GPUTextureView* rt, const Color& color) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override; void ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue) override;
void ClearUA(GPUBuffer* buf, const Float4& value) override; void ClearUA(GPUBuffer* buf, const Float4& value) override;
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override; void ClearUA(GPUBuffer* buf, const uint32 value[4]) override;
void ClearUA(GPUTexture* texture, const uint32 value[4]) override; void ClearUA(GPUTexture* texture, const uint32 value[4]) override;
@@ -713,7 +713,7 @@ void GPUContextDX12::Clear(GPUTextureView* rt, const Color& color)
} }
} }
void GPUContextDX12::ClearDepth(GPUTextureView* depthBuffer, float depthValue) void GPUContextDX12::ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue)
{ {
auto depthBufferDX12 = static_cast<GPUTextureViewDX12*>(depthBuffer); auto depthBufferDX12 = static_cast<GPUTextureViewDX12*>(depthBuffer);
@@ -159,7 +159,7 @@ public:
void* GetNativePtr() const override; void* GetNativePtr() const override;
bool IsDepthBufferBinded() override; bool IsDepthBufferBinded() override;
void Clear(GPUTextureView* rt, const Color& color) override; void Clear(GPUTextureView* rt, const Color& color) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override; void ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue) override;
void ClearUA(GPUBuffer* buf, const Float4& value) override; void ClearUA(GPUBuffer* buf, const Float4& value) override;
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override; void ClearUA(GPUBuffer* buf, const uint32 value[4]) override;
void ClearUA(GPUTexture* texture, const uint32 value[4]) override; void ClearUA(GPUTexture* texture, const uint32 value[4]) override;
@@ -48,7 +48,7 @@ public:
{ {
} }
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override void ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue) override
{ {
} }
@@ -797,7 +797,7 @@ void GPUContextVulkan::Clear(GPUTextureView* rt, const Color& color)
} }
} }
void GPUContextVulkan::ClearDepth(GPUTextureView* depthBuffer, float depthValue) void GPUContextVulkan::ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue)
{ {
const auto rtVulkan = static_cast<GPUTextureViewVulkan*>(depthBuffer); const auto rtVulkan = static_cast<GPUTextureViewVulkan*>(depthBuffer);
@@ -151,7 +151,7 @@ public:
void* GetNativePtr() const override; void* GetNativePtr() const override;
bool IsDepthBufferBinded() override; bool IsDepthBufferBinded() override;
void Clear(GPUTextureView* rt, const Color& color) override; void Clear(GPUTextureView* rt, const Color& color) override;
void ClearDepth(GPUTextureView* depthBuffer, float depthValue) override; void ClearDepthCustom(GPUTextureView* depthBuffer, float depthValue) override;
void ClearUA(GPUBuffer* buf, const Float4& value) override; void ClearUA(GPUBuffer* buf, const Float4& value) override;
void ClearUA(GPUBuffer* buf, const uint32 value[4]) override; void ClearUA(GPUBuffer* buf, const uint32 value[4]) override;
void ClearUA(GPUTexture* texture, const uint32 value[4]) override; void ClearUA(GPUTexture* texture, const uint32 value[4]) override;