Switched vertex type to be chosen at the shader load

master
mitchellhansen 5 years ago
parent fcfa40e335
commit d1051a0ca3

@ -17,11 +17,12 @@ Creation-Date: 2020-02-03T23:30:41-08:00
===== Interface =====
Generally there is a get for handle and pointer and a load (or create) for each of the stored items.
Generally there is a getter for the resource handle & pointer and a load (or create) for each of the stored items.
The class then interacts with these stored items by taking and executing a list of operations to perform on them.
[[VKProcessor::CanvasFrame|CanvasFrame]]
An object which accumulate frame draws. The State will then parse this list of calls and display them on the screen
--------------------

@ -4,7 +4,6 @@ use std::hash::Hash;
use crate::canvas::*;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance;
use vulkano::pipeline::vertex::Vertex;
use std::any::Any;
use crate::VertexTypes;

@ -26,7 +26,7 @@ use std::borrow::Borrow;
use std::fs::File;
use std::io::Read;
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment};
use vulkano::pipeline::vertex::VertexDefinition;
use vulkano::pipeline::vertex::{VertexDefinition, Vertex};
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle, DrawableHandle};
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
@ -34,6 +34,7 @@ use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline;
use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::VertexTypes;
use crate::util::vertex::{TextVertex3D, TextureVertex2D, ImageVertex2D, ColorVertex2D, CanvasFrameAllocation};
use shade_runner::Input;
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
@ -255,17 +256,17 @@ impl CanvasState {
/// Load and Compile a shader with the filename at resources/shaders
/// Takes physical and capabilities as we don't store that in Canvas
pub fn load_shader<T: 'static>(&mut self,
pub fn load_shader<T: 'static, V>(&mut self,
filename: String,
physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
where T: CompiledGraphicsPipeline {
where T: CompiledGraphicsPipeline, V: Vertex {
let handle = Arc::new(CompiledShaderHandle {
handle: self.shader_buffers.len() as u32
});
let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new(
let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new::<V>(
filename.clone(),
self.device.clone(),
handle.clone(),

@ -10,7 +10,7 @@ use shade_runner::{Input, Output, Layout, Entry};
use std::ffi::CStr;
use std::marker::PhantomData;
use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp};
use vulkano::pipeline::vertex::{SingleBufferDefinition, VertexDefinition};
use vulkano::pipeline::vertex::{SingleBufferDefinition, VertexDefinition, Vertex};
use shade_runner as sr;
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
use vulkano::SafeDeref;
@ -18,7 +18,7 @@ use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphics
use crate::canvas::managed::handles::CompiledShaderHandle;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::ShaderSpecializationConstants;
use crate::util::vertex::VertexTypes;
use crate::util::vertex::{VertexTypes, ColorVertex2D};
/// CanvasShader holds the pipeline and render pass for the input shader source
#[derive(Clone)]
@ -34,10 +34,6 @@ pub struct GenericShader {
impl GenericShader {
fn get(&self) -> VertexTypes {
VertexTypes::ImageType
}
}
/// Gives CanvasShader the resource functions
@ -47,7 +43,7 @@ impl CompiledGraphicsPipelineResources for GenericShader {}
impl CompiledGraphicsPipeline for GenericShader {
/// This will explode when the shader does not want to compile
fn new(filename: String,
fn new<V: Vertex>(filename: String,
device: Arc<Device>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
@ -88,8 +84,8 @@ impl CompiledGraphicsPipeline for GenericShader {
graphics_pipeline:
Some(Arc::new(GraphicsPipeline::start()
//SingleBufferDefinition::<Vertex3D>
.vertex_input(vertex_definition)
.vertex_input(SingleBufferDefinition::<V>::new())
//.vertex_input(vertex_definition)
.vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants {
first_constant: 0,
@ -139,8 +135,8 @@ impl CompiledGraphicsPipeline for GenericShader {
self.renderpass.clone()
}
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
GenericShader::new(self.name,
fn recompile<V: Vertex>(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
GenericShader::new::<V>(self.name,
self.device,
self.handle,
render_pass.clone())

@ -9,6 +9,7 @@ use vulkano::device::Device;
use shade_runner::Entry;
use shaderc::ShaderKind;
use crate::canvas::managed::handles::CompiledShaderHandle;
use vulkano::pipeline::vertex::Vertex;
/*
@ -100,15 +101,15 @@ pub trait CompiledGraphicsPipelineResources {
pub trait CompiledGraphicsPipeline {
fn new(filename: String,
fn new<V>(filename: String,
device: Arc<Device>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized;
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized, V: Vertex,;
fn get_name(&self) -> String;
fn get_handle(&self) -> Arc<CompiledShaderHandle>;
fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
fn get_renderpass(&self) -> Arc<dyn RenderPassAbstract + Send + Sync>;
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)
fn recompile<V: Vertex>(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)
-> Self where Self: Sized;
}

@ -9,22 +9,15 @@ use shade_runner::{Input, Output, Layout, Entry};
use std::ffi::CStr;
use std::marker::PhantomData;
use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp};
use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefinition};
use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefinition, Vertex};
use shade_runner as sr;
use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphicsPipelineResources, CompiledGraphicsPipeline};
use crate::canvas::managed::handles::CompiledShaderHandle;
use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::ShaderSpecializationConstants;
use crate::util::vertex::ColorVertex2D;
#[derive(Default, Debug, Clone, Copy)]
pub struct GlyphInstance {
pub screen_position: (f32, f32),
pub atlas_position: (f32, f32),
pub atlas_size: (f32, f32),
pub scale: f32,
}
vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size, scale);
/// CanvasShader holds the pipeline and render pass for the input shader source
#[derive(Clone)]
@ -47,7 +40,7 @@ impl CompiledGraphicsPipelineResources for TextShader {}
impl CompiledGraphicsPipeline for TextShader {
/// This will explode when the shader does not want to compile
fn new(filename: String,
fn new<V: Vertex>(filename: String,
device: Arc<Device>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
@ -111,8 +104,9 @@ impl CompiledGraphicsPipeline for TextShader {
TextShader {
graphics_pipeline:
Some(Arc::new(GraphicsPipeline::start()
//OneVertexOneInstanceDefinition::<Vertex3D, GlyphInstance>
.vertex_input(vertex_definition)
.vertex_input(SingleBufferDefinition::<V>::new())
//.vertex_input(vertex_definition)
.vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants {
first_constant: 0,
@ -160,8 +154,8 @@ impl CompiledGraphicsPipeline for TextShader {
fn get_renderpass(&self) -> Arc<dyn RenderPassAbstract + Send + Sync> {
self.renderpass.clone()
}
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
TextShader::new(self.name,
fn recompile<V: Vertex>(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
TextShader::new::<V>(self.name,
self.device,
self.handle,
self.renderpass.clone())

@ -1,7 +1,6 @@
use std::sync::Arc;
use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance;
use crate::canvas::canvas_frame::{Drawable};
use crate::util::vertex::{VertexTypes, TextureVertex2D, Vertex3D};

@ -40,6 +40,14 @@ pub struct TextVertex3D {
vulkano::impl_vertex!(TextVertex3D, position);
#[derive(Default, Debug, Clone, Copy)]
pub struct GlyphInstance {
pub screen_position: (f32, f32),
pub atlas_position: (f32, f32),
pub atlas_size: (f32, f32),
pub scale: f32,
}
vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size, scale);
// ==============================================================================
#[derive(Debug, Clone)]

@ -20,7 +20,7 @@ use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::text_shader::TextShader;
use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::util::vertex::VertexTypes;
use crate::util::vertex::{VertexTypes, ColorVertex2D, TextVertex3D, TextureVertex2D, ImageVertex2D};
/// VKProcessor holds the vulkan instance information, the swapchain,
@ -168,10 +168,10 @@ impl<'a> VkProcessor<'a> {
/// A hardcoded list of shaders which can be preloaded from this function
pub fn preload_shaders(&mut self) {
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());
self.canvas_state.load_shader::<GenericShader, ColorVertex2D>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
self.canvas_state.load_shader::<GenericShader, TextureVertex2D>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
self.canvas_state.load_shader::<GenericShader, ImageVertex2D>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone());
self.canvas_state.load_shader::<TextShader, TextVertex3D>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
}
/// A hardcoded list of shaders which can be proloaded from this function

Loading…
Cancel
Save