diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index 5a4a1c77a..69dd0134d 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -338,6 +338,7 @@ void GPUContextVulkan::BeginRenderPass() framebufferKey.AttachmentCount = _rtCount; RenderTargetLayoutVulkan layout; layout.RTsCount = _rtCount; + layout.BlendEnable = _currentState && _currentState->BlendEnable; layout.DepthFormat = _rtDepth ? _rtDepth->GetFormat() : PixelFormat::Unknown; for (int32 i = 0; i < GPU_MAX_RT_BINDED; i++) { diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index 5cae6a7ff..9ca399dad 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -427,6 +427,7 @@ uint32 GetHash(const RenderTargetLayoutVulkan& key) uint32 hash = (int32)key.MSAA * 11; CombineHash(hash, (uint32)key.ReadDepth); CombineHash(hash, (uint32)key.WriteDepth); + CombineHash(hash, (uint32)key.BlendEnable); CombineHash(hash, (uint32)key.DepthFormat * 93473262); CombineHash(hash, key.RTsCount * 136); CombineHash(hash, key.Extent.width); @@ -505,8 +506,7 @@ RenderPassVulkan::RenderPassVulkan(GPUDeviceVulkan* device, const RenderTargetLa attachment.flags = 0; attachment.format = RenderToolsVulkan::ToVulkanFormat(layout.RTVsFormats[i]); attachment.samples = (VkSampleCountFlagBits)layout.MSAA; - //attachment.loadOp = currentBlendDesc->BlendEnable ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_DONT_CARE; // TODO: Only if any destination blend? - attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; // TODO: only load when using blend mode + attachment.loadOp = layout.BlendEnable ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h index 1868999b7..882c803b5 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h @@ -235,6 +235,7 @@ public: MSAALevel MSAA; bool ReadDepth; bool WriteDepth; + bool BlendEnable; PixelFormat DepthFormat; PixelFormat RTVsFormats[GPU_MAX_RT_BINDED]; VkExtent2D Extent; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp index 16043b0c7..cdb76e1cf 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp @@ -308,6 +308,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc) _desc.pRasterizationState = &_descRasterization; // Color Blend State + BlendEnable = desc.BlendMode.BlendEnable; RenderToolsVulkan::ZeroStruct(_descColorBlend, VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO); { auto& blend = _descColorBlendAttachments[0]; @@ -321,9 +322,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc) blend.colorWriteMask = (VkColorComponentFlags)desc.BlendMode.RenderTargetWriteMask; } for (int32 i = 1; i < GPU_MAX_RT_BINDED; i++) - { _descColorBlendAttachments[i] = _descColorBlendAttachments[i - 1]; - } _descColorBlend.pAttachments = _descColorBlendAttachments; _descColorBlend.blendConstants[0] = 0.0f; _descColorBlend.blendConstants[1] = 0.0f; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h index 53b3bb7af..29b71a3bc 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h @@ -135,6 +135,8 @@ public: /// uint32 UsedStagesMask; + bool BlendEnable; + /// /// The bitmask of stages that have descriptors. ///