Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ opts.Add(BoolVariable("builtin_enet", "Use the built-in ENet library", True))
opts.Add(BoolVariable("builtin_freetype", "Use the built-in FreeType library", True))
opts.Add(BoolVariable("builtin_msdfgen", "Use the built-in MSDFgen library", True))
opts.Add(BoolVariable("builtin_glslang", "Use the built-in glslang library", True))
opts.Add(BoolVariable("builtin_spirv_tools", "Use the built-in SPIR-V Tools library", True))
opts.Add(BoolVariable("builtin_graphite", "Use the built-in Graphite library", True))
opts.Add(BoolVariable("builtin_harfbuzz", "Use the built-in HarfBuzz library", True))
opts.Add(BoolVariable("builtin_sdl", "Use the built-in SDL library", True))
Expand Down
2 changes: 2 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3314,6 +3314,8 @@
</member>
<member name="rendering/shader_compiler/shader_cache/use_zstd_compression" type="bool" setter="" getter="" default="true">
</member>
<member name="rendering/shader_compiler/shader_compilation/optimize" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/shading/overrides/force_lambert_over_burley" type="bool" setter="" getter="" default="false">
If [code]true[/code], uses faster but lower-quality Lambert material lighting model instead of Burley.
</member>
Expand Down
212 changes: 210 additions & 2 deletions modules/glslang/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,212 @@ env_glslang = env_modules.Clone()
# Thirdparty source files

thirdparty_obj = []
enable_shader_optimization = False

if env["builtin_spirv_tools"]:
enable_shader_optimization = True

thirdparty_dir = "#thirdparty/spirv-tools/"
thirdparty_sources = [
"source/assembly_grammar.cpp",
"source/binary.cpp",
"source/diagnostic.cpp",
"source/disassemble.cpp",
"source/enum_string_mapping.cpp",
"source/extensions.cpp",
"source/ext_inst.cpp",
"source/libspirv.cpp",
"source/name_mapper.cpp",
"source/opcode.cpp",
"source/operand.cpp",
"source/parsed_operand.cpp",
"source/pch_source.cpp",
"source/print.cpp",
"source/software_version.cpp",
"source/spirv_endian.cpp",
"source/spirv_fuzzer_options.cpp",
"source/spirv_optimizer_options.cpp",
"source/spirv_reducer_options.cpp",
"source/spirv_target_env.cpp",
"source/spirv_validator_options.cpp",
"source/table.cpp",
"source/text.cpp",
"source/text_handler.cpp",
"source/opt/aggressive_dead_code_elim_pass.cpp",
"source/opt/amd_ext_to_khr.cpp",
"source/opt/analyze_live_input_pass.cpp",
"source/opt/basic_block.cpp",
"source/opt/block_merge_pass.cpp",
"source/opt/block_merge_util.cpp",
"source/opt/build_module.cpp",
"source/opt/ccp_pass.cpp",
"source/opt/cfg.cpp",
"source/opt/cfg_cleanup_pass.cpp",
"source/opt/code_sink.cpp",
"source/opt/combine_access_chains.cpp",
"source/opt/compact_ids_pass.cpp",
"source/opt/composite.cpp",
"source/opt/constants.cpp",
"source/opt/const_folding_rules.cpp",
"source/opt/control_dependence.cpp",
"source/opt/convert_to_half_pass.cpp",
"source/opt/convert_to_sampled_image_pass.cpp",
"source/opt/copy_prop_arrays.cpp",
"source/opt/dataflow.cpp",
"source/opt/dead_branch_elim_pass.cpp",
"source/opt/dead_insert_elim_pass.cpp",
"source/opt/dead_variable_elimination.cpp",
"source/opt/debug_info_manager.cpp",
"source/opt/decoration_manager.cpp",
"source/opt/def_use_manager.cpp",
"source/opt/desc_sroa.cpp",
"source/opt/desc_sroa_util.cpp",
"source/opt/dominator_analysis.cpp",
"source/opt/dominator_tree.cpp",
"source/opt/eliminate_dead_constant_pass.cpp",
"source/opt/eliminate_dead_functions_pass.cpp",
"source/opt/eliminate_dead_functions_util.cpp",
"source/opt/eliminate_dead_io_components_pass.cpp",
"source/opt/eliminate_dead_members_pass.cpp",
"source/opt/eliminate_dead_output_stores_pass.cpp",
"source/opt/feature_manager.cpp",
"source/opt/fix_func_call_arguments.cpp",
"source/opt/fix_storage_class.cpp",
"source/opt/flatten_decoration_pass.cpp",
"source/opt/fold.cpp",
"source/opt/folding_rules.cpp",
"source/opt/fold_spec_constant_op_and_composite_pass.cpp",
"source/opt/freeze_spec_constant_value_pass.cpp",
"source/opt/function.cpp",
"source/opt/graphics_robust_access_pass.cpp",
"source/opt/if_conversion.cpp",
"source/opt/inline_exhaustive_pass.cpp",
"source/opt/inline_opaque_pass.cpp",
"source/opt/inline_pass.cpp",
"source/opt/instruction.cpp",
"source/opt/instruction_list.cpp",
"source/opt/instrument_pass.cpp",
"source/opt/inst_bindless_check_pass.cpp",
"source/opt/inst_buff_addr_check_pass.cpp",
"source/opt/inst_debug_printf_pass.cpp",
"source/opt/interface_var_sroa.cpp",
"source/opt/interp_fixup_pass.cpp",
"source/opt/ir_context.cpp",
"source/opt/ir_loader.cpp",
"source/opt/licm_pass.cpp",
"source/opt/liveness.cpp",
"source/opt/local_access_chain_convert_pass.cpp",
"source/opt/local_redundancy_elimination.cpp",
"source/opt/local_single_block_elim_pass.cpp",
"source/opt/local_single_store_elim_pass.cpp",
"source/opt/loop_dependence.cpp",
"source/opt/loop_dependence_helpers.cpp",
"source/opt/loop_descriptor.cpp",
"source/opt/loop_fission.cpp",
"source/opt/loop_fusion.cpp",
"source/opt/loop_fusion_pass.cpp",
"source/opt/loop_peeling.cpp",
"source/opt/loop_unroller.cpp",
"source/opt/loop_unswitch_pass.cpp",
"source/opt/loop_utils.cpp",
"source/opt/mem_pass.cpp",
"source/opt/merge_return_pass.cpp",
"source/opt/module.cpp",
"source/opt/optimizer.cpp",
"source/opt/pass.cpp",
"source/opt/pass_manager.cpp",
"source/opt/pch_source_opt.cpp",
"source/opt/private_to_local_pass.cpp",
"source/opt/propagator.cpp",
"source/opt/reduce_load_size.cpp",
"source/opt/redundancy_elimination.cpp",
"source/opt/register_pressure.cpp",
"source/opt/relax_float_ops_pass.cpp",
"source/opt/remove_dontinline_pass.cpp",
"source/opt/remove_duplicates_pass.cpp",
"source/opt/remove_unused_interface_variables_pass.cpp",
"source/opt/replace_desc_array_access_using_var_index.cpp",
"source/opt/replace_invalid_opc.cpp",
"source/opt/scalar_analysis.cpp",
"source/opt/scalar_analysis_simplification.cpp",
"source/opt/scalar_replacement_pass.cpp",
"source/opt/set_spec_constant_default_value_pass.cpp",
"source/opt/simplification_pass.cpp",
"source/opt/spread_volatile_semantics.cpp",
"source/opt/ssa_rewrite_pass.cpp",
"source/opt/strength_reduction_pass.cpp",
"source/opt/strip_debug_info_pass.cpp",
"source/opt/strip_nonsemantic_info_pass.cpp",
"source/opt/struct_cfg_analysis.cpp",
"source/opt/types.cpp",
"source/opt/type_manager.cpp",
"source/opt/unify_const_pass.cpp",
"source/opt/upgrade_memory_model.cpp",
"source/opt/value_number_table.cpp",
"source/opt/vector_dce.cpp",
"source/opt/workaround1209.cpp",
"source/opt/wrap_opkill.cpp",
"source/util/bit_vector.cpp",
"source/util/parse_number.cpp",
"source/util/string_utils.cpp",
"source/val/basic_block.cpp",
"source/val/construct.cpp",
"source/val/function.cpp",
"source/val/instruction.cpp",
"source/val/validate.cpp",
"source/val/validate_adjacency.cpp",
"source/val/validate_annotation.cpp",
"source/val/validate_arithmetics.cpp",
"source/val/validate_atomics.cpp",
"source/val/validate_barriers.cpp",
"source/val/validate_bitwise.cpp",
"source/val/validate_builtins.cpp",
"source/val/validate_capability.cpp",
"source/val/validate_cfg.cpp",
"source/val/validate_composites.cpp",
"source/val/validate_constants.cpp",
"source/val/validate_conversion.cpp",
"source/val/validate_debug.cpp",
"source/val/validate_decorations.cpp",
"source/val/validate_derivatives.cpp",
"source/val/validate_execution_limitations.cpp",
"source/val/validate_extensions.cpp",
"source/val/validate_function.cpp",
"source/val/validate_id.cpp",
"source/val/validate_image.cpp",
"source/val/validate_instruction.cpp",
"source/val/validate_interfaces.cpp",
"source/val/validate_layout.cpp",
"source/val/validate_literals.cpp",
"source/val/validate_logicals.cpp",
"source/val/validate_memory.cpp",
"source/val/validate_memory_semantics.cpp",
"source/val/validate_mesh_shading.cpp",
"source/val/validate_misc.cpp",
"source/val/validate_mode_setting.cpp",
"source/val/validate_non_uniform.cpp",
"source/val/validate_primitives.cpp",
"source/val/validate_ray_query.cpp",
"source/val/validate_ray_tracing.cpp",
"source/val/validate_ray_tracing_reorder.cpp",
"source/val/validate_scopes.cpp",
"source/val/validate_small_type_uses.cpp",
"source/val/validate_type.cpp",
"source/val/validation_state.cpp",
]

thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

env_glslang.Prepend(CPPPATH=[thirdparty_dir])
env_glslang.Prepend(CPPPATH=[thirdparty_dir + "include"])

env_thirdparty = env_glslang.Clone()
env_thirdparty.Prepend(CPPPATH=[thirdparty_dir + "include/generated"])
env_thirdparty.Prepend(CPPPATH=["#thirdparty/spirv-headers/include"])
env_thirdparty.Prepend(CPPPATH=["#thirdparty/spirv-headers/include/spirv/unified1"])
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env.modules_sources += thirdparty_obj

if env["builtin_glslang"]:
thirdparty_dir = "#thirdparty/glslang/"
Expand Down Expand Up @@ -66,14 +272,16 @@ if env["builtin_glslang"]:
# and in installed public headers.
env_glslang.Prepend(CPPEXTPATH=[thirdparty_dir, "#thirdparty"])

env_glslang.Append(CPPDEFINES=[("ENABLE_OPT", 0)])
if enable_shader_optimization:
env_glslang.Append(CPPDEFINES=[("ENABLE_OPT", 0)])
else:
env_glslang.Append(CPPDEFINES=[("ENABLE_OPT", 1)])

env_thirdparty = env_glslang.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env.modules_sources += thirdparty_obj


# Godot source files

module_obj = []
Expand Down
8 changes: 8 additions & 0 deletions modules/glslang/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "core/config/engine.h"
#include "shader_compile.h"
#include "core/config/project_settings.h"
#include "servers/rendering/rendering_device.h"

#include <glslang/Public/ResourceLimits.h>
#include <glslang/Public/ShaderLang.h>
Expand Down Expand Up @@ -103,6 +105,12 @@ Vector<uint8_t> compile_glslang_shader(RenderingDeviceCommons::ShaderStage p_sta
spv::SpvBuildLogger logger;
glslang::SpvOptions spvOptions;

bool optimize = GLOBAL_GET("rendering/shader_compiler/shader_compilation/optimize");
if (optimize) {
spvOptions.disableOptimizer = false;
spvOptions.optimizeSize = true;
}

if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) {
spvOptions.generateDebugInfo = true;
spvOptions.emitNonSemanticShaderDebugInfo = true;
Expand Down
2 changes: 0 additions & 2 deletions servers/rendering/renderer_rd/environment/gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,6 @@ void GI::SDFGI::render_region(Ref<RenderSceneBuffersRD> p_render_buffers, int p_
uint32_t cascade_half_size = cascade_size >> 1;
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, gi->sdfgi_shader.preprocess_pipeline[SDFGIShader::PRE_PROCESS_JUMP_FLOOD_INITIALIZE_HALF]);
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, sdf_initialize_half_uniform_set, 0);
RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(SDFGIShader::PreprocessPushConstant));
RD::get_singleton()->compute_list_dispatch_threads(compute_list, cascade_half_size, cascade_half_size, cascade_half_size);
RD::get_singleton()->compute_list_add_barrier(compute_list);

Expand Down Expand Up @@ -2223,7 +2222,6 @@ void GI::SDFGI::render_region(Ref<RenderSceneBuffersRD> p_render_buffers, int p_

RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, gi->sdfgi_shader.preprocess_pipeline[SDFGIShader::PRE_PROCESS_JUMP_FLOOD_UPSCALE]);
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, sdf_upscale_uniform_set, 0);
RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(SDFGIShader::PreprocessPushConstant));
RD::get_singleton()->compute_list_dispatch_threads(compute_list, cascade_size, cascade_size, cascade_size);
RD::get_singleton()->compute_list_add_barrier(compute_list);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ layout(r16ui, set = 0, binding = 2) uniform restrict readonly uimage3D src_occlu

#endif

#if !defined(MODE_INITIALIZE_JUMP_FLOOD_HALF) && !defined(MODE_UPSCALE_JUMP_FLOOD)

layout(push_constant, std430) uniform Params {
ivec3 scroll;

Expand All @@ -170,6 +172,8 @@ layout(push_constant, std430) uniform Params {
}
params;

#endif

void main() {
#ifdef MODE_SCROLL

Expand Down
1 change: 1 addition & 0 deletions servers/rendering_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,7 @@ void RenderingServer::init() {
// Number of commands that can be drawn per frame.
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/gl_compatibility/item_buffer_size", PROPERTY_HINT_RANGE, "128,1048576,1"), 16384);

GLOBAL_DEF_RST("rendering/shader_compiler/shader_compilation/optimize", false);
GLOBAL_DEF("rendering/shader_compiler/shader_cache/enabled", true);
GLOBAL_DEF("rendering/shader_compiler/shader_cache/compress", true);
GLOBAL_DEF("rendering/shader_compiler/shader_cache/use_zstd_compression", true);
Expand Down
4 changes: 4 additions & 0 deletions thirdparty/glslang/SPIRV/SpvTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector

spvtools::OptimizerOptions spvOptOptions;
optimizer.SetTargetEnv(MapToSpirvToolsEnv(intermediate.getSpv(), logger));
// -- GODOT start --
spvOptOptions.set_preserve_bindings(true);
spvOptOptions.set_preserve_spec_constants(true);
// -- GODOT end --
spvOptOptions.set_run_validator(false); // The validator may run as a separate step later on
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
}
Expand Down
Loading
Loading