Vulkan: Enable subgroupShuffle.

It is used as workaround for the missing subgroupBroadcastDynamicId flag on SPIR-V < 1.5.
This commit is contained in:
degasus 2023-03-24 21:42:43 +01:00
parent 1571098783
commit 196c684ac1
3 changed files with 14 additions and 3 deletions

View File

@ -21,6 +21,14 @@ const uint UNROLL_SIMD = 3; // max MAX_CHARS / 32
// #undef SUPPORTS_SUBGROUP_REDUCTION // #undef SUPPORTS_SUBGROUP_REDUCTION
#ifdef API_VULKAN
// By default, subgroupBroadcast only supports compile time constants as index.
// However we need an uniform instead. This is always supported in OpenGL,
// but in Vulkan only in SPIR-V >= 1.5.
// So fall back to subgroupShuffle on Vulkan instead.
#define subgroupBroadcast subgroupShuffle
#endif
/* /*
The header-only font The header-only font
We have 96 (ASCII) characters, each of them is 12 pixels high and 8 pixels wide. We have 96 (ASCII) characters, each of them is 12 pixels high and 8 pixels wide.

View File

@ -79,6 +79,7 @@ static const char SUBGROUP_HELPER_HEADER[] = R"(
#extension GL_KHR_shader_subgroup_basic : enable #extension GL_KHR_shader_subgroup_basic : enable
#extension GL_KHR_shader_subgroup_arithmetic : enable #extension GL_KHR_shader_subgroup_arithmetic : enable
#extension GL_KHR_shader_subgroup_ballot : enable #extension GL_KHR_shader_subgroup_ballot : enable
#extension GL_KHR_shader_subgroup_shuffle : enable
#define SUPPORTS_SUBGROUP_REDUCTION 1 #define SUPPORTS_SUBGROUP_REDUCTION 1
#define IS_HELPER_INVOCATION gl_HelperInvocation #define IS_HELPER_INVOCATION gl_HelperInvocation

View File

@ -981,9 +981,11 @@ void VulkanContext::PopulateShaderSubgroupSupport()
// We require basic ops (for gl_SubgroupInvocationID), ballot (for subgroupBallot, // We require basic ops (for gl_SubgroupInvocationID), ballot (for subgroupBallot,
// subgroupBallotFindLSB), and arithmetic (for subgroupMin/subgroupMax). // subgroupBallotFindLSB), and arithmetic (for subgroupMin/subgroupMax).
constexpr VkSubgroupFeatureFlags required_operations = VK_SUBGROUP_FEATURE_BASIC_BIT | // Shuffle is enabled as a workaround until SPIR-V >= 1.5 is enabled with broadcast(uniform)
VK_SUBGROUP_FEATURE_ARITHMETIC_BIT | // support.
VK_SUBGROUP_FEATURE_BALLOT_BIT; constexpr VkSubgroupFeatureFlags required_operations =
VK_SUBGROUP_FEATURE_BASIC_BIT | VK_SUBGROUP_FEATURE_ARITHMETIC_BIT |
VK_SUBGROUP_FEATURE_BALLOT_BIT | VK_SUBGROUP_FEATURE_SHUFFLE_BIT;
m_supports_shader_subgroup_operations = m_supports_shader_subgroup_operations =
(subgroup_properties.supportedOperations & required_operations) == required_operations && (subgroup_properties.supportedOperations & required_operations) == required_operations &&
subgroup_properties.supportedStages & VK_SHADER_STAGE_FRAGMENT_BIT && subgroup_properties.supportedStages & VK_SHADER_STAGE_FRAGMENT_BIT &&