From 7efbc19adf0d6b4aece2c28a5cd84fe437de74c6 Mon Sep 17 00:00:00 2001 From: Alexsander Falcucci Date: Sun, 22 Sep 2024 16:08:27 +0200 Subject: [PATCH] ci: improve cross-platform compatibility and workflows - 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` --- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- src/renderer.rs | 94 ++++++++++++++++++++++------------------ 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e94cfa1..d3b0999 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI on: push: branches: - - main + - ci defaults: run: diff --git a/Cargo.toml b/Cargo.toml index 7f5b707..1346b1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/renderer.rs b/src/renderer.rs index fde0940..6df34e9 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -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::{ @@ -32,7 +32,7 @@ pub struct Renderer { pub queue: Queue, pub shaders: HashMap, - #[cfg(not(any(target_os = "macos", target_os = "linux")))] + #[cfg(not(target_os = "macos"))] pub profiler: GpuProfiler, pub format: TextureFormat, @@ -157,25 +157,26 @@ 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, @@ -183,7 +184,7 @@ impl Renderer { queue, shaders, - #[cfg(not(any(target_os = "macos", target_os = "linux")))] + #[cfg(not(target_os = "macos"))] profiler, format, @@ -238,7 +239,7 @@ 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 @@ -246,6 +247,15 @@ impl Renderer { | 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 @@ -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); @@ -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, @@ -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 { @@ -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() { @@ -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, @@ -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 { @@ -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, @@ -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 { @@ -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( @@ -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, @@ -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 { @@ -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() {