Commit 62742f9e by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Optimize shader source macro replacement

@@ LAYOUT-xx @@ and @@ QUALIFIER-xx @@ macros are generated by the compiler when emitting Vulkan GLSL. These macros are replaced at link time in the Vulkan backend. Previously, this replacement was done through calls to angle::ReplaceSubstring, reiterating over the whole source on every replacement. This CL does a prepass on the input source and chunks it up in blocks. Search is optimized as only blocks of a certain type are string-compared (skipping large chunks of shader text). Replace is optimized as the whole shader is not shifted left or right on every replacement. Additionally, this CL modifies the layout macro to the following format: @@ LAYOUT-xx(extra, args) @@ This is used in a follow up CL to have the compiler provide additional layout qualifiers. Bug: angleproject:3220 Change-Id: I6367e781c3304d5f2e0a406e4fb4e6feb4c45f1d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1592070 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent be394bad
......@@ -57,7 +57,7 @@ std::vector<std::string> SplitString(const std::string &input,
if (resultType == SPLIT_WANT_ALL || !piece.empty())
{
result.push_back(piece);
result.push_back(std::move(piece));
}
}
......@@ -101,6 +101,26 @@ std::string TrimString(const std::string &input, const std::string &trimChars)
return input.substr(begin, end - begin + 1);
}
std::string GetPrefix(const std::string &input, size_t offset, const char *delimiter)
{
size_t match = input.find(delimiter, offset);
if (match == std::string::npos)
{
return input.substr(offset);
}
return input.substr(offset, match - offset);
}
std::string GetPrefix(const std::string &input, size_t offset, char delimiter)
{
size_t match = input.find(delimiter, offset);
if (match == std::string::npos)
{
return input.substr(offset);
}
return input.substr(offset, match - offset);
}
bool HexStringToUInt(const std::string &input, unsigned int *uintOut)
{
unsigned int offset = 0;
......
......@@ -41,6 +41,10 @@ void SplitStringAlongWhitespace(const std::string &input, std::vector<std::strin
std::string TrimString(const std::string &input, const std::string &trimChars);
// Return the substring starting at offset and up to the first occurance of the |delimeter|.
std::string GetPrefix(const std::string &input, size_t offset, const char *delimiter);
std::string GetPrefix(const std::string &input, size_t offset, char delimiter);
bool HexStringToUInt(const std::string &input, unsigned int *uintOut);
bool ReadFileToString(const std::string &path, std::string *stringOut);
......
......@@ -63,7 +63,7 @@ void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable)
if (needsCustomLayout)
{
out << "@@ LAYOUT-" << symbol->getName() << " @@";
out << "@@ LAYOUT-" << symbol->getName() << "() @@";
}
else
{
......
......@@ -667,7 +667,7 @@ void TranslatorVulkan::translate(TIntermBlock *root,
if (defaultUniformCount > 0)
{
sink << "\nlayout(@@ DEFAULT-UNIFORMS-SET-BINDING @@) uniform defaultUniforms\n{\n";
sink << "\n@@ LAYOUT-defaultUniforms() @@ uniform defaultUniforms\n{\n";
DeclareDefaultUniformsTraverser defaultTraverser(&sink, getHashFunction(), &getNameMap());
root->traverse(&defaultTraverser);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment