use super::ShaderDefVal;
use crate::mesh::VertexBufferLayout;
use crate::renderer::WgpuWrapper;
use crate::{
define_atomic_id,
render_resource::{BindGroupLayout, Shader},
};
use alloc::borrow::Cow;
use alloc::sync::Arc;
use bevy_asset::Handle;
use core::ops::Deref;
use wgpu::{
ColorTargetState, DepthStencilState, MultisampleState, PrimitiveState, PushConstantRange,
};
define_atomic_id!(RenderPipelineId);
#[derive(Clone, Debug)]
pub struct RenderPipeline {
id: RenderPipelineId,
value: Arc<WgpuWrapper<wgpu::RenderPipeline>>,
}
impl RenderPipeline {
#[inline]
pub fn id(&self) -> RenderPipelineId {
self.id
}
}
impl From<wgpu::RenderPipeline> for RenderPipeline {
fn from(value: wgpu::RenderPipeline) -> Self {
RenderPipeline {
id: RenderPipelineId::new(),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
impl Deref for RenderPipeline {
type Target = wgpu::RenderPipeline;
#[inline]
fn deref(&self) -> &Self::Target {
&self.value
}
}
define_atomic_id!(ComputePipelineId);
#[derive(Clone, Debug)]
pub struct ComputePipeline {
id: ComputePipelineId,
value: Arc<WgpuWrapper<wgpu::ComputePipeline>>,
}
impl ComputePipeline {
#[inline]
pub fn id(&self) -> ComputePipelineId {
self.id
}
}
impl From<wgpu::ComputePipeline> for ComputePipeline {
fn from(value: wgpu::ComputePipeline) -> Self {
ComputePipeline {
id: ComputePipelineId::new(),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
impl Deref for ComputePipeline {
type Target = wgpu::ComputePipeline;
#[inline]
fn deref(&self) -> &Self::Target {
&self.value
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RenderPipelineDescriptor {
pub label: Option<Cow<'static, str>>,
pub layout: Vec<BindGroupLayout>,
pub push_constant_ranges: Vec<PushConstantRange>,
pub vertex: VertexState,
pub primitive: PrimitiveState,
pub depth_stencil: Option<DepthStencilState>,
pub multisample: MultisampleState,
pub fragment: Option<FragmentState>,
pub zero_initialize_workgroup_memory: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct VertexState {
pub shader: Handle<Shader>,
pub shader_defs: Vec<ShaderDefVal>,
pub entry_point: Cow<'static, str>,
pub buffers: Vec<VertexBufferLayout>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FragmentState {
pub shader: Handle<Shader>,
pub shader_defs: Vec<ShaderDefVal>,
pub entry_point: Cow<'static, str>,
pub targets: Vec<Option<ColorTargetState>>,
}
#[derive(Clone, Debug)]
pub struct ComputePipelineDescriptor {
pub label: Option<Cow<'static, str>>,
pub layout: Vec<BindGroupLayout>,
pub push_constant_ranges: Vec<PushConstantRange>,
pub shader: Handle<Shader>,
pub shader_defs: Vec<ShaderDefVal>,
pub entry_point: Cow<'static, str>,
pub zero_initialize_workgroup_memory: bool,
}