yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
0d16228ae
master
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 : 33SLANG_COM_BASE_IUNKNOWN_ALL 34 35/// ICastable 36virtual SLANG_NO_THROW void * SLANG_MCALL castAs (const Guid & guid )SLANG_OVERRIDE ; 37 38/// IArtifact impl 39virtual SLANG_NO_THROW Desc SLANG_MCALL getDesc ()SLANG_OVERRIDE {return m_desc ; } 40virtual SLANG_NO_THROW bool SLANG_MCALL exists ()SLANG_OVERRIDE ; 41 42virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadBlob ( Keep keep, ISlangBlob ** outBlob) 43SLANG_OVERRIDE ; 44virtual SLANG_NO_THROW SlangResult SLANG_MCALL 45requireFile ( Keep keep, IOSFileArtifactRepresentation ** outFileRep) SLANG_OVERRIDE ; 46virtual SLANG_NO_THROW SlangResult SLANG_MCALL 47loadSharedLibrary ( ArtifactKeep keep, ISlangSharedLibrary ** outSharedLibrary) SLANG_OVERRIDE ; 48 49virtual SLANG_NO_THROW const char * SLANG_MCALL getName () SLANG_OVERRIDE 50{ 51return m_name. getBuffer (); 52} 53virtual SLANG_NO_THROW void SLANG_MCALL setName ( const char * name) SLANG_OVERRIDE 54{ 55m_name = name; 56} 57 58virtual SLANG_NO_THROW void SLANG_MCALL addAssociated ( IArtifact * artifact) SLANG_OVERRIDE ; 59virtual SLANG_NO_THROW Slice < IArtifact *> SLANG_MCALL getAssociated () SLANG_OVERRIDE ; 60 61virtual SLANG_NO_THROW void SLANG_MCALL addRepresentation ( ICastable * castable) SLANG_OVERRIDE ; 62virtual SLANG_NO_THROW void SLANG_MCALL addRepresentationUnknown ( ISlangUnknown * rep) 63SLANG_OVERRIDE ; 64virtual SLANG_NO_THROW Slice < ICastable *> SLANG_MCALL getRepresentations () SLANG_OVERRIDE ; 65virtual SLANG_NO_THROW SlangResult SLANG_MCALL getOrCreateRepresentation( 66const Guid & typeGuid, 67ArtifactKeep keep, 68ICastable ** outCastable) SLANG_OVERRIDE ; 69 70virtual SLANG_NO_THROW IArtifactHandler * SLANG_MCALL getHandler () SLANG_OVERRIDE ; 71virtual SLANG_NO_THROW void SLANG_MCALL setHandler ( IArtifactHandler * handler) SLANG_OVERRIDE ; 72 73virtual SLANG_NO_THROW Slice < IArtifact *> SLANG_MCALL getChildren () SLANG_OVERRIDE ; 74virtual SLANG_NO_THROW SlangResult SLANG_MCALL getExpandChildrenResult () SLANG_OVERRIDE 75{ 76return m_expandResult; 77} 78virtual SLANG_NO_THROW void SLANG_MCALL setChildren ( IArtifact * const * children, Count count) 79SLANG_OVERRIDE ; 80virtual SLANG_NO_THROW SlangResult SLANG_MCALL expandChildren () SLANG_OVERRIDE ; 81virtual SLANG_NO_THROW void SLANG_MCALL addChild ( IArtifact * artifact) SLANG_OVERRIDE ; 82 83virtual SLANG_NO_THROW void * SLANG_MCALL findRepresentation ( ContainedKind kind, const Guid & unk) 84SLANG_OVERRIDE ; 85virtual SLANG_NO_THROW void SLANG_MCALL clear ( ContainedKind kind) SLANG_OVERRIDE ; 86virtual SLANG_NO_THROW void SLANG_MCALL removeAt ( ContainedKind kind, Index i) SLANG_OVERRIDE ; 87 88static ComPtr < IArtifact > create ( const Desc & desc) 89{ 90return ComPtr < IArtifact > (new Artifact (desc)); 91} 92static ComPtr < IArtifact > create ( const Desc & desc, const UnownedStringSlice & name) 93{ 94return ComPtr < IArtifact > (new Artifact (desc, name)); 95} 96 97virtual SLANG_NO_THROW uint32_t SLANG_MCALL getItemCount () SLANG_OVERRIDE ; 98virtual SLANG_NO_THROW SlangResult SLANG_MCALL 99getItemData ( uint32_t index, slang ::IBlob ** outblob) SLANG_OVERRIDE ; 100virtual SLANG_NO_THROW SlangResult SLANG_MCALL getMetadata ( slang ::IMetadata ** outMetadata) 101SLANG_OVERRIDE ; 102 103protected: 104/// Ctor 105Artifact ( const Desc & desc, const UnownedStringSlice & name) 106: m_desc (desc), m_name ( name ) 107{ 108} 109Artifact ( const Desc & desc) 110: m_desc (desc) 111{ 112} 113 114IArtifactHandler * _getHandler (); 115void _requireChildren (); 116 117void * getInterface ( const Guid & uuid); 118void * getObject ( const Guid & uuid); 119 120Desc m_desc; ///< Description of the artifact 121String m_name; ///< Name of this artifact 122SlangResult m_expandResult = SLANG_E_UNINITIALIZED ; 123 124ComPtr < IArtifactHandler > 125m_handler; ///< The handler. Can be nullptr and then default handler is used. 126 127List < ComPtr < ICastable>> m_representations; ///< All the representation of this artifact 128List < ComPtr < IArtifact>> m_associated; ///< All the items associated with this artifact 129List < ComPtr < IArtifact>> m_children; ///< All the child artifacts owned 130}; 131 132} // namespace Slang 133 134#endif