Skip to content

Commit

Permalink
Update backend to use ColorBlendAttachmentBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas authored and madame-rachelle committed Jan 26, 2024
1 parent 58acf52 commit 9ff1193
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/common/rendering/vulkan/renderer/vk_renderpass.cpp
Expand Up @@ -319,10 +319,15 @@ std::unique_ptr<VulkanPipeline> VkRenderPassSetup::CreatePipeline(const VkPipeli
// main.vp addresses this by patching up gl_Position.z, which has the side effect of flipping the sign of the front face calculations.
builder.Cull(key.CullMode == Cull_None ? VK_CULL_MODE_NONE : VK_CULL_MODE_BACK_BIT, key.CullMode == Cull_CW ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE);

builder.ColorWriteMask((VkColorComponentFlags)key.ColorMask);
builder.Stencil(VK_STENCIL_OP_KEEP, op2vk[key.StencilPassOp], VK_STENCIL_OP_KEEP, VK_COMPARE_OP_EQUAL, 0xffffffff, 0xffffffff, 0);
BlendMode(builder, key.RenderStyle);
builder.SubpassColorAttachmentCount(PassKey.DrawBuffers);

ColorBlendAttachmentBuilder blendbuilder;
blendbuilder.ColorWriteMask((VkColorComponentFlags)key.ColorMask);
BlendMode(blendbuilder, key.RenderStyle);

for (int i = 0; i < PassKey.DrawBuffers; i++)
builder.AddColorBlendAttachment(blendbuilder.Create());

builder.RasterizationSamples((VkSampleCountFlagBits)PassKey.Samples);

builder.Layout(fb->GetRenderPassManager()->GetPipelineLayout(key.NumTextureLayers));
Expand Down Expand Up @@ -389,7 +394,11 @@ void VkPPRenderPassSetup::CreatePipeline(const VkPPRenderPassKey& key)
builder.Stencil(VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, VK_COMPARE_OP_EQUAL, 0xffffffff, 0xffffffff, 0);
}
builder.Topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP);
BlendMode(builder, key.BlendMode);

ColorBlendAttachmentBuilder blendbuilder;
BlendMode(blendbuilder, key.BlendMode);
builder.AddColorBlendAttachment(blendbuilder.Create());

builder.RasterizationSamples(key.Samples);
builder.Layout(PipelineLayout.get());
builder.RenderPass(RenderPass.get());
Expand Down Expand Up @@ -447,7 +456,7 @@ void VkPPRenderPassSetup::CreateRenderPass(const VkPPRenderPassKey& key)

/////////////////////////////////////////////////////////////////////////////

GraphicsPipelineBuilder& BlendMode(GraphicsPipelineBuilder& builder, const FRenderStyle& style)
ColorBlendAttachmentBuilder& BlendMode(ColorBlendAttachmentBuilder& builder, const FRenderStyle& style)
{
// Just in case Vulkan doesn't do this optimization itself
if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_One && style.DestAlpha == STYLEALPHA_Zero && style.Flags == 0)
Expand Down
3 changes: 2 additions & 1 deletion src/common/rendering/vulkan/renderer/vk_renderpass.h
Expand Up @@ -12,6 +12,7 @@
class VulkanRenderDevice;
class VkPPShader;
class GraphicsPipelineBuilder;
class ColorBlendAttachmentBuilder;

class VkPipelineKey
{
Expand Down Expand Up @@ -118,7 +119,7 @@ class VkPPRenderPassSetup
VulkanRenderDevice* fb = nullptr;
};

GraphicsPipelineBuilder& BlendMode(GraphicsPipelineBuilder& builder, const FRenderStyle& style);
ColorBlendAttachmentBuilder& BlendMode(ColorBlendAttachmentBuilder& builder, const FRenderStyle& style);

class VkRenderPassManager
{
Expand Down

0 comments on commit 9ff1193

Please sign in to comment.