Skip to content

Commit

Permalink
Build SwiftShader Separately (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
McCallisterRomer authored Jun 2, 2024
1 parent 9b2c7a4 commit a874f75
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 54 deletions.
75 changes: 43 additions & 32 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ on:
workflow_dispatch:

jobs:
build:
build-swiftshader:
strategy:
matrix:
os: [windows-2022, ubuntu-20.04, macOS-12]
sdkTag: ['vulkan-sdk-1.3.283.0', 'vulkan-sdk-1.3.280.0', 'vulkan-sdk-1.3.275.0', 'sdk-1.3.261.1']
include:
- os: windows-2022
swiftshaderLibName: vk_swiftshader.dll
Expand All @@ -17,14 +16,52 @@ jobs:
- os: macOS-12
swiftshaderLibName: libvk_swiftshader.dylib

name: 'build ${{ matrix.os }} | ${{ matrix.sdkTag }}'
name: 'swiftshader-${{ matrix.os }}'
runs-on: ${{ matrix.os }}

steps:
- name: Print Inputs
- name: Checkout Swiftshader
uses: actions/checkout@v4
with:
repository: NcStudios/swiftshader
ref: 'release'
path: 'Swiftshader'
submodules: 'recursive'

- name: Build Swiftshader
shell: bash
run: echo "Requested VulkanSDK ${{ matrix.sdkTag }}"
run: |
cmake -S Swiftshader -B Swiftshader/build_out -DCMAKE_BUILD_TYPE=Release
cmake --build Swiftshader/build_out --target vk_swiftshader --config Release --parallel 4
if [[ "${{ runner.os }}" == "Windows" ]]; then
OUT_DIR=Windows
elif [[ "${{ runner.os }}" == "Linux" ]]; then
OUT_DIR=Linux
elif [[ "${{ runner.os }}" == "macOS" ]]; then
OUT_DIR=Darwin
fi
mkdir swiftshader_artifacts
cp Swiftshader/build_out/$OUT_DIR/${{ matrix.swiftshaderLibName }} swiftshader_artifacts
cp Swiftshader/LICENSE.txt swiftshader_artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: swiftshader-${{ matrix.os }}-x64
path: swiftshader_artifacts

build-sdk:
strategy:
matrix:
os: [windows-2022, ubuntu-20.04, macOS-12]
sdkTag: ['vulkan-sdk-1.3.283.0', 'vulkan-sdk-1.3.280.0', 'vulkan-sdk-1.3.275.0', 'sdk-1.3.261.1']

name: '${{ matrix.sdkTag }}-${{ matrix.os }}'
runs-on: ${{ matrix.os }}

steps:
- name: Set up MSVC
if: ${{ runner.os == 'Windows' }}
uses: ilammy/msvc-dev-cmd@v1
Expand All @@ -39,7 +76,7 @@ jobs:
shell: bash
run: |
SDK_VERSION=$(echo "${{ matrix.sdkTag }}" | sed -E 's/[^0-9]*([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?).*/\1/')
echo "ARTIFACT_NAME=vulkanCI-$SDK_VERSION-${{ matrix.os }}-x64" >> $GITHUB_ENV
echo "ARTIFACT_NAME=vulkanSDK-$SDK_VERSION-${{ matrix.os }}-x64" >> $GITHUB_ENV
ROOT_PATH='${{ github.workspace }}'
echo "SDK_PATH=${ROOT_PATH//\\//}/VulkanSDK/$SDK_VERSION" >> $GITHUB_ENV
Expand Down Expand Up @@ -86,32 +123,6 @@ jobs:
cmake --install Vulkan-ValidationLayers/build --prefix ${{ env.SDK_PATH }}
cp Vulkan-ValidationLayers/LICENSE.txt ${{ env.SDK_PATH }}
- name: Checkout Swiftshader
uses: actions/checkout@v4
with:
repository: NcStudios/swiftshader
ref: 'release'
path: 'Swiftshader'
submodules: 'recursive'

- name: Build Swiftshader
shell: bash
run: |
cmake -S Swiftshader -B Swiftshader/build_out -DCMAKE_BUILD_TYPE=Release
cmake --build Swiftshader/build_out --target vk_swiftshader --config Release --parallel 4
if [[ "${{ runner.os }}" == "Windows" ]]; then
OUT_DIR=Windows
elif [[ "${{ runner.os }}" == "Linux" ]]; then
OUT_DIR=Linux
elif [[ "${{ runner.os }}" == "macOS" ]]; then
OUT_DIR=Darwin
fi
mkdir ${{ env.SDK_PATH }}/swiftshader
cp Swiftshader/build_out/$OUT_DIR/${{ matrix.swiftshaderLibName }} ${{ env.SDK_PATH }}/swiftshader
cp Swiftshader/LICENSE.txt ${{ env.SDK_PATH }}/swiftshader
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
mkdir -p artifacts
ARTIFACTS=$(curl -s \
"https://api.github.com/repos/NcStudios/VulkanCI/actions/runs/${{ env.LATEST_RUN_ID }}/artifacts" \
| jq -c '.artifacts[] | select(.name | startswith("vulkanCI-")) | {id: .id, name: .name}')
| jq -c '.artifacts[] | {id: .id, name: .name}')
for ARTIFACT in $(echo "$ARTIFACTS" | jq -c '.'); do
ID=$(echo $ARTIFACT | jq -r '.id')
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![test](https://github.com/NcStudios/VulkanCI/actions/workflows/test.yml/badge.svg)](https://github.com/NcStudios/VulkanCI/actions/workflows/test.yml)

This action enables running Vulkan applications on GitHub-hosted runners. It downloads a pre-built package containing the Vulkan headers, loader, and validation layers as well as [SwiftShader](https://github.com/google/swiftshader) (a software-only Vulkan implementation), and sets up the GitHub environment with the necessary variables. Currently, the environment setup is intended to be minimal, so additional VulkanSDK components are not provided.
This action performs minimal setup to enable building and running Vulkan applications on GitHub-hosted runners. It installs the Vulkan headers, loader, and validation layers, as well as [SwiftShader](https://github.com/google/swiftshader) (a software-only Vulkan implementation), and sets up the GitHub environment with the necessary variables.

## Usage
```yaml
Expand All @@ -19,7 +19,7 @@ This action enables running Vulkan applications on GitHub-hosted runners. It dow
```
## Outputs
- `vulkan-sdk-install-path` Path where the VulkanSDK was installed
- `vulkan-install-path` Path where the VulkanSDK was installed
- `swiftshader-install-path` Path where SwiftShader was installed

Variables can be accessed through the step outputs: `${{ steps.<id>.outputs.swiftshader-install-path }}`.
Expand Down Expand Up @@ -53,4 +53,8 @@ The intention is to support all standard GitHub-hosted runners. Tests currently
- `macOS-14`

## Known Limitations
Due to significant build times, pre-built artifacts are downloaded from the corresponding release of this action. This requires the action version to be specified as a tag - targeting a SHA will not work.

The Vulkan loader is built with `LOADER_USE_UNSAFE_FILE_SEARCH=ON` to more reliably allow file discovery through environment variables. To state the obvious, the artifacts provided here are not intended for use outside of testing environments.

Currently, all macOS binaries are built for x86_64.
52 changes: 33 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ runs:
ACTION_TAG: ${{ github.action_ref }}
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "vk-ci-artifact-name=vulkanCI-${{ inputs.sdkVersion }}-windows-2022-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-sdk-artifact-name=vulkanSDK-${{ inputs.sdkVersion }}-windows-2022-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-artifact-name=swiftshader-windows-2022-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-lib-name=vk_swiftshader.dll" >> "$GITHUB_OUTPUT"
elif [[ "${{ runner.os }}" == "Linux" ]]; then
echo "vk-ci-artifact-name=vulkanCI-${{ inputs.sdkVersion }}-ubuntu-20.04-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-sdk-artifact-name=vulkanSDK-${{ inputs.sdkVersion }}-ubuntu-20.04-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-artifact-name=swiftshader-ubuntu-20.04-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-lib-name=libvk_swiftshader.so" >> "$GITHUB_OUTPUT"
elif [[ "${{ runner.os }}" == "macOS" ]]; then
echo "vk-ci-artifact-name=vulkanCI-${{ inputs.sdkVersion }}-macOS-12-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-sdk-artifact-name=vulkanSDK-${{ inputs.sdkVersion }}-macOS-12-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-artifact-name=swiftshader-macOS-12-x64.zip" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-lib-name=libvk_swiftshader.dylib" >> "$GITHUB_OUTPUT"
else
echo "Unsupported OS: ${{ runner.os }}"
Expand All @@ -47,50 +50,61 @@ runs:
echo "vk-ci-action-tag=$ACTION_TAG" >> "$GITHUB_OUTPUT"
fi
- name: Download Artifacts
- name: Download VulkanSDK Artifact
uses: robinraju/release-downloader@v1.10
with:
repository: 'NcStudios/VulkanCI'
tag: '${{ steps.artifacts.outputs.vk-ci-action-tag }}'
filename: '${{ steps.artifacts.outputs.vk-ci-artifact-name}}'
out-file-path: 'VulkanSDK'
filename: '${{ steps.artifacts.outputs.vk-ci-sdk-artifact-name}}'
out-file-path: '${{ inputs.installPath }}/VulkanSDK'
extract: true

- name: Download Swiftshader Artifact
uses: robinraju/release-downloader@v1.10
with:
repository: 'NcStudios/VulkanCI'
tag: '${{ steps.artifacts.outputs.vk-ci-action-tag }}'
filename: '${{ steps.artifacts.outputs.vk-ci-swiftshader-artifact-name}}'
out-file-path: '${{ inputs.installPath }}/swiftshader'
extract: true

- name: Setup Environment
id: setup-environment
shell: bash
run: |
INSTALL_PATH="${{ inputs.installPath }}/VulkanSDK/${{ inputs.sdkVersion }}"
INSTALL_PATH="${{ inputs.installPath }}"
INSTALL_PATH="${INSTALL_PATH//\\//}"
SDK_INSTALL_PATH="$INSTALL_PATH/VulkanSDK/${{ inputs.sdkVersion }}"
SWIFTSHADER_INSTALL_PATH="$INSTALL_PATH/swiftshader"
echo "VULKAN_SDK=$INSTALL_PATH" >> "$GITHUB_ENV"
echo "VULKAN_SDK=$SDK_INSTALL_PATH" >> "$GITHUB_ENV"
echo "VULKAN_SDK_VERSION=${{ inputs.sdkVersion }}" >> "$GITHUB_ENV"
cat <<EOF > "$INSTALL_PATH/swiftshader/vk_swiftshader_icd.json"
cat <<EOF > "$SWIFTSHADER_INSTALL_PATH/vk_swiftshader_icd.json"
{
"file_format_version": "1.0.0",
"ICD": {
"library_path": "$INSTALL_PATH/swiftshader/${{ steps.artifacts.outputs.vk-ci-swiftshader-lib-name }}",
"library_path": "$SWIFTSHADER_INSTALL_PATH/${{ steps.artifacts.outputs.vk-ci-swiftshader-lib-name }}",
"api_version": "1.0.5"
}
}
EOF
echo "VK_DRIVER_FILES=$INSTALL_PATH/swiftshader/vk_swiftshader_icd.json" >> "$GITHUB_ENV"
echo "VK_DRIVER_FILES=$SWIFTSHADER_INSTALL_PATH/vk_swiftshader_icd.json" >> "$GITHUB_ENV"
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "VK_LAYER_PATH=$INSTALL_PATH/bin" >> "$GITHUB_ENV"
echo "$INSTALL_PATH/bin" >> "$GITHUB_PATH"
echo "VK_LAYER_PATH=$SDK_INSTALL_PATH/bin" >> "$GITHUB_ENV"
echo "$SDK_INSTALL_PATH/bin" >> "$GITHUB_PATH"
elif [[ "${{ runner.os }}" == "Linux" ]]; then
echo "VK_LAYER_PATH=$INSTALL_PATH/share/vulkan/explicit_layer.d" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INSTALL_PATH/lib:$INSTALL_PATH/swiftshader" >> "$GITHUB_ENV"
echo "VK_LAYER_PATH=$SDK_INSTALL_PATH/share/vulkan/explicit_layer.d" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SDK_INSTALL_PATH/lib:$SWIFTSHADER_INSTALL_PATH" >> "$GITHUB_ENV"
elif [[ "${{ runner.os }}" == "macOS" ]]; then
echo "VK_LAYER_PATH=$INSTALL_PATH/share/vulkan/explicit_layer.d" >> "$GITHUB_ENV"
echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$INSTALL_PATH/lib:$INSTALL_PATH/swiftshader" >> "$GITHUB_ENV"
echo "VK_LAYER_PATH=$SDK_INSTALL_PATH/share/vulkan/explicit_layer.d" >> "$GITHUB_ENV"
echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$SDK_INSTALL_PATH/lib:$SWIFTSHADER_INSTALL_PATH" >> "$GITHUB_ENV"
else
echo "Unsupported OS: ${{ runner.os }}"
exit 1
fi
echo "vk-ci-vulkan-install-path=$INSTALL_PATH" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-install-path=$INSTALL_PATH/swiftshader" >> "$GITHUB_OUTPUT"
echo "vk-ci-vulkan-install-path=$SDK_INSTALL_PATH" >> "$GITHUB_OUTPUT"
echo "vk-ci-swiftshader-install-path=$SWIFTSHADER_INSTALL_PATH" >> "$GITHUB_OUTPUT"

0 comments on commit a874f75

Please sign in to comment.