Skip to content

Commit

Permalink
Add Vulkan 1.4 support
Browse files Browse the repository at this point in the history
Update Glslang, SPIRV-Tools, SPIRV-Headers dependencies
  • Loading branch information
dneto0 committed Dec 3, 2024
1 parent 082a73b commit 8d9eb88
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 146 deletions.
4 changes: 2 additions & 2 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ vars = {

'abseil_revision': '1315c900e1ddbb08a23e06eeb9a06450052ccb5e',
'effcee_revision': 'd74d33d93043952a99ae7cd7458baf6bc8df1da0',
'glslang_revision': '0099ed6ad09a78b083c93be9369791dd72cf8a33',
'glslang_revision': 'a0995c49ebcaca2c6d3b03efbabf74f3843decdb',
'googletest_revision': '1d17ea141d2c11b8917d2c7d029f1c4e2b9769b2',
're2_revision': '4a8cee3dd3c3d81b6fe8b867811e193d5819df07',
'spirv_headers_revision': '36d5e2ddaa54c70d2f29081510c66f4fc98e5e53',
'spirv_tools_revision': '7c58952fa8ab2fff009cb6710fad34bd1ce7dff3',
'spirv_tools_revision': '3fb52548bc8a68d349d31e21bd4e80e3d953e87c',
}

deps = {
Expand Down
2 changes: 2 additions & 0 deletions glslc/README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ the following:
* `vulkan1.0`: create SPIR-V under Vulkan 1.0 semantics.
* `vulkan1.1`: create SPIR-V under Vulkan 1.1 semantics.
* `vulkan1.2`: create SPIR-V under Vulkan 1.2 semantics.
* `vulkan1.3`: create SPIR-V under Vulkan 1.3 semantics.
* `vulkan1.4`: create SPIR-V under Vulkan 1.4 semantics.
* `opengl`: create SPIR-V under OpenGL 4.5 semantics.
* `opengl4.5`: create SPIR-V under OpenGL 4.5 semantics.

Expand Down
21 changes: 14 additions & 7 deletions glslc/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ An input file of - represents standard input.
vulkan1.1
vulkan1.2
vulkan1.3
vulkan1.4
vulkan # Same as vulkan1.0
opengl4.5
opengl # Same as opengl4.5
Expand All @@ -174,8 +175,9 @@ An input file of - represents standard input.
required to be supported for the target environment.
For example, default for vulkan1.0 is spv1.0, and
the default for vulkan1.1 is spv1.3,
the default for vulkan1.2 is spv1.5.
the default for vulkan1.3 is spv1.6.
the default for vulkan1.2 is spv1.5,
the default for vulkan1.3 is spv1.6,
the default for vulkan1.4 is spv1.6.
Values are:
spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5, spv1.6
--version Display compiler version information.
Expand Down Expand Up @@ -265,8 +267,9 @@ int main(int argc, char** argv) {

// Sets binding base for the given uniform kind. If stage is
// shader_glsl_infer_from_source then set it for all shader stages.
auto set_binding_base = [&compiler](
shaderc_shader_kind stage, shaderc_uniform_kind kind, uint32_t base) {
auto set_binding_base = [&compiler](shaderc_shader_kind stage,
shaderc_uniform_kind kind,
uint32_t base) {
if (stage == shaderc_glsl_infer_from_source)
compiler.options().SetBindingBase(kind, base);
else
Expand Down Expand Up @@ -452,6 +455,9 @@ int main(int argc, char** argv) {
} else if (target_env_str == "vulkan1.3") {
target_env = shaderc_target_env_vulkan;
version = shaderc_env_version_vulkan_1_3;
} else if (target_env_str == "vulkan1.4") {
target_env = shaderc_target_env_vulkan;
version = shaderc_env_version_vulkan_1_4;
} else if (target_env_str == "opengl") {
target_env = shaderc_target_env_opengl;
} else if (target_env_str == "opengl4.5") {
Expand Down Expand Up @@ -675,9 +681,10 @@ int main(int argc, char** argv) {
// from the file name. If current_fshader_stage is specifed to one of
// the forced shader kinds, use that for the following compilation.
input_files.emplace_back(glslc::InputFileSpec{
arg.str(), (current_fshader_stage == shaderc_glsl_infer_from_source
? glslc::DeduceDefaultShaderKindFromFileName(arg)
: current_fshader_stage),
arg.str(),
(current_fshader_stage == shaderc_glsl_infer_from_source
? glslc::DeduceDefaultShaderKindFromFileName(arg)
: current_fshader_stage),
language, current_entry_point_name});
}
}
Expand Down
15 changes: 13 additions & 2 deletions glslc/test/option_target_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,26 @@ class TestTargetEnvEqVulkan1_2WithVulkan1_1ShaderSucceeds(expect.ValidObjectFile
glslc_args = ['--target-env=vulkan1.2', '-c', shader]

@inside_glslc_testsuite('OptionTargetEnv')
class TestTargetEnvEqVulkan1_2WithVulkan1_0ShaderSucceeds(expect.ValidObjectFile1_6):
class TestTargetEnvEqVulkan1_3WithVulkan1_0ShaderSucceeds(expect.ValidObjectFile1_6):
shader = FileShader(vulkan_vertex_shader(), '.vert')
glslc_args = ['--target-env=vulkan1.3', '-c', shader]

@inside_glslc_testsuite('OptionTargetEnv')
class TestTargetEnvEqVulkan1_2WithVulkan1_1ShaderSucceeds(expect.ValidObjectFile1_6):
class TestTargetEnvEqVulkan1_3WithVulkan1_1ShaderSucceeds(expect.ValidObjectFile1_6):
shader = FileShader(vulkan_compute_subgroup_shader(), '.comp')
glslc_args = ['--target-env=vulkan1.3', '-c', shader]

@inside_glslc_testsuite('OptionTargetEnv')
class TestTargetEnvEqVulkan1_4WithVulkan1_0ShaderSucceeds(expect.ValidObjectFile1_6):
shader = FileShader(vulkan_vertex_shader(), '.vert')
glslc_args = ['--target-env=vulkan1.4', '-c', shader]

@inside_glslc_testsuite('OptionTargetEnv')
class TestTargetEnvEqVulkan1_4WithVulkan1_1ShaderSucceeds(expect.ValidObjectFile1_6):
shader = FileShader(vulkan_compute_subgroup_shader(), '.comp')
glslc_args = ['--target-env=vulkan1.4', '-c', shader]


@inside_glslc_testsuite('OptionTargetEnv')
class TestTargetEnvEqOpenGL4_5WithOpenGLShaderSucceeds(expect.ValidObjectFile):
shader = FileShader(opengl_vertex_shader(), '.vert')
Expand Down
6 changes: 4 additions & 2 deletions glslc/test/parameter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class HelpParameters(
vulkan1.1
vulkan1.2
vulkan1.3
vulkan1.4
vulkan # Same as vulkan1.0
opengl4.5
opengl # Same as opengl4.5
Expand All @@ -178,8 +179,9 @@ class HelpParameters(
required to be supported for the target environment.
For example, default for vulkan1.0 is spv1.0, and
the default for vulkan1.1 is spv1.3,
the default for vulkan1.2 is spv1.5.
the default for vulkan1.3 is spv1.6.
the default for vulkan1.2 is spv1.5,
the default for vulkan1.3 is spv1.6,
the default for vulkan1.4 is spv1.6.
Values are:
spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5, spv1.6
--version Display compiler version information.
Expand Down
1 change: 1 addition & 0 deletions libshaderc/include/shaderc/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef enum {
shaderc_env_version_vulkan_1_1 = ((1u << 22) | (1 << 12)),
shaderc_env_version_vulkan_1_2 = ((1u << 22) | (2 << 12)),
shaderc_env_version_vulkan_1_3 = ((1u << 22) | (3 << 12)),
shaderc_env_version_vulkan_1_4 = ((1u << 22) | (4 << 12)),
// For OpenGL, use the number from #version in shaders.
// TODO(dneto): Currently no difference between OpenGL 4.5 and 4.6.
// See glslang/Standalone/Standalone.cpp
Expand Down
27 changes: 15 additions & 12 deletions libshaderc/src/shaderc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class StageDeducer {
public:
explicit StageDeducer(
shaderc_shader_kind kind = shaderc_glsl_infer_from_source)
: kind_(kind), error_(false){}
: kind_(kind), error_(false) {}
// The method that underlying glslang will call to determine the shader stage
// to be used in current compilation. It is called only when there is neither
// forced shader kind (or say stage, in the view of glslang), nor #pragma
Expand Down Expand Up @@ -203,9 +203,9 @@ class InternalFileIncluder : public shaderc_util::CountingIncluder {
void* user_data)
: resolver_(resolver),
result_releaser_(result_releaser),
user_data_(user_data){}
user_data_(user_data) {}
InternalFileIncluder()
: resolver_(nullptr), result_releaser_(nullptr), user_data_(nullptr){}
: resolver_(nullptr), result_releaser_(nullptr), user_data_(nullptr) {}

private:
// Check the validity of the callbacks.
Expand Down Expand Up @@ -311,6 +311,10 @@ shaderc_util::Compiler::TargetEnvVersion GetCompilerTargetEnvVersion(
version_number) {
return Compiler::TargetEnvVersion::Vulkan_1_3;
}
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::Vulkan_1_4) ==
version_number) {
return Compiler::TargetEnvVersion::Vulkan_1_4;
}
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::OpenGL_4_5) ==
version_number) {
return Compiler::TargetEnvVersion::OpenGL_4_5;
Expand Down Expand Up @@ -569,8 +573,8 @@ void shaderc_compile_options_set_vulkan_rules_relaxed(
options->compiler.SetVulkanRulesRelaxed(enable);
}

void shaderc_compile_options_set_invert_y(
shaderc_compile_options_t options, bool enable) {
void shaderc_compile_options_set_invert_y(shaderc_compile_options_t options,
bool enable) {
options->compiler.EnableInvertY(enable);
}

Expand All @@ -587,9 +591,7 @@ shaderc_compiler_t shaderc_compiler_initialize() {
return compiler;
}

void shaderc_compiler_release(shaderc_compiler_t compiler) {
delete compiler;
}
void shaderc_compiler_release(shaderc_compiler_t compiler) { delete compiler; }

namespace {
shaderc_compilation_result_t CompileToSpecifiedOutputType(
Expand Down Expand Up @@ -629,7 +631,8 @@ shaderc_compilation_result_t CompileToSpecifiedOutputType(
std::tie(compilation_succeeded, compilation_output_data,
compilation_output_data_size_in_bytes) =
additional_options->compiler.Compile(
source_string, forced_stage, input_file_name_str, entry_point_name,
source_string, forced_stage, input_file_name_str,
entry_point_name,
// stage_deducer has a flag: error_, which we need to check later.
// We need to make this a reference wrapper, so that std::function
// won't make a copy for this callable object.
Expand All @@ -641,9 +644,9 @@ shaderc_compilation_result_t CompileToSpecifiedOutputType(
std::tie(compilation_succeeded, compilation_output_data,
compilation_output_data_size_in_bytes) =
shaderc_util::Compiler().Compile(
source_string, forced_stage, input_file_name_str, entry_point_name,
std::ref(stage_deducer), includer, output_type, &errors,
&total_warnings, &total_errors);
source_string, forced_stage, input_file_name_str,
entry_point_name, std::ref(stage_deducer), includer, output_type,
&errors, &total_warnings, &total_errors);
}

result->messages = errors.str();
Expand Down
Loading

0 comments on commit 8d9eb88

Please sign in to comment.