|
|
|
|
168
|
return descriptor;
|
168
|
return descriptor;
|
169
|
};
|
169
|
};
|
170
|
|
170
|
|
171
|
-void PrintShaderResource(const DKShaderResource& res)
|
|
|
|
|
171
|
+void PrintShaderResource(const DKShaderResource& res, DKLogCategory c = DKLogCategory::Info)
|
172
|
{
|
172
|
{
|
173
|
struct MemberPrinter
|
173
|
struct MemberPrinter
|
174
|
{
|
174
|
{
|
175
|
const DKShaderResource& res;
|
175
|
const DKShaderResource& res;
|
176
|
int indent;
|
176
|
int indent;
|
|
|
177
|
+ DKLogCategory c;
|
177
|
void operator()(const DKShaderResourceStruct& str) const
|
178
|
void operator()(const DKShaderResourceStruct& str) const
|
178
|
{
|
179
|
{
|
179
|
DKString indentStr = "";
|
180
|
DKString indentStr = "";
|
|
|
|
|
185
|
{
|
186
|
{
|
186
|
if (mem.count > 1)
|
187
|
if (mem.count > 1)
|
187
|
{
|
188
|
{
|
188
|
- DKLogI(" %ls+ %ls[%d] (%s, Offset: %d, Stride: %d)",
|
|
|
|
|
189
|
+ DKLog(c, " %ls+ %ls[%d] (%s, Offset: %d, Stride: %d)",
|
189
|
(const wchar_t*)indentStr,
|
190
|
(const wchar_t*)indentStr,
|
190
|
(const wchar_t*)mem.name,
|
191
|
(const wchar_t*)mem.name,
|
191
|
mem.count,
|
192
|
mem.count,
|
|
|
|
|
195
|
}
|
196
|
}
|
196
|
else
|
197
|
else
|
197
|
{
|
198
|
{
|
198
|
- DKLogI(" %ls+ %ls (%s, Offset: %d)",
|
|
|
|
|
199
|
+ DKLog(c, " %ls+ %ls (%s, Offset: %d)",
|
199
|
(const wchar_t*)indentStr,
|
200
|
(const wchar_t*)indentStr,
|
200
|
(const wchar_t*)mem.name,
|
201
|
(const wchar_t*)mem.name,
|
201
|
ShaderDataTypeStr(mem.dataType),
|
202
|
ShaderDataTypeStr(mem.dataType),
|
|
|
|
|
205
|
auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
|
206
|
auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
|
206
|
if (p)
|
207
|
if (p)
|
207
|
{
|
208
|
{
|
208
|
- DKLogI(" %ls Struct \"%ls\"",
|
|
|
|
|
209
|
+ DKLog(c, " %ls Struct \"%ls\"",
|
209
|
(const wchar_t*)indentStr,
|
210
|
(const wchar_t*)indentStr,
|
210
|
(const wchar_t*)mem.typeInfoKey);
|
211
|
(const wchar_t*)mem.typeInfoKey);
|
211
|
- MemberPrinter{ res, indent + 1 }.operator()(p->value);
|
|
|
|
|
212
|
+ MemberPrinter{ res, indent + 1, c}.operator()(p->value);
|
212
|
}
|
213
|
}
|
213
|
}
|
214
|
}
|
214
|
}
|
215
|
}
|
215
|
};
|
216
|
};
|
216
|
if (res.count > 1)
|
217
|
if (res.count > 1)
|
217
|
- DKLogI("ShaderResource: %ls[%d] (set=%d, binding=%d)",
|
|
|
|
|
218
|
+ DKLog(c, "ShaderResource: %ls[%d] (set=%d, binding=%d)",
|
218
|
(const wchar_t*)res.name, res.count, res.set, res.binding);
|
219
|
(const wchar_t*)res.name, res.count, res.set, res.binding);
|
219
|
else
|
220
|
else
|
220
|
- DKLogI("ShaderResource: %ls (set=%d, binding=%d)", (const wchar_t*)res.name, res.set, res.binding);
|
|
|
|
|
221
|
+ DKLog(c, "ShaderResource: %ls (set=%d, binding=%d)", (const wchar_t*)res.name, res.set, res.binding);
|
221
|
|
222
|
|
222
|
const char* type = "Unknown (ERROR)";
|
223
|
const char* type = "Unknown (ERROR)";
|
223
|
switch (res.type)
|
224
|
switch (res.type)
|
|
|
|
|
226
|
case DKShaderResource::TypeTexture: type = "Texture"; break;
|
227
|
case DKShaderResource::TypeTexture: type = "Texture"; break;
|
227
|
case DKShaderResource::TypeSampler: type = "Sampler"; break;
|
228
|
case DKShaderResource::TypeSampler: type = "Sampler"; break;
|
228
|
case DKShaderResource::TypeSampledTexture: type = "SampledTexture"; break;
|
229
|
case DKShaderResource::TypeSampledTexture: type = "SampledTexture"; break;
|
229
|
- case DKShaderResource::TypeThreadgroupMemory: type = "Threadinggroup"; break;
|
|
|
230
|
}
|
230
|
}
|
231
|
const char* access = "Unknown (ERROR)";
|
231
|
const char* access = "Unknown (ERROR)";
|
232
|
switch (res.access)
|
232
|
switch (res.access)
|
|
|
|
|
238
|
|
238
|
|
239
|
if (res.type == DKShaderResource::TypeBuffer)
|
239
|
if (res.type == DKShaderResource::TypeBuffer)
|
240
|
{
|
240
|
{
|
241
|
- DKLogI(" Type:%s, Access:%s, Enabled:%d, Size:%d",
|
|
|
|
|
241
|
+ DKLog(c, " Type:%s, Access:%s, Enabled:%d, Size:%d",
|
242
|
type,
|
242
|
type,
|
243
|
access,
|
243
|
access,
|
244
|
int(res.enabled),
|
244
|
int(res.enabled),
|
|
|
|
|
246
|
}
|
246
|
}
|
247
|
else
|
247
|
else
|
248
|
{
|
248
|
{
|
249
|
- DKLogI(" Type:%s, Access:%s, Enabled:%d",
|
|
|
|
|
249
|
+ DKLog(c, " Type:%s, Access:%s, Enabled:%d",
|
250
|
type,
|
250
|
type,
|
251
|
access,
|
251
|
access,
|
252
|
int(res.enabled));
|
252
|
int(res.enabled));
|
253
|
}
|
253
|
}
|
254
|
if (res.typeInfoKey.Length() > 0)
|
254
|
if (res.typeInfoKey.Length() > 0)
|
255
|
- DKLogI(" Struct \"%ls\"", (const wchar_t*)res.typeInfoKey);
|
|
|
|
|
255
|
+ DKLog(c, " Struct \"%ls\"", (const wchar_t*)res.typeInfoKey);
|
256
|
if (res.type == DKShaderResource::TypeBuffer)
|
256
|
if (res.type == DKShaderResource::TypeBuffer)
|
257
|
{
|
257
|
{
|
258
|
auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
|
258
|
auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
|
259
|
if (p)
|
259
|
if (p)
|
260
|
- MemberPrinter{ res, 1 }.operator()(p->value);
|
|
|
|
|
260
|
+ MemberPrinter{ res, 1 , c}.operator()(p->value);
|
261
|
}
|
261
|
}
|
262
|
}
|
262
|
}
|
263
|
|
263
|
|
|
|
|
|
269
|
|
269
|
|
270
|
DKObject<DKGraphicsDevice> device;
|
270
|
DKObject<DKGraphicsDevice> device;
|
271
|
|
271
|
|
|
|
272
|
+ void PrintShaderAttributes(const DKArray<DKShaderAttribute>& attrs, const char* prefix, DKLogCategory c = DKLogCategory::Warning)
|
|
|
273
|
+ {
|
|
|
274
|
+ for (int i = 0; i < attrs.Count(); ++i)
|
|
|
275
|
+ {
|
|
|
276
|
+ const DKShaderAttribute& attr = attrs.Value(i);
|
|
|
277
|
+ DKLog(c, " %s ShaderAttribute[%d]: \"%ls\" (location:%u)",
|
|
|
278
|
+ prefix,
|
|
|
279
|
+ i, (const wchar_t*)attr.name, attr.location);
|
|
|
280
|
+ }
|
|
|
281
|
+ }
|
|
|
282
|
+ void PrintPushConstantLayouts(const DKArray<DKShader::PushConstantLayout>& layouts, DKLogCategory c = DKLogCategory::Warning)
|
|
|
283
|
+ {
|
|
|
284
|
+ for (int i = 0; i < layouts.Count(); ++i)
|
|
|
285
|
+ {
|
|
|
286
|
+ const DKShader::PushConstantLayout& layout = layouts.Value(i);
|
|
|
287
|
+ DKLog(c, " PushConstant:%d \"%ls\" (Offset:%u, Size:%u)",
|
|
|
288
|
+ i,
|
|
|
289
|
+ (const wchar_t*)layout.name, layout.offset, layout.size);
|
|
|
290
|
+
|
|
|
291
|
+ }
|
|
|
292
|
+ }
|
|
|
293
|
+
|
272
|
void TestRenderPipelineReflection(const DKString& path)
|
294
|
void TestRenderPipelineReflection(const DKString& path)
|
273
|
{
|
295
|
{
|
274
|
DKObject<DKData> vertData = resourcePool.LoadResourceData(path + ".vert.spv");
|
296
|
DKObject<DKData> vertData = resourcePool.LoadResourceData(path + ".vert.spv");
|
|
|
|
|
277
|
DKASSERT(vertData);
|
299
|
DKASSERT(vertData);
|
278
|
DKASSERT(fragData);
|
300
|
DKASSERT(fragData);
|
279
|
|
301
|
|
280
|
- DKShader vertShader(vertData, DKShader::Vertex);
|
|
|
281
|
- DKShader fragShader(fragData, DKShader::Fragment);
|
|
|
|
|
302
|
+ DKShader vertShader(vertData);
|
|
|
303
|
+ DKShader fragShader(fragData);
|
|
|
304
|
+
|
|
|
305
|
+ if (1)
|
|
|
306
|
+ {
|
|
|
307
|
+ DKLogCategory c = DKLogCategory::Warning;
|
|
|
308
|
+ DKLog(c, "=========================================================");
|
|
|
309
|
+ DKLog(c, "Vertex-Shader<SPIR-V>.InputAttributes: %d", vertShader.InputAttributes().Count());
|
|
|
310
|
+ PrintShaderAttributes(vertShader.InputAttributes(), "[IN] ", c);
|
|
|
311
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
312
|
+ DKLog(c, "Vertex-Shader<SPIR-V>.OutputAttributes: %d", vertShader.OutputAttributes().Count());
|
|
|
313
|
+ PrintShaderAttributes(vertShader.OutputAttributes(), "[OUT]", c);
|
|
|
314
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
315
|
+ DKLog(c, "Fragment-Shader<SPIR-V>.InputAttributes: %d", fragShader.InputAttributes().Count());
|
|
|
316
|
+ PrintShaderAttributes(fragShader.InputAttributes(), "[IN] ", c);
|
|
|
317
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
318
|
+ DKLog(c, "Fragment-Shader<SPIR-V>.OutputAttributes: %d", fragShader.OutputAttributes().Count());
|
|
|
319
|
+ PrintShaderAttributes(fragShader.OutputAttributes(), "[OUT]", c);
|
|
|
320
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
321
|
+ DKLog(c, "Vertex-Shader<SPIR-V>.Resources: %d", vertShader.Resources().Count());
|
|
|
322
|
+ for (auto& arg : vertShader.Resources())
|
|
|
323
|
+ PrintShaderResource(arg, c);
|
|
|
324
|
+ PrintPushConstantLayouts(vertShader.PushConstantBufferLayouts());
|
|
|
325
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
326
|
+ DKLog(c, "Fragment-Shader<SPIR-V>.Resources: %d", fragShader.Resources().Count());
|
|
|
327
|
+ for (auto& arg : fragShader.Resources())
|
|
|
328
|
+ PrintShaderResource(arg, c);
|
|
|
329
|
+ PrintPushConstantLayouts(fragShader.PushConstantBufferLayouts());
|
|
|
330
|
+ DKLog(c, "=========================================================");
|
|
|
331
|
+ }
|
282
|
|
332
|
|
283
|
DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
|
333
|
DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
|
284
|
DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
|
334
|
DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
|
|
|
|
|
286
|
DKObject<DKShaderFunction> vertShaderFunction = vertShaderModule->CreateFunction(vertShaderModule->FunctionNames().Value(0));
|
336
|
DKObject<DKShaderFunction> vertShaderFunction = vertShaderModule->CreateFunction(vertShaderModule->FunctionNames().Value(0));
|
287
|
DKObject<DKShaderFunction> fragShaderFunction = fragShaderModule->CreateFunction(fragShaderModule->FunctionNames().Value(0));
|
337
|
DKObject<DKShaderFunction> fragShaderFunction = fragShaderModule->CreateFunction(fragShaderModule->FunctionNames().Value(0));
|
288
|
|
338
|
|
289
|
- DKLog("VertexFunction.VertexAttributes: %d", vertShaderFunction->VertexAttributes().Count());
|
|
|
290
|
- for (int i = 0; i < vertShaderFunction->VertexAttributes().Count(); ++i)
|
|
|
291
|
- {
|
|
|
292
|
- const DKVertexAttribute& attr = vertShaderFunction->VertexAttributes().Value(i);
|
|
|
293
|
- DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
|
|
|
294
|
- }
|
|
|
295
|
-
|
|
|
296
|
// setup dummy vertex-descriptor
|
339
|
// setup dummy vertex-descriptor
|
297
|
- DKVertexDescriptor vertexDescriptor = VertexDescriptorForVertexAttributes(vertShaderFunction->VertexAttributes());
|
|
|
|
|
340
|
+ DKVertexDescriptor vertexDescriptor = VertexDescriptorForVertexAttributes(vertShaderFunction->StageInputAttributes());
|
298
|
|
341
|
|
299
|
// setup rendering pipeline state object (PSO)
|
342
|
// setup rendering pipeline state object (PSO)
|
300
|
DKRenderPipelineDescriptor pipelineDescriptor = {};
|
343
|
DKRenderPipelineDescriptor pipelineDescriptor = {};
|
|
|
|
|
315
|
DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
|
358
|
DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
|
316
|
if (pipelineState)
|
359
|
if (pipelineState)
|
317
|
{
|
360
|
{
|
318
|
- DKLog("=========================================================");
|
|
|
319
|
- DKLog("PipelineReflection.VertexResources: %d", reflection.vertexResources.Count());
|
|
|
|
|
361
|
+ DKLogCategory c = DKLogCategory::Error;
|
|
|
362
|
+ DKLog(c, "=========================================================");
|
|
|
363
|
+ DKLog(c, "VertexFunction.StageInputAttributes: %d", vertShaderFunction->StageInputAttributes().Count());
|
|
|
364
|
+ PrintShaderAttributes(vertShaderFunction->StageInputAttributes(), "[IN] ", c);
|
|
|
365
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
366
|
+ DKLog(c, "FragmentFunction.StageInputAttributes: %d", fragShaderFunction->StageInputAttributes().Count());
|
|
|
367
|
+ PrintShaderAttributes(fragShaderFunction->StageInputAttributes(), "[IN] ", c);
|
|
|
368
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
369
|
+ DKLog(c, "PipelineReflection.VertexResources: %d", reflection.vertexResources.Count());
|
320
|
for (auto& arg : reflection.vertexResources)
|
370
|
for (auto& arg : reflection.vertexResources)
|
321
|
- PrintShaderResource(arg);
|
|
|
322
|
- DKLog("---------------------------------------------------------");
|
|
|
323
|
- DKLog("PipelineReflection.FragmentResources: %d", reflection.fragmentResources.Count());
|
|
|
|
|
371
|
+ PrintShaderResource(arg, c);
|
|
|
372
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
373
|
+ DKLog(c, "PipelineReflection.FragmentResources: %d", reflection.fragmentResources.Count());
|
324
|
for (auto& arg : reflection.fragmentResources)
|
374
|
for (auto& arg : reflection.fragmentResources)
|
325
|
- PrintShaderResource(arg);
|
|
|
326
|
- DKLog("=========================================================");
|
|
|
|
|
375
|
+ PrintShaderResource(arg, c);
|
|
|
376
|
+ DKLog(c, "=========================================================");
|
327
|
}
|
377
|
}
|
328
|
else
|
378
|
else
|
329
|
{
|
379
|
{
|
|
|
|
|
337
|
|
387
|
|
338
|
DKASSERT(shaderData);
|
388
|
DKASSERT(shaderData);
|
339
|
|
389
|
|
340
|
- DKShader shader(shaderData, DKShader::Compute);
|
|
|
|
|
390
|
+ DKShader shader(shaderData);
|
|
|
391
|
+
|
|
|
392
|
+ if (1)
|
|
|
393
|
+ {
|
|
|
394
|
+ DKLogCategory c = DKLogCategory::Warning;
|
|
|
395
|
+ DKLog(c, "=========================================================");
|
|
|
396
|
+ DKLog(c, "Compute-Shader<SPIR-V>.InputAttributes: %d", shader.InputAttributes().Count());
|
|
|
397
|
+ PrintShaderAttributes(shader.InputAttributes(), "[IN] ", c);
|
|
|
398
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
399
|
+ DKLog(c, "Compute-Shader<SPIR-V>.OutputAttributes: %d", shader.OutputAttributes().Count());
|
|
|
400
|
+ PrintShaderAttributes(shader.OutputAttributes(), "[OUT]", c);
|
|
|
401
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
402
|
+ DKLog(c, "Compute-Shader<SPIR-V>.Resources: %d", shader.Resources().Count());
|
|
|
403
|
+ for (auto& arg : shader.Resources())
|
|
|
404
|
+ PrintShaderResource(arg, c);
|
|
|
405
|
+ PrintPushConstantLayouts(shader.PushConstantBufferLayouts());
|
|
|
406
|
+ DKLog(c, "=========================================================");
|
|
|
407
|
+ }
|
341
|
|
408
|
|
342
|
DKObject<DKShaderModule> shaderModule = device->CreateShaderModule(&shader);
|
409
|
DKObject<DKShaderModule> shaderModule = device->CreateShaderModule(&shader);
|
343
|
DKObject<DKShaderFunction> shaderFunction = shaderModule->CreateFunction(shaderModule->FunctionNames().Value(0));
|
410
|
DKObject<DKShaderFunction> shaderFunction = shaderModule->CreateFunction(shaderModule->FunctionNames().Value(0));
|
344
|
|
411
|
|
345
|
- DKLog("ComputeFunction.StageInputAttributes: %d", shaderFunction->StageInputAttributes().Count());
|
|
|
346
|
- for (int i = 0; i < shaderFunction->StageInputAttributes().Count(); ++i)
|
|
|
347
|
- {
|
|
|
348
|
- const DKShaderAttribute& attr = shaderFunction->StageInputAttributes().Value(i);
|
|
|
349
|
- DKLog(" --> ShaderAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
|
|
|
350
|
- }
|
|
|
351
|
|
412
|
|
352
|
// setup pipeline state object (PSO)
|
413
|
// setup pipeline state object (PSO)
|
353
|
DKComputePipelineDescriptor pipelineDescriptor = {};
|
414
|
DKComputePipelineDescriptor pipelineDescriptor = {};
|
|
|
|
|
357
|
DKObject<DKComputePipelineState> pipelineState = device->CreateComputePipeline(pipelineDescriptor, &reflection);
|
418
|
DKObject<DKComputePipelineState> pipelineState = device->CreateComputePipeline(pipelineDescriptor, &reflection);
|
358
|
if (pipelineState)
|
419
|
if (pipelineState)
|
359
|
{
|
420
|
{
|
360
|
- DKLog("=========================================================");
|
|
|
361
|
- DKLog("PipelineReflection.Resources: %d", reflection.resources.Count());
|
|
|
|
|
421
|
+ DKLogCategory c = DKLogCategory::Error;
|
|
|
422
|
+ DKLog(c, "=========================================================");
|
|
|
423
|
+ DKLog(c, "ComputeFunction.StageInputAttributes: %d", shaderFunction->StageInputAttributes().Count());
|
|
|
424
|
+ PrintShaderAttributes(shaderFunction->StageInputAttributes(), "[IN]", c);
|
|
|
425
|
+ DKLog(c, "---------------------------------------------------------");
|
|
|
426
|
+ DKLog(c, "PipelineReflection.Resources: %d", reflection.resources.Count());
|
362
|
for (auto& arg : reflection.resources)
|
427
|
for (auto& arg : reflection.resources)
|
363
|
- PrintShaderResource(arg);
|
|
|
364
|
- DKLog("=========================================================");
|
|
|
|
|
428
|
+ PrintShaderResource(arg, c);
|
|
|
429
|
+ DKLog(c, "=========================================================");
|
365
|
}
|
430
|
}
|
366
|
else
|
431
|
else
|
367
|
{
|
432
|
{
|