You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
As GLSLang seems to be all or nothing, added our own defines
This commit is contained in:
@@ -51,6 +51,7 @@ static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage
|
|||||||
};
|
};
|
||||||
|
|
||||||
int ClientInputSemanticsVersion = 100; // maps to, say, #define VULKAN 100
|
int ClientInputSemanticsVersion = 100; // maps to, say, #define VULKAN 100
|
||||||
|
bool check_subgroup_support = true; // assume we support subgroups
|
||||||
|
|
||||||
glslang::EShTargetClientVersion ClientVersion = glslang::EShTargetVulkan_1_2;
|
glslang::EShTargetClientVersion ClientVersion = glslang::EShTargetVulkan_1_2;
|
||||||
glslang::EShTargetLanguageVersion TargetVersion = glslang::EShTargetSpv_1_5;
|
glslang::EShTargetLanguageVersion TargetVersion = glslang::EShTargetSpv_1_5;
|
||||||
@@ -60,6 +61,7 @@ static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage
|
|||||||
if (p_capabilities->version_major == 1 && p_capabilities->version_minor == 0) {
|
if (p_capabilities->version_major == 1 && p_capabilities->version_minor == 0) {
|
||||||
ClientVersion = glslang::EShTargetVulkan_1_0;
|
ClientVersion = glslang::EShTargetVulkan_1_0;
|
||||||
TargetVersion = glslang::EShTargetSpv_1_0;
|
TargetVersion = glslang::EShTargetSpv_1_0;
|
||||||
|
check_subgroup_support = false; // subgroups are not supported in Vulkan 1.0
|
||||||
} else if (p_capabilities->version_major == 1 && p_capabilities->version_minor == 1) {
|
} else if (p_capabilities->version_major == 1 && p_capabilities->version_minor == 1) {
|
||||||
ClientVersion = glslang::EShTargetVulkan_1_1;
|
ClientVersion = glslang::EShTargetVulkan_1_1;
|
||||||
TargetVersion = glslang::EShTargetSpv_1_3;
|
TargetVersion = glslang::EShTargetSpv_1_3;
|
||||||
@@ -77,12 +79,47 @@ static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage
|
|||||||
glslang::TShader shader(stages[p_stage]);
|
glslang::TShader shader(stages[p_stage]);
|
||||||
CharString cs = p_source_code.ascii();
|
CharString cs = p_source_code.ascii();
|
||||||
const char *cs_strings = cs.get_data();
|
const char *cs_strings = cs.get_data();
|
||||||
|
std::string preamble = "";
|
||||||
|
|
||||||
shader.setStrings(&cs_strings, 1);
|
shader.setStrings(&cs_strings, 1);
|
||||||
shader.setEnvInput(glslang::EShSourceGlsl, stages[p_stage], glslang::EShClientVulkan, ClientInputSemanticsVersion);
|
shader.setEnvInput(glslang::EShSourceGlsl, stages[p_stage], glslang::EShClientVulkan, ClientInputSemanticsVersion);
|
||||||
shader.setEnvClient(glslang::EShClientVulkan, ClientVersion);
|
shader.setEnvClient(glslang::EShClientVulkan, ClientVersion);
|
||||||
shader.setEnvTarget(glslang::EShTargetSpv, TargetVersion);
|
shader.setEnvTarget(glslang::EShTargetSpv, TargetVersion);
|
||||||
|
|
||||||
|
if (check_subgroup_support) {
|
||||||
|
uint32_t stage_bit = 1 << p_stage;
|
||||||
|
|
||||||
|
if ((p_capabilities->subgroup_in_shaders & stage_bit) == stage_bit) {
|
||||||
|
// stage supports subgroups
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_basic 1\n";
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_VOTE_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_vote 1\n";
|
||||||
|
}
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_ARITHMETIC_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_arithmetic 1\n";
|
||||||
|
}
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_BALLOT_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_ballot 1\n";
|
||||||
|
}
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_SHUFFLE_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_shuffle 1\n";
|
||||||
|
}
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_SHUFFLE_RELATIVE_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_shuffle_relative 1\n";
|
||||||
|
}
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_CLUSTERED_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_clustered 1\n";
|
||||||
|
}
|
||||||
|
if (p_capabilities->subgroup_operations & RenderingDevice::SUBGROUP_QUAD_BIT) {
|
||||||
|
preamble += "#define has_GL_KHR_shader_subgroup_quad 1\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preamble != "") {
|
||||||
|
shader.setPreamble(preamble.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
||||||
const int DefaultVersion = 100;
|
const int DefaultVersion = 100;
|
||||||
std::string pre_processed_code;
|
std::string pre_processed_code;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void main() {
|
|||||||
|
|
||||||
VERSION_DEFINES
|
VERSION_DEFINES
|
||||||
|
|
||||||
#if defined(GL_KHR_shader_subgroup_ballot) && defined(GL_KHR_shader_subgroup_arithmetic) && defined(GL_KHR_shader_subgroup_vote)
|
#if defined(has_GL_KHR_shader_subgroup_ballot) && defined(has_GL_KHR_shader_subgroup_arithmetic) && defined(has_GL_KHR_shader_subgroup_vote)
|
||||||
|
|
||||||
#extension GL_KHR_shader_subgroup_ballot : enable
|
#extension GL_KHR_shader_subgroup_ballot : enable
|
||||||
#extension GL_KHR_shader_subgroup_arithmetic : enable
|
#extension GL_KHR_shader_subgroup_arithmetic : enable
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#define MAX_GI_PROBES 8
|
#define MAX_GI_PROBES 8
|
||||||
|
|
||||||
#if defined(GL_KHR_shader_subgroup_ballot) && defined(GL_KHR_shader_subgroup_arithmetic)
|
#if defined(has_GL_KHR_shader_subgroup_ballot) && defined(has_GL_KHR_shader_subgroup_arithmetic)
|
||||||
|
|
||||||
#extension GL_KHR_shader_subgroup_ballot : enable
|
#extension GL_KHR_shader_subgroup_ballot : enable
|
||||||
#extension GL_KHR_shader_subgroup_arithmetic : enable
|
#extension GL_KHR_shader_subgroup_arithmetic : enable
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
VERSION_DEFINES
|
VERSION_DEFINES
|
||||||
|
|
||||||
/* Do not use subgroups here, seems there is not much advantage and causes glitches
|
/* Do not use subgroups here, seems there is not much advantage and causes glitches
|
||||||
|
#if defined(has_GL_KHR_shader_subgroup_ballot) && defined(has_GL_KHR_shader_subgroup_arithmetic)
|
||||||
#extension GL_KHR_shader_subgroup_ballot: enable
|
#extension GL_KHR_shader_subgroup_ballot: enable
|
||||||
#extension GL_KHR_shader_subgroup_arithmetic: enable
|
#extension GL_KHR_shader_subgroup_arithmetic: enable
|
||||||
|
|
||||||
#if defined(GL_KHR_shader_subgroup_ballot) && defined(GL_KHR_shader_subgroup_arithmetic)
|
|
||||||
#define USE_SUBGROUPS
|
#define USE_SUBGROUPS
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user