vulkano/vulkano-shaders/tests/rust-gpu/test_shader.rs
Firestar99 093b43e98d
General shader improvements, specifically targeting rust-gpu (#2482)
* added tests for codegen reflect()

* added tests for a typical rust-gpu shader

* make idents that are invalid be named UnnamedX instead of panicing

* add generate_structs option to shader! macro, to disable struct generating

* get rid of macro_use extern crate

* disallow specifying a shader type for binary shaders

* fix mesh shaders output interface not being arrayed

* structs in shader interface panic with explanatory message

* fix clippy lints

Co-authored-by: Rua <ruawhitepaw@gmail.com>

---------

Co-authored-by: Firestar99 <4696087-firestar99@users.noreply.gitlab.com>
Co-authored-by: Rua <ruawhitepaw@gmail.com>
2024-03-03 15:22:39 +01:00

54 lines
1.3 KiB
Rust

//! This is the rust-gpu source code used to generate the spv output files found in this directory.
//! A pre-release version of rust-gpu 0.10 was used, specifically git 3689d11a. Spirv-Builder was
//! configured like this:
//!
//! ```norun
//! SpirvBuilder::new(shader_crate, "spirv-unknown-vulkan1.2")
//! .multimodule(true)
//! .spirv_metadata(SpirvMetadata::Full)
//! ```
use crate::test_shader::some_module::Bla;
use glam::{vec4, Vec4};
use spirv_std::spirv;
mod some_module {
use super::*;
pub struct Bla {
pub value: Vec4,
pub value2: Vec4,
pub decider: f32,
}
impl Bla {
pub fn lerp(&self) -> Vec4 {
self.value * (1. - self.decider) + self.value2 * self.decider
}
}
}
#[spirv(vertex)]
pub fn vertex(
#[spirv(vertex_index)] vertex_id: u32,
#[spirv(position)] position: &mut Vec4,
vtx_color: &mut Bla,
) {
let corners = [
vec4(-0.5, -0.5, 0.1, 1.),
vec4(0.5, -0.5, 0.1, 1.),
vec4(0., 0.5, 0.1, 1.),
];
*position = corners[(vertex_id % 3) as usize];
*vtx_color = Bla {
value: vec4(1., 1., 0., 1.),
value2: vec4(0., 1., 1., 1.),
decider: f32::max(vertex_id as f32, 1.),
};
}
#[spirv(fragment)]
pub fn fragment(vtx_color: Bla, f_color: &mut Vec4) {
*f_color = vtx_color.lerp();
}