2017-07-13 19:07:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/mtl/MtlTestContext.h"
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2020-07-13 20:13:31 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2019-05-08 15:40:55 +00:00
|
|
|
#include "src/gpu/mtl/GrMtlUtil.h"
|
|
|
|
|
2019-05-22 20:23:43 +00:00
|
|
|
#ifdef SK_METAL
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2019-03-15 19:22:39 +00:00
|
|
|
#import <Metal/Metal.h>
|
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
namespace {
|
2019-03-15 19:22:39 +00:00
|
|
|
class MtlTestContextImpl : public sk_gpu_test::MtlTestContext {
|
2017-07-13 19:07:54 +00:00
|
|
|
public:
|
2019-03-15 19:22:39 +00:00
|
|
|
static MtlTestContext* Create(MtlTestContext* sharedContext) {
|
2020-11-12 20:21:11 +00:00
|
|
|
GrMtlBackendContext backendContext = {};
|
2019-03-15 19:22:39 +00:00
|
|
|
if (sharedContext) {
|
|
|
|
MtlTestContextImpl* sharedContextImpl = (MtlTestContextImpl*) sharedContext;
|
2020-11-12 20:21:11 +00:00
|
|
|
backendContext = sharedContextImpl->getMtlBackendContext();
|
2019-03-15 19:22:39 +00:00
|
|
|
} else {
|
2021-02-20 00:08:25 +00:00
|
|
|
id<MTLDevice> device;
|
2020-03-18 17:36:32 +00:00
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
2021-02-20 00:08:25 +00:00
|
|
|
NSArray<id <MTLDevice>>* availableDevices = MTLCopyAllDevices();
|
2020-03-18 17:36:32 +00:00
|
|
|
// Choose the non-integrated CPU if available
|
2021-02-20 00:08:25 +00:00
|
|
|
for (id<MTLDevice> dev in availableDevices) {
|
2020-03-18 17:36:32 +00:00
|
|
|
if (!dev.isLowPower) {
|
2021-02-20 00:08:25 +00:00
|
|
|
device = dev;
|
2020-03-18 17:36:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dev.isRemovable) {
|
2021-02-20 00:08:25 +00:00
|
|
|
device = dev;
|
2020-03-18 17:36:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!device) {
|
2021-02-20 00:08:25 +00:00
|
|
|
device = MTLCreateSystemDefaultDevice();
|
2020-03-18 17:36:32 +00:00
|
|
|
}
|
|
|
|
#else
|
2021-02-20 00:08:25 +00:00
|
|
|
device = MTLCreateSystemDefaultDevice();
|
2020-03-18 17:36:32 +00:00
|
|
|
#endif
|
2021-02-20 00:08:25 +00:00
|
|
|
backendContext.fDevice.retain((__bridge GrMTLHandle)device);
|
|
|
|
id<MTLCommandQueue> queue = [device newCommandQueue];
|
|
|
|
backendContext.fQueue.retain((__bridge GrMTLHandle)queue);
|
2019-03-15 19:22:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 20:21:11 +00:00
|
|
|
return new MtlTestContextImpl(backendContext);
|
2017-07-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 19:22:39 +00:00
|
|
|
~MtlTestContextImpl() override { this->teardown(); }
|
2017-07-13 19:07:54 +00:00
|
|
|
|
|
|
|
void testAbandon() override {}
|
|
|
|
|
|
|
|
void finish() override {}
|
|
|
|
|
2020-07-13 20:13:31 +00:00
|
|
|
sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override {
|
2020-11-12 20:21:11 +00:00
|
|
|
return GrDirectContext::MakeMetal(fMtl, options);
|
2017-07-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-11-12 20:21:11 +00:00
|
|
|
MtlTestContextImpl(const GrMtlBackendContext& mtl)
|
|
|
|
: INHERITED(mtl) {
|
2020-02-21 20:46:27 +00:00
|
|
|
fFenceSupport = true;
|
2019-06-04 13:57:14 +00:00
|
|
|
}
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2020-02-13 17:59:19 +00:00
|
|
|
void onPlatformMakeNotCurrent() const override {}
|
2017-07-13 19:07:54 +00:00
|
|
|
void onPlatformMakeCurrent() const override {}
|
2017-11-17 14:25:23 +00:00
|
|
|
std::function<void()> onPlatformGetAutoContextRestore() const override { return nullptr; }
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = sk_gpu_test::MtlTestContext;
|
2017-07-13 19:07:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2019-03-15 19:22:39 +00:00
|
|
|
MtlTestContext* CreatePlatformMtlTestContext(MtlTestContext* sharedContext) {
|
|
|
|
return MtlTestContextImpl::Create(sharedContext);
|
2017-07-13 19:07:54 +00:00
|
|
|
}
|
2019-03-15 19:22:39 +00:00
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
} // namespace sk_gpu_test
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|