From b52bc313d1d1f908652253b4fdf43ad2ced0e28f Mon Sep 17 00:00:00 2001 From: Alexey Panteleev Date: Tue, 3 Dec 2024 14:58:53 -0800 Subject: [PATCH] Fixed dual-source blending in the forward shading pass on Vulkan. --- include/donut/shaders/binding_helpers.hlsli | 8 ++++++++ shaders/passes/forward_ps.hlsl | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/donut/shaders/binding_helpers.hlsli b/include/donut/shaders/binding_helpers.hlsli index 16c800b..7d36a67 100644 --- a/include/donut/shaders/binding_helpers.hlsli +++ b/include/donut/shaders/binding_helpers.hlsli @@ -29,11 +29,19 @@ #define VK_BINDING(reg,dset) [[vk::binding(reg,dset)]] #define VK_DESCRIPTOR_SET(dset) ,space##dset +// To use dual-source blending on Vulkan, a pixel shader must specify the same Location but different Index +// decorations for two outputs. In HLSL, that can only be achieved with explicit attributes. +// Use on the declarations of pixel shader outputs. +#define VK_LOCATION(loc) [[vk::location(loc)]] +#define VK_LOCATION_INDEX(loc,idx) [[vk::location(loc)]] [[vk::index(idx)]] + #else #define VK_PUSH_CONSTANT #define VK_BINDING(reg,dset) #define VK_DESCRIPTOR_SET(dset) +#define VK_LOCATION(loc) +#define VK_LOCATION_INDEX(loc,idx) #endif diff --git a/shaders/passes/forward_ps.hlsl b/shaders/passes/forward_ps.hlsl index b99f403..972e239 100644 --- a/shaders/passes/forward_ps.hlsl +++ b/shaders/passes/forward_ps.hlsl @@ -71,9 +71,9 @@ void main( in float4 i_position : SV_Position, in SceneVertex i_vtx, in bool i_isFrontFace : SV_IsFrontFace, - out float4 o_color : SV_Target0 + VK_LOCATION_INDEX(0, 0) out float4 o_color : SV_Target0 #if TRANSMISSIVE_MATERIAL - , out float4 o_backgroundBlendFactor : SV_Target1 + , VK_LOCATION_INDEX(0, 1) out float4 o_backgroundBlendFactor : SV_Target1 #endif ) {