Going to just normalize to a single hardcoded enum of vertex definitions. Seems like quite a backpeddle....

master
mitchellhansen 5 years ago
parent cd0c1e6052
commit 80c0d323be

@ -39,8 +39,18 @@ In Shader lie the shader compilers, pipelines, and supporting data.
I need to put them where I create them. The actual shader doesn't. I need to put them where I create them. The actual shader doesn't.
=== canvas frame ===
The current workflow:
enum of vertex types
sprite holds vertex::type1
poly holds vertex::type2
canvasframe holds <enumType>
canvasState.run takes canvasFrame<enumType>
canvasState.draw_commands_test(command_buffer, framebuffers, image_num, canvas_frame);
@ -48,13 +58,35 @@ In Shader lie the shader compilers, pipelines, and supporting data.
-------------------- --------------------
===== Links =====
Dynamic Keys in HashMap
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=b4630cf98afa88fc0fbffdb0112af1c1
VertexDefinition
https://github.com/tomaka/vulkano-examples/blob/81f5a4eb3c5f3fcc6a194d3c41e53b2bc66f7add/gltf/gltf_system.rs#L687-L795
pub enum Content {
Text(String),
Number(u32),
}
impl From for String {
fn wrap(self) {
Content::Text(self)
}
}
impl From for u32 {
fn wrap(self) {
Content::Number(self)
}
}
fn any_content<T>(value : T) where T : IntoContent {
let content : Content = value.wrap();
}

@ -11,14 +11,12 @@ use std::any::Any;
// I don't think this is going to work without getting into Box'ing // I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<V, H> where H: Handle { pub trait DrawableTest<VTypes: Into<VertexTypes>, H: Handle + DynHash> {
fn get_vertices(&self) -> Vec<V>; fn get_vertices(&self) -> VTypes;
fn get_handle(&self) -> H; fn get_handle(&self) -> H;
} }
pub mod dynhash {
mod dynhash {
use std::any::Any; use std::any::Any;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
@ -73,17 +71,16 @@ mod dynhash {
} }
} }
use crate::canvas::canvas_frame::dynhash::DynHash; use crate::canvas::canvas_frame::dynhash::DynHash;
use crate::VertexTypes;
// CanvasFrameTest will be drawn to by objects implementing DrawableTest // CanvasFrameTest will be drawn to by objects implementing DrawableTest
pub struct CanvasFrameTest<VTypes> { pub struct CanvasFrameTest<VTypes> {
pub map: HashMap<Box<dyn DynHash>, Vec<VTypes>>, pub map: HashMap<Box<dyn DynHash>, VTypes>,
} }
impl<VTypes> CanvasFrameTest<VTypes> { impl<VTypes> CanvasFrameTest<VTypes> {
pub fn draw(&mut self, drawable: Vec<VTypes>) { pub fn draw(&mut self, drawable: VTypes) {
self.map.insert(Box::new(10), drawable); self.map.insert(Box::new(10), drawable);
} }
} }
@ -133,18 +130,6 @@ impl CanvasFrame {
} }
} }
// pub fn draw_test<V : VertexDefinitionAndData, H: Handle, In>(&mut self, drawable: &dyn DrawableTest<V, H, In>) {
// let h = drawable.get_handle();
//
// let v = drawable.get_vertices();
//
// let v = v.get(0).unwrap();
//
// // need to fill up the drawables....
//
//
// }
// TODO: Fix this for text and fonts // TODO: Fix this for text and fonts
/// Accumulates the drawables collected Vertex2D's /// Accumulates the drawables collected Vertex2D's

@ -2,7 +2,7 @@ use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer}; use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
use std::sync::Arc; use std::sync::Arc;
use vulkano::format::{ClearValue, Format, R8Unorm}; use vulkano::format::{ClearValue, Format, R8Unorm, ClearValuesTuple};
use vulkano::framebuffer::{FramebufferAbstract, Framebuffer, RenderPass, RenderPassAbstract}; use vulkano::framebuffer::{FramebufferAbstract, Framebuffer, RenderPass, RenderPassAbstract};
use vulkano::device::{Device, Queue}; use vulkano::device::{Device, Queue};
use vulkano::instance::PhysicalDevice; use vulkano::instance::PhysicalDevice;
@ -33,6 +33,7 @@ use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, Ca
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont}; use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline; use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline;
use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::VertexTypes;
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers /// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
@ -101,6 +102,7 @@ impl CanvasState {
device: Arc<Device>, device: Arc<Device>,
physical: PhysicalDevice, physical: PhysicalDevice,
capabilities: Capabilities) -> CanvasState { capabilities: Capabilities) -> CanvasState {
let format = capabilities.supported_formats[0].0; let format = capabilities.supported_formats[0].0;
let render_pass = Arc::new(vulkano::single_pass_renderpass!( let render_pass = Arc::new(vulkano::single_pass_renderpass!(
@ -488,11 +490,11 @@ impl CanvasState {
// This is taking in a canvas frame, which should be some sort of matrix of vertices of generic // This is taking in a canvas frame, which should be some sort of matrix of vertices of generic
// types and handles // types and handles
pub fn draw_commands_test<T: 'static + Send + Sync + Clone>(&mut self, pub fn draw_commands_test<VTypes: Into<VertexTypes>>(&mut self,
mut command_buffer: AutoCommandBufferBuilder, mut command_buffer: AutoCommandBufferBuilder,
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>, framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
image_num: usize, image_num: usize,
canvas_frame: CanvasFrameTest<T>) -> AutoCommandBufferBuilder { canvas_frame: CanvasFrameTest<VTypes>) -> AutoCommandBufferBuilder {
// Specify the color to clear the framebuffer with i.e. blue // Specify the color to clear the framebuffer with i.e. blue
let clear_values = vec!( let clear_values = vec!(
@ -513,32 +515,47 @@ impl CanvasState {
framebuffers[image_num].clone(), false, clear_values.clone(), framebuffers[image_num].clone(), false, clear_values.clone(),
).unwrap(); ).unwrap();
// Solid colors
let mut shader = self.shader_buffers.get(
self.get_shader_handle(String::from("color-passthrough"))
.unwrap().clone().get_handle() as usize
).unwrap();
for (k,v) in canvas_frame.map { for (k,v) in canvas_frame.map {
let value : Vec<T> = v.iter().map(|v| v.clone()).collect(); let buffer: Arc<(dyn BufferAccess + Send + Sync)> = match v.into() {
VertexTypes::TexturedType(vertices) => {
// Solid colors
let mut shader = self.shader_buffers.get(
self.get_shader_handle(String::from("color-passthrough"))
.unwrap().clone().get_handle() as usize
).unwrap();
let buffer = ImmutableBuffer::from_iter(
vertices.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0;
if !self.colored_vertex_buffer.is_empty() {
command_buffer = command_buffer.draw(
shader.get_pipeline().clone(),
&self.dynamic_state.clone(),
vec![buffer.clone()],
(), (),
).unwrap();
}
buffer
},
VertexTypes::VType2(vertices) => {
ImmutableBuffer::from_iter(
vertices.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0
}
};
let buffer : Arc<(dyn BufferAccess + Send + Sync)> = ImmutableBuffer::from_iter(
value.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
).unwrap().0;
if !self.colored_vertex_buffer.is_empty() {
command_buffer = command_buffer.draw(
shader.get_pipeline().clone(),
&self.dynamic_state.clone(),
vec![buffer.clone()],
(), (),
).unwrap();
}
} }
command_buffer command_buffer

@ -18,7 +18,7 @@ impl Handle for CanvasFontHandle {
/// Typed wrapper for a u32 handle /// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CanvasTextureHandle { pub struct CanvasTextureHandle {
pub(in crate::canvas) handle: u32 pub/*(in crate::canvas)*/ handle: u32
} }
impl Handle for CanvasTextureHandle { impl Handle for CanvasTextureHandle {

@ -25,10 +25,11 @@ use crate::util::load_raw;
use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance}; use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance};
use vulkano::instance::debug::DebugCallback; use vulkano::instance::debug::DebugCallback;
use crate::compute::compu_frame::CompuFrame; use crate::compute::compu_frame::CompuFrame;
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest}; use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest, DrawableTest};
use crate::compute::managed::compu_sprite::CompuSprite; use crate::compute::managed::compu_sprite::CompuSprite;
use std::sync::Arc; use std::sync::Arc;
use crate::canvas::managed::handles::CanvasTextureHandle; use crate::canvas::managed::handles::{CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::dynhash::DynHash;
pub mod util; pub mod util;
@ -55,22 +56,48 @@ pub mod compute;
*/ */
pub struct ImplVertexData1 {
pub x: i32, #[derive(Clone)]
pub y: i32, pub struct TextureVertex2D {
pub v_position: [f32; 2],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(TextureVertex2D, v_position, ti_position);
#[derive(Clone)]
pub struct ColorVertex2D {
pub v_position: [f32; 2],
pub color: [f32; 4],
}
vulkano::impl_vertex!(ColorVertex2D, v_position, color);
#[derive(Clone)]
pub struct ImageVertex2D {
pub v_position: [f32; 2],
pub color: [f32; 4],
} }
vulkano::impl_vertex!(ImageVertex2D, v_position, color);
pub struct ImplVertexData2 { #[derive(Clone)]
pub x: i32, pub enum VertexTypes {
pub y: i32, TextureType(Vec<TextureVertex2D>),
ColorType(Vec<ColorVertex2D>),
ImageType(Vec<ImageVertex2D>),
} }
impl ImplVertexData1 {} pub struct DrawableTestee {
impl ImplVertexData2 {} vertices: VertexTypes,
handle: Arc<CanvasTextureHandle>,
}
impl<VTypes: Into<VertexTypes>, H: Handle + DynHash> DrawableTest<VTypes, H> for DrawableTestee {
fn get_vertices(&self) -> VTypes {
unimplemented!()
}
enum VertexTypes { fn get_handle(&self) -> H {
VType1(ImplVertexData1), unimplemented!()
VType2(ImplVertexData2), }
} }
pub fn main() { pub fn main() {
@ -199,27 +226,30 @@ pub fn main() {
break; break;
} }
// let dt = DrawableTestee{ let sprite = Sprite::new((0.0,0.0), (0.0,0.0));
// vertices: vec![ImplVertexData{ x: 0, y: 0 }],
// handle: Arc::new(CanvasTextureHandle{ handle: 0 }) let dt = DrawableTestee {
// }; vertices: VertexTypes::TexturedType(vec![ImplVertexData1 {x:0,y:0}]),
let mut cft : CanvasFrameTest<VertexTypes> = handle: Arc::new(CanvasTextureHandle{ handle: 0 })
};
let mut canvas_frame : CanvasFrameTest<VertexTypes> =
CanvasFrameTest{ map: Default::default() }; CanvasFrameTest{ map: Default::default() };
// cft.draw(&dt); canvas_frame.draw(dt.vertices);
canvas_frame.draw(sprite.get_vertices());
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(&funky_sprite); // canvas.draw(&funky_sprite);
canvas.draw(&test_polygon); // canvas.draw(&test_polygon);
{ {
let g = hprof::enter("Run"); let g = hprof::enter("Run");
processor.run(&surface, processor.run(&surface,
canvas, canvas_frame,
compu_frame); compu_frame);
} }
} }

@ -1,13 +1,18 @@
use std::sync::Arc; use std::sync::Arc;
use crate::util::vertex_3d::Vertex3D; use crate::util::vertex_3d::Vertex3D;
use crate::canvas::*; use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance; use crate::canvas::managed::shader::text_shader::GlyphInstance;
use crate::canvas::canvas_frame::{DrawableTest, Drawable}; use crate::canvas::canvas_frame::{DrawableTest, Drawable};
use crate::{VertexTypes, ImplVertexData1};
use crate::canvas::canvas_frame::dynhash::DynHash;
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Sprite { pub struct Sprite {
pub verts: VertexTypes::TexturedType(vec![]),
pub vertices: [(f32, f32, f32); 6], pub vertices: [(f32, f32, f32); 6],
pub ti_position: [(f32, f32); 6], pub ti_position: [(f32, f32); 6],
@ -98,6 +103,18 @@ impl Sprite {
} }
} }
} }
impl<V: Into<VertexTypes>, H: Handle + DynHash> DrawableTest<V, H> for Sprite{
fn get_vertices(&self) -> V {
VertexTypes::TexturedType(vec![ImplVertexData1{ x: 0, y: 0 }])
}
fn get_handle(&self) -> H {
self.texture_handle.unwrap()
}
}
impl Drawable for Sprite { impl Drawable for Sprite {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> { fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec() self.vertices.to_vec()

@ -11,7 +11,7 @@ use winit::Window;
use crate::compute::compu_state::CompuState; use crate::compute::compu_state::CompuState;
use vulkano::image::ImageUsage; use vulkano::image::ImageUsage;
use crate::compute::compu_frame::CompuFrame; use crate::compute::compu_frame::CompuFrame;
use crate::canvas::canvas_frame::CanvasFrame; use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
use std::time::Duration; use std::time::Duration;
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags}; use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition}; use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition};
@ -21,6 +21,7 @@ use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::text_shader::TextShader; use crate::canvas::managed::shader::text_shader::TextShader;
use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::{ImplVertexData1, VertexTypes};
/// VKProcessor holds the vulkan instance information, the swapchain, /// VKProcessor holds the vulkan instance information, the swapchain,
@ -223,9 +224,10 @@ impl<'a> VkProcessor<'a> {
} }
/// ///
pub fn run(&mut self, pub fn run<VTypes: Into<VertexTypes>>(&mut self,
surface: &'a Arc<Surface<Window>>, surface: &'a Arc<Surface<Window>>,
canvas_frame: CanvasFrame, //canvas_frame: CanvasFrame,
canvas_frame: CanvasFrameTest<VTypes>,
compute_frame: CompuFrame, compute_frame: CompuFrame,
) { ) {
@ -268,7 +270,8 @@ impl<'a> VkProcessor<'a> {
// take the canvas frame and create the vertex buffers // take the canvas frame and create the vertex buffers
// TODO: This performs gpu buffer creation. Shouldn't be in hotpath?? // TODO: This performs gpu buffer creation. Shouldn't be in hotpath??
let g = hprof::enter("Canvas creates GPU buffers"); let g = hprof::enter("Canvas creates GPU buffers");
self.canvas_state.draw(canvas_frame); //self.canvas_state.draw(canvas_frame);
} }
let mut command_buffer = let mut command_buffer =
@ -282,7 +285,9 @@ impl<'a> VkProcessor<'a> {
let g = hprof::enter("Push draw commands to command buffer"); let g = hprof::enter("Push draw commands to command buffer");
// Add the draw commands // Add the draw commands
let mut command_buffer = self.canvas_state.draw_commands(command_buffer, framebuffers, image_num); //let mut command_buffer = self.canvas_state.draw_commands(command_buffer, framebuffers, image_num);
let mut command_buffer =
self.canvas_state.draw_commands_test(command_buffer, framebuffers, image_num, canvas_frame);
// And build // And build
let command_buffer = command_buffer.build().unwrap(); let command_buffer = command_buffer.build().unwrap();

Loading…
Cancel
Save