initial impl of get image set

master
mitchellhansen 5 years ago
parent 77ccd415d0
commit 982e2ad517

@ -52,7 +52,7 @@ void main() {
ivec3 m = max(max(max(d0, d1), d2), d3);
if ((m.x + m.y + m.z) > 975){
if ((m.x + m.y + m.z) > 200){
p.x = 0;
p.y = 0;
p.z = 255;

@ -8,8 +8,6 @@ void main() {
ivec2 size = ivec2(gl_FragCoord.x, gl_FragCoord.y);
f_color = imageLoad(img, size) / (255.0);
// f_color.a += 100;
// f_color = texture(tex, tex_coords);
float gamma = 0.5;
f_color.rgb = pow(f_color.rgb, vec3(1.0/gamma));

@ -1,6 +1,6 @@
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess};
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc};
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc, PersistentDescriptorSetBuilder};
use vulkano::device::{Device, DeviceExtensions, QueuesIter, Queue};
use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, QueueFamily};
use vulkano::pipeline::{ComputePipeline, GraphicsPipeline, GraphicsPipelineAbstract};
@ -26,7 +26,7 @@ use vulkano::image::swapchain::SwapchainImage;
use winit::{EventsLoop, WindowBuilder, Window, Event, WindowEvent};
use vulkano_win::VkSurfaceBuild;
use vulkano::pipeline::vertex::{SingleBufferDefinition, Vertex};
use vulkano::descriptor::PipelineLayoutAbstract;
use vulkano::descriptor::{PipelineLayoutAbstract, DescriptorSet};
use std::alloc::Layout;
use vulkano::pipeline::viewport::Viewport;
use image::ImageFormat;
@ -277,7 +277,6 @@ impl<'a> VkProcessor<'a> {
self.settings_buffer = Some(settings_buffer);
// We now create a buffer that will store the shape of our triangle.
let vertex_buffer = {
vulkano::impl_vertex!(tVertex, position);
@ -301,7 +300,7 @@ impl<'a> VkProcessor<'a> {
).unwrap()
};
let attachment_image = {
let compute_transfer_image = {
let mut usage = ImageUsage::none();
usage.transfer_destination = true;
@ -318,19 +317,41 @@ impl<'a> VkProcessor<'a> {
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
self.img_set = Some(Arc::new(PersistentDescriptorSet::start(self.graphics_pipeline.clone().unwrap().clone(), 0)
// img_set is only used in the run()'s command buffer construction
// So, adding a get image set function, I can just build lazily
self.img_set = Some(Arc::new(PersistentDescriptorSet::start(
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0)
.add_sampled_image(texture.clone(), sampler.clone()).unwrap()
.add_image(attachment_image.clone().unwrap().clone()).unwrap()
.add_image(compute_transfer_image.clone().unwrap().clone()).unwrap()
.build().unwrap()));
self.graphics_image_buffer = Some(texture.clone());
self.graphics_image_swap_buffer = Some(attachment_image.clone().unwrap());
self.graphics_image_swap_buffer = Some(compute_transfer_image.clone().unwrap());
}
// The image set is the containing object for all texture and image hooks.
fn get_image_set(&mut self) -> Box<DescriptorSet + Send + Sync> {
let sampler = Sampler::new(self.device.clone(), Filter::Linear, Filter::Linear,
MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap();
let o : Box<DescriptorSet + Send + Sync> = Box::new(
PersistentDescriptorSet::start(
self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0
)
.add_sampled_image(self.graphics_image_buffer.clone().unwrap().clone(), sampler.clone()).unwrap()
.add_image(self.graphics_image_swap_buffer.clone().unwrap().clone()).unwrap()
.build().unwrap());
o
}
pub fn run(&mut self, surface: &'a Arc<Surface<Window>>, mut frame_future: Box<dyn GpuFuture>) -> Box<dyn GpuFuture> {
let mut framebuffers = window_size_dependent_setup(&self.shader_kernels.clone().unwrap().swapchain_images.clone(),
self.render_pass.clone().unwrap().clone(),
self.shader_kernels.clone().unwrap().render_pass.clone(),
&mut self.dynamic_state);
let mut recreate_swapchain = false;
@ -341,7 +362,7 @@ impl<'a> VkProcessor<'a> {
// Whenever the window resizes we need to recreate everything dependent on the window size.
// In this example that includes the swapchain, the framebuffers and the dynamic state viewport.
if recreate_swapchain {
//self.shader_kernels.unwrap().recreate_swapchain(surface);
self.shader_kernels = Some(self.shader_kernels.clone().unwrap().recreate_swapchain(surface));
framebuffers = window_size_dependent_setup(&self.shader_kernels.clone().unwrap().swapchain_images.clone(),
self.render_pass.clone().unwrap().clone(),
&mut self.dynamic_state);
@ -391,9 +412,10 @@ impl<'a> VkProcessor<'a> {
.begin_render_pass(framebuffers[image_num].clone(), false, clear_values)
.unwrap()
.draw(self.graphics_pipeline.clone().unwrap().clone(),
&self.dynamic_state, v,
self.img_set.clone().unwrap().clone(), ())
.draw(self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(),
&self.dynamic_state.clone(), v,
//self.img_set.clone().unwrap().clone(), ())
self.get_image_set(), ())
.unwrap()
.end_render_pass()

Loading…
Cancel
Save