all: move standalone libraries to libs/ subdirectory

The root dir of our repository has grown quite a lot the past few months.

I'd like to make it more clear where the bulk of the engine lives (`src/`) and
also make it more clear which Mach libraries are consumable as standalone projects.

As for the name of this directory, `libs` was my first choice but there's a bit of
a convention of that being external libraries in Zig projects _today_, while these
are libraries maintained as part of Mach in this repository - not external ones.

We will name this directory `libs`, and if we have a need for external libraries
we will use `external` or `deps` for that directory name. I considered other names
such as `components`, `systems`, `modules` (which are bad as they overlap with
major ECS / engine concepts), and it seems likely the official Zig package manager
will break the convention of using a `libs` dir anyway.

Performed via:

```sh
mkdir libs/
git mv freetype libs/
git mv basisu libs/
git mv gamemode libs/
git mv glfw libs/
git mv gpu libs/
git mv gpu-dawn libs/
git mv sysaudio libs/
git mv sysjs libs/
git mv ecs libs/
```

git-subtree-dir: glfw
git-subtree-mainline: 0d5b853443
git-subtree-split: 572d1144f11b353abdb64fff828b25a4f0fbb7ca

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>

git mv ecs libs/

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-26 13:29:04 -07:00 committed by Stephen Gutekanst
parent 79ec61396f
commit 0645429df9
240 changed files with 6 additions and 6 deletions

2
libs/gpu-dawn/.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
* text=auto eol=lf
upstream/** linguist-vendored

1
libs/gpu-dawn/.github/FUNDING.yml vendored Normal file
View file

@ -0,0 +1 @@
github: slimsag

View file

@ -0,0 +1,5 @@
Please send your change to [the main repository](https://github.com/hexops/mach/tree/main/gpu-dawn) instead, sorry for the trouble!
This helps us avoid some complex merge conflicts we run into when changes are made to both repositories and history needs to be reconciled. Keeping PRs in just that repository enables us to use `git subtree` to trivially keep the two repositories in sync.
Once your PR is merged over there, it'll automatically sync to this repository.

195
libs/gpu-dawn/.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,195 @@
name: CI
on:
workflow_run:
workflows: ["Draft release"]
types:
- completed
jobs:
x86_64-linux-gnu_debug:
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (debug)
run: zig build install -Ddawn-from-source=true -Dtarget=x86_64-linux-gnu
- name: upload (debug)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: x86_64-linux-gnu_debug
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-linux-gnu_release-fast:
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (release-fast)
run: zig build install -Ddawn-from-source=true -Drelease-fast=true -Dtarget=x86_64-linux-gnu
- name: upload (release-fast)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: x86_64-linux-gnu_release-fast
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-linux-musl_debug:
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (debug)
run: zig build install -Ddawn-from-source=true -Dtarget=x86_64-linux-musl
- name: upload (debug)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: x86_64-linux-musl_debug
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-linux-musl_release-fast:
runs-on: ubuntu-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (release-fast)
run: zig build install -Ddawn-from-source=true -Drelease-fast=true -Dtarget=x86_64-linux-musl
- name: upload (release-fast)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: x86_64-linux-musl_release-fast
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-windows-gnu_debug:
runs-on: windows-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Git
run: choco install git
- name: Setup Zig
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://ziglang.org/builds/zig-windows-x86_64-0.10.0-dev.3551+92568a009.zip" -OutFile "C:\zig.zip"
cd C:\
7z x zig.zip
Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.10.0-dev.3551+92568a009\"
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (debug)
run: zig build install -Ddawn-from-source=true -Dtarget=x86_64-windows-gnu
- name: upload (debug)
run: ./dev/upload-release.sh
shell: bash
env:
WINDOWS: true
RELEASE_NAME: x86_64-windows-gnu_debug
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-windows-gnu_release-fast:
runs-on: windows-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Git
run: choco install git
- name: Setup Zig
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://ziglang.org/builds/zig-windows-x86_64-0.10.0-dev.3551+92568a009.zip" -OutFile "C:\zig.zip"
cd C:\
7z x zig.zip
Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.10.0-dev.3551+92568a009\"
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (release-fast)
run: zig build install -Ddawn-from-source=true -Dtarget=x86_64-windows-gnu -Drelease-fast=true
- name: upload (release-fast)
run: ./dev/upload-release.sh
shell: bash
env:
WINDOWS: true
RELEASE_NAME: x86_64-windows-gnu_release-fast
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-macos_debug:
runs-on: macos-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
brew uninstall --ignore-dependencies libx11 # https://github.com/ziglang/zig/issues/11066
brew install xz
sudo sh -c 'wget -c https://ziglang.org/builds/zig-macos-x86_64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (debug)
run: zig build install -Ddawn-from-source=true -Dtarget=x86_64-macos.12-none
env:
AGREE: true
- name: upload (debug)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: x86_64-macos-none_debug
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
x86_64-macos_release-fast:
runs-on: macos-latest
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event.workflow_run.conclusion == 'success' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
brew uninstall --ignore-dependencies libx11 # https://github.com/ziglang/zig/issues/11066
brew install xz
sudo sh -c 'wget -c https://ziglang.org/builds/zig-macos-x86_64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (release-fast)
run: zig build install -Ddawn-from-source=true -Drelease-fast=true -Dtarget=x86_64-macos.12-none
env:
AGREE: true
- name: upload (release-fast)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: x86_64-macos-none_release-fast
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -0,0 +1,16 @@
name: Draft release
on:
push:
branches:
- 'main'
jobs:
draft:
if: ${{ !contains(github.event.head_commit.message, 'update to latest binary release') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Create draft
run: gh release create "release-$(git rev-parse --short HEAD)" --title "Automatic release of main @ $(git rev-parse --short HEAD)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -0,0 +1,45 @@
name: M1
on:
workflow_run:
workflows: ["Draft release"]
types:
- completed
jobs:
aarch64-macos:
if: ${{ github.repository == 'hexops/mach-gpu-dawn' && github.event.workflow_run.conclusion == 'success' }}
runs-on: [self-hosted, macOS, ARM64]
defaults:
run:
shell: "/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}"
steps:
- name: Clean repository submodules
# See https://github.com/actions/checkout/issues/385
run: |
rm -rf $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo rm -rf /usr/local/bin/zig /usr/local/bin/lib/
sudo sh -c 'wget -c https://ziglang.org/builds/zig-macos-aarch64-0.10.0-dev.3551+92568a009.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Clone mach-glfw
run: rm libs/mach-glfw && git clone https://github.com/hexops/mach-glfw libs/mach-glfw
- name: install (debug)
run: zig build install -Ddawn-from-source=true -Dtarget=aarch64-macos.12-none
env:
AGREE: true
- name: upload (debug)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: aarch64-macos-none_debug
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: install (release-fast)
run: zig build install -Ddawn-from-source=true -Drelease-fast=true -Dtarget=aarch64-macos.12-none
env:
AGREE: true
- name: upload (release-fast)
run: ./dev/upload-release.sh
env:
RELEASE_NAME: aarch64-macos-none_release-fast
UPLOAD_HEADERS: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -0,0 +1,45 @@
name: Publish release
on:
workflow_run:
workflows: ["CI"]
types:
- completed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Record latest release version
id: recorded_release_version
# Note: we find the latest non-'update to latest binary release' commit here, which is not
# necessarily HEAD because another build could have succeeded before us and HEAD may now refer
# to 'update to latest binary release' instead of the commit we were building.
# By doing this, we ensure any update we push would refer to the absolute latest binary
# release even if *this* CI run is older.
run: echo "::set-output name=commit::$(git log --oneline | grep -v 'update to latest binary release' | head -n1 | cut -d " " -f1)"
# - name: Publish release
# run: echo "TODO(build-system): gh CLI has no way to mark draft as published?"
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout hexops/mach monorepo
uses: actions/checkout@v2
with:
repository: hexops/mach
token: ${{ secrets.HEXOPS_MACH_GPU_DAWN_PUSH }}
- name: 'gpu/dawn: update hard-coded binary release version'
env:
RELEASE_COMMIT: ${{steps.recorded_release_version.outputs.commit}}
run: |
sed -i "/binary_version: \[\]const u8 =/c\ binary_version: []const u8 = \"release-$RELEASE_COMMIT\"," ./gpu-dawn/build.zig
- name: 'gpu/dawn: use latest binary release'
run: |
git config user.name 'Release automation'
git config user.email 'stephen@hexops.com'
git add .
git commit -m 'gpu-dawn: update to latest binary release'
git push -u origin HEAD

18
libs/gpu-dawn/.gitignore vendored Normal file
View file

@ -0,0 +1,18 @@
# This file is for zig-specific build artifacts.
# If you have OS-specific or editor-specific files to ignore,
# such as *.swp or .DS_Store, put those in your global
# ~/.gitignore and put this in your ~/.gitconfig:
#
# [core]
# excludesfile = ~/.gitignore
#
# Cheers!
# -andrewrk
zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/

10
libs/gpu-dawn/.gitmodules vendored Normal file
View file

@ -0,0 +1,10 @@
[submodule "libs/dawn"]
path = libs/dawn
url = https://github.com/hexops/dawn.git
shallow = true
branch = "generated-2022-08-06"
[submodule "libs/DirectXShaderCompiler"]
path = libs/DirectXShaderCompiler
url = https://github.com/hexops/DirectXShaderCompiler
shallow = true
branch = "mach"

13
libs/gpu-dawn/LICENSE Normal file
View file

@ -0,0 +1,13 @@
Copyright 2021, Hexops Contributors (given via the Git commit history).
All documentation, image, sound, font, and 2D/3D model files are CC-BY-4.0 licensed unless
otherwise noted. You may get a copy of this license at https://creativecommons.org/licenses/by/4.0
Files in a directory with a separate LICENSE file may contain files under different license terms,
described within that LICENSE file.
All other files are licensed under the Apache License, Version 2.0 (see LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
or the MIT license (see LICENSE-MIT or http://opensource.org/licenses/MIT), at your option.
All files in the project without exclusions may not be copied, modified, or distributed except
according to the terms above.

View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
libs/gpu-dawn/LICENSE-MIT Normal file
View file

@ -0,0 +1,25 @@
Copyright (c) 2021 Hexops Contributors (given via the Git commit history).
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

85
libs/gpu-dawn/README.md Normal file
View file

@ -0,0 +1,85 @@
# mach/gpu-dawn, WebGPU/Dawn built with Zig <a href="https://hexops.com"><img align="right" alt="Hexops logo" src="https://raw.githubusercontent.com/hexops/media/master/readme.svg"></img></a>
`mach/gpu-dawn` builds [Dawn](https://dawn.googlesource.com/dawn/), Google Chrome's WebGPU implementation, requiring nothing more than `zig` and `git` to build and cross-compile a static Dawn library for every OS:
* No cmake
* No ninja
* No `gn`
* No system dependencies (xcode, etc.)
* Automagic cross compilation out of the box with nothing more than `zig` and `git`!
* Builds a single static `libdawn.a` with everything you need.
This repository is a separate copy of the same library in the [main Mach repository](https://github.com/hexops/mach), and is automatically kept in sync, so that anyone can use this library in their own project / engine if they like!
## Building from source
Building Dawn from source using this method is simple:
```sh
git clone https://github.com/hexops/mach-gpu-dawn
cd mach-gpu-dawn
rm -rf libs/mach-glfw
git clone https://github.com/hexops/mach-glfw libs/mach-glfw
zig build -Ddawn-from-source=true
```
(Please make sure to use Zig nightly, e.g. v0.10, not v0.9, which you can get a binary release of at the very top of this page: https://ziglang.org/download/)
This will take ~10 minutes to finish (see the 'binary releases' section below.) You can add the following options:
| Option | Description |
|-------------------------------|------------------------------------------------------------|
| `-Drelease-fast=true` | Build a release binary instead of a debug binary (default) |
| `-Dtarget=x86_64-macos.12` | Cross compile to macOS (Intel chipsets) |
| `-Dtarget=aarch64-macos.12` | Cross compile to macOS (Apple Silicon) |
| `-Dtarget=x86_64-linux-gnu` | Cross compile to x86_64 Linux (glibc) |
| `-Dtarget=x86_64-linux-musl` | Cross compile to x86_64 Linux (musl libc) |
| `-Dtarget=x86_64-windows-gnu` | Cross compile to x86_64 Windows |
The following platforms are not yet supported, but we hope to support soon:
* iOS (Dawn does not officially support it yet)
* Android (Dawn does not officially support it yet)
* ARM Linux (aarch64)
* Windows msvc target (Zig targets MinGW libc on Windows currently, msvc support should not be hard to add.)
## Binary releases
Dawn (specifically all the shader compilers, and the DirectXShaderCompiler) is a large C++ codebase and takes 5-10 minutes to build on a modern laptop, you just need to specify `-Ddawn-from-source=true` and wait. Since waiting is no fun, we also have binary releases produced by our GitHub actions:
**[View binary releases](https://github.com/hexops/mach-gpu-dawn/releases/latest)**
Here's how to read the downloads provided:
* `_debug.tar.gz` and `_release-fast.tar.gz` are tarballs of the static library + headers for each OS and debug/release mode, respectively.
* `headers.json.gz` is a JSON archive of all the Dawn/WebGPU headers.
* Files ending in `.a.gz` and `.lib.gz` are the individual static `libdawn.a` and `dawn.lib` (Windows) gzippped and distributed. These are provided as individual downloads so there is no need to extract a tarball.
## A warning about API stability
You should be aware:
* WebGPU's API is not formalized yet.
* Dawn's API is still changing.
* The `webgpu.h` API is still changing
* Dawn and gfx-rs/wgpu, although both try to implement `webgpu.h`, do not exactly implement the same interface. There are subtle differences in device discovery & creation for example.
## Generated code
Dawn itself relies on a fairly large amount of dependencies, generated code, etc. To avoid having any dependency on Google build tools, code generation, etc. we maintain [a minor fork of Dawn which has generated code and third-party dependencies comitted in "generated" branches.](https://github.com/hexops/dawn/tree/main/mach) We are usually up-to-date with the upstream within a few weeks on average.
It also provides a [few small patches to enable building Dawn with the Zig compiler](https://github.com/hexops/mach/issues/168) which we plan to upstream soon, as well as some [patches to build the DirectXShaderCompiler with Zig](https://github.com/hexops/mach/issues/151).
## Join the community
Join the Mach engine community [on Matrix chat](https://matrix.to/#/#hexops:matrix.org) to discuss this project, ask questions, get help, etc.
## Issues
Issues are tracked in the [main Mach repository](https://github.com/hexops/mach/issues?q=is%3Aissue+is%3Aopen+label%3Agpu-dawn).
## License
All Mach code (this repository) is under the Apache and MIT license at your choosing described in the `LICENSE` file. Dawn itself is [similarly permissively licensed](https://github.com/hexops/dawn/blob/main/LICENSE).

29
libs/gpu-dawn/build.zig Normal file
View file

@ -0,0 +1,29 @@
const std = @import("std");
const Builder = std.build.Builder;
const glfw = @import("libs/mach-glfw/build.zig");
const system_sdk = @import("libs/mach-glfw/system_sdk.zig");
const gpu_dawn_sdk = @import("sdk.zig");
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const gpu_dawn = gpu_dawn_sdk.Sdk(.{
.glfw = glfw,
.glfw_include_dir = "libs/mach-glfw/upstream/glfw/include",
.system_sdk = system_sdk,
});
const options = gpu_dawn.Options{
.from_source = b.option(bool, "dawn-from-source", "Build Dawn from source") orelse false,
};
// Just to demonstrate/test linking. This is not a functional example, see the mach/gpu examples
// or Dawn C++ examples for functional example code.
const example = b.addExecutable("dawn-example", "src/main.zig");
example.setBuildMode(mode);
example.setTarget(target);
gpu_dawn.link(b, example, options);
glfw.link(b, example, .{ .system_sdk = .{ .set_sysroot = false } });
example.addPackage(glfw.pkg);
example.install();
}

View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -exuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"/..
rm -rf out/ out.tar.gz headers.json headers.json.gz
# Prepare the `out/` directory that we will bundle.
mkdir out/
cp -R libs/dawn/include out/
cp -R libs/dawn/out/Debug/gen/include/* out/include/
cp libs/dawn/LICENSE out/
zig version > out/ZIG_VERSION
# Bundle headers.json.gz
pushd out
python3 ../dev/dir_to_json.py > ../headers.json
popd
gzip -9 headers.json
# Copy the binary into the out/ directory
if [[ "${WINDOWS:-"false"}" == "true" ]]; then
cp zig-out/lib/dawn.lib out/
else
cp zig-out/lib/libdawn.a out/
fi
# Create out.tar.gz bundle
pushd out
tar -czvf ../out.tar.gz .
popd

View file

@ -0,0 +1,12 @@
import os
import json
def dir_to_dict(d):
dict = {}
for dirpath,_,filenames in os.walk(d):
for f in filenames:
path = os.path.join(dirpath, f)
dict[path] = open(path, 'r').read()
return dict
print(json.dumps(dir_to_dict('.')))

View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -exuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"/..
# Prepare tarball, headers.json.gz, etc.
./dev/bundle-release.sh
if [[ "${UPLOAD_HEADERS:-"false"}" == "true" ]]; then
# Upload headers.json.gz
gh release upload "release-$(git rev-parse --short HEAD)" headers.json.gz
fi
# Upload static library individually.
if [[ "${WINDOWS:-"false"}" == "true" ]]; then
cp zig-out/lib/dawn.lib "dawn_$RELEASE_NAME.lib"
gzip -9 "dawn_$RELEASE_NAME.lib"
gh release upload "release-$(git rev-parse --short HEAD)" "dawn_$RELEASE_NAME.lib.gz"
else
cp zig-out/lib/libdawn.a "libdawn_$RELEASE_NAME.a"
gzip -9 "libdawn_$RELEASE_NAME.a"
gh release upload "release-$(git rev-parse --short HEAD)" "libdawn_$RELEASE_NAME.a.gz"
fi
# Upload tarball of static library + headers.
mv out.tar.gz "$RELEASE_NAME.tar.gz"
gh release upload "release-$(git rev-parse --short HEAD)" "$RELEASE_NAME.tar.gz"

@ -0,0 +1 @@
Subproject commit cff9a6f0b7f961748b822e1d313a7205dfdecf9d

@ -0,0 +1 @@
Subproject commit 0b704c4acae154ec8d4be7615d18a489f270f6c0

View file

@ -0,0 +1 @@
../../glfw

1467
libs/gpu-dawn/sdk.zig Normal file

File diff suppressed because it is too large Load diff

View file

View file

@ -0,0 +1,56 @@
#ifdef __MINGW32__
#include <guiddef.h>
#include <stdint.h>
#define MINGW_UUIDOF(type, spec) \
extern "C++" { \
struct __declspec(uuid(spec)) type; \
template<> const GUID &__mingw_uuidof<type>() { \
static constexpr IID __uuid_inst = guid_from_string(spec); \
return __uuid_inst; \
} \
template<> const GUID &__mingw_uuidof<type*>() { \
return __mingw_uuidof<type>(); \
} \
}
constexpr uint8_t nybble_from_hex(char c) {
return ((c >= '0' && c <= '9')
? (c - '0')
: ((c >= 'a' && c <= 'f')
? (c - 'a' + 10)
: ((c >= 'A' && c <= 'F') ? (c - 'A' + 10)
: /* Should be an error */ -1)));
}
constexpr uint8_t byte_from_hex(char c1, char c2) {
return nybble_from_hex(c1) << 4 | nybble_from_hex(c2);
}
constexpr uint8_t byte_from_hexstr(const char str[2]) {
return nybble_from_hex(str[0]) << 4 | nybble_from_hex(str[1]);
}
constexpr GUID guid_from_string(const char str[37]) {
return GUID{static_cast<uint32_t>(byte_from_hexstr(str)) << 24 |
static_cast<uint32_t>(byte_from_hexstr(str + 2)) << 16 |
static_cast<uint32_t>(byte_from_hexstr(str + 4)) << 8 |
byte_from_hexstr(str + 6),
static_cast<uint16_t>(
static_cast<uint16_t>(byte_from_hexstr(str + 9)) << 8 |
byte_from_hexstr(str + 11)),
static_cast<uint16_t>(
static_cast<uint16_t>(byte_from_hexstr(str + 14)) << 8 |
byte_from_hexstr(str + 16)),
{byte_from_hexstr(str + 19), byte_from_hexstr(str + 21),
byte_from_hexstr(str + 24), byte_from_hexstr(str + 26),
byte_from_hexstr(str + 28), byte_from_hexstr(str + 30),
byte_from_hexstr(str + 32), byte_from_hexstr(str + 34)}};
}
#endif // __MINGW32__
// The point of this helper file is to export the specializations for MINGW_UUIDOF
// below, since MinGW does not have these as part of dxguid yet (not completely up
// to date.)
MINGW_UUIDOF(IDXGraphicsAnalysis, "9f251514-9d4d-4902-9d60-18988ab7d4b5")

View file

@ -0,0 +1 @@
pub fn main() void {}