Merge pull request #134 from mahkoh/jorth/vulkan-blending
vulkan: create separate pipelines for opaque and alpha textures
This commit is contained in:
commit
39d1e49672
1 changed files with 21 additions and 10 deletions
|
|
@ -56,7 +56,8 @@ pub struct VulkanRenderer {
|
||||||
pub(super) formats: Rc<AHashMap<u32, GfxFormat>>,
|
pub(super) formats: Rc<AHashMap<u32, GfxFormat>>,
|
||||||
pub(super) device: Rc<VulkanDevice>,
|
pub(super) device: Rc<VulkanDevice>,
|
||||||
pub(super) fill_pipeline: Rc<VulkanPipeline>,
|
pub(super) fill_pipeline: Rc<VulkanPipeline>,
|
||||||
pub(super) tex_pipeline: Rc<VulkanPipeline>,
|
pub(super) tex_opaque_pipeline: Rc<VulkanPipeline>,
|
||||||
|
pub(super) tex_alpha_pipeline: Rc<VulkanPipeline>,
|
||||||
pub(super) command_pool: Rc<VulkanCommandPool>,
|
pub(super) command_pool: Rc<VulkanCommandPool>,
|
||||||
pub(super) command_buffers: Stack<Rc<VulkanCommandBuffer>>,
|
pub(super) command_buffers: Stack<Rc<VulkanCommandBuffer>>,
|
||||||
pub(super) wait_semaphores: Stack<Rc<VulkanSemaphore>>,
|
pub(super) wait_semaphores: Stack<Rc<VulkanSemaphore>>,
|
||||||
|
|
@ -104,13 +105,18 @@ impl VulkanDevice {
|
||||||
)?;
|
)?;
|
||||||
let sampler = self.create_sampler()?;
|
let sampler = self.create_sampler()?;
|
||||||
let tex_descriptor_set_layout = self.create_descriptor_set_layout(&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::<TexVertPushConstants, ()>(PipelineCreateInfo {
|
self.create_pipeline::<TexVertPushConstants, ()>(PipelineCreateInfo {
|
||||||
vert: self.create_shader(TEX_VERT)?,
|
vert: tex_vert_shader.clone(),
|
||||||
frag: self.create_shader(TEX_FRAG)?,
|
frag: tex_frag_shader.clone(),
|
||||||
alpha: true,
|
alpha,
|
||||||
frag_descriptor_set_layout: Some(tex_descriptor_set_layout.clone()),
|
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 command_pool = self.create_command_pool()?;
|
||||||
let formats: AHashMap<u32, _> = self
|
let formats: AHashMap<u32, _> = self
|
||||||
.formats
|
.formats
|
||||||
|
|
@ -141,7 +147,8 @@ impl VulkanDevice {
|
||||||
formats: Rc::new(formats),
|
formats: Rc::new(formats),
|
||||||
device: self.clone(),
|
device: self.clone(),
|
||||||
fill_pipeline,
|
fill_pipeline,
|
||||||
tex_pipeline,
|
tex_opaque_pipeline,
|
||||||
|
tex_alpha_pipeline,
|
||||||
command_pool,
|
command_pool,
|
||||||
command_buffers: Default::default(),
|
command_buffers: Default::default(),
|
||||||
wait_semaphores: Default::default(),
|
wait_semaphores: Default::default(),
|
||||||
|
|
@ -425,7 +432,11 @@ impl VulkanRenderer {
|
||||||
}
|
}
|
||||||
GfxApiOpt::CopyTexture(c) => {
|
GfxApiOpt::CopyTexture(c) => {
|
||||||
let tex = c.tex.as_vk(&self.device.device);
|
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 {
|
let vert = TexVertPushConstants {
|
||||||
pos: c.target.to_points(),
|
pos: c.target.to_points(),
|
||||||
tex_pos: c.source.to_points(),
|
tex_pos: c.source.to_points(),
|
||||||
|
|
@ -441,13 +452,13 @@ impl VulkanRenderer {
|
||||||
self.device.push_descriptor.cmd_push_descriptor_set(
|
self.device.push_descriptor.cmd_push_descriptor_set(
|
||||||
buf,
|
buf,
|
||||||
PipelineBindPoint::GRAPHICS,
|
PipelineBindPoint::GRAPHICS,
|
||||||
self.tex_pipeline.pipeline_layout,
|
pipeline.pipeline_layout,
|
||||||
0,
|
0,
|
||||||
slice::from_ref(&write_descriptor_set),
|
slice::from_ref(&write_descriptor_set),
|
||||||
);
|
);
|
||||||
dev.cmd_push_constants(
|
dev.cmd_push_constants(
|
||||||
buf,
|
buf,
|
||||||
self.tex_pipeline.pipeline_layout,
|
pipeline.pipeline_layout,
|
||||||
ShaderStageFlags::VERTEX,
|
ShaderStageFlags::VERTEX,
|
||||||
0,
|
0,
|
||||||
uapi::as_bytes(&vert),
|
uapi::as_bytes(&vert),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue