|
|
@ -1,7 +1,7 @@
|
|
|
|
use std::ffi::CStr;
|
|
|
|
use std::ffi::CStr;
|
|
|
|
use vulkano::buffer::{CpuAccessibleBuffer, BufferUsage};
|
|
|
|
use vulkano::buffer::{CpuAccessibleBuffer, BufferUsage};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::canvas::{Drawable, CanvasState, CanvasImageHandle, CanvasTextureHandle};
|
|
|
|
use crate::canvas::canvas_state::{Drawable, CanvasState, CanvasImageHandle, CanvasTextureHandle};
|
|
|
|
use vulkano::framebuffer::RenderPassAbstract;
|
|
|
|
use vulkano::framebuffer::RenderPassAbstract;
|
|
|
|
use vulkano::pipeline::{GraphicsPipelineAbstract, ComputePipeline};
|
|
|
|
use vulkano::pipeline::{GraphicsPipelineAbstract, ComputePipeline};
|
|
|
|
use vulkano::device::Device;
|
|
|
|
use vulkano::device::Device;
|
|
|
@ -18,9 +18,9 @@ use std::path::PathBuf;
|
|
|
|
use shade_runner::{CompiledShaders, Entry, CompileError};
|
|
|
|
use shade_runner::{CompiledShaders, Entry, CompileError};
|
|
|
|
use vulkano::pipeline::shader::ShaderModule;
|
|
|
|
use vulkano::pipeline::shader::ShaderModule;
|
|
|
|
use shaderc::CompileOptions;
|
|
|
|
use shaderc::CompileOptions;
|
|
|
|
use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
|
|
|
|
use crate::compute::compu_kernel::{CompuKernel, CompuKernelHandle};
|
|
|
|
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
|
|
|
|
use crate::compute::compu_buffer::{CompuBuffers, CompuBufferHandle};
|
|
|
|
use crate::compu_frame::CompuFrame;
|
|
|
|
use crate::compute::compu_frame::CompuFrame;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Canvas analog
|
|
|
|
// Canvas analog
|
|
|
@ -30,7 +30,6 @@ pub struct CompuState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CompuState {
|
|
|
|
impl CompuState {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new() -> CompuState {
|
|
|
|
pub fn new() -> CompuState {
|
|
|
|
CompuState {
|
|
|
|
CompuState {
|
|
|
|
compute_buffers: vec![],
|
|
|
|
compute_buffers: vec![],
|
|
|
@ -43,7 +42,6 @@ impl CompuState {
|
|
|
|
dimensions: (u32, u32),
|
|
|
|
dimensions: (u32, u32),
|
|
|
|
stride: u32,
|
|
|
|
stride: u32,
|
|
|
|
device: Arc<Device>) -> Arc<CompuBufferHandle> {
|
|
|
|
device: Arc<Device>) -> Arc<CompuBufferHandle> {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CompuBufferHandle {
|
|
|
|
let handle = Arc::new(CompuBufferHandle {
|
|
|
|
handle: self.compute_buffers.len() as u32
|
|
|
|
handle: self.compute_buffers.len() as u32
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -65,7 +63,6 @@ impl CompuState {
|
|
|
|
pub fn new_kernel(&mut self,
|
|
|
|
pub fn new_kernel(&mut self,
|
|
|
|
filename: String,
|
|
|
|
filename: String,
|
|
|
|
device: Arc<Device>) -> Arc<CompuKernelHandle> {
|
|
|
|
device: Arc<Device>) -> Arc<CompuKernelHandle> {
|
|
|
|
|
|
|
|
|
|
|
|
let handle = Arc::new(CompuKernelHandle {
|
|
|
|
let handle = Arc::new(CompuKernelHandle {
|
|
|
|
handle: self.kernels.len() as u32
|
|
|
|
handle: self.kernels.len() as u32
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -104,13 +101,13 @@ impl CompuState {
|
|
|
|
let size = buffer.get_size();
|
|
|
|
let size = buffer.get_size();
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer
|
|
|
|
command_buffer = command_buffer
|
|
|
|
.dispatch([size.0/8,size.1/8,1], p, d, ()).unwrap()
|
|
|
|
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// i = (Buffer, Image, Kernel)
|
|
|
|
// i = (Buffer, Image, Kernel)
|
|
|
|
for i in compute_frame.swapped_to_image {
|
|
|
|
for i in compute_frame.swapped_to_image {
|
|
|
|
let buffer_id = (*i.0).clone().handle as usize;
|
|
|
|
let buffer_id = (*i.0).clone().handle as usize;
|
|
|
|
let image_id = i.1.clone();
|
|
|
|
let image_id = i.1.clone();
|
|
|
|
let kernel_id = (*i.2).clone().handle as usize;
|
|
|
|
let kernel_id = (*i.2).clone().handle as usize;
|
|
|
|
|
|
|
|
|
|
|
|
let buffer = self.compute_buffers.get(buffer_id).unwrap();
|
|
|
|
let buffer = self.compute_buffers.get(buffer_id).unwrap();
|
|
|
@ -129,7 +126,7 @@ impl CompuState {
|
|
|
|
let size = buffer.get_size();
|
|
|
|
let size = buffer.get_size();
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer
|
|
|
|
command_buffer = command_buffer
|
|
|
|
.dispatch([size.0/8,size.1/8,1], p, d, ()).unwrap()
|
|
|
|
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
|
|
|
|
.copy_buffer_to_image(buffer.get_input_buffer(), image).unwrap();
|
|
|
|
.copy_buffer_to_image(buffer.get_input_buffer(), image).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -137,7 +134,7 @@ impl CompuState {
|
|
|
|
// i = (Input Buffer, Output Buffer, Kernel)
|
|
|
|
// i = (Input Buffer, Output Buffer, Kernel)
|
|
|
|
// Input buffer -> Kernel -> Output buffer
|
|
|
|
// Input buffer -> Kernel -> Output buffer
|
|
|
|
for i in compute_frame.swapped_to_buffer {
|
|
|
|
for i in compute_frame.swapped_to_buffer {
|
|
|
|
let input_buffer_id = (*i.0).clone().handle as usize;
|
|
|
|
let input_buffer_id = (*i.0).clone().handle as usize;
|
|
|
|
let output_buffer_id = (*i.1).clone().handle as usize;
|
|
|
|
let output_buffer_id = (*i.1).clone().handle as usize;
|
|
|
|
let kernel_id = (*i.2).clone().handle as usize;
|
|
|
|
let kernel_id = (*i.2).clone().handle as usize;
|
|
|
|
|
|
|
|
|
|
|
@ -154,7 +151,7 @@ impl CompuState {
|
|
|
|
let size = input_buffer.get_size();
|
|
|
|
let size = input_buffer.get_size();
|
|
|
|
|
|
|
|
|
|
|
|
command_buffer = command_buffer
|
|
|
|
command_buffer = command_buffer
|
|
|
|
// .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap()
|
|
|
|
// .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap()
|
|
|
|
.copy_buffer(
|
|
|
|
.copy_buffer(
|
|
|
|
input_buffer.get_output_buffer(),
|
|
|
|
input_buffer.get_output_buffer(),
|
|
|
|
output_buffer.get_input_buffer()).unwrap();
|
|
|
|
output_buffer.get_input_buffer()).unwrap();
|