Browse Source

DKShaderResource 출력.

Hongtae Kim 6 years ago
parent
commit
8f473f730b
1 changed files with 149 additions and 14 deletions
  1. 149
    14
      TestApp1/TestApp1.cpp

+ 149
- 14
TestApp1/TestApp1.cpp View File

@@ -6,6 +6,153 @@
6 6
 #endif
7 7
 #include <DK.h>
8 8
 
9
+const char* ShaderDataTypeStr(DKShaderDataType t)
10
+{
11
+	switch (t) {
12
+	case DKShaderDataType::Unknown:				return "Unknown";
13
+	case DKShaderDataType::None:				return "None";
14
+
15
+	case DKShaderDataType::Struct:				return "Struct";
16
+	case DKShaderDataType::Texture:				return "Texture";
17
+	case DKShaderDataType::Sampler:				return "Sampler";
18
+
19
+	case DKShaderDataType::Float:				return "Float";
20
+	case DKShaderDataType::Float2:				return "Float2";
21
+	case DKShaderDataType::Float3:				return "Float3";
22
+	case DKShaderDataType::Float4:				return "Float4";
23
+
24
+	case DKShaderDataType::Float2x2:			return "Float2x2";
25
+	case DKShaderDataType::Float2x3:			return "Float2x3";
26
+	case DKShaderDataType::Float2x4:			return "Float2x4";
27
+
28
+	case DKShaderDataType::Float3x2:			return "Float3x2";
29
+	case DKShaderDataType::Float3x3:			return "Float3x3";
30
+	case DKShaderDataType::Float3x4:			return "Float3x4";
31
+
32
+	case DKShaderDataType::Float4x2:			return "Float4x2";
33
+	case DKShaderDataType::Float4x3:			return "Float4x3";
34
+	case DKShaderDataType::Float4x4:			return "Float4x4";
35
+
36
+	case DKShaderDataType::Half:				return "Half";
37
+	case DKShaderDataType::Half2:				return "Half2";
38
+	case DKShaderDataType::Half3:				return "Half3";
39
+	case DKShaderDataType::Half4:				return "Half4";
40
+
41
+	case DKShaderDataType::Half2x2:				return "Half2x2";
42
+	case DKShaderDataType::Half2x3:				return "Half2x3";
43
+	case DKShaderDataType::Half2x4:				return "Half2x4";
44
+
45
+	case DKShaderDataType::Half3x2:				return "Half3x2";
46
+	case DKShaderDataType::Half3x3:				return "Half3x3";
47
+	case DKShaderDataType::Half3x4:				return "Half3x4";
48
+
49
+	case DKShaderDataType::Half4x2:				return "Half4x2";
50
+	case DKShaderDataType::Half4x3:				return "Half4x3";
51
+	case DKShaderDataType::Half4x4:				return "Half4x4";
52
+
53
+	case DKShaderDataType::Int:					return "Int";
54
+	case DKShaderDataType::Int2:				return "Int2";
55
+	case DKShaderDataType::Int3:				return "Int3";
56
+	case DKShaderDataType::Int4:				return "Int4";
57
+
58
+	case DKShaderDataType::UInt:				return "UInt";
59
+	case DKShaderDataType::UInt2:				return "UInt2";
60
+	case DKShaderDataType::UInt3:				return "UInt3";
61
+	case DKShaderDataType::UInt4:				return "UInt4";
62
+
63
+	case DKShaderDataType::Short:				return "Short";
64
+	case DKShaderDataType::Short2:				return "Short2";
65
+	case DKShaderDataType::Short3:				return "Short3";
66
+	case DKShaderDataType::Short4:				return "Short4";
67
+
68
+	case DKShaderDataType::UShort:				return "UShort";
69
+	case DKShaderDataType::UShort2:				return "UShort2";
70
+	case DKShaderDataType::UShort3:				return "UShort3";
71
+	case DKShaderDataType::UShort4:				return "UShort4";
72
+
73
+	case DKShaderDataType::Char:				return "Char";
74
+	case DKShaderDataType::Char2:				return "Char2";
75
+	case DKShaderDataType::Char3:				return "Char3";
76
+	case DKShaderDataType::Char4:				return "Char4";
77
+
78
+	case DKShaderDataType::UChar:				return "UChar";
79
+	case DKShaderDataType::UChar2:				return "UChar2";
80
+	case DKShaderDataType::UChar3:				return "UChar3";
81
+	case DKShaderDataType::UChar4:				return "UChar4";
82
+
83
+	case DKShaderDataType::Bool:				return "Bool";
84
+	case DKShaderDataType::Bool2:				return "Bool2";
85
+	case DKShaderDataType::Bool3:				return "Bool3";
86
+	case DKShaderDataType::Bool4:				return "Bool4";
87
+	}
88
+	return "Error";
89
+}
90
+
91
+void PrintShaderResource(const DKShaderResource& res)
92
+{
93
+	struct MemberPrinter
94
+	{
95
+		const DKShaderResource& res;
96
+		int indent;
97
+		void operator()(const DKShaderResourceStruct& str) const
98
+		{
99
+			DKString indentStr = "";
100
+			for (int i = 0; i < indent; ++i)
101
+			{
102
+				indentStr += "    ";
103
+			}
104
+			for (const DKShaderResourceStructMember& mem : str.members)
105
+			{
106
+				if (mem.count > 1)
107
+				{
108
+					DKLogI(" %ls+ %ls[%d] (%s, Offset: %d, Size: %d, Stride: %d)", (const wchar_t*)indentStr,
109
+						(const wchar_t*)mem.name,
110
+						   mem.count,
111
+						   ShaderDataTypeStr(mem.dataType),
112
+						   mem.offset, mem.size, mem.stride);
113
+
114
+				}
115
+				else
116
+				{
117
+					DKLogI(" %ls+ %ls (%s, Offset: %d, Size: %d)", (const wchar_t*)indentStr,
118
+						(const wchar_t*)mem.name,
119
+						   ShaderDataTypeStr(mem.dataType),
120
+						   mem.offset, mem.size);
121
+				}
122
+
123
+				auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
124
+				if (p)
125
+				{
126
+					MemberPrinter{ res, indent + 1 }.operator()(p->value);
127
+				}
128
+			}
129
+		}
130
+	};
131
+	if (res.count > 1)
132
+		DKLogI("ShaderResource: %ls[%d] (set=%d, binding=%d)",
133
+		(const wchar_t*)res.name, res.count, res.set, res.binding);
134
+	else
135
+		DKLogI("ShaderResource: %ls (set=%d, binding=%d)", (const wchar_t*)res.name, res.set, res.binding);
136
+
137
+	const char* type = "Unknown (ERROR)";
138
+	switch (res.type)
139
+	{
140
+	case DKShaderResource::TypeBuffer: type = "Buffer"; break;
141
+	case DKShaderResource::TypeTexture:	type = "Texture"; break;
142
+	case DKShaderResource::TypeSampler:	type = "Sampler"; break;
143
+	case DKShaderResource::TypeThreadgroupMemory:	type = "Threadinggroup"; break;
144
+	}
145
+	DKLogI(" +Type: %s, Writable: %d, Enabled: %d Alignment: %d, Size: %d",
146
+		   type, int(res.writable), int(res.enabled),
147
+		   res.typeInfo.buffer.alignment,
148
+		   res.typeInfo.buffer.size);
149
+	if (res.type == DKShaderResource::TypeBuffer)
150
+	{
151
+		auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
152
+		if (p)
153
+			MemberPrinter{ res, 1 }.operator()(p->value);
154
+	}
155
+}
9 156
 
10 157
 class TestApp1 : public DKApplication
11 158
 {
@@ -86,24 +233,12 @@ public:
86 233
 		DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
87 234
 		if (pipelineState)
88 235
 		{
89
-			auto printShaderArg = [](const DKShaderResource& arg)
90
-			{
91
-				const char* argType = "Unknown";
92
-				switch (arg.type)
93
-				{
94
-				case DKShaderResource::TypeBuffer:	argType = "Buffer"; break;
95
-				case DKShaderResource::TypeTexture:	argType = "Texture"; break;
96
-				case DKShaderResource::TypeSampler:	argType = "Sampler"; break;
97
-				case DKShaderResource::TypeThreadgroupMemory:	argType = "ThreadMemory"; break;
98
-				}
99
-				DKLog("  --> \"%ls\"[%u] binding:%u:%u type:%s", (const wchar_t*)arg.name, uint32_t(arg.count), arg.set, arg.binding, argType);
100
-			};
101 236
 			DKLog("PipelineReflection.VertexResources: %d", reflection.vertexResources.Count());
102 237
 			for (auto& arg : reflection.vertexResources)
103
-				printShaderArg(arg);
238
+				PrintShaderResource(arg);
104 239
 			DKLog("PipelineReflection.FragmentResources: %d", reflection.fragmentResources.Count());
105 240
 			for (auto& arg : reflection.fragmentResources)
106
-				printShaderArg(arg);
241
+				PrintShaderResource(arg);
107 242
 		}
108 243
 
109 244
 		DKTimer timer;