Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
b061b79
add renderer package
PiquelChips Mar 22, 2026
85909b3
add ash
PiquelChips Mar 22, 2026
160abbe
add log, thiserror & anyhow to renderer
PiquelChips Mar 22, 2026
4c7017b
add glam & validation feature
PiquelChips Mar 22, 2026
f0305a8
setup conditionally enabling validation layers
PiquelChips Mar 22, 2026
122374a
Merge branch 'main' into vulkan
PiquelChips Mar 22, 2026
85d9b9b
Merge branch 'main' into vulkan
PiquelChips Mar 23, 2026
b15d5c9
add errors to renderer
PiquelChips Mar 24, 2026
c4a3ca6
setup renderer instance & validation layer init
PiquelChips Mar 24, 2026
80e7d6e
update platform window to implement window & display handle
PiquelChips Mar 24, 2026
2593554
implement surface creation in renderer
PiquelChips Mar 24, 2026
a047b91
setup physical device selection
PiquelChips Mar 24, 2026
d0ebf0b
update renderer crate comment
PiquelChips Mar 24, 2026
72d2f89
fix clippy warning
PiquelChips Mar 24, 2026
f46bfdc
setup renderer init in engine
PiquelChips Mar 24, 2026
16b8ee5
have vulkan be loaded instead of linked
PiquelChips Mar 24, 2026
d47038d
fmt
PiquelChips Mar 24, 2026
dbcafa5
fmt
PiquelChips Mar 26, 2026
e23b3cb
create logical device
PiquelChips Mar 26, 2026
9c2fea4
create queues
PiquelChips Mar 26, 2026
ff379b2
synchronization & swap chain
PiquelChips Mar 26, 2026
5f50acf
command pool
PiquelChips Mar 26, 2026
ab74303
descriptor sets
PiquelChips Mar 26, 2026
fd68ee8
make sure to create window before returning platform init
PiquelChips Mar 27, 2026
755c480
add todo
PiquelChips Mar 27, 2026
07c81ec
setup better validation config
PiquelChips Mar 27, 2026
d44c309
Merge branch 'main' into vulkan
PiquelChips Mar 30, 2026
249fbfb
add render function
PiquelChips Apr 1, 2026
2ca75d8
impl renderer shutdown
PiquelChips Apr 1, 2026
52fe29e
add utility functions
PiquelChips Apr 1, 2026
e236ed2
add single time command buffer stuff
PiquelChips Apr 2, 2026
4f84a1d
cleanup & add error
PiquelChips Apr 2, 2026
6e725f1
add some image utils
PiquelChips Apr 2, 2026
784250c
add more utlitlites
PiquelChips Apr 2, 2026
e76b33e
move renderer to legacy
PiquelChips Apr 2, 2026
5189430
replace winit with raw window handle in renderer
PiquelChips Apr 2, 2026
e9953e5
start adding new renderer
PiquelChips Apr 2, 2026
0dfe434
remove anyhow error overidding
PiquelChips Apr 2, 2026
423c329
cleanup legacy renderer
PiquelChips Apr 2, 2026
87f8cb8
start new renderer init
PiquelChips Apr 2, 2026
20714fe
add comment
PiquelChips Apr 2, 2026
ed5d4ce
add utils crate
PiquelChips Apr 3, 2026
5cb545f
add version struct
PiquelChips Apr 3, 2026
66b7a1c
add formatting to utils
PiquelChips Apr 3, 2026
31bc128
add zero to version
PiquelChips Apr 3, 2026
38e19a2
add unitests to version
PiquelChips Apr 3, 2026
c6c8f02
add create info to engine
PiquelChips Apr 3, 2026
550200a
add platform configuration to renderer
PiquelChips Apr 3, 2026
0d11f5a
fix typo
PiquelChips Apr 3, 2026
0bc6493
add some new error types
PiquelChips Apr 3, 2026
fb8fe45
add vulkan instance & validation setup
PiquelChips Apr 3, 2026
f4f56c9
fix renderer init in engine
PiquelChips Apr 3, 2026
55fc325
add primary surface creation
PiquelChips Apr 3, 2026
dcd8f52
move version stuff
PiquelChips Apr 3, 2026
673f496
add comments to utils
PiquelChips Apr 3, 2026
3442d35
add window trait to utils
PiquelChips Apr 4, 2026
d1ec31b
impl utils window for platform window
PiquelChips Apr 4, 2026
cae3a99
update engine & renderer to use new window trait
PiquelChips Apr 4, 2026
6ff73ef
cleanup & fix build errors
PiquelChips Apr 4, 2026
4f0f009
add physical device selection
PiquelChips Apr 4, 2026
9dcda5e
have clippy ignore legacy engine
PiquelChips Apr 4, 2026
1ac57dd
add extension constant
PiquelChips Apr 4, 2026
7b274fd
finish vulkan init
PiquelChips Apr 4, 2026
a7f09e5
refactor types in physical_device
PiquelChips Apr 4, 2026
7396238
add window struct
PiquelChips Apr 4, 2026
f5c8bf6
update window handling in renderer
PiquelChips Apr 4, 2026
58a3f30
Merge branch 'main' into vulkan
PiquelChips Apr 4, 2026
dc37e75
readd lock
PiquelChips Apr 4, 2026
f16f044
Merge branch 'main' into vulkan
PiquelChips Apr 4, 2026
1a49569
move utils
PiquelChips Apr 4, 2026
061fbbc
fix typo
PiquelChips Apr 4, 2026
93934af
revert weird box stuff
PiquelChips Apr 4, 2026
2e4303b
setup window creation
PiquelChips Apr 4, 2026
e84cce3
rename error
PiquelChips Apr 4, 2026
feaf822
implement model uploading
PiquelChips Apr 4, 2026
4c71436
cleanup engine errors
PiquelChips Apr 4, 2026
7efdc1f
clean stuff up (clippy)
PiquelChips Apr 4, 2026
cd9e12f
cleanup
PiquelChips Apr 4, 2026
6ad6a05
cleanup structs & add destroy
PiquelChips Apr 4, 2026
09d16a7
add model cmd buffer recording
PiquelChips Apr 4, 2026
573a794
fix build error
PiquelChips Apr 4, 2026
c0ddbdb
Merge branch 'main' into vulkan
PiquelChips Apr 5, 2026
1e91c12
fix duplicate dependencies
PiquelChips Apr 5, 2026
a2d570f
parse cargo version for engine version
PiquelChips Apr 5, 2026
997437f
cleanup unused
PiquelChips Apr 5, 2026
f25bc46
add model name
PiquelChips Apr 5, 2026
cfbc423
add internal model storage
PiquelChips Apr 5, 2026
4bc6585
store main window instead of surface
PiquelChips Apr 5, 2026
7ff6c28
rename structs to model module
PiquelChips Apr 5, 2026
6319755
cleanup
PiquelChips Apr 5, 2026
ac53ff6
add Scene & SceneProxy as Renderer representations of World & Renderable
PiquelChips Apr 5, 2026
b5e80e3
update comments
PiquelChips Apr 5, 2026
df40af7
update comments
PiquelChips Apr 5, 2026
a128a02
add id's to world
PiquelChips Apr 5, 2026
d137261
add scene management to renderer
PiquelChips Apr 5, 2026
d049319
add world management to engine
PiquelChips Apr 5, 2026
66d4931
start setting up the scene building
PiquelChips Apr 5, 2026
27f7507
add up direction constant
PiquelChips Apr 5, 2026
b83fe81
add vector directions to utils
PiquelChips Apr 5, 2026
ce189fc
setup camera utilities
PiquelChips Apr 5, 2026
2bb7242
add view matrix calculation to transform
PiquelChips Apr 5, 2026
b93354c
finish scene construction
PiquelChips Apr 5, 2026
3fa5bd2
update comments
PiquelChips Apr 5, 2026
e80b808
add mvp matrix
PiquelChips Apr 5, 2026
b386c8b
move buffer recording to scene rendering
PiquelChips Apr 5, 2026
b3bc9d0
move swap chain image
PiquelChips Apr 5, 2026
332995c
add in flight frames
PiquelChips Apr 5, 2026
777fdf1
setup descriptor layouts
PiquelChips Apr 5, 2026
5761885
fix error
PiquelChips Apr 5, 2026
078de52
clean imports
PiquelChips Apr 5, 2026
ee0dda3
add vertex binding description & attribute
PiquelChips Apr 5, 2026
985feb9
setup render pass creation
PiquelChips Apr 5, 2026
5858be2
create render pass in renderer
PiquelChips Apr 5, 2026
2a05ea1
setup sync & command buffer in render
PiquelChips Apr 5, 2026
26684c0
fix build error
PiquelChips Apr 5, 2026
e5778db
start adding ubo & descriptor stuff to scene
PiquelChips Apr 5, 2026
8a7ba33
cleanup
PiquelChips Apr 5, 2026
ab3357c
write descriptor sets
PiquelChips Apr 6, 2026
da6b60a
setup graphics pipeline
PiquelChips Apr 6, 2026
b9637ba
setup render pass
PiquelChips Apr 6, 2026
1824bd7
start setting up rendering in scene
PiquelChips Apr 6, 2026
5f05646
setup render pass creation
PiquelChips Apr 6, 2026
680b271
add some utils to window
PiquelChips Apr 6, 2026
f8244ce
fix function params in renderer
PiquelChips Apr 6, 2026
ca0c068
cleanup model api
PiquelChips Apr 6, 2026
04c9c7d
finish scene rendering
PiquelChips Apr 6, 2026
862e27a
setup proxy descriptor sets
PiquelChips Apr 6, 2026
26bb9ce
add a lot of destruction
PiquelChips Apr 6, 2026
556aab1
fix platform blocking
PiquelChips Apr 6, 2026
729b4dd
fix condition in device selection
PiquelChips Apr 6, 2026
eadf188
remove empty file
PiquelChips Apr 6, 2026
cc74569
fix build error
PiquelChips Apr 6, 2026
5303ca4
clippy fixes
PiquelChips Apr 6, 2026
6f1b4ff
Merge branch 'main' into vulkan
PiquelChips Apr 6, 2026
975ef71
add new shader util
PiquelChips Apr 6, 2026
272bfc2
add shader creation
PiquelChips Apr 6, 2026
ea13314
store entrypoint as CStr in shader
PiquelChips Apr 6, 2026
d6d6bfd
setup shader loading in graphics pipeline
PiquelChips Apr 6, 2026
c01e665
fix errors copying DirkEngine-cpp
PiquelChips Apr 6, 2026
810ec00
fix frag & vert shaders
PiquelChips Apr 6, 2026
d632c5f
move ubo struct
PiquelChips Apr 6, 2026
5f973fb
sepcify shader sets
PiquelChips Apr 6, 2026
a28cf23
fix duplicate queue families
PiquelChips Apr 6, 2026
749687c
create basic test world
PiquelChips Apr 6, 2026
9f7b8ef
fix issue with world creation
PiquelChips Apr 6, 2026
9273d83
make model upload private
PiquelChips Apr 6, 2026
8c1fd94
add debug to world
PiquelChips Apr 6, 2026
8aeb024
add resource manager error to renderer
PiquelChips Apr 6, 2026
a6780f3
preload renderer models
PiquelChips Apr 6, 2026
82521e2
add destruction
PiquelChips Apr 6, 2026
26e36a1
fix segfault when dropping window
PiquelChips Apr 6, 2026
d66b1bc
cleanup exiting
PiquelChips Apr 6, 2026
536fb4b
improve logging
PiquelChips Apr 6, 2026
4379d72
fix resource manager build
PiquelChips Apr 6, 2026
f52b0f4
fix issue with mip levels
PiquelChips Apr 6, 2026
6c72866
fix blit needs graphics command buffer
PiquelChips Apr 6, 2026
c5400a4
fix mipping
PiquelChips Apr 6, 2026
cac4ab3
fix small errors
PiquelChips Apr 6, 2026
8c4ad52
implement getting next swapchain image
PiquelChips Apr 6, 2026
eef599a
fix viewport index
PiquelChips Apr 6, 2026
7e9b917
setup semaphores in cmd buffer submitting
PiquelChips Apr 6, 2026
ad8175e
setup presenting
PiquelChips Apr 6, 2026
f18e840
setup material descriptor sets
PiquelChips Apr 6, 2026
3d5bdc5
add todo
PiquelChips Apr 6, 2026
3b37540
fix swapchain image layout
PiquelChips Apr 6, 2026
d251f84
finish destruction
PiquelChips Apr 6, 2026
d97b8c7
fix a few problems with shutdown
PiquelChips Apr 6, 2026
7f55937
move semaphores to window
PiquelChips Apr 6, 2026
f91202a
fix small ordering error
PiquelChips Apr 6, 2026
c1a1ed1
add sleep
PiquelChips Apr 6, 2026
88ed746
add command pool wrapper
PiquelChips Apr 6, 2026
281091c
use new command pool & buffer everywhere
PiquelChips Apr 6, 2026
978427c
refactor layout transitions to make it a lot easier to use
PiquelChips Apr 6, 2026
c4d222a
make sure to end command buffer
PiquelChips Apr 6, 2026
752b16b
move unused aroung
PiquelChips Apr 6, 2026
e0eccab
clippy fix
PiquelChips Apr 6, 2026
41ac32d
add resize window function
PiquelChips Apr 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 228 additions & 35 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ members = [
"Engine/Source/platform",
"Engine/Source/run",
"Engine/Source/resource_manager",
"Engine/Source/utils",
"Engine/Source/renderer",
"Engine/Source/world",
"Engine/Shaders"
]
Expand All @@ -29,15 +31,20 @@ derive-getters = "0.5"

# Engine modules
build = { path = "Engine/Source/build" }
utils = { path = "Engine/Source/utils" }
logging = { path = "Engine/Source/logging" }
engine = { path = "Engine/Source/engine" }
platform = { path = "Engine/Source/platform" }
renderer = { path = "Engine/Source/renderer" }
resource_manager = { path = "Engine/Source/resource_manager" }
world = { path = "Engine/Source/world" }
shaders = { path = "Engine/Shaders" }

# Main Engine Dependencies
winit = "0.31.0-beta.2"
ash = { version = "0.38", features = ["loaded"] }
ash-window = "0.13"
raw-window-handle = "0.6"
glam = "0.32"
gltf = "1"
shaderc = "0.10"
2 changes: 1 addition & 1 deletion Engine/Shaders/shaders/shader.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

layout(binding = 1) uniform sampler2D texSampler;
layout(set = 2, binding = 2) uniform sampler2D texSampler;

layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec2 fragTexCoord;
Expand Down
11 changes: 7 additions & 4 deletions Engine/Shaders/shaders/shader.vert
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#version 450

layout(binding = 0) uniform ModelViewProjection {
mat4 model;
layout(set = 0, binding = 0) uniform SceneUbo {
mat4 view;
mat4 proj;
} mvp;
} scene;

layout(set = 1, binding = 1) uniform ProxyUbo {
mat4 model;
} proxy;

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
Expand All @@ -14,7 +17,7 @@ layout(location = 0) out vec3 fragColor;
layout(location = 1) out vec2 fragTexCoord;

void main() {
gl_Position = mvp.proj * mvp.view * mvp.model * vec4(inPosition, 1.0);
gl_Position = scene.proj * scene.view * proxy.model * vec4(inPosition, 1.0);
fragColor = inColor;
fragTexCoord = inTexCoord;
}
21 changes: 17 additions & 4 deletions Engine/Shaders/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
//! This crate contains all the shaders used in the engine.

use std::ffi::CStr;

/// A simple struct that holds a block of shader bytecode and
/// the name of the shader's entrypoint.
pub struct Shader {
code: &'static [u8],
entrypoint: &'static str,
entrypoint: &'static CStr,
}

impl Shader {
/// Returns the shader code
pub const fn code(&self) -> &[u8] {
self.code
}
/// Returns the code but in blocks of u32
pub fn code_as_u32(&self) -> Vec<u32> {
assert!(
self.code.len().is_multiple_of(4),
"SPIR-V size must be a multiple of 4"
);
self.code
.chunks_exact(4)
.map(|c| u32::from_le_bytes(c.try_into().unwrap()))
.collect()
}
/// Returns the entrypoint of this shader
pub const fn entrypoint(&self) -> &str {
pub const fn entrypoint(&self) -> &CStr {
self.entrypoint
}
}
Expand All @@ -27,5 +40,5 @@ macro_rules! shader {
};
}

pub const VERT: Shader = shader!("shader.vert", "main");
pub const FRAG: Shader = shader!("shader.frag", "main");
pub const VERT: Shader = shader!("shader.vert", c"main");
pub const FRAG: Shader = shader!("shader.frag", c"main");
6 changes: 6 additions & 0 deletions Engine/Source/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ thiserror.workspace = true
log.workspace = true

logging.workspace = true
utils.workspace = true
platform.workspace = true
renderer.workspace = true
world.workspace = true
resource_manager.workspace = true

glam.workspace = true
13 changes: 0 additions & 13 deletions Engine/Source/engine/src/errors.rs

This file was deleted.

154 changes: 139 additions & 15 deletions Engine/Source/engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
use std::time::Instant;
use std::{collections::HashMap, f32::consts::PI, ffi::CString, str::FromStr, time::Instant};

use anyhow::Context;

use crate::errors::{InitResult, RenderResult, ShutdownResult};

mod errors;
use world::{World, WorldId};

/// This is the main struct that holds global engine state.
pub struct Engine {
// order is important as renderer should be dropped before platform
renderer: renderer::Renderer,
platform: platform::Platform,

next_world_id: WorldId,
worlds: HashMap<WorldId, World>,

is_requesting_exit: bool,
exit_error: Option<anyhow::Error>,
last_tick: Instant,
}

impl Engine {
pub fn init() -> InitResult<Self> {
pub fn init() -> anyhow::Result<Self> {
let logger = logging::Logger::new(true, true, true);
logging::init(logger);

let platform = platform::Platform::init();
let version = utils::Version::from_str(env!("CARGO_PKG_VERSION"))?;
let name = "DirkEngine";

let platform = platform::Platform::init().context("platform init")?;
let renderer = renderer::Renderer::init(
renderer::RendererCreateInfo {
engine_name: CString::from_str(name)?,
engine_version: version,
app_name: CString::from_str(name)?,
app_version: version,
},
platform.main_window(),
)
.context("renderer init")?;

/* A rough idea of the flow of the C++ Engine
*
* Intialize Main Engine Objects:
* - EventManager
* - Renderer
* - World
*
* ImGui:
Expand All @@ -35,12 +50,96 @@ impl Engine {
*
* Create main viewport
*/
Ok(Self {
is_requesting_exit: false,
let mut engine = Self {
platform,
renderer,

next_world_id: 0,
worlds: HashMap::new(),

is_requesting_exit: false,
exit_error: None,
last_tick: Instant::now(),
})
};

// TODO: this should be initialized when needed, not now
engine
.renderer
.upload_model(
resource_manager::ResourceManager::load_model("Shrek").context("loading shrek")?,
)
.context("uploading shrek")?;
engine
.renderer
.upload_model(
resource_manager::ResourceManager::load_model("Duck").context("loading duck")?,
)
.context("uploading duck")?;

let world_id = engine.create_world()?;

// THIS IS JUST TEMPORARY FOR TESTING
{
use world::components;
let world = engine.worlds.get_mut(&world_id).unwrap();

let player = world.spawn();
world.insert(
player,
components::Transform {
location: glam::vec3(0., 1000., 1000.),
rotation: glam::vec3(0., PI / 2., PI / 2.),
scale: glam::Vec3::splat(1.),
},
);
world.insert(
player,
components::Camera {
fov: (45_f32).to_radians(),
near_clip: 0.1,
far_clip: 100000.,
width: 100.,
height: 100.,
},
);

let shrek = world.spawn();
world.insert(
shrek,
components::Transform {
location: glam::Vec3::ZERO,
rotation: glam::Vec3::ZERO,
scale: glam::Vec3::splat(1.),
},
);
world.insert(
shrek,
components::Renderable {
model: "Shrek".to_string(),
},
);

let duck = world.spawn();
world.insert(
duck,
components::Transform {
location: glam::vec3(100., 0., 0.),
rotation: glam::Vec3::ZERO,
scale: glam::Vec3::splat(1.),
},
);
world.insert(
shrek,
components::Renderable {
model: "Duck".to_string(),
},
);

// TODO: see engine::create_world
engine.renderer.create_scene(world)?;
}

Ok(engine)
}
/// Engine tick.
/// Returns if the engine should continue ticking.
Expand All @@ -51,6 +150,10 @@ impl Engine {

let delta_time = self.capture_delta_time();

// TODO: renders too fast and semaphores have problem.
// remove when rendering takes longer
std::thread::sleep(std::time::Duration::from_millis(10));

self.platform.tick(delta_time).context("ticking platform")?;
if self.is_requesting_exit() {
return Ok(false);
Expand All @@ -61,11 +164,14 @@ impl Engine {
*
* World Tick
* Main Viewport tick
* Render
*/
Ok(self.is_requesting_exit())

self.render().context("tick: render")?;

Ok(!self.is_requesting_exit())
}
pub fn render(&self) -> RenderResult<()> {
pub fn render(&mut self) -> anyhow::Result<()> {
self.renderer.render()?;
/* Renderer::render
*
* ImGui:
Expand All @@ -78,7 +184,7 @@ impl Engine {
*/
Ok(())
}
pub fn shutdown(&self) -> ShutdownResult<()> {
pub fn shutdown(&mut self) -> anyhow::Result<()> {
/*
* Shutdown ImGui (renderer then platform)
*
Expand Down Expand Up @@ -106,4 +212,22 @@ impl Engine {
self.last_tick = current_time;
delta
}

fn create_world(&mut self) -> anyhow::Result<WorldId> {
let id = self.next_world_id;
self.next_world_id += 1;

let world = World::new(id);
// TODO: have the world submitted here, once not having camera doesn't panic.
// self.renderer
// .create_scene(&world)
// .context("create renderer scene")?;
self.worlds.insert(id, world);
Ok(id)
}
#[allow(unused)]
fn destroy_world(&mut self, id: WorldId) {
// TODO: delete renderer scene
self.worlds.remove(&id);
}
}
2 changes: 2 additions & 0 deletions Engine/Source/platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ anyhow.workspace = true
thiserror.workspace = true
winit.workspace = true

utils.workspace = true

[build-dependencies]
build.workspace = true
8 changes: 6 additions & 2 deletions Engine/Source/platform/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use thiserror::Error;

pub type Result<T> = std::result::Result<T, PlatformError>;
pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Error)]
pub enum PlatformError {
pub enum Error {
#[error("Error in winit event loop: {0}")]
EventLoopError(#[from] winit::error::EventLoopError),
#[error("Error fetching handle: {0}")]
HandleError(#[from] winit::raw_window_handle::HandleError),
#[error("Application exited with code {0}")]
AppExited(i32),
}
Loading
Loading