diff --git a/.gitignore b/.gitignore index 15f02fa..f35f905 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ /target/ /.vscode/ /.idea/ + +/bindgen/ +/docs/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 57d6931..0b37a3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + [[package]] name = "arbitrary" version = "1.4.1" @@ -456,7 +465,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" dependencies = [ - "approx", + "approx 0.4.0", "num-traits", ] @@ -678,22 +687,23 @@ checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" [[package]] name = "drm" -version = "0.12.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98888c4bbd601524c11a7ed63f814b8825f420514f78e96f752c437ae9cbb5d1" +checksum = "80bc8c5c6c2941f70a55c15f8d9f00f9710ebda3ffda98075f996a0e6c92756f" dependencies = [ "bitflags 2.8.0", "bytemuck", "drm-ffi", "drm-fourcc", + "libc", "rustix", ] [[package]] name = "drm-ffi" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97c98727e48b7ccb4f4aea8cfe881e5b07f702d17b7875991881b41af7278d53" +checksum = "d8e41459d99a9b529845f6d2c909eb9adf3b6d2f82635ae40be8de0601726e8b" dependencies = [ "drm-sys", "rustix", @@ -707,9 +717,9 @@ checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4" [[package]] name = "drm-sys" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd39dde40b6e196c2e8763f23d119ddb1a8714534bf7d77fa97a65b0feda3986" +checksum = "bafb66c8dbc944d69e15cfcc661df7e703beffbaec8bd63151368b06c5f9858c" dependencies = [ "libc", "linux-raw-sys 0.6.5", @@ -1281,6 +1291,16 @@ dependencies = [ "libc", ] +[[package]] +name = "matrixmultiply" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a" +dependencies = [ + "autocfg", + "rawpointer", +] + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -1353,6 +1373,7 @@ dependencies = [ "libc", "log", "metal 0.31.0", + "nalgebra", "num_cpus", "objc", "rand 0.9.0", @@ -1419,6 +1440,33 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "nalgebra" +version = "0.33.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26aecdf64b707efd1310e3544d709c5c0ac61c13756046aaaba41be5c4f66a3b" +dependencies = [ + "approx 0.5.1", + "matrixmultiply", + "nalgebra-macros", + "num-complex", + "num-rational", + "num-traits", + "simba", + "typenum", +] + +[[package]] +name = "nalgebra-macros" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ndk" version = "0.8.0" @@ -1527,6 +1575,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + [[package]] name = "num-derive" version = "0.4.2" @@ -2187,6 +2244,12 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + [[package]] name = "rayon" version = "1.10.0" @@ -2286,6 +2349,15 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" +[[package]] +name = "safe_arch" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323" +dependencies = [ + "bytemuck", +] + [[package]] name = "same-file" version = "1.0.6" @@ -2394,6 +2466,19 @@ dependencies = [ "libc", ] +[[package]] +name = "simba" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa" +dependencies = [ + "approx 0.5.1", + "num-complex", + "num-traits", + "paste", + "wide", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -2807,6 +2892,12 @@ version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31" +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.14" @@ -3277,6 +3368,16 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wide" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b5576b9a81633f3e8df296ce0063042a73507636cbe956c61133dd7034ab22" +dependencies = [ + "bytemuck", + "safe_arch", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 6f98018..ba1a6a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,26 +40,27 @@ members = [] # namespace = { path = "path/to/thing" } [build-dependencies] -shaderc = "0.8.3" -num_cpus = "1.16.0" -jobserver = "0.1.32" -gl_generator = "0.14" +shaderc = "0.8.3" # APACHE 2.0 +num_cpus = "1.16.0" # MIT +jobserver = "0.1.32" # MIT +gl_generator = "0.14" # APACHE 2.0 [dependencies] tracing = { version = "0.1.41", features = [ "max_level_debug", "release_max_level_warn", -] } -tracing-subscriber = "0.3.19" -log = "0.4.25" +] } # MIT +tracing-subscriber = "0.3.19" # MIT +log = "0.4.25" # MIT -anyhow = "1.0.95" -thiserror = "2.0.11" +anyhow = "1.0.95" # MIT +thiserror = "2.0.11" # MIT -cgmath = "0.18.0" -image = "0.25.5" -# png = "0.17.16" -tobj = { version = "4.0.2", features = ["log"] } +nalgebra = "0.33.2" # APACHE 2.0 +cgmath = "0.18.0" # APACHE 2.0 +image = "0.25.5" # MIT +# png = "0.17.16" # MIT +tobj = { version = "4.0.2", features = ["log"] } # MIT [target.'cfg(any(target_os = "windows",target_os = "linux",target_os = "macos"))'.dependencies] # vulkan @@ -67,27 +68,27 @@ vulkanalia = { version = "0.26.0", features = [ "libloading", "provisional", "window", -] } -old_winit = { package = "winit", version = "0.29" } # dont update, many many breaking changes with no guides +] } # APACHE 2.0 +old_winit = { package = "winit", version = "0.29" } # APACHE 2.0 # dont update, many many breaking changes with no guides # end vulkan # opengl -glutin = "0.32.2" -glutin-winit = "0.5.0" -raw-window-handle = "0.6" -winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] } -drm = { version = "0.12", optional = true } +glutin = "0.32.2" # APACHE 2.0 +glutin-winit = "0.5.0" # MIT +raw-window-handle = "0.6" # MIT +winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] } # APACHE 2.0 +drm = { version = "0.14.1", optional = true } # MIT # end opengl -ctrlc = "3.4.5" -tokio = { version = "1.43.0", features = ["full"] } +ctrlc = "3.4.5" # MIT +tokio = { version = "1.43.0", features = ["full"] } # MIT [target.'cfg(target_family = "wasm")'.dependencies] -wgpu = "24.0.0" +wgpu = "24.0.0" # MIT [target.'cfg(target_os = "vita")'.dependencies] -vitasdk-sys = { version = "0.3.3", features = ["all-stubs"] } -concat-idents = "1.1.5" -libc = "0.2.153" -rand = "0.9.0" +vitasdk-sys = { version = "0.3.3", features = ["all-stubs"] } # MIT and VITASDK themselves use MIT as well +concat-idents = "1.1.5" # MIT +libc = "0.2.153" # MIT +rand = "0.9.0" # MIT tokio = { version = "1.36.0", features = [ "fs", "macros", @@ -99,12 +100,12 @@ tokio = { version = "1.36.0", features = [ "net", "tracing", "time", -] } +] } # MIT [target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies] -metal = "0.31.0" -objc = "0.2.7" +metal = "0.31.0" # MIT +objc = "0.2.7" # MIT diff --git a/shaders/glsl_default.vert b/shaders/glsl_default.vert index 5510aa3..840711c 100644 --- a/shaders/glsl_default.vert +++ b/shaders/glsl_default.vert @@ -6,7 +6,7 @@ layout(binding = 0) uniform UniformBufferObject { mat4 proj; } ubo; -layout(location = 0) in vec2 inPosition; +layout(location = 0) in vec3 inPosition; layout(location = 1) in vec3 inColor; layout(location = 2) in vec2 inTexCoord; @@ -14,7 +14,7 @@ layout(location = 0) out vec3 fragColor; layout(location = 1) out vec2 fragTexCoord; void main() { - gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0); + gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); fragColor = inColor; fragTexCoord = inTexCoord; } diff --git a/src/graphics_engines/vulkan/mod.rs b/src/graphics_engines/vulkan/mod.rs index e08d2ab..e9a2702 100644 --- a/src/graphics_engines/vulkan/mod.rs +++ b/src/graphics_engines/vulkan/mod.rs @@ -62,14 +62,28 @@ const MAX_FRAMES_IN_FLIGHT:usize = 2; // Vertex::new(vec2(-0.5, 0.5), vec3(0.3, 0.0, 1.0)), // ]; -static VERTICES:[Vertex; 4] = [ - Vertex::new(vec2(-0.5, -0.5), vec3(1.0, 1.0, 1.0), vec2(1.0, 0.0)), - Vertex::new(vec2(0.5, -0.5), vec3(1.0, 1.0, 1.0), vec2(0.0, 0.0)), - Vertex::new(vec2(0.5, 0.5), vec3(1.0, 1.0, 1.0), vec2(0.0, 1.0)), - Vertex::new(vec2(-0.5, 0.5), vec3(1.0, 1.0, 1.0), vec2(1.0, 1.0)), +#[rustfmt::skip] +static VERTICES:&[Vertex] = &[ + // Vertex::new(vec2(-0.5, -0.5), vec3(1.0, 1.0, 1.0), vec2(1.0, 0.0)), + // Vertex::new(vec2(0.5, -0.5), vec3(1.0, 1.0, 1.0), vec2(0.0, 0.0)), + // Vertex::new(vec2(0.5, 0.5), vec3(1.0, 1.0, 1.0), vec2(0.0, 1.0)), + // Vertex::new(vec2(-0.5, 0.5), vec3(1.0, 1.0, 1.0), vec2(1.0, 1.0)), + + Vertex::new(vec3(-0.5, -0.5, 0.0), vec3(1.0, 0.0, 0.0), vec2(1.0, 0.0)), + Vertex::new(vec3( 0.5, -0.5, 0.0), vec3(0.0, 1.0, 0.0), vec2(0.0, 0.0)), + Vertex::new(vec3( 0.5, 0.5, 0.0), vec3(0.0, 0.0, 1.0), vec2(0.0, 1.0)), + Vertex::new(vec3(-0.5, 0.5, 0.0), vec3(1.0, 1.0, 1.0), vec2(1.0, 1.0)), + Vertex::new(vec3(-0.5, -0.5, -0.5), vec3(1.0, 0.0, 0.0), vec2(1.0, 0.0)), + Vertex::new(vec3( 0.5, -0.5, -0.5), vec3(0.0, 1.0, 0.0), vec2(0.0, 0.0)), + Vertex::new(vec3( 0.5, 0.5, -0.5), vec3(0.0, 0.0, 1.0), vec2(0.0, 1.0)), + Vertex::new(vec3(-0.5, 0.5, -0.5), vec3(1.0, 1.0, 1.0), vec2(1.0, 1.0)), ]; -const INDICES:&[u16] = &[0, 1, 2, 2, 3, 0]; +#[rustfmt::skip] +const INDICES:&[u16] = &[ + 0, 1, 2, 2, 3, 0, + 4, 5, 6, 6, 7, 4, +]; /// The shaders compiled by build.rs keep the same name and relative path as the source file exactly macro_rules! const_shaders { @@ -85,6 +99,7 @@ macro_rules! const_shaders { #[derive(Clone, Debug)] pub(crate) struct App { /// Vulkan entrypoint + #[allow(unused)] entry: Entry, instance: Instance, data: AppData, @@ -220,15 +235,22 @@ impl App { let view = Mat4f::look_at_rh(point3(2.0, 2.0, 2.0), point3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 1.0)); - let mut proj = cgmath::perspective( - Deg(45.0), - self.data.swapchain_extent.width as f32 / self.data.swapchain_extent.height as f32, - 0.1, - 10.0, + #[rustfmt::skip] + let correction = Mat4f::new( + 1.0, 0.0, 0.0, 0.0, + // We're also flipping the Y-axis with this line's `-1.0` because cgmath was made with opengl in mind + 0.0, -1.0, 0.0, 0.0, + 0.0, 0.0, 1.0 / 2.0, 0.0, + 0.0, 0.0, 1.0 / 2.0, 1.0, ); - // cgmath was made with opengl in mind, this fixes it to work with vulkan - proj[1][1] *= -1.0; + let proj = correction * + cgmath::perspective( + Deg(45.0), + self.data.swapchain_extent.width as f32 / self.data.swapchain_extent.height as f32, + 0.1, + 10.0, + ); let ubo = UniformBufferObject { model, view, proj }; @@ -1267,13 +1289,13 @@ struct UniformBufferObject { #[repr(C)] #[derive(Copy, Clone, Debug)] struct Vertex { - pos: Vec2f, + pos: Vec3f, color: Vec3f, tex_coord:Vec2f, } impl Vertex { - const fn new(pos:Vec2f, color:Vec3f, tex_coord:Vec2f) -> Self { Self { pos, color, tex_coord } } + const fn new(pos:Vec3f, color:Vec3f, tex_coord:Vec2f) -> Self { Self { pos, color, tex_coord } } fn binding_description() -> vk::VertexInputBindingDescription { vk::VertexInputBindingDescription::builder() @@ -1287,7 +1309,7 @@ impl Vertex { let pos = vk::VertexInputAttributeDescription::builder() .binding(0) .location(0) - .format(vk::Format::R32G32_SFLOAT) + .format(vk::Format::R32G32B32_SFLOAT) .offset(0) .build();