mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
Introduce Begin/EndComputePass (#70)
This commit is contained in:
@@ -47,31 +47,35 @@ namespace metal {
|
||||
RenderPass* currentRenderPass = nullptr;
|
||||
Framebuffer* currentFramebuffer = nullptr;
|
||||
|
||||
void FinishEncoders() {
|
||||
void EnsureNoBlitEncoder() {
|
||||
ASSERT(render == nil);
|
||||
ASSERT(compute == nil);
|
||||
if (blit != nil) {
|
||||
[blit endEncoding];
|
||||
blit = nil;
|
||||
}
|
||||
if (compute != nil) {
|
||||
[compute endEncoding];
|
||||
compute = nil;
|
||||
}
|
||||
}
|
||||
|
||||
void EnsureBlit(id<MTLCommandBuffer> commandBuffer) {
|
||||
ASSERT(render == nil);
|
||||
ASSERT(compute == nil);
|
||||
if (blit == nil) {
|
||||
FinishEncoders();
|
||||
blit = [commandBuffer blitCommandEncoder];
|
||||
}
|
||||
}
|
||||
void EnsureCompute(id<MTLCommandBuffer> commandBuffer) {
|
||||
if (compute == nil) {
|
||||
FinishEncoders();
|
||||
compute = [commandBuffer computeCommandEncoder];
|
||||
// TODO(cwallez@chromium.org): does any state need to be reset?
|
||||
}
|
||||
|
||||
void BeginCompute(id<MTLCommandBuffer> commandBuffer) {
|
||||
EnsureNoBlitEncoder();
|
||||
compute = [commandBuffer computeCommandEncoder];
|
||||
// TODO(cwallez@chromium.org): does any state need to be reset?
|
||||
}
|
||||
|
||||
void EndCompute() {
|
||||
ASSERT(compute != nil);
|
||||
[compute endEncoding];
|
||||
compute = nil;
|
||||
}
|
||||
|
||||
void BeginSubpass(id<MTLCommandBuffer> commandBuffer, uint32_t subpass) {
|
||||
ASSERT(currentRenderPass);
|
||||
if (render != nil) {
|
||||
@@ -111,7 +115,8 @@ namespace metal {
|
||||
render = [commandBuffer renderCommandEncoderWithDescriptor:descriptor];
|
||||
// TODO(cwallez@chromium.org): does any state need to be reset?
|
||||
}
|
||||
void EndRenderPass() {
|
||||
|
||||
void EndSubpass() {
|
||||
ASSERT(render != nil);
|
||||
[render endEncoding];
|
||||
render = nil;
|
||||
@@ -141,12 +146,19 @@ namespace metal {
|
||||
uint32_t currentSubpass = 0;
|
||||
while (commands.NextCommandId(&type)) {
|
||||
switch (type) {
|
||||
case Command::BeginComputePass:
|
||||
{
|
||||
commands.NextCommand<BeginComputePassCmd>();
|
||||
encoders.BeginCompute(commandBuffer);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::BeginRenderPass:
|
||||
{
|
||||
BeginRenderPassCmd* beginRenderPassCmd = commands.NextCommand<BeginRenderPassCmd>();
|
||||
encoders.currentRenderPass = ToBackend(beginRenderPassCmd->renderPass.Get());
|
||||
encoders.currentFramebuffer = ToBackend(beginRenderPassCmd->framebuffer.Get());
|
||||
encoders.FinishEncoders();
|
||||
encoders.EnsureNoBlitEncoder();
|
||||
currentSubpass = 0;
|
||||
}
|
||||
break;
|
||||
@@ -243,7 +255,7 @@ namespace metal {
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
encoders.EnsureCompute(commandBuffer);
|
||||
ASSERT(encoders.compute);
|
||||
ASSERT(lastPipeline->IsCompute());
|
||||
|
||||
[encoders.compute dispatchThreadgroups:MTLSizeMake(dispatch->x, dispatch->y, dispatch->z)
|
||||
@@ -282,16 +294,23 @@ namespace metal {
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndComputePass:
|
||||
{
|
||||
commands.NextCommand<EndComputePassCmd>();
|
||||
encoders.EndCompute();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderPass:
|
||||
{
|
||||
commands.NextCommand<EndRenderPassCmd>();
|
||||
encoders.EndRenderPass();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<EndRenderSubpassCmd>();
|
||||
encoders.EndSubpass();
|
||||
currentSubpass += 1;
|
||||
}
|
||||
break;
|
||||
@@ -302,7 +321,7 @@ namespace metal {
|
||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||
|
||||
if (lastPipeline->IsCompute()) {
|
||||
encoders.EnsureCompute(commandBuffer);
|
||||
ASSERT(encoders.compute);
|
||||
lastPipeline->Encode(encoders.compute);
|
||||
} else {
|
||||
ASSERT(encoders.render);
|
||||
@@ -340,7 +359,7 @@ namespace metal {
|
||||
const auto& layout = group->GetLayout()->GetBindingInfo();
|
||||
|
||||
if (lastPipeline->IsCompute()) {
|
||||
encoders.EnsureCompute(commandBuffer);
|
||||
ASSERT(encoders.compute);
|
||||
} else {
|
||||
ASSERT(encoders.render);
|
||||
}
|
||||
@@ -501,7 +520,9 @@ namespace metal {
|
||||
}
|
||||
}
|
||||
|
||||
encoders.FinishEncoders();
|
||||
encoders.EnsureNoBlitEncoder();
|
||||
ASSERT(encoders.render == nil);
|
||||
ASSERT(encoders.compute == nil);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user