refactor: graphics type aliases

This commit is contained in:
galister
2024-03-06 18:41:34 +01:00
parent 27d77ad638
commit 5800d7d99d

View File

@@ -15,6 +15,15 @@ use vulkano::{device::physical::PhysicalDeviceType, instance::InstanceCreateFlag
#[cfg(feature = "openxr")] #[cfg(feature = "openxr")]
use {ash::vk, std::os::raw::c_void}; use {ash::vk, std::os::raw::c_void};
pub type Vert2Buf = Subbuffer<[Vert2Uv]>;
pub type IndexBuf = Subbuffer<[u16]>;
pub type LegacyPipeline = WlxPipeline<WlxPipelineLegacy>;
pub type DynamicPipeline = WlxPipeline<WlxPipelineDynamic>;
pub type LegacyPass = WlxPass<WlxPipelineLegacy>;
pub type DynamicPass = WlxPass<WlxPipelineDynamic>;
use vulkano::{ use vulkano::{
buffer::{ buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo}, allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
@@ -118,8 +127,8 @@ pub struct WlxGraphics {
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>, pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>, pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
pub quad_verts: Subbuffer<[Vert2Uv]>, pub quad_verts: Vert2Buf,
pub quad_indices: Subbuffer<[u16]>, pub quad_indices: IndexBuf,
pub shared_shaders: RwLock<HashMap<&'static str, Arc<ShaderModule>>>, pub shared_shaders: RwLock<HashMap<&'static str, Arc<ShaderModule>>>,
} }
@@ -474,7 +483,7 @@ impl WlxGraphics {
fn default_quad( fn default_quad(
memory_allocator: Arc<StandardMemoryAllocator>, memory_allocator: Arc<StandardMemoryAllocator>,
) -> anyhow::Result<(Subbuffer<[Vert2Uv]>, Subbuffer<[u16]>)> { ) -> anyhow::Result<(Vert2Buf, IndexBuf)> {
let vertices = [ let vertices = [
Vert2Uv { Vert2Uv {
in_pos: [0., 0.], in_pos: [0., 0.],
@@ -532,7 +541,7 @@ impl WlxGraphics {
y: f32, y: f32,
w: f32, w: f32,
h: f32, h: f32,
) -> anyhow::Result<Subbuffer<[Vert2Uv]>> { ) -> anyhow::Result<Vert2Buf> {
let rw = width; let rw = width;
let rh = height; let rh = height;
@@ -704,8 +713,8 @@ impl WlxGraphics {
frag: Arc<ShaderModule>, frag: Arc<ShaderModule>,
format: Format, format: Format,
blend: Option<AttachmentBlend>, blend: Option<AttachmentBlend>,
) -> anyhow::Result<Arc<WlxPipeline<WlxPipelineLegacy>>> { ) -> anyhow::Result<Arc<LegacyPipeline>> {
Ok(Arc::new(WlxPipeline::<WlxPipelineLegacy>::new( Ok(Arc::new(LegacyPipeline::new(
render_target, render_target,
self.clone(), self.clone(),
vert, vert,
@@ -724,8 +733,8 @@ impl WlxGraphics {
blend: Option<AttachmentBlend>, blend: Option<AttachmentBlend>,
initial_layout: ImageLayout, initial_layout: ImageLayout,
final_layout: ImageLayout, final_layout: ImageLayout,
) -> anyhow::Result<Arc<WlxPipeline<WlxPipelineLegacy>>> { ) -> anyhow::Result<Arc<LegacyPipeline>> {
Ok(Arc::new(WlxPipeline::<WlxPipelineLegacy>::new_with_layout( Ok(Arc::new(LegacyPipeline::new_with_layout(
render_target, render_target,
self.clone(), self.clone(),
vert, vert,
@@ -744,8 +753,8 @@ impl WlxGraphics {
frag: Arc<ShaderModule>, frag: Arc<ShaderModule>,
format: Format, format: Format,
blend: Option<AttachmentBlend>, blend: Option<AttachmentBlend>,
) -> anyhow::Result<Arc<WlxPipeline<WlxPipelineDynamic>>> { ) -> anyhow::Result<Arc<DynamicPipeline>> {
Ok(Arc::new(WlxPipeline::<WlxPipelineDynamic>::new( Ok(Arc::new(DynamicPipeline::new(
self.clone(), self.clone(),
vert, vert,
frag, frag,
@@ -841,10 +850,7 @@ pub struct WlxCommandBuffer {
#[allow(dead_code)] #[allow(dead_code)]
impl WlxCommandBuffer { impl WlxCommandBuffer {
pub fn begin_render_pass( pub fn begin_render_pass(&mut self, pipeline: &LegacyPipeline) -> anyhow::Result<()> {
&mut self,
pipeline: &WlxPipeline<WlxPipelineLegacy>,
) -> anyhow::Result<()> {
self.command_buffer.begin_render_pass( self.command_buffer.begin_render_pass(
RenderPassBeginInfo { RenderPassBeginInfo {
clear_values: vec![Some([0.0, 0.0, 0.0, 0.0].into())], clear_values: vec![Some([0.0, 0.0, 0.0, 0.0].into())],
@@ -1031,11 +1037,11 @@ impl WlxPipeline<WlxPipelineDynamic> {
pub fn create_pass( pub fn create_pass(
self: &Arc<Self>, self: &Arc<Self>,
dimensions: [f32; 2], dimensions: [f32; 2],
vertex_buffer: Subbuffer<[Vert2Uv]>, vertex_buffer: Vert2Buf,
index_buffer: Subbuffer<[u16]>, index_buffer: IndexBuf,
descriptor_sets: Vec<Arc<DescriptorSet>>, descriptor_sets: Vec<Arc<DescriptorSet>>,
) -> anyhow::Result<WlxPass<WlxPipelineDynamic>> { ) -> anyhow::Result<DynamicPass> {
WlxPass::<WlxPipelineDynamic>::new( DynamicPass::new(
self.clone(), self.clone(),
dimensions, dimensions,
vertex_buffer, vertex_buffer,
@@ -1200,11 +1206,11 @@ impl WlxPipeline<WlxPipelineLegacy> {
pub fn create_pass( pub fn create_pass(
self: &Arc<Self>, self: &Arc<Self>,
dimensions: [f32; 2], dimensions: [f32; 2],
vertex_buffer: Subbuffer<[Vert2Uv]>, vertex_buffer: Vert2Buf,
index_buffer: Subbuffer<[u16]>, index_buffer: IndexBuf,
descriptor_sets: Vec<Arc<DescriptorSet>>, descriptor_sets: Vec<Arc<DescriptorSet>>,
) -> anyhow::Result<WlxPass<WlxPipelineLegacy>> { ) -> anyhow::Result<LegacyPass> {
WlxPass::<WlxPipelineLegacy>::new( LegacyPass::new(
self.clone(), self.clone(),
dimensions, dimensions,
vertex_buffer, vertex_buffer,
@@ -1278,18 +1284,18 @@ impl<D> WlxPipeline<D> {
#[allow(dead_code)] #[allow(dead_code)]
pub struct WlxPass<D> { pub struct WlxPass<D> {
pipeline: Arc<WlxPipeline<D>>, pipeline: Arc<WlxPipeline<D>>,
vertex_buffer: Subbuffer<[Vert2Uv]>, vertex_buffer: Vert2Buf,
index_buffer: Subbuffer<[u16]>, index_buffer: IndexBuf,
descriptor_sets: Vec<Arc<DescriptorSet>>, descriptor_sets: Vec<Arc<DescriptorSet>>,
pub command_buffer: Arc<CommandBuffer>, pub command_buffer: Arc<CommandBuffer>,
} }
impl WlxPass<WlxPipelineLegacy> { impl WlxPass<WlxPipelineLegacy> {
fn new( fn new(
pipeline: Arc<WlxPipeline<WlxPipelineLegacy>>, pipeline: Arc<LegacyPipeline>,
dimensions: [f32; 2], dimensions: [f32; 2],
vertex_buffer: Subbuffer<[Vert2Uv]>, vertex_buffer: Vert2Buf,
index_buffer: Subbuffer<[u16]>, index_buffer: IndexBuf,
descriptor_sets: Vec<Arc<DescriptorSet>>, descriptor_sets: Vec<Arc<DescriptorSet>>,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
let viewport = Viewport { let viewport = Viewport {
@@ -1346,10 +1352,10 @@ impl WlxPass<WlxPipelineLegacy> {
impl WlxPass<WlxPipelineDynamic> { impl WlxPass<WlxPipelineDynamic> {
fn new( fn new(
pipeline: Arc<WlxPipeline<WlxPipelineDynamic>>, pipeline: Arc<DynamicPipeline>,
dimensions: [f32; 2], dimensions: [f32; 2],
vertex_buffer: Subbuffer<[Vert2Uv]>, vertex_buffer: Vert2Buf,
index_buffer: Subbuffer<[u16]>, index_buffer: IndexBuf,
descriptor_sets: Vec<Arc<DescriptorSet>>, descriptor_sets: Vec<Arc<DescriptorSet>>,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
let viewport = Viewport { let viewport = Viewport {