From 8d657765940de50a9435806d1629bf93aec6043f Mon Sep 17 00:00:00 2001 From: Dmitry Zolotukhin Date: Tue, 23 Jan 2024 20:49:17 +0100 Subject: [PATCH] Compile shaders, updated Github actions. * GLSL shaders into SPIR-V * metal into metallib Created empty shaders to make the pipeline work. Rearranged shaders dir. --- .github/workflows/cargo-build.yml | 66 +++++++++++++++++++++--------- src/correlation.rs | 4 +- src/shaders/correlation.comp.glsl | 5 +++ src/shaders/correlation.metal | 3 ++ src/{ => shaders}/correlation.wgsl | 0 5 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/shaders/correlation.comp.glsl create mode 100644 src/shaders/correlation.metal rename src/{ => shaders}/correlation.wgsl (100%) diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml index fb81b02..69fe637 100644 --- a/.github/workflows/cargo-build.yml +++ b/.github/workflows/cargo-build.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get current Rust version id: get-rust-version @@ -20,25 +20,30 @@ jobs: - 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 @@ -52,7 +57,7 @@ jobs: os: ubuntu steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get current Rust version id: get-rust-version @@ -60,7 +65,7 @@ jobs: - name: Cache Rust dependencies and artifacts id: cache-rust - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry/index @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 @@ -148,7 +163,7 @@ jobs: arch: [aarch64, x86_64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get current Rust version id: get-rust-version @@ -156,7 +171,7 @@ jobs: - name: Cache Rust dependencies and artifacts id: cache-rust - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry/index @@ -169,6 +184,19 @@ 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 @@ -176,7 +204,7 @@ jobs: 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 diff --git a/src/correlation.rs b/src/correlation.rs index 864a3df..9cf794e 100644 --- a/src/correlation.rs +++ b/src/correlation.rs @@ -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. diff --git a/src/shaders/correlation.comp.glsl b/src/shaders/correlation.comp.glsl new file mode 100644 index 0000000..06f3ba6 --- /dev/null +++ b/src/shaders/correlation.comp.glsl @@ -0,0 +1,5 @@ +#version 450 +#pragma shader_stage(compute) + +void main() { +} diff --git a/src/shaders/correlation.metal b/src/shaders/correlation.metal new file mode 100644 index 0000000..5f61074 --- /dev/null +++ b/src/shaders/correlation.metal @@ -0,0 +1,3 @@ +kernel void add_arrays(uint index [[thread_position_in_grid]]) +{ +} diff --git a/src/correlation.wgsl b/src/shaders/correlation.wgsl similarity index 100% rename from src/correlation.wgsl rename to src/shaders/correlation.wgsl