|
@@ -0,0 +1,462 @@
|
|
1
|
+
|
|
2
|
+#include "app.h"
|
|
3
|
+
|
|
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
|
+
|
|
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)
|
|
112
|
+{
|
|
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;
|
|
237
|
+ DKObject<DKThread> renderThread;
|
|
238
|
+ DKResourcePool resourcePool;
|
|
239
|
+
|
|
240
|
+ DKAtomicNumber32 runningRenderThread;
|
|
241
|
+public:
|
|
242
|
+ void RenderThread(void)
|
|
243
|
+ {
|
|
244
|
+ DKObject<DKData> vertData = resourcePool.LoadResourceData("triangle.vert.spv");
|
|
245
|
+ DKObject<DKData> fragData = resourcePool.LoadResourceData("triangle.frag.spv");
|
|
246
|
+ DKShader vertShader(vertData);
|
|
247
|
+ DKShader fragShader(fragData);
|
|
248
|
+
|
|
249
|
+ DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
|
|
250
|
+ DKObject<DKShaderModule> vertShaderModule = device->CreateShaderModule(&vertShader);
|
|
251
|
+ DKObject<DKShaderModule> fragShaderModule = device->CreateShaderModule(&fragShader);
|
|
252
|
+
|
|
253
|
+ DKObject<DKShaderFunction> vertShaderFunction = vertShaderModule->CreateFunction(vertShaderModule->FunctionNames().Value(0));
|
|
254
|
+ DKObject<DKShaderFunction> fragShaderFunction = fragShaderModule->CreateFunction(fragShaderModule->FunctionNames().Value(0));
|
|
255
|
+
|
|
256
|
+ DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
|
|
257
|
+ DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
|
|
258
|
+
|
|
259
|
+ DKLog("VertexFunction.VertexAttributes: %d", vertShaderFunction->StageInputAttributes().Count());
|
|
260
|
+ for (int i = 0; i < vertShaderFunction->StageInputAttributes().Count(); ++i)
|
|
261
|
+ {
|
|
262
|
+ const DKShaderAttribute& attr = vertShaderFunction->StageInputAttributes().Value(i);
|
|
263
|
+ DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
|
|
264
|
+ }
|
|
265
|
+
|
|
266
|
+ struct Vertex
|
|
267
|
+ {
|
|
268
|
+ DKVector3 position;
|
|
269
|
+ DKVector3 color;
|
|
270
|
+ };
|
|
271
|
+ DKArray<Vertex> vertexData =
|
|
272
|
+ {
|
|
273
|
+ { { 0.0f, -0.5f, 0.0f },{ 1.0f, 1.0f, 1.0f } },
|
|
274
|
+ { { 0.5f, 0.5f, 0.0f },{ 0.0f, 1.0f, 0.0f } },
|
|
275
|
+ { { -0.5f, 0.5f, 0.0f },{ 0.0f, 0.0f, 1.0f } }
|
|
276
|
+ };
|
|
277
|
+ uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
|
|
278
|
+ DKArray<uint32_t> indexData = { 0, 1, 2 };
|
|
279
|
+ uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
|
|
280
|
+
|
|
281
|
+ DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
|
|
282
|
+ memcpy(vertexBuffer->Lock(), vertexData, vertexBufferSize);
|
|
283
|
+ vertexBuffer->Unlock();
|
|
284
|
+
|
|
285
|
+ DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
|
|
286
|
+ memcpy(indexBuffer->Lock(), indexData, indexBufferSize);
|
|
287
|
+ indexBuffer->Unlock();
|
|
288
|
+
|
|
289
|
+ DKRenderPipelineDescriptor pipelineDescriptor;
|
|
290
|
+ pipelineDescriptor.vertexFunction = vertShaderFunction;
|
|
291
|
+ pipelineDescriptor.fragmentFunction = fragShaderFunction;
|
|
292
|
+ pipelineDescriptor.colorAttachments.Resize(1);
|
|
293
|
+ pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
|
|
294
|
+ pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
|
|
295
|
+ pipelineDescriptor.vertexDescriptor.attributes = {
|
|
296
|
+ { DKVertexFormat::Float3, 0, 0, 0 },
|
|
297
|
+ { DKVertexFormat::Float3, sizeof(DKVector3), 0, 1 },
|
|
298
|
+ };
|
|
299
|
+ pipelineDescriptor.vertexDescriptor.layouts = {
|
|
300
|
+ { DKVertexStepRate::Vertex, sizeof(Vertex), 0 },
|
|
301
|
+ };
|
|
302
|
+ pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
|
|
303
|
+ pipelineDescriptor.frontFace = DKFrontFace::CCW;
|
|
304
|
+ pipelineDescriptor.triangleFillMode = DKTriangleFillMode::Fill;
|
|
305
|
+ pipelineDescriptor.depthClipMode = DKDepthClipMode::Clip;
|
|
306
|
+ pipelineDescriptor.cullMode = DKCullMode::None;
|
|
307
|
+ pipelineDescriptor.rasterizationEnabled = true;
|
|
308
|
+
|
|
309
|
+ DKPipelineReflection reflection;
|
|
310
|
+ DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
|
|
311
|
+ if (pipelineState)
|
|
312
|
+ {
|
|
313
|
+ PrintPipelineReflection(&reflection, DKLogCategory::Verbose);
|
|
314
|
+ }
|
|
315
|
+
|
|
316
|
+ DKShaderBindingSetLayout layout;
|
|
317
|
+ if (1)
|
|
318
|
+ {
|
|
319
|
+ DKShaderBinding binding = {
|
|
320
|
+ 0,
|
|
321
|
+ DKShader::DescriptorTypeUniformBuffer,
|
|
322
|
+ 1,
|
|
323
|
+ nullptr
|
|
324
|
+ };
|
|
325
|
+ layout.bindings.Add(binding);
|
|
326
|
+ }
|
|
327
|
+ DKObject<DKShaderBindingSet> bindSet = device->CreateShaderBindingSet(layout);
|
|
328
|
+ if (bindSet)
|
|
329
|
+ {
|
|
330
|
+ struct
|
|
331
|
+ {
|
|
332
|
+ DKMatrix4 projectionMatrix;
|
|
333
|
+ DKMatrix4 modelMatrix;
|
|
334
|
+ DKMatrix4 viewMatrix;
|
|
335
|
+ } ubo;
|
|
336
|
+
|
|
337
|
+ DKObject<DKGpuBuffer> uboBuffer = device->CreateBuffer(sizeof(ubo), DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
|
|
338
|
+ if (uboBuffer)
|
|
339
|
+ {
|
|
340
|
+ ubo.projectionMatrix = DKMatrix4::identity;
|
|
341
|
+ ubo.modelMatrix = DKMatrix4::identity;
|
|
342
|
+ ubo.viewMatrix = DKMatrix4::identity;
|
|
343
|
+
|
|
344
|
+ void* p = uboBuffer->Lock(0);
|
|
345
|
+ if (p)
|
|
346
|
+ {
|
|
347
|
+ memcpy(p, &ubo, sizeof(ubo));
|
|
348
|
+ uboBuffer->Unlock();
|
|
349
|
+
|
|
350
|
+ bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
|
|
351
|
+ }
|
|
352
|
+ else
|
|
353
|
+ {
|
|
354
|
+ DKLogE("GpuBuffer Lock failed!");
|
|
355
|
+ }
|
|
356
|
+ }
|
|
357
|
+ }
|
|
358
|
+
|
|
359
|
+ DKTimer timer;
|
|
360
|
+ timer.Reset();
|
|
361
|
+
|
|
362
|
+ DKLog("Render thread begin");
|
|
363
|
+ while (!runningRenderThread.CompareAndSet(0, 0))
|
|
364
|
+ {
|
|
365
|
+ DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
|
|
366
|
+ double t = timer.Elapsed();
|
|
367
|
+ t = (cos(t) + 1.0) * 0.5;
|
|
368
|
+ rpd.colorAttachments.Value(0).clearColor = DKColor(t, 0.0, 0.0, 0.0);
|
|
369
|
+
|
|
370
|
+ DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
|
|
371
|
+ DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
|
|
372
|
+ if (encoder)
|
|
373
|
+ {
|
|
374
|
+ encoder->SetRenderPipelineState(pipelineState);
|
|
375
|
+ encoder->SetVertexBuffer(vertexBuffer, 0, 0);
|
|
376
|
+ encoder->SetIndexBuffer(indexBuffer, 0, DKIndexType::UInt32);
|
|
377
|
+ encoder->SetResources(0, bindSet);
|
|
378
|
+ // draw scene!
|
|
379
|
+ encoder->DrawIndexed(indexData.Count(), 1, 0, 0, 1);
|
|
380
|
+ encoder->EndEncoding();
|
|
381
|
+ buffer->Commit();
|
|
382
|
+ swapChain->Present();
|
|
383
|
+ }
|
|
384
|
+ else
|
|
385
|
+ {
|
|
386
|
+ }
|
|
387
|
+ DKThread::Sleep(0.01);
|
|
388
|
+ }
|
|
389
|
+ DKLog("RenderThread terminating...");
|
|
390
|
+ }
|
|
391
|
+
|
|
392
|
+ void OnInitialize(void) override
|
|
393
|
+ {
|
|
394
|
+ DKLogD("%s", DKGL_FUNCTION_NAME);
|
|
395
|
+
|
|
396
|
+ DKString resPath = DefaultPath(SystemPath::AppResource);
|
|
397
|
+ resPath = resPath.FilePathStringByAppendingPath("Data");
|
|
398
|
+ DKLog("resPath: %ls", (const wchar_t*)resPath);
|
|
399
|
+ resourcePool.AddLocatorForPath(resPath);
|
|
400
|
+
|
|
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);
|
|
411
|
+
|
|
412
|
+ runningRenderThread = 1;
|
|
413
|
+ renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
|
|
414
|
+ }
|
|
415
|
+ void OnTerminate(void) override
|
|
416
|
+ {
|
|
417
|
+ DKLogD("%s", DKGL_FUNCTION_NAME);
|
|
418
|
+
|
|
419
|
+ runningRenderThread = 0;
|
|
420
|
+ renderThread->WaitTerminate();
|
|
421
|
+ renderThread = NULL;
|
|
422
|
+ window = NULL;
|
|
423
|
+
|
|
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;
|
|
445
|
+ }
|
|
446
|
+};
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+#ifdef _WIN32
|
|
450
|
+int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
|
451
|
+ _In_opt_ HINSTANCE hPrevInstance,
|
|
452
|
+ _In_ LPWSTR lpCmdLine,
|
|
453
|
+ _In_ int nCmdShow)
|
|
454
|
+#else
|
|
455
|
+int main(int argc, const char * argv[])
|
|
456
|
+#endif
|
|
457
|
+{
|
|
458
|
+ TestApp1 app;
|
|
459
|
+ DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
|
|
460
|
+ DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
|
|
461
|
+ return app.Run();
|
|
462
|
+}
|