|
|
|
@ -39,7 +39,7 @@ pub struct VkProcessor<'a> {
|
|
|
|
|
compute_state: CompuState,
|
|
|
|
|
|
|
|
|
|
capabilities: Capabilities,
|
|
|
|
|
canvas: CanvasState,
|
|
|
|
|
canvas_state: CanvasState,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -79,7 +79,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
swapchain_recreate_needed: false,
|
|
|
|
|
compute_state: CompuState::new(),
|
|
|
|
|
capabilities: capabilities.clone(),
|
|
|
|
|
canvas: CanvasState::new(queue, device, physical, capabilities),
|
|
|
|
|
canvas_state: CanvasState::new(queue, device, physical, capabilities),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -142,11 +142,11 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
/// A hardcoded list of textures which can be preloaded from this function
|
|
|
|
|
pub fn preload_textures(&mut self) {
|
|
|
|
|
self.canvas.load_texture(String::from("funky-bird.jpg"));
|
|
|
|
|
self.canvas.load_texture(String::from("button.png"));
|
|
|
|
|
self.canvas.load_texture(String::from("background.jpg"));
|
|
|
|
|
self.canvas.load_texture(String::from("test2.png"));
|
|
|
|
|
self.canvas.load_texture(String::from("sfml.png"));
|
|
|
|
|
self.canvas_state.load_texture(String::from("funky-bird.jpg"));
|
|
|
|
|
self.canvas_state.load_texture(String::from("button.png"));
|
|
|
|
|
self.canvas_state.load_texture(String::from("background.jpg"));
|
|
|
|
|
self.canvas_state.load_texture(String::from("test2.png"));
|
|
|
|
|
self.canvas_state.load_texture(String::from("sfml.png"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A hardcoded list of kernels which can be preloaded from this function
|
|
|
|
@ -157,15 +157,15 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
/// A hardcoded list of shaders which can be proloaded from this function
|
|
|
|
|
pub fn preload_shaders(&mut self) {
|
|
|
|
|
self.canvas.load_shader::<GenericShader>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas.load_shader::<GenericShader>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas.load_shader::<GenericShader>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas.load_shader::<TextShader>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas_state.load_shader::<GenericShader>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas_state.load_shader::<GenericShader>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas_state.load_shader::<GenericShader>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
self.canvas_state.load_shader::<TextShader>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// O(n) Lookup for the matching texture string
|
|
|
|
|
pub fn get_texture_handle(&self, texture_name: String) -> Option<Arc<CanvasTextureHandle>> {
|
|
|
|
|
self.canvas.get_texture_handle(texture_name)
|
|
|
|
|
self.canvas_state.get_texture_handle(texture_name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// O(n) Lookup for the matching kernel string
|
|
|
|
@ -175,7 +175,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
/// O(n) Lookup for the matching shader string
|
|
|
|
|
pub fn get_shader_handle(&self, shader_name: String) -> Option<Arc<CompiledGraphicsPipelineHandle>> {
|
|
|
|
|
self.canvas.get_shader_handle(shader_name)
|
|
|
|
|
self.canvas_state.get_shader_handle(shader_name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create a new image which has the transfer usage
|
|
|
|
@ -184,7 +184,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
usage.transfer_destination = true;
|
|
|
|
|
usage.storage = true;
|
|
|
|
|
|
|
|
|
|
self.canvas.create_image(dimensions, usage)
|
|
|
|
|
self.canvas_state.create_image(dimensions, usage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Builds a compute buffer and returns it's handle
|
|
|
|
@ -215,14 +215,14 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
let g = hprof::enter("Frame buffer, future, swapchain recreate");
|
|
|
|
|
let mut framebuffers =
|
|
|
|
|
self.canvas.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
|
|
|
|
|
self.canvas_state.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
|
|
|
|
|
|
|
|
|
|
// Whenever the window resizes we need to recreate everything dependent on the window size.
|
|
|
|
|
// In this example that includes the swapchain, the framebuffers and the dynamic state viewport.
|
|
|
|
|
if self.swapchain_recreate_needed {
|
|
|
|
|
self.recreate_swapchain(surface);
|
|
|
|
|
framebuffers =
|
|
|
|
|
self.canvas.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
|
|
|
|
|
self.canvas_state.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
|
|
|
|
|
self.swapchain_recreate_needed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -247,7 +247,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
let g = hprof::enter("Canvas creates GPU buffers");
|
|
|
|
|
// take the canvas frame and create the vertex buffers
|
|
|
|
|
// TODO: This performs gpu buffer creation. Shouldn't be in hotpath??
|
|
|
|
|
self.canvas.draw(canvas_frame);
|
|
|
|
|
self.canvas_state.draw(canvas_frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut command_buffer =
|
|
|
|
@ -255,13 +255,13 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
let g = hprof::enter("Push compute commands to command buffer");
|
|
|
|
|
// Add the compute commands
|
|
|
|
|
let mut command_buffer = self.compute_state.compute_commands(compute_frame, command_buffer, &self.canvas);
|
|
|
|
|
let mut command_buffer = self.compute_state.compute_commands(compute_frame, command_buffer, &self.canvas_state);
|
|
|
|
|
drop(g);
|
|
|
|
|
|
|
|
|
|
let g = hprof::enter("Push draw commands to command buffer");
|
|
|
|
|
|
|
|
|
|
// Add the draw commands
|
|
|
|
|
let mut command_buffer = self.canvas.draw_commands(command_buffer, framebuffers, image_num);
|
|
|
|
|
let mut command_buffer = self.canvas_state.draw_commands(command_buffer, framebuffers, image_num);
|
|
|
|
|
|
|
|
|
|
// And build
|
|
|
|
|
let command_buffer = command_buffer.build().unwrap();
|
|
|
|
|