still working on getting ownership of everything squared away
This commit is contained in:
@@ -3,7 +3,7 @@ use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
|
||||
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc};
|
||||
use vulkano::device::{Device, DeviceExtensions, QueuesIter, Queue};
|
||||
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, QueueFamily};
|
||||
use vulkano::pipeline::{ComputePipeline, GraphicsPipeline, GraphicsPipelineAbstract};
|
||||
use vulkano::pipeline::{ComputePipeline, GraphicsPipeline, GraphicsPipelineAbstract, GraphicsPipelineBuilder};
|
||||
use vulkano::sync::{GpuFuture, FlushError};
|
||||
use vulkano::sync;
|
||||
use std::time::SystemTime;
|
||||
@@ -51,11 +51,11 @@ struct EntryPoint<'a> {
|
||||
struct tVertex { position: [f32; 2] }
|
||||
|
||||
pub struct ShaderKernels<'a> {
|
||||
swapchain : Arc<Swapchain<Window>>,
|
||||
swapchain_images: Vec<Arc<SwapchainImage<Window>>>, // Surface which is drawn to
|
||||
pub swapchain : Arc<Swapchain<Window>>,
|
||||
pub swapchain_images: Vec<Arc<SwapchainImage<Window>>>, // Surface which is drawn to
|
||||
pub physical: PhysicalDevice<'a>,
|
||||
|
||||
shader: CompiledShaders,
|
||||
// shader: CompiledShaders,
|
||||
|
||||
options: CompileOptions<'a>,
|
||||
|
||||
@@ -64,7 +64,7 @@ pub struct ShaderKernels<'a> {
|
||||
|
||||
device: Arc<Device>,
|
||||
|
||||
entry_point: EntryPoint<'a>,
|
||||
// entry_point: EntryPoint<'a>,
|
||||
}
|
||||
|
||||
// return the frame buffers
|
||||
@@ -101,43 +101,33 @@ impl<'a> ShaderKernels<'a> {
|
||||
match self.graphics_pipeline.clone() {
|
||||
Some(t) => t,
|
||||
None => {
|
||||
self.graphics_pipeline = Some(Arc::new(
|
||||
GraphicsPipeline::start()
|
||||
// We need to indicate the layout of the vertices.
|
||||
// The type `SingleBufferDefinition` actually contains a template parameter corresponding
|
||||
// to the type of each vertex. But in this code it is automatically inferred.
|
||||
.vertex_input_single_buffer::<tVertex>()
|
||||
|
||||
// A Vulkan shader can in theory contain multiple entry points, so we have to specify
|
||||
// which one. The `main` word of `main_entry_point` actually corresponds to the name of
|
||||
// the entry point.
|
||||
.vertex_shader(self.entry_point.vertex_entry_point.clone().unwrap(), SimpleSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// The content of the vertex buffer describes a list of triangles.
|
||||
.triangle_fan()
|
||||
// Use a resizable viewport set to draw over the entire window
|
||||
.viewports_dynamic_scissors_irrelevant(1)
|
||||
// See `vertex_shader`.
|
||||
.fragment_shader(self.entry_point.frag_entry_point.clone().unwrap(), SimpleSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// We have to indicate which subpass of which render pass this pipeline is going to be used
|
||||
// in. The pipeline will only be usable from this particular subpass.
|
||||
.render_pass(Subpass::from(self.render_pass.clone(), 0).unwrap())
|
||||
// Now that our builder is filled, we call `build()` to obtain an actual pipeline.
|
||||
.build(self.device.clone())
|
||||
.unwrap()
|
||||
));
|
||||
// TODO: Create new graphics pipeline
|
||||
self.graphics_pipeline.clone().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On resizes we have to recreate the swapchain
|
||||
pub fn recreate_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) {
|
||||
let dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
||||
let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
||||
[dimensions.0, dimensions.1]
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let (new_swapchain, new_images) = match self.swapchain.clone().recreate_with_dimension(dimensions) {
|
||||
Ok(r) => r,
|
||||
// This error tends to happen when the user is manually resizing the window.
|
||||
// Simply restarting the loop is the easiest way to fix this issue.
|
||||
Err(SwapchainCreationError::UnsupportedDimensions) => panic!("Uh oh"),
|
||||
Err(err) => panic!("{:?}", err)
|
||||
};
|
||||
|
||||
self.swapchain = new_swapchain;
|
||||
self.swapchain_images = new_images;
|
||||
}
|
||||
|
||||
pub fn new(filename: String,
|
||||
surface: &'a Arc<Surface<Window>>,
|
||||
queue: Arc<Queue>,
|
||||
@@ -185,33 +175,32 @@ impl<'a> ShaderKernels<'a> {
|
||||
.expect("failed to parse");
|
||||
|
||||
let fragment_shader_module: Arc<ShaderModule> = unsafe {
|
||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader.fragment.clone())
|
||||
let filenames1 = ShaderKernels::get_path(filename.clone());
|
||||
let shader1 = sr::load(filenames1.0, filenames1.1)
|
||||
.expect("Shader didn't compile");
|
||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader1.fragment.clone())
|
||||
}.unwrap();
|
||||
|
||||
let vertex_shader_module: Arc<ShaderModule> = unsafe {
|
||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader.vertex.clone())
|
||||
let filenames1 = ShaderKernels::get_path(filename.clone());
|
||||
let shader1 = sr::load(filenames1.0, filenames1.1)
|
||||
.expect("Shader didn't compile");
|
||||
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader1.vertex.clone())
|
||||
}.unwrap();
|
||||
|
||||
let filenames = ShaderKernels::get_path(filename.clone());
|
||||
let mut entry_point = EntryPoint {
|
||||
compiled_shaders: sr::load(filenames.0, filenames.1)
|
||||
.expect("Shader didn't compile"),
|
||||
fragment_shader_module: fragment_shader_module,
|
||||
vertex_shader_module: vertex_shader_module,
|
||||
frag_entry_point: None,
|
||||
vertex_entry_point: None,
|
||||
};
|
||||
|
||||
entry_point.frag_entry_point = unsafe {
|
||||
Some(entry_point.fragment_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||
|
||||
let frag_entry_point = unsafe {
|
||||
Some(fragment_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||
vulkano_entry.frag_input,
|
||||
vulkano_entry.frag_output,
|
||||
vulkano_entry.frag_layout,
|
||||
GraphicsShaderType::Fragment))
|
||||
};
|
||||
|
||||
entry_point.vertex_entry_point = unsafe {
|
||||
Some(entry_point.vertex_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||
let vertex_entry_point = unsafe {
|
||||
Some(vertex_shader_module.graphics_entry_point(CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
||||
vulkano_entry.vert_input,
|
||||
vulkano_entry.vert_output,
|
||||
vulkano_entry.vert_layout,
|
||||
@@ -247,39 +236,6 @@ impl<'a> ShaderKernels<'a> {
|
||||
).unwrap());
|
||||
|
||||
vulkano::impl_vertex!(tVertex, position);
|
||||
// Before we draw we have to create what is called a pipeline. This is similar to an OpenGL
|
||||
// program, but much more specific.
|
||||
let pipeline = GraphicsPipeline::start()
|
||||
// We need to indicate the layout of the vertices.
|
||||
// The type `SingleBufferDefinition` actually contains a template parameter corresponding
|
||||
// to the type of each vertex. But in this code it is automatically inferred.
|
||||
.vertex_input_single_buffer::<tVertex>()
|
||||
|
||||
// A Vulkan shader can in theory contain multiple entry points, so we have to specify
|
||||
// which one. The `main` word of `main_entry_point` actually corresponds to the name of
|
||||
// the entry point.
|
||||
.vertex_shader(entry_point.vertex_entry_point.clone().unwrap(), SimpleSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// The content of the vertex buffer describes a list of triangles.
|
||||
.triangle_fan()
|
||||
// Use a resizable viewport set to draw over the entire window
|
||||
.viewports_dynamic_scissors_irrelevant(1)
|
||||
// See `vertex_shader`.
|
||||
.fragment_shader(entry_point.frag_entry_point.clone().unwrap(), SimpleSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// We have to indicate which subpass of which render pass this pipeline is going to be used
|
||||
// in. The pipeline will only be usable from this particular subpass.
|
||||
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
|
||||
// Now that our builder is filled, we call `build()` to obtain an actual pipeline.
|
||||
.build(device.clone())
|
||||
.unwrap();
|
||||
|
||||
|
||||
|
||||
ShaderKernels {
|
||||
@@ -287,13 +243,41 @@ impl<'a> ShaderKernels<'a> {
|
||||
swapchain_images: images,
|
||||
physical: physical,
|
||||
|
||||
shader: shader,
|
||||
|
||||
options: CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(),
|
||||
render_pass: render_pass,
|
||||
graphics_pipeline: Some(Arc::new(pipeline)),
|
||||
|
||||
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
||||
// We need to indicate the layout of the vertices.
|
||||
// The type `SingleBufferDefinition` actually contains a template parameter corresponding
|
||||
// to the type of each vertex. But in this code it is automatically inferred.
|
||||
.vertex_input_single_buffer::<tVertex>()
|
||||
|
||||
// A Vulkan shader can in theory contain multiple entry points, so we have to specify
|
||||
// which one. The `main` word of `main_entry_point` actually corresponds to the name of
|
||||
// the entry point.
|
||||
.vertex_shader(vertex_entry_point.clone().unwrap(), SimpleSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// The content of the vertex buffer describes a list of triangles.
|
||||
.triangle_fan()
|
||||
// Use a resizable viewport set to draw over the entire window
|
||||
.viewports_dynamic_scissors_irrelevant(1)
|
||||
// See `vertex_shader`.
|
||||
.fragment_shader(frag_entry_point.clone().unwrap(), SimpleSpecializationConstants {
|
||||
first_constant: 0,
|
||||
second_constant: 0,
|
||||
third_constant: 0.0,
|
||||
})
|
||||
// We have to indicate which subpass of which render pass this pipeline is going to be used
|
||||
// in. The pipeline will only be usable from this particular subpass.
|
||||
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
|
||||
// Now that our builder is filled, we call `build()` to obtain an actual pipeline.
|
||||
.build(device.clone())
|
||||
.unwrap())),
|
||||
|
||||
device: device,
|
||||
entry_point: entry_point,
|
||||
render_pass: render_pass,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user