diff --git a/engine/build.rs b/engine/build.rs index 13e247c..be1e635 100644 --- a/engine/build.rs +++ b/engine/build.rs @@ -9,6 +9,14 @@ fn main() -> anyhow::Result<()> { shaderc::EnvVersion::Vulkan1_3 as u32, ); options.set_source_language(shaderc::SourceLanguage::GLSL); + options.set_include_callback(|name, _, _, _| { + let path = format!("devres/shaders/{}", name); + let source = std::fs::read_to_string(&path).unwrap(); + Ok(shaderc::ResolvedInclude { + resolved_name: name.to_string(), + content: source, + }) + }); let is_debug_build = std::env::var("OPT_LEVEL")? == "0"; diff --git a/engine/devres/shaders/shader.frag b/engine/devres/shaders/shader.frag index 81f323b..b00038b 100644 --- a/engine/devres/shaders/shader.frag +++ b/engine/devres/shaders/shader.frag @@ -1,9 +1,11 @@ -#version 450 +#version 460 layout (location = 0) in vec3 fragColor; layout (location = 0) out vec4 outColor; +#include "push_constants.glsl" + void main() { outColor = vec4(fragColor, 1.0); } \ No newline at end of file diff --git a/engine/devres/shaders/shader.vert b/engine/devres/shaders/shader.vert index 70aaedb..0fa169c 100644 --- a/engine/devres/shaders/shader.vert +++ b/engine/devres/shaders/shader.vert @@ -1,36 +1,7 @@ #version 460 -#extension GL_EXT_buffer_reference: require -#extension GL_EXT_scalar_block_layout: require - layout (location = 0) out vec3 fragColor; -struct Vertex { - vec3 position; - vec3 color; -}; - -struct Camera { - mat4 view_projection; -}; - -layout (buffer_reference, scalar) buffer VertexBuffer { - Vertex vertices[]; -}; - -layout (buffer_reference, scalar) buffer CameraBuffer { - Camera cameras[]; -}; - -layout (buffer_reference, scalar) buffer InstanceBuffer { - mat4 model[]; -}; - -layout (scalar, push_constant) uniform Registers -{ - VertexBuffer vertexBuffer; - InstanceBuffer instanceBuffer; - CameraBuffer cameraBuffer; -} pushConstants; +#include "push_constants.glsl" void main() { vec3 position = pushConstants.vertexBuffer.vertices[gl_VertexIndex].position; diff --git a/engine/src/lib.rs b/engine/src/lib.rs index c3c2e7f..8f39c27 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -17,7 +17,7 @@ pub use crate::renderer::window_renderer::WindowRendererAttributes; pub use anyhow; pub use ash::vk; use renderdoc::RenderDoc; -use tracing::{error, info}; +use tracing::info; pub use winit; use winit::keyboard::{Key, NamedKey}; @@ -35,7 +35,7 @@ impl Engine { primary_window_attributes: WindowAttributes, primary_renderer_attributes: WindowRendererAttributes, ) -> Result { - let mut renderdoc = RenderDoc::new().ok(); + let renderdoc = RenderDoc::new().ok(); if renderdoc.is_some() { info!("RenderDoc is available"); }