|
|
@ -22,6 +22,7 @@ use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
|
|
|
use crate::canvas_frame::CanvasFrame;
|
|
|
|
use crate::canvas_frame::CanvasFrame;
|
|
|
|
use std::hash::Hash;
|
|
|
|
use std::hash::Hash;
|
|
|
|
use crate::canvas_shader::CanvasShader;
|
|
|
|
use crate::canvas_shader::CanvasShader;
|
|
|
|
|
|
|
|
use crate::canvas_buffer::{CanvasImage, CanvasTexture};
|
|
|
|
|
|
|
|
|
|
|
|
// Canvas is the accumulator of Sprites for drawing
|
|
|
|
// Canvas is the accumulator of Sprites for drawing
|
|
|
|
|
|
|
|
|
|
|
@ -103,48 +104,6 @@ pub struct CanvasShaderHandle {
|
|
|
|
pub handle: u32
|
|
|
|
pub handle: u32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
|
|
|
pub struct CanvasTexture {
|
|
|
|
|
|
|
|
handle: Arc<CanvasTextureHandle>,
|
|
|
|
|
|
|
|
buffer: Arc<ImmutableImage<Format>>,
|
|
|
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
size: (u32, u32),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl CanvasTexture {
|
|
|
|
|
|
|
|
fn get_descriptor_set(&self,
|
|
|
|
|
|
|
|
shader: Arc<CanvasShader>,
|
|
|
|
|
|
|
|
sampler: Arc<Sampler>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|
|
|
|
shader.clone().get_pipeline().clone(), 0,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_sampled_image(self.buffer.clone(), sampler.clone()).unwrap()
|
|
|
|
|
|
|
|
.build().unwrap());
|
|
|
|
|
|
|
|
o
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
|
|
|
pub struct CanvasImage {
|
|
|
|
|
|
|
|
handle: Arc<CanvasImageHandle>,
|
|
|
|
|
|
|
|
buffer: Arc<AttachmentImage>,
|
|
|
|
|
|
|
|
size: (u32, u32),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl CanvasImage {
|
|
|
|
|
|
|
|
fn get_descriptor_set(&mut self, shader: Arc<CanvasShader>)
|
|
|
|
|
|
|
|
-> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
|
|
|
|
shader.clone().get_pipeline().clone(), 0,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_image(self.buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
.build().unwrap());
|
|
|
|
|
|
|
|
o
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct CanvasState {
|
|
|
|
pub struct CanvasState {
|
|
|
|
dynamic_state: DynamicState,
|
|
|
|
dynamic_state: DynamicState,
|
|
|
@ -199,7 +158,6 @@ impl CanvasState {
|
|
|
|
device: Arc<Device>,
|
|
|
|
device: Arc<Device>,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
physical: PhysicalDevice,
|
|
|
|
capabilities: Capabilities) -> CanvasState {
|
|
|
|
capabilities: Capabilities) -> CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
let solid_color_kernel = String::from("color-passthrough");
|
|
|
|
let solid_color_kernel = String::from("color-passthrough");
|
|
|
|
let texture_kernel = String::from("simple_texture");
|
|
|
|
let texture_kernel = String::from("simple_texture");
|
|
|
|
|
|
|
|
|
|
|
@ -238,8 +196,7 @@ 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 handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let image = CanvasImage {
|
|
|
|
let image = CanvasImage {
|
|
|
|
handle: handle.clone(),
|
|
|
|
handle: handle.clone(),
|
|
|
@ -324,7 +281,6 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_texture_handle(&self, texture_name: String)
|
|
|
|
pub fn get_texture_handle(&self, texture_name: String)
|
|
|
|
-> Option<Arc<CanvasTextureHandle>> {
|
|
|
|
-> Option<Arc<CanvasTextureHandle>> {
|
|
|
|
|
|
|
|
|
|
|
|
for i in self.texture_buffers.clone() {
|
|
|
|
for i in self.texture_buffers.clone() {
|
|
|
|
if i.name == texture_name {
|
|
|
|
if i.name == texture_name {
|
|
|
|
return Some(i.handle.clone());
|
|
|
|
return Some(i.handle.clone());
|
|
|
@ -335,7 +291,6 @@ impl CanvasState {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_texture(&self, texture_handle: Arc<CanvasTextureHandle>)
|
|
|
|
pub fn get_texture(&self, texture_handle: Arc<CanvasTextureHandle>)
|
|
|
|
-> Arc<ImmutableImage<Format>> {
|
|
|
|
-> Arc<ImmutableImage<Format>> {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = texture_handle.handle as usize;
|
|
|
|
let handle = texture_handle.handle as usize;
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(i) = self.texture_buffers.get(handle) {
|
|
|
|
if let Some(i) = self.texture_buffers.get(handle) {
|
|
|
@ -355,10 +310,25 @@ impl CanvasState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn allocate_vertex_buffers(&mut self, device: Arc<Device>) {
|
|
|
|
fn allocate_vertex_buffers(&mut self, device: Arc<Device>) {
|
|
|
|
self.colored_vertex_buffer.clear();
|
|
|
|
|
|
|
|
self.textured_vertex_buffer.clear();
|
|
|
|
|
|
|
|
self.image_vertex_buffer.clear();
|
|
|
|
self.image_vertex_buffer.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
So a bit of brainstorming with the shaders:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I compile shaders into their respective buffers and add them to a descriptor set
|
|
|
|
|
|
|
|
along with the textures or whatever other resource buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
So I'm gonna fix that texturing issue by adding vertex texture coordinate attributes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Still don't really know how I'm gonna do this...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* Going to definitely need to use the CpuAccessbileBuffer
|
|
|
|
|
|
|
|
* Maybe calculate deltas between frames???
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
//TODO should probably use cpu accessible buffer instead of recreating immutes each frame
|
|
|
|
//TODO should probably use cpu accessible buffer instead of recreating immutes each frame
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
CpuAccessibleBuffer::from_iter(
|
|
|
|
CpuAccessibleBuffer::from_iter(
|
|
|
@ -369,6 +339,21 @@ impl CanvasState {
|
|
|
|
).unwrap().0;
|
|
|
|
).unwrap().0;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if self.colored_vertex_buffer.len() == 0 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.colored_vertex_buffer.clear();
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let g = hprof::enter("Colored Vertex Buffer : From Data");
|
|
|
|
|
|
|
|
self.colored_vertex_buffer.push(
|
|
|
|
|
|
|
|
ImmutableBuffer::from_data(self.colored_drawables.clone(),
|
|
|
|
|
|
|
|
BufferUsage::vertex_buffer(),
|
|
|
|
|
|
|
|
self.queue.clone()).unwrap().0
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let g = hprof::enter("Colored Vertex Buffer : From Iter");
|
|
|
|
self.colored_vertex_buffer.push(
|
|
|
|
self.colored_vertex_buffer.push(
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
self.colored_drawables.iter().cloned(),
|
|
|
|
self.colored_drawables.iter().cloned(),
|
|
|
@ -376,9 +361,20 @@ impl CanvasState {
|
|
|
|
self.queue.clone(),
|
|
|
|
self.queue.clone(),
|
|
|
|
).unwrap().0
|
|
|
|
).unwrap().0
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.colored_vertex_buffer.clear();
|
|
|
|
|
|
|
|
//println!("{:?}", self.colored_vertex_buffer.last().unwrap().size());
|
|
|
|
|
|
|
|
//self.colored_vertex_buffer.pop();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// println!("{} {}", self.textured_vertex_buffer.len() , self.textured_drawables.len());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if self.textured_vertex_buffer.len() != self.textured_drawables.len() {
|
|
|
|
|
|
|
|
self.textured_vertex_buffer.clear();
|
|
|
|
for (k, v) in self.textured_drawables.drain() {
|
|
|
|
for (k, v) in self.textured_drawables.drain() {
|
|
|
|
println!("{:?}", v.len());
|
|
|
|
{
|
|
|
|
|
|
|
|
let g = hprof::enter("Textured Vertex Buffer : From Iter");
|
|
|
|
self.textured_vertex_buffer.insert(
|
|
|
|
self.textured_vertex_buffer.insert(
|
|
|
|
k.clone(),
|
|
|
|
k.clone(),
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
|
ImmutableBuffer::from_iter(
|
|
|
@ -388,10 +384,22 @@ impl CanvasState {
|
|
|
|
).unwrap().0,
|
|
|
|
).unwrap().0,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// let g = hprof::enter("Textured Vertex Buffer : From Data");
|
|
|
|
|
|
|
|
// self.textured_vertex_buffer.insert(
|
|
|
|
|
|
|
|
// k.clone(),
|
|
|
|
|
|
|
|
// ImmutableBuffer::from_data(v.first().unwrap().clone(),
|
|
|
|
|
|
|
|
// BufferUsage::vertex_buffer(),
|
|
|
|
|
|
|
|
// self.queue.clone()
|
|
|
|
|
|
|
|
// ).unwrap().0
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//self.textured_vertex_buffer.pop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_solid_color_descriptor_set(&self, kernel: Arc<CanvasShader>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
fn get_solid_color_descriptor_set(&self, kernel: Arc<CanvasShader>) -> Box<dyn DescriptorSet + Send + Sync> {
|
|
|
|
|
|
|
|
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
PersistentDescriptorSet::start(
|
|
|
|
kernel.clone().get_pipeline().clone(), 0,
|
|
|
|
kernel.clone().get_pipeline().clone(), 0,
|
|
|
@ -414,32 +422,36 @@ impl CanvasState {
|
|
|
|
// Solid colors
|
|
|
|
// Solid colors
|
|
|
|
let mut shader = self.shader_buffers.get("color-passthrough").unwrap().clone();
|
|
|
|
let mut shader = self.shader_buffers.get("color-passthrough").unwrap().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs.
|
|
|
|
|
|
|
|
// But we can pass in multiple vertex buffers
|
|
|
|
|
|
|
|
if !self.colored_vertex_buffer.is_empty() {
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
&self.dynamic_state.clone(),
|
|
|
|
&self.dynamic_state.clone(),
|
|
|
|
self.colored_vertex_buffer.clone(),
|
|
|
|
self.colored_vertex_buffer.clone(),
|
|
|
|
(), (),
|
|
|
|
(), (),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Images
|
|
|
|
// Images
|
|
|
|
let mut shader = self.shader_buffers.get("simple_texture").unwrap().clone();
|
|
|
|
let mut shader = self.shader_buffers.get("simple_texture").unwrap().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !self.textured_vertex_buffer.is_empty() {
|
|
|
|
let handle = self.get_texture_handle(String::from("funky-bird.jpg")).unwrap().clone();
|
|
|
|
let handle = self.get_texture_handle(String::from("funky-bird.jpg")).unwrap().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO : BAD BAD BAD. SELECTS FIRST TEXTURE ONLY!!!!!!!!!!!!
|
|
|
|
let descriptor_set = self.texture_buffers.first().clone().unwrap().clone()
|
|
|
|
let descriptor_set = self.texture_buffers.first().clone().unwrap().clone()
|
|
|
|
.get_descriptor_set(shader.clone(), self.sampler.clone());
|
|
|
|
.get_descriptor_set(shader.clone(), self.sampler.clone());
|
|
|
|
|
|
|
|
|
|
|
|
let vertex_buffer = self.textured_vertex_buffer.get(&handle).unwrap().clone();
|
|
|
|
let vertex_buffer = self.textured_vertex_buffer.get(&handle).unwrap().clone();
|
|
|
|
|
|
|
|
|
|
|
|
println!("{:?}", self.texture_buffers.len());
|
|
|
|
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
command_buffer = command_buffer.draw(
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
shader.get_pipeline().clone(),
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
|
|
|
vec![descriptor_set], ()
|
|
|
|
vec![descriptor_set], (),
|
|
|
|
).unwrap();
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
/*for (shader_type, kernel) in self.shader_kernels.clone().iter() {
|
|
|
|
/*for (shader_type, kernel) in self.shader_kernels.clone().iter() {
|
|
|
|
match shader_type {
|
|
|
|
match shader_type {
|
|
|
|
ShaderType::SOLID => {
|
|
|
|
ShaderType::SOLID => {
|
|
|
|