mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 23:41:01 +01:00
This is a major change in how the bundles are implemented. Instead of transparently injecting them into the pass command stream, we are now treating bundles as first-class API objects and API tracing them accordingly. The bundle contains a normalized command stream that is very easy to inject into a native command buffer multiple times.
139 lines
3.8 KiB
Rust
139 lines
3.8 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use crate::{
|
|
device::RenderPassContext,
|
|
id::{DeviceId, PipelineLayoutId, ShaderModuleId},
|
|
validation::StageError,
|
|
LifeGuard, RawString, RefCount, Stored, U32Array,
|
|
};
|
|
use std::borrow::Borrow;
|
|
use wgt::{
|
|
BufferAddress, ColorStateDescriptor, DepthStencilStateDescriptor, IndexFormat, InputStepMode,
|
|
PrimitiveTopology, RasterizationStateDescriptor, VertexAttributeDescriptor,
|
|
};
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug)]
|
|
pub struct VertexBufferLayoutDescriptor {
|
|
pub array_stride: BufferAddress,
|
|
pub step_mode: InputStepMode,
|
|
pub attributes: *const VertexAttributeDescriptor,
|
|
pub attributes_length: usize,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug)]
|
|
pub struct VertexStateDescriptor {
|
|
pub index_format: IndexFormat,
|
|
pub vertex_buffers: *const VertexBufferLayoutDescriptor,
|
|
pub vertex_buffers_length: usize,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug)]
|
|
pub struct ShaderModuleDescriptor {
|
|
pub code: U32Array,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct ShaderModule<B: hal::Backend> {
|
|
pub(crate) raw: B::ShaderModule,
|
|
pub(crate) device_id: Stored<DeviceId>,
|
|
pub(crate) module: Option<naga::Module>,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug)]
|
|
pub struct ProgrammableStageDescriptor {
|
|
pub module: ShaderModuleId,
|
|
pub entry_point: RawString,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug)]
|
|
pub struct ComputePipelineDescriptor {
|
|
pub layout: PipelineLayoutId,
|
|
pub compute_stage: ProgrammableStageDescriptor,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum ComputePipelineError {
|
|
Stage(StageError),
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct ComputePipeline<B: hal::Backend> {
|
|
pub(crate) raw: B::ComputePipeline,
|
|
pub(crate) layout_id: Stored<PipelineLayoutId>,
|
|
pub(crate) device_id: Stored<DeviceId>,
|
|
pub(crate) life_guard: LifeGuard,
|
|
}
|
|
|
|
impl<B: hal::Backend> Borrow<RefCount> for ComputePipeline<B> {
|
|
fn borrow(&self) -> &RefCount {
|
|
self.life_guard.ref_count.as_ref().unwrap()
|
|
}
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug)]
|
|
pub struct RenderPipelineDescriptor {
|
|
pub layout: PipelineLayoutId,
|
|
pub vertex_stage: ProgrammableStageDescriptor,
|
|
pub fragment_stage: *const ProgrammableStageDescriptor,
|
|
pub primitive_topology: PrimitiveTopology,
|
|
pub rasterization_state: *const RasterizationStateDescriptor,
|
|
pub color_states: *const ColorStateDescriptor,
|
|
pub color_states_length: usize,
|
|
pub depth_stencil_state: *const DepthStencilStateDescriptor,
|
|
pub vertex_state: VertexStateDescriptor,
|
|
pub sample_count: u32,
|
|
pub sample_mask: u32,
|
|
pub alpha_to_coverage_enabled: bool,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum RenderPipelineError {
|
|
InvalidVertexAttributeOffset {
|
|
location: wgt::ShaderLocation,
|
|
offset: BufferAddress,
|
|
},
|
|
Stage {
|
|
flag: wgt::ShaderStage,
|
|
error: StageError,
|
|
},
|
|
IncompatibleOutputFormat {
|
|
index: u8,
|
|
},
|
|
InvalidSampleCount(u32),
|
|
}
|
|
|
|
bitflags::bitflags! {
|
|
#[repr(transparent)]
|
|
pub struct PipelineFlags: u32 {
|
|
const BLEND_COLOR = 1;
|
|
const STENCIL_REFERENCE = 2;
|
|
const DEPTH_STENCIL_READ_ONLY = 4;
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct RenderPipeline<B: hal::Backend> {
|
|
pub(crate) raw: B::GraphicsPipeline,
|
|
pub(crate) layout_id: Stored<PipelineLayoutId>,
|
|
pub(crate) device_id: Stored<DeviceId>,
|
|
pub(crate) pass_context: RenderPassContext,
|
|
pub(crate) flags: PipelineFlags,
|
|
pub(crate) index_format: IndexFormat,
|
|
pub(crate) vertex_strides: Vec<(BufferAddress, InputStepMode)>,
|
|
pub(crate) life_guard: LifeGuard,
|
|
}
|
|
|
|
impl<B: hal::Backend> Borrow<RefCount> for RenderPipeline<B> {
|
|
fn borrow(&self) -> &RefCount {
|
|
self.life_guard.ref_count.as_ref().unwrap()
|
|
}
|
|
}
|