Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Build and Publish workflows #226

Merged
merged 9 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/build-deploy-latest.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/build-deploy-stable.yml

This file was deleted.

54 changes: 26 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
name: build

on:
workflow_call:
inputs:
artifact-name:
description: "The name of the artifact to create from this build"
required: true
type: string

push:
branches: [main]
paths-ignore:
- "**/*.gitattributes"
- "**/*.gitignore"
- "**/*.md"
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build WebApp
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true
- name: Install Wasm-Pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build Wasm Project
run: |
cd wgpu-testbed-lib
RUSTFLAGS=--cfg=web_sys_unstable_apis wasm-pack build
cd ..
- name: Build Web Project
run: |
cd wgpu-testbed-webapp
yarn install
yarn build
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: wgpu-testbed-webapp/dist
- name: Checkout Code
uses: actions/checkout@v4

- name: Install Wasm-Pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build Wasm Project
run: ./build.ps1
shell: pwsh

- uses: actions/upload-artifact@v4
with:
name: publish-wasm-site
path: wgpu-testbed-webapp/dist
42 changes: 0 additions & 42 deletions .github/workflows/deploy.yml

This file was deleted.

2 changes: 1 addition & 1 deletion wgpu-testbed-webapp/LICENSE-MIT → LICENCE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) [year] [name]
Copyright (c) 2022-2024 Hugo Woodiwiss

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
13 changes: 9 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
cargo build
#! /usr/bin/env pwsh
#Requires -Version 7.0
#Requires -PSEdition Core

cargo clippy -- -D warnings

Push-Location ".\wgpu-testbed-lib"
$env:RUSTFLAGS = "--cfg=web_sys_unstable_apis"
wasm-pack build
wasm-pack build --release
Pop-Location

Push-Location ".\wgpu-testbed-webapp"
Remove-Item "./node_modules" -Recurse -ErrorAction SilentlyContinue
yarn install
yarn build
Remove-Item "./dist" -Recurse -ErrorAction SilentlyContinue
npm i
npm run build
Pop-Location
6 changes: 3 additions & 3 deletions wgpu-testbed-lib/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Camera {
self.z_far,
);

return OPENGL_TO_WGPU_MATRIX * proj * view;
OPENGL_TO_WGPU_MATRIX * proj * view
}
}

Expand Down Expand Up @@ -127,11 +127,11 @@ impl CameraController {
}

if self.up_pressed {
camera.eye = camera.eye + camera.up * self.speed;
camera.eye += camera.up * self.speed;
}

if self.down_pressed {
camera.eye = camera.eye - camera.up * self.speed;
camera.eye -= camera.up * self.speed;
}
}
}
30 changes: 23 additions & 7 deletions wgpu-testbed-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub async fn run() {

body.append_child(&canvas)
.expect("Append canvas to HTML body");

canvas
.set_attribute("style", "width: 100%; aspect-ratio: 16/9;")
.expect("Set canvas style");
}

let mut render_state = State::new(window.clone()).await;
Expand All @@ -71,20 +75,32 @@ pub async fn run() {
window_id,
} if window_id == window.id() && !render_state.input(event) => match event {
WindowEvent::CloseRequested => target.exit(),
WindowEvent::Resized(new_size) => render_state.resize(*new_size),
WindowEvent::Resized(new_size) => {
#[cfg(target_arch = "wasm32")]
{
use winit::platform::web::WindowExtWebSys;

if (new_size.width > 0 && new_size.height > 0) {
let canvas = window.canvas().expect("Could not get canvas reference");
canvas
.set_attribute("style", "width: 100%; aspect-ratio: auto;")
.expect("Set canvas style");
}
}

render_state.resize(*new_size)
}
WindowEvent::ScaleFactorChanged {
scale_factor: _,
inner_size_writer: _,
} => render_state.resize(window.inner_size()),
WindowEvent::KeyboardInput {
event: key_event, ..
} if key_event.state == ElementState::Pressed => {
match key_event.logical_key {
Key::Named(key) => match key {
NamedKey::Escape => target.exit(),
_ => {}
},
_ => {}
if let Key::Named(key) = key_event.logical_key {
if key == NamedKey::Escape {
target.exit()
}
}

render_state.input(event);
Expand Down
38 changes: 27 additions & 11 deletions wgpu-testbed-lib/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ impl Vertex for ModelVertex {
}

pub struct Material {
#[allow(dead_code)]
pub name: String,
pub textures: HashMap<String, Texture>,
pub bind_group: wgpu::BindGroup,
}

pub struct Mesh {
#[allow(dead_code)]
pub name: String,
pub vertex_buffer: wgpu::Buffer,
pub index_buffer: wgpu::Buffer,
Expand Down Expand Up @@ -265,10 +267,15 @@ impl ModelLoader {
let diffuse_texture = Texture::load(
device,
queue,
resource_base.join(diffuse_path.clone()).to_str().expect(
("Could not convert diffuse path to &str: ".to_owned() + &diffuse_path)
.as_str(),
),
resource_base
.join(diffuse_path.clone())
.to_str()
.unwrap_or_else(|| {
panic!(
"{}",
("Could not convert diffuse path to &str: ".to_owned() + &diffuse_path)
)
}),
false,
)
.await?;
Expand All @@ -280,9 +287,15 @@ impl ModelLoader {
let normal_texture = Texture::load(
device,
queue,
resource_base.join(normal_path.clone()).to_str().expect(
("Could not convert normal path to &str: ".to_owned() + &normal_path).as_str(),
),
resource_base
.join(normal_path.clone())
.to_str()
.unwrap_or_else(|| {
panic!(
"{}",
("Could not convert normal path to &str: ".to_owned() + &normal_path)
)
}),
true,
)
.await?;
Expand Down Expand Up @@ -462,6 +475,7 @@ pub trait DrawModel<'a, 'b>
where
'b: 'a,
{
#[allow(dead_code)]
fn draw_mesh(
&mut self,
mesh: &'b Mesh,
Expand All @@ -478,6 +492,7 @@ where
light: &'b wgpu::BindGroup,
);

#[allow(dead_code)]
fn draw_model(
&mut self,
model: &'b Model,
Expand Down Expand Up @@ -507,8 +522,8 @@ where
self.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
self.set_index_buffer(mesh.index_buffer.slice(..), wgpu::IndexFormat::Uint32);
self.set_bind_group(0, &material.bind_group, &[]);
self.set_bind_group(1, &uniforms, &[]);
self.set_bind_group(2, &light, &[]);
self.set_bind_group(1, uniforms, &[]);
self.set_bind_group(2, light, &[]);
self.draw_mesh_instanced(mesh, material, 0..1, uniforms, light);
}

Expand All @@ -523,8 +538,8 @@ where
self.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
self.set_index_buffer(mesh.index_buffer.slice(..), wgpu::IndexFormat::Uint32);
self.set_bind_group(0, &material.bind_group, &[]);
self.set_bind_group(1, &uniforms, &[]);
self.set_bind_group(2, &light, &[]);
self.set_bind_group(1, uniforms, &[]);
self.set_bind_group(2, light, &[]);
self.draw_indexed(0..mesh.num_elements, 0, instances);
}

Expand Down Expand Up @@ -555,6 +570,7 @@ pub trait DrawLight<'a, 'b>
where
'b: 'a,
{
#[allow(dead_code)]
fn draw_light_mesh(
&mut self,
mesh: &'b Mesh,
Expand Down
6 changes: 3 additions & 3 deletions wgpu-testbed-lib/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn create_render_pipeline(
) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(shader);

return device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label,
layout: Some(layout),
multiview: None,
Expand All @@ -60,7 +60,7 @@ pub fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fragment_main",
targets: targets,
targets,
compilation_options: wgpu::PipelineCompilationOptions {
..Default::default()
},
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn create_render_pipeline(
alpha_to_coverage_enabled: false,
},
cache: None,
});
})
}

pub fn create_compute_pipeline(
Expand Down
Loading