|
@@ -1,243 +1,14 @@
|
1
|
1
|
|
2
|
2
|
#include "app.h"
|
|
3
|
+#include "util.h"
|
3
|
4
|
|
4
|
|
-DKString ShaderStageNames(uint32_t s)
|
5
|
|
-{
|
6
|
|
- DKArray<const char*> stages;
|
7
|
|
- if (s & (uint32_t)DKShaderStage::Vertex)
|
8
|
|
- stages.Add("Vertex");
|
9
|
|
- if (s & (uint32_t)DKShaderStage::TessellationControl)
|
10
|
|
- stages.Add("TessCtrl");
|
11
|
|
- if (s & (uint32_t)DKShaderStage::TessellationEvaluation)
|
12
|
|
- stages.Add("TessEval");
|
13
|
|
- if (s & (uint32_t)DKShaderStage::Geometry)
|
14
|
|
- stages.Add("Geometry");
|
15
|
|
- if (s & (uint32_t)DKShaderStage::Fragment)
|
16
|
|
- stages.Add("Fragment");
|
17
|
|
- if (s & (uint32_t)DKShaderStage::Compute)
|
18
|
|
- stages.Add("Compute");
|
19
|
|
-
|
20
|
|
- if (stages.IsEmpty())
|
21
|
|
- return "";
|
22
|
|
-
|
23
|
|
- DKString str = stages.Value(0);
|
24
|
|
- for (int i = 1; i < stages.Count(); ++i)
|
25
|
|
- str += DKString::Format(", %ls", stages.Value(i));
|
26
|
|
- return str;
|
27
|
|
-}
|
28
|
|
-
|
29
|
|
-const char* ShaderDataTypeStr(DKShaderDataType t)
|
30
|
|
-{
|
31
|
|
- switch (t) {
|
32
|
|
- case DKShaderDataType::Unknown: return "Unknown";
|
33
|
|
- case DKShaderDataType::None: return "None";
|
34
|
|
-
|
35
|
|
- case DKShaderDataType::Struct: return "Struct";
|
36
|
|
- case DKShaderDataType::Texture: return "Texture";
|
37
|
|
- case DKShaderDataType::Sampler: return "Sampler";
|
38
|
|
-
|
39
|
|
- case DKShaderDataType::Float: return "Float";
|
40
|
|
- case DKShaderDataType::Float2: return "Float2";
|
41
|
|
- case DKShaderDataType::Float3: return "Float3";
|
42
|
|
- case DKShaderDataType::Float4: return "Float4";
|
43
|
|
-
|
44
|
|
- case DKShaderDataType::Float2x2: return "Float2x2";
|
45
|
|
- case DKShaderDataType::Float2x3: return "Float2x3";
|
46
|
|
- case DKShaderDataType::Float2x4: return "Float2x4";
|
47
|
|
-
|
48
|
|
- case DKShaderDataType::Float3x2: return "Float3x2";
|
49
|
|
- case DKShaderDataType::Float3x3: return "Float3x3";
|
50
|
|
- case DKShaderDataType::Float3x4: return "Float3x4";
|
51
|
|
-
|
52
|
|
- case DKShaderDataType::Float4x2: return "Float4x2";
|
53
|
|
- case DKShaderDataType::Float4x3: return "Float4x3";
|
54
|
|
- case DKShaderDataType::Float4x4: return "Float4x4";
|
55
|
|
-
|
56
|
|
- case DKShaderDataType::Half: return "Half";
|
57
|
|
- case DKShaderDataType::Half2: return "Half2";
|
58
|
|
- case DKShaderDataType::Half3: return "Half3";
|
59
|
|
- case DKShaderDataType::Half4: return "Half4";
|
60
|
|
-
|
61
|
|
- case DKShaderDataType::Half2x2: return "Half2x2";
|
62
|
|
- case DKShaderDataType::Half2x3: return "Half2x3";
|
63
|
|
- case DKShaderDataType::Half2x4: return "Half2x4";
|
64
|
|
-
|
65
|
|
- case DKShaderDataType::Half3x2: return "Half3x2";
|
66
|
|
- case DKShaderDataType::Half3x3: return "Half3x3";
|
67
|
|
- case DKShaderDataType::Half3x4: return "Half3x4";
|
68
|
|
-
|
69
|
|
- case DKShaderDataType::Half4x2: return "Half4x2";
|
70
|
|
- case DKShaderDataType::Half4x3: return "Half4x3";
|
71
|
|
- case DKShaderDataType::Half4x4: return "Half4x4";
|
72
|
5
|
|
73
|
|
- case DKShaderDataType::Int: return "Int";
|
74
|
|
- case DKShaderDataType::Int2: return "Int2";
|
75
|
|
- case DKShaderDataType::Int3: return "Int3";
|
76
|
|
- case DKShaderDataType::Int4: return "Int4";
|
77
|
|
-
|
78
|
|
- case DKShaderDataType::UInt: return "UInt";
|
79
|
|
- case DKShaderDataType::UInt2: return "UInt2";
|
80
|
|
- case DKShaderDataType::UInt3: return "UInt3";
|
81
|
|
- case DKShaderDataType::UInt4: return "UInt4";
|
82
|
|
-
|
83
|
|
- case DKShaderDataType::Short: return "Short";
|
84
|
|
- case DKShaderDataType::Short2: return "Short2";
|
85
|
|
- case DKShaderDataType::Short3: return "Short3";
|
86
|
|
- case DKShaderDataType::Short4: return "Short4";
|
87
|
|
-
|
88
|
|
- case DKShaderDataType::UShort: return "UShort";
|
89
|
|
- case DKShaderDataType::UShort2: return "UShort2";
|
90
|
|
- case DKShaderDataType::UShort3: return "UShort3";
|
91
|
|
- case DKShaderDataType::UShort4: return "UShort4";
|
92
|
|
-
|
93
|
|
- case DKShaderDataType::Char: return "Char";
|
94
|
|
- case DKShaderDataType::Char2: return "Char2";
|
95
|
|
- case DKShaderDataType::Char3: return "Char3";
|
96
|
|
- case DKShaderDataType::Char4: return "Char4";
|
97
|
|
-
|
98
|
|
- case DKShaderDataType::UChar: return "UChar";
|
99
|
|
- case DKShaderDataType::UChar2: return "UChar2";
|
100
|
|
- case DKShaderDataType::UChar3: return "UChar3";
|
101
|
|
- case DKShaderDataType::UChar4: return "UChar4";
|
102
|
|
-
|
103
|
|
- case DKShaderDataType::Bool: return "Bool";
|
104
|
|
- case DKShaderDataType::Bool2: return "Bool2";
|
105
|
|
- case DKShaderDataType::Bool3: return "Bool3";
|
106
|
|
- case DKShaderDataType::Bool4: return "Bool4";
|
107
|
|
- }
|
108
|
|
- return "Error";
|
109
|
|
-}
|
110
|
|
-
|
111
|
|
-void PrintShaderResource(const DKShaderResource& res, DKLogCategory c = DKLogCategory::Info)
|
|
6
|
+class TriangleDemo : public SampleApp
|
112
|
7
|
{
|
113
|
|
- struct MemberPrinter
|
114
|
|
- {
|
115
|
|
- const DKShaderResource& res;
|
116
|
|
- int indent;
|
117
|
|
- DKLogCategory c;
|
118
|
|
- void operator()(const DKShaderResourceStruct& str) const
|
119
|
|
- {
|
120
|
|
- DKString indentStr = "";
|
121
|
|
- for (int i = 0; i < indent; ++i)
|
122
|
|
- {
|
123
|
|
- indentStr += " ";
|
124
|
|
- }
|
125
|
|
- for (const DKShaderResourceStructMember& mem : str.members)
|
126
|
|
- {
|
127
|
|
- if (mem.count > 1)
|
128
|
|
- {
|
129
|
|
- DKLog(c, " %ls+ %ls[%d] (%s, Offset: %d, Stride: %d)",
|
130
|
|
- (const wchar_t*)indentStr,
|
131
|
|
- (const wchar_t*)mem.name,
|
132
|
|
- mem.count,
|
133
|
|
- ShaderDataTypeStr(mem.dataType),
|
134
|
|
- mem.offset, mem.stride);
|
135
|
|
-
|
136
|
|
- }
|
137
|
|
- else
|
138
|
|
- {
|
139
|
|
- DKLog(c, " %ls+ %ls (%s, Offset: %d)",
|
140
|
|
- (const wchar_t*)indentStr,
|
141
|
|
- (const wchar_t*)mem.name,
|
142
|
|
- ShaderDataTypeStr(mem.dataType),
|
143
|
|
- mem.offset);
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
|
147
|
|
- if (p)
|
148
|
|
- {
|
149
|
|
- DKLog(c, " %ls Struct \"%ls\"",
|
150
|
|
- (const wchar_t*)indentStr,
|
151
|
|
- (const wchar_t*)mem.typeInfoKey);
|
152
|
|
- MemberPrinter{ res, indent + 1, c}.operator()(p->value);
|
153
|
|
- }
|
154
|
|
- }
|
155
|
|
- }
|
156
|
|
- };
|
157
|
|
-
|
158
|
|
-
|
159
|
|
- if (res.count > 1)
|
160
|
|
- DKLog(c, "ShaderResource: %ls[%d] (set=%d, binding=%d, stages=%ls)",
|
161
|
|
- (const wchar_t*)res.name, res.count, res.set, res.binding,
|
162
|
|
- (const wchar_t*)ShaderStageNames(res.stages));
|
163
|
|
- else
|
164
|
|
- DKLog(c, "ShaderResource: %ls (set=%d, binding=%d, stages=%ls)",
|
165
|
|
- (const wchar_t*)res.name, res.set, res.binding,
|
166
|
|
- (const wchar_t*)ShaderStageNames(res.stages));
|
167
|
|
-
|
168
|
|
- const char* type = "Unknown (ERROR)";
|
169
|
|
- switch (res.type)
|
170
|
|
- {
|
171
|
|
- case DKShaderResource::TypeBuffer: type = "Buffer"; break;
|
172
|
|
- case DKShaderResource::TypeTexture: type = "Texture"; break;
|
173
|
|
- case DKShaderResource::TypeSampler: type = "Sampler"; break;
|
174
|
|
- case DKShaderResource::TypeTextureSampler: type = "SampledTexture"; break;
|
175
|
|
- }
|
176
|
|
- const char* access = "Unknown (ERROR)";
|
177
|
|
- switch (res.access)
|
178
|
|
- {
|
179
|
|
- case DKShaderResource::AccessReadOnly: access = "ReadOnly"; break;
|
180
|
|
- case DKShaderResource::AccessWriteOnly: access = "WriteOnly"; break;
|
181
|
|
- case DKShaderResource::AccessReadWrite: access = "ReadWrite"; break;
|
182
|
|
- }
|
183
|
|
-
|
184
|
|
- if (res.type == DKShaderResource::TypeBuffer)
|
185
|
|
- {
|
186
|
|
- DKLog(c, " Type:%s, Access:%s, Enabled:%d, Size:%d",
|
187
|
|
- type,
|
188
|
|
- access,
|
189
|
|
- int(res.enabled),
|
190
|
|
- res.typeInfo.buffer.size);
|
191
|
|
- }
|
192
|
|
- else
|
193
|
|
- {
|
194
|
|
- DKLog(c, " Type:%s, Access:%s, Enabled:%d",
|
195
|
|
- type,
|
196
|
|
- access,
|
197
|
|
- int(res.enabled));
|
198
|
|
- }
|
199
|
|
- if (res.typeInfoKey.Length() > 0)
|
200
|
|
- DKLog(c, " Struct \"%ls\"", (const wchar_t*)res.typeInfoKey);
|
201
|
|
- if (res.type == DKShaderResource::TypeBuffer)
|
202
|
|
- {
|
203
|
|
- auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
|
204
|
|
- if (p)
|
205
|
|
- MemberPrinter{ res, 1 , c}.operator()(p->value);
|
206
|
|
- }
|
207
|
|
-}
|
208
|
|
-
|
209
|
|
-void PrintPipelineReflection(const DKPipelineReflection* reflection, DKLogCategory c = DKLogCategory::Error)
|
210
|
|
-{
|
211
|
|
- DKLog(c, "=========================================================");
|
212
|
|
- DKLog(c, "PipelineReflection.InputAttributes: %d", reflection->inputAttributes.Count());
|
213
|
|
- for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
|
214
|
|
- {
|
215
|
|
- const DKShaderAttribute& attr = reflection->inputAttributes.Value(i);
|
216
|
|
- DKLog(c, " [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
|
217
|
|
- i, (const wchar_t*)attr.name, attr.location);
|
218
|
|
- }
|
219
|
|
- DKLog(c, "---------------------------------------------------------");
|
220
|
|
- DKLog(c, "PipelineReflection.Resources: %d", reflection->resources.Count());
|
221
|
|
- for (auto& arg : reflection->resources)
|
222
|
|
- PrintShaderResource(arg, c);
|
223
|
|
- for (int i = 0; i < reflection->pushConstantLayouts.Count(); ++i)
|
224
|
|
- {
|
225
|
|
- const DKShaderPushConstantLayout& layout = reflection->pushConstantLayouts.Value(i);
|
226
|
|
- DKLog(c, " PushConstant:%d \"%ls\" (offset:%u, size:%u, stages:%ls)",
|
227
|
|
- i, (const wchar_t*)layout.name, layout.offset, layout.size,
|
228
|
|
- (const wchar_t*)ShaderStageNames(layout.stages));
|
229
|
|
- }
|
230
|
|
- DKLog(c, "=========================================================");
|
231
|
|
-}
|
232
|
|
-
|
233
|
|
-
|
234
|
|
-class TestApp1 : public DKApplication
|
235
|
|
-{
|
236
|
|
- DKObject<DKWindow> window;
|
|
8
|
+ DKObject<DKWindow> window;
|
237
|
9
|
DKObject<DKThread> renderThread;
|
238
|
|
- DKResourcePool resourcePool;
|
239
|
|
-
|
240
|
10
|
DKAtomicNumber32 runningRenderThread;
|
|
11
|
+
|
241
|
12
|
public:
|
242
|
13
|
void RenderThread(void)
|
243
|
14
|
{
|
|
@@ -391,26 +162,23 @@ public:
|
391
|
162
|
|
392
|
163
|
void OnInitialize(void) override
|
393
|
164
|
{
|
|
165
|
+ SampleApp::OnInitialize();
|
394
|
166
|
DKLogD("%s", DKGL_FUNCTION_NAME);
|
395
|
167
|
|
396
|
|
- DKString resPath = DefaultPath(SystemPath::AppResource);
|
397
|
|
- resPath = resPath.FilePathStringByAppendingPath("Data");
|
398
|
|
- DKLog("resPath: %ls", (const wchar_t*)resPath);
|
399
|
|
- resourcePool.AddLocatorForPath(resPath);
|
|
168
|
+ // create window
|
|
169
|
+ window = DKWindow::Create("DefaultWindow");
|
|
170
|
+ window->SetOrigin({ 0, 0 });
|
|
171
|
+ window->Resize({ 320, 240 });
|
|
172
|
+ window->Activate();
|
400
|
173
|
|
401
|
|
- window = DKWindow::Create("DefaultWindow");
|
402
|
|
- window->SetOrigin({ 0, 0 });
|
403
|
|
- window->Resize({ 320, 240 });
|
404
|
|
- window->Activate();
|
405
|
|
-
|
406
|
|
- window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
|
407
|
|
- {
|
408
|
|
- if (e.type == DKWindow::WindowEvent::WindowClosed)
|
409
|
|
- DKApplication::Instance()->Terminate(0);
|
410
|
|
- }), NULL, NULL);
|
|
174
|
+ window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
|
|
175
|
+ {
|
|
176
|
+ if (e.type == DKWindow::WindowEvent::WindowClosed)
|
|
177
|
+ DKApplication::Instance()->Terminate(0);
|
|
178
|
+ }), NULL, NULL);
|
411
|
179
|
|
412
|
180
|
runningRenderThread = 1;
|
413
|
|
- renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
|
|
181
|
+ renderThread = DKThread::Create(DKFunction(this, &TriangleDemo::RenderThread)->Invocation());
|
414
|
182
|
}
|
415
|
183
|
void OnTerminate(void) override
|
416
|
184
|
{
|
|
@@ -419,29 +187,9 @@ public:
|
419
|
187
|
runningRenderThread = 0;
|
420
|
188
|
renderThread->WaitTerminate();
|
421
|
189
|
renderThread = NULL;
|
422
|
|
- window = NULL;
|
|
190
|
+ window = NULL;
|
423
|
191
|
|
424
|
|
- DKLogI("Memory Pool Statistics");
|
425
|
|
- size_t numBuckets = DKMemoryPoolNumberOfBuckets();
|
426
|
|
- DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
|
427
|
|
- DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
|
428
|
|
- size_t usedBytes = 0;
|
429
|
|
- for (int i = 0; i < numBuckets; ++i)
|
430
|
|
- {
|
431
|
|
- if (buckets[i].totalChunks > 0)
|
432
|
|
- {
|
433
|
|
- DKLogI("--> %5lu: %5lu/%5lu, usage: %.1f%%, used: %.1fKB, total: %.1fKB",
|
434
|
|
- buckets[i].chunkSize,
|
435
|
|
- buckets[i].usedChunks, buckets[i].totalChunks,
|
436
|
|
- double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0,
|
437
|
|
- double(buckets[i].chunkSize * buckets[i].usedChunks) / 1024.0,
|
438
|
|
- double(buckets[i].chunkSize * buckets[i].totalChunks) / 1024.0
|
439
|
|
- );
|
440
|
|
- usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
|
441
|
|
- }
|
442
|
|
- }
|
443
|
|
- DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
|
444
|
|
- delete[] buckets;
|
|
192
|
+ SampleApp::OnTerminate();
|
445
|
193
|
}
|
446
|
194
|
};
|
447
|
195
|
|
|
@@ -455,7 +203,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
455
|
203
|
int main(int argc, const char * argv[])
|
456
|
204
|
#endif
|
457
|
205
|
{
|
458
|
|
- TestApp1 app;
|
|
206
|
+ TriangleDemo app;
|
459
|
207
|
DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
|
460
|
208
|
DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
|
461
|
209
|
return app.Run();
|