mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-09 20:10:06 +00:00
Add flags for outputting absolute paths for messages (#3467)
Uses std::filesystem to create absolute paths. Also adds "shaderFileName" to TSinkBase so it can be used during message outputs.
This commit is contained in:
parent
e7d4ad91a9
commit
d73712b8f6
@ -182,6 +182,7 @@ bool HlslEnable16BitTypes = false;
|
||||
bool HlslDX9compatible = false;
|
||||
bool HlslDxPositionW = false;
|
||||
bool EnhancedMsgs = false;
|
||||
bool AbsolutePath = false;
|
||||
bool DumpBuiltinSymbols = false;
|
||||
std::vector<std::string> IncludeDirectoryList;
|
||||
|
||||
@ -727,6 +728,8 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
||||
HlslDxPositionW = true;
|
||||
} else if (lowerword == "enhanced-msgs") {
|
||||
EnhancedMsgs = true;
|
||||
} else if (lowerword == "absolute-path") {
|
||||
AbsolutePath = true;
|
||||
} else if (lowerword == "auto-sampled-textures") {
|
||||
autoSampledTextures = true;
|
||||
} else if (lowerword == "invert-y" || // synonyms
|
||||
@ -1159,6 +1162,8 @@ void SetMessageOptions(EShMessages& messages)
|
||||
messages = (EShMessages)(messages | EShMsgBuiltinSymbolTable);
|
||||
if (EnhancedMsgs)
|
||||
messages = (EShMessages)(messages | EShMsgEnhanced);
|
||||
if (AbsolutePath)
|
||||
messages = (EShMessages)(messages | EShMsgAbsolutePath);
|
||||
}
|
||||
|
||||
//
|
||||
@ -1190,6 +1195,7 @@ void CompileShaders(glslang::TWorklist& worklist)
|
||||
if (compiler == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
CompileFile(workItem->name.c_str(), compiler);
|
||||
|
||||
if (! (Options & EOptionSuppressInfolog))
|
||||
@ -1878,7 +1884,7 @@ void CompileFile(const char* fileName, ShHandle compiler)
|
||||
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, &shaderString, 1, nullptr, EShOptNone, GetResources(), 0,
|
||||
(Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
||||
(Options & EOptionDefaultDesktop) ? 110 : 100, false, messages, fileName);
|
||||
// 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;}" };
|
||||
@ -1993,6 +1999,7 @@ void usage()
|
||||
" without explicit bindings\n"
|
||||
" --auto-map-locations | --aml automatically locate input/output lacking\n"
|
||||
" 'location' (fragile, not cross stage)\n"
|
||||
" --absolute-path Prints absolute path for messages\n"
|
||||
" --auto-sampled-textures Removes sampler variables and converts\n"
|
||||
" existing textures to sampled textures\n"
|
||||
" --client {vulkan<ver>|opengl<ver>} see -V and -G\n"
|
||||
|
@ -205,6 +205,7 @@ static int c_shader_messages(glslang_messages_t messages)
|
||||
CONVERT_MSG(GLSLANG_MSG_HLSL_LEGALIZATION_BIT, EShMsgHlslLegalization);
|
||||
CONVERT_MSG(GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT, EShMsgHlslDX9Compatible);
|
||||
CONVERT_MSG(GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT, EShMsgBuiltinSymbolTable);
|
||||
CONVERT_MSG(GLSLANG_MSG_ABSOLUTE_PATH, EShMsgAbsolutePath);
|
||||
return res;
|
||||
#undef CONVERT_MSG
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#define _INFOSINK_INCLUDED_
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include <filesystem>
|
||||
#include <cmath>
|
||||
|
||||
namespace glslang {
|
||||
@ -67,7 +68,7 @@ enum TOutputStream {
|
||||
//
|
||||
class TInfoSinkBase {
|
||||
public:
|
||||
TInfoSinkBase() : outputStream(4) {}
|
||||
TInfoSinkBase() : outputStream(4), shaderFileName(nullptr) {}
|
||||
void erase() { sink.erase(); }
|
||||
TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
|
||||
@ -94,11 +95,22 @@ public:
|
||||
default: append("UNKNOWN ERROR: "); break;
|
||||
}
|
||||
}
|
||||
void location(const TSourceLoc& loc) {
|
||||
void location(const TSourceLoc& loc, bool absolute = false) {
|
||||
const int maxSize = 24;
|
||||
char locText[maxSize];
|
||||
snprintf(locText, maxSize, ":%d", loc.line);
|
||||
append(loc.getStringNameOrNum(false).c_str());
|
||||
|
||||
if(loc.getFilename() == nullptr && shaderFileName != nullptr && absolute) {
|
||||
append(std::filesystem::absolute(shaderFileName).string());
|
||||
} else {
|
||||
std::string location = loc.getStringNameOrNum(false);
|
||||
if (absolute) {
|
||||
append(std::filesystem::absolute(location).string());
|
||||
} else {
|
||||
append(location);
|
||||
}
|
||||
}
|
||||
|
||||
append(locText);
|
||||
append(": ");
|
||||
}
|
||||
@ -119,6 +131,11 @@ public:
|
||||
outputStream = output;
|
||||
}
|
||||
|
||||
void setShaderFileName(const char* file = nullptr)
|
||||
{
|
||||
shaderFileName = file;
|
||||
}
|
||||
|
||||
protected:
|
||||
void append(const char* s);
|
||||
|
||||
@ -131,6 +148,7 @@ protected:
|
||||
void appendToStream(const char* s);
|
||||
TPersistString sink;
|
||||
int outputStream;
|
||||
const char* shaderFileName;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
@ -174,6 +174,7 @@ typedef enum {
|
||||
GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT = (1 << 13),
|
||||
GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT = (1 << 14),
|
||||
GLSLANG_MSG_ENHANCED = (1 << 15),
|
||||
GLSLANG_MSG_ABSOLUTE_PATH = (1 << 16),
|
||||
LAST_ELEMENT_MARKER(GLSLANG_MSG_COUNT),
|
||||
} glslang_messages_t;
|
||||
|
||||
|
@ -59,7 +59,7 @@ void TParseContextBase::outputMessage(const TSourceLoc& loc, const char* szReaso
|
||||
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
|
||||
|
||||
infoSink.info.prefix(prefix);
|
||||
infoSink.info.location(loc);
|
||||
infoSink.info.location(loc, messages & EShMsgAbsolutePath);
|
||||
infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";
|
||||
|
||||
if (prefix == EPrefixError) {
|
||||
|
@ -1434,7 +1434,8 @@ int ShCompile(
|
||||
int /*debugOptions*/,
|
||||
int defaultVersion, // use 100 for ES environment, 110 for desktop
|
||||
bool forwardCompatible, // give errors for use of deprecated features
|
||||
EShMessages messages // warnings/errors/AST; things to print out
|
||||
EShMessages messages, // warnings/errors/AST; things to print out,
|
||||
const char *shaderFileName // the filename
|
||||
)
|
||||
{
|
||||
// Map the generic handle to the C++ object
|
||||
@ -1450,6 +1451,9 @@ int ShCompile(
|
||||
|
||||
compiler->infoSink.info.erase();
|
||||
compiler->infoSink.debug.erase();
|
||||
compiler->infoSink.info.setShaderFileName(shaderFileName);
|
||||
compiler->infoSink.debug.setShaderFileName(shaderFileName);
|
||||
|
||||
|
||||
TIntermediate intermediate(compiler->getLanguage());
|
||||
TShader::ForbidIncluder includer;
|
||||
|
@ -269,6 +269,7 @@ enum EShMessages : unsigned {
|
||||
EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics)
|
||||
EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table
|
||||
EShMsgEnhanced = (1 << 15), // enhanced message readability
|
||||
EShMsgAbsolutePath = (1 << 16), // Output Absolute path for messages
|
||||
LAST_ELEMENT_MARKER(EShMsgCount),
|
||||
};
|
||||
|
||||
@ -335,7 +336,8 @@ GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[],
|
||||
int, // debugOptions unused
|
||||
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
|
||||
bool forwardCompatible = false, // give errors for use of deprecated features
|
||||
EShMessages messages = EShMsgDefault // warnings and errors
|
||||
EShMessages messages = EShMsgDefault, // warnings and errors
|
||||
const char* fileName = nullptr
|
||||
);
|
||||
|
||||
GLSLANG_EXPORT int ShLinkExt(
|
||||
|
Loading…
Reference in New Issue
Block a user