|
|
|
|
75
|
|
75
|
|
76
|
if (textureTarget == nullptr)
|
76
|
if (textureTarget == nullptr)
|
77
|
{
|
77
|
{
|
78
|
- // create depth buffer
|
|
|
79
|
DKTextureDescriptor texDesc = {};
|
78
|
DKTextureDescriptor texDesc = {};
|
80
|
texDesc.textureType = DKTexture::Type2D;
|
79
|
texDesc.textureType = DKTexture::Type2D;
|
81
|
texDesc.pixelFormat = DKPixelFormat::BGRA8Unorm;
|
80
|
texDesc.pixelFormat = DKPixelFormat::BGRA8Unorm;
|
|
|
|
|
85
|
texDesc.mipmapLevels = 1;
|
84
|
texDesc.mipmapLevels = 1;
|
86
|
texDesc.sampleCount = 1;
|
85
|
texDesc.sampleCount = 1;
|
87
|
texDesc.arrayLength = 1;
|
86
|
texDesc.arrayLength = 1;
|
88
|
- texDesc.usage = DKTexture::UsageShaderRead | DKTexture::UsageStorage | DKTexture::UsageSampled;
|
|
|
|
|
87
|
+ texDesc.usage = DKTexture::UsageStorage // For Compute Shader
|
|
|
88
|
+ | DKTexture::UsageSampled | DKTexture::UsageShaderRead;// For FragmentShader
|
89
|
textureTarget = device->CreateTexture(texDesc);
|
89
|
textureTarget = device->CreateTexture(texDesc);
|
90
|
}
|
90
|
}
|
91
|
|
91
|
|
|
|
|
|
198
|
DKAtomicNumber32 runningRenderThread;
|
198
|
DKAtomicNumber32 runningRenderThread;
|
199
|
|
199
|
|
200
|
//Resource
|
200
|
//Resource
|
201
|
- DKObject<UVQuad> Quad;
|
|
|
|
|
201
|
+ DKObject<UVQuad> quad;
|
202
|
DKObject<DKTexture> textureColorMap;
|
202
|
DKObject<DKTexture> textureColorMap;
|
203
|
|
203
|
|
204
|
DKObject<TextureComputeTarget> ComputeTarget;
|
204
|
DKObject<TextureComputeTarget> ComputeTarget;
|
|
|
|
|
265
|
DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
|
265
|
DKObject<DKCommandQueue> computeQueue = device->CreateCommandQueue(DKCommandQueue::Compute);
|
266
|
|
266
|
|
267
|
// Geometry Initialzie
|
267
|
// Geometry Initialzie
|
268
|
- Quad->InitializeGpuResource(graphicsQueue);
|
|
|
|
|
268
|
+ quad->InitializeGpuResource(graphicsQueue);
|
269
|
|
269
|
|
270
|
// create shaders
|
270
|
// create shaders
|
271
|
DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
|
271
|
DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/ComputeShader/texture.vert.spv");
|
|
|
|
|
275
|
DKObject<DKData> sharpenData = resourcePool.LoadResourceData("shaders/ComputeShader/sharpen.comp.spv");
|
275
|
DKObject<DKData> sharpenData = resourcePool.LoadResourceData("shaders/ComputeShader/sharpen.comp.spv");
|
276
|
|
276
|
|
277
|
|
277
|
|
278
|
- DKObject<GPUShader> VS = DKOBJECT_NEW GPUShader(vertData);
|
|
|
279
|
- DKObject<GPUShader> FS = DKOBJECT_NEW GPUShader(fragData);
|
|
|
|
|
278
|
+ DKObject<GPUShader> vs = DKOBJECT_NEW GPUShader(vertData);
|
|
|
279
|
+ DKObject<GPUShader> fs = DKOBJECT_NEW GPUShader(fragData);
|
280
|
|
280
|
|
281
|
- DKObject<GPUShader> CS_E = DKOBJECT_NEW GPUShader(embossData);
|
|
|
282
|
- DKObject<GPUShader> CS_ED = DKOBJECT_NEW GPUShader(edgedetectData);
|
|
|
283
|
- DKObject<GPUShader> CS_SH = DKOBJECT_NEW GPUShader(sharpenData);
|
|
|
|
|
281
|
+ DKObject<GPUShader> cs_e = DKOBJECT_NEW GPUShader(embossData);
|
|
|
282
|
+ DKObject<GPUShader> cs_ed = DKOBJECT_NEW GPUShader(edgedetectData);
|
|
|
283
|
+ DKObject<GPUShader> cs_sh = DKOBJECT_NEW GPUShader(sharpenData);
|
284
|
|
284
|
|
285
|
- VS->InitializeGpuResource(graphicsQueue);
|
|
|
286
|
- FS->InitializeGpuResource(graphicsQueue);
|
|
|
287
|
-
|
|
|
288
|
- CS_E->InitializeGpuResource(computeQueue);
|
|
|
289
|
- CS_ED->InitializeGpuResource(computeQueue);
|
|
|
290
|
- CS_SH->InitializeGpuResource(computeQueue);
|
|
|
291
|
-
|
|
|
292
|
- auto VSF = VS->Function();
|
|
|
293
|
- auto FSF = FS->Function();
|
|
|
294
|
- auto CS_EF = CS_E->Function();
|
|
|
295
|
- auto CS_EDF = CS_ED->Function();
|
|
|
296
|
- auto CS_SHF = CS_SH->Function();
|
|
|
|
|
285
|
+ vs->InitializeGpuResource(graphicsQueue);
|
|
|
286
|
+ fs->InitializeGpuResource(graphicsQueue);
|
297
|
|
287
|
|
|
|
288
|
+ cs_e->InitializeGpuResource(computeQueue);
|
|
|
289
|
+ cs_ed->InitializeGpuResource(computeQueue);
|
|
|
290
|
+ cs_sh->InitializeGpuResource(computeQueue);
|
298
|
|
291
|
|
|
|
292
|
+ auto vsf = vs->Function();
|
|
|
293
|
+ auto fsf = fs->Function();
|
|
|
294
|
+ auto cs_ef = cs_e->Function();
|
|
|
295
|
+ auto cs_edf = cs_ed->Function();
|
|
|
296
|
+ auto cs_shf = cs_sh->Function();
|
299
|
|
297
|
|
300
|
// Texture Resource Initialize
|
298
|
// Texture Resource Initialize
|
301
|
|
299
|
|
|
|
|
|
312
|
computeSamplerDesc.compareFunction = DKCompareFunctionNever;
|
310
|
computeSamplerDesc.compareFunction = DKCompareFunctionNever;
|
313
|
DKObject<DKSamplerState> computeSampler = device->CreateSamplerState(computeSamplerDesc);
|
311
|
DKObject<DKSamplerState> computeSampler = device->CreateSamplerState(computeSamplerDesc);
|
314
|
|
312
|
|
315
|
-
|
|
|
316
|
- // create texture
|
|
|
|
|
313
|
+ // create texture
|
317
|
DKObject<DKTexture> texture = LoadTexture2D(graphicsQueue, resourcePool.LoadResourceData("textures/deathstar3.png"));
|
314
|
DKObject<DKTexture> texture = LoadTexture2D(graphicsQueue, resourcePool.LoadResourceData("textures/deathstar3.png"));
|
318
|
|
315
|
|
319
|
// create sampler
|
316
|
// create sampler
|
|
|
|
|
329
|
|
326
|
|
330
|
DKObject<DKSwapChain> swapChain = graphicsQueue->CreateSwapChain(window);
|
327
|
DKObject<DKSwapChain> swapChain = graphicsQueue->CreateSwapChain(window);
|
331
|
|
328
|
|
332
|
- DKLog("VertexFunction.VertexAttributes: %d", VSF->StageInputAttributes().Count());
|
|
|
333
|
- for (int i = 0; i < VSF->StageInputAttributes().Count(); ++i)
|
|
|
|
|
329
|
+ DKLog("VertexFunction.VertexAttributes: %d", vsf->StageInputAttributes().Count());
|
|
|
330
|
+ for (int i = 0; i < vsf->StageInputAttributes().Count(); ++i)
|
334
|
{
|
331
|
{
|
335
|
- const DKShaderAttribute& attr = VSF->StageInputAttributes().Value(i);
|
|
|
|
|
332
|
+ const DKShaderAttribute& attr = vsf->StageInputAttributes().Value(i);
|
336
|
DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
|
333
|
DKLog(" --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
|
337
|
}
|
334
|
}
|
338
|
|
335
|
|
339
|
|
336
|
|
340
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
337
|
DKRenderPipelineDescriptor pipelineDescriptor;
|
341
|
// setup shader
|
338
|
// setup shader
|
342
|
- pipelineDescriptor.vertexFunction = VSF;
|
|
|
343
|
- pipelineDescriptor.fragmentFunction = FSF;
|
|
|
|
|
339
|
+ pipelineDescriptor.vertexFunction = vsf;
|
|
|
340
|
+ pipelineDescriptor.fragmentFunction = fsf;
|
344
|
|
341
|
|
345
|
// setup color-attachment render-targets
|
342
|
// setup color-attachment render-targets
|
346
|
pipelineDescriptor.colorAttachments.Resize(1);
|
343
|
pipelineDescriptor.colorAttachments.Resize(1);
|
|
|
|
|
354
|
pipelineDescriptor.depthStencilDescriptor.depthCompareFunction = DKCompareFunctionLessEqual;
|
351
|
pipelineDescriptor.depthStencilDescriptor.depthCompareFunction = DKCompareFunctionLessEqual;
|
355
|
|
352
|
|
356
|
// setup vertex buffer and attributes
|
353
|
// setup vertex buffer and attributes
|
357
|
- pipelineDescriptor.vertexDescriptor = Quad->VertexDescriptor();
|
|
|
|
|
354
|
+ pipelineDescriptor.vertexDescriptor = quad->VertexDescriptor();
|
358
|
|
355
|
|
359
|
// setup topology and rasterization
|
356
|
// setup topology and rasterization
|
360
|
pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
|
357
|
pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
|
|
|
|
|
403
|
//auto CS_SHF = CS_SH->Function();
|
400
|
//auto CS_SHF = CS_SH->Function();
|
404
|
|
401
|
|
405
|
DKComputePipelineDescriptor embossComputePipelineDescriptor;
|
402
|
DKComputePipelineDescriptor embossComputePipelineDescriptor;
|
406
|
- embossComputePipelineDescriptor.computeFunction = CS_EF;
|
|
|
|
|
403
|
+ embossComputePipelineDescriptor.computeFunction = cs_ef;
|
407
|
auto Emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
|
404
|
auto Emboss = device->CreateComputePipeline(embossComputePipelineDescriptor);
|
408
|
|
405
|
|
409
|
DKObject<DKTexture> depthBuffer = nullptr;
|
406
|
DKObject<DKTexture> depthBuffer = nullptr;
|
|
|
|
|
456
|
if (computebindSet)
|
453
|
if (computebindSet)
|
457
|
{
|
454
|
{
|
458
|
computebindSet->SetTexture(0, texture);
|
455
|
computebindSet->SetTexture(0, texture);
|
459
|
- //computebindSet->SetSamplerState(0, sampler);
|
|
|
460
|
computebindSet->SetTexture(1, targettex);
|
456
|
computebindSet->SetTexture(1, targettex);
|
461
|
- //computebindSet->SetSamplerState(1, sampler);
|
|
|
462
|
}
|
457
|
}
|
463
|
computeEncoder->SetComputePipelineState(Emboss);
|
458
|
computeEncoder->SetComputePipelineState(Emboss);
|
464
|
computeEncoder->SetResources(0, computebindSet);
|
459
|
computeEncoder->SetResources(0, computebindSet);
|
|
|
|
|
479
|
}
|
474
|
}
|
480
|
|
475
|
|
481
|
encoder->SetRenderPipelineState(pipelineState);
|
476
|
encoder->SetRenderPipelineState(pipelineState);
|
482
|
- encoder->SetVertexBuffer(Quad->VertexBuffer(), 0, 0);
|
|
|
483
|
- encoder->SetIndexBuffer(Quad->IndexBuffer(), 0, DKIndexType::UInt32);
|
|
|
|
|
477
|
+ encoder->SetVertexBuffer(quad->VertexBuffer(), 0, 0);
|
|
|
478
|
+ encoder->SetIndexBuffer(quad->IndexBuffer(), 0, DKIndexType::UInt32);
|
484
|
encoder->SetResources(0, graphicShaderBindingSet->PostcomputeDescSet());
|
479
|
encoder->SetResources(0, graphicShaderBindingSet->PostcomputeDescSet());
|
485
|
// draw scene!
|
480
|
// draw scene!
|
486
|
- encoder->DrawIndexed(Quad->IndicesCount(), 1, 0, 0, 0);
|
|
|
|
|
481
|
+ encoder->DrawIndexed(quad->IndicesCount(), 1, 0, 0, 0);
|
487
|
encoder->EndEncoding();
|
482
|
encoder->EndEncoding();
|
488
|
|
483
|
|
489
|
if (computeCmdbuffer)
|
484
|
if (computeCmdbuffer)
|
|
|
|
|
518
|
DKApplication::Instance()->Terminate(0);
|
513
|
DKApplication::Instance()->Terminate(0);
|
519
|
}), NULL, NULL);
|
514
|
}), NULL, NULL);
|
520
|
|
515
|
|
521
|
- Quad = DKOBJECT_NEW UVQuad();
|
|
|
|
|
516
|
+ quad = DKOBJECT_NEW UVQuad();
|
522
|
|
517
|
|
523
|
runningRenderThread = 1;
|
518
|
runningRenderThread = 1;
|
524
|
renderThread = DKThread::Create(DKFunction(this, &MeshDemo::RenderThread)->Invocation());
|
519
|
renderThread = DKThread::Create(DKFunction(this, &MeshDemo::RenderThread)->Invocation());
|