Fixed a particularly nasty typo bug. Added more moving sprites. Will need to examine order of draw commands. Need to fix the size/8 for misaligned data.

master
mitchellhansen 5 years ago
parent 709a617cd1
commit e8507f9dfc

@ -61,10 +61,10 @@ void main() {
//p.w = 125; //p.w = 125;
} }
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x); // write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x000000FF) ) | (p.x);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8); // write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x0000FF00) ) | (p.y << 8);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16); // write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0x00FF0000) ) | (p.z << 16);
write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24); // write_buffer.buf[idx] = (write_buffer.buf[idx] & (~0xFF000000) ) | (p.w << 24);
} }

@ -1,6 +1,6 @@
#version 450 #version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(set = 0, binding = 0) buffer wData { layout(set = 0, binding = 0) buffer wData {
int buf[]; int buf[];

@ -19,5 +19,4 @@ void main() {
float gamma = 0.5; float gamma = 0.5;
f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma)); f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma));
f_color = vec4(1,1,1,0.5);
} }

@ -285,6 +285,7 @@ impl CanvasState {
/// Takes physical and capabilities as we don't store that in Canvas /// Takes physical and capabilities as we don't store that in Canvas
pub fn load_shader(&mut self, pub fn load_shader(&mut self,
filename: String, filename: String,
shader_type: ShaderType,
physical: PhysicalDevice, physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> { capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
@ -292,15 +293,30 @@ impl CanvasState {
handle: self.shader_buffers.len() as u32 handle: self.shader_buffers.len() as u32
}); });
let shader = Arc::new(CanvasShader::new_colored( let shader = match shader_type {
filename.clone(), ShaderType::SOLID => {
capabilities.clone(), Arc::new(CanvasShader::new_colored(
self.queue.clone(), filename.clone(),
physical.clone(), capabilities.clone(),
self.device.clone(), self.queue.clone(),
handle.clone(), physical.clone(),
self.render_pass.clone()) self.device.clone(),
); handle.clone(),
self.render_pass.clone())
)
}
ShaderType::IMAGE | ShaderType::TEXTURED => {
Arc::new(CanvasShader::new_textured(
filename.clone(),
capabilities.clone(),
self.queue.clone(),
physical.clone(),
self.device.clone(),
handle.clone(),
self.render_pass.clone())
)
}
};
self.shader_buffers.push(shader.clone()); self.shader_buffers.push(shader.clone());

@ -37,9 +37,9 @@ impl CompuFrame {
} }
/* /*
INPUT_BUFFER -> input -> kernel -> output INPUT_BUFFER -> input -> kernel -> output
v------------------^ v------------------^
OUTPUT_BUFFER -> input X kernel X output OUTPUT_BUFFER -> input X kernel X output
*/ */
pub fn add_chained(&mut self, pub fn add_chained(&mut self,
input_buffer: Arc<CompuBufferHandle>, input_buffer: Arc<CompuBufferHandle>,

@ -96,7 +96,7 @@ impl CompuState {
let kernel_id = (*i.1).clone().handle as usize; let kernel_id = (*i.1).clone().handle as usize;
let buffer = self.compute_buffers.get(buffer_id).unwrap(); let buffer = self.compute_buffers.get(buffer_id).unwrap();
let kernel = self.kernels.get(buffer_id).unwrap(); let kernel = self.kernels.get(kernel_id).unwrap();
let p = kernel.clone().get_pipeline(); let p = kernel.clone().get_pipeline();
let d = buffer.get_descriptor_set(kernel.clone().get_pipeline()); let d = buffer.get_descriptor_set(kernel.clone().get_pipeline());
@ -115,7 +115,7 @@ impl CompuState {
let buffer = self.compute_buffers.get(buffer_id).unwrap(); let buffer = self.compute_buffers.get(buffer_id).unwrap();
let image = canvas.get_image(image_id); let image = canvas.get_image(image_id);
let kernel = self.kernels.get(buffer_id).unwrap(); let kernel = self.kernels.get(kernel_id).unwrap();
let p = kernel.clone().get_pipeline(); let p = kernel.clone().get_pipeline();
let d = buffer.get_descriptor_set(kernel.clone().get_pipeline()); let d = buffer.get_descriptor_set(kernel.clone().get_pipeline());
@ -129,7 +129,7 @@ impl CompuState {
let size = buffer.get_size(); let size = buffer.get_size();
command_buffer = command_buffer command_buffer = command_buffer
.dispatch([size.0,size.1,1], p, d, ()).unwrap() .dispatch([size.0/8,size.1/8,1], p, d, ()).unwrap()
.copy_buffer_to_image(buffer.get_input_buffer(), image).unwrap(); .copy_buffer_to_image(buffer.get_input_buffer(), image).unwrap();
} }
@ -148,8 +148,13 @@ impl CompuState {
let pipeline = kernel.clone().get_pipeline(); let pipeline = kernel.clone().get_pipeline();
let descriptor_set = input_buffer.get_descriptor_set(kernel.clone().get_pipeline()); let descriptor_set = input_buffer.get_descriptor_set(kernel.clone().get_pipeline());
if input_buffer.get_size() != output_buffer.get_size() {
panic!("Buffer sizes not the same");
}
let size = input_buffer.get_size();
command_buffer = command_buffer command_buffer = command_buffer
.dispatch([100,100,1], pipeline, descriptor_set, ()).unwrap() .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap()
.copy_buffer( .copy_buffer(
input_buffer.get_output_buffer(), input_buffer.get_output_buffer(),
output_buffer.get_input_buffer()).unwrap(); output_buffer.get_input_buffer()).unwrap();

@ -166,13 +166,31 @@ pub fn main() {
let mut compu_frame = CompuFrame::new(); let mut compu_frame = CompuFrame::new();
compu_frame.add(compute_buffer.clone(), compute_kernel.clone()); compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); // compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
let mut canvas = CanvasFrame::new(); let mut canvas = CanvasFrame::new();
canvas.draw(&sprite); // canvas.draw(&sprite);
canvas.draw(&sprite2); // canvas.draw(&sprite2);
canvas.draw(&sprite3); // canvas.draw(&sprite3);
canvas.draw(&compu_sprite1); canvas.draw(&compu_sprite1);
canvas.draw(&Sprite::new_with_color((
(elapsed_time + 0.0).sin()/2.0, (elapsed_time + 0.0).sin()/2.0),
(0.09,0.09),
(1.0,0.2,0.5,1.0)
));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.0).sin(), 0.0), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.1).sin(), 0.1), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.2).sin(), 0.2), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.3).sin(), 0.3), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.4).sin(), 0.4), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.5).sin(), 0.5), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.6).sin(), 0.6), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.7).sin(), 0.7), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.8).sin(), 0.8), (0.09,0.09), (1.0,1.0,1.0,1.0)));
canvas.draw(&Sprite::new_with_color(((elapsed_time + 0.9).sin(), 0.9), (0.09,0.09), (1.0,1.0,1.0,1.0)));
{ {
let g = hprof::enter("Run"); let g = hprof::enter("Run");
processor.run(&surface, processor.run(&surface,

@ -11,7 +11,7 @@ use winit::Window;
use crate::compu_state::CompuState; use crate::compu_state::CompuState;
use vulkano::image::ImageUsage; use vulkano::image::ImageUsage;
use crate::compu_frame::CompuFrame; use crate::compu_frame::CompuFrame;
use crate::canvas::{CanvasState, CanvasTextureHandle, CanvasImageHandle}; use crate::canvas::{CanvasState, CanvasTextureHandle, CanvasImageHandle, ShaderType};
use crate::canvas_frame::CanvasFrame; use crate::canvas_frame::CanvasFrame;
use crate::compu_kernel::{CompuKernel, CompuKernelHandle}; use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle}; use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
@ -155,9 +155,9 @@ impl<'a> VkProcessor<'a> {
/// A hardcoded list of shaders which can be proloaded from this function /// A hardcoded list of shaders which can be proloaded from this function
pub fn preload_shaders(&mut self) { pub fn preload_shaders(&mut self) {
self.canvas.load_shader(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone()); self.canvas.load_shader(String::from("color-passthrough"), ShaderType::SOLID, self.physical.clone(), self.capabilities.clone());
self.canvas.load_shader(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone()); self.canvas.load_shader(String::from("simple_texture"), ShaderType::TEXTURED, self.physical.clone(), self.capabilities.clone());
self.canvas.load_shader(String::from("simple_image"), self.physical.clone(), self.capabilities.clone()); self.canvas.load_shader(String::from("simple_image"), ShaderType::IMAGE, self.physical.clone(), self.capabilities.clone());
} }
/// O(n) Lookup for the matching texture string /// O(n) Lookup for the matching texture string

Loading…
Cancel
Save