Browse Source

Reflection 더 자세히 출력.

Hongtae Kim 5 years ago
parent
commit
d33ec8e21d
1 changed files with 103 additions and 95 deletions
  1. 103
    95
      TestApp1/TestApp1.cpp

+ 103
- 95
TestApp1/TestApp1.cpp View File

@@ -6,6 +6,31 @@
6 6
 #endif
7 7
 #include <DK.h>
8 8
 
9
+DKString ShaderStageNames(uint32_t s)
10
+{
11
+	DKArray<const char*> stages;
12
+	if (s & (uint32_t)DKShaderStage::Vertex)
13
+		stages.Add("Vertex");
14
+	if (s & (uint32_t)DKShaderStage::TessellationControl)
15
+		stages.Add("TessCtrl");
16
+	if (s & (uint32_t)DKShaderStage::TessellationEvaluation)
17
+		stages.Add("TessEval");
18
+	if (s & (uint32_t)DKShaderStage::Geometry)
19
+		stages.Add("Geometry");
20
+	if (s & (uint32_t)DKShaderStage::Fragment)
21
+		stages.Add("Fragment");
22
+	if (s & (uint32_t)DKShaderStage::Compute)
23
+		stages.Add("Compute");
24
+
25
+	if (stages.IsEmpty())
26
+		return "";
27
+
28
+	DKString str = stages.Value(0);
29
+	for (int i = 1; i < stages.Count(); ++i)
30
+		str += DKString::Format(", %ls", stages.Value(i));
31
+	return str;
32
+}
33
+
9 34
 const char* ShaderDataTypeStr(DKShaderDataType t)
10 35
 {
11 36
 	switch (t) {
@@ -88,14 +113,14 @@ const char* ShaderDataTypeStr(DKShaderDataType t)
88 113
 	return "Error";
89 114
 }
90 115
 
91
-DKVertexDescriptor VertexDescriptorForVertexAttributes(const DKArray<DKVertexAttribute>& attrs)
116
+DKVertexDescriptor VertexDescriptorForVertexAttributes(const DKArray<DKShaderAttribute>& attrs)
92 117
 {
93 118
     uint32_t vertexSize = 0;
94 119
     DKVertexDescriptor descriptor = {};
95 120
 
96 121
     for (uint32_t i = 0; i < attrs.Count(); ++i)
97 122
     {         
98
-        if (const DKVertexAttribute& attr = attrs.Value(i); attr.active)
123
+        if (const DKShaderAttribute& attr = attrs.Value(i); attr.enabled)
99 124
         {
100 125
             DKVertexAttributeDescriptor desc = {};
101 126
 
@@ -214,11 +239,16 @@ void PrintShaderResource(const DKShaderResource& res, DKLogCategory c = DKLogCat
214 239
 			}
215 240
 		}
216 241
 	};
242
+
243
+
217 244
 	if (res.count > 1)
218
-		DKLog(c, "ShaderResource: %ls[%d] (set=%d, binding=%d)",
219
-		(const wchar_t*)res.name, res.count, res.set, res.binding);
245
+		DKLog(c, "ShaderResource: %ls[%d] (set=%d, binding=%d, stages=%ls)",
246
+			 (const wchar_t*)res.name, res.count, res.set, res.binding,
247
+			 (const wchar_t*)ShaderStageNames(res.stages));
220 248
 	else
221
-		DKLog(c, "ShaderResource: %ls (set=%d, binding=%d)", (const wchar_t*)res.name, res.set, res.binding);
249
+		DKLog(c, "ShaderResource: %ls (set=%d, binding=%d, stages=%ls)",
250
+			 (const wchar_t*)res.name, res.set, res.binding,
251
+			 (const wchar_t*)ShaderStageNames(res.stages));
222 252
 
223 253
 	const char* type = "Unknown (ERROR)";
224 254
 	switch (res.type)
@@ -269,27 +299,68 @@ class TestApp1 : public DKApplication
269 299
 
270 300
     DKObject<DKGraphicsDevice> device;
271 301
 
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);
302
+	void PrintShaderReflection(const DKShader* shader, DKLogCategory c = DKLogCategory::Warning)
303
+	{
304
+		DKString stage = ShaderStageNames((uint32_t)shader->Stage());
305
+		if (stage.Length() == 0)
306
+			stage = "Unknown";
307
+
308
+		DKLog(c, "=========================================================");
309
+		DKLog(c, "Shader<%ls.SPIR-V>.InputAttributes: %d",
310
+			(const wchar_t*)stage, shader->InputAttributes().Count());
311
+		for (int i = 0; i < shader->InputAttributes().Count(); ++i)
312
+		{
313
+			const DKShaderAttribute& attr = shader->InputAttributes().Value(i);
314
+			DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
315
+				  i, (const wchar_t*)attr.name, attr.location);
316
+		}
317
+		DKLog(c, "---------------------------------------------------------");
318
+		DKLog(c, "Shader<%ls.SPIR-V>.OutputAttributes: %d",
319
+			(const wchar_t*)stage, shader->OutputAttributes().Count());
320
+		for (int i = 0; i < shader->OutputAttributes().Count(); ++i)
321
+		{
322
+			const DKShaderAttribute& attr = shader->OutputAttributes().Value(i);
323
+			DKLog(c, "  [out] ShaderAttribute[%d]: \"%ls\" (location:%u)",
324
+				  i, (const wchar_t*)attr.name, attr.location);
325
+		}
326
+		DKLog(c, "---------------------------------------------------------");
327
+		DKLog(c, "Shader<%ls.SPIR-V>.Resources: %d",
328
+			  (const wchar_t*)stage, shader->Resources().Count());
329
+		for (auto& arg : shader->Resources())
330
+			PrintShaderResource(arg, c);
331
+		for (int i = 0; i < shader->PushConstantBufferLayouts().Count(); ++i)
332
+		{
333
+			const DKShaderPushConstantLayout& layout = shader->PushConstantBufferLayouts().Value(i);
334
+			DKLog(c, " PushConstant:%d \"%ls\" (offset:%u, size:%u, stages:%ls)",
335
+				  i, (const wchar_t*)layout.name, layout.offset, layout.size,
336
+				  (const wchar_t*)ShaderStageNames(layout.stages));
337
+		}
338
+		DKLog(c, "=========================================================");
339
+	}
290 340
 
291
-        }
292
-    }
341
+	void PrintPipelineReflection(const DKPipelineReflection* reflection, DKLogCategory c = DKLogCategory::Error)
342
+	{
343
+		DKLog(c, "=========================================================");
344
+		DKLog(c, "PipelineReflection.InputAttributes: %d", reflection->inputAttributes.Count());
345
+		for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
346
+		{
347
+			const DKShaderAttribute& attr = reflection->inputAttributes.Value(i);
348
+			DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
349
+				  i, (const wchar_t*)attr.name, attr.location);
350
+		}
351
+		DKLog(c, "---------------------------------------------------------");
352
+		DKLog(c, "PipelineReflection.Resources: %d", reflection->resources.Count());
353
+		for (auto& arg : reflection->resources)
354
+			PrintShaderResource(arg, c);
355
+		for (int i = 0; i < reflection->pushConstantLayouts.Count(); ++i)
356
+		{
357
+			const DKShaderPushConstantLayout& layout = reflection->pushConstantLayouts.Value(i);
358
+			DKLog(c, " PushConstant:%d \"%ls\" (offset:%u, size:%u, stages:%ls)",
359
+				  i, (const wchar_t*)layout.name, layout.offset, layout.size,
360
+				  (const wchar_t*)ShaderStageNames(layout.stages));
361
+		}
362
+		DKLog(c, "=========================================================");
363
+	}
293 364
 
294 365
     void TestRenderPipelineReflection(const DKString& path)
295 366
     {
@@ -302,33 +373,8 @@ class TestApp1 : public DKApplication
302 373
         DKShader vertShader(vertData);
303 374
         DKShader fragShader(fragData);
304 375
 
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
-        }
376
+		PrintShaderReflection(&vertShader, DKLogCategory::Warning);
377
+		PrintShaderReflection(&fragShader, DKLogCategory::Warning);
332 378
 
333 379
         DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
334 380
         DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
@@ -354,26 +400,11 @@ class TestApp1 : public DKApplication
354 400
         pipelineDescriptor.cullMode = DKCullMode::None;
355 401
         pipelineDescriptor.rasterizationEnabled = true;
356 402
 
357
-        DKRenderPipelineReflection reflection;
403
+        DKPipelineReflection reflection;
358 404
         DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
359 405
         if (pipelineState)
360 406
         {
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());
370
-            for (auto& arg : reflection.vertexResources)
371
-                PrintShaderResource(arg, c);
372
-            DKLog(c, "---------------------------------------------------------");
373
-            DKLog(c, "PipelineReflection.FragmentResources: %d", reflection.fragmentResources.Count());
374
-            for (auto& arg : reflection.fragmentResources)
375
-                PrintShaderResource(arg, c);
376
-            DKLog(c, "=========================================================");
407
+			PrintPipelineReflection(&reflection, DKLogCategory::Error);
377 408
         }
378 409
         else
379 410
         {
@@ -389,22 +420,7 @@ class TestApp1 : public DKApplication
389 420
 
390 421
         DKShader shader(shaderData);
391 422
 
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
-        }
423
+		PrintShaderReflection(&shader, DKLogCategory::Warning);
408 424
 
409 425
         DKObject<DKShaderModule> shaderModule = device->CreateShaderModule(&shader);
410 426
         DKObject<DKShaderFunction> shaderFunction = shaderModule->CreateFunction(shaderModule->FunctionNames().Value(0));
@@ -414,19 +430,11 @@ class TestApp1 : public DKApplication
414 430
         DKComputePipelineDescriptor pipelineDescriptor = {};
415 431
         pipelineDescriptor.computeFunction = shaderFunction;
416 432
 
417
-        DKComputePipelineReflection reflection;
433
+        DKPipelineReflection reflection;
418 434
         DKObject<DKComputePipelineState> pipelineState = device->CreateComputePipeline(pipelineDescriptor, &reflection);
419 435
         if (pipelineState)
420 436
         {
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());
427
-            for (auto& arg : reflection.resources)
428
-                PrintShaderResource(arg, c);
429
-            DKLog(c, "=========================================================");
437
+			PrintPipelineReflection(&reflection, DKLogCategory::Error);
430 438
         }
431 439
         else
432 440
         {