yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b118451e3
master
1// debug-helper-functions.cpp 2#include "debug-helper-functions.h" 3 4namespace gfx 5{ 6using namespace Slang ; 7 8namespace debug 9{ 10 11thread_localconst char * _currentFunctionName = nullptr ; 12 13SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (Device ) 14SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT (BufferResource ,Resource ) 15SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT (TextureResource ,Resource ) 16SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (CommandQueue ) 17SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (Framebuffer ) 18SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (FramebufferLayout ) 19SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (InputLayout ) 20SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (RenderPassLayout ) 21SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (PipelineState ) 22SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (ResourceView ) 23SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (SamplerState ) 24SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (ShaderObject ) 25SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (ShaderProgram ) 26SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (Swapchain ) 27SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (QueryPool ) 28SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT (AccelerationStructure ,ResourceView ) 29SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (Fence ) 30SLANG_GFX_DEBUG_GET_INTERFACE_IMPL (ShaderTable ) 31 32String _gfxGetFuncName (const char * input ) 33{ 34UnownedStringSlice str (input ); 35auto prefixIndex = str .indexOf (UnownedStringSlice ("Debug" )); 36if (prefixIndex == -1 ) 37return input ; 38auto endIndex = str .lastIndexOf ('(' ); 39if (endIndex == -1 ) 40endIndex = str .getLength (); 41auto startIndex = prefixIndex + 5 ; 42StringBuilder sb ; 43sb .appendChar ('I' ); 44sb .append (str .subString (startIndex ,endIndex - startIndex )); 45return sb .produceString (); 46} 47 48void validateAccelerationStructureBuildInputs ( 49const IAccelerationStructure ::BuildInputs & buildInputs ) 50{ 51switch (buildInputs .kind ) 52 { 53case IAccelerationStructure ::Kind ::TopLevel : 54if (!buildInputs .instanceDescs ) 55 { 56GFX_DIAGNOSE_WARNING ("IAccelerationStructure::BuildInputs::instanceDescs is null " 57"when creating a top-level acceleration structure." ); 58 } 59break ; 60case IAccelerationStructure ::Kind ::BottomLevel : 61if (!buildInputs .geometryDescs ) 62 { 63GFX_DIAGNOSE_WARNING ("IAccelerationStructure::BuildInputs::geometryDescs is null " 64"when creating a bottom-level acceleration structure." ); 65 } 66for (int i = 0 ;i < buildInputs .descCount ;i ++ ) 67 { 68switch (buildInputs .geometryDescs [i ].type ) 69 { 70case IAccelerationStructure ::GeometryType ::Triangles : 71switch (buildInputs .geometryDescs [i ].content .triangles .vertexFormat ) 72 { 73case Format ::R32G32B32_FLOAT : 74case Format ::R32G32_FLOAT : 75case Format ::R16G16B16A16_FLOAT : 76case Format ::R16G16_FLOAT : 77case Format ::R16G16B16A16_SNORM : 78case Format ::R16G16_SNORM : 79break ; 80default : 81GFX_DIAGNOSE_ERROR ( 82"Unsupported " 83"IAccelerationStructure::TriangleDesc::vertexFormat. Valid " 84"values are R32G32B32_FLOAT, R32G32_FLOAT, R16G16B16A16_FLOAT, " 85"R16G16_FLOAT, " 86"R16G16B16A16_SNORM or R16G16_SNORM." ); 87 } 88if (buildInputs .geometryDescs [i ].content .triangles .indexCount ) 89 { 90switch (buildInputs .geometryDescs [i ].content .triangles .indexFormat ) 91 { 92case Format ::R32_UINT : 93case Format ::R16_UINT : 94break ; 95default : 96GFX_DIAGNOSE_ERROR ( 97"Unsupported " 98"IAccelerationStructure::TriangleDesc::indexFormat. Valid " 99"values are Unknown, R32_UINT or R16_UINT." ); 100 } 101if (!buildInputs .geometryDescs [i ].content .triangles .indexData ) 102 { 103GFX_DIAGNOSE_ERROR ( 104"IAccelerationStructure::TriangleDesc::indexData cannot be " 105"null if " 106"IAccelerationStructure::TriangleDesc::indexCount is not 0" ); 107 } 108 } 109if (buildInputs .geometryDescs [i ].content .triangles .indexFormat != Format ::Unknown ) 110 { 111if (buildInputs .geometryDescs [i ].content .triangles .indexCount == 0 ) 112 { 113GFX_DIAGNOSE_ERROR ("IAccelerationStructure::TriangleDesc::" 114"indexCount cannot be 0 if " 115"IAccelerationStructure::TriangleDesc::" 116"indexFormat is not Format::Unknown" ); 117 } 118if (buildInputs .geometryDescs [i ].content .triangles .indexData == 0 ) 119 { 120GFX_DIAGNOSE_ERROR ( 121"IAccelerationStructure::TriangleDesc::indexData cannot be " 122"null if " 123"IAccelerationStructure::TriangleDesc::indexFormat is not " 124"Format::Unknown" ); 125 } 126 } 127else 128 { 129if (buildInputs .geometryDescs [i ].content .triangles .indexCount != 0 ) 130 { 131GFX_DIAGNOSE_ERROR ( 132"IAccelerationStructure::TriangleDesc::indexCount must be 0 if " 133"IAccelerationStructure::TriangleDesc::indexFormat is " 134"Format::Unknown" ); 135 } 136if (buildInputs .geometryDescs [i ].content .triangles .indexData != 0 ) 137 { 138GFX_DIAGNOSE_ERROR ( 139"IAccelerationStructure::TriangleDesc::indexData must be null " 140"if " 141"IAccelerationStructure::TriangleDesc::indexFormat is " 142"Format::Unknown" ); 143 } 144 } 145if (!buildInputs .geometryDescs [i ].content .triangles .vertexData ) 146 { 147GFX_DIAGNOSE_ERROR ( 148"IAccelerationStructure::TriangleDesc::vertexData cannot be null." ); 149 } 150break ; 151 } 152 } 153break ; 154default : 155GFX_DIAGNOSE_ERROR ("Invalid value of IAccelerationStructure::Kind." ); 156break ; 157 } 158} 159 160}// namespace debug 161}// namespace gfx