DKGL2 sample codes

ComputeShader.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. #include <cstddef>
  2. #include "app.h"
  3. #include "util.h"
  4. class UVQuad : public GPUGeometry
  5. {
  6. private:
  7. struct Vertex
  8. {
  9. DKVector3 Pos;
  10. DKVector2 UV;
  11. };
  12. DKArray<UVQuad::Vertex> vertices =
  13. {
  14. { { 1.0f, 1.0f, 0.0f }, { 1.0f, 1.0f } },
  15. { { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f } },
  16. { { -1.0f, -1.0f, 0.0f }, { 0.0f, 0.0f } },
  17. { { 1.0f, -1.0f, 0.0f }, { 1.0f, 0.0f } }
  18. };
  19. DKArray<uint32_t> indices = { 0,1,2,2,3,0 };
  20. public:
  21. UVQuad() = default;
  22. size_t VerticesCount() const { return vertices.Count(); }
  23. size_t IndicesCount() const { return indices.Count(); }
  24. UVQuad::Vertex* VerticesData() { return vertices; }
  25. uint32_t* IndicesData() { return indices; }
  26. void InitializeGpuResource(DKCommandQueue* queue)
  27. {
  28. DKGraphicsDevice* device = queue->Device();
  29. uint32_t vertexBufferSize = static_cast<uint32_t>(VerticesCount()) * sizeof(UVQuad::Vertex);
  30. uint32_t indexBufferSize = IndicesCount() * sizeof(uint32_t);
  31. vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
  32. memcpy(vertexBuffer->Contents(), VerticesData(), vertexBufferSize);
  33. vertexBuffer->Flush();
  34. indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
  35. memcpy(indexBuffer->Contents(), IndicesData(), indexBufferSize);
  36. indexBuffer->Flush();
  37. // setup vertex buffer and attributes
  38. vertexDesc.attributes = {
  39. { DKVertexFormat::Float3, offsetof(UVQuad::Vertex, Pos), 0, 0 },
  40. { DKVertexFormat::Float2, offsetof(UVQuad::Vertex, UV), 0, 1 },
  41. };
  42. vertexDesc.layouts = {
  43. { DKVertexStepRate::Vertex, sizeof(UVQuad::Vertex), 0 },
  44. };
  45. }
  46. };
  47. class TextureComputeTarget
  48. {
  49. private:
  50. DKObject<DKTexture> textureTarget = nullptr;
  51. public:
  52. TextureComputeTarget() = default;
  53. DKTexture* ComputeTarget(DKCommandQueue* queue, int w, int h)
  54. {
  55. auto device = queue->Device();
  56. if (textureTarget)
  57. {
  58. if (textureTarget->Width() != w ||
  59. textureTarget->Height() != h)
  60. textureTarget = nullptr;
  61. }
  62. if (textureTarget == nullptr)
  63. {
  64. // create depth buffer
  65. DKTextureDescriptor texDesc = {};
  66. texDesc.textureType = DKTexture::Type2D;
  67. texDesc.pixelFormat = DKPixelFormat::BGRA8Unorm;
  68. texDesc.width = w;
  69. texDesc.height = h;
  70. texDesc.depth = 1;
  71. texDesc.mipmapLevels = 1;
  72. texDesc.sampleCount = 1;
  73. texDesc.arrayLength = 1;
  74. texDesc.usage = DKTexture::UsageShaderRead | DKTexture::UsageShaderWrite | DKTexture::UsageSampled;
  75. textureTarget = device->CreateTexture(texDesc);
  76. }
  77. return textureTarget;
  78. }
  79. };
  80. class GPUShader
  81. {
  82. private:
  83. DKObject<DKData> shaderData = nullptr;
  84. DKObject<DKShaderModule> shaderModule = nullptr;
  85. DKObject<DKShaderFunction> shaderFunc = nullptr;
  86. public:
  87. GPUShader(DKData* data) : shaderData(data)
  88. {
  89. }
  90. void InitializeGpuResource(DKCommandQueue* queue)
  91. {
  92. if (shaderData)
  93. {
  94. DKGraphicsDevice* device = queue->Device();
  95. DKShader shader(shaderData);
  96. shaderModule = device->CreateShaderModule(&shader);
  97. shaderFunc = shaderModule->CreateFunction(shaderModule->FunctionNames().Value(0));
  98. }
  99. }
  100. DKShaderFunction* Function() { return shaderFunc; }
  101. };
  102. class GraphicShaderBindingSet
  103. {
  104. public:
  105. struct UBO
  106. {
  107. DKMatrix4 projectionMatrix;
  108. DKMatrix4 modelMatrix;
  109. };
  110. private:
  111. DKShaderBindingSetLayout descriptorSetLayout;
  112. DKObject<DKShaderBindingSet> descriptorSetPreCompute;
  113. DKObject<DKShaderBindingSet> descriptorSetPostCompute;
  114. DKObject<DKRenderPipelineState> pipelineState;
  115. DKObject<DKGpuBuffer> uniformBuffer;
  116. UBO* ubo = nullptr;
  117. public:
  118. GraphicShaderBindingSet() = default;
  119. DKShaderBindingSet* PrecomputeDescSet() { return descriptorSetPreCompute; }
  120. DKShaderBindingSet* PostcomputeDescSet() { return descriptorSetPostCompute; }
  121. DKRenderPipelineState* GraphicPipelineState() { return pipelineState; }
  122. void InitializeGpuResource(DKGraphicsDevice* device)
  123. {
  124. if (1)
  125. {
  126. DKShaderBinding bindings[2] = {
  127. {
  128. 0,
  129. DKShader::DescriptorTypeUniformBuffer,
  130. 1,
  131. nullptr
  132. },
  133. {
  134. 1,
  135. DKShader::DescriptorTypeTextureSampler,
  136. 1,
  137. nullptr
  138. },
  139. };
  140. descriptorSetLayout.bindings.Add(bindings, 2);
  141. }
  142. descriptorSetPreCompute = device->CreateShaderBindingSet(descriptorSetLayout);
  143. descriptorSetPostCompute = device->CreateShaderBindingSet(descriptorSetLayout);
  144. uniformBuffer = device->CreateBuffer(sizeof(GraphicShaderBindingSet::UBO), DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
  145. if (descriptorSetPreCompute)
  146. {
  147. if (uniformBuffer)
  148. {
  149. ubo = reinterpret_cast<UBO*>(uniformBuffer->Contents());
  150. ubo->projectionMatrix = DKMatrix4::identity;
  151. ubo->modelMatrix = DKMatrix4::identity;
  152. uniformBuffer->Flush();
  153. descriptorSetPreCompute->SetBuffer(0, uniformBuffer, 0, sizeof(UBO));
  154. }
  155. }
  156. if (descriptorSetPostCompute)
  157. {
  158. if (uniformBuffer && ubo)
  159. {
  160. descriptorSetPostCompute->SetBuffer(0, uniformBuffer, 0, sizeof(UBO));
  161. }
  162. }
  163. //descriptorSetPreCompute->SetTexture(1, texture);
  164. //descriptorSetPreCompute->SetSamplerState(1, sampler);
  165. }
  166. DKGpuBuffer* UniformBuffer() { return uniformBuffer; }
  167. UBO* UniformBufferO() { return ubo; }
  168. };
  169. class MeshDemo : public SampleApp
  170. {
  171. DKObject<DKWindow> window;
  172. DKObject<DKThread> renderThread;
  173. DKAtomicNumber32 runningRenderThread;
  174. //Resource
  175. DKObject<UVQuad> Quad;
  176. DKObject<DKTexture> textureColorMap;
  177. DKObject<TextureComputeTarget> ComputeTarget;
  178. DKObject<DKSamplerState> sampleState = nullptr;;
  179. DKObject<GraphicShaderBindingSet> graphicShaderBindingSet = nullptr;
  180. public:
  181. DKObject<DKTexture> LoadTexture2D(DKCommandQueue* queue, DKData* data)
  182. {
  183. DKObject<DKImage> image = DKImage::Create(data);
  184. if (image)
  185. {
  186. DKGraphicsDevice* device = queue->Device();
  187. DKTextureDescriptor texDesc = {};
  188. texDesc.textureType = DKTexture::Type2D;
  189. texDesc.pixelFormat = DKPixelFormat::RGBA8Unorm;
  190. texDesc.width = image->Width();
  191. texDesc.height = image->Height();
  192. texDesc.depth = 1;
  193. texDesc.mipmapLevels = 1;
  194. texDesc.sampleCount = 1;
  195. texDesc.arrayLength = 1;
  196. texDesc.usage = DKTexture::UsageStorage | DKTexture::UsageShaderRead | DKTexture::UsageCopyDestination | DKTexture::UsageSampled;
  197. DKObject<DKTexture> tex = device->CreateTexture(texDesc);
  198. if (tex)
  199. {
  200. size_t bytesPerPixel = image->BytesPerPixel();
  201. DKASSERT_DESC(bytesPerPixel == DKPixelFormatBytesPerPixel(texDesc.pixelFormat), "BytesPerPixel mismatch!");
  202. uint32_t width = image->Width();
  203. uint32_t height = image->Height();
  204. size_t bufferLength = bytesPerPixel * width * height;
  205. DKObject<DKGpuBuffer> stagingBuffer = device->CreateBuffer(bufferLength, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
  206. memcpy(stagingBuffer->Contents(), image->Contents(), bufferLength);
  207. stagingBuffer->Flush();
  208. DKObject<DKCommandBuffer> cb = queue->CreateCommandBuffer();
  209. DKObject<DKCopyCommandEncoder> encoder = cb->CreateCopyCommandEncoder();
  210. encoder->CopyFromBufferToTexture(stagingBuffer,
  211. { 0, width, height },
  212. tex,
  213. { 0,0, 0,0,0 },
  214. { width,height,1 });
  215. encoder->EndEncoding();
  216. cb->Commit();
  217. DKLog("Texture created!");
  218. return tex;
  219. }
  220. }
  221. return nullptr;
  222. }
  223. void RenderThread(void)
  224. {
  225. // Device and Queue Preperation
  226. DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
  227. DKObject<DKCommandQueue> graphicsQueue = device->CreateCommandQueue(DKCommandQueue::Graphics);
  228. DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
  229. // Geometry Initialzie
  230. Quad->InitializeGpuResource(graphicsQueue);
  231. // create shaders
  232. DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
  233. DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.frag.spv");
  234. DKObject<DKData> embossData = resourcePool.LoadResourceData("shaders/ComputeShader/emboss.comp.spv");
  235. DKObject<DKData> edgedetectData = resourcePool.LoadResourceData("shaders/ComputeShader/edgedetect.comp.spv");
  236. DKObject<DKData> sharpenData = resourcePool.LoadResourceData("shaders/ComputeShader/sharpen.comp.spv");
  237. DKObject<GPUShader> VS = DKOBJECT_NEW GPUShader(vertData);
  238. DKObject<GPUShader> FS = DKOBJECT_NEW GPUShader(fragData);
  239. DKObject<GPUShader> CS_E = DKOBJECT_NEW GPUShader(embossData);
  240. DKObject<GPUShader> CS_ED = DKOBJECT_NEW GPUShader(edgedetectData);
  241. DKObject<GPUShader> CS_SH = DKOBJECT_NEW GPUShader(sharpenData);
  242. VS->InitializeGpuResource(graphicsQueue);
  243. FS->InitializeGpuResource(graphicsQueue);
  244. CS_E->InitializeGpuResource(computeQueue);
  245. CS_ED->InitializeGpuResource(computeQueue);
  246. CS_SH->InitializeGpuResource(computeQueue);
  247. auto VSF = VS->Function();
  248. auto FSF = FS->Function();
  249. auto CS_EF = CS_E->Function();
  250. auto CS_EDF = CS_ED->Function();
  251. auto CS_SHF = CS_SH->Function();
  252. // Texture Resource Initialize
  253. ComputeTarget = DKOBJECT_NEW TextureComputeTarget();
  254. DKSamplerDescriptor computeSamplerDesc = {};
  255. computeSamplerDesc.magFilter = DKSamplerDescriptor::MinMagFilterLinear;
  256. computeSamplerDesc.minFilter = DKSamplerDescriptor::MinMagFilterLinear;
  257. computeSamplerDesc.mipFilter = DKSamplerDescriptor::MipFilterLinear;
  258. computeSamplerDesc.addressModeU = DKSamplerDescriptor::AddressModeClampToEdge;
  259. computeSamplerDesc.addressModeV = DKSamplerDescriptor::AddressModeClampToEdge;
  260. computeSamplerDesc.addressModeW = DKSamplerDescriptor::AddressModeClampToEdge;
  261. computeSamplerDesc.maxAnisotropy = 1.0f;
  262. computeSamplerDesc.compareFunction = DKCompareFunctionNever;
  263. DKObject<DKSamplerState> computeSampler = device->CreateSamplerState(computeSamplerDesc);
  264. // create texture
  265. DKObject<DKTexture> texture = LoadTexture2D(graphicsQueue, resourcePool.LoadResourceData("textures/deathstar3.png"));
  266. // create sampler
  267. DKSamplerDescriptor samplerDesc = {};
  268. samplerDesc.magFilter = DKSamplerDescriptor::MinMagFilterLinear;
  269. samplerDesc.minFilter = DKSamplerDescriptor::MinMagFilterLinear;
  270. samplerDesc.addressModeU = DKSamplerDescriptor::AddressModeClampToEdge;
  271. samplerDesc.addressModeV = DKSamplerDescriptor::AddressModeClampToEdge;
  272. samplerDesc.addressModeW = DKSamplerDescriptor::AddressModeClampToEdge;
  273. samplerDesc.maxAnisotropy = 1;
  274. DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
  275. DKObject<DKSwapChain> swapChain = graphicsQueue->CreateSwapChain(window);
  276. DKLog("VertexFunction.VertexAttributes: %d", VSF->StageInputAttributes().Count());
  277. for (int i = 0; i < VSF->StageInputAttributes().Count(); ++i)
  278. {
  279. const DKShaderAttribute& attr = VSF->StageInputAttributes().Value(i);
  280. DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
  281. }
  282. DKRenderPipelineDescriptor pipelineDescriptor;
  283. // setup shader
  284. pipelineDescriptor.vertexFunction = VSF;
  285. pipelineDescriptor.fragmentFunction = FSF;
  286. // setup color-attachment render-targets
  287. pipelineDescriptor.colorAttachments.Resize(1);
  288. pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
  289. pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = false;
  290. pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
  291. pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
  292. // setup depth-stencil
  293. pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::D32Float;
  294. pipelineDescriptor.depthStencilDescriptor.depthWriteEnabled = true;
  295. pipelineDescriptor.depthStencilDescriptor.depthCompareFunction = DKCompareFunctionLessEqual;
  296. // setup vertex buffer and attributes
  297. pipelineDescriptor.vertexDescriptor = Quad->VertexDescriptor();
  298. // setup topology and rasterization
  299. pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
  300. pipelineDescriptor.frontFace = DKFrontFace::CCW;
  301. pipelineDescriptor.triangleFillMode = DKTriangleFillMode::Fill;
  302. pipelineDescriptor.depthClipMode = DKDepthClipMode::Clip;
  303. pipelineDescriptor.cullMode = DKCullMode::Back;
  304. pipelineDescriptor.rasterizationEnabled = true;
  305. DKPipelineReflection reflection;
  306. DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
  307. if (pipelineState)
  308. {
  309. PrintPipelineReflection(&reflection, DKLogCategory::Verbose);
  310. }
  311. ///
  312. graphicShaderBindingSet = DKOBJECT_NEW GraphicShaderBindingSet();
  313. graphicShaderBindingSet->InitializeGpuResource(device);
  314. auto uboBuffer = graphicShaderBindingSet->UniformBuffer();
  315. auto ubo = graphicShaderBindingSet->UniformBufferO();
  316. // ComputerBuffer Layout
  317. DKShaderBindingSetLayout ComputeLayout;
  318. if (1)
  319. {
  320. DKShaderBinding bindings[2] = {
  321. {
  322. 0,
  323. DKShader::DescriptorTypeStorageTexture,
  324. 1,
  325. nullptr
  326. }, // Input Image (read-only)
  327. {
  328. 1,
  329. DKShader::DescriptorTypeStorageTexture,
  330. 1,
  331. nullptr
  332. }, // Output image (write)
  333. };
  334. ComputeLayout.bindings.Add(bindings, 2);
  335. }
  336. DKObject<DKShaderBindingSet> computebindSet = device->CreateShaderBindingSet(ComputeLayout);
  337. //auto CS_EF = CS_E->Function();
  338. //auto CS_EDF = CS_ED->Function();
  339. //auto CS_SHF = CS_SH->Function();
  340. DKComputePipelineDescriptor embossComputePipelineDescriptor;
  341. embossComputePipelineDescriptor.computeFunction = CS_EF;
  342. auto Emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
  343. DKObject<DKTexture> depthBuffer = nullptr;
  344. DKObject<DKTexture> targettex = nullptr;
  345. DKTimer timer;
  346. timer.Reset();
  347. DKLog("Render thread begin");
  348. while (!runningRenderThread.CompareAndSet(0, 0))
  349. {
  350. DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
  351. double t = timer.Elapsed();
  352. double waveT = (cos(t) + 1.0) * 0.5;
  353. rpd.colorAttachments.Value(0).clearColor = DKColor(waveT, 0.0, 0.0, 0.0);
  354. int width = rpd.colorAttachments.Value(0).renderTarget->Width();
  355. int height = rpd.colorAttachments.Value(0).renderTarget->Height();
  356. if (depthBuffer)
  357. {
  358. if (depthBuffer->Width() != width ||
  359. depthBuffer->Height() != height )
  360. depthBuffer = nullptr;
  361. }
  362. if (depthBuffer == nullptr)
  363. {
  364. // create depth buffer
  365. DKTextureDescriptor texDesc = {};
  366. texDesc.textureType = DKTexture::Type2D;
  367. texDesc.pixelFormat = DKPixelFormat::D32Float;
  368. texDesc.width = width;
  369. texDesc.height = height;
  370. texDesc.depth = 1;
  371. texDesc.mipmapLevels = 1;
  372. texDesc.sampleCount = 1;
  373. texDesc.arrayLength = 1;
  374. texDesc.usage = DKTexture::UsageRenderTarget;
  375. depthBuffer = device->CreateTexture(texDesc);
  376. }
  377. rpd.depthStencilAttachment.renderTarget = depthBuffer;
  378. rpd.depthStencilAttachment.loadAction = DKRenderPassAttachmentDescriptor::LoadActionClear;
  379. rpd.depthStencilAttachment.storeAction = DKRenderPassAttachmentDescriptor::StoreActionDontCare;
  380. targettex = ComputeTarget->ComputeTarget(computeQueue, width, height);
  381. DKObject<DKCommandBuffer> computeCmdbuffer = computeQueue->CreateCommandBuffer();
  382. DKObject<DKComputeCommandEncoder> computeEncoder = computeCmdbuffer->CreateComputeCommandEncoder();
  383. if (computeEncoder)
  384. {
  385. if (computebindSet)
  386. {
  387. computebindSet->SetTexture(0, texture);
  388. //computebindSet->SetSamplerState(0, sampler);
  389. computebindSet->SetTexture(1, targettex);
  390. //computebindSet->SetSamplerState(1, sampler);
  391. }
  392. computeEncoder->SetComputePipelineState(Emboss);
  393. computeEncoder->SetResources(0, computebindSet);
  394. computeEncoder->Dispatch(width / 16, height / 16, 1);
  395. computeEncoder->EndEncoding();
  396. }
  397. DKObject<DKCommandBuffer> buffer = graphicsQueue->CreateCommandBuffer();
  398. DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
  399. if (encoder)
  400. {
  401. if (graphicShaderBindingSet->PostcomputeDescSet() && ubo)
  402. {
  403. graphicShaderBindingSet->PostcomputeDescSet()->SetBuffer(0, uboBuffer, 0, sizeof(GraphicShaderBindingSet::UBO));
  404. graphicShaderBindingSet->PostcomputeDescSet()->SetTexture(1, targettex);
  405. graphicShaderBindingSet->PostcomputeDescSet()->SetSamplerState(1, sampler);
  406. }
  407. encoder->SetRenderPipelineState(pipelineState);
  408. encoder->SetVertexBuffer(Quad->VertexBuffer(), 0, 0);
  409. encoder->SetIndexBuffer(Quad->IndexBuffer(), 0, DKIndexType::UInt32);
  410. encoder->SetResources(0, graphicShaderBindingSet->PostcomputeDescSet());
  411. // draw scene!
  412. encoder->DrawIndexed(Quad->IndicesCount(), 1, 0, 0, 0);
  413. encoder->EndEncoding();
  414. if (computeCmdbuffer)
  415. computeCmdbuffer->Commit();
  416. buffer->Commit();
  417. swapChain->Present();
  418. }
  419. else
  420. {
  421. }
  422. DKThread::Sleep(0.01);
  423. }
  424. DKLog("RenderThread terminating...");
  425. }
  426. void OnInitialize(void) override
  427. {
  428. SampleApp::OnInitialize();
  429. DKLogD("%s", DKGL_FUNCTION_NAME);
  430. // create window
  431. window = DKWindow::Create("DefaultWindow");
  432. window->SetOrigin({ 0, 0 });
  433. window->Resize({ 320, 240 });
  434. window->Activate();
  435. window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
  436. {
  437. if (e.type == DKWindow::WindowEvent::WindowClosed)
  438. DKApplication::Instance()->Terminate(0);
  439. }), NULL, NULL);
  440. Quad = DKOBJECT_NEW UVQuad();
  441. runningRenderThread = 1;
  442. renderThread = DKThread::Create(DKFunction(this, &MeshDemo::RenderThread)->Invocation());
  443. }
  444. void OnTerminate(void) override
  445. {
  446. DKLogD("%s", DKGL_FUNCTION_NAME);
  447. runningRenderThread = 0;
  448. renderThread->WaitTerminate();
  449. renderThread = NULL;
  450. window = NULL;
  451. SampleApp::OnTerminate();
  452. }
  453. };
  454. #ifdef _WIN32
  455. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  456. _In_opt_ HINSTANCE hPrevInstance,
  457. _In_ LPWSTR lpCmdLine,
  458. _In_ int nCmdShow)
  459. #else
  460. int main(int argc, const char * argv[])
  461. #endif
  462. {
  463. MeshDemo app;
  464. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  465. DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
  466. return app.Run();
  467. }