diff --git a/MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp b/MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp index d420c7b5..934727a1 100644 --- a/MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp @@ -116,7 +116,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { .TargetGLVersion = {3, 3, 0}, // Target OpenGL Version .TargetGLSLVersion = {4, 6, 0}, // Target Shading Language Version .Extensions = {V_OpenGL30, V_OpenGL31, V_OpenGL32, // OpenGL Extensions - V_OpenGL33}, + V_OpenGL33, E_GL_ARB_draw_buffers_blend}, .IsCompatibilityProfile = false // Is Compatibility Profile }, .StaticBackendCapability = {.AllowVSOnlyPrograms = false} // Backend Capability diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.cpp index de4e9706..7c58f70d 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.cpp @@ -27,12 +27,12 @@ namespace MobileGL::MG_Backend::DirectVulkan { XXHASH_VERIFY(XXH64_update(m_hashState, &payload.depthTestEnable, sizeof(payload.depthTestEnable))); XXHASH_VERIFY(XXH64_update(m_hashState, &payload.depthWriteEnable, sizeof(payload.depthWriteEnable))); XXHASH_VERIFY(XXH64_update(m_hashState, &payload.depthCompareOp, sizeof(payload.depthCompareOp))); - XXHASH_VERIFY(XXH64_update(m_hashState, &payload.blendEnable, sizeof(payload.blendEnable))); - XXHASH_VERIFY(XXH64_update(m_hashState, &payload.srcColorBlendFactor, sizeof(payload.srcColorBlendFactor))); - XXHASH_VERIFY(XXH64_update(m_hashState, &payload.dstColorBlendFactor, sizeof(payload.dstColorBlendFactor))); - XXHASH_VERIFY(XXH64_update(m_hashState, &payload.srcAlphaBlendFactor, sizeof(payload.srcAlphaBlendFactor))); - XXHASH_VERIFY(XXH64_update(m_hashState, &payload.dstAlphaBlendFactor, sizeof(payload.dstAlphaBlendFactor))); - XXHASH_VERIFY(XXH64_update(m_hashState, &payload.colorWriteMask, sizeof(payload.colorWriteMask))); + if (payload.colorAttachmentCount > 0) { + XXHASH_VERIFY(XXH64_update( + m_hashState, + payload.colorBlendAttachments.data(), + sizeof(payload.colorBlendAttachments[0]) * payload.colorAttachmentCount)); + } return XXH64_digest(m_hashState); } @@ -62,7 +62,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { MOBILEGL_ASSERT(payload.vertexInputState != nullptr, "PipelineFactory: vertexInputState is null"); MOBILEGL_ASSERT(payload.pipelineLayout != VK_NULL_HANDLE, "PipelineFactory: pipelineLayout is null"); MOBILEGL_ASSERT(payload.renderPass != VK_NULL_HANDLE, "PipelineFactory: renderPass is null"); - MOBILEGL_ASSERT(payload.colorAttachmentCount <= 32, + MOBILEGL_ASSERT(payload.colorAttachmentCount <= PipelineCreatePayload::kMaxColorAttachments, "PipelineFactory: colorAttachmentCount=%u is unexpectedly large", payload.colorAttachmentCount); MGLOG_D("PipelineFactory::CreatePipeline: programHash=0x%llx vertexInputHash=0x%llx colorAttachmentCount=%u subpass=%u", @@ -104,17 +104,10 @@ namespace MobileGL::MG_Backend::DirectVulkan { depthStencil.depthBoundsTestEnable = VK_FALSE; depthStencil.stencilTestEnable = VK_FALSE; - VkPipelineColorBlendAttachmentState colorAttachTemplate{}; - colorAttachTemplate.colorWriteMask = payload.colorWriteMask; - colorAttachTemplate.blendEnable = payload.blendEnable ? VK_TRUE : VK_FALSE; - colorAttachTemplate.srcColorBlendFactor = payload.srcColorBlendFactor; - colorAttachTemplate.dstColorBlendFactor = payload.dstColorBlendFactor; - colorAttachTemplate.colorBlendOp = VK_BLEND_OP_ADD; - colorAttachTemplate.srcAlphaBlendFactor = payload.srcAlphaBlendFactor; - colorAttachTemplate.dstAlphaBlendFactor = payload.dstAlphaBlendFactor; - colorAttachTemplate.alphaBlendOp = VK_BLEND_OP_ADD; - Vector colorAttachments(payload.colorAttachmentCount, - colorAttachTemplate); + Vector colorAttachments(payload.colorAttachmentCount); + for (Uint32 i = 0; i < payload.colorAttachmentCount; ++i) { + colorAttachments[i] = payload.colorBlendAttachments[i]; + } VkPipelineColorBlendStateCreateInfo blend{VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO}; blend.attachmentCount = payload.colorAttachmentCount; blend.pAttachments = colorAttachments.empty() ? nullptr : colorAttachments.data(); diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.h b/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.h index 1c86e608..6c3d41fb 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.h +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/PipelineFactory.h @@ -10,6 +10,7 @@ #include "Config.h" #include "../VkIncludes.h" +#include "MG_State/GLState/FramebufferState/FramebufferObject.h" #include namespace MobileGL::MG_Backend::DirectVulkan { @@ -18,6 +19,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { using HashType = Uint64; struct PipelineCreatePayload { + static constexpr Uint32 kMaxColorAttachments = MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS; + HashType programHash = 0; HashType vertexInputHash = 0; VkPipelineLayout pipelineLayout = VK_NULL_HANDLE; @@ -30,14 +33,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { Bool depthTestEnable = false; Bool depthWriteEnable = false; VkCompareOp depthCompareOp = VK_COMPARE_OP_ALWAYS; - Bool blendEnable = false; - VkBlendFactor srcColorBlendFactor = VK_BLEND_FACTOR_ONE; - VkBlendFactor dstColorBlendFactor = VK_BLEND_FACTOR_ZERO; - VkBlendFactor srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - VkBlendFactor dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - VkColorComponentFlags colorWriteMask = - VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + Array colorBlendAttachments{}; const Vector* stages = nullptr; const VkPipelineVertexInputStateCreateInfo* vertexInputState = nullptr; };