Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
FC2a: a Material's textures of every dimension (1d, 2d_array, cube, cube_array, 3d), up to 6 samplers, and Bevy's fallback image for a texture it doesn't give (127/127)
shinyobjectzfff38cbcd62b
diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.listindex 78de2d17..ea8ebb5a 100644--- a/bench/bevy-parity/examples.list+++ b/bench/bevy-parity/examples.list@@ -126,3 +126,4 @@ shader/shader_materialshader/shader_defsshader/shader_material_screenspace_textureshader/shader_material_2d+shader/fallback_imagediff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsvindex b6cd7d97..666f418c 100644--- a/bench/bevy-parity/runs.tsv+++ b/bench/bevy-parity/runs.tsv@@ -125,3 +125,4 @@ shader/shader_material - 30shader/shader_defs - 10shader/shader_material_screenspace_texture - 10,60shader/shader_material_2d - 10+shader/fallback_image - 10diff --git a/docs/bevy-parity.md b/docs/bevy-parity.mdindex 6ebf85a7..749fbbfa 100644--- a/docs/bevy-parity.md+++ b/docs/bevy-parity.md@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys andframe time at most 1.25x the example's). Wall time is one machine's, measured in the same run.-Examples: **438**, ported **126**, passing **126**, excluded **16** (docs/bevy-parity/excluded.tsv), left **296**.+Examples: **438**, ported **127**, passing **127**, excluded **16** (docs/bevy-parity/excluded.tsv), left **295**.raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the exampledoesn't pay.@@ -185,11 +185,12 @@ doesn't pay.| 2d/sprite_slice | 10 | 0.997293 | 11 | 0 / 0 | 464 / 521 | 5 / 7 | 1 / 1 | 43.511 / 1.426 = 1.426 + 0 | yes | || shader/animate_shader | 30 | 1.000000 | 0 | 0 / 0 | 447 / 510 | 6 / 8 | 1 / 2 | 23.2 / 1.629 = 1.629 + 0 | yes | || shader/animate_shader | 60 | 1.000000 | 0 | 0 / 0 | 447 / 510 | 6 / 8 | 1 / 2 | 3.338 / 1.465 = 1.465 + 0 | yes | |-| shader/shader_material | 30 | 1.000000 | 0 | 0 / 0 | 447 / 510 | 6 / 8 | 1 / 2 | 18.093 / 1.611 = 1.611 + 0 | yes | || shader/shader_defs | 10 | 0.999999 | 0 | 0 / 0 | 448 / 511 | 7 / 8 | 1 / 3 | 45.978 / 2.503 = 2.503 + 0 | yes | || shader/shader_material_screenspace_texture | 10 | 0.998864 | 2 | 1 / 1 | 449 / 512 | 7 / 9 | 2 / 3 | 48.436 / 2.407 = 2.407 + 0 | yes | || shader/shader_material_screenspace_texture | 60 | 0.998929 | 2 | 1 / 1 | 449 / 512 | 7 / 9 | 2 / 3 | 3.231 / 1.598 = 1.598 + 0 | yes | || shader/shader_material_2d | 10 | 1.000000 | 0 | 0 / 0 | 447 / 510 | 6 / 8 | 1 / 1 | 45.128 / 1.489 = 1.489 + 0 | yes | |+| shader/shader_material | 30 | 1.000000 | 0 | 0 / 0 | 447 / 510 | 6 / 8 | 1 / 2 | 19.131 / 1.539 = 1.539 + 0 | yes | |+| shader/fallback_image | 10 | 1.000000 | 0 | 0 / 0 | 447 / 510 | 6 / 8 | 1 / 2 | 42.667 / 2.26 = 2.26 + 0 | yes | |## Excludeddiff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonlindex f13cd4e2..6b0237a2 100644--- a/docs/bevy-parity/results.jsonl+++ b/docs/bevy-parity/results.jsonl@@ -172,8 +172,9 @@{"example":"2d/sprite_slice","frame":10,"ssim":0.997293,"tile":11,"bevy":{"batch_keys":0,"entities":464,"extents":[],"frame":10,"frame_ms":43.511,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":521,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.426,"step_ms":null,"cost_ms":1.426},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader/animate_shader","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":23.2,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":37,"entities":510,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.629,"step_ms":null,"cost_ms":1.629},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader/animate_shader","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":60,"frame_ms":3.338,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":67,"entities":510,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.465,"step_ms":null,"cost_ms":1.465},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}-{"example":"shader/shader_material","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":18.093,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":38,"entities":510,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.611,"step_ms":null,"cost_ms":1.611},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader/shader_defs","frame":10,"ssim":0.999999,"tile":0,"bevy":{"batch_keys":0,"entities":448,"extents":["0.5000 0.5000 0.5000"],"frame":10,"frame_ms":45.978,"materials":1,"mesh_entities":2,"meshes":7,"other_material":2,"visible":2},"raea":{"frame":17,"entities":511,"mesh_entities":2,"visible":2,"meshes":8,"materials":3,"batch_keys":0,"other_material":2,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.503,"step_ms":null,"cost_ms":2.503},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader/shader_material_screenspace_texture","frame":10,"ssim":0.998864,"tile":2,"bevy":{"batch_keys":1,"entities":449,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame":10,"frame_ms":48.436,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":18,"entities":512,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame_ms":2.407,"step_ms":null,"cost_ms":2.407},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader/shader_material_screenspace_texture","frame":60,"ssim":0.998929,"tile":2,"bevy":{"batch_keys":1,"entities":449,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame":60,"frame_ms":3.231,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":68,"entities":512,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame_ms":1.598,"step_ms":null,"cost_ms":1.598},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader/shader_material_2d","frame":10,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":[],"frame":10,"frame_ms":45.128,"materials":1,"mesh_entities":0,"meshes":6,"other_material":0,"visible":0},"raea":{"frame":17,"entities":510,"mesh_entities":0,"visible":0,"meshes":8,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.489,"step_ms":null,"cost_ms":1.489},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/shader_material","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":19.131,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":38,"entities":510,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.539,"step_ms":null,"cost_ms":1.539},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/fallback_image","frame":10,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":10,"frame_ms":42.667,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":17,"entities":510,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.26,"step_ms":null,"cost_ms":2.26},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}diff --git a/sdk/raea/bench/bevy-parity/shader/fallback_image.tsx b/sdk/raea/bench/bevy-parity/shader/fallback_image.tsxnew file mode 100644index 00000000..46c3037d--- /dev/null+++ b/sdk/raea/bench/bevy-parity/shader/fallback_image.tsx@@ -0,0 +1,24 @@+// Bevy v0.20.0 examples/shader/fallback_image.rs in raea's TSX (docs/control.feature FC0a, FC2a): a 1 m cube at the+// origin with the example's own Material, assets/shaders/fallback_image_test.wesl as written: a texture of each+// dimension (1d, 2d, 2d_array, cube, cube_array, 3d) and a sampler for each, none given, so each binds Bevy's+// fallback image of its dimension; its fragment writes nothing. The camera at (5, 5, 5) looking at (1.5, 0, 0), in+// Bevy's default 1280 x 720 window.+import { Composition, registerRoot, staticFile } from "raea";+import { Transform } from "raea/transform";+import { Camera3d } from "raea/camera";+import { Cuboid, Mesh3d } from "raea/mesh";+import { Material } from "@raea/render/bevy3d"; // raea/pbr once scene-loop lands (its pbr.ts commit)++function Shot() {+ return (+ <>+ <Mesh3d transform={Transform.IDENTITY}>+ <Cuboid half_size={[0.5, 0.5, 0.5]} />+ <Material fragment={staticFile("shaders/fallback_image_test.wesl")} />+ </Mesh3d>+ <Camera3d transform={Transform.fromXyz(5, 5, 5).lookingAt([1.5, 0, 0])} />+ </>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);diff --git a/systems/shader/src/own.rs b/systems/shader/src/own.rsindex 9cff7927..34e747bd 100644--- a/systems/shader/src/own.rs+++ b/systems/shader/src/own.rs@@ -21,7 +21,7 @@ use bevy::shader::{Shader, ShaderRef};use bevy::sprite_render::{AlphaMode2d, Material2d, Material2dKey, Material2dPipeline, Material2dPlugin};use serde_json::Value;-use crate::ui_bind::{rebind_in, Rebound};+use crate::ui_bind::{rebind_in, Rebound, DIMS};use crate::{layout, register, Inputs, OwnSurface, Shaded};/// The fragment shader every pipeline starts from, swapped in `specialize` for the material's own (its uuid).@@ -68,6 +68,19 @@ pub struct OwnMaterial {#[texture(14)]#[sampler(15)]t3: Option<Handle<Image>>,+ // one texture of each other dimension (ui_bind.rs DIMS), the 1d's and 2d_array's samplers the 5th and 6th+ #[texture(16, dimension = "1d")]+ #[sampler(17)]+ d1: Option<Handle<Image>>,+ #[texture(18, dimension = "2d_array")]+ #[sampler(19)]+ d2a: Option<Handle<Image>>,+ #[texture(20, dimension = "cube")]+ cube: Option<Handle<Image>>,+ #[texture(21, dimension = "cube_array")]+ cube_array: Option<Handle<Image>>,+ #[texture(22, dimension = "3d")]+ d3: Option<Handle<Image>>,shader: u128,/// the vertex shader's uuid, 0 for Bevy's mesh vertex shadervertex: u128,@@ -164,14 +177,22 @@ pub fn build(world: &mut World, v: &Value, image: &mut impl FnMut(&mut World, &Vlet mut rest = o.clone();let given = rest.remove("uniforms").and_then(|u| u.as_object().cloned()).unwrap_or_default();let ins = Inputs::read(world, &rest, what, image)?;- let Rebound { src, uniforms, textures, .. } = rebind_in(&ins.src, groups, what).map_err(|e| format!("{path}: {e}"))?;+ let Rebound { src, uniforms, textures, others, .. } = rebind_in(&ins.src, groups, what, true).map_err(|e| format!("{path}: {e}"))?;let [u0, u1, u2, u3, u4, u5, u6, u7] = layout::slots(&src, &uniforms, &given, &ins.defs).map_err(|e| format!("{path}: {e}"))?;if let Some((k, _)) = ins.textures.iter().find(|(k, _)| !textures.contains(k)) {- return Err(format!("{path} has no texture {k}"));+ return Err(format!("{path} has no texture_2d {k}"));}+ // a texture the source declares and the spec doesn't give is Bevy's fallback image, as an Option<Handle<Image>>+ // field left None bindslet mut t: [Option<Handle<Image>>; 4] = Default::default();for (i, name) in textures.iter().enumerate() {- t[i] = Some(ins.textures.iter().find(|(k, _)| k == name).map(|x| x.1.clone()).ok_or_else(|| format!("{path}'s texture {name} has no picture"))?);+ t[i] = ins.textures.iter().find(|(k, _)| k == name).map(|x| x.1.clone());+ }+ // the other dimensions: a 2d_array from the spec's one texture array ({layers}); the rest are fallbacks for now+ let mut dims: [Option<Handle<Image>>; 5] = Default::default();+ if let Some((name, h)) = &ins.array {+ let i = others.iter().position(|(n, d)| n == name && *d == "2d_array").ok_or_else(|| format!("{path} has no texture_2d_array {name}"))?;+ dims[DIMS.iter().position(|x| x.1 == others[i].1).unwrap_or(1)] = Some(h.clone());}let krate = folder(world, path, &src)?;let shader = register(world, src, &ins.defs, "raea own material", &krate);@@ -179,7 +200,7 @@ pub fn build(world: &mut World, v: &Value, image: &mut impl FnMut(&mut World, &VNone => 0,Some(p) => {let s = std::fs::read_to_string(p).map_err(|e| format!("{what}'s vertex {p}: {e}"))?;- let s = rebind_in(&s, groups, what).map_err(|e| format!("{p}: {e}"))?.src;+ let s = rebind_in(&s, groups, what, true).map_err(|e| format!("{p}: {e}"))?.src;let krate = folder(world, p, &s)?;register(world, s, &ins.defs, "raea own material vertex", &krate)}@@ -195,7 +216,8 @@ pub fn build(world: &mut World, v: &Value, image: &mut impl FnMut(&mut World, &VSome(v) => return Err(format!("a Material's cull_mode is \"Front\", \"Back\" or null (none), got {v}")),};let [t0, t1, t2, t3] = t;- Ok(OwnMaterial { u0, u1, u2, u3, u4, u5, u6, u7, t0, t1, t2, t3, shader, vertex, alpha, depth_bias, cull })+ let [d1, d2a, cube, cube_array, d3] = dims;+ Ok(OwnMaterial { u0, u1, u2, u3, u4, u5, u6, u7, t0, t1, t2, t3, d1, d2a, cube, cube_array, d3, shader, vertex, alpha, depth_bias, cull })}/// Bevy's AlphaMode as the SDK writes it: "Opaque", "Blend", {"Mask": cutoff}, "Premultiplied", "AlphaToCoverage",diff --git a/systems/shader/src/ui_bind.rs b/systems/shader/src/ui_bind.rsindex 53d80f2b..1cd03593 100644--- a/systems/shader/src/ui_bind.rs+++ b/systems/shader/src/ui_bind.rs@@ -7,6 +7,10 @@/// Uniform buffers a UiMaterial may bind, and textures (each with its sampler).pub const UNIFORMS: usize = 8;pub const TEXTURES: usize = 4;+/// A Material's textures of the other dimensions (`dims`), one of each, at their own slots: its first two samplers past+/// the 2D textures' at 17 and 19 (Bevy's view binds up to 8 of the fragment stage's 16).+pub const DIMS: [(&str, &str, usize); 5] = [("texture_1d<", "1d", 16), ("texture_2d_array<", "2d_array", 18), ("texture_cube<", "cube", 20), ("texture_cube_array<", "cube_array", 21), ("texture_3d<", "3d", 22)];+pub const SAMPLERS_WITH_DIMS: usize = 6;/// A UiMaterial source with its bindings renumbered: its uniforms (name, WGSL type) and its textures' names, each in/// its slot's order, and how many samplers it binds.@@ -15,18 +19,23 @@ pub struct Rebound {pub src: String,pub uniforms: Vec<(String, String)>,pub textures: Vec<String>,+ /// its textures of other dimensions (`dims`): each name and its dimension, "1d", "2d_array", "cube", ...+ pub others: Vec<(String, &'static str)>,pub samplers: usize,}/// `src`'s `@group(1)` declarations renumbered into raea's slots (see the module's doc), a UiMaterial's.pub fn rebind(src: &str) -> Result<Rebound, String> {- rebind_in(src, &["1"], "a UiMaterial")+ rebind_in(src, &["1"], "a UiMaterial", false)}/// `src`'s declarations in any of `groups` (as the source writes the group: `1`, `constants::MATERIAL_BIND_GROUP`)/// renumbered into raea's slots; bindings of other groups left as written. Refused: a binding that isn't a uniform, a-/// texture_2d or a sampler, and more of each than raea has slots for (`what` names the material in errors).-pub fn rebind_in(src: &str, groups: &[&str], what: &str) -> Result<Rebound, String> {+/// texture_2d or a sampler (with `dims`, also a texture of another dimension, DIMS), and more of each than raea has+/// slots for (`what` names the material in errors).+pub fn rebind_in(src: &str, groups: &[&str], what: &str, dims: bool) -> Result<Rebound, String> {+ let mut others: Vec<(String, &'static str)> = Vec::new();+ let max_samplers = if dims { SAMPLERS_WITH_DIMS } else { TEXTURES };let mut out = String::with_capacity(src.len());let (mut uniforms, mut textures, mut samplers) = (Vec::new(), Vec::new(), 0usize);let mut rest = src;@@ -67,10 +76,16 @@ pub fn rebind_in(src: &str, groups: &[&str], what: &str) -> Result<Rebound, StriUNIFORMS + 2 * (textures.len() - 1)} else if ty == "sampler" {samplers += 1;- if samplers > TEXTURES {- return Err(format!("{what} binds at most {TEXTURES} samplers, {name} is one more"));+ if samplers > max_samplers {+ return Err(format!("{what} binds at most {max_samplers} samplers, {name} is one more"));}UNIFORMS + 2 * (samplers - 1) + 1+ } else if let Some(&(_, d, slot)) = DIMS.iter().find(|(p, ..)| dims && ty.starts_with(p)) {+ if others.iter().any(|(_, o)| *o == d) {+ return Err(format!("{what} binds one texture_{d}, {name} is a second"));+ }+ others.push((name.clone(), d));+ slot} else {return Err(format!("{what}'s binding {name} is a var<uniform>, a texture_2d<f32> or a sampler, got {ty} (the rest are FC2a's to come)"));};@@ -79,10 +94,10 @@ pub fn rebind_in(src: &str, groups: &[&str], what: &str) -> Result<Rebound, Strirest = &rest[close + 1..];}out += rest;- if samplers > textures.len() {- return Err(format!("{what}'s samplers are its textures', one each: {samplers} samplers for {} textures", textures.len()));+ if samplers > textures.len() + others.len() {+ return Err(format!("{what}'s samplers are its textures', one each: {samplers} samplers for {} textures", textures.len() + others.len()));}- Ok(Rebound { src: out, uniforms, textures, samplers })+ Ok(Rebound { src: out, uniforms, textures, others, samplers })}/// The group a declaration's `@group(N)` names.@@ -125,4 +140,19 @@ mod tests {assert!(rebind(&nine).unwrap_err().contains("at most 8 uniforms"));assert!(rebind("@group(1) @binding(0) var s: sampler;\n@group(1) @binding(1) var s2: sampler;\n@group(1) @binding(2) var t: texture_2d<f32>;").unwrap_err().contains("one each"));}++ #[test]+ fn a_materials_other_dimensions_go_to_their_slots_and_its_samplers_in_order() {+ // Bevy's fallback_image_test.wesl: a texture of each dimension, each with its sampler+ let src = ["1d", "2d", "2d_array", "cube", "cube_array", "3d"].iter().enumerate().map(|(i, d)| format!("@group(3) @binding({}) var t_{d}: texture_{d}<f32>;\n@group(3) @binding({}) var s_{d}: sampler;\n", 2 * i, 2 * i + 1)).collect::<String>();+ let r = rebind_in(&src, &["3"], "a Material", true).unwrap();+ assert_eq!(r.textures, vec!["t_2d".to_string()]);+ assert_eq!(r.others.iter().map(|o| o.1).collect::<Vec<_>>(), vec!["1d", "2d_array", "cube", "cube_array", "3d"]);+ for want in ["@binding(16) var t_1d", "@binding(9) var s_1d", "@binding(8) var t_2d", "@binding(11) var s_2d", "@binding(18) var t_2d_array", "@binding(20) var t_cube:", "@binding(21) var t_cube_array", "@binding(22) var t_3d", "@binding(19) var s_3d"] {+ assert!(r.src.contains(want), "{want} in {}", r.src);+ }+ // a UiMaterial takes none of them, and a Material one of each+ assert!(rebind_in(&src, &["3"], "a UiMaterial", false).unwrap_err().contains("texture_1d"));+ assert!(rebind_in("@group(3) @binding(0) var a: texture_3d<f32>;\n@group(3) @binding(1) var b: texture_3d<f32>;", &["3"], "a Material", true).unwrap_err().contains("a second"));+ }}