yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// debug-shader-object.cpp 2#include "debug-shader-object.h" 3 4#include "debug-helper-functions.h" 5#include "debug-resource-views.h" 6#include "debug-sampler-state.h" 7 8namespace gfx 9{ 10using namespace Slang ; 11 12namespace debug 13{ 14 15ShaderObjectContainerType DebugShaderObject ::getContainerType () 16{ 17SLANG_GFX_API_FUNC ; 18return baseObject -> getContainerType (); 19} 20 21void DebugShaderObject ::checkCompleteness () 22{ 23auto layout = baseObject -> getElementTypeLayout (); 24for (Index i = 0 ;i < layout -> getBindingRangeCount ();i ++ ) 25 { 26if (layout -> getBindingRangeBindingCount (i )!= 0 ) 27 { 28if (!m_initializedBindingRanges .contains (i )) 29 { 30auto var = layout -> getBindingRangeLeafVariable (i ); 31GFX_DIAGNOSE_ERROR_FORMAT ( 32"shader parameter '%s' is not initialized in the shader object of type '%s'." , 33var -> getName (), 34m_slangType -> getName ()); 35 } 36 } 37 } 38} 39 40slang::TypeLayoutReflection * DebugShaderObject ::getElementTypeLayout () 41{ 42SLANG_GFX_API_FUNC ; 43return baseObject -> getElementTypeLayout (); 44} 45 46GfxCount DebugShaderObject ::getEntryPointCount () 47{ 48SLANG_GFX_API_FUNC ; 49return baseObject -> getEntryPointCount (); 50} 51 52Result DebugShaderObject ::getEntryPoint (GfxIndex index ,IShaderObject ** entryPoint ) 53{ 54SLANG_GFX_API_FUNC ; 55if (m_entryPoints .getCount ()== 0 ) 56 { 57for (GfxIndex i = 0 ;i < getEntryPointCount ();i ++ ) 58 { 59RefPtr < DebugShaderObject > entryPointObj = new DebugShaderObject (); 60SLANG_RETURN_ON_FAIL ( 61baseObject -> getEntryPoint (i ,entryPointObj -> baseObject .writeRef ())); 62m_entryPoints .add (entryPointObj ); 63 } 64 } 65if (index > (GfxCount )m_entryPoints .getCount ()) 66 { 67GFX_DIAGNOSE_ERROR ("`index` must not exceed `entryPointCount`." ); 68return SLANG_FAIL ; 69 } 70returnComPtr (entryPoint ,m_entryPoints [index ]); 71return SLANG_OK ; 72} 73 74Result DebugShaderObject ::setData (ShaderOffset const & offset ,void const * data ,Size size ) 75{ 76SLANG_GFX_API_FUNC ; 77return baseObject -> setData (offset ,data ,size ); 78} 79 80Result DebugShaderObject ::getObject (ShaderOffset const & offset ,IShaderObject ** object ) 81{ 82SLANG_GFX_API_FUNC ; 83 84ComPtr < IShaderObject > innerObject ; 85auto resultCode = baseObject -> getObject (offset ,innerObject .writeRef ()); 86SLANG_RETURN_ON_FAIL (resultCode ); 87RefPtr < DebugShaderObject > debugShaderObject ; 88if (m_objects .tryGetValue (ShaderOffsetKey {offset },debugShaderObject )) 89 { 90if (debugShaderObject -> baseObject == innerObject ) 91 { 92returnComPtr (object ,debugShaderObject ); 93return resultCode ; 94 } 95 } 96debugShaderObject = new DebugShaderObject (); 97debugShaderObject -> baseObject = innerObject ; 98debugShaderObject -> m_typeName = innerObject -> getElementTypeLayout ()-> getName (); 99m_objects [ShaderOffsetKey {offset }]= debugShaderObject ; 100returnComPtr (object ,debugShaderObject ); 101return resultCode ; 102} 103 104Result DebugShaderObject ::setObject (ShaderOffset const & offset ,IShaderObject * object ) 105{ 106SLANG_GFX_API_FUNC ; 107auto objectImpl = getDebugObj (object ); 108m_objects [ShaderOffsetKey {offset }]= objectImpl ; 109m_initializedBindingRanges .add (offset .bindingRangeIndex ); 110objectImpl -> checkCompleteness (); 111return baseObject -> setObject (offset ,getInnerObj (object )); 112} 113 114Result DebugShaderObject ::setResource (ShaderOffset const & offset ,IResourceView * resourceView ) 115{ 116SLANG_GFX_API_FUNC ; 117auto viewImpl = getDebugObj (resourceView ); 118m_resources [ShaderOffsetKey {offset }]= viewImpl ; 119m_initializedBindingRanges .add (offset .bindingRangeIndex ); 120return baseObject -> setResource (offset ,getInnerObj (resourceView )); 121} 122 123Result DebugShaderObject ::setSampler (ShaderOffset const & offset ,ISamplerState * sampler ) 124{ 125SLANG_GFX_API_FUNC ; 126auto samplerImpl = getDebugObj (sampler ); 127m_samplers [ShaderOffsetKey {offset }]= samplerImpl ; 128m_initializedBindingRanges .add (offset .bindingRangeIndex ); 129return baseObject -> setSampler (offset ,getInnerObj (sampler )); 130} 131 132Result DebugShaderObject ::setCombinedTextureSampler ( 133ShaderOffset const & offset , 134IResourceView * textureView , 135ISamplerState * sampler ) 136{ 137SLANG_GFX_API_FUNC ; 138auto samplerImpl = getDebugObj (sampler ); 139m_samplers [ShaderOffsetKey {offset }]= samplerImpl ; 140auto viewImpl = getDebugObj (textureView ); 141m_resources [ShaderOffsetKey {offset }]= viewImpl ; 142m_initializedBindingRanges .add (offset .bindingRangeIndex ); 143return baseObject -> setCombinedTextureSampler ( 144offset , 145getInnerObj (viewImpl ), 146getInnerObj (sampler )); 147} 148 149Result DebugShaderObject ::setSpecializationArgs ( 150ShaderOffset const & offset , 151const slang::SpecializationArg * args , 152GfxCount count ) 153{ 154SLANG_GFX_API_FUNC ; 155return baseObject -> setSpecializationArgs (offset ,args ,count ); 156} 157 158Result DebugShaderObject ::getCurrentVersion ( 159ITransientResourceHeap * transientHeap , 160IShaderObject ** outObject ) 161{ 162SLANG_GFX_API_FUNC ; 163ComPtr < IShaderObject > innerObject ; 164SLANG_RETURN_ON_FAIL ( 165baseObject -> getCurrentVersion (getInnerObj (transientHeap ),innerObject .writeRef ())); 166RefPtr < DebugShaderObject > debugShaderObject = new DebugShaderObject (); 167debugShaderObject -> baseObject = innerObject ; 168debugShaderObject -> m_typeName = innerObject -> getElementTypeLayout ()-> getName (); 169returnComPtr (outObject ,debugShaderObject ); 170return SLANG_OK ; 171} 172 173const void * DebugShaderObject ::getRawData () 174{ 175SLANG_GFX_API_FUNC ; 176return baseObject -> getRawData (); 177} 178 179size_t DebugShaderObject ::getSize () 180{ 181SLANG_GFX_API_FUNC ; 182return baseObject -> getSize (); 183} 184 185Result DebugShaderObject ::setConstantBufferOverride (IBufferResource * constantBuffer ) 186{ 187SLANG_GFX_API_FUNC ; 188return baseObject -> setConstantBufferOverride (getInnerObj (constantBuffer )); 189} 190 191Result DebugRootShaderObject ::setSpecializationArgs ( 192ShaderOffset const & offset , 193const slang::SpecializationArg * args , 194GfxCount count ) 195{ 196SLANG_GFX_API_FUNC ; 197 198return baseObject -> setSpecializationArgs (offset ,args ,count ); 199} 200 201void DebugRootShaderObject ::reset () 202{ 203m_entryPoints .clear (); 204m_objects .clear (); 205m_resources .clear (); 206m_samplers .clear (); 207baseObject .detach (); 208} 209 210}// namespace debug 211}// namespace gfx