Metal support

So, when will Metal support a package manager? The use case is very simple. We have a C (C++) module that contains a header file with a core structure used in Swift targets and shaders.

module CoreStructures {
    header "Rhombus.h"
}

struct Rhombus {

    float2 center;

};

It would be great if we could import this module directly in the *.metal file to access this core structure.

#include <metal_stdlib>

#import "CoreStructures"

using namespace metal;



float processRhombus(Rhombus rhombus) {}

Without this, we have to duplicate the header file separately in the application code (where the shaders are located) and in the C (C++) target in SPM

2 Likes

That's worthy of a SwiftPM GitHub issue. I know some work was done recently to support metal shaders in packages, but I'm not sure how far that got.

I thought switching to swift-build was going to bring with it more support for resource tooling, like Metal, since it's already supported through Xcode's usage of swift-build. Was that not the case?

Perhaps covered by the top two?

I think (in my humble opinion) there are two approaches here.

  • The difficult one: get SPM to build the Metal library. I think Doug mentioned this.
  • The easy one: tweak the settings and make sure the module built with SPM and imported into the main application is accessible not only from .swift files but also from .metal files.

We still need to get SwiftPM to tell SwiftBuild about the metal files. Mixed language targets don't work for the same reason. SwiftPM still needs to generate the right PIF so that SwiftBuild does the right thing.

And those things aren't hard. We're still focused on making sure we can build existing Swift packages with SwiftBuild. The good news is that we're really close right now for 6.4.

3 Likes