Update to latest ZVulkan
This commit is contained in:
parent
c1f38b18c4
commit
a8cf44bcda
6 changed files with 104 additions and 73 deletions
|
|
@ -350,6 +350,22 @@ private:
|
|||
const char* debugName = nullptr;
|
||||
};
|
||||
|
||||
class ColorBlendAttachmentBuilder
|
||||
{
|
||||
public:
|
||||
ColorBlendAttachmentBuilder();
|
||||
|
||||
ColorBlendAttachmentBuilder& ColorWriteMask(VkColorComponentFlags mask);
|
||||
ColorBlendAttachmentBuilder& AdditiveBlendMode();
|
||||
ColorBlendAttachmentBuilder& AlphaBlendMode();
|
||||
ColorBlendAttachmentBuilder& BlendMode(VkBlendOp op, VkBlendFactor src, VkBlendFactor dst);
|
||||
|
||||
VkPipelineColorBlendAttachmentState Create() { return colorBlendAttachment; }
|
||||
|
||||
private:
|
||||
VkPipelineColorBlendAttachmentState colorBlendAttachment = { };
|
||||
};
|
||||
|
||||
class GraphicsPipelineBuilder
|
||||
{
|
||||
public:
|
||||
|
|
@ -369,13 +385,9 @@ public:
|
|||
GraphicsPipelineBuilder& DepthFunc(VkCompareOp func);
|
||||
GraphicsPipelineBuilder& DepthClampEnable(bool value);
|
||||
GraphicsPipelineBuilder& DepthBias(bool enable, float biasConstantFactor, float biasClamp, float biasSlopeFactor);
|
||||
GraphicsPipelineBuilder& ColorWriteMask(VkColorComponentFlags mask);
|
||||
GraphicsPipelineBuilder& Stencil(VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp, VkCompareOp compareOp, uint32_t compareMask, uint32_t writeMask, uint32_t reference);
|
||||
|
||||
GraphicsPipelineBuilder& AdditiveBlendMode();
|
||||
GraphicsPipelineBuilder& AlphaBlendMode();
|
||||
GraphicsPipelineBuilder& BlendMode(VkBlendOp op, VkBlendFactor src, VkBlendFactor dst);
|
||||
GraphicsPipelineBuilder& SubpassColorAttachmentCount(int count);
|
||||
GraphicsPipelineBuilder& AddColorBlendAttachment(VkPipelineColorBlendAttachmentState state);
|
||||
|
||||
GraphicsPipelineBuilder& AddVertexShader(VulkanShader *shader);
|
||||
GraphicsPipelineBuilder& AddFragmentShader(VulkanShader *shader);
|
||||
|
|
@ -398,7 +410,6 @@ private:
|
|||
VkPipelineViewportStateCreateInfo viewportState = { };
|
||||
VkPipelineRasterizationStateCreateInfo rasterizer = { };
|
||||
VkPipelineMultisampleStateCreateInfo multisampling = { };
|
||||
VkPipelineColorBlendAttachmentState colorBlendAttachment = { };
|
||||
VkPipelineColorBlendStateCreateInfo colorBlending = { };
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencil = { };
|
||||
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
||||
|
|
|
|||
|
|
@ -920,6 +920,63 @@ std::unique_ptr<VulkanFramebuffer> FramebufferBuilder::Create(VulkanDevice* devi
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
ColorBlendAttachmentBuilder::ColorBlendAttachmentBuilder()
|
||||
{
|
||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
colorBlendAttachment.blendEnable = VK_FALSE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
}
|
||||
|
||||
ColorBlendAttachmentBuilder& ColorBlendAttachmentBuilder::ColorWriteMask(VkColorComponentFlags mask)
|
||||
{
|
||||
colorBlendAttachment.colorWriteMask = mask;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColorBlendAttachmentBuilder& ColorBlendAttachmentBuilder::AdditiveBlendMode()
|
||||
{
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColorBlendAttachmentBuilder& ColorBlendAttachmentBuilder::AlphaBlendMode()
|
||||
{
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColorBlendAttachmentBuilder& ColorBlendAttachmentBuilder::BlendMode(VkBlendOp op, VkBlendFactor src, VkBlendFactor dst)
|
||||
{
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = src;
|
||||
colorBlendAttachment.dstColorBlendFactor = dst;
|
||||
colorBlendAttachment.colorBlendOp = op;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = src;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = dst;
|
||||
colorBlendAttachment.alphaBlendOp = op;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GraphicsPipelineBuilder::GraphicsPipelineBuilder()
|
||||
{
|
||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
|
|
@ -980,20 +1037,9 @@ GraphicsPipelineBuilder::GraphicsPipelineBuilder()
|
|||
multisampling.alphaToCoverageEnable = VK_FALSE;
|
||||
multisampling.alphaToOneEnable = VK_FALSE;
|
||||
|
||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
colorBlendAttachment.blendEnable = VK_FALSE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
|
||||
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
colorBlending.logicOpEnable = VK_FALSE;
|
||||
colorBlending.logicOp = VK_LOGIC_OP_COPY;
|
||||
colorBlending.attachmentCount = 1;
|
||||
colorBlending.pAttachments = &colorBlendAttachment;
|
||||
colorBlending.blendConstants[0] = 0.0f;
|
||||
colorBlending.blendConstants[1] = 0.0f;
|
||||
colorBlending.blendConstants[2] = 0.0f;
|
||||
|
|
@ -1114,53 +1160,9 @@ GraphicsPipelineBuilder& GraphicsPipelineBuilder::DepthBias(bool enable, float b
|
|||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::ColorWriteMask(VkColorComponentFlags mask)
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddColorBlendAttachment(VkPipelineColorBlendAttachmentState state)
|
||||
{
|
||||
colorBlendAttachment.colorWriteMask = mask;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AdditiveBlendMode()
|
||||
{
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AlphaBlendMode()
|
||||
{
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::BlendMode(VkBlendOp op, VkBlendFactor src, VkBlendFactor dst)
|
||||
{
|
||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||
colorBlendAttachment.srcColorBlendFactor = src;
|
||||
colorBlendAttachment.dstColorBlendFactor = dst;
|
||||
colorBlendAttachment.colorBlendOp = op;
|
||||
colorBlendAttachment.srcAlphaBlendFactor = src;
|
||||
colorBlendAttachment.dstAlphaBlendFactor = dst;
|
||||
colorBlendAttachment.alphaBlendOp = op;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::SubpassColorAttachmentCount(int count)
|
||||
{
|
||||
colorBlendAttachments.resize(count, colorBlendAttachment);
|
||||
colorBlending.pAttachments = colorBlendAttachments.data();
|
||||
colorBlending.attachmentCount = (uint32_t)colorBlendAttachments.size();
|
||||
colorBlendAttachments.push_back(state);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -1229,6 +1231,11 @@ GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddDynamicState(VkDynamicState
|
|||
|
||||
std::unique_ptr<VulkanPipeline> GraphicsPipelineBuilder::Create(VulkanDevice* device)
|
||||
{
|
||||
if (colorBlendAttachments.empty())
|
||||
colorBlendAttachments.push_back(ColorBlendAttachmentBuilder().Create());
|
||||
colorBlending.pAttachments = colorBlendAttachments.data();
|
||||
colorBlending.attachmentCount = (uint32_t)colorBlendAttachments.size();
|
||||
|
||||
VkPipeline pipeline = 0;
|
||||
VkResult result = vkCreateGraphicsPipelines(device->device, cache ? cache->cache : VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline);
|
||||
CheckVulkanError(result, "Could not create graphics pipeline");
|
||||
|
|
@ -1825,7 +1832,8 @@ std::vector<VulkanCompatibleDevice> VulkanDeviceBuilder::FindDevices(const std::
|
|||
// Check if all required features are there
|
||||
if (info.Features.Features.samplerAnisotropy != VK_TRUE ||
|
||||
info.Features.Features.fragmentStoresAndAtomics != VK_TRUE ||
|
||||
info.Features.Features.multiDrawIndirect != VK_TRUE)
|
||||
info.Features.Features.multiDrawIndirect != VK_TRUE ||
|
||||
info.Features.Features.independentBlend != VK_TRUE)
|
||||
continue;
|
||||
|
||||
VulkanCompatibleDevice dev;
|
||||
|
|
@ -1849,6 +1857,7 @@ std::vector<VulkanCompatibleDevice> VulkanDeviceBuilder::FindDevices(const std::
|
|||
enabledFeatures.Features.depthClamp = deviceFeatures.Features.depthClamp;
|
||||
enabledFeatures.Features.shaderClipDistance = deviceFeatures.Features.shaderClipDistance;
|
||||
enabledFeatures.Features.multiDrawIndirect = deviceFeatures.Features.multiDrawIndirect;
|
||||
enabledFeatures.Features.independentBlend = deviceFeatures.Features.independentBlend;
|
||||
enabledFeatures.BufferDeviceAddress.bufferDeviceAddress = deviceFeatures.BufferDeviceAddress.bufferDeviceAddress;
|
||||
enabledFeatures.AccelerationStructure.accelerationStructure = deviceFeatures.AccelerationStructure.accelerationStructure;
|
||||
enabledFeatures.RayQuery.rayQuery = deviceFeatures.RayQuery.rayQuery;
|
||||
|
|
|
|||
|
|
@ -126,9 +126,9 @@ bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, boo
|
|||
}
|
||||
else
|
||||
{
|
||||
if (supportsMailbox)
|
||||
/*if (supportsMailbox)
|
||||
presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
else if (supportsImmediate)
|
||||
else*/ if (supportsImmediate)
|
||||
presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
}
|
||||
|
|
@ -140,6 +140,8 @@ bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, boo
|
|||
actualExtent.height = std::max(caps.Capabilites.minImageExtent.height, std::min(caps.Capabilites.maxImageExtent.height, actualExtent.height));
|
||||
if (actualExtent.width == 0 || actualExtent.height == 0)
|
||||
{
|
||||
if (swapchain)
|
||||
vkDestroySwapchainKHR(device->device, swapchain, nullptr);
|
||||
swapchain = VK_NULL_HANDLE;
|
||||
lost = true;
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,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());
|
||||
|
|
|
|||
|
|
@ -306,10 +306,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, key.ShaderKey.UseLevelMesh));
|
||||
|
|
@ -321,7 +326,7 @@ std::unique_ptr<VulkanPipeline> VkRenderPassSetup::CreatePipeline(const VkPipeli
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include <map>
|
||||
|
||||
class VulkanRenderDevice;
|
||||
class GraphicsPipelineBuilder;
|
||||
class ColorBlendAttachmentBuilder;
|
||||
class VkPPShader;
|
||||
class VkPPRenderPassKey;
|
||||
class VkPPRenderPassSetup;
|
||||
|
|
@ -95,7 +95,7 @@ public:
|
|||
int UseVertexData;
|
||||
};
|
||||
|
||||
GraphicsPipelineBuilder& BlendMode(GraphicsPipelineBuilder& builder, const FRenderStyle& style);
|
||||
ColorBlendAttachmentBuilder& BlendMode(ColorBlendAttachmentBuilder& builder, const FRenderStyle& style);
|
||||
|
||||
class VkRenderPassManager
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue