From 0e5e16c2f02370cca51e17161c2154fa45bc0059 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Mon, 18 Mar 2024 10:34:56 +0100 Subject: [PATCH] vulkan: create separate pipelines for opaque and alpha textures --- src/gfx_apis/vulkan/renderer.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/gfx_apis/vulkan/renderer.rs b/src/gfx_apis/vulkan/renderer.rs index 8c2f6c2c..9948dbf7 100644 --- a/src/gfx_apis/vulkan/renderer.rs +++ b/src/gfx_apis/vulkan/renderer.rs @@ -56,7 +56,8 @@ pub struct VulkanRenderer { pub(super) formats: Rc>, pub(super) device: Rc, pub(super) fill_pipeline: Rc, - pub(super) tex_pipeline: Rc, + pub(super) tex_opaque_pipeline: Rc, + pub(super) tex_alpha_pipeline: Rc, pub(super) command_pool: Rc, pub(super) command_buffers: Stack>, pub(super) wait_semaphores: Stack>, @@ -104,13 +105,18 @@ impl VulkanDevice { )?; let sampler = self.create_sampler()?; let tex_descriptor_set_layout = self.create_descriptor_set_layout(&sampler)?; - let tex_pipeline = + let tex_vert_shader = self.create_shader(TEX_VERT)?; + let tex_frag_shader = self.create_shader(TEX_FRAG)?; + let create_tex_pipeline = |alpha| { self.create_pipeline::(PipelineCreateInfo { - vert: self.create_shader(TEX_VERT)?, - frag: self.create_shader(TEX_FRAG)?, - alpha: true, + vert: tex_vert_shader.clone(), + frag: tex_frag_shader.clone(), + alpha, frag_descriptor_set_layout: Some(tex_descriptor_set_layout.clone()), - })?; + }) + }; + let tex_opaque_pipeline = create_tex_pipeline(false)?; + let tex_alpha_pipeline = create_tex_pipeline(true)?; let command_pool = self.create_command_pool()?; let formats: AHashMap = self .formats @@ -141,7 +147,8 @@ impl VulkanDevice { formats: Rc::new(formats), device: self.clone(), fill_pipeline, - tex_pipeline, + tex_opaque_pipeline, + tex_alpha_pipeline, command_pool, command_buffers: Default::default(), wait_semaphores: Default::default(), @@ -425,7 +432,11 @@ impl VulkanRenderer { } GfxApiOpt::CopyTexture(c) => { let tex = c.tex.as_vk(&self.device.device); - bind(&self.tex_pipeline); + let pipeline = match tex.format.has_alpha { + true => &self.tex_alpha_pipeline, + false => &self.tex_opaque_pipeline, + }; + bind(pipeline); let vert = TexVertPushConstants { pos: c.target.to_points(), tex_pos: c.source.to_points(), @@ -441,13 +452,13 @@ impl VulkanRenderer { self.device.push_descriptor.cmd_push_descriptor_set( buf, PipelineBindPoint::GRAPHICS, - self.tex_pipeline.pipeline_layout, + pipeline.pipeline_layout, 0, slice::from_ref(&write_descriptor_set), ); dev.cmd_push_constants( buf, - self.tex_pipeline.pipeline_layout, + pipeline.pipeline_layout, ShaderStageFlags::VERTEX, 0, uapi::as_bytes(&vert),