Skip to content

Commit

Permalink
ci: improve cross-platform compatibility and workflows
Browse files Browse the repository at this point in the history
- update `ci.yml` to listen for push events on the `ci` branch
- change dependencies based on the target operating system in `cargo.toml`
- modify conditional compilation for `macos` and `linux` in `src/renderer.rs`
  • Loading branch information
falcucci committed Sep 22, 2024
1 parent 0f52be3 commit 7efbc19
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches:
- main
- ci

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ termcolor = "1.4.1"
wgpu = { workspace = true, features = ["glsl"] }
winit = { workspace = true }

[target.'cfg(not(any(target_os = "linux", target_os = "macos")))'.dependencies]
[target.'cfg(not(target_os = "macos"))'.dependencies]
wgpu-profiler = { version = "0.18.0", features = ["tracy"] }

[dev-dependencies]
Expand Down
94 changes: 52 additions & 42 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use glam::*;
use glamour::{AsRaw, Rect};
use wgpu::*;

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
use wgpu_profiler::{GpuProfiler, GpuProfilerSettings};

use crate::{
Expand All @@ -32,7 +32,7 @@ pub struct Renderer {
pub queue: Queue,
pub shaders: HashMap<String, ShaderModule>,

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
pub profiler: GpuProfiler,

pub format: TextureFormat,
Expand Down Expand Up @@ -157,33 +157,34 @@ impl Renderer {
);
let shaders = shaders.await;

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
let mut profiler = GpuProfiler::new_with_tracy_client(
GpuProfilerSettings {
// enable_timer_queries: false,
..Default::default()
},
adapter.get_info().backend,
&device,
&queue,
)
.expect("Could not create profiler");

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
profiler
.change_settings(GpuProfilerSettings {
enable_timer_queries: false,
..Default::default()
})
.unwrap();
#[cfg(not(target_os = "macos"))]
{
let mut profiler = GpuProfiler::new_with_tracy_client(
GpuProfilerSettings {
// enable_timer_queries: false,
..Default::default()
},
adapter.get_info().backend,
&device,
&queue,
)
.expect("Could not create profiler");

profiler
.change_settings(GpuProfilerSettings {
enable_timer_queries: false,
..Default::default()
})
.unwrap();
}

Self {
adapter,
device,
queue,
shaders,

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
profiler,

format,
Expand Down Expand Up @@ -238,14 +239,23 @@ impl Renderer {
}

pub fn add_default_required_features() -> Features {
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
{
Features::PUSH_CONSTANTS
| Features::VERTEX_WRITABLE_STORAGE
| Features::CLEAR_TEXTURE
| Features::DUAL_SOURCE_BLENDING
}

#[cfg(target_os = "linux")]
{
Features::PUSH_CONSTANTS
| Features::VERTEX_WRITABLE_STORAGE
| Features::CLEAR_TEXTURE
| Features::DUAL_SOURCE_BLENDING
| GpuProfiler::ALL_WGPU_TIMER_FEATURES
}

#[cfg(target_os = "windows")]
{
Features::PUSH_CONSTANTS
Expand Down Expand Up @@ -372,7 +382,7 @@ impl Renderer {
);
}

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
{
self.profiler.resolve_queries(&mut encoder);

Expand All @@ -393,16 +403,16 @@ impl Renderer {
constants: ShaderConstants,
resources: &Resources,
) {
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut mask_scope = self.profiler.scope("mask", encoder, &self.device);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let mask_scope: &mut CommandEncoder = encoder;

if let Some(mask_contents) = mask_contents {
for batch in mask_contents.primitives.iter() {
for drawable in self.drawables.iter_mut() {
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut render_pass = mask_scope.scoped_render_pass(
"Mask",
&self.device,
Expand All @@ -421,7 +431,7 @@ impl Renderer {
},
);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let render_pass = mask_scope.begin_render_pass(&RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(RenderPassColorAttachment {
Expand All @@ -442,10 +452,10 @@ impl Renderer {

profiling::scope!("drawable", &drawable.name);

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut drawable_scope = render_pass.scope(&drawable.name, &self.device);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let mut drawable_scope = render_pass;

if !drawable.ready() {
Expand Down Expand Up @@ -476,7 +486,7 @@ impl Renderer {
}
}
} else {
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
mask_scope.scoped_render_pass(
"Clear Mask Texture",
&self.device,
Expand All @@ -499,7 +509,7 @@ impl Renderer {
},
);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
mask_scope.begin_render_pass(&RenderPassDescriptor {
label: Some("Clear Mask Texture"),
color_attachments: &[Some(RenderPassColorAttachment {
Expand Down Expand Up @@ -528,16 +538,16 @@ impl Renderer {
constants: ShaderConstants,
resources: &Resources,
) {
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut content_scope = self
.profiler
.scope("content", context.encoder, &self.device);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let content_scope = context.encoder;

if *context.first {
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
content_scope.scoped_render_pass(
"Clear Offscreen Texture",
&self.device,
Expand All @@ -557,7 +567,7 @@ impl Renderer {
},
);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
content_scope.begin_render_pass(&RenderPassDescriptor {
label: Some("Clear Offscreen Texture"),
color_attachments: &[Some(RenderPassColorAttachment {
Expand All @@ -576,11 +586,11 @@ impl Renderer {
'offscreen_copy: for batch in contents.primitives.iter() {
for drawable in self.drawables.iter() {
if drawable.has_work(batch) && drawable.requires_offscreen_copy() {
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut copy_scope =
content_scope.scope("Copy Frame to Offscreen", &self.device);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let copy_scope = &mut *content_scope;

copy_scope.copy_texture_to_texture(
Expand Down Expand Up @@ -627,7 +637,7 @@ impl Renderer {
}
};

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut render_pass = content_scope.scoped_render_pass(
"Layer Render Pass",
&self.device,
Expand All @@ -643,7 +653,7 @@ impl Renderer {
},
);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let render_pass = content_scope.begin_render_pass(&RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(RenderPassColorAttachment {
Expand All @@ -657,10 +667,10 @@ impl Renderer {

profiling::scope!("drawable", &drawable.name);

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[cfg(not(target_os = "macos"))]
let mut drawable_scope = render_pass.scope(&drawable.name, &self.device);

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_os = "macos")]
let mut drawable_scope = render_pass;

if !drawable.ready() {
Expand Down

0 comments on commit 7efbc19

Please sign in to comment.