yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
6.9 KiB168 linesraw
1// slang-artifact-helper.h
2#ifndef SLANG_ARTIFACT_HELPER_H
3#define SLANG_ARTIFACT_HELPER_H
4
5#include "../core/slang-com-object.h"
6#include "slang-artifact-representation.h"
7#include "slang-artifact.h"
8
9namespace Slang
10{
11
12class IArtifactHelper : public ICastable
13{
14    SLANG_COM_INTERFACE(0x882b25d7, 0xe300, 0x4b20, {0xbe, 0xb, 0x26, 0xd2, 0x52, 0x3e, 0x70, 0x20})
15
16    /// Create an artifact
17    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
18    createArtifact(const ArtifactDesc& desc, const char* name, IArtifact** outArtifact) = 0;
19
20    /// Get the parent to a kind
21    virtual SLANG_NO_THROW ArtifactKind SLANG_MCALL getKindParent(ArtifactKind kind) = 0;
22    /// Get the name of a kind
23    virtual SLANG_NO_THROW UnownedStringSlice SLANG_MCALL getKindName(ArtifactKind kind) = 0;
24    /// Returns true if kind is derived from base
25    virtual SLANG_NO_THROW bool SLANG_MCALL
26    isKindDerivedFrom(ArtifactKind kind, ArtifactKind base) = 0;
27
28    /// Get the parent payload for payload
29    virtual SLANG_NO_THROW ArtifactPayload SLANG_MCALL
30    getPayloadParent(ArtifactPayload payload) = 0;
31    /// Get the payload name text
32    virtual SLANG_NO_THROW UnownedStringSlice SLANG_MCALL
33    getPayloadName(ArtifactPayload payload) = 0;
34    /// Returns true if payload is derived from base
35    virtual SLANG_NO_THROW bool SLANG_MCALL
36    isPayloadDerivedFrom(ArtifactPayload payload, ArtifactPayload base) = 0;
37
38    /// Get the parent type of a style
39    virtual SLANG_NO_THROW ArtifactStyle SLANG_MCALL getStyleParent(ArtifactStyle style) = 0;
40    /// Get text name for a style
41    virtual SLANG_NO_THROW UnownedStringSlice SLANG_MCALL getStyleName(ArtifactStyle style) = 0;
42    /// Returns true if style is derived from base
43    virtual SLANG_NO_THROW bool SLANG_MCALL
44    isStyleDerivedFrom(ArtifactStyle style, ArtifactStyle base) = 0;
45
46    /// Create a lock file, the path of which can be used to generate other temporary files
47    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
48    createLockFile(const CharSlice& nameBase, IOSFileArtifactRepresentation** outLockFile) = 0;
49
50    /// Given a desc and a basePath returns a suitable name
51    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
52    calcArtifactDescPath(const ArtifactDesc& desc, const char* basePath, ISlangBlob** outPath) = 0;
53
54    /// Given an artifact and a basePath returns a suitable name
55    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
56    calcArtifactPath(IArtifact*, const char* basePath, ISlangBlob** outPath) = 0;
57
58    /// Given a compile target return the equivalent desc
59    virtual SLANG_NO_THROW ArtifactDesc SLANG_MCALL
60    makeDescForCompileTarget(SlangCompileTarget target) = 0;
61
62    /// Given an interface returns as a castable interface. This might just cast unk into ICastable,
63    /// or wrap it such that it uses the castable interface
64    virtual SLANG_NO_THROW void SLANG_MCALL
65    getCastable(ISlangUnknown* unk, ICastable** outCastable) = 0;
66
67    /// Create a file rep
68    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createOSFileArtifactRepresentation(
69        IOSFileArtifactRepresentation::Kind kind,
70        const CharSlice& path,
71        IOSFileArtifactRepresentation* lockFile,
72        IOSFileArtifactRepresentation** outRep) = 0;
73
74    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createExtFileArtifactRepresentation(
75        const CharSlice& path,
76        ISlangFileSystemExt* system,
77        IExtFileArtifactRepresentation** outRep) = 0;
78
79    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createOSFileArtifact(
80        const ArtifactDesc& desc,
81        const CharSlice& slice,
82        IArtifact** outArtifact) = 0;
83};
84
85class DefaultArtifactHelper : public IArtifactHelper
86{
87public:
88    // ISlangUnknown
89    SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE { return 1; }
90    SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE { return 1; }
91    SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject)
92        SLANG_OVERRIDE;
93
94    // ICastable
95    SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
96
97    // IArtifactHelper
98    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createArtifact(
99        const ArtifactDesc& desc,
100        const char* name,
101        IArtifact** outArtifact) SLANG_OVERRIDE;
102
103    virtual SLANG_NO_THROW ArtifactKind SLANG_MCALL getKindParent(ArtifactKind kind) SLANG_OVERRIDE;
104    virtual SLANG_NO_THROW UnownedStringSlice SLANG_MCALL getKindName(ArtifactKind kind)
105        SLANG_OVERRIDE;
106    virtual SLANG_NO_THROW bool SLANG_MCALL isKindDerivedFrom(ArtifactKind kind, ArtifactKind base)
107        SLANG_OVERRIDE;
108
109    virtual SLANG_NO_THROW ArtifactPayload SLANG_MCALL getPayloadParent(ArtifactPayload payload)
110        SLANG_OVERRIDE;
111    virtual SLANG_NO_THROW UnownedStringSlice SLANG_MCALL getPayloadName(ArtifactPayload payload)
112        SLANG_OVERRIDE;
113    virtual SLANG_NO_THROW bool SLANG_MCALL
114    isPayloadDerivedFrom(ArtifactPayload payload, ArtifactPayload base) SLANG_OVERRIDE;
115
116    virtual SLANG_NO_THROW ArtifactStyle SLANG_MCALL getStyleParent(ArtifactStyle style)
117        SLANG_OVERRIDE;
118    virtual SLANG_NO_THROW UnownedStringSlice SLANG_MCALL getStyleName(ArtifactStyle style)
119        SLANG_OVERRIDE;
120    virtual SLANG_NO_THROW bool SLANG_MCALL
121    isStyleDerivedFrom(ArtifactStyle style, ArtifactStyle base) SLANG_OVERRIDE;
122
123    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createLockFile(
124        const CharSlice& nameBase,
125        IOSFileArtifactRepresentation** outLockFile) SLANG_OVERRIDE;
126
127    virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcArtifactDescPath(
128        const ArtifactDesc& desc,
129        const char* basePath,
130        ISlangBlob** outPath) SLANG_OVERRIDE;
131
132    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
133    calcArtifactPath(IArtifact*, const char* basePath, ISlangBlob** outPath) SLANG_OVERRIDE;
134
135    virtual SLANG_NO_THROW ArtifactDesc SLANG_MCALL
136    makeDescForCompileTarget(SlangCompileTarget target) SLANG_OVERRIDE;
137
138    virtual SLANG_NO_THROW void SLANG_MCALL getCastable(ISlangUnknown* unk, ICastable** outCastable)
139        SLANG_OVERRIDE;
140
141    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createOSFileArtifactRepresentation(
142        IOSFileArtifactRepresentation::Kind kind,
143        const CharSlice& path,
144        IOSFileArtifactRepresentation* lockFile,
145        IOSFileArtifactRepresentation** outRep) SLANG_OVERRIDE;
146
147    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createExtFileArtifactRepresentation(
148        const CharSlice& path,
149        ISlangFileSystemExt* system,
150        IExtFileArtifactRepresentation** outRep) SLANG_OVERRIDE;
151
152    virtual SLANG_NO_THROW SlangResult SLANG_MCALL createOSFileArtifact(
153        const ArtifactDesc& desc,
154        const CharSlice& slice,
155        IArtifact** outArtifact) SLANG_OVERRIDE;
156
157    static IArtifactHelper* getSingleton() { return &g_singleton; }
158
159protected:
160    void* getInterface(const Guid& guid);
161    void* getObject(const Guid& guid);
162
163    static DefaultArtifactHelper g_singleton;
164};
165
166} // namespace Slang
167
168#endif