I need to impl a private module so I can have a private get_paths

master
mitchellhansen 5 years ago
parent 5462566396
commit fa2c9397bf

@ -10,15 +10,17 @@ simple-stopwatch="0.1.4"
nalgebra = "0.18.0" nalgebra = "0.18.0"
image = "0.21.2" image = "0.21.2"
rand = "0.6.5" rand = "0.6.5"
vulkano = "0.13.0" #vulkano = "0.13.0"
#vulkano = {path = "../vulkano/vulkano"} vulkano = {path = "../vulkano/vulkano"}
vulkano-shaders = "0.13.0" #vulkano-shaders = "0.14.0"
vulkano-win = "0.13.0" vulkano-shaders = {path = "../vulkano-shaders"}
#vulkano-win = "0.14.0"
vulkano-win= {path = "../vulkano-win"}
time = "0.1.38" time = "0.1.38"
shaderc = "0.5.0" shaderc = "0.6.1"
#shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"} #shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"}
shade_runner = {path = "../shade_runner"} shade_runner = {path = "../shade_runner"}
winit = "0.19.1" winit = "0.19.1"
#criterion = "0.3.0" #criterion = "0.3.0"
hprof = "0.1.3" hprof = "0.1.3"
rusttype = { version = "0.7.0", features = ["gpu_cache"] } rusttype = { version = "0.7.0", features = ["gpu_cache"] }

@ -24,6 +24,7 @@ use crate::canvas_text::{CanvasText, CanvasTextHandle};
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle}; use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache}; use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
use crate::vertex_3d::Vertex3D; use crate::vertex_3d::Vertex3D;
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
/// A drawable object can be passed into a CanvasFrame to be rendered /// A drawable object can be passed into a CanvasFrame to be rendered
/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color /// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color
@ -175,7 +176,23 @@ impl CanvasState {
CanvasState { CanvasState {
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None }, dynamic_state: DynamicState {
line_width: None,
viewports: None,
scissors: None,
compare_mask: Some(DynamicStencilValue {
face: StencilFaceFlags::StencilFrontAndBack,
value: 0xFF,
}),
write_mask: Some(DynamicStencilValue {
face: StencilFaceFlags::StencilFrontAndBack,
value: 0xFF,
}),
reference: Some(DynamicStencilValue {
face: StencilFaceFlags::StencilFrontAndBack,
value: 0xFF,
}),
},
sampler: Sampler::new(device.clone(), sampler: Sampler::new(device.clone(),
Filter::Linear, Filter::Linear, Filter::Linear, Filter::Linear,
MipmapMode::Nearest, MipmapMode::Nearest,
@ -332,10 +349,12 @@ impl CanvasState {
shader_type: ShaderType, shader_type: ShaderType,
physical: PhysicalDevice, physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> { capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
let handle = Arc::new(CanvasShaderHandle { let handle = Arc::new(CanvasShaderHandle {
handle: self.shader_buffers.len() as u32 handle: self.shader_buffers.len() as u32
}); });
// TODO : what is even going on here
let shader = match shader_type { let shader = match shader_type {
ShaderType::SOLID => { ShaderType::SOLID => {
Arc::new(CanvasShader::new( Arc::new(CanvasShader::new(
@ -478,7 +497,7 @@ impl CanvasState {
/// Pushes the draw commands to the command buffer. Requires the framebuffers and /// Pushes the draw commands to the command buffer. Requires the framebuffers and
/// image number to be passed in as they are taken care of by the vkprocessor /// image number to be passed in as they are taken care of by the vkprocessor
pub fn draw_commands(&self, pub fn draw_commands(&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) -> AutoCommandBufferBuilder { image_num: usize) -> AutoCommandBufferBuilder {
@ -486,9 +505,16 @@ impl CanvasState {
// 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!(
ClearValue::Float([0.0, 0.0, 1.0, 1.0]), ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
ClearValue::DepthStencil((1.0, 0)), ClearValue::DepthStencil((1.0, 0x00)),
); );
// self.dynamic_state = DynamicState {
// line_width: None,
// viewports: self.dynamic_state.viewports.clone(),
// scissors: None,
// compare_mask: Some(StencilMask{ face: StencilFaceFlags::StencilFaceFrontBit, mask: 0xFF }),
// };
let mut command_buffer = command_buffer.begin_render_pass( let mut command_buffer = command_buffer.begin_render_pass(
framebuffers[image_num].clone(), false, clear_values.clone(), framebuffers[image_num].clone(), false, clear_values.clone(),
).unwrap(); ).unwrap();
@ -501,6 +527,7 @@ impl CanvasState {
// This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs. // This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs.
// But we can pass in multiple vertex buffers // But we can pass in multiple vertex buffers
if !self.colored_vertex_buffer.is_empty() { 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(),
@ -510,7 +537,6 @@ impl CanvasState {
).unwrap(); ).unwrap();
} }
// Images // Images
let mut shader = self.shader_buffers.get( let mut shader = self.shader_buffers.get(
self.get_shader_handle(String::from("simple_image")) self.get_shader_handle(String::from("simple_image"))
@ -529,10 +555,10 @@ impl CanvasState {
&self.dynamic_state.clone(), vec![vertex_buffer], &self.dynamic_state.clone(), vec![vertex_buffer],
vec![descriptor_set], (), vec![descriptor_set], (),
).unwrap(); ).unwrap();
} }
} }
// Textures // Textures
let mut shader = self.shader_buffers.get( let mut shader = self.shader_buffers.get(
self.get_shader_handle(String::from("simple_texture")) self.get_shader_handle(String::from("simple_texture"))

@ -12,6 +12,51 @@ use crate::vertex_2d::Vertex2D;
use vulkano::pipeline::vertex::SingleBufferDefinition; use vulkano::pipeline::vertex::SingleBufferDefinition;
use crate::vertex_3d::Vertex3D; use crate::vertex_3d::Vertex3D;
use vulkano::pipeline::depth_stencil::{DepthStencil, Stencil, StencilOp, Compare, DepthBounds}; use vulkano::pipeline::depth_stencil::{DepthStencil, Stencil, StencilOp, Compare, DepthBounds};
use std::collections::HashSet;
/// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompiledGraphicsPipelineHandle {
pub handle: u32
}
pub trait CompiledGraphicsPipeline {
fn get_paths(&self, filename: String) -> Vec<(ShaderType, PathBuf)> {
let project_root =
std::env::current_dir()
.expect("failed to get root directory");
let mut shader_path = project_root.clone();
shader_path.push(PathBuf::from("resources/shaders/"));
let mut vertex_shader_path = shader_path.clone();
vertex_shader_path.push(PathBuf::from("resources/shaders/"));
vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
let mut fragment_shader_path = project_root.clone();
fragment_shader_path.push(PathBuf::from("resources/shaders/"));
fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
(vertex_shader_path, fragment_shader_path)
}
fn new(filename: String, shaders: HashSet<ShaderType>) -> Box<dyn CompiledGraphicsPipeline>;
fn get_name() -> String;
fn get_handle() -> Arc<AbstractCompiledPipelineHandle>;
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
fn recompile();
}
/// Legacy ShaderType enum for single type shaders.
#[derive(PartialEq, Eq, Hash, Clone)]
pub enum ShaderType {
VERTEX = 0,
FRAGMENT = 1,
GEOMETRY = 2,
TESSELATION = 3,
}
/// Typed wrapper for a u32 shader handle (index id) /// Typed wrapper for a u32 shader handle (index id)
@ -31,9 +76,8 @@ pub struct CanvasShader {
pub(crate) name: String, pub(crate) name: String,
} }
impl CanvasShader { impl CompiledGraphicsPipeline for CanvasShader {
/// Takes the filename of a .vertex .fragment shader combo in resources/shaders/
/// Returns pathbuffer of that vertex and fragment shader
fn get_path(filename: String) -> (PathBuf, PathBuf) { fn get_path(filename: String) -> (PathBuf, PathBuf) {
let project_root = let project_root =
std::env::current_dir() std::env::current_dir()
@ -53,6 +97,30 @@ impl CanvasShader {
(vertex_shader_path, fragment_shader_path) (vertex_shader_path, fragment_shader_path)
} }
fn new(filename: String, shaders: HashSet<ShaderType>) -> Box<dyn CompiledGraphicsPipeline> {
}
fn get_name() -> String {
unimplemented!()
}
fn get_handle() -> Arc<_> {
unimplemented!()
}
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract> {
unimplemented!()
}
fn recompile() {
unimplemented!()
}
}
impl CanvasShader {
/// Clone and returns the compiled graphics pipeline /// Clone and returns the compiled graphics pipeline
pub fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> { pub fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {
self.graphics_pipeline.clone().unwrap() self.graphics_pipeline.clone().unwrap()
@ -119,16 +187,25 @@ impl CanvasShader {
depth_bounds_test: DepthBounds::Disabled, depth_bounds_test: DepthBounds::Disabled,
stencil_front: Stencil { stencil_front: Stencil {
compare: Compare::Equal, compare: Compare::Equal,
pass_op: StencilOp::Invert, pass_op: StencilOp::IncrementAndWrap,
fail_op: StencilOp::Invert, fail_op: StencilOp::DecrementAndClamp,
depth_fail_op: StencilOp::Keep, depth_fail_op: StencilOp::Keep,
compare_mask: Some(0x01), compare_mask: None,
write_mask: Some(0xFF), write_mask: None,
reference: Some(0x01), reference: None,
},
stencil_back: Stencil {
compare: Compare::Equal,
pass_op: StencilOp::Invert,
fail_op: StencilOp::Zero,
depth_fail_op: StencilOp::Zero,
compare_mask: None,
write_mask: None,
reference: None,
}, },
stencil_back: Default::default()
}; };
CanvasShader { CanvasShader {
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start() graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()

@ -25,6 +25,7 @@ use crate::compu_buffer::CompuBuffers;
use crate::util::load_raw; use crate::util::load_raw;
use crate::canvas_frame::CanvasFrame; use crate::canvas_frame::CanvasFrame;
use crate::sprite::Poly; use crate::sprite::Poly;
use vulkano::instance::debug::DebugCallback;
pub mod util; pub mod util;
@ -58,6 +59,10 @@ pub fn main() {
Instance::new(None, &extensions, None).unwrap() Instance::new(None, &extensions, None).unwrap()
}; };
let _callback = DebugCallback::errors_and_warnings(&instance, |msg| {
println!("Debug callback: {:?}", msg.description);
}).ok();
let mut events_loop = EventsLoop::new(); let mut events_loop = EventsLoop::new();
let mut surface = WindowBuilder::new() let mut surface = WindowBuilder::new()
.with_dimensions(LogicalSize::from((800, 800))) .with_dimensions(LogicalSize::from((800, 800)))
@ -106,7 +111,6 @@ pub fn main() {
let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0)); let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
drop(q2); drop(q2);
drop(q1); drop(q1);
@ -186,6 +190,8 @@ pub fn main() {
drop(l); drop(l);
hprof::end_frame(); hprof::end_frame();
hprof::profiler().print_timing(); hprof::profiler().print_timing();
} }

@ -153,32 +153,65 @@ impl Poly {
Poly { Poly {
vertices: vec![ vertices: vec![
(position.0, position.1 , normalized_depth), // top left (-0.5 , -0.5 , normalized_depth),
(position.0, position.1 + size.1 , normalized_depth), // bottom left (-1.0 , 1.0 , normalized_depth),
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right (-0.25 , 0.0 , normalized_depth),
(position.0, position.1 , normalized_depth), // top left (-0.25 , 0.0 , normalized_depth),
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right (-1.0 , 1.0 , normalized_depth),
(position.0 + size.0, position.1 , normalized_depth), // top right (0.0 , 0.5 , normalized_depth),
(0.25 , 0.0 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , 0.5 , normalized_depth),
(0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.25 , 0.0 , normalized_depth),
(0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.5 , -0.5 , normalized_depth),
(0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , -0.1 , normalized_depth),
(-0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , -0.1 , normalized_depth),
(position.0 - 0.1, position.1 , normalized_depth), // top left (-0.5 , -0.5 , normalized_depth),
(position.0 - 0.1 + size.0, position.1 + size.1, normalized_depth), // bottom right (-1.0 , 1.0 , normalized_depth),
(position.0 - 0.1 + size.0, position.1 , normalized_depth), // top right (-0.25 , -0.5 , normalized_depth),
], ],
position: position, position: position,
ti_position: vec![ ti_position: vec![
(-0.0, -0.0), // top left (0.0,0.0),
(-0.0, 1.0), // bottom left (0.0,0.0),
( 1.0, 1.0), // bottom right (0.0,0.0),
(0.0,0.0),
(-0.0, -0.0), // top left (0.0,0.0),
( 1.0, 1.0), // bottom right (0.0,0.0),
( 1.0, -0.0), // top right (0.0,0.0),
(0.0,0.0),
(-0.0, -0.0), // top left (0.0,0.0),
( 1.0, 1.0), // bottom right (0.0,0.0),
( 1.0, -0.0), // top right (0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
], ],
size: size, size: size,
color: color, color: color,

@ -17,6 +17,7 @@ use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle}; use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
use std::time::Duration; use std::time::Duration;
use crate::canvas_shader::CanvasShaderHandle; use crate::canvas_shader::CanvasShaderHandle;
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
/// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states /// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states
/// ///
@ -27,7 +28,6 @@ pub struct VkProcessor<'a> {
pub device: Arc<Device>, pub device: Arc<Device>,
pub queues: QueuesIter, pub queues: QueuesIter,
pub queue: Arc<Queue>, pub queue: Arc<Queue>,
pub dynamic_state: DynamicState,
pub swapchain: Option<Arc<Swapchain<Window>>>, pub swapchain: Option<Arc<Swapchain<Window>>>,
pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>, pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>,
@ -72,7 +72,6 @@ impl<'a> VkProcessor<'a> {
device: device.clone(), device: device.clone(),
queue: queue.clone(), queue: queue.clone(),
queues: queues, queues: queues,
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
swapchain: None, swapchain: None,
swapchain_images: None, swapchain_images: None,
swapchain_recreate_needed: false, swapchain_recreate_needed: false,

Loading…
Cancel
Save