From cf49e1ec2103e59336c21b5b6ce2df7f4f382909 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 3 Mar 2019 23:54:13 +0100 Subject: [PATCH] - add depth clamp support --- src/rendering/vulkan/renderer/vk_renderpass.cpp | 1 + src/rendering/vulkan/renderer/vk_renderpass.h | 1 + src/rendering/vulkan/renderer/vk_renderstate.cpp | 5 +++-- src/rendering/vulkan/renderer/vk_renderstate.h | 2 +- src/rendering/vulkan/system/vk_builders.h | 6 ++++++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index 242114a8c..4e6b3b118 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -295,6 +295,7 @@ void VkRenderPassSetup::CreatePipeline(const VkRenderPassKey &key) builder.setTopology(vktopology[key.DrawType]); builder.setDepthStencilEnable(key.DepthTest, key.DepthWrite, key.StencilTest); builder.setDepthFunc(depthfunc2vk[key.DepthFunc]); + builder.setDepthClampEnable(key.DepthClamp); builder.setCull(key.CullMode == Cull_None ? VK_CULL_MODE_NONE : VK_CULL_MODE_FRONT_AND_BACK, key.CullMode == Cull_CW ? VK_FRONT_FACE_CLOCKWISE : VK_FRONT_FACE_COUNTER_CLOCKWISE); builder.setColorWriteMask((VkColorComponentFlagBits)key.ColorMask); builder.setStencil(VK_STENCIL_OP_KEEP, op2vk[key.StencilPassOp], VK_STENCIL_OP_KEEP, VK_COMPARE_OP_EQUAL, 0xffffffff, 0xffffffff, 0); diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index b8c6dd39b..108f36bbb 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -18,6 +18,7 @@ public: int DepthWrite; int DepthTest; int DepthFunc; + int DepthClamp; int StencilTest; int StencilPassOp; int ColorMask; diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index f59680c8e..dd19ff7b0 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -52,8 +52,8 @@ void VkRenderState::DrawIndexed(int dt, int index, int count, bool apply) bool VkRenderState::SetDepthClamp(bool on) { - bool lastValue = mLastDepthClamp; - mLastDepthClamp = on; + bool lastValue = mDepthClamp; + mDepthClamp = on; mNeedApply = true; return lastValue; } @@ -244,6 +244,7 @@ void VkRenderState::ApplyRenderPass(int dt) passKey.DepthTest = mDepthTest; passKey.DepthWrite = mDepthTest && mDepthWrite; passKey.DepthFunc = mDepthFunc; + passKey.DepthClamp = mDepthClamp; passKey.StencilTest = mStencilTest; passKey.StencilPassOp = mStencilOp; passKey.ColorMask = mColorMask; diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index 2aef47749..bfc0edd30 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -57,7 +57,7 @@ private: void ApplyVertexBuffers(); void ApplyMaterial(); - bool mLastDepthClamp = true; + bool mDepthClamp = true; VulkanCommandBuffer *mCommandBuffer = nullptr; VkRenderPassKey mRenderPassKey = {}; bool mNeedApply = true; diff --git a/src/rendering/vulkan/system/vk_builders.h b/src/rendering/vulkan/system/vk_builders.h index 39f1c9db4..a6645edd9 100644 --- a/src/rendering/vulkan/system/vk_builders.h +++ b/src/rendering/vulkan/system/vk_builders.h @@ -188,6 +188,7 @@ public: void setCull(VkCullModeFlags cullMode, VkFrontFace frontFace); void setDepthStencilEnable(bool test, bool write, bool stencil); void setDepthFunc(VkCompareOp func); + void setDepthClampEnable(bool value); void setColorWriteMask(VkColorComponentFlags mask); void setStencil(VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp, VkCompareOp compareOp, uint32_t compareMask, uint32_t writeMask, uint32_t reference); @@ -800,6 +801,11 @@ inline void GraphicsPipelineBuilder::setDepthFunc(VkCompareOp func) depthStencil.depthCompareOp = func; } +inline void GraphicsPipelineBuilder::setDepthClampEnable(bool value) +{ + rasterizer.depthClampEnable = value ? VK_TRUE : VK_FALSE; +} + inline void GraphicsPipelineBuilder::setColorWriteMask(VkColorComponentFlags mask) { colorBlendAttachment.colorWriteMask = mask;