summaryrefslogtreecommitdiff
path: root/source/slang
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-03-02 17:03:16 -0500
committerGitHub <noreply@github.com>2021-03-02 14:03:16 -0800
commitc2653ba1ec8f06453f0653d141bcd348eff5d4a5 (patch)
tree85bfafed35844d5d2fe90a93f82eb0254045d416 /source/slang
parentb81e8d4c8b718e97c6d6fc65b09850f19fb80502 (diff)
Fix issue with long identifier names in GLSL output (#1731)
* #include an absolute path didn't work - because paths were taken to always be relative. * First pass at handling 'names' that are too long in GLSL output. * Test to check functionality with very long func name. * Add access a long names buffer. * Fix typo in assert. Fix issue with coercion error for 1.0f / 0x7fffffff Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-emit-c-like.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index d099af255..8e106fe55 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -620,6 +620,37 @@ void CLikeSourceEmitter::appendScrubbedName(const UnownedStringSlice& name, Stri
out.appendChar(c);
prevChar = c;
}
+
+ if (getSourceLanguage() == SourceLanguage::GLSL)
+ {
+ // It looks like the default glslang name limit is 1024, but let's go a little less so there is some wiggle room
+ const Index maxTokenLength = 1024 - 8;
+
+ const Index length = out.getLength();
+
+ if (length > maxTokenLength)
+ {
+ // We are going to output with a prefix and a hash of the full name
+ const HashCode64 hash = getStableHashCode64(out.getBuffer(), length);
+ // Two hex chars per byte
+ const Index hashSize = sizeof(hash) * 2;
+
+ // Work out a size that is within range taking into account the hash size and extra chars
+ Index reducedBaseLength = maxTokenLength - hashSize - 1;
+ // If it has a trailing _ remove it.
+ // We know because of scrubbing there can only be single _
+ reducedBaseLength -= Index(out[reducedBaseLength - 1] == '_');
+
+ // Reduce the length
+ out.reduceLength(reducedBaseLength);
+ // Let's add a _ to separate from the rest of the name
+ out.appendChar('_');
+ // Append the hash in hex
+ out.append(uint64_t(hash), 16);
+
+ SLANG_ASSERT(out.getLength() <= maxTokenLength);
+ }
+ }
}
String CLikeSourceEmitter::generateEntryPointNameImpl(IREntryPointDecoration* entryPointDecor)