yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
3.8 KiB104 linesraw
1// slang-artifact-util.h
2#ifndef SLANG_ARTIFACT_UTIL_H
3#define SLANG_ARTIFACT_UTIL_H
4
5#include "slang-artifact-associated.h"
6#include "slang-artifact-representation.h"
7#include "slang-artifact.h"
8#include "slang-com-ptr.h"
9
10namespace Slang
11{
12
13struct ArtifactUtil
14{
15    typedef bool (*FindFunc)(IArtifact* artifact, void* data);
16
17    enum class FindStyle : uint8_t
18    {
19        Self,              ///< Just on self
20        SelfOrChildren,    ///< Self, or if container just the children
21        Recursive,         ///< On self plus any children recursively
22        Children,          ///< Only on children
23        ChildrenRecursive, ///< Only on children recursively
24    };
25
26    /// Find an artifact that matches desc allowing derivations. Flags is ignored
27    static IArtifact* findArtifactByDerivedDesc(
28        IArtifact* artifact,
29        FindStyle findStyle,
30        const ArtifactDesc& desc);
31    /// Find an artifact that predicate matches
32    static IArtifact* findArtifactByPredicate(
33        IArtifact* artifact,
34        FindStyle findStyle,
35        FindFunc func,
36        void* data);
37    /// Find by name
38    static IArtifact* findArtifactByName(
39        IArtifact* artifact,
40        FindStyle findStyle,
41        const char* name);
42    /// Find by desc exactly
43    static IArtifact* findArtifactByDesc(
44        IArtifact* artifact,
45        FindStyle findStyle,
46        const ArtifactDesc& desc);
47
48    /// Creates an empty artifact for a type
49    static ComPtr<IArtifact> createArtifactForCompileTarget(SlangCompileTarget target);
50
51    /// Create an artifact
52    static ComPtr<IArtifact> createArtifact(const ArtifactDesc& desc, const char* name);
53    static ComPtr<IArtifact> createArtifact(const ArtifactDesc& desc);
54
55    /// True if is significant
56    static bool isSignificant(IArtifact* artifact);
57    /// True if is significant
58    static bool isSignificant(const ArtifactDesc& desc);
59
60    /// Returns true if an artifact is 'significant'.
61    /// The data parameter is unused and just used to make work as FindFunc
62    static bool isSignificant(IArtifact* artifact, void* data);
63
64    /// Find a significant artifact
65    static IArtifact* findSignificant(IArtifact* artifact);
66
67    /// Find the path/name associated with the artifact.
68    /// The path is *not* necessarily the path on the file system. The order of search is
69    /// * If the artifact has a name return that
70    /// * If the artifact has a IPathFileArtifactRepresentation (that isn't temporary) return it's
71    /// path
72    /// * If not found return an empty slice
73    static UnownedStringSlice findPath(IArtifact* artifact);
74    /// Find a name
75    static UnownedStringSlice findName(IArtifact* artifact);
76
77    /// Sometimes we have artifacts that don't specify a payload type - perhaps because they can be
78    /// interpretted in different ways This function uses the associated name and file
79    /// representations to infer a extension. If none is found returns an empty slice.
80    static UnownedStringSlice inferExtension(IArtifact* artifact);
81
82    /// Given a desc and a basePath returns a suitable path for a entity of specified desc
83    static SlangResult calcPath(
84        IArtifact* artifact,
85        const UnownedStringSlice& basePath,
86        StringBuilder& outPath);
87
88    /// Given a desc and a baseName works out the the output file name
89    static SlangResult calcName(
90        IArtifact* artifact,
91        const UnownedStringSlice& baseName,
92        StringBuilder& outName);
93
94    /// Convenience function that adds metadata to artifact. If metadata is nullptr nothing is
95    /// added.
96    static void addAssociated(IArtifact* artifact, IArtifactPostEmitMetadata* metadata);
97    /// Convenience function that adds diagnostics to artifact. If diagnostics is nullptr nothing is
98    /// added.
99    static void addAssociated(IArtifact* artifact, IArtifactDiagnostics* diagnostics);
100};
101
102} // namespace Slang
103
104#endif