summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-10-09 19:22:22 -0700
committerGitHub <noreply@github.com>2025-10-09 19:22:22 -0700
commita3372605363cfe511b5248cb1393f59b25cb2483 (patch)
treeb779f0e145cc2e4a1853401813937463586d973a
parente420f2f980813559b186a6a6bcd5540f74310d02 (diff)
Improve perf with `-separate-debug-info` (#8670)
When Slang form a new spirv code without the debug info, List container had to reserve the memory space before adding items in it. This improves the given repro test time from 56 minutes to 6 minutes.
-rw-r--r--source/slang/slang-emit.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index c57851bc2..1bd1f8b5c 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -2342,6 +2342,10 @@ public:
// we can read.
SlangResult loadBlob(ComPtr<IArtifact>& artifact)
{
+ m_nonSemanticDebugInfoExtSetId = 0;
+ m_words.clear();
+ m_headerWords.clear();
+
ComPtr<ISlangBlob> spirvBlob;
SlangResult res = artifact->loadBlob(ArtifactKeep::Yes, spirvBlob.writeRef());
if (SLANG_FAILED(res) || !spirvBlob ||
@@ -2349,7 +2353,6 @@ public:
return SLANG_FAIL;
// Populate the full array of SPIR-V words.
- m_words.clear();
m_words.addRange(
reinterpret_cast<const SpvWord*>(spirvBlob->getBufferPointer()),
spirvBlob->getBufferSize() / sizeof(SpvWord));
@@ -2363,7 +2366,9 @@ public:
}
// Get the header words.
- List<SpvWord> getHeaderWords() const { return m_headerWords; }
+ const List<SpvWord>& getHeaderWords() const { return m_headerWords; }
+
+ Index getWordCount() const { return m_words.getCount(); }
// Visit all SPIRV instructions (excluding header words), invoking the callback for each
// instruction. The callback should be a function or lambda with signature: void(const
@@ -2457,9 +2462,15 @@ static SlangResult stripDbgSpirvFromArtifact(
SpirvInstructionHelper spirvInstructionHelper;
SLANG_RETURN_ON_FAIL(spirvInstructionHelper.loadBlob(artifact));
- auto headerWords = spirvInstructionHelper.getHeaderWords();
+ const auto& headerWords = spirvInstructionHelper.getHeaderWords();
List<uint8_t> spirvWordsList;
+ if (auto totalWordCapacity = headerWords.getCount() + spirvInstructionHelper.getWordCount())
+ {
+ const Index byteCapacity = totalWordCapacity * sizeof(SpvWord);
+ spirvWordsList.reserve(byteCapacity);
+ }
+
spirvWordsList.addRange(
reinterpret_cast<const uint8_t*>(headerWords.getBuffer()),
headerWords.getCount() * sizeof(SpvWord));