// Optional metal-cpp ownership probe, separate from the SDK-only .mm program. // Supply Apple's metal-cpp headers; see README. Define these in ONE translation unit. #define NS_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION #include #include #include int main() { auto pool = NS::TransferPtr(NS::AutoreleasePool::alloc()->init()); auto device = NS::TransferPtr(MTL::CreateSystemDefaultDevice()); if (!device) { std::cerr << "No Metal device\n"; return 1; } auto queue = NS::TransferPtr(device->newCommandQueue()); if (!queue) { std::cerr << "Cannot create command queue\n"; return 1; } // commandBuffer() is borrowed/autoreleased. Retain it to express our ownership. auto commands = NS::RetainPtr(queue->commandBuffer()); if (!commands) { std::cerr << "Cannot create command buffer\n"; return 1; } std::cout << device->name()->utf8String() << '\n'; // Nothing submitted; reverse declaration order releases commands, queue, device, pool. }