@@ -15,6 +15,29 @@ using Slang::ComPtr;
15
15
16
16
namespace gfx_test
17
17
{
18
+ class DebugPrinter : public rhi ::IDebugCallback
19
+ {
20
+ public:
21
+ virtual SLANG_NO_THROW void SLANG_MCALL handleMessage (
22
+ rhi::DebugMessageType type,
23
+ rhi::DebugMessageSource source,
24
+ const char * message) override
25
+ {
26
+ static const char * kTypeStrings [] = {" INFO" , " WARN" , " ERROR" };
27
+ static const char * kSourceStrings [] = {" Layer" , " Driver" , " Slang" };
28
+ if (type == rhi::DebugMessageType::Error)
29
+ {
30
+ printf (" [%s] (%s) %s\n " , kTypeStrings [int (type)], kSourceStrings [int (source)], message);
31
+ fflush (stdout);
32
+ }
33
+ }
34
+ static DebugPrinter* getInstance ()
35
+ {
36
+ static DebugPrinter instance;
37
+ return &instance;
38
+ }
39
+ };
40
+
18
41
void diagnoseIfNeeded (slang::IBlob* diagnosticsBlob)
19
42
{
20
43
if (diagnosticsBlob != nullptr )
@@ -110,62 +133,6 @@ Result loadComputeProgram(
110
133
return outShaderProgram ? SLANG_OK : SLANG_FAIL;
111
134
}
112
135
113
- // Slang::Result loadComputeProgram(
114
- // rhi::IDevice* device,
115
- // slang::ISession* slangSession,
116
- // Slang::ComPtr<rhi::IShaderProgram>& outShaderProgram,
117
- // const char* shaderModuleName,
118
- // const char* entryPointName,
119
- // slang::ProgramLayout*& slangReflection,
120
- // PrecompilationMode precompilationMode)
121
- // {
122
- // Slang::ComPtr<slang::IBlob> diagnosticsBlob;
123
- // slang::IModule* module = slangSession->loadModule(shaderModuleName,
124
- // diagnosticsBlob.writeRef()); diagnoseIfNeeded(diagnosticsBlob); if (!module)
125
- // return SLANG_FAIL;
126
- //
127
- // ComPtr<slang::IEntryPoint> computeEntryPoint;
128
- // SLANG_RETURN_ON_FAIL(
129
- // module->findEntryPointByName(entryPointName, computeEntryPoint.writeRef()));
130
- //
131
- // Slang::List<slang::IComponentType*> componentTypes;
132
- // componentTypes.add(module);
133
- // componentTypes.add(computeEntryPoint);
134
- //
135
- // Slang::ComPtr<slang::IComponentType> composedProgram;
136
- // SlangResult result = slangSession->createCompositeComponentType(
137
- // componentTypes.getBuffer(),
138
- // componentTypes.getCount(),
139
- // composedProgram.writeRef(),
140
- // diagnosticsBlob.writeRef());
141
- // diagnoseIfNeeded(diagnosticsBlob);
142
- // SLANG_RETURN_ON_FAIL(result);
143
- //
144
- // ComPtr<slang::IComponentType> linkedProgram;
145
- // result = composedProgram->link(linkedProgram.writeRef(), diagnosticsBlob.writeRef());
146
- // diagnoseIfNeeded(diagnosticsBlob);
147
- // SLANG_RETURN_ON_FAIL(result);
148
- //
149
- // composedProgram = linkedProgram;
150
- // slangReflection = composedProgram->getLayout();
151
- //
152
- // rhi::ShaderProgramDesc programDesc = {};
153
- // programDesc.slangGlobalScope = composedProgram.get();
154
- // if (precompilationMode == PrecompilationMode::ExternalLink)
155
- // {
156
- // programDesc.downstreamLinkMode = rhi::IShaderProgram::DownstreamLinkMode::Deferred;
157
- // }
158
- // else
159
- // {
160
- // programDesc.downstreamLinkMode = gfx::IShaderProgram::DownstreamLinkMode::None;
161
- // }
162
- //
163
- // auto shaderProgram = device->createProgram(programDesc);
164
- //
165
- // outShaderProgram = shaderProgram;
166
- // return SLANG_OK;
167
- // }
168
-
169
136
Result loadComputeProgramFromSource (
170
137
IDevice* device,
171
138
ComPtr<IShaderProgram>& outShaderProgram,
@@ -303,6 +270,10 @@ Slang::ComPtr<IDevice> createTestingDevice(
303
270
deviceDesc.slang .compilerOptionEntries = compilerOptions.data ();
304
271
deviceDesc.slang .compilerOptionEntryCount = compilerOptions.size ();
305
272
273
+ if (context->enableDebugLayers ) {
274
+ deviceDesc.enableValidation = context->enableDebugLayers ;
275
+ deviceDesc.debugCallback = DebugPrinter::getInstance ();
276
+ }
306
277
307
278
D3D12DeviceExtendedDesc extDesc = {};
308
279
if (deviceType == DeviceType::D3D12)
0 commit comments