Skip to content

Commit 92fc525

Browse files
committed
[update] winit and fix render semaphores not being attached to queue submissions.
1 parent 09290ba commit 92fc525

8 files changed

Lines changed: 48 additions & 21 deletions

File tree

crates/lambda-platform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ path = "src/lib.rs"
99

1010
[dependencies]
1111
gfx-hal = "=0.9.0"
12-
winit = "=0.26.1"
12+
winit = "=0.27.4"
1313
shaderc = "=0.7"
1414
cfg-if = "=1.0.0"
1515

crates/lambda-platform/src/gfx/api.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//! implementations to use.
33
44
cfg_if::cfg_if! {
5-
if #[cfg(feature = "with-gl")] {
5+
if #[cfg(feature = "gfx-with-gl")] {
66
pub use gfx_backend_gl as RenderingAPI;
7-
} else if #[cfg(feature = "with-vulkan")] {
7+
} else if #[cfg(feature = "gfx-with-vulkan")] {
88
pub use gfx_backend_vulkan as RenderingAPI;
9-
} else if #[cfg(feature = "with-metal")] {
9+
} else if #[cfg(feature = "gfx-with-metal")] {
1010
pub use gfx_backend_metal as RenderingAPI;
11-
} else if #[cfg(feature = "with-dx11")] {
11+
} else if #[cfg(feature = "gfx-with-dx11")] {
1212
pub use gfx_backend_dx11 as RenderingAPI;
13-
} else if #[cfg(feature = "with-dx12")] {
13+
} else if #[cfg(feature = "gfx-with-dx12")] {
1414
pub use gfx_backend_dx12 as RenderingAPI;
1515
} else if #[cfg(feature = "detect-platform")] {
1616
pub use gfx_platform_backend as RenderingAPI;

crates/lambda-platform/src/gfx/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum Command<RenderBackend: gfx_hal::Backend> {
9494
pipeline: Rc<RenderPipeline<RenderBackend>>,
9595
stage: super::pipeline::PipelineStage,
9696
offset: u32,
97-
bytes: &'static [u32],
97+
bytes: Vec<u32>,
9898
},
9999
EndRecording,
100100
}
@@ -182,7 +182,7 @@ impl<'command_pool, RenderBackend: gfx_hal::Backend>
182182
super::pipeline::internal::pipeline_layout_for(pipeline.as_ref()),
183183
stage,
184184
offset,
185-
bytes,
185+
bytes.as_slice(),
186186
),
187187
Command::Draw { vertices } => self.command_buffer.draw(vertices, 0..1),
188188
Command::EndRecording => self.command_buffer.finish(),

crates/lambda-platform/src/gfx/fence.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,10 @@ pub mod internal {
133133
) -> &mut RenderBackend::Semaphore {
134134
return &mut semaphore.semaphore;
135135
}
136+
137+
pub fn semaphore_for<RenderBackend: gfx_hal::Backend>(
138+
semaphore: &super::RenderSemaphore<RenderBackend>,
139+
) -> &RenderBackend::Semaphore {
140+
return &semaphore.semaphore;
141+
}
136142
}

crates/lambda-platform/src/gfx/gpu.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
129129
pub fn submit_command_buffer<'render_context>(
130130
&mut self,
131131
command_buffer: &mut CommandBuffer<RenderBackend>,
132-
signal_semaphores: Vec<RenderSemaphore<RenderBackend>>,
132+
signal_semaphores: Vec<&RenderSemaphore<RenderBackend>>,
133133
fence: &mut RenderSubmissionFence<RenderBackend>,
134134
) {
135135
let commands =
@@ -139,7 +139,11 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
139139
self.queue_group.queues[0].submit(
140140
commands,
141141
vec![].into_iter(),
142-
vec![].into_iter(),
142+
// TODO(vmarcella): This was needed to allow the push constants to
143+
// properly render to the screen. Look into a better way to do this.
144+
signal_semaphores.into_iter().map(|semaphore| {
145+
return super::fence::internal::semaphore_for(semaphore);
146+
}),
143147
Some(super::fence::internal::mutable_fence_for(fence)),
144148
);
145149
}
@@ -154,6 +158,7 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
154158
let (render_surface, render_image) =
155159
super::surface::internal::borrow_surface_and_take_image(surface);
156160

161+
println!("Rendering to surface.");
157162
let result = unsafe {
158163
self.queue_group.queues[0].present(
159164
render_surface,
@@ -169,6 +174,8 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
169174
);
170175
}
171176

177+
println!("Rendered to surface.");
178+
172179
return Ok(());
173180
}
174181
}

crates/lambda-platform/src/gfx/pipeline.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ impl<RenderBackend: internal::Backend> RenderPipelineBuilder<RenderBackend> {
8989
) -> RenderPipeline<RenderBackend> {
9090
// TODO(vmarcella): The pipeline layout should be configurable through the
9191
// RenderPipelineBuilder.
92+
let push_constants = self.push_constants.into_iter();
93+
9294
let pipeline_layout = unsafe {
9395
use internal::Device;
96+
9497
super::internal::logical_device_for(gpu)
95-
.create_pipeline_layout(
96-
vec![].into_iter(),
97-
self.push_constants.into_iter(),
98-
)
98+
.create_pipeline_layout(vec![].into_iter(), push_constants)
9999
.expect(
100100
"The GPU does not have enough memory to allocate a pipeline layout",
101101
)

crates/lambda-platform/src/gfx/shader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl ShaderModuleBuilder {
2929
pub fn new() -> Self {
3030
return Self {
3131
entry_name: "main".to_string(),
32-
specializations: ShaderSpecializations::default(),
32+
specializations: ShaderSpecializations::EMPTY,
3333
};
3434
}
3535

crates/lambda-platform/src/shaderc/mod.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ impl ShaderCompilerBuilder {
1515
pub fn build(self) -> ShaderCompiler {
1616
let compiler =
1717
shaderc::Compiler::new().expect("Failed to create shaderc compiler.");
18+
19+
let mut options = shaderc::CompileOptions::new()
20+
.expect("Failed to create shaderc compile options.");
21+
1822
return ShaderCompiler {
1923
compiler,
20-
default_options: shaderc::CompileOptions::new()
21-
.expect("Failed to set the default shaderc compiler options"),
24+
default_options: options,
2225
};
2326
}
2427
}
@@ -84,8 +87,6 @@ impl ShaderCompiler {
8487
entry_point: &str,
8588
shader_kind: ShaderKind,
8689
) -> Vec<u32> {
87-
// TODO(vmarcella): Investigate into common strategies for reading from files
88-
// efficiently in Rust.
8990
let mut opened_shader_file = std::fs::File::open(path).unwrap();
9091
let mut shader_source = String::new();
9192
opened_shader_file
@@ -94,7 +95,13 @@ impl ShaderCompiler {
9495

9596
let compiled_shader = self
9697
.compiler
97-
.compile_into_spirv(&shader_source, shader_kind, path, entry_point, None)
98+
.compile_into_spirv(
99+
&shader_source,
100+
shader_kind,
101+
path,
102+
entry_point,
103+
Some(&self.default_options),
104+
)
98105
.expect("Failed to compile the shader.");
99106
return compiled_shader.as_binary().to_vec();
100107
}
@@ -109,8 +116,15 @@ impl ShaderCompiler {
109116
) -> Vec<u32> {
110117
let compiled_shader = self
111118
.compiler
112-
.compile_into_spirv(shader_source, shader_kind, name, entry_point, None)
119+
.compile_into_spirv(
120+
shader_source,
121+
shader_kind,
122+
name,
123+
entry_point,
124+
Some(&self.default_options),
125+
)
113126
.expect("Failed to compile the shader.");
127+
114128
return compiled_shader.as_binary().to_vec();
115129
}
116130
}

0 commit comments

Comments
 (0)