summaryrefslogtreecommitdiff
path: root/source/core/slang-castable-util.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-22 17:39:56 -0400
committerGitHub <noreply@github.com>2022-08-22 14:39:56 -0700
commit6ab0baf910dea838dca2d29557c3361297180a34 (patch)
tree4f2a3418f0662c8a61fd1ba9bf1c1d24b77c276b /source/core/slang-castable-util.h
parent4bd3e6e02324f913e8927fe69d32c0aafe9fc831 (diff)
Improve binary compatibility for DownstreamCompiler types (#2371)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP replacing DownstreamCompileResult. * First attempt at replacing DownstreamCompileResult with IArtifact and associated types. * Small renaming around CharSlice. * ICastable -> ISlangCastable Added IClonable Fix issue with cloning in ArtifactDiagnostics. * Only add the blob if one is defined in DXC. * Guard adding blob representation. * Make cloneInterface available across code base. Set enums backing type for ArtifactDiagnostic. * Added ::create for ArtifactDiagnostics. * Use SemanticVersion for DownstreamCompilerDesc. Set sizes for enum types. * Depreciate old incompatible CompileOptions. Change SemanticVersion use 32 bits for the patch. * Split out CastableUtil. * Change IDownstreamCompiler to use canConvert and convert to use artifact types. * Fix typos. * Fix typo bug. Allow trafficing in PTX assembly/binaries * struct DownstreamCompilerBaseUtil -> struct DownstreamCompilerUtilBase Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/core/slang-castable-util.h')
-rw-r--r--source/core/slang-castable-util.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/source/core/slang-castable-util.h b/source/core/slang-castable-util.h
new file mode 100644
index 000000000..4d3c3900c
--- /dev/null
+++ b/source/core/slang-castable-util.h
@@ -0,0 +1,58 @@
+// slang-castable-util.h
+#ifndef SLANG_CASTABLE_UTIL_H
+#define SLANG_CASTABLE_UTIL_H
+
+#include "slang-castable-list.h"
+
+#include "../../slang-com-helper.h"
+#include "../../slang-com-ptr.h"
+
+#include "../core/slang-com-object.h"
+
+namespace Slang
+{
+
+/* An adapter such that types which aren't derived from ICastable, can be used as such.
+
+With the following caveats.
+* the interfaces/objects of the adapter are checked *first*, so IUnknown will always be for the adapter
+* assumes when doing a queryInterface on the contained item, it will remain in scope when released (this is *not* strict COM)
+*/
+class UnknownCastableAdapter : public ComBaseObject, public IUnknownCastableAdapter
+{
+public:
+ SLANG_COM_BASE_IUNKNOWN_ALL
+
+ // ICastable
+ SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
+
+ // IUnknownCastableAdapter
+ virtual SLANG_NO_THROW ISlangUnknown* SLANG_MCALL getContained() SLANG_OVERRIDE { return m_contained; }
+
+ UnknownCastableAdapter(ISlangUnknown* unk):
+ m_contained(unk)
+ {
+ SLANG_ASSERT(unk);
+ }
+
+protected:
+ void* getInterface(const Guid& guid);
+ void* getObject(const Guid& guid);
+
+ ComPtr<ISlangUnknown> m_contained;
+
+ // We hold a cache for a single lookup to make things a little faster
+ void* m_found = nullptr;
+ Guid m_foundGuid;
+};
+
+struct CastableUtil
+{
+ /// Given an ISlangUnkown return as a castable interface.
+ /// Can use UnknownCastableAdapter if can't queryInterface unk to ICastable
+ static ComPtr<ICastable> getCastable(ISlangUnknown* unk);
+};
+
+} // namespace Slang
+
+#endif