|
@@ -115,18 +115,14 @@ enum TFailCode {
|
|
|
EShLanguage FindLanguage(const std::string& name, bool parseSuffix=true);
|
|
EShLanguage FindLanguage(const std::string& name, bool parseSuffix=true);
|
|
|
void CompileFile(const char* fileName, ShHandle);
|
|
void CompileFile(const char* fileName, ShHandle);
|
|
|
void usage();
|
|
void usage();
|
|
|
-void FreeFileData(char** data);
|
|
|
|
|
-char** ReadFileData(const char* fileName);
|
|
|
|
|
|
|
+char* ReadFileData(const char* fileName);
|
|
|
|
|
+void FreeFileData(char* data);
|
|
|
void InfoLogMsg(const char* msg, const char* name, const int num);
|
|
void InfoLogMsg(const char* msg, const char* name, const int num);
|
|
|
|
|
|
|
|
// Globally track if any compile or link failure.
|
|
// Globally track if any compile or link failure.
|
|
|
bool CompileFailed = false;
|
|
bool CompileFailed = false;
|
|
|
bool LinkFailed = false;
|
|
bool LinkFailed = false;
|
|
|
|
|
|
|
|
-// Use to test breaking up a single shader file into multiple strings.
|
|
|
|
|
-// Set in ReadFileData().
|
|
|
|
|
-int NumShaderStrings;
|
|
|
|
|
-
|
|
|
|
|
TBuiltInResource Resources;
|
|
TBuiltInResource Resources;
|
|
|
std::string ConfigFile;
|
|
std::string ConfigFile;
|
|
|
|
|
|
|
@@ -135,29 +131,13 @@ std::string ConfigFile;
|
|
|
//
|
|
//
|
|
|
void ProcessConfigFile()
|
|
void ProcessConfigFile()
|
|
|
{
|
|
{
|
|
|
- char** configStrings = 0;
|
|
|
|
|
- char* config = 0;
|
|
|
|
|
- if (ConfigFile.size() > 0) {
|
|
|
|
|
- configStrings = ReadFileData(ConfigFile.c_str());
|
|
|
|
|
- if (configStrings)
|
|
|
|
|
- config = *configStrings;
|
|
|
|
|
- else {
|
|
|
|
|
- printf("Error opening configuration file; will instead use the default configuration\n");
|
|
|
|
|
- usage();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (config == 0) {
|
|
|
|
|
|
|
+ if (ConfigFile.size() == 0)
|
|
|
Resources = glslang::DefaultTBuiltInResource;
|
|
Resources = glslang::DefaultTBuiltInResource;
|
|
|
- return;
|
|
|
|
|
|
|
+ else {
|
|
|
|
|
+ char* configString = ReadFileData(ConfigFile.c_str());
|
|
|
|
|
+ glslang::DecodeResourceLimits(&Resources, configString);
|
|
|
|
|
+ FreeFileData(configString);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- glslang::DecodeResourceLimits(&Resources, config);
|
|
|
|
|
-
|
|
|
|
|
- if (configStrings)
|
|
|
|
|
- FreeFileData(configStrings);
|
|
|
|
|
- else
|
|
|
|
|
- delete[] config;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int Options = 0;
|
|
int Options = 0;
|
|
@@ -177,6 +157,53 @@ std::array<unsigned int, EShLangCount> baseSsboBinding;
|
|
|
std::array<unsigned int, EShLangCount> baseUavBinding;
|
|
std::array<unsigned int, EShLangCount> baseUavBinding;
|
|
|
std::array<std::vector<std::string>, EShLangCount> baseResourceSetBinding;
|
|
std::array<std::vector<std::string>, EShLangCount> baseResourceSetBinding;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+// Add things like "#define ..." to a preamble to use in the beginning of the shader.
|
|
|
|
|
+class TPreamble {
|
|
|
|
|
+public:
|
|
|
|
|
+ TPreamble() { }
|
|
|
|
|
+
|
|
|
|
|
+ bool isSet() const { return text.size() > 0; }
|
|
|
|
|
+ const char* get() const { return text.c_str(); }
|
|
|
|
|
+
|
|
|
|
|
+ // #define...
|
|
|
|
|
+ void addDef(std::string def)
|
|
|
|
|
+ {
|
|
|
|
|
+ text.append("#define ");
|
|
|
|
|
+ fixLine(def);
|
|
|
|
|
+
|
|
|
|
|
+ // The first "=" needs to turn into a space
|
|
|
|
|
+ int equal = def.find_first_of("=");
|
|
|
|
|
+ if (equal != def.npos)
|
|
|
|
|
+ def[equal] = ' ';
|
|
|
|
|
+
|
|
|
|
|
+ text.append(def);
|
|
|
|
|
+ text.append("\n");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // #undef...
|
|
|
|
|
+ void addUndef(std::string undef)
|
|
|
|
|
+ {
|
|
|
|
|
+ text.append("#undef ");
|
|
|
|
|
+ fixLine(undef);
|
|
|
|
|
+ text.append(undef);
|
|
|
|
|
+ text.append("\n");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+protected:
|
|
|
|
|
+ void fixLine(std::string& line)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Can't go past a newline in the line
|
|
|
|
|
+ int end = line.find_first_of("\n");
|
|
|
|
|
+ if (end != line.npos)
|
|
|
|
|
+ line = line.substr(0, end);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::string text; // contents of preamble
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+TPreamble UserPreamble;
|
|
|
|
|
+
|
|
|
//
|
|
//
|
|
|
// Create the default name for saving a binary if -o is not provided.
|
|
// Create the default name for saving a binary if -o is not provided.
|
|
|
//
|
|
//
|
|
@@ -310,6 +337,14 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|
|
ExecutableName = argv[0];
|
|
ExecutableName = argv[0];
|
|
|
workItems.reserve(argc);
|
|
workItems.reserve(argc);
|
|
|
|
|
|
|
|
|
|
+ const auto getStringOperand = [&](const char* desc) {
|
|
|
|
|
+ if (argv[0][2] == 0) {
|
|
|
|
|
+ printf("%s must immediately follow option (no spaces)\n", desc);
|
|
|
|
|
+ exit(EFailUsage);
|
|
|
|
|
+ }
|
|
|
|
|
+ return argv[0] + 2;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
argc--;
|
|
argc--;
|
|
|
argv++;
|
|
argv++;
|
|
|
for (; argc >= 1; argc--, argv++) {
|
|
for (; argc >= 1; argc--, argv++) {
|
|
@@ -321,18 +356,49 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|
|
std::transform(lowerword.begin(), lowerword.end(), lowerword.begin(), ::tolower);
|
|
std::transform(lowerword.begin(), lowerword.end(), lowerword.begin(), ::tolower);
|
|
|
|
|
|
|
|
// handle --word style options
|
|
// handle --word style options
|
|
|
- if (lowerword == "shift-sampler-bindings" || // synonyms
|
|
|
|
|
|
|
+ if (lowerword == "auto-map-bindings" || // synonyms
|
|
|
|
|
+ lowerword == "auto-map-binding" ||
|
|
|
|
|
+ lowerword == "amb") {
|
|
|
|
|
+ Options |= EOptionAutoMapBindings;
|
|
|
|
|
+ } else if (lowerword == "auto-map-locations" || // synonyms
|
|
|
|
|
+ lowerword == "aml") {
|
|
|
|
|
+ Options |= EOptionAutoMapLocations;
|
|
|
|
|
+ } else if (lowerword == "flatten-uniform-arrays" || // synonyms
|
|
|
|
|
+ lowerword == "flatten-uniform-array" ||
|
|
|
|
|
+ lowerword == "fua") {
|
|
|
|
|
+ Options |= EOptionFlattenUniformArrays;
|
|
|
|
|
+ } else if (lowerword == "hlsl-offsets") {
|
|
|
|
|
+ Options |= EOptionHlslOffsets;
|
|
|
|
|
+ } else if (lowerword == "hlsl-iomap" ||
|
|
|
|
|
+ lowerword == "hlsl-iomapper" ||
|
|
|
|
|
+ lowerword == "hlsl-iomapping") {
|
|
|
|
|
+ Options |= EOptionHlslIoMapping;
|
|
|
|
|
+ } else if (lowerword == "keep-uncalled" || // synonyms
|
|
|
|
|
+ lowerword == "ku") {
|
|
|
|
|
+ Options |= EOptionKeepUncalled;
|
|
|
|
|
+ } else if (lowerword == "no-storage-format" || // synonyms
|
|
|
|
|
+ lowerword == "nsf") {
|
|
|
|
|
+ Options |= EOptionNoStorageFormat;
|
|
|
|
|
+ } else if (lowerword == "resource-set-bindings" || // synonyms
|
|
|
|
|
+ lowerword == "resource-set-binding" ||
|
|
|
|
|
+ lowerword == "rsb") {
|
|
|
|
|
+ ProcessResourceSetBindingBase(argc, argv, baseResourceSetBinding);
|
|
|
|
|
+ } else if (lowerword == "shift-image-bindings" || // synonyms
|
|
|
|
|
+ lowerword == "shift-image-binding" ||
|
|
|
|
|
+ lowerword == "sib") {
|
|
|
|
|
+ ProcessBindingBase(argc, argv, baseImageBinding);
|
|
|
|
|
+ } else if (lowerword == "shift-sampler-bindings" || // synonyms
|
|
|
lowerword == "shift-sampler-binding" ||
|
|
lowerword == "shift-sampler-binding" ||
|
|
|
lowerword == "ssb") {
|
|
lowerword == "ssb") {
|
|
|
ProcessBindingBase(argc, argv, baseSamplerBinding);
|
|
ProcessBindingBase(argc, argv, baseSamplerBinding);
|
|
|
|
|
+ } else if (lowerword == "shift-uav-bindings" || // synonyms
|
|
|
|
|
+ lowerword == "shift-uav-binding" ||
|
|
|
|
|
+ lowerword == "suavb") {
|
|
|
|
|
+ ProcessBindingBase(argc, argv, baseUavBinding);
|
|
|
} else if (lowerword == "shift-texture-bindings" || // synonyms
|
|
} else if (lowerword == "shift-texture-bindings" || // synonyms
|
|
|
lowerword == "shift-texture-binding" ||
|
|
lowerword == "shift-texture-binding" ||
|
|
|
lowerword == "stb") {
|
|
lowerword == "stb") {
|
|
|
ProcessBindingBase(argc, argv, baseTextureBinding);
|
|
ProcessBindingBase(argc, argv, baseTextureBinding);
|
|
|
- } else if (lowerword == "shift-image-bindings" || // synonyms
|
|
|
|
|
- lowerword == "shift-image-binding" ||
|
|
|
|
|
- lowerword == "sib") {
|
|
|
|
|
- ProcessBindingBase(argc, argv, baseImageBinding);
|
|
|
|
|
} else if (lowerword == "shift-ubo-bindings" || // synonyms
|
|
} else if (lowerword == "shift-ubo-bindings" || // synonyms
|
|
|
lowerword == "shift-ubo-binding" ||
|
|
lowerword == "shift-ubo-binding" ||
|
|
|
lowerword == "shift-cbuffer-bindings" ||
|
|
lowerword == "shift-cbuffer-bindings" ||
|
|
@@ -344,61 +410,48 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|
|
lowerword == "shift-ssbo-binding" ||
|
|
lowerword == "shift-ssbo-binding" ||
|
|
|
lowerword == "sbb") {
|
|
lowerword == "sbb") {
|
|
|
ProcessBindingBase(argc, argv, baseSsboBinding);
|
|
ProcessBindingBase(argc, argv, baseSsboBinding);
|
|
|
- } else if (lowerword == "resource-set-bindings" || // synonyms
|
|
|
|
|
- lowerword == "resource-set-binding" ||
|
|
|
|
|
- lowerword == "rsb") {
|
|
|
|
|
- ProcessResourceSetBindingBase(argc, argv, baseResourceSetBinding);
|
|
|
|
|
- } else if (lowerword == "shift-uav-bindings" || // synonyms
|
|
|
|
|
- lowerword == "shift-uav-binding" ||
|
|
|
|
|
- lowerword == "suavb") {
|
|
|
|
|
- ProcessBindingBase(argc, argv, baseUavBinding);
|
|
|
|
|
- } else if (lowerword == "auto-map-bindings" || // synonyms
|
|
|
|
|
- lowerword == "auto-map-binding" ||
|
|
|
|
|
- lowerword == "amb") {
|
|
|
|
|
- Options |= EOptionAutoMapBindings;
|
|
|
|
|
- } else if (lowerword == "flatten-uniform-arrays" || // synonyms
|
|
|
|
|
- lowerword == "flatten-uniform-array" ||
|
|
|
|
|
- lowerword == "fua") {
|
|
|
|
|
- Options |= EOptionFlattenUniformArrays;
|
|
|
|
|
- } else if (lowerword == "no-storage-format" || // synonyms
|
|
|
|
|
- lowerword == "nsf") {
|
|
|
|
|
- Options |= EOptionNoStorageFormat;
|
|
|
|
|
- } else if (lowerword == "variable-name" || // synonyms
|
|
|
|
|
- lowerword == "vn") {
|
|
|
|
|
- Options |= EOptionOutputHexadecimal;
|
|
|
|
|
- variableName = argv[1];
|
|
|
|
|
|
|
+ } else if (lowerword == "source-entrypoint" || // synonyms
|
|
|
|
|
+ lowerword == "sep") {
|
|
|
|
|
+ sourceEntryPointName = argv[1];
|
|
|
if (argc > 0) {
|
|
if (argc > 0) {
|
|
|
argc--;
|
|
argc--;
|
|
|
argv++;
|
|
argv++;
|
|
|
} else
|
|
} else
|
|
|
- Error("no <C-variable-name> provided for --variable-name");
|
|
|
|
|
|
|
+ Error("no <entry-point> provided for --source-entrypoint");
|
|
|
break;
|
|
break;
|
|
|
- } else if (lowerword == "source-entrypoint" || // synonyms
|
|
|
|
|
- lowerword == "sep") {
|
|
|
|
|
- sourceEntryPointName = argv[1];
|
|
|
|
|
|
|
+ } else if (lowerword == "variable-name" || // synonyms
|
|
|
|
|
+ lowerword == "vn") {
|
|
|
|
|
+ Options |= EOptionOutputHexadecimal;
|
|
|
|
|
+ variableName = argv[1];
|
|
|
if (argc > 0) {
|
|
if (argc > 0) {
|
|
|
argc--;
|
|
argc--;
|
|
|
argv++;
|
|
argv++;
|
|
|
} else
|
|
} else
|
|
|
- Error("no <entry-point> provided for --source-entrypoint");
|
|
|
|
|
|
|
+ Error("no <C-variable-name> provided for --variable-name");
|
|
|
break;
|
|
break;
|
|
|
- } else if (lowerword == "keep-uncalled" || // synonyms
|
|
|
|
|
- lowerword == "ku") {
|
|
|
|
|
- Options |= EOptionKeepUncalled;
|
|
|
|
|
- } else if (lowerword == "hlsl-offsets") {
|
|
|
|
|
- Options |= EOptionHlslOffsets;
|
|
|
|
|
- } else if (lowerword == "hlsl-iomap" ||
|
|
|
|
|
- lowerword == "hlsl-iomapper" ||
|
|
|
|
|
- lowerword == "hlsl-iomapping") {
|
|
|
|
|
- Options |= EOptionHlslIoMapping;
|
|
|
|
|
- } else if (lowerword == "auto-map-locations" || // synonyms
|
|
|
|
|
- lowerword == "aml") {
|
|
|
|
|
- Options |= EOptionAutoMapLocations;
|
|
|
|
|
} else {
|
|
} else {
|
|
|
usage();
|
|
usage();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case 'C':
|
|
|
|
|
+ Options |= EOptionCascadingErrors;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'D':
|
|
|
|
|
+ if (argv[0][2] == 0)
|
|
|
|
|
+ Options |= EOptionReadHlsl;
|
|
|
|
|
+ else
|
|
|
|
|
+ UserPreamble.addDef(getStringOperand("-D<macro> macro name"));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'E':
|
|
|
|
|
+ Options |= EOptionOutputPreprocessed;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'G':
|
|
|
|
|
+ Options |= EOptionSpv;
|
|
|
|
|
+ Options |= EOptionLinkProgram;
|
|
|
|
|
+ // undo a -H default to Vulkan
|
|
|
|
|
+ Options &= ~EOptionVulkanRules;
|
|
|
|
|
+ break;
|
|
|
case 'H':
|
|
case 'H':
|
|
|
Options |= EOptionHumanReadableSpv;
|
|
Options |= EOptionHumanReadableSpv;
|
|
|
if ((Options & EOptionSpv) == 0) {
|
|
if ((Options & EOptionSpv) == 0) {
|
|
@@ -409,16 +462,7 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case 'I':
|
|
case 'I':
|
|
|
- if (argv[0][2] == 0) {
|
|
|
|
|
- printf("include path must immediately follow (no spaces) -I\n");
|
|
|
|
|
- exit(EFailUsage);
|
|
|
|
|
- }
|
|
|
|
|
- IncludeDirectoryList.push_back(argv[0]+2);
|
|
|
|
|
- break;
|
|
|
|
|
- case 'V':
|
|
|
|
|
- Options |= EOptionSpv;
|
|
|
|
|
- Options |= EOptionVulkanRules;
|
|
|
|
|
- Options |= EOptionLinkProgram;
|
|
|
|
|
|
|
+ IncludeDirectoryList.push_back(getStringOperand("-I<dir> include path"));
|
|
|
break;
|
|
break;
|
|
|
case 'S':
|
|
case 'S':
|
|
|
shaderStageName = argv[1];
|
|
shaderStageName = argv[1];
|
|
@@ -428,27 +472,20 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
|
|
} else
|
|
} else
|
|
|
Error("no <stage> specified for -S");
|
|
Error("no <stage> specified for -S");
|
|
|
break;
|
|
break;
|
|
|
- case 'G':
|
|
|
|
|
|
|
+ case 'U':
|
|
|
|
|
+ UserPreamble.addUndef(getStringOperand("-U<macro>: macro name"));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'V':
|
|
|
Options |= EOptionSpv;
|
|
Options |= EOptionSpv;
|
|
|
|
|
+ Options |= EOptionVulkanRules;
|
|
|
Options |= EOptionLinkProgram;
|
|
Options |= EOptionLinkProgram;
|
|
|
- // undo a -H default to Vulkan
|
|
|
|
|
- Options &= ~EOptionVulkanRules;
|
|
|
|
|
- break;
|
|
|
|
|
- case 'E':
|
|
|
|
|
- Options |= EOptionOutputPreprocessed;
|
|
|
|
|
break;
|
|
break;
|
|
|
case 'c':
|
|
case 'c':
|
|
|
Options |= EOptionDumpConfig;
|
|
Options |= EOptionDumpConfig;
|
|
|
break;
|
|
break;
|
|
|
- case 'C':
|
|
|
|
|
- Options |= EOptionCascadingErrors;
|
|
|
|
|
- break;
|
|
|
|
|
case 'd':
|
|
case 'd':
|
|
|
Options |= EOptionDefaultDesktop;
|
|
Options |= EOptionDefaultDesktop;
|
|
|
break;
|
|
break;
|
|
|
- case 'D':
|
|
|
|
|
- Options |= EOptionReadHlsl;
|
|
|
|
|
- break;
|
|
|
|
|
case 'e':
|
|
case 'e':
|
|
|
// HLSL todo: entry point handle needs much more sophistication.
|
|
// HLSL todo: entry point handle needs much more sophistication.
|
|
|
// This is okay for one compilation unit with one entry point.
|
|
// This is okay for one compilation unit with one entry point.
|
|
@@ -590,36 +627,41 @@ void PutsIfNonEmpty(const char* str)
|
|
|
// This prevents erroneous newlines from appearing.
|
|
// This prevents erroneous newlines from appearing.
|
|
|
void StderrIfNonEmpty(const char* str)
|
|
void StderrIfNonEmpty(const char* str)
|
|
|
{
|
|
{
|
|
|
- if (str && str[0]) {
|
|
|
|
|
- fprintf(stderr, "%s\n", str);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (str && str[0])
|
|
|
|
|
+ fprintf(stderr, "%s\n", str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Simple bundling of what makes a compilation unit for ease in passing around,
|
|
// Simple bundling of what makes a compilation unit for ease in passing around,
|
|
|
// and separation of handling file IO versus API (programmatic) compilation.
|
|
// and separation of handling file IO versus API (programmatic) compilation.
|
|
|
struct ShaderCompUnit {
|
|
struct ShaderCompUnit {
|
|
|
EShLanguage stage;
|
|
EShLanguage stage;
|
|
|
- std::string fileName;
|
|
|
|
|
- char** text; // memory owned/managed externally
|
|
|
|
|
- const char* fileNameList[1];
|
|
|
|
|
|
|
+ static const int maxCount = 1;
|
|
|
|
|
+ int count; // live number of strings/names
|
|
|
|
|
+ const char* text[maxCount]; // memory owned/managed externally
|
|
|
|
|
+ std::string fileName[maxCount]; // hold's the memory, but...
|
|
|
|
|
+ const char* fileNameList[maxCount]; // downstream interface wants pointers
|
|
|
|
|
|
|
|
- // Need to have a special constructors to adjust the fileNameList, since back end needs a list of ptrs
|
|
|
|
|
- ShaderCompUnit(EShLanguage istage, std::string &ifileName, char** itext)
|
|
|
|
|
- {
|
|
|
|
|
- stage = istage;
|
|
|
|
|
- fileName = ifileName;
|
|
|
|
|
- text = itext;
|
|
|
|
|
- fileNameList[0] = fileName.c_str();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ShaderCompUnit(EShLanguage stage) : stage(stage), count(0) { }
|
|
|
|
|
|
|
|
- ShaderCompUnit(const ShaderCompUnit &rhs)
|
|
|
|
|
|
|
+ ShaderCompUnit(const ShaderCompUnit& rhs)
|
|
|
{
|
|
{
|
|
|
stage = rhs.stage;
|
|
stage = rhs.stage;
|
|
|
- fileName = rhs.fileName;
|
|
|
|
|
- text = rhs.text;
|
|
|
|
|
- fileNameList[0] = fileName.c_str();
|
|
|
|
|
|
|
+ count = rhs.count;
|
|
|
|
|
+ for (int i = 0; i < count; ++i) {
|
|
|
|
|
+ fileName[i] = rhs.fileName[i];
|
|
|
|
|
+ text[i] = rhs.text[i];
|
|
|
|
|
+ fileNameList[i] = rhs.fileName[i].c_str();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void addString(std::string& ifileName, const char* itext)
|
|
|
|
|
+ {
|
|
|
|
|
+ assert(count < maxCount);
|
|
|
|
|
+ fileName[count] = ifileName;
|
|
|
|
|
+ text[count] = itext;
|
|
|
|
|
+ fileNameList[count] = fileName[count].c_str();
|
|
|
|
|
+ ++count;
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
//
|
|
//
|
|
@@ -646,11 +688,13 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|
|
for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) {
|
|
for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) {
|
|
|
const auto &compUnit = *it;
|
|
const auto &compUnit = *it;
|
|
|
glslang::TShader* shader = new glslang::TShader(compUnit.stage);
|
|
glslang::TShader* shader = new glslang::TShader(compUnit.stage);
|
|
|
- shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, 1);
|
|
|
|
|
|
|
+ shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, compUnit.count);
|
|
|
if (entryPointName) // HLSL todo: this needs to be tracked per compUnits
|
|
if (entryPointName) // HLSL todo: this needs to be tracked per compUnits
|
|
|
shader->setEntryPoint(entryPointName);
|
|
shader->setEntryPoint(entryPointName);
|
|
|
if (sourceEntryPointName)
|
|
if (sourceEntryPointName)
|
|
|
shader->setSourceEntryPoint(sourceEntryPointName);
|
|
shader->setSourceEntryPoint(sourceEntryPointName);
|
|
|
|
|
+ if (UserPreamble.isSet())
|
|
|
|
|
+ shader->setPreamble(UserPreamble.get());
|
|
|
|
|
|
|
|
shader->setShiftSamplerBinding(baseSamplerBinding[compUnit.stage]);
|
|
shader->setShiftSamplerBinding(baseSamplerBinding[compUnit.stage]);
|
|
|
shader->setShiftTextureBinding(baseTextureBinding[compUnit.stage]);
|
|
shader->setShiftTextureBinding(baseTextureBinding[compUnit.stage]);
|
|
@@ -697,7 +741,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|
|
|
|
|
|
|
if (! (Options & EOptionSuppressInfolog) &&
|
|
if (! (Options & EOptionSuppressInfolog) &&
|
|
|
! (Options & EOptionMemoryLeakMode)) {
|
|
! (Options & EOptionMemoryLeakMode)) {
|
|
|
- PutsIfNonEmpty(compUnit.fileName.c_str());
|
|
|
|
|
|
|
+ PutsIfNonEmpty(compUnit.fileName[0].c_str());
|
|
|
PutsIfNonEmpty(shader->getInfoLog());
|
|
PutsIfNonEmpty(shader->getInfoLog());
|
|
|
PutsIfNonEmpty(shader->getInfoDebugLog());
|
|
PutsIfNonEmpty(shader->getInfoDebugLog());
|
|
|
}
|
|
}
|
|
@@ -798,17 +842,11 @@ void CompileAndLinkShaderFiles(glslang::TWorklist& Worklist)
|
|
|
// they are all getting linked together.)
|
|
// they are all getting linked together.)
|
|
|
glslang::TWorkItem* workItem;
|
|
glslang::TWorkItem* workItem;
|
|
|
while (Worklist.remove(workItem)) {
|
|
while (Worklist.remove(workItem)) {
|
|
|
- ShaderCompUnit compUnit(
|
|
|
|
|
- FindLanguage(workItem->name),
|
|
|
|
|
- workItem->name,
|
|
|
|
|
- ReadFileData(workItem->name.c_str())
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- if (! compUnit.text) {
|
|
|
|
|
|
|
+ ShaderCompUnit compUnit(FindLanguage(workItem->name));
|
|
|
|
|
+ char* fileText = ReadFileData(workItem->name.c_str());
|
|
|
|
|
+ if (fileText == nullptr)
|
|
|
usage();
|
|
usage();
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ compUnit.addString(workItem->name, fileText);
|
|
|
compUnits.push_back(compUnit);
|
|
compUnits.push_back(compUnit);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -823,8 +861,10 @@ void CompileAndLinkShaderFiles(glslang::TWorklist& Worklist)
|
|
|
glslang::OS_DumpMemoryCounters();
|
|
glslang::OS_DumpMemoryCounters();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // free memory from ReadFileData, which got stored in a const char*
|
|
|
|
|
+ // as the first string above
|
|
|
for (auto it = compUnits.begin(); it != compUnits.end(); ++it)
|
|
for (auto it = compUnits.begin(); it != compUnits.end(); ++it)
|
|
|
- FreeFileData(it->text);
|
|
|
|
|
|
|
+ FreeFileData(const_cast<char*>(it->text[0]));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int C_DECL main(int argc, char* argv[])
|
|
int C_DECL main(int argc, char* argv[])
|
|
@@ -974,29 +1014,22 @@ EShLanguage FindLanguage(const std::string& name, bool parseSuffix)
|
|
|
void CompileFile(const char* fileName, ShHandle compiler)
|
|
void CompileFile(const char* fileName, ShHandle compiler)
|
|
|
{
|
|
{
|
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
- char** shaderStrings = ReadFileData(fileName);
|
|
|
|
|
- if (! shaderStrings) {
|
|
|
|
|
- usage();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- int* lengths = new int[NumShaderStrings];
|
|
|
|
|
|
|
+ char* shaderString = ReadFileData(fileName);
|
|
|
|
|
|
|
|
// move to length-based strings, rather than null-terminated strings
|
|
// move to length-based strings, rather than null-terminated strings
|
|
|
- for (int s = 0; s < NumShaderStrings; ++s)
|
|
|
|
|
- lengths[s] = (int)strlen(shaderStrings[s]);
|
|
|
|
|
-
|
|
|
|
|
- if (! shaderStrings) {
|
|
|
|
|
- CompileFailed = true;
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ int* lengths = new int[1];
|
|
|
|
|
+ lengths[0] = (int)strlen(shaderString);
|
|
|
|
|
|
|
|
EShMessages messages = EShMsgDefault;
|
|
EShMessages messages = EShMsgDefault;
|
|
|
SetMessageOptions(messages);
|
|
SetMessageOptions(messages);
|
|
|
|
|
|
|
|
|
|
+ if (UserPreamble.isSet())
|
|
|
|
|
+ Error("-D and -U options require -l (linking)\n");
|
|
|
|
|
+
|
|
|
for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
|
|
for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
|
|
|
for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) {
|
|
for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) {
|
|
|
// ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
|
// ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
|
|
- ret = ShCompile(compiler, shaderStrings, NumShaderStrings, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
|
|
|
|
|
|
+ ret = ShCompile(compiler, &shaderString, 1, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
|
|
// const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err",
|
|
// const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err",
|
|
|
// "or should be l", "ine 1", "string 5\n", "float glo", "bal",
|
|
// "or should be l", "ine 1", "string 5\n", "float glo", "bal",
|
|
|
// ";\n#error should be line 2\n void main() {", "global = 2.3;}" };
|
|
// ";\n#error should be line 2\n void main() {", "global = 2.3;}" };
|
|
@@ -1009,7 +1042,7 @@ void CompileFile(const char* fileName, ShHandle compiler)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
delete [] lengths;
|
|
delete [] lengths;
|
|
|
- FreeFileData(shaderStrings);
|
|
|
|
|
|
|
+ FreeFileData(shaderString);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
if (ret == 0)
|
|
|
CompileFailed = true;
|
|
CompileFailed = true;
|
|
@@ -1022,8 +1055,8 @@ void usage()
|
|
|
{
|
|
{
|
|
|
printf("Usage: glslangValidator [option]... [file]...\n"
|
|
printf("Usage: glslangValidator [option]... [file]...\n"
|
|
|
"\n"
|
|
"\n"
|
|
|
- "Where: each 'file' ends in .<stage>, where <stage> is one of\n"
|
|
|
|
|
- " .conf to provide an optional config file that replaces the default configuration\n"
|
|
|
|
|
|
|
+ "'file' can end in .<stage> for auto-stage classification, where <stage> is:\n"
|
|
|
|
|
+ " .conf to provide a config file that replaces the default configuration\n"
|
|
|
" (see -c option below for generating a template)\n"
|
|
" (see -c option below for generating a template)\n"
|
|
|
" .vert for a vertex shader\n"
|
|
" .vert for a vertex shader\n"
|
|
|
" .tesc for a tessellation control shader\n"
|
|
" .tesc for a tessellation control shader\n"
|
|
@@ -1032,27 +1065,27 @@ void usage()
|
|
|
" .frag for a fragment shader\n"
|
|
" .frag for a fragment shader\n"
|
|
|
" .comp for a compute shader\n"
|
|
" .comp for a compute shader\n"
|
|
|
"\n"
|
|
"\n"
|
|
|
- "Compilation warnings and errors will be printed to stdout.\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- "To get other information, use one of the following options:\n"
|
|
|
|
|
- "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"
|
|
|
|
|
|
|
+ "Options:\n"
|
|
|
|
|
+ " -C cascading errors; risk crash from accumulation of error recoveries\n"
|
|
|
|
|
+ " -D input is HLSL\n"
|
|
|
|
|
+ " -D<macro=def>\n"
|
|
|
|
|
+ " -D<macro> define a pre-processor macro\n"
|
|
|
|
|
+ " -E print pre-processed GLSL; cannot be used with -l;\n"
|
|
|
|
|
+ " errors will appear on stderr.\n"
|
|
|
" -G create SPIR-V binary, under OpenGL semantics; turns on -l;\n"
|
|
" -G create SPIR-V binary, under OpenGL semantics; turns on -l;\n"
|
|
|
" default file name is <stage>.spv (-o overrides this)\n"
|
|
" default file name is <stage>.spv (-o overrides this)\n"
|
|
|
" -H print human readable form of SPIR-V; turns on -V\n"
|
|
" -H print human readable form of SPIR-V; turns on -V\n"
|
|
|
" -I<dir> add dir to the include search path; includer's directory\n"
|
|
" -I<dir> add dir to the include search path; includer's directory\n"
|
|
|
" is searched first, followed by left-to-right order of -I\n"
|
|
" is searched first, followed by left-to-right order of -I\n"
|
|
|
- " -E print pre-processed GLSL; cannot be used with -l;\n"
|
|
|
|
|
- " errors will appear on stderr.\n"
|
|
|
|
|
" -S <stage> uses specified stage rather than parsing the file extension\n"
|
|
" -S <stage> uses specified stage rather than parsing the file extension\n"
|
|
|
- " valid choices for <stage> are vert, tesc, tese, geom, frag, or comp\n"
|
|
|
|
|
|
|
+ " choices for <stage> are vert, tesc, tese, geom, frag, or comp\n"
|
|
|
|
|
+ " -U<macro> undefine a pre-precossor macro\n"
|
|
|
|
|
+ " -V create SPIR-V binary, under Vulkan semantics; turns on -l;\n"
|
|
|
|
|
+ " default file name is <stage>.spv (-o overrides this)\n"
|
|
|
" -c configuration dump;\n"
|
|
" -c configuration dump;\n"
|
|
|
" creates the default configuration file (redirect to a .conf file)\n"
|
|
" creates the default configuration file (redirect to a .conf file)\n"
|
|
|
- " -C cascading errors; risks crashes from accumulation of error recoveries\n"
|
|
|
|
|
" -d default to desktop (#version 110) when there is no shader #version\n"
|
|
" -d default to desktop (#version 110) when there is no shader #version\n"
|
|
|
" (default is ES version 100)\n"
|
|
" (default is ES version 100)\n"
|
|
|
- " -D input is HLSL\n"
|
|
|
|
|
" -e specify entry-point name\n"
|
|
" -e specify entry-point name\n"
|
|
|
" -g generate debug information\n"
|
|
" -g generate debug information\n"
|
|
|
" -h print this usage message\n"
|
|
" -h print this usage message\n"
|
|
@@ -1066,59 +1099,46 @@ void usage()
|
|
|
" -t multi-threaded mode\n"
|
|
" -t multi-threaded mode\n"
|
|
|
" -v print version strings\n"
|
|
" -v print version strings\n"
|
|
|
" -w suppress warnings (except as required by #extension : warn)\n"
|
|
" -w suppress warnings (except as required by #extension : warn)\n"
|
|
|
- " -x save 32-bit hexadecimal numbers as text, requires a binary option (e.g., -V)\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --shift-sampler-binding [stage] num set base binding number for samplers\n"
|
|
|
|
|
- " --ssb [stage] num synonym for --shift-sampler-binding\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --shift-texture-binding [stage] num set base binding number for textures\n"
|
|
|
|
|
- " --stb [stage] num synonym for --shift-texture-binding\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --shift-image-binding [stage] num set base binding number for images (uav)\n"
|
|
|
|
|
- " --sib [stage] num synonym for --shift-image-binding\n"
|
|
|
|
|
|
|
+ " -x save binary output as text-based 32-bit hexadecimal numbers\n"
|
|
|
|
|
+ " --auto-map-bindings automatically bind uniform variables\n"
|
|
|
|
|
+ " without explicit bindings.\n"
|
|
|
|
|
+ " --amb synonym for --auto-map-bindings\n"
|
|
|
|
|
+ " --auto-map-locations automatically locate input/output lacking\n"
|
|
|
|
|
+ " 'location'\n (fragile, not cross stage)\n"
|
|
|
|
|
+ " --aml synonym for --auto-map-locations\n"
|
|
|
|
|
+ " --flatten-uniform-arrays flatten uniform texture/sampler arrays to\n"
|
|
|
|
|
+ " scalars\n"
|
|
|
|
|
+ " --fua synonym for --flatten-uniform-arrays\n"
|
|
|
"\n"
|
|
"\n"
|
|
|
- " --shift-UBO-binding [stage] num set base binding number for UBOs\n"
|
|
|
|
|
- " --shift-cbuffer-binding [stage] num synonym for --shift-UBO-binding\n"
|
|
|
|
|
- " --sub [stage] num synonym for --shift-UBO-binding\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --shift-ssbo-binding [stage] num set base binding number for SSBOs\n"
|
|
|
|
|
- " --sbb [stage] num synonym for --shift-ssbo-binding\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --resource-set-binding [stage] num set descriptor set and binding number for resources\n"
|
|
|
|
|
- " --rsb [stage] type set binding synonym for --resource-set-binding\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --shift-uav-binding [stage] num set base binding number for UAVs\n"
|
|
|
|
|
- " --suavb [stage] num synonym for --shift-uav-binding\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --auto-map-bindings automatically bind uniform variables without\n"
|
|
|
|
|
- " explicit bindings.\n"
|
|
|
|
|
- " --amb synonym for --auto-map-bindings\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --auto-map-locations automatically locate input/output lacking 'location'\n"
|
|
|
|
|
- " (fragile, not cross stage: recommend explicit\n"
|
|
|
|
|
- " 'location' use in shader)\n"
|
|
|
|
|
- " --aml synonym for --auto-map-locations\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --flatten-uniform-arrays flatten uniform texture & sampler arrays to scalars\n"
|
|
|
|
|
- " --fua synonym for --flatten-uniform-arrays\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --no-storage-format use Unknown image format\n"
|
|
|
|
|
- " --nsf synonym for --no-storage-format\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --source-entrypoint name the given shader source function is renamed to be the entry point given in -e\n"
|
|
|
|
|
- " --sep synonym for --source-entrypoint\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --keep-uncalled don't eliminate uncalled functions when linking\n"
|
|
|
|
|
- " --ku synonym for --keep-uncalled\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --variable-name <name> Creates a C header file that contains a uint32_t array named <name>\n"
|
|
|
|
|
- " initialized with the shader binary code.\n"
|
|
|
|
|
- " --vn <name> synonym for --variable-name <name>\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --hlsl-offsets Allow block offsets to follow HLSL rules instead of GLSL rules.\n"
|
|
|
|
|
- " Works independently of source language.\n"
|
|
|
|
|
- "\n"
|
|
|
|
|
- " --hlsl-iomap Perform IO mapping in HLSL register space.\n"
|
|
|
|
|
|
|
+ " --hlsl-offsets Allow block offsets to follow HLSL rules\n"
|
|
|
|
|
+ " Works independently of source language\n"
|
|
|
|
|
+ " --hlsl-iomap Perform IO mapping in HLSL register space\n"
|
|
|
|
|
+ " --keep-uncalled don't eliminate uncalled functions\n"
|
|
|
|
|
+ " --ku synonym for --keep-uncalled\n"
|
|
|
|
|
+ " --no-storage-format use Unknown image format\n"
|
|
|
|
|
+ " --nsf synonym for --no-storage-format\n"
|
|
|
|
|
+ " --resource-set-binding [stage] num descriptor set and binding for resources\n"
|
|
|
|
|
+ " --rsb [stage] type set binding synonym for --resource-set-binding\n"
|
|
|
|
|
+ " --shift-image-binding [stage] num base binding number for images (uav)\n"
|
|
|
|
|
+ " --sib [stage] num synonym for --shift-image-binding\n"
|
|
|
|
|
+ " --shift-sampler-binding [stage] num base binding number for samplers\n"
|
|
|
|
|
+ " --ssb [stage] num synonym for --shift-sampler-binding\n"
|
|
|
|
|
+ " --shift-ssbo-binding [stage] num base binding number for SSBOs\n"
|
|
|
|
|
+ " --sbb [stage] num synonym for --shift-ssbo-binding\n"
|
|
|
|
|
+ " --shift-texture-binding [stage] num base binding number for textures\n"
|
|
|
|
|
+ " --stb [stage] num synonym for --shift-texture-binding\n"
|
|
|
|
|
+ " --shift-uav-binding [stage] num base binding number for UAVs\n"
|
|
|
|
|
+ " --suavb [stage] num synonym for --shift-uav-binding\n"
|
|
|
|
|
+ " --shift-UBO-binding [stage] num base binding number for UBOs\n"
|
|
|
|
|
+ " --shift-cbuffer-binding [stage] num synonym for --shift-UBO-binding\n"
|
|
|
|
|
+ " --sub [stage] num synonym for --shift-UBO-binding\n"
|
|
|
|
|
+ " --source-entrypoint name the given shader source function is\n"
|
|
|
|
|
+ " renamed to be the entry point given in -e\n"
|
|
|
|
|
+ " --sep synonym for --source-entrypoint\n"
|
|
|
|
|
+ " --variable-name <name> Creates a C header file that contains a\n"
|
|
|
|
|
+ " uint32_t array named <name>\n"
|
|
|
|
|
+ " initialized with the shader binary code.\n"
|
|
|
|
|
+ " --vn <name> synonym for --variable-name <name>\n"
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
exit(EFailUsage);
|
|
exit(EFailUsage);
|
|
@@ -1156,76 +1176,33 @@ int fopen_s(
|
|
|
//
|
|
//
|
|
|
// Malloc a string of sufficient size and read a string into it.
|
|
// Malloc a string of sufficient size and read a string into it.
|
|
|
//
|
|
//
|
|
|
-char** ReadFileData(const char* fileName)
|
|
|
|
|
|
|
+char* ReadFileData(const char* fileName)
|
|
|
{
|
|
{
|
|
|
FILE *in = nullptr;
|
|
FILE *in = nullptr;
|
|
|
int errorCode = fopen_s(&in, fileName, "r");
|
|
int errorCode = fopen_s(&in, fileName, "r");
|
|
|
-
|
|
|
|
|
- int count = 0;
|
|
|
|
|
- const int maxSourceStrings = 5; // for testing splitting shader/tokens across multiple strings
|
|
|
|
|
- char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); // freed in FreeFileData()
|
|
|
|
|
-
|
|
|
|
|
if (errorCode || in == nullptr)
|
|
if (errorCode || in == nullptr)
|
|
|
Error("unable to open input file");
|
|
Error("unable to open input file");
|
|
|
|
|
|
|
|
|
|
+ int count = 0;
|
|
|
while (fgetc(in) != EOF)
|
|
while (fgetc(in) != EOF)
|
|
|
count++;
|
|
count++;
|
|
|
|
|
|
|
|
fseek(in, 0, SEEK_SET);
|
|
fseek(in, 0, SEEK_SET);
|
|
|
|
|
|
|
|
- char *fdata = (char*)malloc(count+2); // freed before return of this function
|
|
|
|
|
- if (! fdata)
|
|
|
|
|
- Error("can't allocate memory");
|
|
|
|
|
-
|
|
|
|
|
- if ((int)fread(fdata, 1, count, in) != count) {
|
|
|
|
|
- free(fdata);
|
|
|
|
|
|
|
+ char* return_data = (char*)malloc(count + 1); // freed in FreeFileData()
|
|
|
|
|
+ if ((int)fread(return_data, 1, count, in) != count) {
|
|
|
|
|
+ free(return_data);
|
|
|
Error("can't read input file");
|
|
Error("can't read input file");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fdata[count] = '\0';
|
|
|
|
|
|
|
+ return_data[count] = '\0';
|
|
|
fclose(in);
|
|
fclose(in);
|
|
|
|
|
|
|
|
- if (count == 0) {
|
|
|
|
|
- // recover from empty file
|
|
|
|
|
- return_data[0] = (char*)malloc(count+2); // freed in FreeFileData()
|
|
|
|
|
- return_data[0][0]='\0';
|
|
|
|
|
- NumShaderStrings = 0;
|
|
|
|
|
- free(fdata);
|
|
|
|
|
-
|
|
|
|
|
- return return_data;
|
|
|
|
|
- } else
|
|
|
|
|
- NumShaderStrings = 1; // Set to larger than 1 for testing multiple strings
|
|
|
|
|
-
|
|
|
|
|
- // compute how to split up the file into multiple strings, for testing multiple strings
|
|
|
|
|
- int len = (int)(ceil)((float)count/(float)NumShaderStrings);
|
|
|
|
|
- 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;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- len = count;
|
|
|
|
|
- }
|
|
|
|
|
- ++i;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- free(fdata);
|
|
|
|
|
-
|
|
|
|
|
return return_data;
|
|
return return_data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void FreeFileData(char** data)
|
|
|
|
|
|
|
+void FreeFileData(char* data)
|
|
|
{
|
|
{
|
|
|
- for(int i = 0; i < NumShaderStrings; i++)
|
|
|
|
|
- free(data[i]);
|
|
|
|
|
-
|
|
|
|
|
free(data);
|
|
free(data);
|
|
|
}
|
|
}
|
|
|
|
|
|