running. Rust is absolutley amazing. I haven't run this in ~20 commits, yet it only took a few unwrap() fixes and it's back working

master
mitchellhansen 5 years ago
parent 0357296771
commit ebf2cb5322

@ -238,8 +238,11 @@ impl CanvasState {
} }
pub fn create_image(&mut self, dimensions: (u32, u32), usage: ImageUsage) -> Arc<CanvasImageHandle> { pub fn create_image(&mut self, dimensions: (u32, u32), usage: ImageUsage) -> Arc<CanvasImageHandle> {
let handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32});
let image = CanvasImage { let image = CanvasImage {
handle: Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 + 1 }), handle: handle.clone(),
buffer: AttachmentImage::with_usage( buffer: AttachmentImage::with_usage(
self.device.clone(), self.device.clone(),
[dimensions.0, dimensions.1], [dimensions.0, dimensions.1],
@ -247,8 +250,9 @@ impl CanvasState {
usage).unwrap(), usage).unwrap(),
size: dimensions, size: dimensions,
}; };
let handle = image.handle.clone();
self.image_buffers.push(Arc::new(image)); self.image_buffers.push(Arc::new(image));
handle handle
} }
@ -303,7 +307,7 @@ impl CanvasState {
let texture_buffer = self.get_texture_from_file(filename.clone()); let texture_buffer = self.get_texture_from_file(filename.clone());
let handle = Arc::new(CanvasTextureHandle { let handle = Arc::new(CanvasTextureHandle {
handle: self.texture_buffers.len() as u32 + 1 handle: self.texture_buffers.len() as u32
}); });
let texture = Arc::new(CanvasTexture { let texture = Arc::new(CanvasTexture {

@ -23,6 +23,8 @@ pub struct CompuKernel {
compute_pipeline: Option<std::sync::Arc<ComputePipeline<PipelineLayout<shade_runner::layouts::ComputeLayout>>>>, compute_pipeline: Option<std::sync::Arc<ComputePipeline<PipelineLayout<shade_runner::layouts::ComputeLayout>>>>,
compute_kernel_path: PathBuf, compute_kernel_path: PathBuf,
name: String,
shader: CompiledShaders, shader: CompiledShaders,
entry: Entry, entry: Entry,
shader_module: Arc<ShaderModule>, shader_module: Arc<ShaderModule>,
@ -48,7 +50,7 @@ impl CompuKernel {
pub fn new(filename: String, device: Arc<Device>, pub fn new(filename: String, device: Arc<Device>,
handle: Arc<CompuKernelHandle>) -> CompuKernel { handle: Arc<CompuKernelHandle>) -> CompuKernel {
let compute_path = CompuKernel::get_path(filename); let compute_path = CompuKernel::get_path(filename.clone());
let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap();
@ -64,6 +66,7 @@ impl CompuKernel {
CompuKernel { CompuKernel {
name: filename,
handle: handle, handle: handle,
device: device, device: device,
shader: shader, shader: shader,
@ -120,6 +123,13 @@ impl CompuKernel {
self.get_pipeline() self.get_pipeline()
} }
pub fn get_handle(&self) -> Arc<CompuKernelHandle> {
self.handle.clone()
}
pub fn get_name(&self) -> String {
self.name.clone()
}
} }
#[repr(C)] #[repr(C)]

@ -30,6 +30,7 @@ pub struct CompuState {
} }
impl CompuState { impl CompuState {
pub fn new() -> CompuState { pub fn new() -> CompuState {
CompuState { CompuState {
compute_buffers: vec![], compute_buffers: vec![],
@ -44,11 +45,11 @@ impl CompuState {
device: Arc<Device>) -> Arc<CompuBufferHandle> { device: Arc<Device>) -> Arc<CompuBufferHandle> {
let handle = Arc::new(CompuBufferHandle { let handle = Arc::new(CompuBufferHandle {
handle: self.compute_buffers.len() as u32 + 1 handle: self.compute_buffers.len() as u32
}); });
self.compute_buffers.push( self.compute_buffers.push(
CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone())); (CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone())));
handle handle
} }
@ -66,14 +67,23 @@ impl CompuState {
device: Arc<Device>) -> Arc<CompuKernelHandle> { device: Arc<Device>) -> Arc<CompuKernelHandle> {
let handle = Arc::new(CompuKernelHandle { let handle = Arc::new(CompuKernelHandle {
handle: self.kernels.len() as u32 + 1 handle: self.kernels.len() as u32
}); });
self.kernels.push(CompuKernel::new(filename, device.clone(), handle.clone())); self.kernels.push((CompuKernel::new(filename, device.clone(), handle.clone())));
handle handle
} }
pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> {
for i in self.kernels.clone() {
if i.get_name() == kernel_name {
return Some(i.get_handle());
}
}
None
}
pub fn compute_commands(&mut self, pub fn compute_commands(&mut self,
compute_frame: CompuFrame, compute_frame: CompuFrame,
mut command_buffer: AutoCommandBufferBuilder, mut command_buffer: AutoCommandBufferBuilder,

@ -71,6 +71,10 @@ fn main() {
let mut processor = vkprocessor::VkProcessor::new(&instance, &surface); let mut processor = vkprocessor::VkProcessor::new(&instance, &surface);
processor.create_swapchain(&surface); processor.create_swapchain(&surface);
processor.preload_kernels();
processor.preload_shaders();
processor.preload_textures();
let mut timer = Timer::new(); let mut timer = Timer::new();
let mut frame_future = Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>; let mut frame_future = Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
@ -85,6 +89,7 @@ fn main() {
let sprite = Sprite::new_with_color((0.,0.), (0.1,0.1), (1.,0.,0.,1.)); let sprite = Sprite::new_with_color((0.,0.), (0.1,0.1), (1.,0.,0.,1.));
let sprite2 = Sprite::new_with_color((-1.,-0.5), (0.1,0.1), (0.,1.,0.,1.)); let sprite2 = Sprite::new_with_color((-1.,-0.5), (0.1,0.1), (0.,1.,0.,1.));
@ -93,7 +98,6 @@ fn main() {
let image_data = load_raw(String::from("funky-bird.jpg")); let image_data = load_raw(String::from("funky-bird.jpg"));
let compute_buffer = processor.new_compute_buffer(image_data.0, image_data.1, 4); let compute_buffer = processor.new_compute_buffer(image_data.0, image_data.1, 4);
// TODO need to implement
let compute_kernel = processor.get_kernel_handle(String::from("simple-edge.compute")) let compute_kernel = processor.get_kernel_handle(String::from("simple-edge.compute"))
.expect("Can't find that kernel"); .expect("Can't find that kernel");

@ -133,8 +133,12 @@ impl<'a> VkProcessor<'a> {
pub fn preload_textures(&mut self) { pub fn preload_textures(&mut self) {
self.canvas.load_texture(String::from("funky-bird.jpg")); 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"));
} }
pub fn preload_kernels(&mut self) { pub fn preload_kernels(&mut self) {
self.compute_state.new_kernel(String::from("simple-homogenize.compute"), self.device.clone());
self.compute_state.new_kernel(String::from("simple-edge.compute"), self.device.clone()); self.compute_state.new_kernel(String::from("simple-edge.compute"), self.device.clone());
} }
pub fn preload_shaders(&mut self) { pub fn preload_shaders(&mut self) {
@ -145,7 +149,7 @@ impl<'a> VkProcessor<'a> {
None None
} }
pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> { pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> {
None self.compute_state.get_kernel_handle(kernel_name)
} }
pub fn get_shader_handle(&self, shader_name: String) -> Option<Arc<CanvasShaderHandle>> { pub fn get_shader_handle(&self, shader_name: String) -> Option<Arc<CanvasShaderHandle>> {
None None

Loading…
Cancel
Save