DKGL2 sample codes

ComputeShader.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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, 0.0f } },
  15. { { -1.0f, 1.0f, 0.0f }, { 0.0f, 0.0f } },
  16. { { -1.0f, -1.0f, 0.0f }, { 0.0f, 1.0f } },
  17. { { 1.0f, -1.0f, 0.0f }, { 1.0f, 1.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. DKTextureDescriptor texDesc = {};
  65. texDesc.textureType = DKTexture::Type2D;
  66. texDesc.pixelFormat = DKPixelFormat::BGRA8Unorm;
  67. texDesc.width = w;
  68. texDesc.height = h;
  69. texDesc.depth = 1;
  70. texDesc.mipmapLevels = 1;
  71. texDesc.sampleCount = 1;
  72. texDesc.arrayLength = 1;
  73. texDesc.usage = DKTexture::UsageStorage // For Compute Shader
  74. | DKTexture::UsageSampled | DKTexture::UsageShaderRead;// For FragmentShader
  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. }
  164. DKGpuBuffer* UniformBuffer() { return uniformBuffer; }
  165. UBO* UniformBufferO() { return ubo; }
  166. };
  167. class ComputeShaderDemo : public SampleApp
  168. {
  169. DKObject<DKWindow> window;
  170. DKObject<DKThread> renderThread;
  171. DKAtomicNumber32 runningRenderThread;
  172. //Resource
  173. DKObject<UVQuad> quad;
  174. DKObject<DKTexture> textureColorMap;
  175. DKObject<TextureComputeTarget> computeTarget;
  176. DKObject<DKSamplerState> sampleState = nullptr;;
  177. DKObject<GraphicShaderBindingSet> graphicShaderBindingSet = nullptr;
  178. public:
  179. DKObject<DKTexture> LoadTexture2D(DKCommandQueue* queue, DKData* data)
  180. {
  181. DKObject<DKImage> image = DKImage::Create(data);
  182. if (image)
  183. {
  184. DKGraphicsDevice* device = queue->Device();
  185. DKTextureDescriptor texDesc = {};
  186. texDesc.textureType = DKTexture::Type2D;
  187. texDesc.pixelFormat = DKPixelFormat::RGBA8Unorm;
  188. texDesc.width = image->Width();
  189. texDesc.height = image->Height();
  190. texDesc.depth = 1;
  191. texDesc.mipmapLevels = 1;
  192. texDesc.sampleCount = 1;
  193. texDesc.arrayLength = 1;
  194. texDesc.usage = DKTexture::UsageStorage | DKTexture::UsageShaderRead | DKTexture::UsageCopyDestination | DKTexture::UsageSampled;
  195. DKObject<DKTexture> tex = device->CreateTexture(texDesc);
  196. if (tex)
  197. {
  198. size_t bytesPerPixel = image->BytesPerPixel();
  199. DKASSERT_DESC(bytesPerPixel == DKPixelFormatBytesPerPixel(texDesc.pixelFormat), "BytesPerPixel mismatch!");
  200. uint32_t width = image->Width();
  201. uint32_t height = image->Height();
  202. size_t bufferLength = bytesPerPixel * width * height;
  203. DKObject<DKGpuBuffer> stagingBuffer = device->CreateBuffer(bufferLength, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
  204. memcpy(stagingBuffer->Contents(), image->Contents(), bufferLength);
  205. stagingBuffer->Flush();
  206. DKObject<DKCommandBuffer> cb = queue->CreateCommandBuffer();
  207. DKObject<DKCopyCommandEncoder> encoder = cb->CreateCopyCommandEncoder();
  208. encoder->CopyFromBufferToTexture(stagingBuffer,
  209. { 0, width, height },
  210. tex,
  211. { 0,0, 0,0,0 },
  212. { width,height,1 });
  213. encoder->EndEncoding();
  214. cb->Commit();
  215. DKLog("Texture created!");
  216. return tex;
  217. }
  218. }
  219. return nullptr;
  220. }
  221. void RenderThread(void)
  222. {
  223. // Device and Queue Preperation
  224. DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
  225. DKObject<DKCommandQueue> graphicsQueue = device->CreateCommandQueue(DKCommandQueue::Graphics);
  226. DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
  227. // Geometry Initialzie
  228. quad->InitializeGpuResource(graphicsQueue);
  229. // create shaders
  230. DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
  231. DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.frag.spv");
  232. DKObject<DKData> embossData = resourcePool.LoadResourceData("shaders/ComputeShader/emboss.comp.spv");
  233. DKObject<DKData> edgedetectData = resourcePool.LoadResourceData("shaders/ComputeShader/edgedetect.comp.spv");
  234. DKObject<DKData> sharpenData = resourcePool.LoadResourceData("shaders/ComputeShader/sharpen.comp.spv");
  235. DKObject<GPUShader> vs = DKOBJECT_NEW GPUShader(vertData);
  236. DKObject<GPUShader> fs = DKOBJECT_NEW GPUShader(fragData);
  237. DKObject<GPUShader> cs_e = DKOBJECT_NEW GPUShader(embossData);
  238. DKObject<GPUShader> cs_ed = DKOBJECT_NEW GPUShader(edgedetectData);
  239. DKObject<GPUShader> cs_sh = DKOBJECT_NEW GPUShader(sharpenData);
  240. vs->InitializeGpuResource(graphicsQueue);
  241. fs->InitializeGpuResource(graphicsQueue);
  242. cs_e->InitializeGpuResource(computeQueue);
  243. cs_ed->InitializeGpuResource(computeQueue);
  244. cs_sh->InitializeGpuResource(computeQueue);
  245. auto vsf = vs->Function();
  246. auto fsf = fs->Function();
  247. auto cs_ef = cs_e->Function();
  248. auto cs_edf = cs_ed->Function();
  249. auto cs_shf = cs_sh->Function();
  250. // Texture Resource Initialize
  251. computeTarget = DKOBJECT_NEW TextureComputeTarget();
  252. DKSamplerDescriptor computeSamplerDesc = {};
  253. computeSamplerDesc.magFilter = DKSamplerDescriptor::MinMagFilterLinear;
  254. computeSamplerDesc.minFilter = DKSamplerDescriptor::MinMagFilterLinear;
  255. computeSamplerDesc.mipFilter = DKSamplerDescriptor::MipFilterLinear;
  256. computeSamplerDesc.addressModeU = DKSamplerDescriptor::AddressModeClampToEdge;
  257. computeSamplerDesc.addressModeV = DKSamplerDescriptor::AddressModeClampToEdge;
  258. computeSamplerDesc.addressModeW = DKSamplerDescriptor::AddressModeClampToEdge;
  259. computeSamplerDesc.maxAnisotropy = 1.0f;
  260. computeSamplerDesc.compareFunction = DKCompareFunctionNever;
  261. DKObject<DKSamplerState> computeSampler = device->CreateSamplerState(computeSamplerDesc);
  262. // create texture
  263. DKObject<DKTexture> texture = LoadTexture2D(graphicsQueue, resourcePool.LoadResourceData("textures/deathstar3.png"));
  264. // create sampler
  265. DKSamplerDescriptor samplerDesc = {};
  266. samplerDesc.magFilter = DKSamplerDescriptor::MinMagFilterLinear;
  267. samplerDesc.minFilter = DKSamplerDescriptor::MinMagFilterLinear;
  268. samplerDesc.addressModeU = DKSamplerDescriptor::AddressModeClampToEdge;
  269. samplerDesc.addressModeV = DKSamplerDescriptor::AddressModeClampToEdge;
  270. samplerDesc.addressModeW = DKSamplerDescriptor::AddressModeClampToEdge;
  271. samplerDesc.maxAnisotropy = 1;
  272. DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
  273. DKObject<DKSwapChain> swapChain = graphicsQueue->CreateSwapChain(window);
  274. DKLog("VertexFunction.VertexAttributes: %d", vsf->StageInputAttributes().Count());
  275. for (int i = 0; i < vsf->StageInputAttributes().Count(); ++i)
  276. {
  277. const DKShaderAttribute& attr = vsf->StageInputAttributes().Value(i);
  278. DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
  279. }
  280. DKRenderPipelineDescriptor pipelineDescriptor;
  281. // setup shader
  282. pipelineDescriptor.vertexFunction = vsf;
  283. pipelineDescriptor.fragmentFunction = fsf;
  284. // setup color-attachment render-targets
  285. pipelineDescriptor.colorAttachments.Resize(1);
  286. pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
  287. pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = false;
  288. pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
  289. pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
  290. // setup depth-stencil
  291. pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::D32Float;
  292. pipelineDescriptor.depthStencilDescriptor.depthWriteEnabled = true;
  293. pipelineDescriptor.depthStencilDescriptor.depthCompareFunction = DKCompareFunctionLessEqual;
  294. // setup vertex buffer and attributes
  295. pipelineDescriptor.vertexDescriptor = quad->VertexDescriptor();
  296. // setup topology and rasterization
  297. pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
  298. pipelineDescriptor.frontFace = DKFrontFace::CCW;
  299. pipelineDescriptor.triangleFillMode = DKTriangleFillMode::Fill;
  300. pipelineDescriptor.depthClipMode = DKDepthClipMode::Clip;
  301. pipelineDescriptor.cullMode = DKCullMode::Back;
  302. pipelineDescriptor.rasterizationEnabled = true;
  303. DKPipelineReflection reflection;
  304. DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
  305. if (pipelineState)
  306. {
  307. PrintPipelineReflection(&reflection, DKLogCategory::Verbose);
  308. }
  309. ///
  310. graphicShaderBindingSet = DKOBJECT_NEW GraphicShaderBindingSet();
  311. graphicShaderBindingSet->InitializeGpuResource(device);
  312. auto uboBuffer = graphicShaderBindingSet->UniformBuffer();
  313. auto ubo = graphicShaderBindingSet->UniformBufferO();
  314. // ComputerBuffer Layout
  315. DKShaderBindingSetLayout ComputeLayout;
  316. if (1)
  317. {
  318. DKShaderBinding bindings[2] = {
  319. {
  320. 0,
  321. DKShader::DescriptorTypeStorageTexture,
  322. 1,
  323. nullptr
  324. }, // Input Image (read-only)
  325. {
  326. 1,
  327. DKShader::DescriptorTypeStorageTexture,
  328. 1,
  329. nullptr
  330. }, // Output image (write)
  331. };
  332. ComputeLayout.bindings.Add(bindings, 2);
  333. }
  334. DKObject<DKShaderBindingSet> computebindSet = device->CreateShaderBindingSet(ComputeLayout);
  335. //auto CS_EF = CS_E->Function();
  336. //auto CS_EDF = CS_ED->Function();
  337. //auto CS_SHF = CS_SH->Function();
  338. DKComputePipelineDescriptor embossComputePipelineDescriptor;
  339. embossComputePipelineDescriptor.computeFunction = cs_ef;
  340. auto emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
  341. DKObject<DKTexture> depthBuffer = nullptr;
  342. DKObject<DKTexture> targettex = nullptr;
  343. DKTimer timer;
  344. timer.Reset();
  345. DKLog("Render thread begin");
  346. while (!runningRenderThread.CompareAndSet(0, 0))
  347. {
  348. DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
  349. double t = timer.Elapsed();
  350. double waveT = (cos(t) + 1.0) * 0.5;
  351. rpd.colorAttachments.Value(0).clearColor = DKColor(waveT, 0.0, 0.0, 0.0);
  352. int width = rpd.colorAttachments.Value(0).renderTarget->Width();
  353. int height = rpd.colorAttachments.Value(0).renderTarget->Height();
  354. if (depthBuffer)
  355. {
  356. if (depthBuffer->Width() != width ||
  357. depthBuffer->Height() != height )
  358. depthBuffer = nullptr;
  359. }
  360. if (depthBuffer == nullptr)
  361. {
  362. // create depth buffer
  363. DKTextureDescriptor texDesc = {};
  364. texDesc.textureType = DKTexture::Type2D;
  365. texDesc.pixelFormat = DKPixelFormat::D32Float;
  366. texDesc.width = width;
  367. texDesc.height = height;
  368. texDesc.depth = 1;
  369. texDesc.mipmapLevels = 1;
  370. texDesc.sampleCount = 1;
  371. texDesc.arrayLength = 1;
  372. texDesc.usage = DKTexture::UsageRenderTarget;
  373. depthBuffer = device->CreateTexture(texDesc);
  374. }
  375. rpd.depthStencilAttachment.renderTarget = depthBuffer;
  376. rpd.depthStencilAttachment.loadAction = DKRenderPassAttachmentDescriptor::LoadActionClear;
  377. rpd.depthStencilAttachment.storeAction = DKRenderPassAttachmentDescriptor::StoreActionDontCare;
  378. targettex = computeTarget->ComputeTarget(computeQueue, width, height);
  379. DKObject<DKCommandBuffer> computeCmdbuffer = computeQueue->CreateCommandBuffer();
  380. DKObject<DKComputeCommandEncoder> computeEncoder = computeCmdbuffer->CreateComputeCommandEncoder();
  381. if (computeEncoder)
  382. {
  383. if (computebindSet)
  384. {
  385. computebindSet->SetTexture(0, texture);
  386. computebindSet->SetTexture(1, targettex);
  387. }
  388. computeEncoder->SetComputePipelineState(emboss);
  389. computeEncoder->SetResources(0, computebindSet);
  390. computeEncoder->Dispatch(width / 16, height / 16, 1);
  391. computeEncoder->EndEncoding();
  392. }
  393. DKObject<DKCommandBuffer> buffer = graphicsQueue->CreateCommandBuffer();
  394. DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
  395. if (encoder)
  396. {
  397. if (graphicShaderBindingSet->PostcomputeDescSet() && ubo)
  398. {
  399. graphicShaderBindingSet->PostcomputeDescSet()->SetBuffer(0, uboBuffer, 0, sizeof(GraphicShaderBindingSet::UBO));
  400. graphicShaderBindingSet->PostcomputeDescSet()->SetTexture(1, targettex);
  401. graphicShaderBindingSet->PostcomputeDescSet()->SetSamplerState(1, sampler);
  402. }
  403. encoder->SetRenderPipelineState(pipelineState);
  404. encoder->SetVertexBuffer(quad->VertexBuffer(), 0, 0);
  405. encoder->SetIndexBuffer(quad->IndexBuffer(), 0, DKIndexType::UInt32);
  406. encoder->SetResources(0, graphicShaderBindingSet->PostcomputeDescSet());
  407. // draw scene!
  408. encoder->DrawIndexed(quad->IndicesCount(), 1, 0, 0, 0);
  409. encoder->EndEncoding();
  410. if (computeCmdbuffer)
  411. computeCmdbuffer->Commit();
  412. buffer->Commit();
  413. swapChain->Present();
  414. }
  415. else
  416. {
  417. }
  418. DKThread::Sleep(0.01);
  419. }
  420. DKLog("RenderThread terminating...");
  421. }
  422. void OnInitialize(void) override
  423. {
  424. SampleApp::OnInitialize();
  425. DKLogD("%s", DKGL_FUNCTION_NAME);
  426. // create window
  427. window = DKWindow::Create("DefaultWindow");
  428. window->SetOrigin({ 0, 0 });
  429. window->Resize({ 320, 240 });
  430. window->Activate();
  431. window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
  432. {
  433. if (e.type == DKWindow::WindowEvent::WindowClosed)
  434. DKApplication::Instance()->Terminate(0);
  435. }), NULL, NULL);
  436. quad = DKOBJECT_NEW UVQuad();
  437. runningRenderThread = 1;
  438. renderThread = DKThread::Create(DKFunction(this, &ComputeShaderDemo::RenderThread)->Invocation());
  439. }
  440. void OnTerminate(void) override
  441. {
  442. DKLogD("%s", DKGL_FUNCTION_NAME);
  443. runningRenderThread = 0;
  444. renderThread->WaitTerminate();
  445. renderThread = NULL;
  446. window = NULL;
  447. SampleApp::OnTerminate();
  448. }
  449. };
  450. #ifdef _WIN32
  451. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  452. _In_opt_ HINSTANCE hPrevInstance,
  453. _In_ LPWSTR lpCmdLine,
  454. _In_ int nCmdShow)
  455. #else
  456. int main(int argc, const char * argv[])
  457. #endif
  458. {
  459. ComputeShaderDemo app;
  460. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  461. DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
  462. return app.Run();
  463. }