2012-12-12 21:15:54 +00:00
|
|
|
//
|
|
|
|
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
2013-02-17 06:01:50 +00:00
|
|
|
//Copyright (C) 2013 LunarG, Inc.
|
|
|
|
//
|
2012-12-12 21:15:54 +00:00
|
|
|
//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.
|
|
|
|
//
|
2013-09-17 19:26:08 +00:00
|
|
|
|
|
|
|
// this only applies to the standalone wrapper, not the front end in general
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
|
2016-05-19 17:31:43 +00:00
|
|
|
#include "ResourceLimits.h"
|
2013-07-31 18:44:13 +00:00
|
|
|
#include "Worklist.h"
|
2012-12-12 21:15:54 +00:00
|
|
|
#include "./../glslang/Include/ShHandle.h"
|
2015-08-01 23:10:02 +00:00
|
|
|
#include "./../glslang/Include/revision.h"
|
2012-12-12 21:15:54 +00:00
|
|
|
#include "./../glslang/Public/ShaderLang.h"
|
2015-03-03 17:09:43 +00:00
|
|
|
#include "../SPIRV/GlslangToSpv.h"
|
2015-08-07 04:53:06 +00:00
|
|
|
#include "../SPIRV/GLSL.std.450.h"
|
2015-03-04 03:48:38 +00:00
|
|
|
#include "../SPIRV/doc.h"
|
|
|
|
#include "../SPIRV/disassemble.h"
|
2016-08-05 20:04:23 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2015-11-16 17:03:28 +00:00
|
|
|
#include "../glslang/OSDependent/osinclude.h"
|
2012-12-12 21:15:54 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
SH_IMPORT_EXPORT void ShOutputHtml();
|
|
|
|
}
|
|
|
|
|
2013-08-31 02:41:30 +00:00
|
|
|
// Command-line options
|
|
|
|
enum TOptions {
|
2016-07-09 20:50:57 +00:00
|
|
|
EOptionNone = 0,
|
|
|
|
EOptionIntermediate = (1 << 0),
|
|
|
|
EOptionSuppressInfolog = (1 << 1),
|
|
|
|
EOptionMemoryLeakMode = (1 << 2),
|
|
|
|
EOptionRelaxedErrors = (1 << 3),
|
|
|
|
EOptionGiveWarnings = (1 << 4),
|
|
|
|
EOptionLinkProgram = (1 << 5),
|
|
|
|
EOptionMultiThreaded = (1 << 6),
|
|
|
|
EOptionDumpConfig = (1 << 7),
|
|
|
|
EOptionDumpReflection = (1 << 8),
|
|
|
|
EOptionSuppressWarnings = (1 << 9),
|
|
|
|
EOptionDumpVersions = (1 << 10),
|
|
|
|
EOptionSpv = (1 << 11),
|
|
|
|
EOptionHumanReadableSpv = (1 << 12),
|
|
|
|
EOptionVulkanRules = (1 << 13),
|
|
|
|
EOptionDefaultDesktop = (1 << 14),
|
|
|
|
EOptionOutputPreprocessed = (1 << 15),
|
|
|
|
EOptionOutputHexadecimal = (1 << 16),
|
|
|
|
EOptionReadHlsl = (1 << 17),
|
|
|
|
EOptionCascadingErrors = (1 << 18),
|
2013-08-31 02:41:30 +00:00
|
|
|
};
|
|
|
|
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
2015-07-13 01:28:10 +00:00
|
|
|
// Return codes from main/exit().
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
|
|
|
enum TFailCode {
|
|
|
|
ESuccess = 0,
|
|
|
|
EFailUsage,
|
|
|
|
EFailCompile,
|
|
|
|
EFailLink,
|
|
|
|
EFailCompilerCreate,
|
2013-07-31 18:44:13 +00:00
|
|
|
EFailThreadCreate,
|
2012-12-12 21:15:54 +00:00
|
|
|
EFailLinkerCreate
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2015-07-13 01:28:10 +00:00
|
|
|
// Forward declarations.
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
2013-08-29 00:39:25 +00:00
|
|
|
EShLanguage FindLanguage(const std::string& name);
|
2014-02-18 23:37:57 +00:00
|
|
|
void CompileFile(const char* fileName, ShHandle);
|
2012-12-12 21:15:54 +00:00
|
|
|
void usage();
|
2013-10-28 18:12:06 +00:00
|
|
|
void FreeFileData(char** data);
|
|
|
|
char** ReadFileData(const char* fileName);
|
2013-02-11 22:36:01 +00:00
|
|
|
void InfoLogMsg(const char* msg, const char* name, const int num);
|
2013-06-25 18:10:05 +00:00
|
|
|
|
2013-11-07 23:33:24 +00:00
|
|
|
// Globally track if any compile or link failure.
|
|
|
|
bool CompileFailed = false;
|
|
|
|
bool LinkFailed = false;
|
|
|
|
|
2013-09-17 19:26:08 +00:00
|
|
|
// Use to test breaking up a single shader file into multiple strings.
|
2015-07-13 01:28:10 +00:00
|
|
|
// Set in ReadFileData().
|
2013-10-28 18:12:06 +00:00
|
|
|
int NumShaderStrings;
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-09-17 19:26:08 +00:00
|
|
|
TBuiltInResource Resources;
|
|
|
|
std::string ConfigFile;
|
|
|
|
|
|
|
|
//
|
2016-04-02 19:09:14 +00:00
|
|
|
// Parse either a .conf file provided by the user or the default from glslang::DefaultTBuiltInResource
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
2013-09-17 19:26:08 +00:00
|
|
|
void ProcessConfigFile()
|
2013-04-11 16:31:09 +00:00
|
|
|
{
|
2013-09-17 19:26:08 +00:00
|
|
|
char** configStrings = 0;
|
2014-02-18 23:37:57 +00:00
|
|
|
char* config = 0;
|
2013-09-17 19:26:08 +00:00
|
|
|
if (ConfigFile.size() > 0) {
|
2013-10-28 18:12:06 +00:00
|
|
|
configStrings = ReadFileData(ConfigFile.c_str());
|
2013-09-17 19:26:08 +00:00
|
|
|
if (configStrings)
|
|
|
|
config = *configStrings;
|
|
|
|
else {
|
|
|
|
printf("Error opening configuration file; will instead use the default configuration\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config == 0) {
|
2016-03-04 21:22:34 +00:00
|
|
|
Resources = glslang::DefaultTBuiltInResource;
|
|
|
|
return;
|
2013-09-17 19:26:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 17:50:49 +00:00
|
|
|
glslang::DecodeResourceLimits(&Resources, config);
|
2013-10-22 01:50:39 +00:00
|
|
|
|
2013-09-17 19:26:08 +00:00
|
|
|
if (configStrings)
|
|
|
|
FreeFileData(configStrings);
|
2016-01-18 14:26:25 +00:00
|
|
|
else
|
|
|
|
delete[] config;
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 19:52:57 +00:00
|
|
|
// thread-safe list of shaders to asynchronously grab and compile
|
2013-07-31 18:44:13 +00:00
|
|
|
glslang::TWorklist Worklist;
|
2013-09-06 19:52:57 +00:00
|
|
|
|
|
|
|
// array of unique places to leave the shader names and infologs for the asynchronous compiles
|
2014-06-05 16:30:53 +00:00
|
|
|
glslang::TWorkItem** Work = 0;
|
2013-09-06 19:52:57 +00:00
|
|
|
int NumWorkItems = 0;
|
|
|
|
|
2013-08-31 02:41:30 +00:00
|
|
|
int Options = 0;
|
2015-07-13 01:28:10 +00:00
|
|
|
const char* ExecutableName = nullptr;
|
|
|
|
const char* binaryFileName = nullptr;
|
2016-03-13 01:17:47 +00:00
|
|
|
const char* entryPointName = nullptr;
|
2015-07-13 01:28:10 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create the default name for saving a binary if -o is not provided.
|
|
|
|
//
|
|
|
|
const char* GetBinaryName(EShLanguage stage)
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
if (binaryFileName == nullptr) {
|
|
|
|
switch (stage) {
|
|
|
|
case EShLangVertex: name = "vert.spv"; break;
|
|
|
|
case EShLangTessControl: name = "tesc.spv"; break;
|
|
|
|
case EShLangTessEvaluation: name = "tese.spv"; break;
|
|
|
|
case EShLangGeometry: name = "geom.spv"; break;
|
|
|
|
case EShLangFragment: name = "frag.spv"; break;
|
|
|
|
case EShLangCompute: name = "comp.spv"; break;
|
|
|
|
default: name = "unknown"; break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
name = binaryFileName;
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-09-17 19:26:08 +00:00
|
|
|
//
|
|
|
|
// *.conf => this is a config file that can set limits/resources
|
|
|
|
//
|
|
|
|
bool SetConfigFile(const std::string& name)
|
|
|
|
{
|
|
|
|
if (name.size() < 5)
|
|
|
|
return false;
|
|
|
|
|
2013-10-11 16:28:43 +00:00
|
|
|
if (name.compare(name.size() - 5, 5, ".conf") == 0) {
|
2013-09-17 19:26:08 +00:00
|
|
|
ConfigFile = name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-13 01:28:10 +00:00
|
|
|
//
|
|
|
|
// Give error and exit with failure code.
|
|
|
|
//
|
|
|
|
void Error(const char* message)
|
|
|
|
{
|
|
|
|
printf("%s: Error %s (use -h for usage)\n", ExecutableName, message);
|
|
|
|
exit(EFailUsage);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do all command-line argument parsing. This includes building up the work-items
|
|
|
|
// to be processed later, and saving all the command-line options.
|
|
|
|
//
|
|
|
|
// Does not return (it exits) if command-line is fatally flawed.
|
|
|
|
//
|
|
|
|
void ProcessArguments(int argc, char* argv[])
|
2013-07-31 18:44:13 +00:00
|
|
|
{
|
2013-09-06 19:52:57 +00:00
|
|
|
ExecutableName = argv[0];
|
|
|
|
NumWorkItems = argc; // will include some empties where the '-' options were, but it doesn't matter, they'll be 0
|
2014-06-05 16:30:53 +00:00
|
|
|
Work = new glslang::TWorkItem*[NumWorkItems];
|
2015-07-13 01:28:10 +00:00
|
|
|
for (int w = 0; w < NumWorkItems; ++w)
|
|
|
|
Work[w] = 0;
|
2013-09-06 19:52:57 +00:00
|
|
|
|
2013-07-31 18:44:13 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
for (; argc >= 1; argc--, argv++) {
|
|
|
|
if (argv[0][0] == '-') {
|
2015-05-15 16:02:07 +00:00
|
|
|
switch (argv[0][1]) {
|
|
|
|
case 'H':
|
|
|
|
Options |= EOptionHumanReadableSpv;
|
2016-07-07 23:46:42 +00:00
|
|
|
if ((Options & EOptionSpv) == 0) {
|
|
|
|
// default to Vulkan
|
|
|
|
Options |= EOptionSpv;
|
|
|
|
Options |= EOptionVulkanRules;
|
|
|
|
Options |= EOptionLinkProgram;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-03 17:09:43 +00:00
|
|
|
case 'V':
|
2015-07-13 01:28:10 +00:00
|
|
|
Options |= EOptionSpv;
|
|
|
|
Options |= EOptionVulkanRules;
|
|
|
|
Options |= EOptionLinkProgram;
|
|
|
|
break;
|
|
|
|
case 'G':
|
2015-03-03 17:09:43 +00:00
|
|
|
Options |= EOptionSpv;
|
2014-08-25 20:07:55 +00:00
|
|
|
Options |= EOptionLinkProgram;
|
2016-07-07 23:46:42 +00:00
|
|
|
// undo a -H default to Vulkan
|
|
|
|
Options &= ~EOptionVulkanRules;
|
2014-07-28 04:21:04 +00:00
|
|
|
break;
|
2015-06-17 02:38:44 +00:00
|
|
|
case 'E':
|
|
|
|
Options |= EOptionOutputPreprocessed;
|
|
|
|
break;
|
2013-09-17 19:26:08 +00:00
|
|
|
case 'c':
|
|
|
|
Options |= EOptionDumpConfig;
|
|
|
|
break;
|
2016-07-09 20:50:57 +00:00
|
|
|
case 'C':
|
|
|
|
Options |= EOptionCascadingErrors;
|
|
|
|
break;
|
2013-07-31 18:44:13 +00:00
|
|
|
case 'd':
|
2014-08-13 20:17:19 +00:00
|
|
|
Options |= EOptionDefaultDesktop;
|
2013-07-31 18:44:13 +00:00
|
|
|
break;
|
2016-03-13 01:34:36 +00:00
|
|
|
case 'D':
|
|
|
|
Options |= EOptionReadHlsl;
|
|
|
|
break;
|
2016-03-13 01:17:47 +00:00
|
|
|
case 'e':
|
|
|
|
// HLSL todo: entry point handle needs much more sophistication.
|
|
|
|
// This is okay for one compilation unit with one entry point.
|
|
|
|
entryPointName = argv[1];
|
|
|
|
if (argc > 0) {
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
} else
|
|
|
|
Error("no <entry-point> provided for -e");
|
|
|
|
break;
|
2015-07-13 01:28:10 +00:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
break;
|
2013-09-17 19:26:08 +00:00
|
|
|
case 'i':
|
2013-08-31 02:41:30 +00:00
|
|
|
Options |= EOptionIntermediate;
|
2013-07-31 18:44:13 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
2014-08-25 20:07:55 +00:00
|
|
|
Options |= EOptionLinkProgram;
|
2013-08-31 02:41:30 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
Options |= EOptionMemoryLeakMode;
|
2013-07-31 18:44:13 +00:00
|
|
|
break;
|
2015-07-13 01:28:10 +00:00
|
|
|
case 'o':
|
|
|
|
binaryFileName = argv[1];
|
|
|
|
if (argc > 0) {
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
} else
|
|
|
|
Error("no <file> provided for -o");
|
|
|
|
break;
|
2013-11-07 01:06:34 +00:00
|
|
|
case 'q':
|
|
|
|
Options |= EOptionDumpReflection;
|
|
|
|
break;
|
2013-07-31 18:44:13 +00:00
|
|
|
case 'r':
|
2013-08-31 02:41:30 +00:00
|
|
|
Options |= EOptionRelaxedErrors;
|
2013-07-31 18:44:13 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
2013-08-31 02:41:30 +00:00
|
|
|
Options |= EOptionSuppressInfolog;
|
2013-07-31 18:44:13 +00:00
|
|
|
break;
|
2013-09-06 19:52:57 +00:00
|
|
|
case 't':
|
|
|
|
#ifdef _WIN32
|
2013-11-07 17:44:20 +00:00
|
|
|
Options |= EOptionMultiThreaded;
|
2013-09-06 19:52:57 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2013-12-04 04:43:40 +00:00
|
|
|
case 'v':
|
|
|
|
Options |= EOptionDumpVersions;
|
|
|
|
break;
|
2013-11-07 17:44:20 +00:00
|
|
|
case 'w':
|
|
|
|
Options |= EOptionSuppressWarnings;
|
|
|
|
break;
|
2016-05-27 17:55:53 +00:00
|
|
|
case 'x':
|
|
|
|
Options |= EOptionOutputHexadecimal;
|
|
|
|
break;
|
2013-07-31 18:44:13 +00:00
|
|
|
default:
|
2015-07-13 01:28:10 +00:00
|
|
|
usage();
|
|
|
|
break;
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
2013-09-06 19:52:57 +00:00
|
|
|
} else {
|
2013-09-17 19:26:08 +00:00
|
|
|
std::string name(argv[0]);
|
|
|
|
if (! SetConfigFile(name)) {
|
|
|
|
Work[argc] = new glslang::TWorkItem(name);
|
|
|
|
Worklist.add(Work[argc]);
|
|
|
|
}
|
2013-09-06 19:52:57 +00:00
|
|
|
}
|
2013-07-31 18:44:13 +00:00
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2015-07-13 01:28:10 +00:00
|
|
|
// Make sure that -E is not specified alongside linking (which includes SPV generation)
|
|
|
|
if ((Options & EOptionOutputPreprocessed) && (Options & EOptionLinkProgram))
|
|
|
|
Error("can't use -E when linking is selected");
|
2015-06-17 02:38:44 +00:00
|
|
|
|
2016-05-27 17:55:53 +00:00
|
|
|
// -o or -x makes no sense if there is no target binary
|
2015-07-13 01:28:10 +00:00
|
|
|
if (binaryFileName && (Options & EOptionSpv) == 0)
|
|
|
|
Error("no binary generation requested (e.g., -V)");
|
2013-07-31 18:44:13 +00:00
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2015-07-13 01:28:10 +00:00
|
|
|
//
|
|
|
|
// Translate the meaningful subset of command-line options to parser-behavior options.
|
|
|
|
//
|
2013-11-07 17:44:20 +00:00
|
|
|
void SetMessageOptions(EShMessages& messages)
|
|
|
|
{
|
|
|
|
if (Options & EOptionRelaxedErrors)
|
|
|
|
messages = (EShMessages)(messages | EShMsgRelaxedErrors);
|
|
|
|
if (Options & EOptionIntermediate)
|
|
|
|
messages = (EShMessages)(messages | EShMsgAST);
|
|
|
|
if (Options & EOptionSuppressWarnings)
|
|
|
|
messages = (EShMessages)(messages | EShMsgSuppressWarnings);
|
2015-07-13 01:28:10 +00:00
|
|
|
if (Options & EOptionSpv)
|
|
|
|
messages = (EShMessages)(messages | EShMsgSpvRules);
|
|
|
|
if (Options & EOptionVulkanRules)
|
|
|
|
messages = (EShMessages)(messages | EShMsgVulkanRules);
|
2015-06-24 21:00:46 +00:00
|
|
|
if (Options & EOptionOutputPreprocessed)
|
|
|
|
messages = (EShMessages)(messages | EShMsgOnlyPreprocessor);
|
2016-03-13 01:34:36 +00:00
|
|
|
if (Options & EOptionReadHlsl)
|
|
|
|
messages = (EShMessages)(messages | EShMsgReadHlsl);
|
2016-07-09 20:50:57 +00:00
|
|
|
if (Options & EOptionCascadingErrors)
|
|
|
|
messages = (EShMessages)(messages | EShMsgCascadingErrors);
|
2013-11-07 17:44:20 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 01:28:10 +00:00
|
|
|
//
|
2013-09-04 21:19:27 +00:00
|
|
|
// Thread entry point, for non-linking asynchronous mode.
|
2013-11-07 23:33:24 +00:00
|
|
|
//
|
|
|
|
// Return 0 for failure, 1 for success.
|
|
|
|
//
|
2015-12-01 20:59:53 +00:00
|
|
|
unsigned int CompileShaders(void*)
|
2013-07-31 18:44:13 +00:00
|
|
|
{
|
2013-09-06 19:52:57 +00:00
|
|
|
glslang::TWorkItem* workItem;
|
|
|
|
while (Worklist.remove(workItem)) {
|
|
|
|
ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options);
|
2013-07-31 18:44:13 +00:00
|
|
|
if (compiler == 0)
|
2013-11-07 23:33:24 +00:00
|
|
|
return 0;
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-11-07 17:44:20 +00:00
|
|
|
CompileFile(workItem->name.c_str(), compiler);
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-08-31 02:41:30 +00:00
|
|
|
if (! (Options & EOptionSuppressInfolog))
|
2013-09-06 19:52:57 +00:00
|
|
|
workItem->results = ShGetInfoLog(compiler);
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-07-31 18:44:13 +00:00
|
|
|
ShDestruct(compiler);
|
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-07-31 18:44:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2015-06-19 05:14:19 +00:00
|
|
|
// Outputs the given string, but only if it is non-null and non-empty.
|
|
|
|
// This prevents erroneous newlines from appearing.
|
2015-06-24 21:00:46 +00:00
|
|
|
void PutsIfNonEmpty(const char* str)
|
2015-06-19 05:14:19 +00:00
|
|
|
{
|
|
|
|
if (str && str[0]) {
|
|
|
|
puts(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 21:00:46 +00:00
|
|
|
// Outputs the given string to stderr, but only if it is non-null and non-empty.
|
|
|
|
// This prevents erroneous newlines from appearing.
|
|
|
|
void StderrIfNonEmpty(const char* str)
|
|
|
|
{
|
|
|
|
if (str && str[0]) {
|
|
|
|
fprintf(stderr, "%s\n", str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 22:30:03 +00:00
|
|
|
// Simple bundling of what makes a compilation unit for ease in passing around,
|
|
|
|
// and separation of handling file IO versus API (programmatic) compilation.
|
|
|
|
struct ShaderCompUnit {
|
|
|
|
EShLanguage stage;
|
|
|
|
std::string fileName;
|
|
|
|
char** text; // memory owned/managed externally
|
|
|
|
};
|
|
|
|
|
2013-09-04 21:19:27 +00:00
|
|
|
//
|
2016-01-16 22:30:03 +00:00
|
|
|
// For linking mode: Will independently parse each compilation unit, but then put them
|
|
|
|
// in the same program and link them together, making at most one linked module per
|
|
|
|
// pipeline stage.
|
2013-09-04 21:19:27 +00:00
|
|
|
//
|
|
|
|
// Uses the new C++ interface instead of the old handle-based interface.
|
|
|
|
//
|
2016-01-16 22:30:03 +00:00
|
|
|
|
|
|
|
void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
2013-09-04 21:19:27 +00:00
|
|
|
{
|
|
|
|
// keep track of what to free
|
|
|
|
std::list<glslang::TShader*> shaders;
|
2016-01-16 22:30:03 +00:00
|
|
|
|
2013-09-04 21:19:27 +00:00
|
|
|
EShMessages messages = EShMsgDefault;
|
2013-11-07 17:44:20 +00:00
|
|
|
SetMessageOptions(messages);
|
2013-09-04 21:19:27 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Per-shader processing...
|
|
|
|
//
|
|
|
|
|
2013-11-01 03:08:40 +00:00
|
|
|
glslang::TProgram& program = *new glslang::TProgram;
|
2016-02-23 21:17:38 +00:00
|
|
|
for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) {
|
|
|
|
const auto &compUnit = *it;
|
2016-01-16 22:30:03 +00:00
|
|
|
glslang::TShader* shader = new glslang::TShader(compUnit.stage);
|
|
|
|
shader->setStrings(compUnit.text, 1);
|
2016-03-13 01:17:47 +00:00
|
|
|
if (entryPointName) // HLSL todo: this needs to be tracked per compUnits
|
|
|
|
shader->setEntryPoint(entryPointName);
|
2013-09-04 21:19:27 +00:00
|
|
|
shaders.push_back(shader);
|
2015-07-12 00:01:03 +00:00
|
|
|
|
2015-06-17 02:38:44 +00:00
|
|
|
const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100;
|
2013-09-04 21:19:27 +00:00
|
|
|
|
2015-06-17 02:38:44 +00:00
|
|
|
if (Options & EOptionOutputPreprocessed) {
|
|
|
|
std::string str;
|
2016-03-07 18:23:09 +00:00
|
|
|
glslang::TShader::ForbidInclude includer;
|
2015-06-17 15:40:33 +00:00
|
|
|
if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false,
|
2016-03-07 18:23:09 +00:00
|
|
|
messages, &str, includer)) {
|
2015-06-24 21:00:46 +00:00
|
|
|
PutsIfNonEmpty(str.c_str());
|
|
|
|
} else {
|
|
|
|
CompileFailed = true;
|
|
|
|
}
|
|
|
|
StderrIfNonEmpty(shader->getInfoLog());
|
|
|
|
StderrIfNonEmpty(shader->getInfoDebugLog());
|
2015-06-17 02:38:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (! shader->parse(&Resources, defaultVersion, false, messages))
|
2013-11-07 23:33:24 +00:00
|
|
|
CompileFailed = true;
|
2015-06-17 02:38:44 +00:00
|
|
|
|
2013-09-04 21:19:27 +00:00
|
|
|
program.addShader(shader);
|
|
|
|
|
2016-01-16 22:30:03 +00:00
|
|
|
if (! (Options & EOptionSuppressInfolog) &&
|
|
|
|
! (Options & EOptionMemoryLeakMode)) {
|
|
|
|
PutsIfNonEmpty(compUnit.fileName.c_str());
|
2015-06-24 21:00:46 +00:00
|
|
|
PutsIfNonEmpty(shader->getInfoLog());
|
|
|
|
PutsIfNonEmpty(shader->getInfoDebugLog());
|
2013-09-04 21:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Program-level processing...
|
|
|
|
//
|
|
|
|
|
2016-03-13 01:17:47 +00:00
|
|
|
// Link
|
2015-07-13 01:28:10 +00:00
|
|
|
if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages))
|
2013-11-07 23:33:24 +00:00
|
|
|
LinkFailed = true;
|
|
|
|
|
2016-03-13 01:17:47 +00:00
|
|
|
// Report
|
2016-01-16 22:30:03 +00:00
|
|
|
if (! (Options & EOptionSuppressInfolog) &&
|
|
|
|
! (Options & EOptionMemoryLeakMode)) {
|
2015-06-24 21:00:46 +00:00
|
|
|
PutsIfNonEmpty(program.getInfoLog());
|
|
|
|
PutsIfNonEmpty(program.getInfoDebugLog());
|
2013-09-04 21:19:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 01:17:47 +00:00
|
|
|
// Reflect
|
2013-11-07 01:06:34 +00:00
|
|
|
if (Options & EOptionDumpReflection) {
|
|
|
|
program.buildReflection();
|
|
|
|
program.dumpReflection();
|
|
|
|
}
|
|
|
|
|
2016-03-13 01:17:47 +00:00
|
|
|
// Dump SPIR-V
|
2015-03-03 17:09:43 +00:00
|
|
|
if (Options & EOptionSpv) {
|
2014-07-28 04:21:04 +00:00
|
|
|
if (CompileFailed || LinkFailed)
|
2015-07-13 01:28:10 +00:00
|
|
|
printf("SPIR-V is not generated for failed compile or link\n");
|
2014-07-28 04:21:04 +00:00
|
|
|
else {
|
|
|
|
for (int stage = 0; stage < EShLangCount; ++stage) {
|
2014-08-24 18:21:00 +00:00
|
|
|
if (program.getIntermediate((EShLanguage)stage)) {
|
2015-03-03 17:09:43 +00:00
|
|
|
std::vector<unsigned int> spirv;
|
2016-05-02 22:11:54 +00:00
|
|
|
std::string warningsErrors;
|
2016-05-04 19:55:59 +00:00
|
|
|
spv::SpvBuildLogger logger;
|
|
|
|
glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger);
|
2016-01-16 22:30:03 +00:00
|
|
|
|
|
|
|
// Dump the spv to a file or stdout, etc., but only if not doing
|
|
|
|
// memory/perf testing, as it's not internal to programmatic use.
|
|
|
|
if (! (Options & EOptionMemoryLeakMode)) {
|
2016-05-27 17:55:53 +00:00
|
|
|
printf("%s", logger.getAllMessages().c_str());
|
|
|
|
if (Options & EOptionOutputHexadecimal) {
|
|
|
|
glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage));
|
|
|
|
} else {
|
|
|
|
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
|
|
|
|
}
|
2016-01-16 22:30:03 +00:00
|
|
|
if (Options & EOptionHumanReadableSpv) {
|
|
|
|
spv::Disassemble(std::cout, spirv);
|
|
|
|
}
|
2015-03-04 03:48:38 +00:00
|
|
|
}
|
2014-08-24 18:21:00 +00:00
|
|
|
}
|
2014-07-28 04:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 03:08:40 +00:00
|
|
|
// Free everything up, program has to go before the shaders
|
|
|
|
// because it might have merged stuff from the shaders, and
|
|
|
|
// the stuff from the shaders has to have its destructors called
|
|
|
|
// before the pools holding the memory in the shaders is freed.
|
|
|
|
delete &program;
|
2013-09-04 21:19:27 +00:00
|
|
|
while (shaders.size() > 0) {
|
|
|
|
delete shaders.back();
|
|
|
|
shaders.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 22:30:03 +00:00
|
|
|
//
|
|
|
|
// Do file IO part of compile and link, handing off the pure
|
|
|
|
// API/programmatic mode to CompileAndLinkShaderUnits(), which can
|
|
|
|
// be put in a loop for testing memory footprint and performance.
|
|
|
|
//
|
|
|
|
// This is just for linking mode: meaning all the shaders will be put into the
|
|
|
|
// the same program linked together.
|
|
|
|
//
|
|
|
|
// This means there are a limited number of work items (not multi-threading mode)
|
|
|
|
// and that the point is testing at the linking level. Hence, to enable
|
|
|
|
// performance and memory testing, the actual compile/link can be put in
|
|
|
|
// a loop, independent of processing the work items and file IO.
|
|
|
|
//
|
|
|
|
void CompileAndLinkShaderFiles()
|
|
|
|
{
|
|
|
|
std::vector<ShaderCompUnit> compUnits;
|
|
|
|
|
|
|
|
// Transfer all the work items from to a simple list of
|
|
|
|
// of compilation units. (We don't care about the thread
|
|
|
|
// work-item distribution properties in this path, which
|
|
|
|
// is okay due to the limited number of shaders, know since
|
|
|
|
// they are all getting linked together.)
|
|
|
|
glslang::TWorkItem* workItem;
|
|
|
|
while (Worklist.remove(workItem)) {
|
|
|
|
ShaderCompUnit compUnit = {
|
|
|
|
FindLanguage(workItem->name),
|
|
|
|
workItem->name,
|
|
|
|
ReadFileData(workItem->name.c_str())
|
|
|
|
};
|
|
|
|
|
|
|
|
if (! compUnit.text) {
|
|
|
|
usage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
compUnits.push_back(compUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actual call to programmatic processing of compile and link,
|
|
|
|
// in a loop for testing memory and performance. This part contains
|
|
|
|
// all the perf/memory that a programmatic consumer will care about.
|
|
|
|
for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
|
|
|
|
for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j)
|
|
|
|
CompileAndLinkShaderUnits(compUnits);
|
|
|
|
|
|
|
|
if (Options & EOptionMemoryLeakMode)
|
|
|
|
glslang::OS_DumpMemoryCounters();
|
|
|
|
}
|
|
|
|
|
2016-02-23 21:17:38 +00:00
|
|
|
for (auto it = compUnits.begin(); it != compUnits.end(); ++it)
|
|
|
|
FreeFileData(it->text);
|
2016-01-16 22:30:03 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 18:44:13 +00:00
|
|
|
int C_DECL main(int argc, char* argv[])
|
|
|
|
{
|
2015-07-13 01:28:10 +00:00
|
|
|
ProcessArguments(argc, argv);
|
2013-07-31 18:44:13 +00:00
|
|
|
|
2013-09-17 19:26:08 +00:00
|
|
|
if (Options & EOptionDumpConfig) {
|
2016-03-04 21:22:34 +00:00
|
|
|
printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str());
|
2013-09-17 19:26:08 +00:00
|
|
|
if (Worklist.empty())
|
|
|
|
return ESuccess;
|
|
|
|
}
|
|
|
|
|
2015-08-01 23:10:02 +00:00
|
|
|
if (Options & EOptionDumpVersions) {
|
|
|
|
printf("Glslang Version: %s %s\n", GLSLANG_REVISION, GLSLANG_DATE);
|
2013-12-04 04:43:40 +00:00
|
|
|
printf("ESSL Version: %s\n", glslang::GetEsslVersionString());
|
|
|
|
printf("GLSL Version: %s\n", glslang::GetGlslVersionString());
|
2015-07-13 01:28:10 +00:00
|
|
|
std::string spirvVersion;
|
|
|
|
glslang::GetSpirvVersion(spirvVersion);
|
2015-08-01 23:10:02 +00:00
|
|
|
printf("SPIR-V Version %s\n", spirvVersion.c_str());
|
2015-08-07 04:53:06 +00:00
|
|
|
printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision);
|
2015-11-16 04:33:39 +00:00
|
|
|
printf("Khronos Tool ID %d\n", glslang::GetKhronosToolId());
|
2016-07-20 22:03:29 +00:00
|
|
|
printf("GL_KHR_vulkan_glsl version %d\n", 100);
|
|
|
|
printf("ARB_GL_gl_spirv version %d\n", 100);
|
2013-12-04 04:43:40 +00:00
|
|
|
if (Worklist.empty())
|
|
|
|
return ESuccess;
|
|
|
|
}
|
|
|
|
|
2013-09-17 19:26:08 +00:00
|
|
|
if (Worklist.empty()) {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessConfigFile();
|
|
|
|
|
2013-09-04 21:19:27 +00:00
|
|
|
//
|
|
|
|
// Two modes:
|
2013-09-06 19:52:57 +00:00
|
|
|
// 1) linking all arguments together, single-threaded, new C++ interface
|
|
|
|
// 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface
|
2013-09-04 21:19:27 +00:00
|
|
|
//
|
2015-06-17 02:38:44 +00:00
|
|
|
if (Options & EOptionLinkProgram ||
|
|
|
|
Options & EOptionOutputPreprocessed) {
|
2013-11-01 17:41:52 +00:00
|
|
|
glslang::InitializeProcess();
|
2016-01-16 22:30:03 +00:00
|
|
|
CompileAndLinkShaderFiles();
|
2013-11-01 17:41:52 +00:00
|
|
|
glslang::FinalizeProcess();
|
2016-01-18 14:26:25 +00:00
|
|
|
for (int w = 0; w < NumWorkItems; ++w) {
|
|
|
|
if (Work[w]) {
|
|
|
|
delete Work[w];
|
|
|
|
}
|
|
|
|
}
|
2013-11-01 17:41:52 +00:00
|
|
|
} else {
|
|
|
|
ShInitialize();
|
|
|
|
|
2013-09-06 19:52:57 +00:00
|
|
|
bool printShaderNames = Worklist.size() > 1;
|
|
|
|
|
|
|
|
if (Options & EOptionMultiThreaded) {
|
|
|
|
const int NumThreads = 16;
|
|
|
|
void* threads[NumThreads];
|
|
|
|
for (int t = 0; t < NumThreads; ++t) {
|
|
|
|
threads[t] = glslang::OS_CreateThread(&CompileShaders);
|
|
|
|
if (! threads[t]) {
|
|
|
|
printf("Failed to create thread\n");
|
|
|
|
return EFailThreadCreate;
|
|
|
|
}
|
2013-07-31 18:44:13 +00:00
|
|
|
}
|
2013-09-06 19:52:57 +00:00
|
|
|
glslang::OS_WaitForAllThreads(threads, NumThreads);
|
2013-11-07 23:33:24 +00:00
|
|
|
} else
|
|
|
|
CompileShaders(0);
|
2013-09-06 19:52:57 +00:00
|
|
|
|
|
|
|
// Print out all the resulting infologs
|
|
|
|
for (int w = 0; w < NumWorkItems; ++w) {
|
|
|
|
if (Work[w]) {
|
2015-12-15 16:52:34 +00:00
|
|
|
if (printShaderNames || Work[w]->results.size() > 0)
|
2015-06-24 21:00:46 +00:00
|
|
|
PutsIfNonEmpty(Work[w]->name.c_str());
|
|
|
|
PutsIfNonEmpty(Work[w]->results.c_str());
|
2013-09-06 19:52:57 +00:00
|
|
|
delete Work[w];
|
|
|
|
}
|
|
|
|
}
|
2013-11-01 17:41:52 +00:00
|
|
|
|
|
|
|
ShFinalize();
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
2013-07-31 18:44:13 +00:00
|
|
|
|
2016-01-18 14:26:25 +00:00
|
|
|
delete[] Work;
|
|
|
|
|
2013-11-07 23:33:24 +00:00
|
|
|
if (CompileFailed)
|
2012-12-12 21:15:54 +00:00
|
|
|
return EFailCompile;
|
2013-11-07 23:33:24 +00:00
|
|
|
if (LinkFailed)
|
2012-12-12 21:15:54 +00:00
|
|
|
return EFailLink;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Deduce the language from the filename. Files must end in one of the
|
|
|
|
// following extensions:
|
|
|
|
//
|
2013-07-31 18:44:13 +00:00
|
|
|
// .vert = vertex
|
|
|
|
// .tesc = tessellation control
|
|
|
|
// .tese = tessellation evaluation
|
|
|
|
// .geom = geometry
|
|
|
|
// .frag = fragment
|
2013-08-31 02:41:30 +00:00
|
|
|
// .comp = compute
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
2013-08-29 00:39:25 +00:00
|
|
|
EShLanguage FindLanguage(const std::string& name)
|
2012-12-12 21:15:54 +00:00
|
|
|
{
|
2013-07-31 18:44:13 +00:00
|
|
|
size_t ext = name.rfind('.');
|
|
|
|
if (ext == std::string::npos) {
|
|
|
|
usage();
|
2012-12-12 21:34:14 +00:00
|
|
|
return EShLangVertex;
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 18:44:13 +00:00
|
|
|
std::string suffix = name.substr(ext + 1, std::string::npos);
|
|
|
|
if (suffix == "vert")
|
|
|
|
return EShLangVertex;
|
|
|
|
else if (suffix == "tesc")
|
|
|
|
return EShLangTessControl;
|
|
|
|
else if (suffix == "tese")
|
|
|
|
return EShLangTessEvaluation;
|
|
|
|
else if (suffix == "geom")
|
|
|
|
return EShLangGeometry;
|
|
|
|
else if (suffix == "frag")
|
|
|
|
return EShLangFragment;
|
Put in infrastructure for tessellation, geometry, and compute stages, and partially flesh out with built-in functions.
Added the built-in functions EmitVertex(), EndPrimitive(), barrier(), memoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(), memoryBarrierImage(), memoryBarrierShared(), and groupMemoryBarrier().
Have not added any new built-in variables.
Also changed the linear performance relateToOperator() to a high-performance version.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22659 e7fa87d3-cd2b-0410-9028-fcbf551c1848
2013-08-09 17:14:49 +00:00
|
|
|
else if (suffix == "comp")
|
|
|
|
return EShLangCompute;
|
2013-07-31 18:44:13 +00:00
|
|
|
|
|
|
|
usage();
|
2012-12-12 21:34:14 +00:00
|
|
|
return EShLangVertex;
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2013-09-04 21:19:27 +00:00
|
|
|
// Read a file's data into a string, and compile it using the old interface ShCompile,
|
|
|
|
// for non-linkable results.
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
2014-02-18 23:37:57 +00:00
|
|
|
void CompileFile(const char* fileName, ShHandle compiler)
|
2012-12-12 21:15:54 +00:00
|
|
|
{
|
2015-05-18 01:59:45 +00:00
|
|
|
int ret = 0;
|
2013-06-25 18:10:05 +00:00
|
|
|
char** shaderStrings = ReadFileData(fileName);
|
2013-06-26 22:42:55 +00:00
|
|
|
if (! shaderStrings) {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2013-06-25 18:10:05 +00:00
|
|
|
int* lengths = new int[NumShaderStrings];
|
|
|
|
|
|
|
|
// move to length-based strings, rather than null-terminated strings
|
|
|
|
for (int s = 0; s < NumShaderStrings; ++s)
|
2014-02-19 02:47:20 +00:00
|
|
|
lengths[s] = (int)strlen(shaderStrings[s]);
|
2013-04-17 19:34:23 +00:00
|
|
|
|
2013-11-07 23:33:24 +00:00
|
|
|
if (! shaderStrings) {
|
|
|
|
CompileFailed = true;
|
|
|
|
return;
|
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-05-05 23:46:22 +00:00
|
|
|
EShMessages messages = EShMsgDefault;
|
2013-11-07 17:44:20 +00:00
|
|
|
SetMessageOptions(messages);
|
2013-09-04 21:19:27 +00:00
|
|
|
|
2013-08-31 02:41:30 +00:00
|
|
|
for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
|
|
|
|
for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) {
|
2014-08-13 20:17:19 +00:00
|
|
|
//ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
2015-05-18 01:59:45 +00:00
|
|
|
ret = ShCompile(compiler, shaderStrings, NumShaderStrings, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
2013-10-28 18:12:06 +00:00
|
|
|
//const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err",
|
|
|
|
// "or should be l", "ine 1", "string 5\n", "float glo", "bal",
|
|
|
|
// ";\n#error should be line 2\n void main() {", "global = 2.3;}" };
|
2013-06-25 18:10:05 +00:00
|
|
|
//const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" };
|
2015-05-18 01:59:45 +00:00
|
|
|
//ret = ShCompile(compiler, multi, 7, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
2013-06-25 18:10:05 +00:00
|
|
|
}
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-08-31 02:41:30 +00:00
|
|
|
if (Options & EOptionMemoryLeakMode)
|
2013-07-31 18:44:13 +00:00
|
|
|
glslang::OS_DumpMemoryCounters();
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 18:10:05 +00:00
|
|
|
delete [] lengths;
|
|
|
|
FreeFileData(shaderStrings);
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2013-11-07 23:33:24 +00:00
|
|
|
if (ret == 0)
|
|
|
|
CompileFailed = true;
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// print usage to stdout
|
|
|
|
//
|
|
|
|
void usage()
|
|
|
|
{
|
2013-12-04 04:43:40 +00:00
|
|
|
printf("Usage: glslangValidator [option]... [file]...\n"
|
|
|
|
"\n"
|
2015-03-03 17:09:43 +00:00
|
|
|
"Where: each 'file' ends in .<stage>, where <stage> is one of\n"
|
2015-07-13 01:28:10 +00:00
|
|
|
" .conf to provide an optional config file that replaces the default configuration\n"
|
|
|
|
" (see -c option below for generating a template)\n"
|
|
|
|
" .vert for a vertex shader\n"
|
|
|
|
" .tesc for a tessellation control shader\n"
|
|
|
|
" .tese for a tessellation evaluation shader\n"
|
|
|
|
" .geom for a geometry shader\n"
|
|
|
|
" .frag for a fragment shader\n"
|
|
|
|
" .comp for a compute shader\n"
|
2013-12-04 04:43:40 +00:00
|
|
|
"\n"
|
2013-08-05 15:52:03 +00:00
|
|
|
"Compilation warnings and errors will be printed to stdout.\n"
|
2013-12-04 04:43:40 +00:00
|
|
|
"\n"
|
2013-08-05 15:52:03 +00:00
|
|
|
"To get other information, use one of the following options:\n"
|
2015-07-13 01:28:10 +00:00
|
|
|
"Each option must be specified separately.\n"
|
|
|
|
" -V create SPIR-V binary, under Vulkan semantics; turns on -l;\n"
|
|
|
|
" default file name is <stage>.spv (-o overrides this)\n"
|
|
|
|
" -G create SPIR-V binary, under OpenGL semantics; turns on -l;\n"
|
|
|
|
" default file name is <stage>.spv (-o overrides this)\n"
|
|
|
|
" -H print human readable form of SPIR-V; turns on -V\n"
|
2015-06-24 21:00:46 +00:00
|
|
|
" -E print pre-processed GLSL; cannot be used with -l;\n"
|
|
|
|
" errors will appear on stderr.\n"
|
2015-07-13 01:28:10 +00:00
|
|
|
" -c configuration dump;\n"
|
|
|
|
" creates the default configuration file (redirect to a .conf file)\n"
|
2016-07-09 20:50:57 +00:00
|
|
|
" -C cascading errors; risks crashes from accumulation of error recoveries\n"
|
2015-07-13 01:28:10 +00:00
|
|
|
" -d default to desktop (#version 110) when there is no shader #version\n"
|
|
|
|
" (default is ES version 100)\n"
|
2016-03-13 01:34:36 +00:00
|
|
|
" -D input is HLSL\n"
|
2016-03-13 01:17:47 +00:00
|
|
|
" -e specify entry-point name\n"
|
2015-07-13 01:28:10 +00:00
|
|
|
" -h print this usage message\n"
|
|
|
|
" -i intermediate tree (glslang AST) is printed out\n"
|
|
|
|
" -l link all input files together to form a single module\n"
|
|
|
|
" -m memory leak mode\n"
|
2016-05-27 17:55:53 +00:00
|
|
|
" -o <file> save binary to <file>, requires a binary option (e.g., -V)\n"
|
2015-07-13 01:28:10 +00:00
|
|
|
" -q dump reflection query database\n"
|
|
|
|
" -r relaxed semantic error-checking mode\n"
|
|
|
|
" -s silent mode\n"
|
|
|
|
" -t multi-threaded mode\n"
|
|
|
|
" -v print version strings\n"
|
|
|
|
" -w suppress warnings (except as required by #extension : warn)\n"
|
2016-05-31 13:39:41 +00:00
|
|
|
" -x save 32-bit hexadecimal numbers as text, requires a binary option (e.g., -V)\n"
|
2013-11-07 17:44:20 +00:00
|
|
|
);
|
2015-07-13 01:28:10 +00:00
|
|
|
|
|
|
|
exit(EFailUsage);
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-06 19:57:34 +00:00
|
|
|
#if !defined _MSC_VER && !defined MINGW_HAS_SECURE_API
|
2013-03-08 23:14:42 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
int fopen_s(
|
|
|
|
FILE** pFile,
|
2014-02-18 23:37:57 +00:00
|
|
|
const char* filename,
|
|
|
|
const char* mode
|
2013-03-08 23:14:42 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!pFile || !filename || !mode) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* f = fopen(filename, mode);
|
|
|
|
if (! f) {
|
|
|
|
if (errno != 0) {
|
|
|
|
return errno;
|
|
|
|
} else {
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pFile = f;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-12-12 21:15:54 +00:00
|
|
|
//
|
|
|
|
// Malloc a string of sufficient size and read a string into it.
|
|
|
|
//
|
2014-02-18 23:37:57 +00:00
|
|
|
char** ReadFileData(const char* fileName)
|
2012-12-12 21:15:54 +00:00
|
|
|
{
|
2015-07-12 00:01:03 +00:00
|
|
|
FILE *in = nullptr;
|
2014-10-06 19:57:34 +00:00
|
|
|
int errorCode = fopen_s(&in, fileName, "r");
|
2014-08-18 19:42:35 +00:00
|
|
|
|
2012-12-12 21:15:54 +00:00
|
|
|
int count = 0;
|
2015-07-12 00:01:03 +00:00
|
|
|
const int maxSourceStrings = 5; // for testing splitting shader/tokens across multiple strings
|
|
|
|
char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); // freed in FreeFileData()
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2015-07-13 01:28:10 +00:00
|
|
|
if (errorCode || in == nullptr)
|
|
|
|
Error("unable to open input file");
|
2012-12-12 21:15:54 +00:00
|
|
|
|
|
|
|
while (fgetc(in) != EOF)
|
|
|
|
count++;
|
|
|
|
|
2014-08-18 19:42:35 +00:00
|
|
|
fseek(in, 0, SEEK_SET);
|
2015-05-18 01:59:45 +00:00
|
|
|
|
2015-07-12 00:01:03 +00:00
|
|
|
char *fdata = (char*)malloc(count+2); // freed before return of this function
|
2015-07-13 01:28:10 +00:00
|
|
|
if (! fdata)
|
|
|
|
Error("can't allocate memory");
|
|
|
|
|
2015-07-12 00:01:03 +00:00
|
|
|
if ((int)fread(fdata, 1, count, in) != count) {
|
|
|
|
free(fdata);
|
2015-07-13 01:28:10 +00:00
|
|
|
Error("can't read input file");
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
2015-07-13 01:28:10 +00:00
|
|
|
|
2012-12-12 21:15:54 +00:00
|
|
|
fdata[count] = '\0';
|
|
|
|
fclose(in);
|
2015-07-12 00:01:03 +00:00
|
|
|
|
2013-10-28 18:12:06 +00:00
|
|
|
if (count == 0) {
|
2015-07-12 00:01:03 +00:00
|
|
|
// recover from empty file
|
|
|
|
return_data[0] = (char*)malloc(count+2); // freed in FreeFileData()
|
2012-12-12 21:15:54 +00:00
|
|
|
return_data[0][0]='\0';
|
2013-10-28 18:12:06 +00:00
|
|
|
NumShaderStrings = 0;
|
2015-07-12 00:01:03 +00:00
|
|
|
free(fdata);
|
|
|
|
|
|
|
|
return return_data;
|
2013-10-28 18:12:06 +00:00
|
|
|
} else
|
2015-07-12 00:01:03 +00:00
|
|
|
NumShaderStrings = 1; // Set to larger than 1 for testing multiple strings
|
2012-12-12 21:15:54 +00:00
|
|
|
|
2015-07-12 00:01:03 +00:00
|
|
|
// compute how to split up the file into multiple strings, for testing multiple strings
|
2014-08-18 19:42:35 +00:00
|
|
|
int len = (int)(ceil)((float)count/(float)NumShaderStrings);
|
2015-07-12 00:01:03 +00:00
|
|
|
int ptr_len = 0;
|
|
|
|
int i = 0;
|
|
|
|
while (count > 0) {
|
|
|
|
return_data[i] = (char*)malloc(len + 2); // freed in FreeFileData()
|
|
|
|
memcpy(return_data[i], fdata + ptr_len, len);
|
|
|
|
return_data[i][len] = '\0';
|
|
|
|
count -= len;
|
|
|
|
ptr_len += len;
|
|
|
|
if (count < len) {
|
|
|
|
if (count == 0) {
|
|
|
|
NumShaderStrings = i + 1;
|
2012-12-12 21:15:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-12 00:01:03 +00:00
|
|
|
len = count;
|
2014-08-18 19:42:35 +00:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2015-07-12 00:01:03 +00:00
|
|
|
|
|
|
|
free(fdata);
|
|
|
|
|
2012-12-12 21:15:54 +00:00
|
|
|
return return_data;
|
|
|
|
}
|
|
|
|
|
2014-02-18 23:37:57 +00:00
|
|
|
void FreeFileData(char** data)
|
2012-12-12 21:15:54 +00:00
|
|
|
{
|
2015-07-12 00:01:03 +00:00
|
|
|
for(int i = 0; i < NumShaderStrings; i++)
|
2012-12-12 21:15:54 +00:00
|
|
|
free(data[i]);
|
2015-07-12 00:01:03 +00:00
|
|
|
|
|
|
|
free(data);
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:36:01 +00:00
|
|
|
void InfoLogMsg(const char* msg, const char* name, const int num)
|
2012-12-12 21:15:54 +00:00
|
|
|
{
|
2015-06-10 23:23:12 +00:00
|
|
|
if (num >= 0 )
|
|
|
|
printf("#### %s %s %d INFO LOG ####\n", msg, name, num);
|
|
|
|
else
|
|
|
|
printf("#### %s %s INFO LOG ####\n", msg, name);
|
2012-12-12 21:15:54 +00:00
|
|
|
}
|