tilework-metal 0.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/ext/tilework/metal/bridge.swift +1203 -0
- data/ext/tilework/metal/extconf.rb +65 -0
- data/ext/tilework/metal/gpu_bridge.c +840 -0
- data/lib/tilework/backend/metal.rb +40 -0
- metadata +66 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# mkmf does not support Swift, so the Makefile is written directly.
|
|
4
|
+
#
|
|
5
|
+
# 1. macOS -> link bridge.swift with swiftc
|
|
6
|
+
# 2. elsewhere -> a no-op Makefile (so `bundle install` does not fail
|
|
7
|
+
# without Metal; core's backend= turns the missing extension into a
|
|
8
|
+
# Tilework::DeviceError)
|
|
9
|
+
#
|
|
10
|
+
# The product goes to lib/tilework/metal/bridge.<dlext> so it cannot collide
|
|
11
|
+
# with other backends.
|
|
12
|
+
|
|
13
|
+
require "rbconfig"
|
|
14
|
+
|
|
15
|
+
hdrdir = RbConfig::CONFIG["rubyhdrdir"]
|
|
16
|
+
archhdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
|
|
17
|
+
dlext = RbConfig::CONFIG["DLEXT"] # darwin: "bundle"
|
|
18
|
+
cc = RbConfig::CONFIG["CC"]
|
|
19
|
+
srcdir = File.expand_path(__dir__)
|
|
20
|
+
|
|
21
|
+
if RbConfig::CONFIG["host_os"] =~ /darwin/
|
|
22
|
+
# The C side (gpu_bridge.c) is compiled with clang and linked together with
|
|
23
|
+
# the Swift side (bridge.swift) into a .bundle, using swiftc as the linker
|
|
24
|
+
# driver. Ruby symbols resolve via -undefined dynamic_lookup, as is usual
|
|
25
|
+
# for C extensions.
|
|
26
|
+
makefile = <<~MAKEFILE
|
|
27
|
+
TARGET = bridge.#{dlext}
|
|
28
|
+
CC = #{cc}
|
|
29
|
+
SWIFTC = swiftc
|
|
30
|
+
CFLAGS = -O2 -Wall -fPIC -DTILEWORK_BRIDGE_MODULE=\\\"MetalBridge\\\" -I#{hdrdir} -I#{archhdrdir}
|
|
31
|
+
SWIFTFLAGS = -O -parse-as-library
|
|
32
|
+
LDFLAGS = -Xlinker -undefined -Xlinker dynamic_lookup -framework Metal -framework MetalPerformanceShadersGraph
|
|
33
|
+
# MPSGraphFFTDescriptor / realToHermiteanFFT etc. need macOS 14 or later.
|
|
34
|
+
DEPLOY = MACOSX_DEPLOYMENT_TARGET=14.0
|
|
35
|
+
|
|
36
|
+
SRCDIR = #{srcdir}
|
|
37
|
+
|
|
38
|
+
all: $(TARGET)
|
|
39
|
+
|
|
40
|
+
gpu_bridge.o: $(SRCDIR)/gpu_bridge.c
|
|
41
|
+
\t$(DEPLOY) $(CC) $(CFLAGS) -c $(SRCDIR)/gpu_bridge.c -o $@
|
|
42
|
+
|
|
43
|
+
$(TARGET): gpu_bridge.o $(SRCDIR)/bridge.swift
|
|
44
|
+
\t$(DEPLOY) $(SWIFTC) $(SWIFTFLAGS) -emit-library $(SRCDIR)/bridge.swift gpu_bridge.o $(LDFLAGS) -o $@
|
|
45
|
+
|
|
46
|
+
clean:
|
|
47
|
+
\trm -f $(TARGET) gpu_bridge.o
|
|
48
|
+
|
|
49
|
+
# gem install calls install with sitearchdir overridden. Install to the
|
|
50
|
+
# namespaced path rather than a flat one so require
|
|
51
|
+
# "tilework/metal/bridge" resolves.
|
|
52
|
+
sitearchdir = .
|
|
53
|
+
install: $(TARGET)
|
|
54
|
+
\tmkdir -p $(sitearchdir)/tilework/metal
|
|
55
|
+
\tcp $(TARGET) $(sitearchdir)/tilework/metal/$(TARGET)
|
|
56
|
+
|
|
57
|
+
.PHONY: all clean install
|
|
58
|
+
MAKEFILE
|
|
59
|
+
|
|
60
|
+
File.write("Makefile", makefile)
|
|
61
|
+
puts "created Makefile (Metal backend)"
|
|
62
|
+
else
|
|
63
|
+
File.write("Makefile", "all:\ninstall:\nclean:\n.PHONY: all install clean\n")
|
|
64
|
+
puts "skipping tilework/metal build (not on macOS)"
|
|
65
|
+
end
|