refactoring the shader container. To Trait or not to Trait? Probably Trait
This commit is contained in:
@@ -2,12 +2,13 @@ use crate::canvas::canvas_state::{CanvasTextureHandle, CanvasImageHandle};
|
|||||||
use vulkano::image::{ImmutableImage, AttachmentImage};
|
use vulkano::image::{ImmutableImage, AttachmentImage};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use vulkano::format::{Format, R8Unorm};
|
use vulkano::format::{Format, R8Unorm};
|
||||||
use crate::canvas::canvas_shader::CanvasShader;
|
use crate::canvas::canvas_shader::GenericShader;
|
||||||
use vulkano::sampler::Sampler;
|
use vulkano::sampler::Sampler;
|
||||||
use vulkano::descriptor::DescriptorSet;
|
use vulkano::descriptor::DescriptorSet;
|
||||||
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
|
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
|
||||||
use vulkano::buffer::CpuAccessibleBuffer;
|
use vulkano::buffer::CpuAccessibleBuffer;
|
||||||
use crate::canvas::canvas_text::{CanvasTextCacheHandle, CanvasTextHandle};
|
use crate::canvas::canvas_text::{CanvasTextCacheHandle, CanvasTextHandle};
|
||||||
|
use vulkano::pipeline::GraphicsPipelineAbstract;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CanvasTexture {
|
pub struct CanvasTexture {
|
||||||
@@ -19,11 +20,11 @@ pub struct CanvasTexture {
|
|||||||
|
|
||||||
impl CanvasTexture {
|
impl CanvasTexture {
|
||||||
pub fn get_descriptor_set(&self,
|
pub fn get_descriptor_set(&self,
|
||||||
shader: Arc<CanvasShader>,
|
pipeline: Arc<dyn GraphicsPipelineAbstract + Sync + Send>,
|
||||||
sampler: Arc<Sampler>) -> Box<dyn DescriptorSet + Send + Sync> {
|
sampler: Arc<Sampler>) -> 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(
|
||||||
shader.clone().get_pipeline().clone(), 0,
|
pipeline.clone(), 0,
|
||||||
)
|
)
|
||||||
.add_sampled_image(self.buffer.clone(), sampler.clone()).unwrap()
|
.add_sampled_image(self.buffer.clone(), sampler.clone()).unwrap()
|
||||||
.build().unwrap());
|
.build().unwrap());
|
||||||
@@ -39,11 +40,11 @@ pub struct CanvasImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CanvasImage {
|
impl CanvasImage {
|
||||||
pub fn get_descriptor_set(&self, shader: Arc<CanvasShader>)
|
pub fn get_descriptor_set(&self, pipeline: Arc<dyn GraphicsPipelineAbstract + Sync + Send>)
|
||||||
-> Box<dyn DescriptorSet + Send + Sync> {
|
-> 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(
|
||||||
shader.clone().get_pipeline().clone(), 0,
|
pipeline.clone(), 0,
|
||||||
)
|
)
|
||||||
.add_image(self.buffer.clone()).unwrap()
|
.add_image(self.buffer.clone()).unwrap()
|
||||||
.build().unwrap());
|
.build().unwrap());
|
||||||
@@ -60,11 +61,11 @@ pub struct CanvasTextCache {
|
|||||||
|
|
||||||
impl CanvasTextCache {
|
impl CanvasTextCache {
|
||||||
pub fn get_descriptor_set(&self,
|
pub fn get_descriptor_set(&self,
|
||||||
shader: Arc<CanvasShader>,
|
pipeline: Arc<dyn GraphicsPipelineAbstract + Sync + Send>,
|
||||||
sampler: Arc<Sampler>) -> Box<dyn DescriptorSet + Send + Sync> {
|
sampler: Arc<Sampler>) -> 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(
|
||||||
shader.clone().get_pipeline().clone(), 0,
|
pipeline.clone(), 0,
|
||||||
)
|
)
|
||||||
.add_buffer(self.buffer.clone()).unwrap()
|
.add_buffer(self.buffer.clone()).unwrap()
|
||||||
.build().unwrap());
|
.build().unwrap());
|
||||||
@@ -82,11 +83,11 @@ pub struct CanvasText {
|
|||||||
|
|
||||||
impl CanvasText {
|
impl CanvasText {
|
||||||
pub fn get_descriptor_set(&self,
|
pub fn get_descriptor_set(&self,
|
||||||
shader: Arc<CanvasShader>,
|
pipeline: Arc<dyn GraphicsPipelineAbstract + Sync + Send>,
|
||||||
sampler: Arc<Sampler>) -> Box<dyn DescriptorSet + Send + Sync> {
|
sampler: Arc<Sampler>) -> 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(
|
||||||
shader.clone().get_pipeline().clone(), 0,
|
pipeline.clone(), 0,
|
||||||
)
|
)
|
||||||
.add_sampled_image(self.buffer.clone(), sampler.clone()).unwrap()
|
.add_sampled_image(self.buffer.clone(), sampler.clone()).unwrap()
|
||||||
.build().unwrap());
|
.build().unwrap());
|
||||||
|
|||||||
@@ -13,6 +13,47 @@ use crate::util::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;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
/// Inheriting this gives private functions to grab resources
|
||||||
|
trait CompiledGraphicsPipelineResources {
|
||||||
|
fn get_paths(filename: String, types: HashSet<ShaderType>) -> 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 paths = Vec::new();
|
||||||
|
|
||||||
|
for shader_type in types {
|
||||||
|
match shader_type {
|
||||||
|
ShaderType::VERTEX => {
|
||||||
|
let mut shader_path = shader_path.clone();
|
||||||
|
shader_path.push(PathBuf::from(filename.clone() + ".vert"));
|
||||||
|
paths.push((shader_type, shader_path));
|
||||||
|
}
|
||||||
|
ShaderType::FRAGMENT => {
|
||||||
|
let mut shader_path = shader_path.clone();
|
||||||
|
shader_path.push(PathBuf::from(filename.clone() + ".frag"));
|
||||||
|
paths.push((shader_type, shader_path));
|
||||||
|
}
|
||||||
|
ShaderType::GEOMETRY => {
|
||||||
|
let mut shader_path = shader_path.clone();
|
||||||
|
shader_path.push(PathBuf::from(filename.clone() + ".geom"));
|
||||||
|
paths.push((shader_type, shader_path));
|
||||||
|
}
|
||||||
|
ShaderType::TESSELLATION => {
|
||||||
|
let mut shader_path = shader_path.clone();
|
||||||
|
shader_path.push(PathBuf::from(filename.clone() + ".tess"));
|
||||||
|
paths.push((shader_type, shader_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paths
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 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 CompiledGraphicsPipelineHandle {
|
pub struct CompiledGraphicsPipelineHandle {
|
||||||
@@ -20,32 +61,11 @@ pub struct CompiledGraphicsPipelineHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait CompiledGraphicsPipeline {
|
pub trait CompiledGraphicsPipeline {
|
||||||
// fn get_paths(&self, filename: String) -> Vec<(ShaderType, PathBuf)> {
|
fn get_name(&self) -> String;
|
||||||
//
|
fn get_handle(&self) -> Arc<CompiledGraphicsPipelineHandle>;
|
||||||
// let project_root =
|
fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
|
||||||
// std::env::current_dir()
|
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)
|
||||||
// .expect("failed to get root directory");
|
-> Self where Self: Sized;
|
||||||
//
|
|
||||||
// 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>) -> Self;
|
|
||||||
fn get_name() -> String;
|
|
||||||
fn get_handle() -> Arc<CompiledGraphicsPipelineHandle>;
|
|
||||||
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
|
|
||||||
fn recompile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Legacy ShaderType enum for single type shaders.
|
/// Legacy ShaderType enum for single type shaders.
|
||||||
@@ -54,7 +74,8 @@ pub enum ShaderType {
|
|||||||
VERTEX = 0,
|
VERTEX = 0,
|
||||||
FRAGMENT = 1,
|
FRAGMENT = 1,
|
||||||
GEOMETRY = 2,
|
GEOMETRY = 2,
|
||||||
TESSELATION = 3,
|
TESSELLATION_CONTROL = 3,
|
||||||
|
TESSELLATION_EVALUATION = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,121 +87,96 @@ pub struct CanvasShaderHandle {
|
|||||||
|
|
||||||
/// CanvasShader holds the pipeline and render pass for the input shader source
|
/// CanvasShader holds the pipeline and render pass for the input shader source
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CanvasShader {
|
pub struct GenericShader {
|
||||||
|
|
||||||
graphics_pipeline: Option<Arc<dyn GraphicsPipelineAbstract + Sync + Send>>,
|
graphics_pipeline: Option<Arc<dyn GraphicsPipelineAbstract + Sync + Send>>,
|
||||||
|
|
||||||
|
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||||
|
name: String,
|
||||||
|
shader_types: HashSet<ShaderType>,
|
||||||
|
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
pub(crate) handle: Arc<CanvasShaderHandle>,
|
|
||||||
pub(crate) name: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompiledGraphicsPipeline for CanvasShader {
|
/// Gives CanvasShader the resource functions
|
||||||
|
impl CompiledGraphicsPipelineResources for GenericShader {}
|
||||||
|
|
||||||
// fn get_path(filename: String) -> (PathBuf, PathBuf) {
|
/// Convenience interface so we don't have to juggle shader types
|
||||||
// let project_root =
|
impl CompiledGraphicsPipeline for GenericShader {
|
||||||
// std::env::current_dir()
|
fn get_name(&self) -> String {
|
||||||
// .expect("failed to get root directory");
|
self.name.clone()
|
||||||
//
|
|
||||||
// let mut shader_path = project_root.clone();
|
|
||||||
// shader_path.push(PathBuf::from("resources/shaders/"));
|
|
||||||
//
|
|
||||||
// let mut vertex_shader_path = project_root.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>) -> Self {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name() -> String {
|
fn get_handle(&self) -> Arc<CompiledGraphicsPipelineHandle> {
|
||||||
unimplemented!()
|
self.handle.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_handle() -> Arc<CompiledGraphicsPipelineHandle> {
|
fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn recompile() {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CanvasShader {
|
|
||||||
|
|
||||||
fn get_path(filename: String) -> (PathBuf, 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 = project_root.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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clone and returns the compiled graphics pipeline
|
|
||||||
pub fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {
|
|
||||||
self.graphics_pipeline.clone().unwrap()
|
self.graphics_pipeline.clone().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new shader.
|
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
|
||||||
|
GenericShader::new(self.name,
|
||||||
|
self.shader_types,
|
||||||
|
self.device,
|
||||||
|
self.handle,
|
||||||
|
render_pass.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GenericShader {
|
||||||
|
|
||||||
/// This will explode when the shader does not want to compile
|
/// This will explode when the shader does not want to compile
|
||||||
pub fn new(filename: String,
|
pub fn new(filename: String,
|
||||||
capabilities: Capabilities,
|
shader_types: HashSet<ShaderType>,
|
||||||
queue: Arc<Queue>,
|
device: Arc<Device>,
|
||||||
physical: PhysicalDevice,
|
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||||
device: Arc<Device>,
|
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
|
||||||
handle: Arc<CanvasShaderHandle>,
|
|
||||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,) -> CanvasShader {
|
|
||||||
|
|
||||||
let format = capabilities.supported_formats[0].0;
|
let filenames = GenericShader::get_paths(filename.clone(), shader_types.clone());
|
||||||
|
|
||||||
let filenames = CanvasShader::get_path(filename.clone());
|
|
||||||
|
|
||||||
// TODO: better compile message, run til successful compile
|
// TODO: better compile message, run til successful compile
|
||||||
let shader = sr::load(filenames.0, filenames.1)
|
|
||||||
.expect("Shader didn't compile");
|
|
||||||
|
|
||||||
let vulkano_entry =
|
|
||||||
sr::parse(&shader)
|
|
||||||
.expect("failed to parse");
|
|
||||||
|
for shader in filenames {
|
||||||
|
match shader.0 {
|
||||||
|
ShaderType::VERTEX => {
|
||||||
|
let shader = sr::load(filenames.0, filenames.1)
|
||||||
|
.expect("Shader didn't compile");
|
||||||
|
|
||||||
|
let vulkano_entry =
|
||||||
|
sr::parse(&shader)
|
||||||
|
.expect("failed to parse");
|
||||||
|
}
|
||||||
|
ShaderType::FRAGMENT => {
|
||||||
|
|
||||||
|
}
|
||||||
|
ShaderType::GEOMETRY => {
|
||||||
|
|
||||||
|
}
|
||||||
|
ShaderType::TESSELLATION => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let fragment_shader_module: Arc<ShaderModule> = unsafe {
|
let fragment_shader_module: Arc<ShaderModule> = unsafe {
|
||||||
let filenames1 = CanvasShader::get_path(filename.clone());
|
let filenames1 = GenericShader::get_path(filename.clone());
|
||||||
let shader1 = sr::load(filenames1.0, filenames1.1)
|
let shader1 = sr::load(filenames1.0, filenames1.1)
|
||||||
.expect("Shader didn't compile");
|
.expect("Shader didn't compile");
|
||||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader1.fragment.clone())
|
ShaderModule::from_words(device.clone(), &shader1.fragment.clone())
|
||||||
}.unwrap();
|
}.unwrap();
|
||||||
|
|
||||||
|
|
||||||
let vertex_shader_module: Arc<ShaderModule> = unsafe {
|
let vertex_shader_module: Arc<ShaderModule> = unsafe {
|
||||||
let filenames1 = CanvasShader::get_path(filename.clone());
|
|
||||||
|
let filenames1 = GenericShader::get_path(filename.clone());
|
||||||
let shader1 = sr::load(filenames1.0, filenames1.1)
|
let shader1 = sr::load(filenames1.0, filenames1.1)
|
||||||
.expect("Shader didn't compile");
|
.expect("Shader didn't compile");
|
||||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader1.vertex.clone())
|
ShaderModule::from_words(device.clone(), &shader1.vertex.clone())
|
||||||
}.unwrap();
|
}.unwrap();
|
||||||
|
|
||||||
let filenames = CanvasShader::get_path(filename.clone());
|
|
||||||
|
|
||||||
|
|
||||||
let frag_entry_point = unsafe {
|
let frag_entry_point = unsafe {
|
||||||
Some(fragment_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
Some(fragment_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||||
@@ -199,31 +195,31 @@ impl CanvasShader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let stencil = DepthStencil {
|
let stencil = DepthStencil {
|
||||||
depth_compare: Compare::Less,
|
depth_compare: Compare::Less,
|
||||||
depth_write: true,
|
depth_write: true,
|
||||||
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::IncrementAndWrap,
|
pass_op: StencilOp::IncrementAndWrap,
|
||||||
fail_op: StencilOp::DecrementAndClamp,
|
fail_op: StencilOp::DecrementAndClamp,
|
||||||
depth_fail_op: StencilOp::Keep,
|
depth_fail_op: StencilOp::Keep,
|
||||||
compare_mask: None,
|
compare_mask: None,
|
||||||
write_mask: None,
|
write_mask: None,
|
||||||
reference: None,
|
reference: None,
|
||||||
},
|
},
|
||||||
stencil_back: Stencil {
|
stencil_back: Stencil {
|
||||||
compare: Compare::Equal,
|
compare: Compare::Equal,
|
||||||
pass_op: StencilOp::Invert,
|
pass_op: StencilOp::Invert,
|
||||||
fail_op: StencilOp::Zero,
|
fail_op: StencilOp::Zero,
|
||||||
depth_fail_op: StencilOp::Zero,
|
depth_fail_op: StencilOp::Zero,
|
||||||
compare_mask: None,
|
compare_mask: None,
|
||||||
write_mask: None,
|
write_mask: None,
|
||||||
reference: None,
|
reference: None,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CanvasShader {
|
GenericShader {
|
||||||
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
||||||
|
|
||||||
.vertex_input(SingleBufferDefinition::<Vertex3D>::new())
|
.vertex_input(SingleBufferDefinition::<Vertex3D>::new())
|
||||||
@@ -256,6 +252,7 @@ impl CanvasShader {
|
|||||||
device: device,
|
device: device,
|
||||||
handle: handle.clone(),
|
handle: handle.clone(),
|
||||||
name: filename.clone(),
|
name: filename.clone(),
|
||||||
|
shader_types: shader_types.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
|||||||
use crate::canvas::canvas_frame::CanvasFrame;
|
use crate::canvas::canvas_frame::CanvasFrame;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use crate::canvas::canvas_text::{CanvasText, CanvasTextHandle};
|
use crate::canvas::canvas_text::{CanvasText, CanvasTextHandle};
|
||||||
use crate::canvas::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
use crate::canvas::canvas_shader::{GenericShader, CanvasShaderHandle, CompiledGraphicsPipelineHandle, CompiledGraphicsPipeline};
|
||||||
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
use crate::canvas::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
||||||
use crate::util::vertex_3d::Vertex3D;
|
use crate::util::vertex_3d::Vertex3D;
|
||||||
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
||||||
@@ -32,7 +32,6 @@ use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
|||||||
/// Split out to two drawables?
|
/// Split out to two drawables?
|
||||||
///
|
///
|
||||||
pub trait Drawable {
|
pub trait Drawable {
|
||||||
|
|
||||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
||||||
fn get_color(&self) -> (f32, f32, f32, f32);
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
||||||
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
||||||
@@ -84,7 +83,7 @@ pub struct CanvasState {
|
|||||||
// hold the image, texture, and shader buffers the same was as we do CompuState
|
// hold the image, texture, and shader buffers the same was as we do CompuState
|
||||||
image_buffers: Vec<Arc<CanvasImage>>,
|
image_buffers: Vec<Arc<CanvasImage>>,
|
||||||
texture_buffers: Vec<Arc<CanvasTexture>>,
|
texture_buffers: Vec<Arc<CanvasTexture>>,
|
||||||
shader_buffers: Vec<Arc<CanvasShader>>,
|
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||||
text_buffers: Vec<Arc<(CanvasText, CanvasTextCache)>>,
|
text_buffers: Vec<Arc<(CanvasText, CanvasTextCache)>>,
|
||||||
|
|
||||||
// Hold onto the vertices we get from the Compu and Canvas Frames
|
// Hold onto the vertices we get from the Compu and Canvas Frames
|
||||||
@@ -218,7 +217,6 @@ impl CanvasState {
|
|||||||
|
|
||||||
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
|
||||||
pub fn create_text_buffers(&mut self, dimensions: (u32, u32)) -> Arc<CanvasTextHandle> {
|
pub fn create_text_buffers(&mut self, dimensions: (u32, u32)) -> Arc<CanvasTextHandle> {
|
||||||
|
|
||||||
let handle = Arc::new(CanvasTextHandle { handle: self.text_buffers.len() as u32 });
|
let handle = Arc::new(CanvasTextHandle { handle: self.text_buffers.len() as u32 });
|
||||||
//
|
//
|
||||||
// let text = CanvasText {
|
// let text = CanvasText {
|
||||||
@@ -348,39 +346,21 @@ impl CanvasState {
|
|||||||
filename: String,
|
filename: String,
|
||||||
shader_type: ShaderType,
|
shader_type: ShaderType,
|
||||||
physical: PhysicalDevice,
|
physical: PhysicalDevice,
|
||||||
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>> {
|
||||||
|
|
||||||
let handle = Arc::new(CanvasShaderHandle {
|
let handle = Arc::new(CompiledGraphicsPipelineHandle {
|
||||||
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 {
|
|
||||||
ShaderType::SOLID => {
|
|
||||||
Arc::new(CanvasShader::new(
|
|
||||||
filename.clone(),
|
|
||||||
capabilities.clone(),
|
|
||||||
self.queue.clone(),
|
|
||||||
physical.clone(),
|
|
||||||
self.device.clone(),
|
|
||||||
handle.clone(),
|
|
||||||
self.render_pass.clone())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ShaderType::IMAGE | ShaderType::TEXTURED => {
|
|
||||||
Arc::new(CanvasShader::new(
|
|
||||||
filename.clone(),
|
|
||||||
capabilities.clone(),
|
|
||||||
self.queue.clone(),
|
|
||||||
physical.clone(),
|
|
||||||
self.device.clone(),
|
|
||||||
handle.clone(),
|
|
||||||
self.render_pass.clone())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
self.shader_buffers.push(shader.clone());
|
let shader : Box<dyn CompiledGraphicsPipeline> = Box::new(GenericShader::new(
|
||||||
|
filename.clone(),
|
||||||
|
self.device.clone(),
|
||||||
|
handle.clone(),
|
||||||
|
self.render_pass.clone()
|
||||||
|
));
|
||||||
|
|
||||||
|
self.shader_buffers.push(Arc::new(shader));
|
||||||
|
|
||||||
Some(handle)
|
Some(handle)
|
||||||
}
|
}
|
||||||
@@ -398,10 +378,10 @@ impl CanvasState {
|
|||||||
|
|
||||||
/// Using the shader name, iterates through the stored textures and matches by the name
|
/// Using the shader name, iterates through the stored textures and matches by the name
|
||||||
pub fn get_shader_handle(&self, shader_name: String)
|
pub fn get_shader_handle(&self, shader_name: String)
|
||||||
-> Option<Arc<CanvasShaderHandle>> {
|
-> Option<Arc<CompiledGraphicsPipelineHandle>> {
|
||||||
for shader in self.shader_buffers.clone() {
|
for shader in self.shader_buffers.clone() {
|
||||||
if shader.name == shader_name {
|
if shader.get_name() == shader_name {
|
||||||
return Some(shader.handle.clone());
|
return Some(shader.get_handle().clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@@ -487,7 +467,7 @@ impl CanvasState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the descriptor set for solid colors using the input kernel (needs to support solid colors)
|
/// Builds the descriptor set for solid colors using the input kernel (needs to support solid colors)
|
||||||
fn get_solid_color_descriptor_set(&self, kernel: Arc<CanvasShader>) -> Box<dyn DescriptorSet + Send + Sync> {
|
fn get_solid_color_descriptor_set(&self, kernel: Arc<GenericShader>) -> 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,
|
||||||
@@ -547,7 +527,7 @@ impl CanvasState {
|
|||||||
for (image_handle, vertex_buffer) in self.image_vertex_buffer.clone() {
|
for (image_handle, vertex_buffer) in self.image_vertex_buffer.clone() {
|
||||||
let handle = image_handle.clone().handle as usize;
|
let handle = image_handle.clone().handle as usize;
|
||||||
let descriptor_set = self.image_buffers.get(handle).clone().unwrap().clone()
|
let descriptor_set = self.image_buffers.get(handle).clone().unwrap().clone()
|
||||||
.get_descriptor_set(shader.clone());
|
.get_descriptor_set(shader.get_pipeline().clone());
|
||||||
|
|
||||||
command_buffer = command_buffer.draw(
|
command_buffer = command_buffer.draw(
|
||||||
shader.get_pipeline().clone(),
|
shader.get_pipeline().clone(),
|
||||||
@@ -555,7 +535,6 @@ impl CanvasState {
|
|||||||
&self.dynamic_state.clone(), vec![vertex_buffer],
|
&self.dynamic_state.clone(), vec![vertex_buffer],
|
||||||
vec![descriptor_set], (),
|
vec![descriptor_set], (),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,7 +548,7 @@ impl CanvasState {
|
|||||||
for (texture_handle, vertex_buffer) in self.textured_vertex_buffer.clone() {
|
for (texture_handle, vertex_buffer) in self.textured_vertex_buffer.clone() {
|
||||||
let handle = texture_handle.clone().handle as usize;
|
let handle = texture_handle.clone().handle as usize;
|
||||||
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
||||||
.get_descriptor_set(shader.clone(), self.sampler.clone());
|
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone());
|
||||||
|
|
||||||
command_buffer = command_buffer.draw(
|
command_buffer = command_buffer.draw(
|
||||||
shader.get_pipeline().clone(),
|
shader.get_pipeline().clone(),
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ pub mod canvas_buffer;
|
|||||||
|
|
||||||
|
|
||||||
use crate::canvas::canvas_frame::CanvasFrame;
|
use crate::canvas::canvas_frame::CanvasFrame;
|
||||||
|
use crate::canvas::canvas_shader::GenericShader;
|
||||||
@@ -16,7 +16,7 @@ use crate::canvas::canvas_frame::CanvasFrame;
|
|||||||
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
|
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
|
||||||
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
|
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use crate::canvas::canvas_shader::CanvasShaderHandle;
|
use crate::canvas::canvas_shader::{CanvasShaderHandle, CompiledGraphicsPipeline, CompiledGraphicsPipelineHandle};
|
||||||
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
|
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
|
||||||
@@ -171,7 +171,7 @@ impl<'a> VkProcessor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// O(n) Lookup for the matching shader string
|
/// O(n) Lookup for the matching shader string
|
||||||
pub fn get_shader_handle(&self, shader_name: String) -> Option<Arc<CanvasShaderHandle>> {
|
pub fn get_shader_handle(&self, shader_name: String) -> Option<Arc<CompiledGraphicsPipelineHandle>> {
|
||||||
self.canvas.get_shader_handle(shader_name)
|
self.canvas.get_shader_handle(shader_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user