yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaMove switch statement bodies to their own lines (#5493)b118451e3

master
6.6 KiB161 linesraw
1// debug-helper-functions.cpp
2#include "debug-helper-functions.h"
3
4namespace gfx
5{
6using namespace Slang;
7
8namespace debug
9{
10
11thread_local const 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{
34    UnownedStringSlice str(input);
35    auto prefixIndex = str.indexOf(UnownedStringSlice("Debug"));
36    if (prefixIndex == -1)
37        return input;
38    auto endIndex = str.lastIndexOf('(');
39    if (endIndex == -1)
40        endIndex = str.getLength();
41    auto startIndex = prefixIndex + 5;
42    StringBuilder sb;
43    sb.appendChar('I');
44    sb.append(str.subString(startIndex, endIndex - startIndex));
45    return sb.produceString();
46}
47
48void validateAccelerationStructureBuildInputs(
49    const IAccelerationStructure::BuildInputs& buildInputs)
50{
51    switch (buildInputs.kind)
52    {
53    case IAccelerationStructure::Kind::TopLevel:
54        if (!buildInputs.instanceDescs)
55        {
56            GFX_DIAGNOSE_WARNING("IAccelerationStructure::BuildInputs::instanceDescs is null "
57                                 "when creating a top-level acceleration structure.");
58        }
59        break;
60    case IAccelerationStructure::Kind::BottomLevel:
61        if (!buildInputs.geometryDescs)
62        {
63            GFX_DIAGNOSE_WARNING("IAccelerationStructure::BuildInputs::geometryDescs is null "
64                                 "when creating a bottom-level acceleration structure.");
65        }
66        for (int i = 0; i < buildInputs.descCount; i++)
67        {
68            switch (buildInputs.geometryDescs[i].type)
69            {
70            case IAccelerationStructure::GeometryType::Triangles:
71                switch (buildInputs.geometryDescs[i].content.triangles.vertexFormat)
72                {
73                case Format::R32G32B32_FLOAT:
74                case Format::R32G32_FLOAT:
75                case Format::R16G16B16A16_FLOAT:
76                case Format::R16G16_FLOAT:
77                case Format::R16G16B16A16_SNORM:
78                case Format::R16G16_SNORM:
79                    break;
80                default:
81                    GFX_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                }
88                if (buildInputs.geometryDescs[i].content.triangles.indexCount)
89                {
90                    switch (buildInputs.geometryDescs[i].content.triangles.indexFormat)
91                    {
92                    case Format::R32_UINT:
93                    case Format::R16_UINT:
94                        break;
95                    default:
96                        GFX_DIAGNOSE_ERROR(
97                            "Unsupported "
98                            "IAccelerationStructure::TriangleDesc::indexFormat. Valid "
99                            "values are Unknown, R32_UINT or R16_UINT.");
100                    }
101                    if (!buildInputs.geometryDescs[i].content.triangles.indexData)
102                    {
103                        GFX_DIAGNOSE_ERROR(
104                            "IAccelerationStructure::TriangleDesc::indexData cannot be "
105                            "null if "
106                            "IAccelerationStructure::TriangleDesc::indexCount is not 0");
107                    }
108                }
109                if (buildInputs.geometryDescs[i].content.triangles.indexFormat != Format::Unknown)
110                {
111                    if (buildInputs.geometryDescs[i].content.triangles.indexCount == 0)
112                    {
113                        GFX_DIAGNOSE_ERROR("IAccelerationStructure::TriangleDesc::"
114                                           "indexCount cannot be 0 if "
115                                           "IAccelerationStructure::TriangleDesc::"
116                                           "indexFormat is not Format::Unknown");
117                    }
118                    if (buildInputs.geometryDescs[i].content.triangles.indexData == 0)
119                    {
120                        GFX_DIAGNOSE_ERROR(
121                            "IAccelerationStructure::TriangleDesc::indexData cannot be "
122                            "null if "
123                            "IAccelerationStructure::TriangleDesc::indexFormat is not "
124                            "Format::Unknown");
125                    }
126                }
127                else
128                {
129                    if (buildInputs.geometryDescs[i].content.triangles.indexCount != 0)
130                    {
131                        GFX_DIAGNOSE_ERROR(
132                            "IAccelerationStructure::TriangleDesc::indexCount must be 0 if "
133                            "IAccelerationStructure::TriangleDesc::indexFormat is "
134                            "Format::Unknown");
135                    }
136                    if (buildInputs.geometryDescs[i].content.triangles.indexData != 0)
137                    {
138                        GFX_DIAGNOSE_ERROR(
139                            "IAccelerationStructure::TriangleDesc::indexData must be null "
140                            "if "
141                            "IAccelerationStructure::TriangleDesc::indexFormat is "
142                            "Format::Unknown");
143                    }
144                }
145                if (!buildInputs.geometryDescs[i].content.triangles.vertexData)
146                {
147                    GFX_DIAGNOSE_ERROR(
148                        "IAccelerationStructure::TriangleDesc::vertexData cannot be null.");
149                }
150                break;
151            }
152        }
153        break;
154    default:
155        GFX_DIAGNOSE_ERROR("Invalid value of IAccelerationStructure::Kind.");
156        break;
157    }
158}
159
160} // namespace debug
161} // namespace gfx