ci: emit github warnings on failure

This commit is contained in:
chyyran 2024-02-22 00:02:09 -05:00 committed by Ronny Chan
parent c7dd7796db
commit b5bc3c11e1
10 changed files with 86 additions and 38 deletions

View file

@ -32,4 +32,4 @@ jobs:
toolchain: nightly toolchain: nightly
override: true override: true
- name: Test - name: Test
run: cargo test -p librashader --test reflect -- --nocapture run: cargo test -p librashader --features=github-ci --test reflect -- --nocapture

View file

@ -1,24 +0,0 @@
use glob::glob;
use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderPreset;
use rayon::prelude::*;
#[test]
fn preprocess_all_slang_presets_parsed() {
for entry in glob("../test/slang-shaders/**/*.slangp").unwrap() {
if let Ok(path) = entry {
if let Ok(preset) = ShaderPreset::try_parse(&path) {
preset.shaders.into_par_iter().for_each(|shader| {
if let Err(e) = ShaderSource::load(&shader.name) {
println!(
"Failed to preprocess shader {} from preset {}: {:?}",
shader.name.display(),
path.display(),
e
);
}
})
}
}
}
}

View file

@ -5,17 +5,22 @@ pub trait OutputTarget {
} }
/// Shader compiler target for GLSL. /// Shader compiler target for GLSL.
#[derive(Debug)]
pub struct GLSL; pub struct GLSL;
/// Shader compiler target for HLSL. /// Shader compiler target for HLSL.
#[derive(Debug)]
pub struct HLSL; pub struct HLSL;
/// Shader compiler target for SPIR-V. /// Shader compiler target for SPIR-V.
#[derive(Debug)]
pub struct SPIRV; pub struct SPIRV;
/// Shader compiler target for MSL. /// Shader compiler target for MSL.
#[derive(Debug)]
pub struct MSL; pub struct MSL;
/// Shader compiler target for DXIL. /// Shader compiler target for DXIL.
/// ///
/// The resulting DXIL object is always unvalidated and /// The resulting DXIL object is always unvalidated and
/// must be validated using platform APIs before usage. /// must be validated using platform APIs before usage.
#[derive(Debug)]
pub struct DXIL; pub struct DXIL;
/// Shader compiler target for WGSL. /// Shader compiler target for WGSL.

View file

@ -36,8 +36,8 @@ mod test {
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics}; use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
use crate::reflect::ReflectShader; use crate::reflect::ReflectShader;
use bitflags::Flags; use bitflags::Flags;
use librashader_common::map::FastHashMap;
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use rustc_hash::FxHashMap;
#[test] #[test]
pub fn test_into() { pub fn test_into() {
@ -45,7 +45,7 @@ mod test {
// let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap(); // let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap();
let result = ShaderSource::load("../test/basic.slang").unwrap(); let result = ShaderSource::load("../test/basic.slang").unwrap();
let mut uniform_semantics: FxHashMap<String, UniformSemantic> = Default::default(); let mut uniform_semantics: FastHashMap<String, UniformSemantic> = Default::default();
for (_index, param) in result.parameters.iter().enumerate() { for (_index, param) in result.parameters.iter().enumerate() {
uniform_semantics.insert( uniform_semantics.insert(

View file

@ -11,6 +11,7 @@ use crate::reflect::semantics::{
MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
}; };
use crate::reflect::{align_uniform_size, ReflectShader}; use crate::reflect::{align_uniform_size, ReflectShader};
use std::fmt::{Debug};
use std::ops::Deref; use std::ops::Deref;
use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type}; use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type};
@ -19,6 +20,7 @@ use spirv_cross::ErrorCode;
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
/// Reflect shaders under SPIRV-Cross semantics. /// Reflect shaders under SPIRV-Cross semantics.
#[derive(Debug)]
pub struct SpirvCross; pub struct SpirvCross;
// This is "probably" OK. // This is "probably" OK.

View file

@ -3,6 +3,7 @@ pub mod spirv;
pub mod wgsl; pub mod wgsl;
use crate::error::{SemanticsErrorKind, ShaderReflectError}; use crate::error::{SemanticsErrorKind, ShaderReflectError};
use std::fmt::{Debug};
use crate::front::SpirvCompilation; use crate::front::SpirvCompilation;
use naga::{ use naga::{
@ -27,8 +28,8 @@ use crate::reflect::{align_uniform_size, ReflectShader, ShaderReflection};
/// ///
/// The Naga reflector will lower combined image samplers to split, /// The Naga reflector will lower combined image samplers to split,
/// with the same bind point on descriptor group 1. /// with the same bind point on descriptor group 1.
#[derive(Debug)]
pub struct Naga; pub struct Naga;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct NagaReflect { pub(crate) struct NagaReflect {
pub(crate) vertex: Module, pub(crate) vertex: Module,

View file

@ -164,15 +164,15 @@ mod test {
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics}; use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
use crate::reflect::ReflectShader; use crate::reflect::ReflectShader;
use bitflags::Flags; use bitflags::Flags;
use librashader_common::map::FastHashMap;
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use rustc_hash::FxHashMap;
use spirv_cross::msl; use spirv_cross::msl;
#[test] #[test]
pub fn test_into() { pub fn test_into() {
let result = ShaderSource::load("../test/basic.slang").unwrap(); let result = ShaderSource::load("../test/basic.slang").unwrap();
let mut uniform_semantics: FxHashMap<String, UniformSemantic> = Default::default(); let mut uniform_semantics: FastHashMap<String, UniformSemantic> = Default::default();
for (_index, param) in result.parameters.iter().enumerate() { for (_index, param) in result.parameters.iter().enumerate() {
uniform_semantics.insert( uniform_semantics.insert(

View file

@ -3,8 +3,8 @@ use crate::util;
use librashader_reflect::back::wgsl::NagaWgslContext; use librashader_reflect::back::wgsl::NagaWgslContext;
use librashader_reflect::back::ShaderCompilerOutput; use librashader_reflect::back::ShaderCompilerOutput;
use librashader_reflect::reflect::ShaderReflection; use librashader_reflect::reflect::ShaderReflection;
use librashader_runtime::render_target::RenderTarget;
use librashader_runtime::quad::VertexInput; use librashader_runtime::quad::VertexInput;
use librashader_runtime::render_target::RenderTarget;
use std::borrow::Cow; use std::borrow::Cow;
use std::sync::Arc; use std::sync::Arc;
use wgpu::{ use wgpu::{

View file

@ -74,6 +74,9 @@ full = ["runtime-all", "reflect-all", "preprocess", "presets"]
# cache hack # cache hack
docsrs = ["librashader-cache/docsrs", "objc2/unstable-docsrs"] docsrs = ["librashader-cache/docsrs", "objc2/unstable-docsrs"]
# emits warning messages in tests
github-ci = []
[dev-dependencies] [dev-dependencies]
glob = "0.3.1" glob = "0.3.1"
rayon = "1.6.1" rayon = "1.6.1"

View file

@ -25,10 +25,19 @@ fn collect_all_slang_presets() -> Vec<(PathBuf, ShaderPreset)> {
.into_par_iter() .into_par_iter()
.filter_map(|entry| { .filter_map(|entry| {
if let Ok(path) = entry { if let Ok(path) = entry {
if let Ok(preset) = ShaderPreset::try_parse(&path) { match ShaderPreset::try_parse(&path) {
Ok(preset) => {
println!("[INFO] Parsing preset {path:?}"); println!("[INFO] Parsing preset {path:?}");
return Some((path, preset)); return Some((path, preset));
} }
Err(e) => {
#[cfg(feature = "github-ci")]
println!(
"::warning file={},title=Failed to parse preset::{e:?}",
path.display()
)
}
}
} }
return None; return None;
}) })
@ -62,28 +71,80 @@ pub fn preprocess_all_slang_presets_parsed() {
path.display(), path.display(),
e e
); );
#[cfg(feature = "github-ci")]
println!(
"::warning file={},title=Failed to preprocess shader::{e:?}",
path.display()
)
} }
}) })
} }
} }
fn compile_presets<O: OutputTarget, R>() trait TypeDebug {
const DEBUG: &'static str;
}
impl TypeDebug for Naga {
const DEBUG: &'static str = "Naga";
}
impl TypeDebug for SpirvCross {
const DEBUG: &'static str = "SpirvCross";
}
impl TypeDebug for DXIL {
const DEBUG: &'static str = "DXIL";
}
impl TypeDebug for HLSL {
const DEBUG: &'static str = "HLSL";
}
impl TypeDebug for WGSL {
const DEBUG: &'static str = "WGSL";
}
impl TypeDebug for SPIRV {
const DEBUG: &'static str = "SPIRV";
}
impl TypeDebug for GLSL {
const DEBUG: &'static str = "GLSL";
}
impl TypeDebug for MSL {
const DEBUG: &'static str = "MSL";
}
fn compile_presets<O: OutputTarget, R: TypeDebug>()
where where
O: Sized, O: Sized,
O: FromCompilation<SpirvCompilation, R>, O: FromCompilation<SpirvCompilation, R>,
O: TypeDebug,
{ {
let presets = ALL_SLANG_PRESETS.read().unwrap(); let presets = ALL_SLANG_PRESETS.read().unwrap();
presets.par_iter().for_each(|(path, preset)| { presets.par_iter().for_each(|(path, preset)| {
println!( println!(
"[INFO] Compiling {path:?} into {} reflecting with {}", "[INFO] Compiling {} into {} reflecting with {}",
std::any::type_name::<O>(), path.display(),
std::any::type_name::<R>() O::DEBUG,
R::DEBUG
); );
if let Err(e) = O::compile_preset_passes::<SpirvCompilation, R, Box<dyn Error>>( if let Err(e) = O::compile_preset_passes::<SpirvCompilation, R, Box<dyn Error>>(
preset.shaders.clone(), preset.shaders.clone(),
&preset.textures, &preset.textures,
) { ) {
eprintln!("[ERROR] {:?} ({path:?})", e); eprintln!("[ERROR] {:?} ({path:?})", e);
#[cfg(feature = "github-ci")]
println!(
"::warning file={},title=Failed to reflect {} with {}::{e}",
path.display(),
O::DEBUG,
R::DEBUG
)
} }
}); });
} }