Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to metal C++? #2

Closed
machineko opened this issue Dec 30, 2021 · 5 comments
Closed

Migrate to metal C++? #2

machineko opened this issue Dec 30, 2021 · 5 comments
Labels
speculative Note sure if we want this.

Comments

@machineko
Copy link

machineko commented Dec 30, 2021

https://developer.apple.com/metal/cpp/

@maleadt maleadt added the speculative Note sure if we want this. label Jun 23, 2022
@maleadt
Copy link
Member

maleadt commented Jun 23, 2022

This would be useful if we had a good C++ FFI. Without it, you'd probably end up writing shims anyway.

@maleadt
Copy link
Member

maleadt commented Jun 26, 2022

It's something to keep in mind though, so it doesn't hurt to let this open.

@maleadt maleadt reopened this Jun 26, 2022
@maleadt
Copy link
Member

maleadt commented Jan 31, 2023

I had a brief look at using SWIG with the experimental C back-end from swig/swig#2086, but ran into a few problems. Documenting those here:

  • SWIG doesn't handle _MTL_INLINE (but we can sed that away)
  • callbacks are blocks, not ordinary function pointers: https://en.wikipedia.org/wiki/Blocks_(C_language_extension). Maybe we can treat those without captures like ordinary function pointers (i.e. remove the (^)), but not all (e.g. newBuffer(const void* pointer, NS::UInteger length, MTL::ResourceOptions options, void (^deallocator)(void*, NS::UInteger)))

metal-cpp/Metal.i

%module MTL
%{
#define NS_PRIVATE_IMPLEMENTATION
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include <Metal/Metal.hpp>
%}

// includes taken from Metal.hpp (-includeall works too,
// but includes too much, like system headers)
#define NS_PRIVATE_IMPLEMENTATION
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION

%include "MTLAccelerationStructure.hpp"
%include "MTLAccelerationStructureCommandEncoder.hpp"
%include "MTLAccelerationStructureTypes.hpp"
%include "MTLArgument.hpp"
%include "MTLArgumentEncoder.hpp"
%include "MTLBinaryArchive.hpp"
%include "MTLBlitCommandEncoder.hpp"
%include "MTLBlitPass.hpp"
%include "MTLBuffer.hpp"
%include "MTLCaptureManager.hpp"
%include "MTLCaptureScope.hpp"
%include "MTLCommandBuffer.hpp"
%include "MTLCommandEncoder.hpp"
%include "MTLCommandQueue.hpp"
%include "MTLComputeCommandEncoder.hpp"
%include "MTLComputePass.hpp"
%include "MTLComputePipeline.hpp"
%include "MTLCounters.hpp"
%include "MTLDefines.hpp"
%include "MTLDepthStencil.hpp"
%include "MTLDevice.hpp"
%include "MTLDrawable.hpp"
%include "MTLDynamicLibrary.hpp"
%include "MTLEvent.hpp"
%include "MTLFence.hpp"
%include "MTLFunctionConstantValues.hpp"
%include "MTLFunctionDescriptor.hpp"
%include "MTLFunctionHandle.hpp"
%include "MTLFunctionLog.hpp"
%include "MTLFunctionStitching.hpp"
%include "MTLHeaderBridge.hpp"
%include "MTLHeap.hpp"
%include "MTLIndirectCommandBuffer.hpp"
%include "MTLIndirectCommandEncoder.hpp"
%include "MTLIntersectionFunctionTable.hpp"
%include "MTLIOCommandBuffer.hpp"
%include "MTLIOCommandQueue.hpp"
%include "MTLIOCompressor.hpp"
%include "MTLLibrary.hpp"
%include "MTLLinkedFunctions.hpp"
%include "MTLParallelRenderCommandEncoder.hpp"
%include "MTLPipeline.hpp"
%include "MTLPixelFormat.hpp"
%include "MTLPrivate.hpp"
%include "MTLRasterizationRate.hpp"
%include "MTLRenderCommandEncoder.hpp"
%include "MTLRenderPass.hpp"
%include "MTLRenderPipeline.hpp"
%include "MTLResource.hpp"
%include "MTLResourceStateCommandEncoder.hpp"
%include "MTLResourceStatePass.hpp"
%include "MTLSampler.hpp"
%include "MTLStageInputOutputDescriptor.hpp"
%include "MTLTexture.hpp"
%include "MTLTypes.hpp"
%include "MTLVertexDescriptor.hpp"
%include "MTLVisibleFunctionTable.hpp"
%include "MTLVersion.hpp"

swig -Imetal-cpp/Metal -c++ -c metal-cpp/Metal.i

@christiangnrd
Copy link
Contributor

Does #117 close this issue?

@maleadt
Copy link
Member

maleadt commented Mar 10, 2023

Yeah, thanks.

@maleadt maleadt closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speculative Note sure if we want this.
Projects
None yet
Development

No branches or pull requests

3 participants