Skip to content

Commit 7fc0aab

Browse files
committed
Initial commit
0 parents  commit 7fc0aab

File tree

14 files changed

+1373
-0
lines changed

14 files changed

+1373
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Files generated by invoking Julia with --code-coverage
2+
*.jl.cov
3+
*.jl.*.cov
4+
5+
# Files generated by invoking Julia with --track-allocation
6+
*.jl.mem
7+
8+
# System-specific files and directories generated by the BinaryProvider and BinDeps packages
9+
# They contain absolute paths specific to the host computer, and so should not be committed
10+
deps/deps.jl
11+
deps/build.log
12+
deps/downloads/
13+
deps/usr/
14+
deps/src/
15+
16+
# Build artifacts for creating documentation generated by the Documenter package
17+
docs/build/
18+
docs/site/
19+
20+
# File generated by Pkg, the package manager, based on a corresponding Project.toml
21+
# It records a fixed state of all packages used by the project. As such, it should not be
22+
# committed for packages, but should be committed for applications that require a static
23+
# environment.
24+
Manifest.toml

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Arhik
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Project.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name = "WGPUGUI"
2+
uuid = "edfb154a-8991-4155-9628-fd26c9c32bf2"
3+
authors = ["Arhik <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98"
8+
GLFW_jll = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
9+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
10+
WGPUCore = "53d714bf-0d76-4802-84b4-6cb75cca55f5"
11+
WGPUNative = "c14bfd16-04f9-4c2f-a915-b355584b5509"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# WGPUGUI
2+
Graphics Interface Library for JuliaWGPU

deps/artifacts.jl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using Debugger
2+
using Downloads
3+
4+
include("build.jl")
5+
6+
using Tar, Inflate, SHA
7+
8+
arch = lowercase(String(Sys.ARCH))
9+
kernel = lowercase(String(Sys.KERNEL))
10+
11+
# modifying conventions for wgpu specifically based on
12+
# releases at https://github.com/gfx-rs/wgpu-native/releases/tag/v0.12.0.1
13+
14+
version = "v0.1.2"
15+
kernels = ["macos"]
16+
archs = ["arm64", "x86_64"]
17+
18+
io = IOBuffer()
19+
20+
function writeIO(io, arch, kernel, sha1, sha256, filename, url)
21+
write(
22+
io,
23+
"""
24+
[[Cocoa]]
25+
arch = "$arch"
26+
git-tree-sha1 = "$sha1"
27+
os = "$kernel"
28+
29+
[[Cocoa.download]]
30+
sha256 = "$sha256"
31+
url = "$url"
32+
33+
""",
34+
)
35+
end
36+
37+
remoteurl = "https://github.com/dvijaha/WGPUCore.jl/releases/download/v0.1.2"
38+
39+
function generateArtifacts()
40+
for kernel in kernels
41+
for arch in archs
42+
tarfile = "WGPUCore.$version.$(arch)-$(kernel).tar.gz"
43+
try
44+
run(`rm cocoa.dylib`)
45+
build(arch)
46+
run(`tar -czvf $tarfile cocoa.dylib`)
47+
run(`rm cocoa.dylib`)
48+
catch(e)
49+
println("$e")
50+
end
51+
end
52+
end
53+
end
54+
55+
function writeArtifactsTOML()
56+
for kernel in kernels
57+
for arch in archs
58+
tarfile = "WGPUCore.$version.$(arch)-$(kernel).tar.gz"
59+
try
60+
Downloads.download(joinpath(remoteurl, tarfile), tarfile)
61+
@info joinpath(remoteurl, tarfile)
62+
sha256Val = bytes2hex(open(sha256, tarfile))
63+
sha1Val = Tar.tree_hash(IOBuffer(inflate_gzip(tarfile)))
64+
writeIO(
65+
io,
66+
arch,
67+
kernel,
68+
sha1Val,
69+
sha256Val,
70+
"",
71+
joinpath(remoteurl, tarfile),
72+
)
73+
catch e
74+
println("$e")
75+
end
76+
end
77+
end
78+
seek(io, 0)
79+
f = open("Artifacts.toml", "w")
80+
write(f, io)
81+
close(f)
82+
end
83+
84+
generateArtifacts()
85+
@info """
86+
Please upload files while I wait for input
87+
"""
88+
readline()
89+
writeArtifactsTOML()
90+
91+
run(`mv Artifacts.toml ../`)

deps/build.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using GLFW_jll
2+
using GLFW
3+
using Pkg.Artifacts
4+
5+
glfwpath = pkgdir(GLFW_jll)
6+
artifact_toml = joinpath(glfwpath, "Artifacts.toml")
7+
glfwHash = artifact_hash("GLFW", artifact_toml)
8+
glfwlibpath = joinpath(artifact_path(glfwHash), "lib")
9+
10+
arch = begin
11+
curArch = nothing
12+
if Sys.ARCH == :aarch64
13+
curArch = "arm64"
14+
elseif Sys.ARCH == :x64 # TODO check
15+
curArch = "x86_64"
16+
end
17+
curArch
18+
end
19+
20+
function build(arch)
21+
22+
out = Pipe()
23+
err = Pipe()
24+
25+
26+
cmd = `brew --prefix glfw`
27+
28+
process = run(pipeline(ignorestatus(cmd), stdout=out, stderr=err))
29+
close(out.in)
30+
close(err.in)
31+
brewpath = joinpath(String(read(out)) |> strip, "include")
32+
error = String(read(err))
33+
code = process.exitcode
34+
35+
cmd = `clang -arch $(arch) -dynamiclib cocoa.m
36+
-I $(brewpath) -o cocoa.dylib
37+
-framework cocoa
38+
-L $glfwlibpath
39+
-lGLFW -framework AppKit -framework Metal -framework QuartzCore`
40+
41+
out = Pipe()
42+
err = Pipe()
43+
44+
process = run(pipeline(ignorestatus(cmd), stdout=out, stderr=err))
45+
46+
close(out.in)
47+
close(err.in)
48+
49+
code = process.exitcode
50+
51+
if code == 0
52+
@info "Compiled $arch Cocoa Artifact"
53+
else
54+
@error "Compilation failed"
55+
end
56+
end
57+
58+
if abspath(PROGRAM_FILE) == @__FILE__
59+
build(arch)
60+
end
61+

deps/cocoa.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "Cocoa/Cocoa.h"
2+
#define GLFW_INCLUDE_NONE
3+
#define GLFW_EXPOSE_NATIVE_COCOA
4+
5+
#include <GLFW/glfw3.h>
6+
#include <GLFW/glfw3native.h>
7+
#import <Metal/Metal.h>
8+
#import <QuartzCore/CAMetalLayer.h>
9+
10+
CAMetalLayer * getMetalLayer() {
11+
CAMetalLayer *swapchain = [CAMetalLayer layer];
12+
return swapchain;
13+
}
14+
15+
void wantLayer(void * ptr) {
16+
NSWindow *nswindow = ptr;
17+
[nswindow.contentView setWantsLayer:YES];
18+
}
19+
20+
void setMetalLayer(void * ptr, void * layer) {
21+
NSWindow *nswindow = ptr;
22+
[nswindow.contentView setLayer:layer];
23+
}

src/WGPUGUI.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module WGPUGUI
2+
3+
export getCanvas
4+
using WGPUNative
5+
using WGPUCore
6+
using WGPUCore: AbstractWGPUCanvas, AbstractWGPUCanvasContext
7+
#using WGPUCore: WGPUTextureFormat, WGPUTextureUsage, WGPUSurface
8+
9+
include("offscreen.jl")
10+
11+
if Sys.isapple()
12+
include("events.jl")
13+
include("metalglfw.jl")
14+
elseif Sys.islinux()
15+
include("events.jl")
16+
include("linuxglfw.jl")
17+
elseif Sys.iswindows()
18+
include("events.jl")
19+
include("glfwWindows.jl")
20+
end
21+
22+
23+
function WGPUCore.getCanvas(s::Symbol)
24+
if s==:OFFSCREEN
25+
return defaultCanvas(OffscreenCanvas)
26+
elseif s==:GLFW
27+
if Sys.iswindows()
28+
return defaultCanvas(GLFWWinCanvas)
29+
elseif Sys.isapple()
30+
return defaultCanvas(GLFWMacCanvas)
31+
elseif Sys.islinux()
32+
return defaultCanvas(GLFWLinuxCanvas)
33+
end
34+
else
35+
@error "Couldn't create canvas"
36+
end
37+
end
38+
39+
40+
end # module WGPUGUI

0 commit comments

Comments
 (0)