Browse Source

no message

Hongtae Kim 5 years ago
parent
commit
f7941bae08
1 changed files with 105 additions and 40 deletions
  1. 105
    40
      TestApp1/TestApp1.cpp

+ 105
- 40
TestApp1/TestApp1.cpp View File

@@ -168,12 +168,13 @@ DKVertexDescriptor VertexDescriptorForVertexAttributes(const DKArray<DKVertexAtt
168 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 173
 	struct MemberPrinter
174 174
 	{
175 175
 		const DKShaderResource& res;
176 176
 		int indent;
177
+        DKLogCategory c;
177 178
 		void operator()(const DKShaderResourceStruct& str) const
178 179
 		{
179 180
 			DKString indentStr = "";
@@ -185,7 +186,7 @@ void PrintShaderResource(const DKShaderResource& res)
185 186
 			{
186 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 190
 						   (const wchar_t*)indentStr,
190 191
 						   (const wchar_t*)mem.name,
191 192
 						   mem.count,
@@ -195,7 +196,7 @@ void PrintShaderResource(const DKShaderResource& res)
195 196
 				}
196 197
 				else
197 198
 				{
198
-					DKLogI(" %ls+ %ls (%s, Offset: %d)",
199
+					DKLog(c, " %ls+ %ls (%s, Offset: %d)",
199 200
 						   (const wchar_t*)indentStr,
200 201
 						   (const wchar_t*)mem.name,
201 202
 						   ShaderDataTypeStr(mem.dataType),
@@ -205,19 +206,19 @@ void PrintShaderResource(const DKShaderResource& res)
205 206
 				auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
206 207
 				if (p)
207 208
 				{
208
-					DKLogI(" %ls  Struct \"%ls\"",
209
+					DKLog(c, " %ls  Struct \"%ls\"",
209 210
 						   (const wchar_t*)indentStr,
210 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 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 219
 		(const wchar_t*)res.name, res.count, res.set, res.binding);
219 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 223
 	const char* type = "Unknown (ERROR)";
223 224
 	switch (res.type)
@@ -226,7 +227,6 @@ void PrintShaderResource(const DKShaderResource& res)
226 227
 	case DKShaderResource::TypeTexture:	type = "Texture"; break;
227 228
 	case DKShaderResource::TypeSampler:	type = "Sampler"; break;
228 229
     case DKShaderResource::TypeSampledTexture: type = "SampledTexture"; break;
229
-	case DKShaderResource::TypeThreadgroupMemory:	type = "Threadinggroup"; break;
230 230
 	}
231 231
 	const char* access = "Unknown (ERROR)";
232 232
 	switch (res.access)
@@ -238,7 +238,7 @@ void PrintShaderResource(const DKShaderResource& res)
238 238
 
239 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 242
                type,
243 243
                access,
244 244
                int(res.enabled),
@@ -246,18 +246,18 @@ void PrintShaderResource(const DKShaderResource& res)
246 246
     }
247 247
     else
248 248
     {
249
-        DKLogI(" Type:%s, Access:%s, Enabled:%d",
249
+        DKLog(c, " Type:%s, Access:%s, Enabled:%d",
250 250
                type,
251 251
                access,
252 252
                int(res.enabled));
253 253
     }
254 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 256
 	if (res.type == DKShaderResource::TypeBuffer)
257 257
 	{
258 258
 		auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
259 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,6 +269,28 @@ class TestApp1 : public DKApplication
269 269
 
270 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 294
     void TestRenderPipelineReflection(const DKString& path)
273 295
     {
274 296
         DKObject<DKData> vertData = resourcePool.LoadResourceData(path + ".vert.spv");
@@ -277,8 +299,36 @@ class TestApp1 : public DKApplication
277 299
         DKASSERT(vertData);
278 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 333
         DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
284 334
         DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
@@ -286,15 +336,8 @@ class TestApp1 : public DKApplication
286 336
         DKObject<DKShaderFunction> vertShaderFunction = vertShaderModule->CreateFunction(vertShaderModule->FunctionNames().Value(0));
287 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 339
         // setup dummy vertex-descriptor
297
-        DKVertexDescriptor vertexDescriptor = VertexDescriptorForVertexAttributes(vertShaderFunction->VertexAttributes());
340
+        DKVertexDescriptor vertexDescriptor = VertexDescriptorForVertexAttributes(vertShaderFunction->StageInputAttributes());
298 341
 
299 342
         // setup rendering pipeline state object (PSO)
300 343
         DKRenderPipelineDescriptor pipelineDescriptor = {};
@@ -315,15 +358,22 @@ class TestApp1 : public DKApplication
315 358
         DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
316 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 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 374
             for (auto& arg : reflection.fragmentResources)
325
-                PrintShaderResource(arg);
326
-            DKLog("=========================================================");
375
+                PrintShaderResource(arg, c);
376
+            DKLog(c, "=========================================================");
327 377
         }
328 378
         else
329 379
         {
@@ -337,17 +387,28 @@ class TestApp1 : public DKApplication
337 387
 
338 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 409
         DKObject<DKShaderModule> shaderModule = device->CreateShaderModule(&shader);
343 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 413
         // setup pipeline state object (PSO)
353 414
         DKComputePipelineDescriptor pipelineDescriptor = {};
@@ -357,11 +418,15 @@ class TestApp1 : public DKApplication
357 418
         DKObject<DKComputePipelineState> pipelineState = device->CreateComputePipeline(pipelineDescriptor, &reflection);
358 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 427
             for (auto& arg : reflection.resources)
363
-                PrintShaderResource(arg);
364
-            DKLog("=========================================================");
428
+                PrintShaderResource(arg, c);
429
+            DKLog(c, "=========================================================");
365 430
         }
366 431
         else
367 432
         {