yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
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{ 34typedef ArtifactPayload Payload ; 35typedef ArtifactKind Kind ; 36typedef ArtifactStyle Style ; 37typedef ArtifactDesc Desc ; 38 39/// Returns true if the kind is binary linkable 40static bool isKindBinaryLinkable (Kind kind ); 41 42/// True if is a CPU target - either 43static bool isCpuLikeTarget (const ArtifactDesc & desc ); 44 45/// True if is a CPU binary 46static bool isCpuBinary (const ArtifactDesc & desc ); 47/// True if is a GPU usable (can be passed to a driver/API and be used) 48static bool isGpuUsable (const ArtifactDesc & desc ); 49 50/// True if the desc holds textual information 51static bool isText (const ArtifactDesc & desc ); 52 53/// True if artifact appears to be linkable 54static bool isLinkable (const ArtifactDesc & desc ); 55 56/// Try to determine the desc from just a file extension (passed without .) 57static ArtifactDesc getDescFromExtension (const UnownedStringSlice & slice ); 58 59/// Try to determine the desc from a path 60static ArtifactDesc getDescFromPath (const UnownedStringSlice & slice ); 61 62/// Appends the default file extension for the artifact type. 63static SlangResult appendDefaultExtension (const ArtifactDesc & desc ,StringBuilder & out ); 64 65/// Get the extension for CPU/Host for a kind 66static SlangResult appendCpuExtensionForKind (Kind kind ,StringBuilder & out ); 67 68/// Given a desc and a path returns the base name (stripped of prefix and extension) 69static 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) 72static 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 76static 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 79static SlangResult calcPathForDesc ( 80const ArtifactDesc & desc , 81const UnownedStringSlice & basePath , 82StringBuilder & outPath ); 83 84/// Given a desc and a baseName works out the the output file name 85static SlangResult calcNameForDesc ( 86const ArtifactDesc & desc , 87const UnownedStringSlice & baseName , 88StringBuilder & outName ); 89 90/// Returns true if there is a defined name extension/type for this desc 91static SlangResult hasDefinedNameForDesc (const ArtifactDesc & desc ); 92 93/// Given a target returns the ArtifactDesc 94static ArtifactDesc makeDescForCompileTarget (SlangCompileTarget target ); 95 96/// Get the payload for the specified language 97static ArtifactPayload getPayloadForSourceLanaguage (SlangSourceLanguage language ); 98/// Given a source language return a desc 99static ArtifactDesc makeDescForSourceLanguage (SlangSourceLanguage language ); 100 101/// Returns the closest compile target for desc. Will return 102/// SLANG_TARGET_UNKNOWN if not known 103static SlangCompileTarget getCompileTargetFromDesc (const ArtifactDesc & desc ); 104 105/// Make ArtifactDesc from target 106static bool isDescDerivedFrom (const ArtifactDesc & desc ,const ArtifactDesc & from ); 107 108/// True if `to` is disassembly of `from` 109static bool isDisassembly (const ArtifactDesc & from ,const ArtifactDesc & to ); 110 111/// Append the desc as text to out 112static void appendText (const ArtifactDesc & desc ,StringBuilder & out ); 113 114/// Given an artifact desc return a description as a string 115static String getText (const ArtifactDesc & desc ); 116}; 117 118// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 119inline /* static */ bool ArtifactDescUtil ::isDescDerivedFrom ( 120const ArtifactDesc & desc , 121const ArtifactDesc & from ) 122{ 123// TODO(JS): Currently this ignores flags in desc. That may or may not be right 124// long term. 125return isDerivedFrom (desc .kind ,from .kind )&& isDerivedFrom (desc .payload ,from .payload )&& 126isDerivedFrom (desc .style ,from .style ); 127} 128 129}// namespace Slang 130 131#endif