diff options
-rw-r--r-- | modules/glslang/SCsub | 9 | ||||
-rw-r--r-- | modules/glslang/glslang_resource_limits.h | 147 | ||||
-rw-r--r-- | modules/glslang/register_types.cpp | 13 | ||||
-rw-r--r-- | thirdparty/README.md | 8 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/CInterface/spirv_c_interface.cpp | 110 | ||||
-rw-r--r-- | thirdparty/glslang/StandAlone/DirStackFileIncluder.h | 149 | ||||
-rw-r--r-- | thirdparty/glslang/StandAlone/ResourceLimits.cpp | 496 | ||||
-rw-r--r-- | thirdparty/glslang/StandAlone/ResourceLimits.h | 57 | ||||
-rw-r--r-- | thirdparty/glslang/glslang/CInterface/glslang_c_interface.cpp | 428 |
9 files changed, 164 insertions, 1253 deletions
diff --git a/modules/glslang/SCsub b/modules/glslang/SCsub index 1954a32697..22ef1b5ea9 100644 --- a/modules/glslang/SCsub +++ b/modules/glslang/SCsub @@ -12,7 +12,6 @@ thirdparty_obj = [] if env["builtin_glslang"]: thirdparty_dir = "#thirdparty/glslang/" thirdparty_sources = [ - "glslang/CInterface/glslang_c_interface.cpp", "glslang/MachineIndependent/attribute.cpp", "glslang/MachineIndependent/Constant.cpp", "glslang/MachineIndependent/glslang_tab.cpp", @@ -44,7 +43,6 @@ if env["builtin_glslang"]: "glslang/GenericCodeGen/CodeGen.cpp", "glslang/GenericCodeGen/Link.cpp", "OGLCompilersDLL/InitializeDll.cpp", - "SPIRV/CInterface/spirv_c_interface.cpp", "SPIRV/disassemble.cpp", "SPIRV/doc.cpp", "SPIRV/GlslangToSpv.cpp", @@ -54,7 +52,6 @@ if env["builtin_glslang"]: "SPIRV/SpvPostProcess.cpp", "SPIRV/SPVRemapper.cpp", "SPIRV/SpvTools.cpp", - "StandAlone/ResourceLimits.cpp", ] if env["platform"] == "windows": @@ -65,10 +62,12 @@ if env["builtin_glslang"]: thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] # Treat glslang headers as system headers to avoid raising warnings. Not supported on MSVC. + # Include `#thirdparty` to workaround mismatch between location of `SPIRV` in library source + # and in installed public headers. if not env.msvc: - env_glslang.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path]) + env_glslang.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path, "-isystem", Dir("#thirdparty").path]) else: - env_glslang.Prepend(CPPPATH=[thirdparty_dir]) + env_glslang.Prepend(CPPPATH=[thirdparty_dir, "#thirdparty"]) env_glslang.Append(CPPDEFINES=["ENABLE_OPT=0"]) diff --git a/modules/glslang/glslang_resource_limits.h b/modules/glslang/glslang_resource_limits.h new file mode 100644 index 0000000000..05390f95ad --- /dev/null +++ b/modules/glslang/glslang_resource_limits.h @@ -0,0 +1,147 @@ +/*************************************************************************/ +/* glslang_resource_limits.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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. */ +/*************************************************************************/ + +#ifndef GLSLANG_RESOURCE_LIMITS_H +#define GLSLANG_RESOURCE_LIMITS_H + +#include <glslang/Include/ResourceLimits.h> + +// Synchronized with upstream glslang/StandAlone/ResourceLimits.cpp which is not +// part of the public API. + +const TBuiltInResource DefaultTBuiltInResource = { + /* .MaxLights = */ 32, + /* .MaxClipPlanes = */ 6, + /* .MaxTextureUnits = */ 32, + /* .MaxTextureCoords = */ 32, + /* .MaxVertexAttribs = */ 64, + /* .MaxVertexUniformComponents = */ 4096, + /* .MaxVaryingFloats = */ 64, + /* .MaxVertexTextureImageUnits = */ 32, + /* .MaxCombinedTextureImageUnits = */ 80, + /* .MaxTextureImageUnits = */ 32, + /* .MaxFragmentUniformComponents = */ 4096, + /* .MaxDrawBuffers = */ 32, + /* .MaxVertexUniformVectors = */ 128, + /* .MaxVaryingVectors = */ 8, + /* .MaxFragmentUniformVectors = */ 16, + /* .MaxVertexOutputVectors = */ 16, + /* .MaxFragmentInputVectors = */ 15, + /* .MinProgramTexelOffset = */ -8, + /* .MaxProgramTexelOffset = */ 7, + /* .MaxClipDistances = */ 8, + /* .MaxComputeWorkGroupCountX = */ 65535, + /* .MaxComputeWorkGroupCountY = */ 65535, + /* .MaxComputeWorkGroupCountZ = */ 65535, + /* .MaxComputeWorkGroupSizeX = */ 1024, + /* .MaxComputeWorkGroupSizeY = */ 1024, + /* .MaxComputeWorkGroupSizeZ = */ 64, + /* .MaxComputeUniformComponents = */ 1024, + /* .MaxComputeTextureImageUnits = */ 16, + /* .MaxComputeImageUniforms = */ 8, + /* .MaxComputeAtomicCounters = */ 8, + /* .MaxComputeAtomicCounterBuffers = */ 1, + /* .MaxVaryingComponents = */ 60, + /* .MaxVertexOutputComponents = */ 64, + /* .MaxGeometryInputComponents = */ 64, + /* .MaxGeometryOutputComponents = */ 128, + /* .MaxFragmentInputComponents = */ 128, + /* .MaxImageUnits = */ 8, + /* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8, + /* .MaxCombinedShaderOutputResources = */ 8, + /* .MaxImageSamples = */ 0, + /* .MaxVertexImageUniforms = */ 0, + /* .MaxTessControlImageUniforms = */ 0, + /* .MaxTessEvaluationImageUniforms = */ 0, + /* .MaxGeometryImageUniforms = */ 0, + /* .MaxFragmentImageUniforms = */ 8, + /* .MaxCombinedImageUniforms = */ 8, + /* .MaxGeometryTextureImageUnits = */ 16, + /* .MaxGeometryOutputVertices = */ 256, + /* .MaxGeometryTotalOutputComponents = */ 1024, + /* .MaxGeometryUniformComponents = */ 1024, + /* .MaxGeometryVaryingComponents = */ 64, + /* .MaxTessControlInputComponents = */ 128, + /* .MaxTessControlOutputComponents = */ 128, + /* .MaxTessControlTextureImageUnits = */ 16, + /* .MaxTessControlUniformComponents = */ 1024, + /* .MaxTessControlTotalOutputComponents = */ 4096, + /* .MaxTessEvaluationInputComponents = */ 128, + /* .MaxTessEvaluationOutputComponents = */ 128, + /* .MaxTessEvaluationTextureImageUnits = */ 16, + /* .MaxTessEvaluationUniformComponents = */ 1024, + /* .MaxTessPatchComponents = */ 120, + /* .MaxPatchVertices = */ 32, + /* .MaxTessGenLevel = */ 64, + /* .MaxViewports = */ 16, + /* .MaxVertexAtomicCounters = */ 0, + /* .MaxTessControlAtomicCounters = */ 0, + /* .MaxTessEvaluationAtomicCounters = */ 0, + /* .MaxGeometryAtomicCounters = */ 0, + /* .MaxFragmentAtomicCounters = */ 8, + /* .MaxCombinedAtomicCounters = */ 8, + /* .MaxAtomicCounterBindings = */ 1, + /* .MaxVertexAtomicCounterBuffers = */ 0, + /* .MaxTessControlAtomicCounterBuffers = */ 0, + /* .MaxTessEvaluationAtomicCounterBuffers = */ 0, + /* .MaxGeometryAtomicCounterBuffers = */ 0, + /* .MaxFragmentAtomicCounterBuffers = */ 1, + /* .MaxCombinedAtomicCounterBuffers = */ 1, + /* .MaxAtomicCounterBufferSize = */ 16384, + /* .MaxTransformFeedbackBuffers = */ 4, + /* .MaxTransformFeedbackInterleavedComponents = */ 64, + /* .MaxCullDistances = */ 8, + /* .MaxCombinedClipAndCullDistances = */ 8, + /* .MaxSamples = */ 4, + /* .maxMeshOutputVerticesNV = */ 256, + /* .maxMeshOutputPrimitivesNV = */ 512, + /* .maxMeshWorkGroupSizeX_NV = */ 32, + /* .maxMeshWorkGroupSizeY_NV = */ 1, + /* .maxMeshWorkGroupSizeZ_NV = */ 1, + /* .maxTaskWorkGroupSizeX_NV = */ 32, + /* .maxTaskWorkGroupSizeY_NV = */ 1, + /* .maxTaskWorkGroupSizeZ_NV = */ 1, + /* .maxMeshViewCountNV = */ 4, + /* .maxDualSourceDrawBuffersEXT = */ 1, + + /* .limits = */ { + /* .nonInductiveForLoops = */ 1, + /* .whileLoops = */ 1, + /* .doWhileLoops = */ 1, + /* .generalUniformIndexing = */ 1, + /* .generalAttributeMatrixVectorIndexing = */ 1, + /* .generalVaryingIndexing = */ 1, + /* .generalSamplerIndexing = */ 1, + /* .generalVariableIndexing = */ 1, + /* .generalConstantMatrixVectorIndexing = */ 1, + } +}; + +#endif // GLSLANG_RESOURCE_LIMITS_H diff --git a/modules/glslang/register_types.cpp b/modules/glslang/register_types.cpp index c67d5ff5ab..8e69ba78c7 100644 --- a/modules/glslang/register_types.cpp +++ b/modules/glslang/register_types.cpp @@ -32,10 +32,11 @@ #include "servers/rendering/rendering_device.h" -#include <SPIRV/GlslangToSpv.h> -#include <StandAlone/ResourceLimits.h> +#include "glslang_resource_limits.h" + #include <glslang/Include/Types.h> #include <glslang/Public/ShaderLang.h> +#include <glslang/SPIRV/GlslangToSpv.h> static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage, const String &p_source_code, RenderingDevice::ShaderLanguage p_language, String *r_error, const RenderingDevice::Capabilities *p_capabilities) { Vector<uint8_t> ret; @@ -129,7 +130,7 @@ static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage std::string pre_processed_code; //preprocess - if (!shader.preprocess(&glslang::DefaultTBuiltInResource, DefaultVersion, ENoProfile, false, false, messages, &pre_processed_code, includer)) { + if (!shader.preprocess(&DefaultTBuiltInResource, DefaultVersion, ENoProfile, false, false, messages, &pre_processed_code, includer)) { if (r_error) { (*r_error) = "Failed pre-process:\n"; (*r_error) += shader.getInfoLog(); @@ -144,7 +145,7 @@ static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage shader.setStrings(&cs_strings, 1); //parse - if (!shader.parse(&glslang::DefaultTBuiltInResource, DefaultVersion, false, messages)) { + if (!shader.parse(&DefaultTBuiltInResource, DefaultVersion, false, messages)) { if (r_error) { (*r_error) = "Failed parse:\n"; (*r_error) += shader.getInfoLog(); @@ -190,8 +191,8 @@ static String _get_cache_key_function_glsl(const RenderingDevice::Capabilities * } void preregister_glslang_types() { - // initialize in case it's not initialized. This is done once per thread - // and it's safe to call multiple times + // Initialize in case it's not initialized. This is done once per thread + // and it's safe to call multiple times. glslang::InitializeProcess(); RenderingDevice::shader_set_compile_to_spirv_function(_compile_shader_glsl); RenderingDevice::shader_set_get_cache_key_function(_get_cache_key_function_glsl); diff --git a/thirdparty/README.md b/thirdparty/README.md index 29bb32df70..239ea940ca 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -175,10 +175,14 @@ Version should be kept in sync with the one of the used Vulkan SDK (see `vulkan` section). Check Vulkan-ValidationLayers at the matching SDK tag for the known good glslang commit: https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/scripts/known_good.json +When updating, also review that our `modules/glslang/glslang_resource_limits.h` +copy of `DefaultTBuiltInResource` is in sync with the one defined upstream in +`StandAlone/ResourceLimits.cpp`. + Files extracted from upstream source: -- `glslang` (except `glslang/HLSL`), `OGLCompilersDLL`, `SPIRV` -- `StandAlone/{DirStackFileIncluder.h,ResourceLimits.{cpp,h}}` +- `glslang` (except `glslang/HLSL`), `OGLCompilersDLL`, `SPIRV`, + minus the `CInterface` folders (depends on `StandAlone`) - Run `cmake . && make` and copy generated `include/glslang/build_info.h` to `glslang/build_info.h` - `LICENSE.txt` diff --git a/thirdparty/glslang/SPIRV/CInterface/spirv_c_interface.cpp b/thirdparty/glslang/SPIRV/CInterface/spirv_c_interface.cpp deleted file mode 100644 index a0790f48f1..0000000000 --- a/thirdparty/glslang/SPIRV/CInterface/spirv_c_interface.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/** - This code is based on the glslang_c_interface implementation by Viktor Latypov -**/ - -/** -BSD 2-Clause License - -Copyright (c) 2019, Viktor Latypov -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**/ - -#include "glslang/Include/glslang_c_interface.h" - -#include "SPIRV/GlslangToSpv.h" -#include "SPIRV/Logger.h" -#include "SPIRV/SpvTools.h" - -typedef struct glslang_program_s { - glslang::TProgram* program; - std::vector<unsigned int> spirv; - std::string loggerMessages; -} glslang_program_t; - -static EShLanguage c_shader_stage(glslang_stage_t stage) -{ - switch (stage) { - case GLSLANG_STAGE_VERTEX: - return EShLangVertex; - case GLSLANG_STAGE_TESSCONTROL: - return EShLangTessControl; - case GLSLANG_STAGE_TESSEVALUATION: - return EShLangTessEvaluation; - case GLSLANG_STAGE_GEOMETRY: - return EShLangGeometry; - case GLSLANG_STAGE_FRAGMENT: - return EShLangFragment; - case GLSLANG_STAGE_COMPUTE: - return EShLangCompute; - case GLSLANG_STAGE_RAYGEN_NV: - return EShLangRayGen; - case GLSLANG_STAGE_INTERSECT_NV: - return EShLangIntersect; - case GLSLANG_STAGE_ANYHIT_NV: - return EShLangAnyHit; - case GLSLANG_STAGE_CLOSESTHIT_NV: - return EShLangClosestHit; - case GLSLANG_STAGE_MISS_NV: - return EShLangMiss; - case GLSLANG_STAGE_CALLABLE_NV: - return EShLangCallable; - case GLSLANG_STAGE_TASK_NV: - return EShLangTaskNV; - case GLSLANG_STAGE_MESH_NV: - return EShLangMeshNV; - default: - break; - } - return EShLangCount; -} - -GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage) -{ - spv::SpvBuildLogger logger; - glslang::SpvOptions spvOptions; - spvOptions.validate = true; - - const glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage)); - - glslang::GlslangToSpv(*intermediate, program->spirv, &logger, &spvOptions); - - program->loggerMessages = logger.getAllMessages(); -} - -GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program) { return program->spirv.size(); } - -GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int* out) -{ - memcpy(out, program->spirv.data(), program->spirv.size() * sizeof(unsigned int)); -} - -GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program) -{ - return program->spirv.data(); -} - -GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program) -{ - return program->loggerMessages.empty() ? nullptr : program->loggerMessages.c_str(); -} diff --git a/thirdparty/glslang/StandAlone/DirStackFileIncluder.h b/thirdparty/glslang/StandAlone/DirStackFileIncluder.h deleted file mode 100644 index 5a33c78fa2..0000000000 --- a/thirdparty/glslang/StandAlone/DirStackFileIncluder.h +++ /dev/null @@ -1,149 +0,0 @@ -// -// Copyright (C) 2002-2005 3Dlabs Inc. Ltd. -// Copyright (C) 2017 Google, Inc. -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// -// Neither the name of 3Dlabs Inc. Ltd. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// - -#pragma once - -#include <vector> -#include <string> -#include <fstream> -#include <algorithm> -#include <set> - -#include "./../glslang/Public/ShaderLang.h" - -// Default include class for normal include convention of search backward -// through the stack of active include paths (for nested includes). -// Can be overridden to customize. -class DirStackFileIncluder : public glslang::TShader::Includer { -public: - DirStackFileIncluder() : externalLocalDirectoryCount(0) { } - - virtual IncludeResult* includeLocal(const char* headerName, - const char* includerName, - size_t inclusionDepth) override - { - return readLocalPath(headerName, includerName, (int)inclusionDepth); - } - - virtual IncludeResult* includeSystem(const char* headerName, - const char* /*includerName*/, - size_t /*inclusionDepth*/) override - { - return readSystemPath(headerName); - } - - // Externally set directories. E.g., from a command-line -I<dir>. - // - Most-recently pushed are checked first. - // - All these are checked after the parse-time stack of local directories - // is checked. - // - This only applies to the "local" form of #include. - // - Makes its own copy of the path. - virtual void pushExternalLocalDirectory(const std::string& dir) - { - directoryStack.push_back(dir); - externalLocalDirectoryCount = (int)directoryStack.size(); - } - - virtual void releaseInclude(IncludeResult* result) override - { - if (result != nullptr) { - delete [] static_cast<tUserDataElement*>(result->userData); - delete result; - } - } - - virtual std::set<std::string> getIncludedFiles() - { - return includedFiles; - } - - virtual ~DirStackFileIncluder() override { } - -protected: - typedef char tUserDataElement; - std::vector<std::string> directoryStack; - int externalLocalDirectoryCount; - std::set<std::string> includedFiles; - - // Search for a valid "local" path based on combining the stack of include - // directories and the nominal name of the header. - virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth) - { - // Discard popped include directories, and - // initialize when at parse-time first level. - directoryStack.resize(depth + externalLocalDirectoryCount); - if (depth == 1) - directoryStack.back() = getDirectory(includerName); - - // Find a directory that works, using a reverse search of the include stack. - for (auto it = directoryStack.rbegin(); it != directoryStack.rend(); ++it) { - std::string path = *it + '/' + headerName; - std::replace(path.begin(), path.end(), '\\', '/'); - std::ifstream file(path, std::ios_base::binary | std::ios_base::ate); - if (file) { - directoryStack.push_back(getDirectory(path)); - includedFiles.insert(path); - return newIncludeResult(path, file, (int)file.tellg()); - } - } - - return nullptr; - } - - // Search for a valid <system> path. - // Not implemented yet; returning nullptr signals failure to find. - virtual IncludeResult* readSystemPath(const char* /*headerName*/) const - { - return nullptr; - } - - // Do actual reading of the file, filling in a new include result. - virtual IncludeResult* newIncludeResult(const std::string& path, std::ifstream& file, int length) const - { - char* content = new tUserDataElement [length]; - file.seekg(0, file.beg); - file.read(content, length); - return new IncludeResult(path, content, length, content); - } - - // If no path markers, return current working directory. - // Otherwise, strip file name and return path leading up to it. - virtual std::string getDirectory(const std::string path) const - { - size_t last = path.find_last_of("/\\"); - return last == std::string::npos ? "." : path.substr(0, last); - } -}; diff --git a/thirdparty/glslang/StandAlone/ResourceLimits.cpp b/thirdparty/glslang/StandAlone/ResourceLimits.cpp deleted file mode 100644 index 7c7f4c4e49..0000000000 --- a/thirdparty/glslang/StandAlone/ResourceLimits.cpp +++ /dev/null @@ -1,496 +0,0 @@ -// -// Copyright (C) 2016 Google, Inc. -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// -// Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -#include <cstdlib> -#include <cstring> -#include <sstream> -#include <cctype> - -#include "ResourceLimits.h" - -namespace glslang { - -const TBuiltInResource DefaultTBuiltInResource = { - /* .MaxLights = */ 32, - /* .MaxClipPlanes = */ 6, - /* .MaxTextureUnits = */ 32, - /* .MaxTextureCoords = */ 32, - /* .MaxVertexAttribs = */ 64, - /* .MaxVertexUniformComponents = */ 4096, - /* .MaxVaryingFloats = */ 64, - /* .MaxVertexTextureImageUnits = */ 32, - /* .MaxCombinedTextureImageUnits = */ 80, - /* .MaxTextureImageUnits = */ 32, - /* .MaxFragmentUniformComponents = */ 4096, - /* .MaxDrawBuffers = */ 32, - /* .MaxVertexUniformVectors = */ 128, - /* .MaxVaryingVectors = */ 8, - /* .MaxFragmentUniformVectors = */ 16, - /* .MaxVertexOutputVectors = */ 16, - /* .MaxFragmentInputVectors = */ 15, - /* .MinProgramTexelOffset = */ -8, - /* .MaxProgramTexelOffset = */ 7, - /* .MaxClipDistances = */ 8, - /* .MaxComputeWorkGroupCountX = */ 65535, - /* .MaxComputeWorkGroupCountY = */ 65535, - /* .MaxComputeWorkGroupCountZ = */ 65535, - /* .MaxComputeWorkGroupSizeX = */ 1024, - /* .MaxComputeWorkGroupSizeY = */ 1024, - /* .MaxComputeWorkGroupSizeZ = */ 64, - /* .MaxComputeUniformComponents = */ 1024, - /* .MaxComputeTextureImageUnits = */ 16, - /* .MaxComputeImageUniforms = */ 8, - /* .MaxComputeAtomicCounters = */ 8, - /* .MaxComputeAtomicCounterBuffers = */ 1, - /* .MaxVaryingComponents = */ 60, - /* .MaxVertexOutputComponents = */ 64, - /* .MaxGeometryInputComponents = */ 64, - /* .MaxGeometryOutputComponents = */ 128, - /* .MaxFragmentInputComponents = */ 128, - /* .MaxImageUnits = */ 8, - /* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8, - /* .MaxCombinedShaderOutputResources = */ 8, - /* .MaxImageSamples = */ 0, - /* .MaxVertexImageUniforms = */ 0, - /* .MaxTessControlImageUniforms = */ 0, - /* .MaxTessEvaluationImageUniforms = */ 0, - /* .MaxGeometryImageUniforms = */ 0, - /* .MaxFragmentImageUniforms = */ 8, - /* .MaxCombinedImageUniforms = */ 8, - /* .MaxGeometryTextureImageUnits = */ 16, - /* .MaxGeometryOutputVertices = */ 256, - /* .MaxGeometryTotalOutputComponents = */ 1024, - /* .MaxGeometryUniformComponents = */ 1024, - /* .MaxGeometryVaryingComponents = */ 64, - /* .MaxTessControlInputComponents = */ 128, - /* .MaxTessControlOutputComponents = */ 128, - /* .MaxTessControlTextureImageUnits = */ 16, - /* .MaxTessControlUniformComponents = */ 1024, - /* .MaxTessControlTotalOutputComponents = */ 4096, - /* .MaxTessEvaluationInputComponents = */ 128, - /* .MaxTessEvaluationOutputComponents = */ 128, - /* .MaxTessEvaluationTextureImageUnits = */ 16, - /* .MaxTessEvaluationUniformComponents = */ 1024, - /* .MaxTessPatchComponents = */ 120, - /* .MaxPatchVertices = */ 32, - /* .MaxTessGenLevel = */ 64, - /* .MaxViewports = */ 16, - /* .MaxVertexAtomicCounters = */ 0, - /* .MaxTessControlAtomicCounters = */ 0, - /* .MaxTessEvaluationAtomicCounters = */ 0, - /* .MaxGeometryAtomicCounters = */ 0, - /* .MaxFragmentAtomicCounters = */ 8, - /* .MaxCombinedAtomicCounters = */ 8, - /* .MaxAtomicCounterBindings = */ 1, - /* .MaxVertexAtomicCounterBuffers = */ 0, - /* .MaxTessControlAtomicCounterBuffers = */ 0, - /* .MaxTessEvaluationAtomicCounterBuffers = */ 0, - /* .MaxGeometryAtomicCounterBuffers = */ 0, - /* .MaxFragmentAtomicCounterBuffers = */ 1, - /* .MaxCombinedAtomicCounterBuffers = */ 1, - /* .MaxAtomicCounterBufferSize = */ 16384, - /* .MaxTransformFeedbackBuffers = */ 4, - /* .MaxTransformFeedbackInterleavedComponents = */ 64, - /* .MaxCullDistances = */ 8, - /* .MaxCombinedClipAndCullDistances = */ 8, - /* .MaxSamples = */ 4, - /* .maxMeshOutputVerticesNV = */ 256, - /* .maxMeshOutputPrimitivesNV = */ 512, - /* .maxMeshWorkGroupSizeX_NV = */ 32, - /* .maxMeshWorkGroupSizeY_NV = */ 1, - /* .maxMeshWorkGroupSizeZ_NV = */ 1, - /* .maxTaskWorkGroupSizeX_NV = */ 32, - /* .maxTaskWorkGroupSizeY_NV = */ 1, - /* .maxTaskWorkGroupSizeZ_NV = */ 1, - /* .maxMeshViewCountNV = */ 4, - /* .maxDualSourceDrawBuffersEXT = */ 1, - - /* .limits = */ { - /* .nonInductiveForLoops = */ 1, - /* .whileLoops = */ 1, - /* .doWhileLoops = */ 1, - /* .generalUniformIndexing = */ 1, - /* .generalAttributeMatrixVectorIndexing = */ 1, - /* .generalVaryingIndexing = */ 1, - /* .generalSamplerIndexing = */ 1, - /* .generalVariableIndexing = */ 1, - /* .generalConstantMatrixVectorIndexing = */ 1, - }}; - -std::string GetDefaultTBuiltInResourceString() -{ - std::ostringstream ostream; - - ostream << "MaxLights " << DefaultTBuiltInResource.maxLights << "\n" - << "MaxClipPlanes " << DefaultTBuiltInResource.maxClipPlanes << "\n" - << "MaxTextureUnits " << DefaultTBuiltInResource.maxTextureUnits << "\n" - << "MaxTextureCoords " << DefaultTBuiltInResource.maxTextureCoords << "\n" - << "MaxVertexAttribs " << DefaultTBuiltInResource.maxVertexAttribs << "\n" - << "MaxVertexUniformComponents " << DefaultTBuiltInResource.maxVertexUniformComponents << "\n" - << "MaxVaryingFloats " << DefaultTBuiltInResource.maxVaryingFloats << "\n" - << "MaxVertexTextureImageUnits " << DefaultTBuiltInResource.maxVertexTextureImageUnits << "\n" - << "MaxCombinedTextureImageUnits " << DefaultTBuiltInResource.maxCombinedTextureImageUnits << "\n" - << "MaxTextureImageUnits " << DefaultTBuiltInResource.maxTextureImageUnits << "\n" - << "MaxFragmentUniformComponents " << DefaultTBuiltInResource.maxFragmentUniformComponents << "\n" - << "MaxDrawBuffers " << DefaultTBuiltInResource.maxDrawBuffers << "\n" - << "MaxVertexUniformVectors " << DefaultTBuiltInResource.maxVertexUniformVectors << "\n" - << "MaxVaryingVectors " << DefaultTBuiltInResource.maxVaryingVectors << "\n" - << "MaxFragmentUniformVectors " << DefaultTBuiltInResource.maxFragmentUniformVectors << "\n" - << "MaxVertexOutputVectors " << DefaultTBuiltInResource.maxVertexOutputVectors << "\n" - << "MaxFragmentInputVectors " << DefaultTBuiltInResource.maxFragmentInputVectors << "\n" - << "MinProgramTexelOffset " << DefaultTBuiltInResource.minProgramTexelOffset << "\n" - << "MaxProgramTexelOffset " << DefaultTBuiltInResource.maxProgramTexelOffset << "\n" - << "MaxClipDistances " << DefaultTBuiltInResource.maxClipDistances << "\n" - << "MaxComputeWorkGroupCountX " << DefaultTBuiltInResource.maxComputeWorkGroupCountX << "\n" - << "MaxComputeWorkGroupCountY " << DefaultTBuiltInResource.maxComputeWorkGroupCountY << "\n" - << "MaxComputeWorkGroupCountZ " << DefaultTBuiltInResource.maxComputeWorkGroupCountZ << "\n" - << "MaxComputeWorkGroupSizeX " << DefaultTBuiltInResource.maxComputeWorkGroupSizeX << "\n" - << "MaxComputeWorkGroupSizeY " << DefaultTBuiltInResource.maxComputeWorkGroupSizeY << "\n" - << "MaxComputeWorkGroupSizeZ " << DefaultTBuiltInResource.maxComputeWorkGroupSizeZ << "\n" - << "MaxComputeUniformComponents " << DefaultTBuiltInResource.maxComputeUniformComponents << "\n" - << "MaxComputeTextureImageUnits " << DefaultTBuiltInResource.maxComputeTextureImageUnits << "\n" - << "MaxComputeImageUniforms " << DefaultTBuiltInResource.maxComputeImageUniforms << "\n" - << "MaxComputeAtomicCounters " << DefaultTBuiltInResource.maxComputeAtomicCounters << "\n" - << "MaxComputeAtomicCounterBuffers " << DefaultTBuiltInResource.maxComputeAtomicCounterBuffers << "\n" - << "MaxVaryingComponents " << DefaultTBuiltInResource.maxVaryingComponents << "\n" - << "MaxVertexOutputComponents " << DefaultTBuiltInResource.maxVertexOutputComponents << "\n" - << "MaxGeometryInputComponents " << DefaultTBuiltInResource.maxGeometryInputComponents << "\n" - << "MaxGeometryOutputComponents " << DefaultTBuiltInResource.maxGeometryOutputComponents << "\n" - << "MaxFragmentInputComponents " << DefaultTBuiltInResource.maxFragmentInputComponents << "\n" - << "MaxImageUnits " << DefaultTBuiltInResource.maxImageUnits << "\n" - << "MaxCombinedImageUnitsAndFragmentOutputs " << DefaultTBuiltInResource.maxCombinedImageUnitsAndFragmentOutputs << "\n" - << "MaxCombinedShaderOutputResources " << DefaultTBuiltInResource.maxCombinedShaderOutputResources << "\n" - << "MaxImageSamples " << DefaultTBuiltInResource.maxImageSamples << "\n" - << "MaxVertexImageUniforms " << DefaultTBuiltInResource.maxVertexImageUniforms << "\n" - << "MaxTessControlImageUniforms " << DefaultTBuiltInResource.maxTessControlImageUniforms << "\n" - << "MaxTessEvaluationImageUniforms " << DefaultTBuiltInResource.maxTessEvaluationImageUniforms << "\n" - << "MaxGeometryImageUniforms " << DefaultTBuiltInResource.maxGeometryImageUniforms << "\n" - << "MaxFragmentImageUniforms " << DefaultTBuiltInResource.maxFragmentImageUniforms << "\n" - << "MaxCombinedImageUniforms " << DefaultTBuiltInResource.maxCombinedImageUniforms << "\n" - << "MaxGeometryTextureImageUnits " << DefaultTBuiltInResource.maxGeometryTextureImageUnits << "\n" - << "MaxGeometryOutputVertices " << DefaultTBuiltInResource.maxGeometryOutputVertices << "\n" - << "MaxGeometryTotalOutputComponents " << DefaultTBuiltInResource.maxGeometryTotalOutputComponents << "\n" - << "MaxGeometryUniformComponents " << DefaultTBuiltInResource.maxGeometryUniformComponents << "\n" - << "MaxGeometryVaryingComponents " << DefaultTBuiltInResource.maxGeometryVaryingComponents << "\n" - << "MaxTessControlInputComponents " << DefaultTBuiltInResource.maxTessControlInputComponents << "\n" - << "MaxTessControlOutputComponents " << DefaultTBuiltInResource.maxTessControlOutputComponents << "\n" - << "MaxTessControlTextureImageUnits " << DefaultTBuiltInResource.maxTessControlTextureImageUnits << "\n" - << "MaxTessControlUniformComponents " << DefaultTBuiltInResource.maxTessControlUniformComponents << "\n" - << "MaxTessControlTotalOutputComponents " << DefaultTBuiltInResource.maxTessControlTotalOutputComponents << "\n" - << "MaxTessEvaluationInputComponents " << DefaultTBuiltInResource.maxTessEvaluationInputComponents << "\n" - << "MaxTessEvaluationOutputComponents " << DefaultTBuiltInResource.maxTessEvaluationOutputComponents << "\n" - << "MaxTessEvaluationTextureImageUnits " << DefaultTBuiltInResource.maxTessEvaluationTextureImageUnits << "\n" - << "MaxTessEvaluationUniformComponents " << DefaultTBuiltInResource.maxTessEvaluationUniformComponents << "\n" - << "MaxTessPatchComponents " << DefaultTBuiltInResource.maxTessPatchComponents << "\n" - << "MaxPatchVertices " << DefaultTBuiltInResource.maxPatchVertices << "\n" - << "MaxTessGenLevel " << DefaultTBuiltInResource.maxTessGenLevel << "\n" - << "MaxViewports " << DefaultTBuiltInResource.maxViewports << "\n" - << "MaxVertexAtomicCounters " << DefaultTBuiltInResource.maxVertexAtomicCounters << "\n" - << "MaxTessControlAtomicCounters " << DefaultTBuiltInResource.maxTessControlAtomicCounters << "\n" - << "MaxTessEvaluationAtomicCounters " << DefaultTBuiltInResource.maxTessEvaluationAtomicCounters << "\n" - << "MaxGeometryAtomicCounters " << DefaultTBuiltInResource.maxGeometryAtomicCounters << "\n" - << "MaxFragmentAtomicCounters " << DefaultTBuiltInResource.maxFragmentAtomicCounters << "\n" - << "MaxCombinedAtomicCounters " << DefaultTBuiltInResource.maxCombinedAtomicCounters << "\n" - << "MaxAtomicCounterBindings " << DefaultTBuiltInResource.maxAtomicCounterBindings << "\n" - << "MaxVertexAtomicCounterBuffers " << DefaultTBuiltInResource.maxVertexAtomicCounterBuffers << "\n" - << "MaxTessControlAtomicCounterBuffers " << DefaultTBuiltInResource.maxTessControlAtomicCounterBuffers << "\n" - << "MaxTessEvaluationAtomicCounterBuffers " << DefaultTBuiltInResource.maxTessEvaluationAtomicCounterBuffers << "\n" - << "MaxGeometryAtomicCounterBuffers " << DefaultTBuiltInResource.maxGeometryAtomicCounterBuffers << "\n" - << "MaxFragmentAtomicCounterBuffers " << DefaultTBuiltInResource.maxFragmentAtomicCounterBuffers << "\n" - << "MaxCombinedAtomicCounterBuffers " << DefaultTBuiltInResource.maxCombinedAtomicCounterBuffers << "\n" - << "MaxAtomicCounterBufferSize " << DefaultTBuiltInResource.maxAtomicCounterBufferSize << "\n" - << "MaxTransformFeedbackBuffers " << DefaultTBuiltInResource.maxTransformFeedbackBuffers << "\n" - << "MaxTransformFeedbackInterleavedComponents " << DefaultTBuiltInResource.maxTransformFeedbackInterleavedComponents << "\n" - << "MaxCullDistances " << DefaultTBuiltInResource.maxCullDistances << "\n" - << "MaxCombinedClipAndCullDistances " << DefaultTBuiltInResource.maxCombinedClipAndCullDistances << "\n" - << "MaxSamples " << DefaultTBuiltInResource.maxSamples << "\n" - << "MaxMeshOutputVerticesNV " << DefaultTBuiltInResource.maxMeshOutputVerticesNV << "\n" - << "MaxMeshOutputPrimitivesNV " << DefaultTBuiltInResource.maxMeshOutputPrimitivesNV << "\n" - << "MaxMeshWorkGroupSizeX_NV " << DefaultTBuiltInResource.maxMeshWorkGroupSizeX_NV << "\n" - << "MaxMeshWorkGroupSizeY_NV " << DefaultTBuiltInResource.maxMeshWorkGroupSizeY_NV << "\n" - << "MaxMeshWorkGroupSizeZ_NV " << DefaultTBuiltInResource.maxMeshWorkGroupSizeZ_NV << "\n" - << "MaxTaskWorkGroupSizeX_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeX_NV << "\n" - << "MaxTaskWorkGroupSizeY_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeY_NV << "\n" - << "MaxTaskWorkGroupSizeZ_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeZ_NV << "\n" - << "MaxMeshViewCountNV " << DefaultTBuiltInResource.maxMeshViewCountNV << "\n" - << "MaxDualSourceDrawBuffersEXT " << DefaultTBuiltInResource.maxDualSourceDrawBuffersEXT << "\n" - << "nonInductiveForLoops " << DefaultTBuiltInResource.limits.nonInductiveForLoops << "\n" - << "whileLoops " << DefaultTBuiltInResource.limits.whileLoops << "\n" - << "doWhileLoops " << DefaultTBuiltInResource.limits.doWhileLoops << "\n" - << "generalUniformIndexing " << DefaultTBuiltInResource.limits.generalUniformIndexing << "\n" - << "generalAttributeMatrixVectorIndexing " << DefaultTBuiltInResource.limits.generalAttributeMatrixVectorIndexing << "\n" - << "generalVaryingIndexing " << DefaultTBuiltInResource.limits.generalVaryingIndexing << "\n" - << "generalSamplerIndexing " << DefaultTBuiltInResource.limits.generalSamplerIndexing << "\n" - << "generalVariableIndexing " << DefaultTBuiltInResource.limits.generalVariableIndexing << "\n" - << "generalConstantMatrixVectorIndexing " << DefaultTBuiltInResource.limits.generalConstantMatrixVectorIndexing << "\n" - ; - - return ostream.str(); -} - -void DecodeResourceLimits(TBuiltInResource* resources, char* config) -{ - static const char* delims = " \t\n\r"; - - size_t pos = 0; - std::string configStr(config); - - while ((pos = configStr.find_first_not_of(delims, pos)) != std::string::npos) { - const size_t token_s = pos; - const size_t token_e = configStr.find_first_of(delims, token_s); - const size_t value_s = configStr.find_first_not_of(delims, token_e); - const size_t value_e = configStr.find_first_of(delims, value_s); - pos = value_e; - - // Faster to use compare(), but prefering readability. - const std::string tokenStr = configStr.substr(token_s, token_e-token_s); - const std::string valueStr = configStr.substr(value_s, value_e-value_s); - - if (value_s == std::string::npos || ! (valueStr[0] == '-' || isdigit(valueStr[0]))) { - printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", - valueStr.c_str()); - return; - } - - const int value = std::atoi(valueStr.c_str()); - - if (tokenStr == "MaxLights") - resources->maxLights = value; - else if (tokenStr == "MaxClipPlanes") - resources->maxClipPlanes = value; - else if (tokenStr == "MaxTextureUnits") - resources->maxTextureUnits = value; - else if (tokenStr == "MaxTextureCoords") - resources->maxTextureCoords = value; - else if (tokenStr == "MaxVertexAttribs") - resources->maxVertexAttribs = value; - else if (tokenStr == "MaxVertexUniformComponents") - resources->maxVertexUniformComponents = value; - else if (tokenStr == "MaxVaryingFloats") - resources->maxVaryingFloats = value; - else if (tokenStr == "MaxVertexTextureImageUnits") - resources->maxVertexTextureImageUnits = value; - else if (tokenStr == "MaxCombinedTextureImageUnits") - resources->maxCombinedTextureImageUnits = value; - else if (tokenStr == "MaxTextureImageUnits") - resources->maxTextureImageUnits = value; - else if (tokenStr == "MaxFragmentUniformComponents") - resources->maxFragmentUniformComponents = value; - else if (tokenStr == "MaxDrawBuffers") - resources->maxDrawBuffers = value; - else if (tokenStr == "MaxVertexUniformVectors") - resources->maxVertexUniformVectors = value; - else if (tokenStr == "MaxVaryingVectors") - resources->maxVaryingVectors = value; - else if (tokenStr == "MaxFragmentUniformVectors") - resources->maxFragmentUniformVectors = value; - else if (tokenStr == "MaxVertexOutputVectors") - resources->maxVertexOutputVectors = value; - else if (tokenStr == "MaxFragmentInputVectors") - resources->maxFragmentInputVectors = value; - else if (tokenStr == "MinProgramTexelOffset") - resources->minProgramTexelOffset = value; - else if (tokenStr == "MaxProgramTexelOffset") - resources->maxProgramTexelOffset = value; - else if (tokenStr == "MaxClipDistances") - resources->maxClipDistances = value; - else if (tokenStr == "MaxComputeWorkGroupCountX") - resources->maxComputeWorkGroupCountX = value; - else if (tokenStr == "MaxComputeWorkGroupCountY") - resources->maxComputeWorkGroupCountY = value; - else if (tokenStr == "MaxComputeWorkGroupCountZ") - resources->maxComputeWorkGroupCountZ = value; - else if (tokenStr == "MaxComputeWorkGroupSizeX") - resources->maxComputeWorkGroupSizeX = value; - else if (tokenStr == "MaxComputeWorkGroupSizeY") - resources->maxComputeWorkGroupSizeY = value; - else if (tokenStr == "MaxComputeWorkGroupSizeZ") - resources->maxComputeWorkGroupSizeZ = value; - else if (tokenStr == "MaxComputeUniformComponents") - resources->maxComputeUniformComponents = value; - else if (tokenStr == "MaxComputeTextureImageUnits") - resources->maxComputeTextureImageUnits = value; - else if (tokenStr == "MaxComputeImageUniforms") - resources->maxComputeImageUniforms = value; - else if (tokenStr == "MaxComputeAtomicCounters") - resources->maxComputeAtomicCounters = value; - else if (tokenStr == "MaxComputeAtomicCounterBuffers") - resources->maxComputeAtomicCounterBuffers = value; - else if (tokenStr == "MaxVaryingComponents") - resources->maxVaryingComponents = value; - else if (tokenStr == "MaxVertexOutputComponents") - resources->maxVertexOutputComponents = value; - else if (tokenStr == "MaxGeometryInputComponents") - resources->maxGeometryInputComponents = value; - else if (tokenStr == "MaxGeometryOutputComponents") - resources->maxGeometryOutputComponents = value; - else if (tokenStr == "MaxFragmentInputComponents") - resources->maxFragmentInputComponents = value; - else if (tokenStr == "MaxImageUnits") - resources->maxImageUnits = value; - else if (tokenStr == "MaxCombinedImageUnitsAndFragmentOutputs") - resources->maxCombinedImageUnitsAndFragmentOutputs = value; - else if (tokenStr == "MaxCombinedShaderOutputResources") - resources->maxCombinedShaderOutputResources = value; - else if (tokenStr == "MaxImageSamples") - resources->maxImageSamples = value; - else if (tokenStr == "MaxVertexImageUniforms") - resources->maxVertexImageUniforms = value; - else if (tokenStr == "MaxTessControlImageUniforms") - resources->maxTessControlImageUniforms = value; - else if (tokenStr == "MaxTessEvaluationImageUniforms") - resources->maxTessEvaluationImageUniforms = value; - else if (tokenStr == "MaxGeometryImageUniforms") - resources->maxGeometryImageUniforms = value; - else if (tokenStr == "MaxFragmentImageUniforms") - resources->maxFragmentImageUniforms = value; - else if (tokenStr == "MaxCombinedImageUniforms") - resources->maxCombinedImageUniforms = value; - else if (tokenStr == "MaxGeometryTextureImageUnits") - resources->maxGeometryTextureImageUnits = value; - else if (tokenStr == "MaxGeometryOutputVertices") - resources->maxGeometryOutputVertices = value; - else if (tokenStr == "MaxGeometryTotalOutputComponents") - resources->maxGeometryTotalOutputComponents = value; - else if (tokenStr == "MaxGeometryUniformComponents") - resources->maxGeometryUniformComponents = value; - else if (tokenStr == "MaxGeometryVaryingComponents") - resources->maxGeometryVaryingComponents = value; - else if (tokenStr == "MaxTessControlInputComponents") - resources->maxTessControlInputComponents = value; - else if (tokenStr == "MaxTessControlOutputComponents") - resources->maxTessControlOutputComponents = value; - else if (tokenStr == "MaxTessControlTextureImageUnits") - resources->maxTessControlTextureImageUnits = value; - else if (tokenStr == "MaxTessControlUniformComponents") - resources->maxTessControlUniformComponents = value; - else if (tokenStr == "MaxTessControlTotalOutputComponents") - resources->maxTessControlTotalOutputComponents = value; - else if (tokenStr == "MaxTessEvaluationInputComponents") - resources->maxTessEvaluationInputComponents = value; - else if (tokenStr == "MaxTessEvaluationOutputComponents") - resources->maxTessEvaluationOutputComponents = value; - else if (tokenStr == "MaxTessEvaluationTextureImageUnits") - resources->maxTessEvaluationTextureImageUnits = value; - else if (tokenStr == "MaxTessEvaluationUniformComponents") - resources->maxTessEvaluationUniformComponents = value; - else if (tokenStr == "MaxTessPatchComponents") - resources->maxTessPatchComponents = value; - else if (tokenStr == "MaxPatchVertices") - resources->maxPatchVertices = value; - else if (tokenStr == "MaxTessGenLevel") - resources->maxTessGenLevel = value; - else if (tokenStr == "MaxViewports") - resources->maxViewports = value; - else if (tokenStr == "MaxVertexAtomicCounters") - resources->maxVertexAtomicCounters = value; - else if (tokenStr == "MaxTessControlAtomicCounters") - resources->maxTessControlAtomicCounters = value; - else if (tokenStr == "MaxTessEvaluationAtomicCounters") - resources->maxTessEvaluationAtomicCounters = value; - else if (tokenStr == "MaxGeometryAtomicCounters") - resources->maxGeometryAtomicCounters = value; - else if (tokenStr == "MaxFragmentAtomicCounters") - resources->maxFragmentAtomicCounters = value; - else if (tokenStr == "MaxCombinedAtomicCounters") - resources->maxCombinedAtomicCounters = value; - else if (tokenStr == "MaxAtomicCounterBindings") - resources->maxAtomicCounterBindings = value; - else if (tokenStr == "MaxVertexAtomicCounterBuffers") - resources->maxVertexAtomicCounterBuffers = value; - else if (tokenStr == "MaxTessControlAtomicCounterBuffers") - resources->maxTessControlAtomicCounterBuffers = value; - else if (tokenStr == "MaxTessEvaluationAtomicCounterBuffers") - resources->maxTessEvaluationAtomicCounterBuffers = value; - else if (tokenStr == "MaxGeometryAtomicCounterBuffers") - resources->maxGeometryAtomicCounterBuffers = value; - else if (tokenStr == "MaxFragmentAtomicCounterBuffers") - resources->maxFragmentAtomicCounterBuffers = value; - else if (tokenStr == "MaxCombinedAtomicCounterBuffers") - resources->maxCombinedAtomicCounterBuffers = value; - else if (tokenStr == "MaxAtomicCounterBufferSize") - resources->maxAtomicCounterBufferSize = value; - else if (tokenStr == "MaxTransformFeedbackBuffers") - resources->maxTransformFeedbackBuffers = value; - else if (tokenStr == "MaxTransformFeedbackInterleavedComponents") - resources->maxTransformFeedbackInterleavedComponents = value; - else if (tokenStr == "MaxCullDistances") - resources->maxCullDistances = value; - else if (tokenStr == "MaxCombinedClipAndCullDistances") - resources->maxCombinedClipAndCullDistances = value; - else if (tokenStr == "MaxSamples") - resources->maxSamples = value; - else if (tokenStr == "MaxMeshOutputVerticesNV") - resources->maxMeshOutputVerticesNV = value; - else if (tokenStr == "MaxMeshOutputPrimitivesNV") - resources->maxMeshOutputPrimitivesNV = value; - else if (tokenStr == "MaxMeshWorkGroupSizeX_NV") - resources->maxMeshWorkGroupSizeX_NV = value; - else if (tokenStr == "MaxMeshWorkGroupSizeY_NV") - resources->maxMeshWorkGroupSizeY_NV = value; - else if (tokenStr == "MaxMeshWorkGroupSizeZ_NV") - resources->maxMeshWorkGroupSizeZ_NV = value; - else if (tokenStr == "MaxTaskWorkGroupSizeX_NV") - resources->maxTaskWorkGroupSizeX_NV = value; - else if (tokenStr == "MaxTaskWorkGroupSizeY_NV") - resources->maxTaskWorkGroupSizeY_NV = value; - else if (tokenStr == "MaxTaskWorkGroupSizeZ_NV") - resources->maxTaskWorkGroupSizeZ_NV = value; - else if (tokenStr == "MaxMeshViewCountNV") - resources->maxMeshViewCountNV = value; - else if (tokenStr == "nonInductiveForLoops") - resources->limits.nonInductiveForLoops = (value != 0); - else if (tokenStr == "whileLoops") - resources->limits.whileLoops = (value != 0); - else if (tokenStr == "doWhileLoops") - resources->limits.doWhileLoops = (value != 0); - else if (tokenStr == "generalUniformIndexing") - resources->limits.generalUniformIndexing = (value != 0); - else if (tokenStr == "generalAttributeMatrixVectorIndexing") - resources->limits.generalAttributeMatrixVectorIndexing = (value != 0); - else if (tokenStr == "generalVaryingIndexing") - resources->limits.generalVaryingIndexing = (value != 0); - else if (tokenStr == "generalSamplerIndexing") - resources->limits.generalSamplerIndexing = (value != 0); - else if (tokenStr == "generalVariableIndexing") - resources->limits.generalVariableIndexing = (value != 0); - else if (tokenStr == "generalConstantMatrixVectorIndexing") - resources->limits.generalConstantMatrixVectorIndexing = (value != 0); - else - printf("Warning: unrecognized limit (%s) in configuration file.\n", tokenStr.c_str()); - - } -} - -} // end namespace glslang diff --git a/thirdparty/glslang/StandAlone/ResourceLimits.h b/thirdparty/glslang/StandAlone/ResourceLimits.h deleted file mode 100644 index 736248eb39..0000000000 --- a/thirdparty/glslang/StandAlone/ResourceLimits.h +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright (C) 2016 Google, Inc. -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// -// Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -#ifndef _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_ -#define _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_ - -#include <string> - -#include "../glslang/Include/ResourceLimits.h" - -namespace glslang { - -// These are the default resources for TBuiltInResources, used for both -// - parsing this string for the case where the user didn't supply one, -// - dumping out a template for user construction of a config file. -extern const TBuiltInResource DefaultTBuiltInResource; - -// Returns the DefaultTBuiltInResource as a human-readable string. -std::string GetDefaultTBuiltInResourceString(); - -// Decodes the resource limits from |config| to |resources|. -void DecodeResourceLimits(TBuiltInResource* resources, char* config); - -} // end namespace glslang - -#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_ diff --git a/thirdparty/glslang/glslang/CInterface/glslang_c_interface.cpp b/thirdparty/glslang/glslang/CInterface/glslang_c_interface.cpp deleted file mode 100644 index 2e04f53ace..0000000000 --- a/thirdparty/glslang/glslang/CInterface/glslang_c_interface.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/** - This code is based on the glslang_c_interface implementation by Viktor Latypov -**/ - -/** -BSD 2-Clause License - -Copyright (c) 2019, Viktor Latypov -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**/ - -#include "glslang/Include/glslang_c_interface.h" - -#include "StandAlone/DirStackFileIncluder.h" -#include "StandAlone/ResourceLimits.h" -#include "glslang/Include/ShHandle.h" - -#include "glslang/Include/ResourceLimits.h" -#include "glslang/MachineIndependent/Versions.h" - -static_assert(int(GLSLANG_STAGE_COUNT) == EShLangCount, ""); -static_assert(int(GLSLANG_STAGE_MASK_COUNT) == EShLanguageMaskCount, ""); -static_assert(int(GLSLANG_SOURCE_COUNT) == glslang::EShSourceCount, ""); -static_assert(int(GLSLANG_CLIENT_COUNT) == glslang::EShClientCount, ""); -static_assert(int(GLSLANG_TARGET_COUNT) == glslang::EShTargetCount, ""); -static_assert(int(GLSLANG_TARGET_CLIENT_VERSION_COUNT) == glslang::EShTargetClientVersionCount, ""); -static_assert(int(GLSLANG_TARGET_LANGUAGE_VERSION_COUNT) == glslang::EShTargetLanguageVersionCount, ""); -static_assert(int(GLSLANG_OPT_LEVEL_COUNT) == EshOptLevelCount, ""); -static_assert(int(GLSLANG_TEX_SAMP_TRANS_COUNT) == EShTexSampTransCount, ""); -static_assert(int(GLSLANG_MSG_COUNT) == EShMsgCount, ""); -static_assert(int(GLSLANG_REFLECTION_COUNT) == EShReflectionCount, ""); -static_assert(int(GLSLANG_PROFILE_COUNT) == EProfileCount, ""); -static_assert(sizeof(glslang_limits_t) == sizeof(TLimits), ""); -static_assert(sizeof(glslang_resource_t) == sizeof(TBuiltInResource), ""); - -typedef struct glslang_shader_s { - glslang::TShader* shader; - std::string preprocessedGLSL; -} glslang_shader_t; - -typedef struct glslang_program_s { - glslang::TProgram* program; - std::vector<unsigned int> spirv; - std::string loggerMessages; -} glslang_program_t; - -/* Wrapper/Adapter for C glsl_include_callbacks_t functions - - This class contains a 'glsl_include_callbacks_t' structure - with C include_local/include_system callback pointers. - - This class implement TShader::Includer interface - by redirecting C++ virtual methods to C callbacks. - - The 'IncludeResult' instances produced by this Includer - contain a reference to glsl_include_result_t C structure - to allow its lifetime management by another C callback - (CallbackIncluder::callbacks::free_include_result) -*/ -class CallbackIncluder : public glslang::TShader::Includer { -public: - /* Wrapper of IncludeResult which stores a glsl_include_result object internally */ - class CallbackIncludeResult : public glslang::TShader::Includer::IncludeResult { - public: - CallbackIncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, - void* userData, glsl_include_result_t* includeResult) - : glslang::TShader::Includer::IncludeResult(headerName, headerData, headerLength, userData), - includeResult(includeResult) - { - } - - virtual ~CallbackIncludeResult() {} - - protected: - friend class CallbackIncluder; - - glsl_include_result_t* includeResult; - }; - -public: - CallbackIncluder(glsl_include_callbacks_t _callbacks, void* _context) : callbacks(_callbacks), context(_context) {} - - virtual ~CallbackIncluder() {} - - virtual IncludeResult* includeSystem(const char* headerName, const char* includerName, - size_t inclusionDepth) override - { - if (this->callbacks.include_system) { - glsl_include_result_t* result = - this->callbacks.include_system(this->context, headerName, includerName, inclusionDepth); - - return new CallbackIncludeResult(std::string(headerName), result->header_data, result->header_length, - nullptr, result); - } - - return glslang::TShader::Includer::includeSystem(headerName, includerName, inclusionDepth); - } - - virtual IncludeResult* includeLocal(const char* headerName, const char* includerName, - size_t inclusionDepth) override - { - if (this->callbacks.include_local) { - glsl_include_result_t* result = - this->callbacks.include_local(this->context, headerName, includerName, inclusionDepth); - - return new CallbackIncludeResult(std::string(headerName), result->header_data, result->header_length, - nullptr, result); - } - - return glslang::TShader::Includer::includeLocal(headerName, includerName, inclusionDepth); - } - - /* This function only calls free_include_result callback - when the IncludeResult instance is allocated by a C function */ - virtual void releaseInclude(IncludeResult* result) override - { - if (result == nullptr) - return; - - if (this->callbacks.free_include_result && (result->userData == nullptr)) { - CallbackIncludeResult* innerResult = static_cast<CallbackIncludeResult*>(result); - /* use internal free() function */ - this->callbacks.free_include_result(this->context, innerResult->includeResult); - /* ignore internal fields of TShader::Includer::IncludeResult */ - delete result; - return; - } - - delete[] static_cast<char*>(result->userData); - delete result; - } - -private: - CallbackIncluder() {} - - /* C callback pointers */ - glsl_include_callbacks_t callbacks; - /* User-defined context */ - void* context; -}; - -GLSLANG_EXPORT int glslang_initialize_process() { return static_cast<int>(glslang::InitializeProcess()); } - -GLSLANG_EXPORT void glslang_finalize_process() { glslang::FinalizeProcess(); } - -static EShLanguage c_shader_stage(glslang_stage_t stage) -{ - switch (stage) { - case GLSLANG_STAGE_VERTEX: - return EShLangVertex; - case GLSLANG_STAGE_TESSCONTROL: - return EShLangTessControl; - case GLSLANG_STAGE_TESSEVALUATION: - return EShLangTessEvaluation; - case GLSLANG_STAGE_GEOMETRY: - return EShLangGeometry; - case GLSLANG_STAGE_FRAGMENT: - return EShLangFragment; - case GLSLANG_STAGE_COMPUTE: - return EShLangCompute; - case GLSLANG_STAGE_RAYGEN_NV: - return EShLangRayGen; - case GLSLANG_STAGE_INTERSECT_NV: - return EShLangIntersect; - case GLSLANG_STAGE_ANYHIT_NV: - return EShLangAnyHit; - case GLSLANG_STAGE_CLOSESTHIT_NV: - return EShLangClosestHit; - case GLSLANG_STAGE_MISS_NV: - return EShLangMiss; - case GLSLANG_STAGE_CALLABLE_NV: - return EShLangCallable; - case GLSLANG_STAGE_TASK_NV: - return EShLangTaskNV; - case GLSLANG_STAGE_MESH_NV: - return EShLangMeshNV; - default: - break; - } - return EShLangCount; -} - -static int c_shader_messages(glslang_messages_t messages) -{ -#define CONVERT_MSG(in, out) \ - if ((messages & in) == in) \ - res |= out; - - int res = 0; - - CONVERT_MSG(GLSLANG_MSG_RELAXED_ERRORS_BIT, EShMsgRelaxedErrors); - CONVERT_MSG(GLSLANG_MSG_SUPPRESS_WARNINGS_BIT, EShMsgSuppressWarnings); - CONVERT_MSG(GLSLANG_MSG_AST_BIT, EShMsgAST); - CONVERT_MSG(GLSLANG_MSG_SPV_RULES_BIT, EShMsgSpvRules); - CONVERT_MSG(GLSLANG_MSG_VULKAN_RULES_BIT, EShMsgVulkanRules); - CONVERT_MSG(GLSLANG_MSG_ONLY_PREPROCESSOR_BIT, EShMsgOnlyPreprocessor); - CONVERT_MSG(GLSLANG_MSG_READ_HLSL_BIT, EShMsgReadHlsl); - CONVERT_MSG(GLSLANG_MSG_CASCADING_ERRORS_BIT, EShMsgCascadingErrors); - CONVERT_MSG(GLSLANG_MSG_KEEP_UNCALLED_BIT, EShMsgKeepUncalled); - CONVERT_MSG(GLSLANG_MSG_HLSL_OFFSETS_BIT, EShMsgHlslOffsets); - CONVERT_MSG(GLSLANG_MSG_DEBUG_INFO_BIT, EShMsgDebugInfo); - CONVERT_MSG(GLSLANG_MSG_HLSL_ENABLE_16BIT_TYPES_BIT, EShMsgHlslEnable16BitTypes); - CONVERT_MSG(GLSLANG_MSG_HLSL_LEGALIZATION_BIT, EShMsgHlslLegalization); - CONVERT_MSG(GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT, EShMsgHlslDX9Compatible); - CONVERT_MSG(GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT, EShMsgBuiltinSymbolTable); - return res; -#undef CONVERT_MSG -} - -static glslang::EShTargetLanguageVersion -c_shader_target_language_version(glslang_target_language_version_t target_language_version) -{ - switch (target_language_version) { - case GLSLANG_TARGET_SPV_1_0: - return glslang::EShTargetSpv_1_0; - case GLSLANG_TARGET_SPV_1_1: - return glslang::EShTargetSpv_1_1; - case GLSLANG_TARGET_SPV_1_2: - return glslang::EShTargetSpv_1_2; - case GLSLANG_TARGET_SPV_1_3: - return glslang::EShTargetSpv_1_3; - case GLSLANG_TARGET_SPV_1_4: - return glslang::EShTargetSpv_1_4; - case GLSLANG_TARGET_SPV_1_5: - return glslang::EShTargetSpv_1_5; - default: - break; - } - return glslang::EShTargetSpv_1_0; -} - -static glslang::EShClient c_shader_client(glslang_client_t client) -{ - switch (client) { - case GLSLANG_CLIENT_VULKAN: - return glslang::EShClientVulkan; - case GLSLANG_CLIENT_OPENGL: - return glslang::EShClientOpenGL; - default: - break; - } - - return glslang::EShClientNone; -} - -static glslang::EShTargetClientVersion c_shader_client_version(glslang_target_client_version_t client_version) -{ - switch (client_version) { - case GLSLANG_TARGET_VULKAN_1_1: - return glslang::EShTargetVulkan_1_1; - case GLSLANG_TARGET_OPENGL_450: - return glslang::EShTargetOpenGL_450; - default: - break; - } - - return glslang::EShTargetVulkan_1_0; -} - -static glslang::EShTargetLanguage c_shader_target_language(glslang_target_language_t target_language) -{ - if (target_language == GLSLANG_TARGET_NONE) - return glslang::EShTargetNone; - - return glslang::EShTargetSpv; -} - -static glslang::EShSource c_shader_source(glslang_source_t source) -{ - switch (source) { - case GLSLANG_SOURCE_GLSL: - return glslang::EShSourceGlsl; - case GLSLANG_SOURCE_HLSL: - return glslang::EShSourceHlsl; - default: - break; - } - - return glslang::EShSourceNone; -} - -static EProfile c_shader_profile(glslang_profile_t profile) -{ - switch (profile) { - case GLSLANG_BAD_PROFILE: - return EBadProfile; - case GLSLANG_NO_PROFILE: - return ENoProfile; - case GLSLANG_CORE_PROFILE: - return ECoreProfile; - case GLSLANG_COMPATIBILITY_PROFILE: - return ECompatibilityProfile; - case GLSLANG_ES_PROFILE: - return EEsProfile; - case GLSLANG_PROFILE_COUNT: // Should not use this - break; - } - - return EProfile(); -} - -GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input) -{ - if (!input || !input->code) { - printf("Error creating shader: null input(%p)/input->code\n", input); - - if (input) - printf("input->code = %p\n", input->code); - - return nullptr; - } - - glslang_shader_t* shader = new glslang_shader_t(); - - shader->shader = new glslang::TShader(c_shader_stage(input->stage)); - shader->shader->setStrings(&input->code, 1); - shader->shader->setEnvInput(c_shader_source(input->language), c_shader_stage(input->stage), - c_shader_client(input->client), input->default_version); - shader->shader->setEnvClient(c_shader_client(input->client), c_shader_client_version(input->client_version)); - shader->shader->setEnvTarget(c_shader_target_language(input->target_language), - c_shader_target_language_version(input->target_language_version)); - - return shader; -} - -GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader) -{ - return shader->preprocessedGLSL.c_str(); -} - -GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input) -{ - DirStackFileIncluder Includer; - /* TODO: use custom callbacks if they are available in 'i->callbacks' */ - return shader->shader->preprocess( - reinterpret_cast<const TBuiltInResource*>(input->resource), - input->default_version, - c_shader_profile(input->default_profile), - input->force_default_version_and_profile != 0, - input->forward_compatible != 0, - (EShMessages)c_shader_messages(input->messages), - &shader->preprocessedGLSL, - Includer - ); -} - -GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input) -{ - const char* preprocessedCStr = shader->preprocessedGLSL.c_str(); - shader->shader->setStrings(&preprocessedCStr, 1); - - return shader->shader->parse( - reinterpret_cast<const TBuiltInResource*>(input->resource), - input->default_version, - input->forward_compatible != 0, - (EShMessages)c_shader_messages(input->messages) - ); -} - -GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader) { return shader->shader->getInfoLog(); } - -GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader) { return shader->shader->getInfoDebugLog(); } - -GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader) -{ - if (!shader) - return; - - delete (shader->shader); - delete (shader); -} - -GLSLANG_EXPORT glslang_program_t* glslang_program_create() -{ - glslang_program_t* p = new glslang_program_t(); - p->program = new glslang::TProgram(); - return p; -} - -GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program) -{ - if (!program) - return; - - delete (program->program); - delete (program); -} - -GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader) -{ - program->program->addShader(shader->shader); -} - -GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages) -{ - return (int)program->program->link((EShMessages)messages); -} - -GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program) -{ - return program->program->getInfoLog(); -} - -GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program) -{ - return program->program->getInfoDebugLog(); -} |