yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
de7ccaf12
master
1// slang-artifact-associated-impl.h 2#ifndef SLANG_ARTIFACT_ASSOCIATED_IMPL_H 3#define SLANG_ARTIFACT_ASSOCIATED_IMPL_H 4 5#include "../core/slang-com-object.h" 6#include "../core/slang-memory-arena.h" 7#include "slang-artifact-associated.h" 8#include "slang-artifact-diagnostic-util.h" 9#include "slang-artifact-util.h" 10#include "slang-com-helper.h" 11#include "slang-com-ptr.h" 12 13namespace Slang 14{ 15 16class ArtifactDiagnostics :public ComBaseObject ,public IArtifactDiagnostics 17{ 18public : 19typedef ArtifactDiagnostics ThisType ; 20 21SLANG_COM_BASE_IUNKNOWN_ALL 22 23// ICastable 24SLANG_NO_THROW void * SLANG_MCALL castAs (const Guid & guid )SLANG_OVERRIDE ; 25// IClonable 26SLANG_NO_THROW virtual void * SLANG_MCALL clone (const Guid & intf )SLANG_OVERRIDE ; 27// IDiagnostic 28SLANG_NO_THROW virtual const Diagnostic * SLANG_MCALL getAt (Index i )SLANG_OVERRIDE 29 { 30return & m_diagnostics [i ]; 31 } 32SLANG_NO_THROW virtual Count SLANG_MCALL getCount ()SLANG_OVERRIDE 33 { 34return m_diagnostics .getCount (); 35 } 36SLANG_NO_THROW virtual void SLANG_MCALL add (const Diagnostic & diagnostic )SLANG_OVERRIDE ; 37SLANG_NO_THROW virtual void SLANG_MCALL removeAt (Index i )SLANG_OVERRIDE 38 { 39m_diagnostics .removeAt (i ); 40 } 41SLANG_NO_THROW virtual SlangResult SLANG_MCALL getResult ()SLANG_OVERRIDE {return m_result ; } 42SLANG_NO_THROW virtual void SLANG_MCALL setResult (SlangResult res )SLANG_OVERRIDE 43 { 44m_result = res ; 45 } 46SLANG_NO_THROW virtual void SLANG_MCALL setRaw (const CharSlice & slice )SLANG_OVERRIDE ; 47SLANG_NO_THROW virtual void SLANG_MCALL appendRaw (const CharSlice & slice )SLANG_OVERRIDE ; 48SLANG_NO_THROW virtual TerminatedCharSlice SLANG_MCALL getRaw ()SLANG_OVERRIDE 49 { 50return SliceUtil ::asTerminatedCharSlice (m_raw ); 51 } 52SLANG_NO_THROW virtual void SLANG_MCALL reset ()SLANG_OVERRIDE ; 53SLANG_NO_THROW virtual Count SLANG_MCALL getCountAtLeastSeverity( Diagnostic ::Severity severity) 54SLANG_OVERRIDE ; 55SLANG_NO_THROW virtual Count SLANG_MCALL getCountBySeverity( Diagnostic ::Severity severity) 56SLANG_OVERRIDE ; 57SLANG_NO_THROW virtual bool SLANG_MCALL hasOfAtLeastSeverity( Diagnostic ::Severity severity) 58SLANG_OVERRIDE ; 59SLANG_NO_THROW virtual Count SLANG_MCALL getCountByStage( 60Diagnostic ::Stage stage, 61Count outCounts [ Int (Diagnostic::Severity::CountOf)]) SLANG_OVERRIDE ; 62SLANG_NO_THROW virtual void SLANG_MCALL removeBySeverity( Diagnostic ::Severity severity) 63SLANG_OVERRIDE ; 64SLANG_NO_THROW virtual void SLANG_MCALL maybeAddNote( const CharSlice & in) SLANG_OVERRIDE ; 65SLANG_NO_THROW virtual void SLANG_MCALL requireErrorDiagnostic () SLANG_OVERRIDE ; 66SLANG_NO_THROW virtual void SLANG_MCALL calcSummary ( ISlangBlob ** outBlob) SLANG_OVERRIDE ; 67SLANG_NO_THROW virtual void SLANG_MCALL calcSimplifiedSummary ( ISlangBlob ** outBlob) 68SLANG_OVERRIDE ; 69 70/// Default ctor 71ArtifactDiagnostics () 72: ComBaseObject () 73{ 74} 75/// Copy ctor 76ArtifactDiagnostics( const ThisType & rhs); 77 78/// Create 79static ComPtr < IArtifactDiagnostics > create () 80{ 81return ComPtr < IArtifactDiagnostics > (new ThisType); 82} 83 84protected : 85void * getInterface ( const Guid & uuid); 86void * getObject ( const Guid & uuid); 87 88SliceAllocator m_allocator; 89 90List < Diagnostic > m_diagnostics; 91SlangResult m_result = SLANG_OK ; 92 93// Raw diagnostics 94StringBuilder m_raw; 95}; 96 97/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! ArtifactPostEmitMetadata !!!!!!!!!!!!!!!!!!!!!!!!!! */ 98 99struct ShaderBindingRange 100{ 101slang :: ParameterCategory category = slang ::ParameterCategory::None; 102UInt spaceIndex = 0 ; 103UInt registerIndex = 0 ; 104UInt registerCount = 0 ; // 0 for unsized 105 106bool isInfinite () const { return registerCount == 0 ; } 107 108bool containsBinding ( slang ::ParameterCategory _category, UInt _spaceIndex, UInt _registerIndex) 109const 110{ 111return category == _category && spaceIndex == _spaceIndex && 112registerIndex <= _registerIndex && 113( isInfinite () || registerCount + registerIndex > _registerIndex); 114} 115 116bool intersectsWith ( const ShaderBindingRange & other) const 117{ 118if (category != other. category || spaceIndex != other. spaceIndex ) 119return false; 120 121const bool leftIntersection = 122(registerIndex < other. registerIndex + other. registerCount ) || other. isInfinite (); 123const bool rightIntersection = 124(other. registerIndex < registerIndex + registerCount) || isInfinite (); 125 126return leftIntersection && rightIntersection; 127} 128 129bool adjacentTo ( const ShaderBindingRange & other) const 130{ 131if (category != other. category || spaceIndex != other. spaceIndex ) 132return false; 133 134const bool leftIntersection = 135(registerIndex <= other. registerIndex + other. registerCount ) || other. isInfinite (); 136const bool rightIntersection = 137(other. registerIndex <= registerIndex + registerCount) || isInfinite (); 138 139return leftIntersection && rightIntersection; 140} 141 142void mergeWith ( const ShaderBindingRange other) 143{ 144UInt newRegisterIndex = Math:: Min (registerIndex, other. registerIndex ); 145 146if (other. isInfinite ()) 147registerCount = 0 ; 148else if (! isInfinite ()) 149registerCount = Math:: Max ( 150registerIndex + registerCount, 151other. registerIndex + other. registerCount ) - 152newRegisterIndex; 153 154registerIndex = newRegisterIndex; 155} 156 157static bool isUsageTracked ( slang ::ParameterCategory category) 158{ 159switch (category) 160{ 161case slang:: ConstantBuffer : 162case slang:: ShaderResource : 163case slang:: UnorderedAccess : 164case slang:: SamplerState : 165case slang:: DescriptorTableSlot : 166case slang:: VaryingInput : 167case slang:: VaryingOutput : 168case slang:: SpecializationConstant : 169case slang:: SubElementRegisterSpace : 170return true; 171default : 172return false; 173} 174} 175}; 176 177class ArtifactPostEmitMetadata : public ComBaseObject, public IArtifactPostEmitMetadata 178{ 179public : 180typedef ArtifactPostEmitMetadata ThisType; 181 182SLANG_CLASS_GUID ( 0x6f82509f , 0xe48b , 0x4b83 , { 0xa3 , 0x84 , 0x5d , 0x70 , 0x83 , 0x19 , 0x83 , 0xcc }) 183 184SLANG_COM_BASE_IUNKNOWN_ALL 185 186// ICastable 187SLANG_NO_THROW void * SLANG_MCALL castAs( const Guid & guid) SLANG_OVERRIDE ; 188 189// IArtifactPostEmitMetadata 190SLANG_NO_THROW virtual Slice < ShaderBindingRange > SLANG_MCALL getUsedBindingRanges () 191SLANG_OVERRIDE ; 192SLANG_NO_THROW virtual Slice < String > SLANG_MCALL getExportedFunctionMangledNames () 193SLANG_OVERRIDE ; 194 195// IMetadata 196SLANG_NO_THROW virtual SlangResult isParameterLocationUsed ( 197SlangParameterCategory category, // is this a `t` register? `s` register? 198SlangUInt spaceIndex, // `space` for D3D12, `set` for Vulkan 199SlangUInt registerIndex, // `register` for D3D12, `binding` for Vulkan 200bool & outUsed) SLANG_OVERRIDE ; 201 202SLANG_NO_THROW virtual const char * SLANG_MCALL getDebugBuildIdentifier() SLANG_OVERRIDE ; 203 204void * getInterface ( const Guid & uuid); 205void * getObject ( const Guid & uuid); 206 207static ComPtr < IArtifactPostEmitMetadata > create () 208{ 209return ComPtr < IArtifactPostEmitMetadata > (new ThisType); 210} 211 212List < ShaderBindingRange > m_usedBindings; 213List < String > m_exportedFunctionMangledNames; 214String m_debugBuildIdentifier; 215}; 216 217} // namespace Slang 218 219#endif