vk: log commands to renderpass
This commit is contained in:
parent
4595a5ccc3
commit
f8ba964b01
7 changed files with 123 additions and 13 deletions
|
@ -87,6 +87,16 @@ impl From<Size<u32>> for vk::Extent3D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Size<u32>> for vk::Extent2D {
|
||||||
|
fn from(value: Size<u32>) -> Self {
|
||||||
|
vk::Extent2D {
|
||||||
|
width: value.width,
|
||||||
|
height: value.height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<vk::Extent3D> for Size<u32> {
|
impl From<vk::Extent3D> for Size<u32> {
|
||||||
fn from(value: vk::Extent3D) -> Self {
|
fn from(value: vk::Extent3D) -> Self {
|
||||||
Size {
|
Size {
|
||||||
|
@ -123,6 +133,18 @@ impl From<&vk::Viewport> for Size<u32> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Size<u32>> for vk::Viewport {
|
||||||
|
fn from(value: Size<u32>) -> Self {
|
||||||
|
vk::Viewport {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
width: value.width as f32,
|
||||||
|
height: value.height as f32,
|
||||||
|
min_depth: 0.0,
|
||||||
|
max_depth: 1.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
impl From<FilterMode> for vk::Filter {
|
impl From<FilterMode> for vk::Filter {
|
||||||
fn from(value: FilterMode) -> Self {
|
fn from(value: FilterMode) -> Self {
|
||||||
match value {
|
match value {
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl DrawQuad {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_vbo(&self, cmd: &vk::CommandBuffer, vbo: VboType) {
|
pub fn bind_vbo(&self, cmd: vk::CommandBuffer, vbo: VboType) {
|
||||||
let offset = match vbo {
|
let offset = match vbo {
|
||||||
VboType::Offscreen => 0,
|
VboType::Offscreen => 0,
|
||||||
VboType::Final => std::mem::size_of::<[f32; 16]>(),
|
VboType::Final => std::mem::size_of::<[f32; 16]>(),
|
||||||
|
@ -66,7 +66,7 @@ impl DrawQuad {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.device.cmd_bind_vertex_buffers(
|
self.device.cmd_bind_vertex_buffers(
|
||||||
*cmd,
|
cmd,
|
||||||
0,
|
0,
|
||||||
&[self.buffer.handle],
|
&[self.buffer.handle],
|
||||||
&[offset as vk::DeviceSize],
|
&[offset as vk::DeviceSize],
|
||||||
|
|
|
@ -22,9 +22,9 @@ use librashader_runtime::uniforms::UniformStorage;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use crate::draw_quad::{VBO_DEFAULT_FINAL, VBO_OFFSCREEN};
|
use crate::draw_quad::{DrawQuad, VBO_DEFAULT_FINAL, VBO_OFFSCREEN};
|
||||||
use crate::framebuffer::OutputFramebuffer;
|
use crate::framebuffer::OutputFramebuffer;
|
||||||
use crate::rendertarget::RenderTarget;
|
use crate::rendertarget::{DEFAULT_MVP, RenderTarget};
|
||||||
|
|
||||||
pub struct Vulkan {
|
pub struct Vulkan {
|
||||||
// physical_device: vk::PhysicalDevice,
|
// physical_device: vk::PhysicalDevice,
|
||||||
|
@ -130,7 +130,6 @@ pub struct FilterChainVulkan {
|
||||||
pub(crate) output_framebuffers: Box<[OwnedTexture]>,
|
pub(crate) output_framebuffers: Box<[OwnedTexture]>,
|
||||||
// pub(crate) feedback_framebuffers: Box<[OwnedFramebuffer]>,
|
// pub(crate) feedback_framebuffers: Box<[OwnedFramebuffer]>,
|
||||||
// pub(crate) history_framebuffers: VecDeque<OwnedFramebuffer>,
|
// pub(crate) history_framebuffers: VecDeque<OwnedFramebuffer>,
|
||||||
// pub(crate) draw_quad: DrawQuad,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FilterMutable {
|
pub struct FilterMutable {
|
||||||
|
@ -141,10 +140,13 @@ pub struct FilterMutable {
|
||||||
pub(crate) struct FilterCommon {
|
pub(crate) struct FilterCommon {
|
||||||
pub(crate) luts: FxHashMap<usize, LutTexture>,
|
pub(crate) luts: FxHashMap<usize, LutTexture>,
|
||||||
pub samplers: SamplerSet,
|
pub samplers: SamplerSet,
|
||||||
|
pub(crate) draw_quad: DrawQuad,
|
||||||
|
|
||||||
// pub output_textures: Box<[Option<Texture>]>,
|
// pub output_textures: Box<[Option<Texture>]>,
|
||||||
// pub feedback_textures: Box<[Option<Texture>]>,
|
// pub feedback_textures: Box<[Option<Texture>]>,
|
||||||
// pub history_textures: Box<[Option<Texture>]>,
|
// pub history_textures: Box<[Option<Texture>]>,
|
||||||
pub config: FilterMutable,
|
pub config: FilterMutable,
|
||||||
|
pub device: ash::Device,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FilterChainOptionsVulkan = ();
|
pub type FilterChainOptionsVulkan = ();
|
||||||
|
@ -200,6 +202,8 @@ impl FilterChainVulkan {
|
||||||
.map(|param| (param.name, param.value))
|
.map(|param| (param.name, param.value))
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
|
draw_quad: DrawQuad::new(&device.device, &device.memory_properties)?,
|
||||||
|
device: device.device.clone()
|
||||||
},
|
},
|
||||||
passes: filters,
|
passes: filters,
|
||||||
vulkan: device,
|
vulkan: device,
|
||||||
|
@ -470,7 +474,7 @@ impl FilterChainVulkan {
|
||||||
let target = &self.output_framebuffers[index];
|
let target = &self.output_framebuffers[index];
|
||||||
// todo: use proper mode
|
// todo: use proper mode
|
||||||
let out = RenderTarget {
|
let out = RenderTarget {
|
||||||
mvp: VBO_DEFAULT_FINAL,
|
mvp: DEFAULT_MVP,
|
||||||
output: OutputFramebuffer::new(&self.vulkan, &pass.graphics_pipeline.render_pass, target.image.image, target.image.size)?,
|
output: OutputFramebuffer::new(&self.vulkan, &pass.graphics_pipeline.render_pass, target.image.image, target.image.size)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::error;
|
use crate::{error, util};
|
||||||
use crate::filter_chain::FilterCommon;
|
use crate::filter_chain::FilterCommon;
|
||||||
use crate::rendertarget::RenderTarget;
|
use crate::rendertarget::RenderTarget;
|
||||||
use crate::samplers::{SamplerSet, VulkanSampler};
|
use crate::samplers::{SamplerSet, VulkanSampler};
|
||||||
|
@ -10,12 +10,11 @@ use librashader_common::{ImageFormat, Size};
|
||||||
use librashader_preprocess::ShaderSource;
|
use librashader_preprocess::ShaderSource;
|
||||||
use librashader_presets::ShaderPassConfig;
|
use librashader_presets::ShaderPassConfig;
|
||||||
use librashader_reflect::back::ShaderCompilerOutput;
|
use librashader_reflect::back::ShaderCompilerOutput;
|
||||||
use librashader_reflect::reflect::semantics::{
|
use librashader_reflect::reflect::semantics::{BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics};
|
||||||
MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
|
|
||||||
};
|
|
||||||
use librashader_reflect::reflect::ShaderReflection;
|
use librashader_reflect::reflect::ShaderReflection;
|
||||||
use librashader_runtime::uniforms::UniformStorage;
|
use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use crate::draw_quad::VboType;
|
||||||
|
|
||||||
pub struct FilterPass {
|
pub struct FilterPass {
|
||||||
pub device: ash::Device,
|
pub device: ash::Device,
|
||||||
|
@ -101,6 +100,50 @@ impl FilterPass {
|
||||||
.bind_to_descriptor_set(descriptor, ubo.binding, &self.uniform_storage)?;
|
.bind_to_descriptor_set(descriptor, ubo.binding, &self.uniform_storage)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output.output.begin_pass(cmd);
|
||||||
|
|
||||||
|
let render_pass_info = vk::RenderPassBeginInfo::builder()
|
||||||
|
.framebuffer(output.output.framebuffer)
|
||||||
|
.render_pass(self.graphics_pipeline.render_pass.handle)
|
||||||
|
.render_area(vk::Rect2D {
|
||||||
|
offset: Default::default(),
|
||||||
|
extent: output.output.size.into(),
|
||||||
|
}).build();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
parent.device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE);
|
||||||
|
parent.device.cmd_bind_pipeline(cmd, vk::PipelineBindPoint::GRAPHICS, self.graphics_pipeline.pipeline);
|
||||||
|
|
||||||
|
// todo: allow frames in flight.
|
||||||
|
parent.device.cmd_bind_descriptor_sets(cmd, vk::PipelineBindPoint::GRAPHICS, self.graphics_pipeline.layout.layout, 0,
|
||||||
|
&[self.graphics_pipeline.layout.descriptor_sets[0]], &[]);
|
||||||
|
|
||||||
|
if let Some(push) = &self.reflection.push_constant {
|
||||||
|
let mut stage_mask = vk::ShaderStageFlags::empty();
|
||||||
|
if push.stage_mask.contains(BindingStage::FRAGMENT) {
|
||||||
|
stage_mask |= vk::ShaderStageFlags::FRAGMENT;
|
||||||
|
}
|
||||||
|
if push.stage_mask.contains(BindingStage::VERTEX) {
|
||||||
|
stage_mask |= vk::ShaderStageFlags::VERTEX;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.device.cmd_push_constants(cmd, self.graphics_pipeline.layout.layout, stage_mask, 0, self.uniform_storage.push_slice());
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.draw_quad.bind_vbo(cmd, VboType::Offscreen);
|
||||||
|
|
||||||
|
parent.device.cmd_set_scissor(cmd, 0, &[
|
||||||
|
vk::Rect2D {
|
||||||
|
offset: Default::default(),
|
||||||
|
extent: output.output.size.into()
|
||||||
|
}]);
|
||||||
|
|
||||||
|
parent.device.cmd_set_viewport(cmd, 0, &[output.output.size.into()]);
|
||||||
|
parent.device.cmd_draw(cmd, 4, 1, 0, 0);
|
||||||
|
parent.device.cmd_end_render_pass(cmd);
|
||||||
|
|
||||||
|
output.output.end_pass(cmd);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::error;
|
use crate::{error, util};
|
||||||
use crate::filter_chain::Vulkan;
|
use crate::filter_chain::Vulkan;
|
||||||
use crate::renderpass::VulkanRenderPass;
|
use crate::renderpass::VulkanRenderPass;
|
||||||
use crate::texture::OwnedTexture;
|
use crate::texture::OwnedTexture;
|
||||||
|
@ -70,6 +70,7 @@ pub(crate) struct OutputFramebuffer {
|
||||||
pub size: Size<u32>,
|
pub size: Size<u32>,
|
||||||
device: ash::Device,
|
device: ash::Device,
|
||||||
image_view: vk::ImageView,
|
image_view: vk::ImageView,
|
||||||
|
image: vk::Image,
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -125,11 +126,43 @@ impl OutputFramebuffer {
|
||||||
Ok(OutputFramebuffer {
|
Ok(OutputFramebuffer {
|
||||||
device: vulkan.device.clone(),
|
device: vulkan.device.clone(),
|
||||||
size,
|
size,
|
||||||
|
image,
|
||||||
framebuffer,
|
framebuffer,
|
||||||
image_view,
|
image_view,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn begin_pass(&self, cmd: vk::CommandBuffer) {
|
||||||
|
unsafe {
|
||||||
|
util::vulkan_image_layout_transition_levels(&self.device, cmd, self.image,
|
||||||
|
1,
|
||||||
|
vk::ImageLayout::UNDEFINED,
|
||||||
|
vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
|
||||||
|
vk::AccessFlags::empty(),
|
||||||
|
vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE,
|
||||||
|
vk::PipelineStageFlags::ALL_GRAPHICS,
|
||||||
|
vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT,
|
||||||
|
vk::QUEUE_FAMILY_IGNORED,
|
||||||
|
vk::QUEUE_FAMILY_IGNORED)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn end_pass(&self, cmd: vk::CommandBuffer) {
|
||||||
|
// todo: generate mips
|
||||||
|
unsafe {
|
||||||
|
util::vulkan_image_layout_transition_levels(&self.device, cmd, self.image,
|
||||||
|
vk::REMAINING_MIP_LEVELS,
|
||||||
|
vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
|
||||||
|
vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
|
||||||
|
vk::AccessFlags::COLOR_ATTACHMENT_WRITE,
|
||||||
|
vk::AccessFlags::SHADER_READ,
|
||||||
|
vk::PipelineStageFlags::ALL_GRAPHICS,
|
||||||
|
vk::PipelineStageFlags::FRAGMENT_SHADER,
|
||||||
|
vk::QUEUE_FAMILY_IGNORED,
|
||||||
|
vk::QUEUE_FAMILY_IGNORED)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn get_renderpass_begin_info(&self, area: vk::Rect2D, clear: Option<&[vk::ClearValue]>) -> vk::RenderPassBeginInfo {
|
// pub fn get_renderpass_begin_info(&self, area: vk::Rect2D, clear: Option<&[vk::ClearValue]>) -> vk::RenderPassBeginInfo {
|
||||||
// let mut builder = vk::RenderPassBeginInfo::builder()
|
// let mut builder = vk::RenderPassBeginInfo::builder()
|
||||||
// .render_pass(self.render_pass.handle)
|
// .render_pass(self.render_pass.handle)
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
use crate::framebuffer::OutputFramebuffer;
|
use crate::framebuffer::OutputFramebuffer;
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
pub static DEFAULT_MVP: &[f32; 16] = &[
|
||||||
|
2f32, 0.0, 0.0, 0.0,
|
||||||
|
0.0, 2.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 2.0, 0.0,
|
||||||
|
-1.0, -1.0, 0.0, 1.0,
|
||||||
|
];
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct RenderTarget<'a> {
|
pub(crate) struct RenderTarget<'a> {
|
||||||
pub mvp: &'a [f32; 16],
|
pub mvp: &'a [f32; 16],
|
||||||
|
|
|
@ -178,7 +178,7 @@ impl Drop for VulkanShaderModule {
|
||||||
pub struct VulkanGraphicsPipeline {
|
pub struct VulkanGraphicsPipeline {
|
||||||
pub layout: PipelineLayoutObjects,
|
pub layout: PipelineLayoutObjects,
|
||||||
pub render_pass: VulkanRenderPass,
|
pub render_pass: VulkanRenderPass,
|
||||||
pipeline: vk::Pipeline,
|
pub pipeline: vk::Pipeline,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VulkanGraphicsPipeline {
|
impl VulkanGraphicsPipeline {
|
||||||
|
|
Loading…
Add table
Reference in a new issue