Skip to content

Commit

Permalink
Compile shaders
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.
  • Loading branch information
zlogic committed Jan 23, 2024
1 parent e47ea54 commit dabecf1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
66 changes: 47 additions & 19 deletions .github/workflows/cargo-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,38 @@ 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: glslang -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
Expand All @@ -52,15 +57,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,14 +87,19 @@ 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
Expand All @@ -103,7 +113,7 @@ jobs:
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 +123,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 +136,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,7 +150,7 @@ 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
Expand All @@ -148,15 +163,15 @@ jobs:
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 +184,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 dabecf1

Please sign in to comment.