yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
4.9 KiB131 linesraw
1// slang-artifact-desc.h
2
3#ifndef SLANG_ARTIFACT_DESC_UTIL_H
4#define SLANG_ARTIFACT_DESC_UTIL_H
5
6#include "slang-artifact.h"
7
8namespace Slang
9{
10
11/// Get the parent kind
12ArtifactKind getParent(ArtifactKind kind);
13/// Returns true if kind is derived from base
14bool isDerivedFrom(ArtifactKind kind, ArtifactKind base);
15/// Get the name for the kind
16UnownedStringSlice getName(ArtifactKind kind);
17
18/// Get the parent payload
19ArtifactPayload getParent(ArtifactPayload payload);
20/// Returns true if payload is derived from base
21bool isDerivedFrom(ArtifactPayload payload, ArtifactPayload base);
22/// Get the name for the payload
23UnownedStringSlice getName(ArtifactPayload payload);
24
25/// Get the parent style
26ArtifactStyle getParent(ArtifactStyle style);
27/// Returns true if style is derived from base
28bool isDerivedFrom(ArtifactStyle style, ArtifactStyle base);
29/// Get the name for the style
30UnownedStringSlice getName(ArtifactStyle style);
31
32struct ArtifactDescUtil
33{
34    typedef ArtifactPayload Payload;
35    typedef ArtifactKind Kind;
36    typedef ArtifactStyle Style;
37    typedef ArtifactDesc Desc;
38
39    /// Returns true if the kind is binary linkable
40    static bool isKindBinaryLinkable(Kind kind);
41
42    /// True if is a CPU target - either
43    static bool isCpuLikeTarget(const ArtifactDesc& desc);
44
45    /// True if is a CPU binary
46    static bool isCpuBinary(const ArtifactDesc& desc);
47    /// True if is a GPU usable (can be passed to a driver/API and be used)
48    static bool isGpuUsable(const ArtifactDesc& desc);
49
50    /// True if the desc holds textual information
51    static bool isText(const ArtifactDesc& desc);
52
53    /// True if artifact  appears to be linkable
54    static bool isLinkable(const ArtifactDesc& desc);
55
56    /// Try to determine the desc from just a file extension (passed without .)
57    static ArtifactDesc getDescFromExtension(const UnownedStringSlice& slice);
58
59    /// Try to determine the desc from a path
60    static ArtifactDesc getDescFromPath(const UnownedStringSlice& slice);
61
62    /// Appends the default file extension for the artifact type.
63    static SlangResult appendDefaultExtension(const ArtifactDesc& desc, StringBuilder& out);
64
65    /// Get the extension for CPU/Host for a kind
66    static SlangResult appendCpuExtensionForKind(Kind kind, StringBuilder& out);
67
68    /// Given a desc and a path returns the base name (stripped of prefix and extension)
69    static String getBaseNameFromPath(const ArtifactDesc& desc, const UnownedStringSlice& path);
70
71    /// Given a desc and a name returns the base name (stripped of prefix and extension)
72    static String getBaseNameFromName(const ArtifactDesc& desc, const UnownedStringSlice& path);
73
74    /// Get the base name of the fileRep
75    /// If no base name is found will return an empty slice
76    static String getBaseName(const ArtifactDesc& desc, IPathArtifactRepresentation* fileRep);
77
78    /// Given a desc and a basePath returns a suitable path for a entity of specified desc
79    static SlangResult calcPathForDesc(
80        const ArtifactDesc& desc,
81        const UnownedStringSlice& basePath,
82        StringBuilder& outPath);
83
84    /// Given a desc and a baseName works out the the output file name
85    static SlangResult calcNameForDesc(
86        const ArtifactDesc& desc,
87        const UnownedStringSlice& baseName,
88        StringBuilder& outName);
89
90    /// Returns true if there is a defined name extension/type for this desc
91    static SlangResult hasDefinedNameForDesc(const ArtifactDesc& desc);
92
93    /// Given a target returns the ArtifactDesc
94    static ArtifactDesc makeDescForCompileTarget(SlangCompileTarget target);
95
96    /// Get the payload for the specified language
97    static ArtifactPayload getPayloadForSourceLanaguage(SlangSourceLanguage language);
98    /// Given a source language return a desc
99    static ArtifactDesc makeDescForSourceLanguage(SlangSourceLanguage language);
100
101    /// Returns the closest compile target for desc. Will return
102    /// SLANG_TARGET_UNKNOWN if not known
103    static SlangCompileTarget getCompileTargetFromDesc(const ArtifactDesc& desc);
104
105    /// Make ArtifactDesc from target
106    static bool isDescDerivedFrom(const ArtifactDesc& desc, const ArtifactDesc& from);
107
108    /// True if `to` is disassembly of `from`
109    static bool isDisassembly(const ArtifactDesc& from, const ArtifactDesc& to);
110
111    /// Append the desc as text to out
112    static void appendText(const ArtifactDesc& desc, StringBuilder& out);
113
114    /// Given an artifact desc return a description as a string
115    static String getText(const ArtifactDesc& desc);
116};
117
118// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
119inline /* static */ bool ArtifactDescUtil::isDescDerivedFrom(
120    const ArtifactDesc& desc,
121    const ArtifactDesc& from)
122{
123    // TODO(JS): Currently this ignores flags in desc. That may or may not be right
124    // long term.
125    return isDerivedFrom(desc.kind, from.kind) && isDerivedFrom(desc.payload, from.payload) &&
126           isDerivedFrom(desc.style, from.style);
127}
128
129} // namespace Slang
130
131#endif