summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/Util.cpp
diff options
context:
space:
mode:
authorMarkus Wick <degasus@users.noreply.github.com>2017-09-11 13:28:09 +0200
committerGitHub <noreply@github.com>2017-09-11 13:28:09 +0200
commit002e01d0ede3bd0eeebebc09f8f6a813ebc8d444 (patch)
tree5fb17c3d07988499767c51908b49dac2d8d9c881 /Source/Core/VideoBackends/Vulkan/Util.cpp
parent9d169449a7898cefab29a5e033f82560cfcdef5e (diff)
parent24ddea04ce3c843dd1de3d34d775e9a49d195225 (diff)
Merge pull request #5343 from stenzek/videocommon-states
Move depth, rasterization and sampler states to VideoCommon
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/Util.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/Util.cpp75
1 files changed, 22 insertions, 53 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/Util.cpp b/Source/Core/VideoBackends/Vulkan/Util.cpp
index 9796811978..8a94dd42ad 100644
--- a/Source/Core/VideoBackends/Vulkan/Util.cpp
+++ b/Source/Core/VideoBackends/Vulkan/Util.cpp
@@ -185,39 +185,6 @@ VkBlendFactor GetAlphaBlendFactor(VkBlendFactor factor)
}
}
-RasterizationState GetNoCullRasterizationState()
-{
- RasterizationState state = {};
- state.cull_mode = VK_CULL_MODE_NONE;
- state.samples = VK_SAMPLE_COUNT_1_BIT;
- state.per_sample_shading = VK_FALSE;
- state.depth_clamp = VK_FALSE;
- return state;
-}
-
-DepthStencilState GetNoDepthTestingDepthStencilState()
-{
- DepthStencilState state = {};
- state.test_enable = VK_FALSE;
- state.write_enable = VK_FALSE;
- state.compare_op = VK_COMPARE_OP_ALWAYS;
- return state;
-}
-
-BlendingState GetNoBlendingBlendState()
-{
- BlendingState state = {};
- state.blendenable = false;
- state.srcfactor = BlendMode::ONE;
- state.srcfactoralpha = BlendMode::ZERO;
- state.dstfactor = BlendMode::ONE;
- state.dstfactoralpha = BlendMode::ZERO;
- state.logicopenable = false;
- state.colorupdate = true;
- state.alphaupdate = true;
- return state;
-}
-
void SetViewportAndScissor(VkCommandBuffer command_buffer, int x, int y, int width, int height,
float min_depth /*= 0.0f*/, float max_depth /*= 1.0f*/)
{
@@ -335,7 +302,7 @@ VkShaderModule CompileAndCreateComputeShader(const std::string& source_code, boo
UtilityShaderDraw::UtilityShaderDraw(VkCommandBuffer command_buffer,
VkPipelineLayout pipeline_layout, VkRenderPass render_pass,
VkShaderModule vertex_shader, VkShaderModule geometry_shader,
- VkShaderModule pixel_shader)
+ VkShaderModule pixel_shader, PrimitiveType primitive)
: m_command_buffer(command_buffer)
{
// Populate minimal pipeline state
@@ -345,16 +312,16 @@ UtilityShaderDraw::UtilityShaderDraw(VkCommandBuffer command_buffer,
m_pipeline_info.vs = vertex_shader;
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.blend_state.hex = Util::GetNoBlendingBlendState().hex;
- m_pipeline_info.primitive_topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
+ m_pipeline_info.rasterization_state.hex = RenderState::GetNoCullRasterizationState().hex;
+ m_pipeline_info.rasterization_state.primitive = primitive;
+ m_pipeline_info.depth_state.hex = RenderState::GetNoDepthTestingDepthStencilState().hex;
+ m_pipeline_info.blend_state.hex = RenderState::GetNoBlendingBlendState().hex;
+ m_pipeline_info.multisampling_state.per_sample_shading = false;
+ m_pipeline_info.multisampling_state.samples = 1;
}
-UtilityShaderVertex* UtilityShaderDraw::ReserveVertices(VkPrimitiveTopology topology, size_t count)
+UtilityShaderVertex* UtilityShaderDraw::ReserveVertices(size_t count)
{
- m_pipeline_info.primitive_topology = topology;
-
if (!g_object_cache->GetUtilityShaderVertexBuffer()->ReserveMemory(
sizeof(UtilityShaderVertex) * count, sizeof(UtilityShaderVertex), true, true, true))
PanicAlert("Failed to allocate space for vertices in backend shader");
@@ -372,10 +339,9 @@ void UtilityShaderDraw::CommitVertices(size_t count)
m_vertex_count = static_cast<uint32_t>(count);
}
-void UtilityShaderDraw::UploadVertices(VkPrimitiveTopology topology, UtilityShaderVertex* vertices,
- size_t count)
+void UtilityShaderDraw::UploadVertices(UtilityShaderVertex* vertices, size_t count)
{
- UtilityShaderVertex* upload_vertices = ReserveVertices(topology, count);
+ UtilityShaderVertex* upload_vertices = ReserveVertices(count);
memcpy(upload_vertices, vertices, sizeof(UtilityShaderVertex) * count);
CommitVertices(count);
}
@@ -447,12 +413,17 @@ void UtilityShaderDraw::SetPSTexelBuffer(VkBufferView view)
void UtilityShaderDraw::SetRasterizationState(const RasterizationState& state)
{
- m_pipeline_info.rasterization_state.bits = state.bits;
+ m_pipeline_info.rasterization_state.hex = state.hex;
+}
+
+void UtilityShaderDraw::SetMultisamplingState(const MultisamplingState& state)
+{
+ m_pipeline_info.multisampling_state.hex = state.hex;
}
-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)
@@ -506,7 +477,7 @@ void UtilityShaderDraw::DrawQuad(int x, int y, int width, int height, float z)
vertices[3].SetColor(1.0f, 1.0f, 1.0f, 1.0f);
Util::SetViewportAndScissor(m_command_buffer, x, y, width, height);
- UploadVertices(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, vertices, ArraySize(vertices));
+ UploadVertices(vertices, ArraySize(vertices));
Draw();
}
@@ -535,7 +506,7 @@ void UtilityShaderDraw::DrawQuad(int dst_x, int dst_y, int dst_width, int dst_he
vertices[3].SetColor(1.0f, 1.0f, 1.0f, 1.0f);
Util::SetViewportAndScissor(m_command_buffer, dst_x, dst_y, dst_width, dst_height);
- UploadVertices(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, vertices, ArraySize(vertices));
+ UploadVertices(vertices, ArraySize(vertices));
Draw();
}
@@ -562,7 +533,7 @@ void UtilityShaderDraw::DrawColoredQuad(int x, int y, int width, int height, u32
vertices[3].SetColor(color);
Util::SetViewportAndScissor(m_command_buffer, x, y, width, height);
- UploadVertices(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, vertices, ArraySize(vertices));
+ UploadVertices(vertices, ArraySize(vertices));
Draw();
}
@@ -571,11 +542,9 @@ void UtilityShaderDraw::SetViewportAndScissor(int x, int y, int width, int heigh
Util::SetViewportAndScissor(m_command_buffer, x, y, width, height, 0.0f, 1.0f);
}
-void UtilityShaderDraw::DrawWithoutVertexBuffer(VkPrimitiveTopology primitive_topology,
- u32 vertex_count)
+void UtilityShaderDraw::DrawWithoutVertexBuffer(u32 vertex_count)
{
m_pipeline_info.vertex_format = nullptr;
- m_pipeline_info.primitive_topology = primitive_topology;
BindDescriptors();
if (!BindPipeline())