Skip to content
Permalink
Browse files
[WebGPU] Integrate Metal-cpp
https://bugs.webkit.org/show_bug.cgi?id=240746
<rdar://problem/89344870>

Reviewed by Dean Jackson.

Metal-cpp is a low-overhead C++ interface for Metal.
https://developer.apple.com/metal/cpp/

Metal-cpp isn't a library per-se, but is instead just a collection of files which users
are supposed to just copy into their project. This does just that, and hooks up all the
necessary flags and paths and everything.

This uses the "single header alternative" described on that webpage, and creates the
single file as a build step.

Metal-cpp files should not be style-checked.

* Source/WebGPU/Configurations/WebGPU.xcconfig:
* Source/WebGPU/WebGPU.xcodeproj/project.pbxproj:
* Source/WebGPU/WebGPU/Metal.cpp: Added.
* Source/WebGPU/WebGPU/config.h:
* Source/WebGPU/WebGPU/metal-cpp/Foundation/Foundation.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSArray.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSAutoreleasePool.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSBundle.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSData.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSDate.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSDefines.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSDictionary.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSEnumerator.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSError.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSLock.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSNotification.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSNumber.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSObjCRuntime.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSObject.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSPrivate.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSProcessInfo.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSRange.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSString.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSTypes.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Foundation/NSURL.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/LICENSE.txt: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLAccelerationStructure.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLAccelerationStructureCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLAccelerationStructureTypes.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLArgument.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLArgumentEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLBinaryArchive.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLBlitCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLBlitPass.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLBuffer.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLCaptureManager.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLCaptureScope.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLCommandBuffer.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLCommandQueue.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLComputeCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLComputePass.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLComputePipeline.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLCounters.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLDefines.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLDepthStencil.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLDevice.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLDrawable.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLDynamicLibrary.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLEvent.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLFence.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLFunctionConstantValues.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLFunctionDescriptor.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLFunctionHandle.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLFunctionLog.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLFunctionStitching.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLHeaderBridge.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLHeap.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLIndirectCommandBuffer.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLIndirectCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLIntersectionFunctionTable.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLLibrary.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLLinkedFunctions.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLParallelRenderCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLPipeline.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLPixelFormat.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLPrivate.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLRasterizationRate.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLRenderCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLRenderPass.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLRenderPipeline.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLResource.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLResourceStateCommandEncoder.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLResourceStatePass.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLSampler.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLStageInputOutputDescriptor.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLTexture.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLTypes.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLVertexDescriptor.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/MTLVisibleFunctionTable.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/Metal/Metal.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/QuartzCore/CADefines.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/QuartzCore/CAMetalDrawable.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/QuartzCore/CAPrivate.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/QuartzCore/QuartzCore.hpp: Added.
* Source/WebGPU/WebGPU/metal-cpp/README.md: Added.
* Source/WebGPU/WebGPU/metal-cpp/SingleHeader/MakeSingleHeader.py: Added.
(HeaderPrefix):
(HeaderPrefix.__init__):
(HeaderPrefix.__str__):
(HeaderPrefix.__get_commit_hash):
(HeaderPrefix.__get_commit_string):
(HeaderPrefix.__get_date_string):
(__meta_data_string):
(SingleHeader):
(SingleHeader.__init__):
(SingleHeader.__str__):
(SingleHeader.append):
(SingleHeader.process):
(SingleHeader.__read_header):
(SingleHeader.__strip_pragma_once):
(SingleHeader.__strip_comments):
(SingleHeader.__strip_empty_lines):
(SingleHeader.__substitute_include_directive):
(SingleHeader.__process_include_directives):
(SingleHeader.__process_foundation_directives):
(SingleHeader.__process_header):
(create_argument_parser):
(parse_arguments):
(make_header):
(make_dir):
(write_header):
* Tools/Scripts/webkitpy/style/checker.py:

Canonical link: https://commits.webkit.org/250827@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294599 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
litherum committed May 21, 2022
1 parent 6b07b8b commit e901f75b4dfdd6db7ac4f49f4016a87ba24ba758
Showing 88 changed files with 22,214 additions and 2 deletions.
@@ -23,7 +23,10 @@

#include "Version.xcconfig"

WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wexit-time-destructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety -Wno-typedef-redefinition -Wno-ignored-qualifiers;

HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/usr/local/include" $(inherited);
SYSTEM_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/DerivedSources/WebGPU/metal-cpp $(inherited);

WK_PRIVATE_FRAMEWORKS_DIR = $(WK_PRIVATE_FRAMEWORKS_DIR_$(USE_INTERNAL_SDK));
WK_PRIVATE_FRAMEWORKS_DIR_[sdk=macos*] = $(PROJECT_DIR)/../../WebKitLibraries/WebKitPrivateFrameworkStubs/Mac/$(TARGET_MAC_OS_X_VERSION_MAJOR);
@@ -89,4 +92,8 @@ MODULEMAP_FILE = WebGPU/WebGPU.modulemap;
SUPPORTS_TEXT_BASED_API = YES;
TAPI_VERIFY_MODE = Pedantic;

OTHER_LDFLAGS = $(inherited) $(SOURCE_VERSION_LDFLAGS);
// HEADERMAP_INCLUDES_PROJECT_HEADERS = NO;

USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES;

OTHER_LDFLAGS = $(inherited) $(SOURCE_VERSION_LDFLAGS) -Xlinker -no_warn_inits;

Large diffs are not rendered by default.

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define NS_PRIVATE_IMPLEMENTATION
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include <Metal/Metal.hpp>
@@ -30,8 +30,12 @@

#include <Metal/Metal.h>

#include <Metal/Metal.hpp>

#include <wtf/Assertions.h>

#include <wtf/DisallowCType.h>

#include <wtf/Platform.h>

#include <wtf/RetainPtr.h>
@@ -0,0 +1,45 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Foundation/Foundation.hpp
//
// Copyright 2020-2021 Apple Inc.
//
// 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.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "NSArray.hpp"
#include "NSAutoreleasePool.hpp"
#include "NSBundle.hpp"
#include "NSData.hpp"
#include "NSDate.hpp"
#include "NSDefines.hpp"
#include "NSDictionary.hpp"
#include "NSEnumerator.hpp"
#include "NSError.hpp"
#include "NSLock.hpp"
#include "NSNotification.hpp"
#include "NSNumber.hpp"
#include "NSObject.hpp"
#include "NSPrivate.hpp"
#include "NSProcessInfo.hpp"
#include "NSRange.hpp"
#include "NSString.hpp"
#include "NSTypes.hpp"
#include "NSURL.hpp"

//-------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -0,0 +1,115 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Foundation/NSArray.hpp
//
// Copyright 2020-2021 Apple Inc.
//
// 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.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "NSObject.hpp"
#include "NSTypes.hpp"

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

namespace NS
{
class Array : public Copying<Array>
{
public:
static Array* array();
static Array* array(const Object* pObject);
static Array* array(const Object* const* pObjects, UInteger count);

static Array* alloc();

Array* init();
Array* init(const Object* const* pObjects, UInteger count);
Array* init(const class Coder* pCoder);

template <class _Object = Object>
_Object* object(UInteger index) const;
UInteger count() const;
};
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::array()
{
return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(array));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::array(const Object* pObject)
{
return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObject_), pObject);
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::array(const Object* const* pObjects, UInteger count)
{
return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObjects_count_), pObjects, count);
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::alloc()
{
return NS::Object::alloc<Array>(_NS_PRIVATE_CLS(NSArray));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::init()
{
return NS::Object::init<Array>();
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::init(const Object* const* pObjects, UInteger count)
{
return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithObjects_count_), pObjects, count);
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::Array* NS::Array::init(const class Coder* pCoder)
{
return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithCoder_), pCoder);
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::UInteger NS::Array::count() const
{
return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(count));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

template <class _Object>
_NS_INLINE _Object* NS::Array::object(UInteger index) const
{
return Object::sendMessage<_Object*>(this, _NS_PRIVATE_SEL(objectAtIndex_), index);
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -0,0 +1,83 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Foundation/NSAutoreleasePool.hpp
//
// Copyright 2020-2021 Apple Inc.
//
// 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.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------

#pragma once

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "NSDefines.hpp"
#include "NSObject.hpp"
#include "NSPrivate.hpp"
#include "NSTypes.hpp"

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

namespace NS
{
class AutoreleasePool : public Object
{
public:
static AutoreleasePool* alloc();
AutoreleasePool* init();

void drain();

void addObject(Object* pObject);

static void showPools();
};
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::AutoreleasePool* NS::AutoreleasePool::alloc()
{
return NS::Object::alloc<AutoreleasePool>(_NS_PRIVATE_CLS(NSAutoreleasePool));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE NS::AutoreleasePool* NS::AutoreleasePool::init()
{
return NS::Object::init<AutoreleasePool>();
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE void NS::AutoreleasePool::drain()
{
Object::sendMessage<void>(this, _NS_PRIVATE_SEL(drain));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE void NS::AutoreleasePool::addObject(Object* pObject)
{
Object::sendMessage<void>(this, _NS_PRIVATE_SEL(addObject_), pObject);
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

_NS_INLINE void NS::AutoreleasePool::showPools()
{
Object::sendMessage<void>(_NS_PRIVATE_CLS(NSAutoreleasePool), _NS_PRIVATE_SEL(showPools));
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------

0 comments on commit e901f75

Please sign in to comment.