Skip to content

Commit

Permalink
Compile shaders, updated Github actions.
Browse files Browse the repository at this point in the history
* GLSL shaders into SPIR-V
* metal into metallib

Created empty shaders to make the pipeline work.
Rearranged shaders dir.
Ensure that build fails if validation doesn't pass checks.
  • Loading branch information
zlogic committed Jan 23, 2024
1 parent e47ea54 commit 59a894f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 21 deletions.
70 changes: 50 additions & 20 deletions .github/workflows/cargo-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,42 @@ jobs:
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current Rust version
id: get-rust-version
run: echo VERSION=$(rustc --version | sed s/\ /_/g) >> "$GITHUB_OUTPUT"

- name: Cache Rust dependencies and artifacts
id: cache-rust
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
~/.cargo/bin/naga
${{ github.workspace }}/target
key: lint-${{ runner.os }}-${{ steps.get-rust-version.outputs.VERSION }}-${{ hashFiles('Cargo.lock') }}

- name: Install naga
if: steps.cache-rust.outputs.cache-hit != 'true'
run: cargo install naga-cli
- name: Install glslang
run: sudo apt install glslang-tools

- name: Build SPIR-V shaders with glslang
run: glslangValidator -V -g0 src/shaders/correlation.comp.glsl -o src/shaders/correlation.spv

- name: Validate shaders with naga
run: naga src/correlation.wgsl
- name: Validate Rust code with clippy
run: cargo clippy

- name: Upload SPIR-V shaders
uses: actions/upload-artifact@v4
with:
name: shaders-spv
path: src/shaders/correlation.spv

build-linux:
# Older Ubuntu versions will link with an older GLIBC and provide better compatibility
runs-on: ubuntu-20.04
needs: validate
strategy:
fail-fast: true
matrix:
Expand All @@ -52,15 +58,15 @@ jobs:
os: ubuntu

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current Rust version
id: get-rust-version
run: echo VERSION=$(rustc --version | sed s/\ /_/g) >> "$GITHUB_OUTPUT"

- name: Cache Rust dependencies and artifacts
id: cache-rust
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
Expand All @@ -82,28 +88,33 @@ jobs:
echo "CFLAGS=-march=armv8.2-a" >> $GITHUB_ENV
echo "CXXFLAGS=-march=armv8.2-a" >> $GITHUB_ENV
- name: Download SPIR-V shaders
uses: actions/download-artifact@v4
with:
name: shaders-spv

- name: Build
run: cargo build --target=${{ matrix.arch }}-unknown-linux-gnu --release

- name: Package application
run: tar -cvjf cybervision-${{ matrix.os }}-${{ matrix.arch }}.tar.bz2 -C target/${{ matrix.arch }}-unknown-linux-gnu/release cybervision

- name: Upload application
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: cybervision-${{ matrix.os }}-${{ matrix.arch }}
path: cybervision-*.tar.bz2

build-windows:
runs-on: windows-latest

needs: validate
strategy:
fail-fast: true
matrix:
arch: [aarch64, x86_64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current Rust version
id: get-rust-version
Expand All @@ -113,7 +124,7 @@ jobs:
- name: Cache Rust dependencies and artifacts
id: cache-rust
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~\.cargo\registry\index
Expand All @@ -126,6 +137,11 @@ jobs:
if: matrix.arch == 'aarch64'
run: rustup target add ${{ matrix.arch }}-pc-windows-msvc

- name: Download SPIR-V shaders
uses: actions/download-artifact@v4
with:
name: shaders-spv

- name: Build
run: |
$Env:RUSTFLAGS = "-C target-feature=+crt-static"
Expand All @@ -135,28 +151,29 @@ jobs:
run: Compress-Archive -Path .\target\${{ matrix.arch }}-pc-windows-msvc\release\cybervision.exe -DestinationPath cybervision-${{ runner.os }}-${{ matrix.arch }}.zip

- name: Upload application
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: cybervision-${{ runner.os }}-${{ matrix.arch }}
path: cybervision-*.zip

build-macos:
runs-on: macos-latest
needs: validate
strategy:
fail-fast: true
matrix:
arch: [aarch64, x86_64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get current Rust version
id: get-rust-version
run: echo VERSION=$(rustc --version | sed s/\ /_/g) >> "$GITHUB_OUTPUT"

- name: Cache Rust dependencies and artifacts
id: cache-rust
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
Expand All @@ -169,14 +186,27 @@ jobs:
if: matrix.arch == 'aarch64'
run: rustup target add ${{ matrix.arch }}-apple-darwin

- name: Cache shaders
id: cache-shaders
uses: actions/cache@v4
with:
path: src/shaders/correlation.metallib
key: shaders-${{ runner.os }}-${{matrix.arch}}-${{ hashFiles('src/shaders/correlation.metal') }}

- name: Compile shaders
if: steps.cache-shaders.outputs.cache-hit != 'true'
run: |
xcrun -sdk macosx metal -c src/shaders/correlation.metal -o src/shaders/correlation.air
xcrun -sdk macosx metallib -c src/shaders/correlation.air -o src/shaders/correlation.metallib
- name: Build
run: cargo build --target=${{ matrix.arch }}-apple-darwin --release

- name: Package application
run: tar -cvjf cybervision-${{ runner.os }}-${{ matrix.arch }}.tar.bz2 -C target/${{ matrix.arch }}-apple-darwin/release cybervision

- name: Upload application
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: cybervision-${{ runner.os }}-${{ matrix.arch }}
path: cybervision-*.tar.bz2
4 changes: 3 additions & 1 deletion src/correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,9 @@ mod gpu {

let shader_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("correlation.wgsl"))),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!(
"shaders/correlation.wgsl"
))),
});

// Init buffers.
Expand Down
5 changes: 5 additions & 0 deletions src/shaders/correlation.comp.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#version 450
#pragma shader_stage(compute)

void main() {
}
3 changes: 3 additions & 0 deletions src/shaders/correlation.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kernel void add_arrays(uint index [[thread_position_in_grid]])
{
}
File renamed without changes.

0 comments on commit 59a894f

Please sign in to comment.