Reland "Metal: Add CommandRecordingContext"

This is a reland of 2b3975f808

The previous CL failed to retain autoreleased ObjC objects which
should live longer than the autoreleasepool block. This reland fixes
the issue and adds tests for it.

Original change's description:
> Metal: Add CommandRecordingContext
>
> Introduces the idea of a CommandRecordingContext to the Metal backend,
> similar to other backends. This is a class to track which Metal encoder
> is open on the device-global pending MTLCommandBuffer.
> It will be needed to open/close encoders for lazy clearing.
>
> Bug: dawn:145
> Change-Id: Ief6b71a079d73943677d2b61382d1c36b88a4f87
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14780
> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Austin Eng <enga@chromium.org>

Bug: dawn:145
Change-Id: I67494b35225ce8f6443a3fa9787d054522e5d422
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15042
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng
2020-01-15 18:22:53 +00:00
committed by Commit Bot service account
parent 855a24b150
commit 0c66bcd13a
9 changed files with 354 additions and 149 deletions

View File

@@ -0,0 +1,61 @@
// Copyright 2020 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "tests/DawnTest.h"
#include "dawn_native/metal/DeviceMTL.h"
using namespace dawn_native::metal;
class MetalAutoreleasePoolTests : public DawnTest {
private:
void TestSetUp() override {
DAWN_SKIP_TEST_IF(UsesWire());
mMtlDevice = reinterpret_cast<Device*>(device.Get());
}
protected:
Device* mMtlDevice = nullptr;
};
// Test that the MTLCommandBuffer owned by the pending command context can
// outlive an autoreleasepool block.
TEST_P(MetalAutoreleasePoolTests, CommandBufferOutlivesAutorelease) {
@autoreleasepool {
// Get the recording context which will allocate a MTLCommandBuffer.
// It will get autoreleased at the end of this block.
mMtlDevice->GetPendingCommandContext();
}
// Submitting the command buffer should succeed.
mMtlDevice->SubmitPendingCommandBuffer();
}
// Test that the MTLBlitCommandEncoder owned by the pending command context
// can outlive an autoreleasepool block.
TEST_P(MetalAutoreleasePoolTests, EncoderOutlivesAutorelease) {
@autoreleasepool {
// Get the recording context which will allocate a MTLCommandBuffer.
// Begin a blit encoder.
// Both will get autoreleased at the end of this block.
mMtlDevice->GetPendingCommandContext()->EnsureBlit();
}
// Submitting the command buffer should succeed.
mMtlDevice->GetPendingCommandContext()->EndBlit();
mMtlDevice->SubmitPendingCommandBuffer();
}
DAWN_INSTANTIATE_TEST(MetalAutoreleasePoolTests, MetalBackend);