-
-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
5,431 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,7 +303,7 @@ bin/ | |
# - Linux/MacOS | ||
odin | ||
!odin/ | ||
odin.dSYM | ||
**/*.dSYM | ||
*.bin | ||
demo.bin | ||
libLLVM*.so* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
lib/* | ||
!lib/.gitkeep | ||
example/web/triangle.wasm | ||
example/web/wgpu.js | ||
example/web/runtime.js | ||
example/example | ||
example/example.exe | ||
example/triangle | ||
example/triangle.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# WGPU | ||
|
||
A cross-platform (and WASM) GPU API. | ||
|
||
WASM support is achieved by providing wrappers around the browser native WebGPU API | ||
that are called instead of the [wgpu-native](https://github.com/gfx-rs/wgpu-native) library, | ||
the wgpu-native library provides support for all other targets. | ||
|
||
Have a look at the `example/` directory for the rendering of a basic triangle. | ||
|
||
## Getting the wgpu-native libraries | ||
|
||
For native support (not the browser), some libraries are required. Fortunately this is | ||
extremely easy, just download them from the [releases on GitHub](https://github.com/gfx-rs/wgpu-native/releases/tag/v0.19.4.1), | ||
the bindings are for v0.19.4.1 at the moment. | ||
|
||
These are expected in the `lib` folder under the same name as they are released (just unzipped). | ||
By default it will look for a static release version (`wgpu-OS-ARCH-release.a|lib`), | ||
you can set `-define:WGPU_DEBUG=true` for it to look for a debug version, | ||
and use `-define:WGPU_SHARED=true` to look for the shared libraries. | ||
|
||
## WASM | ||
|
||
For WASM, the module has to be built with a function table to enable callbacks. | ||
You can do so using `-extra-linker-flags:"--export-table"`. | ||
|
||
Being able to allocate is also required (for some auxiliary APIs but also for mapping/unmapping buffers). | ||
|
||
You can set the context that is used for allocations by setting the global variable `wpgu.g_context`. | ||
It will default to the `runtime.default_context`. | ||
|
||
Again, have a look at the `example/` and how it is set up, doing the `--import-memory` and the likes | ||
is not strictly necessary but allows your app more memory than the minimal default. | ||
|
||
The bindings work on both `-target:js_wasm32` and `-target:js_wasm64p32`. | ||
|
||
## GLFW Glue | ||
|
||
There is an inner package `glfwglue` that can be used to glue together WGPU and GLFW. | ||
It exports one procedure `GetSurface(wgpu.Instance, glfw.WindowHandle) -> glfw.Surface`. | ||
The procedure will call the needed target specific procedures and return a surface configured | ||
for the given window. | ||
|
||
To support Wayland on Linux, you need to have GLFW compiled to support it, and use | ||
`-define:WGPU_GFLW_GLUE_SUPPORT_WAYLAND=true` to enable the package to check for Wayland. | ||
|
||
Do note that wgpu does not require GLFW, you can use native windows or another windowing library too. | ||
For that you can take inspiration from `glfwglue` on glueing them together. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FILES := $(wildcard *) | ||
|
||
# NOTE: changing this requires changing the same values in the `web/index.html`. | ||
INITIAL_MEMORY_PAGES := 2000 | ||
MAX_MEMORY_PAGES := 65536 | ||
|
||
PAGE_SIZE := 65536 | ||
INITIAL_MEMORY_BYTES := $(shell expr $(INITIAL_MEMORY_PAGES) \* $(PAGE_SIZE)) | ||
MAX_MEMORY_BYTES := $(shell expr $(MAX_MEMORY_PAGES) \* $(PAGE_SIZE)) | ||
|
||
web/triangle.wasm: $(FILES) ../wgpu.js ../../wasm/js/runtime.js | ||
odin build . \ | ||
-target:js_wasm32 -out:web/triangle.wasm -o:size \ | ||
-extra-linker-flags:"--export-table --import-memory --initial-memory=$(INITIAL_MEMORY_BYTES) --max-memory=$(MAX_MEMORY_BYTES)" | ||
|
||
cp ../wgpu.js web/wgpu.js | ||
cp ../../wasm/js/runtime.js web/runtime.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
REM NOTE: changing this requires changing the same values in the `web/index.html`. | ||
set INITIAL_MEMORY_PAGES=2000 | ||
set MAX_MEMORY_PAGES=65536 | ||
|
||
set PAGE_SIZE=65536 | ||
set /a INITIAL_MEMORY_BYTES=%INITIAL_MEMORY_PAGES% * %PAGE_SIZE% | ||
set /a MAX_MEMORY_BYTES=%MAX_MEMORY_PAGES% * %PAGE_SIZE% | ||
|
||
call odin.exe build . -target:js_wasm32 -out:web/triangle.wasm -o:size -extra-linker-flags:"--export-table --import-memory --initial-memory=%INITIAL_MEMORY_BYTES% --max-memory=%MAX_MEMORY_BYTES%" | ||
|
||
copy "..\wgpu.js" "web\wgpu.js" | ||
copy "..\..\wasm\js\runtime.js" "web\runtime.js" |
Oops, something went wrong.