Skip to content

Commit

Permalink
Add GLSLang v12.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
furby-tm committed Oct 19, 2023
1 parent d6c2abc commit c77a056
Show file tree
Hide file tree
Showing 140 changed files with 136,601 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import PackageDescription

let package = Package(
name: "MetaverseKit",
platforms: [
.macOS(.v11),
.visionOS(.v1),
.iOS(.v12),
.tvOS(.v12),
.watchOS(.v4)
],
products: [
.library(
name: "Eigen",
Expand All @@ -25,6 +32,10 @@ let package = Package(
name: "MoltenVK",
targets: ["MoltenVK"]
),
.library(
name: "Glslang",
targets: ["Glslang"]
),
],
targets: [
.target(
Expand Down Expand Up @@ -99,6 +110,28 @@ let package = Package(
]
),

.target(
name: "Glslang",
exclude: [
"include/glslang/CMakeLists.txt",
"include/glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl",
"include/glslang/MachineIndependent/glslang.m4",
"include/glslang/MachineIndependent/glslang.y",
"include/glslang/OSDependent/Unix/CMakeLists.txt",
"include/glslang/OSDependent/Web",
"include/glslang/OSDependent/Windows",
"include/glslang/updateGrammar",
"include/SPIRV/CMakeLists.txt",
],
publicHeadersPath: "include",
cxxSettings: [
.define("ENABLE_HLSL", to: "1")
],
swiftSettings: [
.interoperabilityMode(.Cxx),
]
),

.binaryTarget(
name: "Python",
url: "https://github.com/wabiverse/Kraken/releases/download/1.50a/Python.xcframework.zip",
Expand Down
165 changes: 165 additions & 0 deletions Sources/Glslang/include/OGLCompilersDLL/InitializeDll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// 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.
//

#define SH_EXPORTING

#include <cassert>

#include "InitializeDll.h"
#include "../glslang/Include/InitializeGlobals.h"
#include "../glslang/Public/ShaderLang.h"
#include "../glslang/Include/PoolAlloc.h"

namespace glslang {

OS_TLSIndex ThreadInitializeIndex = OS_INVALID_TLS_INDEX;

// Per-process initialization.
// Needs to be called at least once before parsing, etc. is done.
// Will also do thread initialization for the calling thread; other
// threads will need to do that explicitly.
bool InitProcess()
{
glslang::GetGlobalLock();

if (ThreadInitializeIndex != OS_INVALID_TLS_INDEX) {
//
// Function is re-entrant.
//

glslang::ReleaseGlobalLock();
return true;
}

ThreadInitializeIndex = OS_AllocTLSIndex();

if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitProcess(): Failed to allocate TLS area for init flag");

glslang::ReleaseGlobalLock();
return false;
}

if (! InitializePoolIndex()) {
assert(0 && "InitProcess(): Failed to initialize global pool");

glslang::ReleaseGlobalLock();
return false;
}

if (! InitThread()) {
assert(0 && "InitProcess(): Failed to initialize thread");

glslang::ReleaseGlobalLock();
return false;
}

glslang::ReleaseGlobalLock();
return true;
}

// Per-thread scoped initialization.
// Must be called at least once by each new thread sharing the
// symbol tables, etc., needed to parse.
bool InitThread()
{
//
// This function is re-entrant
//
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitThread(): Process hasn't been initalised.");
return false;
}

if (OS_GetTLSValue(ThreadInitializeIndex) != nullptr)
return true;

if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
assert(0 && "InitThread(): Unable to set init flag.");
return false;
}

glslang::SetThreadPoolAllocator(nullptr);

return true;
}

// Not necessary to call this: InitThread() is reentrant, and the need
// to do per thread tear down has been removed.
//
// This is kept, with memory management removed, to satisfy any exiting
// calls to it that rely on it.
bool DetachThread()
{
bool success = true;

if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
return true;

//
// Function is re-entrant and this thread may not have been initialized.
//
if (OS_GetTLSValue(ThreadInitializeIndex) != nullptr) {
if (!OS_SetTLSValue(ThreadInitializeIndex, nullptr)) {
assert(0 && "DetachThread(): Unable to clear init flag.");
success = false;
}
}

return success;
}

// Not necessary to call this: InitProcess() is reentrant.
//
// This is kept, with memory management removed, to satisfy any exiting
// calls to it that rely on it.
//
// Users of glslang should call shFinalize() or glslang::FinalizeProcess() for
// process-scoped memory tear down.
bool DetachProcess()
{
bool success = true;

if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
return true;

success = DetachThread();

OS_FreeTLSIndex(ThreadInitializeIndex);
ThreadInitializeIndex = OS_INVALID_TLS_INDEX;

return success;
}

} // end namespace glslang
49 changes: 49 additions & 0 deletions Sources/Glslang/include/OGLCompilersDLL/InitializeDll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// 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.
//
#ifndef __INITIALIZEDLL_H
#define __INITIALIZEDLL_H

#include "../glslang/OSDependent/osinclude.h"

namespace glslang {

bool InitProcess();
bool InitThread();
bool DetachThread(); // not called from standalone, perhaps other tools rely on parts of it
bool DetachProcess(); // not called from standalone, perhaps other tools rely on parts of it

} // end namespace glslang

#endif // __INITIALIZEDLL_H

124 changes: 124 additions & 0 deletions Sources/Glslang/include/SPIRV/CInterface/spirv_c_interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
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"

static_assert(sizeof(glslang_spv_options_t) == sizeof(glslang::SpvOptions), "");

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:
return EShLangRayGen;
case GLSLANG_STAGE_INTERSECT:
return EShLangIntersect;
case GLSLANG_STAGE_ANYHIT:
return EShLangAnyHit;
case GLSLANG_STAGE_CLOSESTHIT:
return EShLangClosestHit;
case GLSLANG_STAGE_MISS:
return EShLangMiss;
case GLSLANG_STAGE_CALLABLE:
return EShLangCallable;
case GLSLANG_STAGE_TASK:
return EShLangTask;
case GLSLANG_STAGE_MESH:
return EShLangMesh;
default:
break;
}
return EShLangCount;
}

GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage)
{
glslang_spv_options_t spv_options;
spv_options.generate_debug_info = false;
spv_options.strip_debug_info = false;
spv_options.emit_nonsemantic_shader_debug_info = false;
spv_options.emit_nonsemantic_shader_debug_source = false;
spv_options.disable_optimizer = true;
spv_options.optimize_size = false;
spv_options.disassemble = false;
spv_options.validate = true;

glslang_program_SPIRV_generate_with_options(program, stage, &spv_options);
}

GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options) {
spv::SpvBuildLogger logger;

const glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage));

glslang::GlslangToSpv(*intermediate, program->spirv, &logger, reinterpret_cast<glslang::SpvOptions*>(spv_options));

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();
}
Loading

0 comments on commit c77a056

Please sign in to comment.