summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorjarcherNV <jarcher@nvidia.com>2025-06-06 14:30:06 -0700
committerGitHub <noreply@github.com>2025-06-06 14:30:06 -0700
commit0d16228ae22fa2e1a00e62dc099eea08da7717fe (patch)
tree067573914132892dc1336dcdea2c8b595f24f871 /source/compiler-core
parent649d533727b31b28397ffb3a530e655ac3861547 (diff)
Add command line option for separate debug info (#7178)
* Add command line option for separate debug info Add command line arg -separate-debug-info which, if provided, produces both a .spv and a .dbg.spv file. The .dbg.spv file contains full debug info and the .spv file has all debug info stripped out. Also add a DebugBuildIdentifier instruction to store a unique hash in both the output files, so they can be more easily matched together. A matching API is provided to allow using the Slang API to retrieve a base and debug SPIRV as well as the debug build identifier string.
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-artifact-associated-impl.cpp5
-rw-r--r--source/compiler-core/slang-artifact-associated-impl.h3
-rw-r--r--source/compiler-core/slang-artifact-associated.h3
-rw-r--r--source/compiler-core/slang-artifact-impl.cpp42
-rw-r--r--source/compiler-core/slang-artifact-impl.h6
-rw-r--r--source/compiler-core/slang-artifact.h5
-rw-r--r--source/compiler-core/slang-spirv-core-grammar.h1
7 files changed, 64 insertions, 1 deletions
diff --git a/source/compiler-core/slang-artifact-associated-impl.cpp b/source/compiler-core/slang-artifact-associated-impl.cpp
index 88ed9f665..11bfec8bc 100644
--- a/source/compiler-core/slang-artifact-associated-impl.cpp
+++ b/source/compiler-core/slang-artifact-associated-impl.cpp
@@ -339,5 +339,10 @@ SlangResult ArtifactPostEmitMetadata::isParameterLocationUsed(
return SLANG_OK;
}
+const char* ArtifactPostEmitMetadata::getDebugBuildIdentifier()
+{
+ return m_debugBuildIdentifier.getBuffer();
+}
+
} // namespace Slang
diff --git a/source/compiler-core/slang-artifact-associated-impl.h b/source/compiler-core/slang-artifact-associated-impl.h
index 0418b2018..6ae01626a 100644
--- a/source/compiler-core/slang-artifact-associated-impl.h
+++ b/source/compiler-core/slang-artifact-associated-impl.h
@@ -198,6 +198,8 @@ public:
SlangUInt registerIndex, // `register` for D3D12, `binding` for Vulkan
bool& outUsed) SLANG_OVERRIDE;
+ SLANG_NO_THROW virtual const char* SLANG_MCALL getDebugBuildIdentifier() SLANG_OVERRIDE;
+
void* getInterface(const Guid& uuid);
void* getObject(const Guid& uuid);
@@ -208,6 +210,7 @@ public:
List<ShaderBindingRange> m_usedBindings;
List<String> m_exportedFunctionMangledNames;
+ String m_debugBuildIdentifier;
};
} // namespace Slang
diff --git a/source/compiler-core/slang-artifact-associated.h b/source/compiler-core/slang-artifact-associated.h
index c8e74f98b..05d3f8ec4 100644
--- a/source/compiler-core/slang-artifact-associated.h
+++ b/source/compiler-core/slang-artifact-associated.h
@@ -138,6 +138,9 @@ public:
/// Get the list of functions that were exported in the linked IR
SLANG_NO_THROW virtual Slice<String> SLANG_MCALL getExportedFunctionMangledNames() = 0;
+
+ /// Get the debug build identifier for a base and debug spirv pair
+ SLANG_NO_THROW virtual const char* SLANG_MCALL getDebugBuildIdentifier() = 0;
};
} // namespace Slang
diff --git a/source/compiler-core/slang-artifact-impl.cpp b/source/compiler-core/slang-artifact-impl.cpp
index 31c01f1de..1aed32cea 100644
--- a/source/compiler-core/slang-artifact-impl.cpp
+++ b/source/compiler-core/slang-artifact-impl.cpp
@@ -170,6 +170,48 @@ void Artifact::removeAt(ContainedKind kind, Index i)
}
}
+uint32_t Artifact::getItemCount()
+{
+ // Ignore the metadata when counting items, and the base artifact is item 0.
+ uint32_t count = 1;
+ for (auto artifact : m_associated)
+ if (artifact->getDesc().payload != ArtifactPayload::Metadata &&
+ artifact->getDesc().payload != ArtifactPayload::PostEmitMetadata)
+ count++;
+ return count;
+}
+
+SlangResult Artifact::getItemData(uint32_t index, slang::IBlob** outblob)
+{
+ // Item 0 is the base artifact, otherwise iterate and ignore the metadata.
+ if (index == 0)
+ return loadBlob(ArtifactKeep::Yes, outblob);
+
+ uint32_t count = 1;
+ for (auto artifact : m_associated)
+ {
+ if (artifact->getDesc().payload == ArtifactPayload::Metadata ||
+ artifact->getDesc().payload == ArtifactPayload::PostEmitMetadata)
+ continue;
+ if (count == index)
+ return artifact->loadBlob(ArtifactKeep::Yes, outblob);
+ count++;
+ }
+ return SLANG_FAIL;
+}
+
+SlangResult Artifact::getMetadata(slang::IMetadata** outMetadata)
+{
+ // Find and return the associated metadata artifact.
+ auto metadata = findAssociatedRepresentation<IArtifactPostEmitMetadata>(this);
+ if (!metadata)
+ return SLANG_E_NOT_AVAILABLE;
+
+ *outMetadata = static_cast<slang::IMetadata*>(metadata);
+ (*outMetadata)->addRef();
+ return SLANG_OK;
+}
+
SlangResult Artifact::getOrCreateRepresentation(
const Guid& typeGuid,
ArtifactKeep keep,
diff --git a/source/compiler-core/slang-artifact-impl.h b/source/compiler-core/slang-artifact-impl.h
index a307a9d6d..8df105953 100644
--- a/source/compiler-core/slang-artifact-impl.h
+++ b/source/compiler-core/slang-artifact-impl.h
@@ -94,6 +94,12 @@ public:
return ComPtr<IArtifact>(new Artifact(desc, name));
}
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL getItemCount() SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ getItemData(uint32_t index, slang::IBlob** outblob) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getMetadata(slang::IMetadata** outMetadata)
+ SLANG_OVERRIDE;
+
protected:
/// Ctor
Artifact(const Desc& desc, const UnownedStringSlice& name)
diff --git a/source/compiler-core/slang-artifact.h b/source/compiler-core/slang-artifact.h
index 46e8831ff..5f69182c3 100644
--- a/source/compiler-core/slang-artifact.h
+++ b/source/compiler-core/slang-artifact.h
@@ -407,8 +407,11 @@ considered as a kind of side channel to associate arbitrary data including tempo
artifact.
A `child artifact` belongs to the artifact, within the hierarchy of artifacts.
+
+This also uses the ICompileResult interface to more easily allow the Slang API to retrieve
+multiple associated artifacts in cases where both base and debug spirv are needed.
*/
-class IArtifact : public ICastable
+class IArtifact : public slang::ICompileResult
{
public:
SLANG_COM_INTERFACE(
diff --git a/source/compiler-core/slang-spirv-core-grammar.h b/source/compiler-core/slang-spirv-core-grammar.h
index e91caa79a..87ac898d8 100644
--- a/source/compiler-core/slang-spirv-core-grammar.h
+++ b/source/compiler-core/slang-spirv-core-grammar.h
@@ -6,6 +6,7 @@
#include "../core/slang-string.h"
#include <optional>
+#include <spirv/unified1/NonSemanticShaderDebugInfo100.h>
#include <spirv/unified1/spirv.h>
namespace Slang