From fcf83dbf9effab3bd98bad2b83b2468b7eb05cfd Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 9 Jun 2017 11:34:21 -0700 Subject: Initial import of code. --- tools/glslang/glslang.cpp | 175 +++++++++++++++++++++++ tools/glslang/glslang.h | 23 ++++ tools/glslang/glslang.vcxproj | 237 +++++++++++++++++++++++++++++++ tools/glslang/glslang.vcxproj.filters | 253 ++++++++++++++++++++++++++++++++++ 4 files changed, 688 insertions(+) create mode 100644 tools/glslang/glslang.cpp create mode 100644 tools/glslang/glslang.h create mode 100644 tools/glslang/glslang.vcxproj create mode 100644 tools/glslang/glslang.vcxproj.filters (limited to 'tools/glslang') diff --git a/tools/glslang/glslang.cpp b/tools/glslang/glslang.cpp new file mode 100644 index 000000000..cf563faff --- /dev/null +++ b/tools/glslang/glslang.cpp @@ -0,0 +1,175 @@ +// glslang.cpp +#include "glslang.h" + + +#include "StandAlone/ResourceLimits.h" +#include "StandAlone/Worklist.h" +#include "glslang/Include/ShHandle.h" +#include "glslang/Include/revision.h" +#include "glslang/Public/ShaderLang.h" +#include "SPIRV/GlslangToSpv.h" +#include "SPIRV/GLSL.std.450.h" +#include "SPIRV/doc.h" +#include "SPIRV/disassemble.h" + +#include "../../Slang.h" + +#if 0 +#include +#include +#include +#include +#include +#include +#include +#endif + +#ifdef _WIN32 +#include +#endif + +#include + +// This is a wrapper to allow us to run the `glslang` compiler +// in a controlled fashion. + +#define UNLIMITED 9999 + +static TBuiltInResource gResources = +{ + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, UNLIMITED, + UNLIMITED, UNLIMITED, UNLIMITED, + + { true, true, true, true, true, true, true, true, true, } +}; + +static void dump( + std::string const& text, + glslang_OutputFunc outputFunc, + void* outputUserData, + FILE* fallbackStream) +{ + if( outputFunc ) + { + outputFunc(text.c_str(), outputUserData); + } + else + { + fprintf(fallbackStream, "%s", text.c_str()); + + // also output it for debug purposes + OutputDebugStringA(text.c_str()); + } +} + +static void dumpDiagnostics( + glslang_CompileRequest* request, + std::string const& log) +{ + dump(log, request->diagnosticFunc, request->diagnosticUserData, stderr); +} + +extern "C" +_declspec(dllexport) +int glslang_compile(glslang_CompileRequest* request) +{ + glslang::InitializeProcess(); + + EShLanguage glslangStage; + switch( request->slangStage ) + { +#define CASE(SP, GL) case SLANG_STAGE_##SP: glslangStage = EShLang##GL; break + CASE(VERTEX, Vertex); + CASE(FRAGMENT, Fragment); + CASE(GEOMETRY, Geometry); + CASE(HULL, TessControl); + CASE(DOMAIN, TessEvaluation); + CASE(COMPUTE, Compute); + +#undef CASE + + default: + return 1; + } + + // TODO: compute glslang stage to use + + glslang::TShader* shader = new glslang::TShader(glslangStage); + auto shaderPtr = std::unique_ptr(shader); + + glslang::TProgram* program = new glslang::TProgram(); + auto programPtr = std::unique_ptr(program); + + int sourceTextLength = (int) strlen(request->sourceText); + + shader->setPreamble("#extension GL_GOOGLE_cpp_style_line_directive : require\n"); + + shader->setStringsWithLengthsAndNames( + &request->sourceText, + &sourceTextLength, + &request->sourcePath, + 1); + + // Note: this seems required to get past a bug where + // glslang complains about a declaration of `out gl_PerVertex` + // that it (seemingly) *should* allow according to the GLSL-for-Vulkan + // extension. + shader->setAutoMapLocations(true); + + // Let's auto-map the bindings too, just because we can + shader->setAutoMapBindings(true); + + EShMessages messages = EShMessages(EShMsgSpvRules | EShMsgVulkanRules); + + if( !shader->parse(&gResources, 110, false, messages) ) + { + dumpDiagnostics(request, shader->getInfoLog()); + return 1; + } + + program->addShader(shader); + + if( !program->link(messages) ) + { + dumpDiagnostics(request, program->getInfoLog()); + return 1; + } + + if( !program->mapIO() ) + { + dumpDiagnostics(request, program->getInfoLog()); + return 1; + } + + for(int stage = 0; stage < EShLangCount; ++stage) + { + auto stageIntermediate = program->getIntermediate((EShLanguage)stage); + if(!stageIntermediate) + continue; + + std::vector spirv; + std::string warningsErrors; + spv::SpvBuildLogger logger; + glslang::GlslangToSpv(*stageIntermediate, spirv, &logger); + + dumpDiagnostics(request, logger.getAllMessages()); + + std::stringstream spirvAsmStream; + + spv::Disassemble(spirvAsmStream, spirv); + + dump(spirvAsmStream.str(), request->outputFunc, request->outputUserData, stdout); + } + + + glslang::FinalizeProcess(); + + return 0; +} diff --git a/tools/glslang/glslang.h b/tools/glslang/glslang.h new file mode 100644 index 000000000..73c8a978e --- /dev/null +++ b/tools/glslang/glslang.h @@ -0,0 +1,23 @@ +// glslang.h +#ifndef GLSLANG_H_INCLUDED +#define GLSLANG_H_INCLUDED + +typedef void (*glslang_OutputFunc)(char const* text, void* userData); + +struct glslang_CompileRequest +{ + char const* sourcePath; + char const* sourceText; + + glslang_OutputFunc diagnosticFunc; + void* diagnosticUserData; + + glslang_OutputFunc outputFunc; + void* outputUserData; + + int slangStage; +}; + +typedef int (*glslang_CompileFunc)(glslang_CompileRequest* request); + +#endif diff --git a/tools/glslang/glslang.vcxproj b/tools/glslang/glslang.vcxproj new file mode 100644 index 000000000..b8034e0bc --- /dev/null +++ b/tools/glslang/glslang.vcxproj @@ -0,0 +1,237 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {C495878A-832C-485B-B347-0998A90CC936} + Win32Proj + glslang + 8.1 + + + + DynamicLibrary + true + v140 + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + DynamicLibrary + true + v140 + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)external\glslang\;$(IncludePath) + + + true + $(SolutionDir)external\glslang\;$(IncludePath) + + + false + $(SolutionDir)external\glslang\;$(IncludePath) + + + false + $(SolutionDir)external\glslang\;$(IncludePath) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;GLSLANG_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + + + Level3 + Disabled + _DEBUG;_WINDOWS;_USRDLL;GLSLANG_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;GLSLANG_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_WINDOWS;_USRDLL;GLSLANG_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/glslang/glslang.vcxproj.filters b/tools/glslang/glslang.vcxproj.filters new file mode 100644 index 000000000..79a7657ce --- /dev/null +++ b/tools/glslang/glslang.vcxproj.filters @@ -0,0 +1,253 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file -- cgit v1.2.3