pub use self::{builder::GraphicsPipelineBuilder, creation_error::GraphicsPipelineCreationError};
use self::{
color_blend::ColorBlendState, depth_stencil::DepthStencilState,
discard_rectangle::DiscardRectangleState, input_assembly::InputAssemblyState,
multisample::MultisampleState, rasterization::RasterizationState,
render_pass::PipelineRenderPassType, tessellation::TessellationState,
vertex_input::VertexInputState, viewport::ViewportState,
};
use super::{DynamicState, Pipeline, PipelineBindPoint, PipelineLayout};
use crate::{
device::{Device, DeviceOwned},
shader::{DescriptorRequirements, ShaderStage},
VulkanObject,
};
use ahash::HashMap;
use std::{
fmt::{Debug, Error as FmtError, Formatter},
num::NonZeroU64,
ptr,
sync::Arc,
};
mod builder;
pub mod color_blend;
mod creation_error;
pub mod depth_stencil;
pub mod discard_rectangle;
pub mod input_assembly;
pub mod multisample;
pub mod rasterization;
pub mod render_pass;
pub mod tessellation;
pub mod vertex_input;
pub mod viewport;
pub struct GraphicsPipeline {
handle: ash::vk::Pipeline,
device: Arc<Device>,
id: NonZeroU64,
layout: Arc<PipelineLayout>,
render_pass: PipelineRenderPassType,
shaders: HashMap<ShaderStage, ()>,
descriptor_requirements: HashMap<(u32, u32), DescriptorRequirements>,
num_used_descriptor_sets: u32,
vertex_input_state: VertexInputState,
input_assembly_state: InputAssemblyState,
tessellation_state: Option<TessellationState>,
viewport_state: Option<ViewportState>,
discard_rectangle_state: Option<DiscardRectangleState>,
rasterization_state: RasterizationState,
multisample_state: Option<MultisampleState>,
depth_stencil_state: Option<DepthStencilState>,
color_blend_state: Option<ColorBlendState>,
dynamic_state: HashMap<DynamicState, bool>,
}
impl GraphicsPipeline {
#[inline]
pub fn start() -> GraphicsPipelineBuilder<
'static,
'static,
'static,
'static,
'static,
VertexInputState,
(),
(),
(),
(),
(),
> {
GraphicsPipelineBuilder::new()
}
#[inline]
pub fn device(&self) -> &Arc<Device> {
&self.device
}
#[inline]
pub fn render_pass(&self) -> &PipelineRenderPassType {
&self.render_pass
}
#[inline]
pub(crate) fn shader(&self, stage: ShaderStage) -> Option<()> {
self.shaders.get(&stage).copied()
}
#[inline]
pub fn descriptor_requirements(
&self,
) -> impl ExactSizeIterator<Item = ((u32, u32), &DescriptorRequirements)> {
self.descriptor_requirements
.iter()
.map(|(loc, reqs)| (*loc, reqs))
}
#[inline]
pub fn vertex_input_state(&self) -> &VertexInputState {
&self.vertex_input_state
}
#[inline]
pub fn input_assembly_state(&self) -> &InputAssemblyState {
&self.input_assembly_state
}
#[inline]
pub fn tessellation_state(&self) -> Option<&TessellationState> {
self.tessellation_state.as_ref()
}
#[inline]
pub fn viewport_state(&self) -> Option<&ViewportState> {
self.viewport_state.as_ref()
}
#[inline]
pub fn discard_rectangle_state(&self) -> Option<&DiscardRectangleState> {
self.discard_rectangle_state.as_ref()
}
#[inline]
pub fn rasterization_state(&self) -> &RasterizationState {
&self.rasterization_state
}
#[inline]
pub fn multisample_state(&self) -> Option<&MultisampleState> {
self.multisample_state.as_ref()
}
#[inline]
pub fn depth_stencil_state(&self) -> Option<&DepthStencilState> {
self.depth_stencil_state.as_ref()
}
#[inline]
pub fn color_blend_state(&self) -> Option<&ColorBlendState> {
self.color_blend_state.as_ref()
}
#[inline]
pub fn dynamic_state(&self, state: DynamicState) -> Option<bool> {
self.dynamic_state.get(&state).copied()
}
#[inline]
pub fn dynamic_states(&self) -> impl ExactSizeIterator<Item = (DynamicState, bool)> + '_ {
self.dynamic_state.iter().map(|(k, v)| (*k, *v))
}
}
impl Pipeline for GraphicsPipeline {
#[inline]
fn bind_point(&self) -> PipelineBindPoint {
PipelineBindPoint::Graphics
}
#[inline]
fn layout(&self) -> &Arc<PipelineLayout> {
&self.layout
}
#[inline]
fn num_used_descriptor_sets(&self) -> u32 {
self.num_used_descriptor_sets
}
}
unsafe impl DeviceOwned for GraphicsPipeline {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
impl Debug for GraphicsPipeline {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
write!(f, "<Vulkan graphics pipeline {:?}>", self.handle)
}
}
unsafe impl VulkanObject for GraphicsPipeline {
type Handle = ash::vk::Pipeline;
#[inline]
fn handle(&self) -> Self::Handle {
self.handle
}
}
impl Drop for GraphicsPipeline {
#[inline]
fn drop(&mut self) {
unsafe {
let fns = self.device.fns();
(fns.v1_0.destroy_pipeline)(self.device.handle(), self.handle, ptr::null());
}
}
}
crate::impl_id_counter!(GraphicsPipeline);