|
@@ -234,7 +234,9 @@ public:
|
234
|
234
|
DKObject<DKCommandQueue> graphicsQueue;
|
235
|
235
|
DKObject<DKCommandQueue> computeQueue;
|
236
|
236
|
|
237
|
|
- bool useSingleQueue = false;
|
|
237
|
+ bool useSingleQueue = true;
|
|
238
|
+ bool useSingleCommandBuffer = true;
|
|
239
|
+
|
238
|
240
|
if (useSingleQueue)
|
239
|
241
|
{
|
240
|
242
|
graphicsQueue = device->CreateCommandQueue(DKCommandQueue::Graphics | DKCommandQueue::Compute);
|
|
@@ -424,8 +426,26 @@ public:
|
424
|
426
|
rpd.depthStencilAttachment.loadAction = DKRenderPassAttachmentDescriptor::LoadActionClear;
|
425
|
427
|
rpd.depthStencilAttachment.storeAction = DKRenderPassAttachmentDescriptor::StoreActionDontCare;
|
426
|
428
|
|
427
|
|
- DKObject<DKCommandBuffer> computeCmdbuffer = computeQueue->CreateCommandBuffer();
|
428
|
|
- DKObject<DKComputeCommandEncoder> computeEncoder = computeCmdbuffer->CreateComputeCommandEncoder();
|
|
429
|
+
|
|
430
|
+ DKObject<DKComputeCommandEncoder> computeEncoder = nullptr;
|
|
431
|
+ DKObject<DKRenderCommandEncoder> renderEncoder = nullptr;
|
|
432
|
+
|
|
433
|
+ if (1)
|
|
434
|
+ {
|
|
435
|
+ auto commandBuffer = computeQueue->CreateCommandBuffer();
|
|
436
|
+ computeEncoder = commandBuffer->CreateComputeCommandEncoder();
|
|
437
|
+ }
|
|
438
|
+ if (1)
|
|
439
|
+ {
|
|
440
|
+ DKObject<DKCommandBuffer> commandBuffer = nullptr;
|
|
441
|
+ if (computeQueue == graphicsQueue && useSingleCommandBuffer)
|
|
442
|
+ commandBuffer = computeEncoder->CommandBuffer();
|
|
443
|
+ else
|
|
444
|
+ commandBuffer = graphicsQueue->CreateCommandBuffer();
|
|
445
|
+
|
|
446
|
+ renderEncoder = commandBuffer->CreateRenderCommandEncoder(rpd);
|
|
447
|
+ }
|
|
448
|
+
|
429
|
449
|
if (computeEncoder)
|
430
|
450
|
{
|
431
|
451
|
if (computebindSet)
|
|
@@ -441,10 +461,7 @@ public:
|
441
|
461
|
computeEncoder->EndEncoding();
|
442
|
462
|
}
|
443
|
463
|
|
444
|
|
- DKObject<DKCommandBuffer> buffer = graphicsQueue->CreateCommandBuffer();
|
445
|
|
- DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
|
446
|
|
-
|
447
|
|
- if (encoder)
|
|
464
|
+ if (renderEncoder)
|
448
|
465
|
{
|
449
|
466
|
if (graphicShaderBindingSet->PostcomputeDescSet() && ubo)
|
450
|
467
|
{
|
|
@@ -453,18 +470,18 @@ public:
|
453
|
470
|
graphicShaderBindingSet->PostcomputeDescSet()->SetSamplerState(1, sampler);
|
454
|
471
|
}
|
455
|
472
|
|
456
|
|
- encoder->SetRenderPipelineState(pipelineState);
|
457
|
|
- encoder->SetVertexBuffer(quad->VertexBuffer(), 0, 0);
|
458
|
|
- encoder->SetIndexBuffer(quad->IndexBuffer(), 0, DKIndexType::UInt32);
|
459
|
|
- encoder->SetResources(0, graphicShaderBindingSet->PostcomputeDescSet());
|
|
473
|
+ renderEncoder->SetRenderPipelineState(pipelineState);
|
|
474
|
+ renderEncoder->SetVertexBuffer(quad->VertexBuffer(), 0, 0);
|
|
475
|
+ renderEncoder->SetIndexBuffer(quad->IndexBuffer(), 0, DKIndexType::UInt32);
|
|
476
|
+ renderEncoder->SetResources(0, graphicShaderBindingSet->PostcomputeDescSet());
|
460
|
477
|
// draw scene!
|
461
|
|
- encoder->DrawIndexed(quad->IndicesCount(), 1, 0, 0, 0);
|
462
|
|
- encoder->EndEncoding();
|
|
478
|
+ renderEncoder->DrawIndexed(quad->IndicesCount(), 1, 0, 0, 0);
|
|
479
|
+ renderEncoder->EndEncoding();
|
463
|
480
|
|
464
|
|
- if (computeCmdbuffer)
|
465
|
|
- computeCmdbuffer->Commit();
|
|
481
|
+ if (computeEncoder->CommandBuffer() != renderEncoder->CommandBuffer())
|
|
482
|
+ computeEncoder->CommandBuffer()->Commit();
|
466
|
483
|
|
467
|
|
- buffer->Commit();
|
|
484
|
+ renderEncoder->CommandBuffer()->Commit();
|
468
|
485
|
|
469
|
486
|
swapChain->Present();
|
470
|
487
|
}
|