initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
85
modules/glslang/SCsub
Normal file
85
modules/glslang/SCsub
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_glslang = env_modules.Clone()
|
||||
|
||||
# Thirdparty source files
|
||||
|
||||
thirdparty_obj = []
|
||||
|
||||
if env["builtin_glslang"]:
|
||||
thirdparty_dir = "#thirdparty/glslang/"
|
||||
thirdparty_sources = [
|
||||
"glslang/GenericCodeGen/CodeGen.cpp",
|
||||
"glslang/GenericCodeGen/Link.cpp",
|
||||
"glslang/MachineIndependent/attribute.cpp",
|
||||
"glslang/MachineIndependent/Constant.cpp",
|
||||
"glslang/MachineIndependent/glslang_tab.cpp",
|
||||
"glslang/MachineIndependent/InfoSink.cpp",
|
||||
"glslang/MachineIndependent/Initialize.cpp",
|
||||
"glslang/MachineIndependent/Intermediate.cpp",
|
||||
"glslang/MachineIndependent/intermOut.cpp",
|
||||
"glslang/MachineIndependent/IntermTraverse.cpp",
|
||||
"glslang/MachineIndependent/iomapper.cpp",
|
||||
"glslang/MachineIndependent/limits.cpp",
|
||||
"glslang/MachineIndependent/linkValidate.cpp",
|
||||
"glslang/MachineIndependent/parseConst.cpp",
|
||||
"glslang/MachineIndependent/ParseContextBase.cpp",
|
||||
"glslang/MachineIndependent/ParseHelper.cpp",
|
||||
"glslang/MachineIndependent/PoolAlloc.cpp",
|
||||
"glslang/MachineIndependent/preprocessor/PpAtom.cpp",
|
||||
"glslang/MachineIndependent/preprocessor/PpContext.cpp",
|
||||
"glslang/MachineIndependent/preprocessor/Pp.cpp",
|
||||
"glslang/MachineIndependent/preprocessor/PpScanner.cpp",
|
||||
"glslang/MachineIndependent/preprocessor/PpTokens.cpp",
|
||||
"glslang/MachineIndependent/propagateNoContraction.cpp",
|
||||
"glslang/MachineIndependent/reflection.cpp",
|
||||
"glslang/MachineIndependent/RemoveTree.cpp",
|
||||
"glslang/MachineIndependent/Scan.cpp",
|
||||
"glslang/MachineIndependent/ShaderLang.cpp",
|
||||
"glslang/MachineIndependent/SpirvIntrinsics.cpp",
|
||||
"glslang/MachineIndependent/SymbolTable.cpp",
|
||||
"glslang/MachineIndependent/Versions.cpp",
|
||||
"glslang/ResourceLimits/ResourceLimits.cpp",
|
||||
"SPIRV/disassemble.cpp",
|
||||
"SPIRV/doc.cpp",
|
||||
"SPIRV/GlslangToSpv.cpp",
|
||||
"SPIRV/InReadableOrder.cpp",
|
||||
"SPIRV/Logger.cpp",
|
||||
"SPIRV/SpvBuilder.cpp",
|
||||
"SPIRV/SpvPostProcess.cpp",
|
||||
"SPIRV/SPVRemapper.cpp",
|
||||
"SPIRV/SpvTools.cpp",
|
||||
]
|
||||
|
||||
if env["platform"] == "windows":
|
||||
thirdparty_sources.append("glslang/OSDependent/Windows/ossource.cpp")
|
||||
else:
|
||||
thirdparty_sources.append("glslang/OSDependent/Unix/ossource.cpp")
|
||||
|
||||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
||||
|
||||
# Include `#thirdparty` to workaround mismatch between location of `SPIRV` in library source
|
||||
# and in installed public headers.
|
||||
env_glslang.Prepend(CPPEXTPATH=[thirdparty_dir, "#thirdparty"])
|
||||
|
||||
env_glslang.Append(CPPDEFINES=["ENABLE_OPT=0"])
|
||||
|
||||
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 = []
|
||||
|
||||
env_glslang.add_source_files(module_obj, "*.cpp")
|
||||
env.modules_sources += module_obj
|
||||
|
||||
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
||||
env.Depends(module_obj, thirdparty_obj)
|
8
modules/glslang/config.py
Normal file
8
modules/glslang/config.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def can_build(env, platform):
|
||||
# glslang is only needed when Vulkan, Direct3D 12 or Metal-based renderers are available,
|
||||
# as OpenGL doesn't use glslang.
|
||||
return env["vulkan"] or env["d3d12"] or env["metal"]
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
139
modules/glslang/register_types.cpp
Normal file
139
modules/glslang/register_types.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/**************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
#include "shader_compile.h"
|
||||
|
||||
#include <glslang/Public/ResourceLimits.h>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
|
||||
Vector<uint8_t> compile_glslang_shader(RenderingDeviceCommons::ShaderStage p_stage, const String &p_source_code, RenderingDeviceCommons::ShaderLanguageVersion p_language_version, RenderingDeviceCommons::ShaderSpirvVersion p_spirv_version, String *r_error) {
|
||||
Vector<uint8_t> ret;
|
||||
EShLanguage stages[RenderingDeviceCommons::SHADER_STAGE_MAX] = {
|
||||
EShLangVertex,
|
||||
EShLangFragment,
|
||||
EShLangTessControl,
|
||||
EShLangTessEvaluation,
|
||||
EShLangCompute
|
||||
};
|
||||
|
||||
int ClientInputSemanticsVersion = 100; // maps to, say, #define VULKAN 100
|
||||
|
||||
// The enum values can be converted directly.
|
||||
glslang::EShTargetClientVersion ClientVersion = (glslang::EShTargetClientVersion)p_language_version;
|
||||
glslang::EShTargetLanguageVersion TargetVersion = (glslang::EShTargetLanguageVersion)p_spirv_version;
|
||||
|
||||
glslang::TShader shader(stages[p_stage]);
|
||||
CharString cs = p_source_code.ascii();
|
||||
const char *cs_strings = cs.get_data();
|
||||
std::string preamble = "";
|
||||
|
||||
shader.setStrings(&cs_strings, 1);
|
||||
shader.setEnvInput(glslang::EShSourceGlsl, stages[p_stage], glslang::EShClientVulkan, ClientInputSemanticsVersion);
|
||||
shader.setEnvClient(glslang::EShClientVulkan, ClientVersion);
|
||||
shader.setEnvTarget(glslang::EShTargetSpv, TargetVersion);
|
||||
|
||||
if (!preamble.empty()) {
|
||||
shader.setPreamble(preamble.c_str());
|
||||
}
|
||||
|
||||
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
||||
if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) {
|
||||
messages = (EShMessages)(messages | EShMsgDebugInfo);
|
||||
}
|
||||
const int DefaultVersion = 100;
|
||||
|
||||
//parse
|
||||
if (!shader.parse(GetDefaultResources(), DefaultVersion, false, messages)) {
|
||||
if (r_error) {
|
||||
(*r_error) = "Failed parse:\n";
|
||||
(*r_error) += shader.getInfoLog();
|
||||
(*r_error) += "\n";
|
||||
(*r_error) += shader.getInfoDebugLog();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//link
|
||||
glslang::TProgram program;
|
||||
program.addShader(&shader);
|
||||
|
||||
if (!program.link(messages)) {
|
||||
if (r_error) {
|
||||
(*r_error) = "Failed link:\n";
|
||||
(*r_error) += program.getInfoLog();
|
||||
(*r_error) += "\n";
|
||||
(*r_error) += program.getInfoDebugLog();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> SpirV;
|
||||
spv::SpvBuildLogger logger;
|
||||
glslang::SpvOptions spvOptions;
|
||||
|
||||
if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) {
|
||||
spvOptions.generateDebugInfo = true;
|
||||
spvOptions.emitNonSemanticShaderDebugInfo = true;
|
||||
spvOptions.emitNonSemanticShaderDebugSource = true;
|
||||
}
|
||||
|
||||
glslang::GlslangToSpv(*program.getIntermediate(stages[p_stage]), SpirV, &logger, &spvOptions);
|
||||
|
||||
ret.resize(SpirV.size() * sizeof(uint32_t));
|
||||
{
|
||||
uint8_t *w = ret.ptrw();
|
||||
memcpy(w, &SpirV[0], SpirV.size() * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void initialize_glslang_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_CORE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize in case it's not initialized. This is done once per thread
|
||||
// and it's safe to call multiple times.
|
||||
glslang::InitializeProcess();
|
||||
}
|
||||
|
||||
void uninitialize_glslang_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_CORE) {
|
||||
return;
|
||||
}
|
||||
|
||||
glslang::FinalizeProcess();
|
||||
}
|
38
modules/glslang/register_types.h
Normal file
38
modules/glslang/register_types.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**************************************************************************/
|
||||
/* register_types.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MODULE_GLSLANG_HAS_PREREGISTER
|
||||
|
||||
#include "modules/register_module_types.h"
|
||||
|
||||
void initialize_glslang_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_glslang_module(ModuleInitializationLevel p_level);
|
35
modules/glslang/shader_compile.h
Normal file
35
modules/glslang/shader_compile.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**************************************************************************/
|
||||
/* shader_compile.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "servers/rendering/rendering_device_commons.h"
|
||||
|
||||
Vector<uint8_t> compile_glslang_shader(RenderingDeviceCommons::ShaderStage p_stage, const String &p_source_code, RenderingDeviceCommons::ShaderLanguageVersion p_language_version, RenderingDeviceCommons::ShaderSpirvVersion p_spirv_version, String *r_error);
|
Reference in New Issue
Block a user