summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2017-04-30 15:54:45 +1000
committerStenzek <stenzek@gmail.com>2017-09-11 19:40:26 +1000
commit2869c570f1d0b67d2ee4304ea528bef3ef4b563e (patch)
tree2f10d4f34da42a5e9f81706f853451bd8a59a701 /Source/Core/VideoBackends/Vulkan
parent4d36f0cc87d2cc2bc40ec1c36a65623dc3822f01 (diff)
Renderer: Move depth state to VideoCommon and seperate from bpmem
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan')
-rw-r--r--Source/Core/VideoBackends/Vulkan/Constants.h10
-rw-r--r--Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp8
-rw-r--r--Source/Core/VideoBackends/Vulkan/Renderer.cpp50
-rw-r--r--Source/Core/VideoBackends/Vulkan/Renderer.h2
-rw-r--r--Source/Core/VideoBackends/Vulkan/ShaderCache.cpp15
-rw-r--r--Source/Core/VideoBackends/Vulkan/ShaderCache.h2
-rw-r--r--Source/Core/VideoBackends/Vulkan/StateTracker.cpp16
-rw-r--r--Source/Core/VideoBackends/Vulkan/StateTracker.h9
-rw-r--r--Source/Core/VideoBackends/Vulkan/Util.cpp16
-rw-r--r--Source/Core/VideoBackends/Vulkan/Util.h4
10 files changed, 44 insertions, 88 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/Constants.h b/Source/Core/VideoBackends/Vulkan/Constants.h
index 9d1ab3fecd..e51c54e18c 100644
--- a/Source/Core/VideoBackends/Vulkan/Constants.h
+++ b/Source/Core/VideoBackends/Vulkan/Constants.h
@@ -135,16 +135,6 @@ union RasterizationState
u32 bits;
};
-// Depth state info
-union DepthStencilState
-{
- BitField<0, 1, VkBool32> test_enable;
- BitField<1, 1, VkBool32> write_enable;
- BitField<2, 3, VkCompareOp> compare_op;
-
- u32 bits;
-};
-
// Sampler info
union SamplerState
{
diff --git a/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp b/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
index dec6d9e952..45d17a17e3 100644
--- a/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
+++ b/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
@@ -1164,16 +1164,16 @@ void FramebufferManager::DrawPokeVertices(const EFBPokeVertex* vertices, size_t
pipeline_info.render_pass = m_efb_load_render_pass;
pipeline_info.rasterization_state.bits = Util::GetNoCullRasterizationState().bits;
pipeline_info.rasterization_state.samples = m_efb_samples;
- pipeline_info.depth_stencil_state.bits = Util::GetNoDepthTestingDepthStencilState().bits;
+ pipeline_info.depth_state.hex = Util::GetNoDepthTestingDepthStencilState().hex;
pipeline_info.blend_state.hex = Util::GetNoBlendingBlendState().hex;
pipeline_info.blend_state.colorupdate = write_color;
pipeline_info.blend_state.alphaupdate = write_color;
pipeline_info.primitive_topology = m_poke_primitive_topology;
if (write_depth)
{
- pipeline_info.depth_stencil_state.test_enable = VK_TRUE;
- pipeline_info.depth_stencil_state.write_enable = VK_TRUE;
- pipeline_info.depth_stencil_state.compare_op = VK_COMPARE_OP_ALWAYS;
+ pipeline_info.depth_state.testenable = true;
+ pipeline_info.depth_state.updateenable = true;
+ pipeline_info.depth_state.func = ZMode::ALWAYS;
}
VkPipeline pipeline = g_shader_cache->GetPipeline(pipeline_info);
diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp
index 7a94572b1e..97c23ca2ef 100644
--- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp
+++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp
@@ -459,10 +459,10 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool color_enable, bool alpha
blend_state.colorupdate = color_enable;
blend_state.alphaupdate = alpha_enable;
- DepthStencilState depth_state = Util::GetNoDepthTestingDepthStencilState();
- depth_state.test_enable = z_enable ? VK_TRUE : VK_FALSE;
- depth_state.write_enable = z_enable ? VK_TRUE : VK_FALSE;
- depth_state.compare_op = VK_COMPARE_OP_ALWAYS;
+ DepthState depth_state = Util::GetNoDepthTestingDepthStencilState();
+ depth_state.testenable = z_enable;
+ depth_state.updateenable = z_enable;
+ depth_state.func = ZMode::ALWAYS;
RasterizationState rs_state = Util::GetNoCullRasterizationState();
rs_state.per_sample_shading = g_ActiveConfig.bSSAA ? VK_TRUE : VK_FALSE;
@@ -476,7 +476,7 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool color_enable, bool alpha
g_shader_cache->GetPassthroughGeometryShader(), m_clear_fragment_shader);
draw.SetRasterizationState(rs_state);
- draw.SetDepthStencilState(depth_state);
+ draw.SetDepthState(depth_state);
draw.SetBlendState(blend_state);
draw.DrawColoredQuad(target_rc.left, target_rc.top, target_rc.GetWidth(), target_rc.GetHeight(),
@@ -1303,45 +1303,9 @@ void Renderer::SetGenerationMode()
StateTracker::GetInstance()->SetRasterizationState(new_rs_state);
}
-void Renderer::SetDepthMode()
+void Renderer::SetDepthState(const DepthState& state)
{
- DepthStencilState new_ds_state = {};
- new_ds_state.test_enable = bpmem.zmode.testenable ? VK_TRUE : VK_FALSE;
- new_ds_state.write_enable = bpmem.zmode.updateenable ? VK_TRUE : VK_FALSE;
-
- // Inverted depth, hence these are swapped
- switch (bpmem.zmode.func)
- {
- case ZMode::NEVER:
- new_ds_state.compare_op = VK_COMPARE_OP_NEVER;
- break;
- case ZMode::LESS:
- new_ds_state.compare_op = VK_COMPARE_OP_GREATER;
- break;
- case ZMode::EQUAL:
- new_ds_state.compare_op = VK_COMPARE_OP_EQUAL;
- break;
- case ZMode::LEQUAL:
- new_ds_state.compare_op = VK_COMPARE_OP_GREATER_OR_EQUAL;
- break;
- case ZMode::GREATER:
- new_ds_state.compare_op = VK_COMPARE_OP_LESS;
- break;
- case ZMode::NEQUAL:
- new_ds_state.compare_op = VK_COMPARE_OP_NOT_EQUAL;
- break;
- case ZMode::GEQUAL:
- new_ds_state.compare_op = VK_COMPARE_OP_LESS_OR_EQUAL;
- break;
- case ZMode::ALWAYS:
- new_ds_state.compare_op = VK_COMPARE_OP_ALWAYS;
- break;
- default:
- new_ds_state.compare_op = VK_COMPARE_OP_ALWAYS;
- break;
- }
-
- StateTracker::GetInstance()->SetDepthStencilState(new_ds_state);
+ StateTracker::GetInstance()->SetDepthState(state);
}
void Renderer::SetBlendingState(const BlendingState& state)
diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.h b/Source/Core/VideoBackends/Vulkan/Renderer.h
index 5ec1be8277..12272e57a0 100644
--- a/Source/Core/VideoBackends/Vulkan/Renderer.h
+++ b/Source/Core/VideoBackends/Vulkan/Renderer.h
@@ -59,7 +59,7 @@ public:
void SetBlendingState(const BlendingState& state) override;
void SetScissorRect(const EFBRectangle& rc) override;
void SetGenerationMode() override;
- void SetDepthMode() override;
+ void SetDepthState(const DepthState& state) override;
void SetSamplerState(int stage, int texindex, bool custom_tex) override;
void SetInterlacingMode() override;
void SetViewport() override;
diff --git a/Source/Core/VideoBackends/Vulkan/ShaderCache.cpp b/Source/Core/VideoBackends/Vulkan/ShaderCache.cpp
index 7d5c3e2379..fb62560ad9 100644
--- a/Source/Core/VideoBackends/Vulkan/ShaderCache.cpp
+++ b/Source/Core/VideoBackends/Vulkan/ShaderCache.cpp
@@ -122,16 +122,21 @@ GetVulkanMultisampleState(const RasterizationState& rs_state)
};
}
-static VkPipelineDepthStencilStateCreateInfo
-GetVulkanDepthStencilState(const DepthStencilState& state)
+static VkPipelineDepthStencilStateCreateInfo GetVulkanDepthStencilState(const DepthState& state)
{
+ // Less/greater are swapped due to inverted depth.
+ static constexpr std::array<VkCompareOp, 8> funcs = {
+ {VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_EQUAL,
+ VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_NOT_EQUAL,
+ VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_ALWAYS}};
+
return {
VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType
nullptr, // const void* pNext
0, // VkPipelineDepthStencilStateCreateFlags flags
- state.test_enable, // VkBool32 depthTestEnable
- state.write_enable, // VkBool32 depthWriteEnable
- state.compare_op, // VkCompareOp depthCompareOp
+ state.testenable, // VkBool32 depthTestEnable
+ state.updateenable, // VkBool32 depthWriteEnable
+ funcs[state.func], // VkCompareOp depthCompareOp
VK_FALSE, // VkBool32 depthBoundsTestEnable
VK_FALSE, // VkBool32 stencilTestEnable
{}, // VkStencilOpState front
diff --git a/Source/Core/VideoBackends/Vulkan/ShaderCache.h b/Source/Core/VideoBackends/Vulkan/ShaderCache.h
index 56f888d363..34813687f5 100644
--- a/Source/Core/VideoBackends/Vulkan/ShaderCache.h
+++ b/Source/Core/VideoBackends/Vulkan/ShaderCache.h
@@ -49,7 +49,7 @@ struct PipelineInfo
VkRenderPass render_pass;
BlendingState blend_state;
RasterizationState rasterization_state;
- DepthStencilState depth_stencil_state;
+ DepthState depth_state;
VkPrimitiveTopology primitive_topology;
};
diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
index ae583374e8..5e09f6838e 100644
--- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
+++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
@@ -58,9 +58,9 @@ bool StateTracker::Initialize()
m_pipeline_state.rasterization_state.cull_mode = VK_CULL_MODE_NONE;
m_pipeline_state.rasterization_state.per_sample_shading = VK_FALSE;
m_pipeline_state.rasterization_state.depth_clamp = VK_FALSE;
- m_pipeline_state.depth_stencil_state.test_enable = VK_TRUE;
- m_pipeline_state.depth_stencil_state.write_enable = VK_TRUE;
- m_pipeline_state.depth_stencil_state.compare_op = VK_COMPARE_OP_LESS;
+ m_pipeline_state.depth_state.testenable = true;
+ m_pipeline_state.depth_state.updateenable = true;
+ m_pipeline_state.depth_state.func = ZMode::ALWAYS;
m_pipeline_state.blend_state.hex = 0;
m_pipeline_state.blend_state.blendenable = false;
m_pipeline_state.blend_state.srcfactor = BlendMode::ONE;
@@ -167,7 +167,7 @@ void StateTracker::AppendToPipelineUIDCache(const PipelineInfo& info)
SerializedPipelineUID sinfo;
sinfo.blend_state_bits = info.blend_state.hex;
sinfo.rasterizer_state_bits = info.rasterization_state.bits;
- sinfo.depth_stencil_state_bits = info.depth_stencil_state.bits;
+ sinfo.depth_state_bits = info.depth_state.hex;
sinfo.vertex_decl = m_pipeline_state.vertex_format->GetVertexDeclaration();
sinfo.vs_uid = m_vs_uid;
sinfo.gs_uid = m_gs_uid;
@@ -212,7 +212,7 @@ bool StateTracker::PrecachePipelineUID(const SerializedPipelineUID& uid)
}
pinfo.render_pass = m_load_render_pass;
pinfo.rasterization_state.bits = uid.rasterizer_state_bits;
- pinfo.depth_stencil_state.bits = uid.depth_stencil_state_bits;
+ pinfo.depth_state.hex = uid.depth_state_bits;
pinfo.blend_state.hex = uid.blend_state_bits;
pinfo.primitive_topology = uid.primitive_topology;
@@ -316,12 +316,12 @@ void StateTracker::SetRasterizationState(const RasterizationState& state)
m_dirty_flags |= DIRTY_FLAG_PIPELINE;
}
-void StateTracker::SetDepthStencilState(const DepthStencilState& state)
+void StateTracker::SetDepthState(const DepthState& state)
{
- if (m_pipeline_state.depth_stencil_state.bits == state.bits)
+ if (m_pipeline_state.depth_state.hex == state.hex)
return;
- m_pipeline_state.depth_stencil_state.bits = state.bits;
+ m_pipeline_state.depth_state.hex = state.hex;
m_dirty_flags |= DIRTY_FLAG_PIPELINE;
}
diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.h b/Source/Core/VideoBackends/Vulkan/StateTracker.h
index 73da3ad646..8b0602ddb1 100644
--- a/Source/Core/VideoBackends/Vulkan/StateTracker.h
+++ b/Source/Core/VideoBackends/Vulkan/StateTracker.h
@@ -39,10 +39,7 @@ public:
{
return m_pipeline_state.rasterization_state;
}
- const DepthStencilState& GetDepthStencilState() const
- {
- return m_pipeline_state.depth_stencil_state;
- }
+ const DepthState& GetDepthStencilState() const { return m_pipeline_state.depth_state; }
const BlendingState& GetBlendState() const { return m_pipeline_state.blend_state; }
void SetVertexBuffer(VkBuffer buffer, VkDeviceSize offset);
void SetIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType type);
@@ -58,7 +55,7 @@ public:
void DisableBackFaceCulling();
void SetRasterizationState(const RasterizationState& state);
- void SetDepthStencilState(const DepthStencilState& state);
+ void SetDepthState(const DepthState& state);
void SetBlendState(const BlendingState& state);
bool CheckForShaderChanges(u32 gx_primitive_type);
@@ -130,7 +127,7 @@ private:
struct SerializedPipelineUID
{
u32 rasterizer_state_bits;
- u32 depth_stencil_state_bits;
+ u32 depth_state_bits;
u32 blend_state_bits;
PortableVertexDeclaration vertex_decl;
VertexShaderUid vs_uid;
diff --git a/Source/Core/VideoBackends/Vulkan/Util.cpp b/Source/Core/VideoBackends/Vulkan/Util.cpp
index 9796811978..b935acd8ef 100644
--- a/Source/Core/VideoBackends/Vulkan/Util.cpp
+++ b/Source/Core/VideoBackends/Vulkan/Util.cpp
@@ -195,12 +195,12 @@ RasterizationState GetNoCullRasterizationState()
return state;
}
-DepthStencilState GetNoDepthTestingDepthStencilState()
+DepthState GetNoDepthTestingDepthStencilState()
{
- DepthStencilState state = {};
- state.test_enable = VK_FALSE;
- state.write_enable = VK_FALSE;
- state.compare_op = VK_COMPARE_OP_ALWAYS;
+ DepthState state = {};
+ state.testenable = false;
+ state.updateenable = false;
+ state.func = ZMode::ALWAYS;
return state;
}
@@ -346,7 +346,7 @@ UtilityShaderDraw::UtilityShaderDraw(VkCommandBuffer command_buffer,
m_pipeline_info.gs = geometry_shader;
m_pipeline_info.ps = pixel_shader;
m_pipeline_info.rasterization_state.bits = Util::GetNoCullRasterizationState().bits;
- m_pipeline_info.depth_stencil_state.bits = Util::GetNoDepthTestingDepthStencilState().bits;
+ m_pipeline_info.depth_state.hex = Util::GetNoDepthTestingDepthStencilState().hex;
m_pipeline_info.blend_state.hex = Util::GetNoBlendingBlendState().hex;
m_pipeline_info.primitive_topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
}
@@ -450,9 +450,9 @@ void UtilityShaderDraw::SetRasterizationState(const RasterizationState& state)
m_pipeline_info.rasterization_state.bits = state.bits;
}
-void UtilityShaderDraw::SetDepthStencilState(const DepthStencilState& state)
+void UtilityShaderDraw::SetDepthState(const DepthState& state)
{
- m_pipeline_info.depth_stencil_state.bits = state.bits;
+ m_pipeline_info.depth_state.hex = state.hex;
}
void UtilityShaderDraw::SetBlendState(const BlendingState& state)
diff --git a/Source/Core/VideoBackends/Vulkan/Util.h b/Source/Core/VideoBackends/Vulkan/Util.h
index c99f0e968c..4f84d8a645 100644
--- a/Source/Core/VideoBackends/Vulkan/Util.h
+++ b/Source/Core/VideoBackends/Vulkan/Util.h
@@ -39,7 +39,7 @@ VkRect2D ClampRect2D(const VkRect2D& rect, u32 width, u32 height);
VkBlendFactor GetAlphaBlendFactor(VkBlendFactor factor);
RasterizationState GetNoCullRasterizationState();
-DepthStencilState GetNoDepthTestingDepthStencilState();
+DepthState GetNoDepthTestingDepthStencilState();
BlendingState GetNoBlendingBlendState();
// Combines viewport and scissor updates
@@ -151,7 +151,7 @@ public:
void SetPSTexelBuffer(VkBufferView view);
void SetRasterizationState(const RasterizationState& state);
- void SetDepthStencilState(const DepthStencilState& state);
+ void SetDepthState(const DepthState& state);
void SetBlendState(const BlendingState& state);
void BeginRenderPass(VkFramebuffer framebuffer, const VkRect2D& region,