1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
// debug-helper-functions.h
#pragma once
#include "debug-base.h"
#include "debug-buffer.h"
#include "debug-command-buffer.h"
#include "debug-command-queue.h"
#include "debug-device.h"
#include "debug-fence.h"
#include "debug-framebuffer.h"
#include "debug-pipeline-state.h"
#include "debug-query.h"
#include "debug-render-pass.h"
#include "debug-resource-views.h"
#include "debug-sampler-state.h"
#include "debug-shader-object.h"
#include "debug-shader-program.h"
#include "debug-shader-table.h"
#include "debug-swap-chain.h"
#include "debug-texture.h"
#include "debug-transient-heap.h"
#include "debug-vertex-layout.h"
namespace gfx
{
using namespace Slang;
namespace debug
{
#ifdef __FUNCSIG__
#define SLANG_FUNC_SIG __FUNCSIG__
#elif defined(__PRETTY_FUNCTION__)
#define SLANG_FUNC_SIG __FUNCSIG__
#elif defined(__FUNCTION__)
#define SLANG_FUNC_SIG __FUNCTION__
#else
#define SLANG_FUNC_SIG "UnknownFunction"
#endif
extern thread_local const char* _currentFunctionName;
struct SetCurrentFuncRAII
{
SetCurrentFuncRAII(const char* funcName) { _currentFunctionName = funcName; }
~SetCurrentFuncRAII() { _currentFunctionName = nullptr; }
};
#define SLANG_GFX_API_FUNC SetCurrentFuncRAII setFuncNameRAII(SLANG_FUNC_SIG)
#define SLANG_GFX_API_FUNC_NAME(x) SetCurrentFuncRAII setFuncNameRAII(x)
/// Returns the public API function name from a `SLANG_FUNC_SIG` string.
String _gfxGetFuncName(const char* input);
template<typename... TArgs>
char* _gfxDiagnoseFormat(
char* buffer, // Initial buffer to output formatted string.
size_t shortBufferSize, // Size of the initial buffer.
List<char>& bufferArray, // A list for allocating a large buffer if needed.
const char* format, // The format string.
TArgs... args)
{
int length = sprintf_s(buffer, shortBufferSize, format, args...);
if (length < 0)
return buffer;
if (length > 255)
{
bufferArray.setCount(length + 1);
buffer = bufferArray.getBuffer();
sprintf_s(buffer, bufferArray.getCount(), format, args...);
}
return buffer;
}
template<typename... TArgs>
void _gfxDiagnoseImpl(DebugMessageType type, const char* format, TArgs... args)
{
char shortBuffer[256];
List<char> bufferArray;
auto buffer =
_gfxDiagnoseFormat(shortBuffer, sizeof(shortBuffer), bufferArray, format, args...);
getDebugCallback()->handleMessage(type, DebugMessageSource::Layer, buffer);
}
#define GFX_DIAGNOSE_ERROR(message) \
_gfxDiagnoseImpl( \
DebugMessageType::Error, \
"%s: %s", \
_gfxGetFuncName(_currentFunctionName ? _currentFunctionName : SLANG_FUNC_SIG).getBuffer(), \
message)
#define GFX_DIAGNOSE_WARNING(message) \
_gfxDiagnoseImpl( \
DebugMessageType::Warning, \
"%s: %s", \
_gfxGetFuncName(_currentFunctionName ? _currentFunctionName : SLANG_FUNC_SIG).getBuffer(), \
message)
#define GFX_DIAGNOSE_INFO(message) \
_gfxDiagnoseImpl( \
DebugMessageType::Info, \
"%s: %s", \
_gfxGetFuncName(_currentFunctionName ? _currentFunctionName : SLANG_FUNC_SIG).getBuffer(), \
message)
#define GFX_DIAGNOSE_FORMAT(type, format, ...) \
{ \
char shortBuffer[256]; \
List<char> bufferArray; \
auto message = _gfxDiagnoseFormat( \
shortBuffer, \
sizeof(shortBuffer), \
bufferArray, \
format, \
__VA_ARGS__); \
_gfxDiagnoseImpl( \
type, \
"%s: %s", \
_gfxGetFuncName(_currentFunctionName ? _currentFunctionName : SLANG_FUNC_SIG) \
.getBuffer(), \
message); \
}
#define GFX_DIAGNOSE_ERROR_FORMAT(...) GFX_DIAGNOSE_FORMAT(DebugMessageType::Error, __VA_ARGS__)
#define SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(typeName) \
I##typeName* Debug##typeName::getInterface(const Slang::Guid& guid) \
{ \
return (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_I##typeName) \
? static_cast<I##typeName*>(this) \
: nullptr; \
}
#define SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT(typeName, parentType) \
I##typeName* Debug##typeName::getInterface(const Slang::Guid& guid) \
{ \
return (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_I##typeName || \
guid == GfxGUID::IID_I##parentType) \
? static_cast<I##typeName*>(this) \
: nullptr; \
}
// Utility conversion functions to get Debug* object or the inner object from a user provided
// pointer.
#define SLANG_GFX_DEBUG_GET_OBJ_IMPL(type) \
inline Debug##type* getDebugObj(I##type* ptr) \
{ \
return static_cast<Debug##type*>(static_cast<DebugObject<I##type>*>(ptr)); \
} \
inline I##type* getInnerObj(I##type* ptr) \
{ \
if (!ptr) \
return nullptr; \
auto debugObj = getDebugObj(ptr); \
return debugObj->baseObject; \
}
#define SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(type) \
inline Debug##type* getDebugObj(I##type* ptr) \
{ \
return static_cast<Debug##type*>(static_cast<UnownedDebugObject<I##type>*>(ptr)); \
} \
inline I##type* getInnerObj(I##type* ptr) \
{ \
if (!ptr) \
return nullptr; \
auto debugObj = getDebugObj(ptr); \
return debugObj->baseObject; \
}
SLANG_GFX_DEBUG_GET_OBJ_IMPL(Device)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(BufferResource)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(TextureResource)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(CommandBuffer)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(CommandQueue)
SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(ComputeCommandEncoder)
SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(RenderCommandEncoder)
SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(ResourceCommandEncoder)
SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(RayTracingCommandEncoder)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(Framebuffer)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(FramebufferLayout)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(InputLayout)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(RenderPassLayout)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(PipelineState)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(ResourceView)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(SamplerState)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(ShaderObject)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(ShaderProgram)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(Swapchain)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(TransientResourceHeap)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(QueryPool)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(AccelerationStructure)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(Fence)
SLANG_GFX_DEBUG_GET_OBJ_IMPL(ShaderTable)
void validateAccelerationStructureBuildInputs(
const IAccelerationStructure::BuildInputs& buildInputs);
} // namespace debug
} // namespace gfx
|