yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

jarcherNVAdd command line option for separate debug info (#7178)0d16228ae

master
5.3 KiB134 linesraw
1// slang-artifact-impl.h
2#ifndef SLANG_ARTIFACT_IMPL_H
3#define SLANG_ARTIFACT_IMPL_H
4
5#include "../core/slang-com-object.h"
6#include "slang-artifact.h"
7#include "slang-com-helper.h"
8#include "slang-com-ptr.h"
9
10namespace Slang
11{
12
13/*
14Discussion:
15
16Another issue occurs around wanting to hold multiple kernels within a container. The problem here is
17that although through the desc we can identify what target a kernel is for, there is no way of
18telling what stage it is for.
19
20When discussing the idea of a shader cache, one idea was to use a ISlangFileSystem (which could
21actually be a zip, or directory or in memory rep) as the main structure. Within this it can contain
22kernels, and then a json manifest can describe what each of these actually are.
23
24This all 'works', in that we can add an element of ISlangFileSystem with a desc of Container. Code
25that uses this can then go through the process of finding, and getting the blob, and find from the
26manifest what it means. That does sound a little tedious though. Perhaps we just have an interface
27that handles this detail, such that we search for that first. That interface is just attached to the
28artifact as an element.
29*/
30class Artifact : public ComBaseObject, public IArtifact
31{
32public:
33    SLANG_COM_BASE_IUNKNOWN_ALL
34
35    /// ICastable
36    virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
37
38    /// IArtifact impl
39    virtual SLANG_NO_THROW Desc SLANG_MCALL getDesc() SLANG_OVERRIDE { return m_desc; }
40    virtual SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE;
41
42    virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadBlob(Keep keep, ISlangBlob** outBlob)
43        SLANG_OVERRIDE;
44    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
45    requireFile(Keep keep, IOSFileArtifactRepresentation** outFileRep) SLANG_OVERRIDE;
46    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
47    loadSharedLibrary(ArtifactKeep keep, ISlangSharedLibrary** outSharedLibrary) SLANG_OVERRIDE;
48
49    virtual SLANG_NO_THROW const char* SLANG_MCALL getName() SLANG_OVERRIDE
50    {
51        return m_name.getBuffer();
52    }
53    virtual SLANG_NO_THROW void SLANG_MCALL setName(const char* name) SLANG_OVERRIDE
54    {
55        m_name = name;
56    }
57
58    virtual SLANG_NO_THROW void SLANG_MCALL addAssociated(IArtifact* artifact) SLANG_OVERRIDE;
59    virtual SLANG_NO_THROW Slice<IArtifact*> SLANG_MCALL getAssociated() SLANG_OVERRIDE;
60
61    virtual SLANG_NO_THROW void SLANG_MCALL addRepresentation(ICastable* castable) SLANG_OVERRIDE;
62    virtual SLANG_NO_THROW void SLANG_MCALL addRepresentationUnknown(ISlangUnknown* rep)
63        SLANG_OVERRIDE;
64    virtual SLANG_NO_THROW Slice<ICastable*> SLANG_MCALL getRepresentations() SLANG_OVERRIDE;
65    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getOrCreateRepresentation(
66        const Guid& typeGuid,
67        ArtifactKeep keep,
68        ICastable** outCastable) SLANG_OVERRIDE;
69
70    virtual SLANG_NO_THROW IArtifactHandler* SLANG_MCALL getHandler() SLANG_OVERRIDE;
71    virtual SLANG_NO_THROW void SLANG_MCALL setHandler(IArtifactHandler* handler) SLANG_OVERRIDE;
72
73    virtual SLANG_NO_THROW Slice<IArtifact*> SLANG_MCALL getChildren() SLANG_OVERRIDE;
74    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getExpandChildrenResult() SLANG_OVERRIDE
75    {
76        return m_expandResult;
77    }
78    virtual SLANG_NO_THROW void SLANG_MCALL setChildren(IArtifact* const* children, Count count)
79        SLANG_OVERRIDE;
80    virtual SLANG_NO_THROW SlangResult SLANG_MCALL expandChildren() SLANG_OVERRIDE;
81    virtual SLANG_NO_THROW void SLANG_MCALL addChild(IArtifact* artifact) SLANG_OVERRIDE;
82
83    virtual SLANG_NO_THROW void* SLANG_MCALL findRepresentation(ContainedKind kind, const Guid& unk)
84        SLANG_OVERRIDE;
85    virtual SLANG_NO_THROW void SLANG_MCALL clear(ContainedKind kind) SLANG_OVERRIDE;
86    virtual SLANG_NO_THROW void SLANG_MCALL removeAt(ContainedKind kind, Index i) SLANG_OVERRIDE;
87
88    static ComPtr<IArtifact> create(const Desc& desc)
89    {
90        return ComPtr<IArtifact>(new Artifact(desc));
91    }
92    static ComPtr<IArtifact> create(const Desc& desc, const UnownedStringSlice& name)
93    {
94        return ComPtr<IArtifact>(new Artifact(desc, name));
95    }
96
97    virtual SLANG_NO_THROW uint32_t SLANG_MCALL getItemCount() SLANG_OVERRIDE;
98    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
99    getItemData(uint32_t index, slang::IBlob** outblob) SLANG_OVERRIDE;
100    virtual SLANG_NO_THROW SlangResult SLANG_MCALL getMetadata(slang::IMetadata** outMetadata)
101        SLANG_OVERRIDE;
102
103protected:
104    /// Ctor
105    Artifact(const Desc& desc, const UnownedStringSlice& name)
106        : m_desc(desc), m_name(name)
107    {
108    }
109    Artifact(const Desc& desc)
110        : m_desc(desc)
111    {
112    }
113
114    IArtifactHandler* _getHandler();
115    void _requireChildren();
116
117    void* getInterface(const Guid& uuid);
118    void* getObject(const Guid& uuid);
119
120    Desc m_desc;   ///< Description of the artifact
121    String m_name; ///< Name of this artifact
122    SlangResult m_expandResult = SLANG_E_UNINITIALIZED;
123
124    ComPtr<IArtifactHandler>
125        m_handler; ///< The handler. Can be nullptr and then default handler is used.
126
127    List<ComPtr<ICastable>> m_representations; ///< All the representation of this artifact
128    List<ComPtr<IArtifact>> m_associated;      ///< All the items associated with this artifact
129    List<ComPtr<IArtifact>> m_children;        ///< All the child artifacts owned
130};
131
132} // namespace Slang
133
134#endif