mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Compute Pipeline Specialization (#3979)
# Objective - Fixes #3970 - To support Bevy's shader abstraction(shader defs, shader imports and hot shader reloading) for compute shaders, I have followed carts advice and change the `PipelinenCache` to accommodate both compute and render pipelines. ## Solution - renamed `RenderPipelineCache` to `PipelineCache` - Cached Pipelines are now represented by an enum (render, compute) - split the `SpecializedPipelines` into `SpecializedRenderPipelines` and `SpecializedComputePipelines` - updated the game of life example ## Open Questions - should `SpecializedRenderPipelines` and `SpecializedComputePipelines` be merged and how would we do that? - should the `get_render_pipeline` and `get_compute_pipeline` methods be merged? - is pipeline specialization for different entry points a good pattern Co-authored-by: Kurt Kühnert <51823519+Ku95@users.noreply.github.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
parent
0a4136d266
commit
9e450f2827
21 changed files with 516 additions and 318 deletions
|
@ -27,7 +27,7 @@ use bevy_render::{
|
|||
color::Color,
|
||||
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType},
|
||||
render_phase::{
|
||||
batch_phase_system, sort_phase_system, BatchedPhaseItem, CachedPipelinePhaseItem,
|
||||
batch_phase_system, sort_phase_system, BatchedPhaseItem, CachedRenderPipelinePhaseItem,
|
||||
DrawFunctionId, DrawFunctions, EntityPhaseItem, PhaseItem, RenderPhase,
|
||||
},
|
||||
render_resource::*,
|
||||
|
@ -198,7 +198,7 @@ impl Plugin for CorePipelinePlugin {
|
|||
pub struct Transparent2d {
|
||||
pub sort_key: FloatOrd,
|
||||
pub entity: Entity,
|
||||
pub pipeline: CachedPipelineId,
|
||||
pub pipeline: CachedRenderPipelineId,
|
||||
pub draw_function: DrawFunctionId,
|
||||
/// Range in the vertex buffer of this item
|
||||
pub batch_range: Option<Range<u32>>,
|
||||
|
@ -225,9 +225,9 @@ impl EntityPhaseItem for Transparent2d {
|
|||
}
|
||||
}
|
||||
|
||||
impl CachedPipelinePhaseItem for Transparent2d {
|
||||
impl CachedRenderPipelinePhaseItem for Transparent2d {
|
||||
#[inline]
|
||||
fn cached_pipeline(&self) -> CachedPipelineId {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId {
|
||||
self.pipeline
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ impl BatchedPhaseItem for Transparent2d {
|
|||
|
||||
pub struct Opaque3d {
|
||||
pub distance: f32,
|
||||
pub pipeline: CachedPipelineId,
|
||||
pub pipeline: CachedRenderPipelineId,
|
||||
pub entity: Entity,
|
||||
pub draw_function: DrawFunctionId,
|
||||
}
|
||||
|
@ -270,16 +270,16 @@ impl EntityPhaseItem for Opaque3d {
|
|||
}
|
||||
}
|
||||
|
||||
impl CachedPipelinePhaseItem for Opaque3d {
|
||||
impl CachedRenderPipelinePhaseItem for Opaque3d {
|
||||
#[inline]
|
||||
fn cached_pipeline(&self) -> CachedPipelineId {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId {
|
||||
self.pipeline
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AlphaMask3d {
|
||||
pub distance: f32,
|
||||
pub pipeline: CachedPipelineId,
|
||||
pub pipeline: CachedRenderPipelineId,
|
||||
pub entity: Entity,
|
||||
pub draw_function: DrawFunctionId,
|
||||
}
|
||||
|
@ -305,16 +305,16 @@ impl EntityPhaseItem for AlphaMask3d {
|
|||
}
|
||||
}
|
||||
|
||||
impl CachedPipelinePhaseItem for AlphaMask3d {
|
||||
impl CachedRenderPipelinePhaseItem for AlphaMask3d {
|
||||
#[inline]
|
||||
fn cached_pipeline(&self) -> CachedPipelineId {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId {
|
||||
self.pipeline
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Transparent3d {
|
||||
pub distance: f32,
|
||||
pub pipeline: CachedPipelineId,
|
||||
pub pipeline: CachedRenderPipelineId,
|
||||
pub entity: Entity,
|
||||
pub draw_function: DrawFunctionId,
|
||||
}
|
||||
|
@ -340,9 +340,9 @@ impl EntityPhaseItem for Transparent3d {
|
|||
}
|
||||
}
|
||||
|
||||
impl CachedPipelinePhaseItem for Transparent3d {
|
||||
impl CachedRenderPipelinePhaseItem for Transparent3d {
|
||||
#[inline]
|
||||
fn cached_pipeline(&self) -> CachedPipelineId {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId {
|
||||
self.pipeline
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use bevy_render::{
|
|||
SetItemPipeline, TrackedRenderPass,
|
||||
},
|
||||
render_resource::{
|
||||
BindGroup, BindGroupLayout, RenderPipelineCache, RenderPipelineDescriptor, Shader,
|
||||
BindGroup, BindGroupLayout, PipelineCache, RenderPipelineDescriptor, Shader,
|
||||
SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines,
|
||||
},
|
||||
renderer::RenderDevice,
|
||||
|
@ -307,7 +307,7 @@ pub fn queue_material_meshes<M: SpecializedMaterial>(
|
|||
transparent_draw_functions: Res<DrawFunctions<Transparent3d>>,
|
||||
material_pipeline: Res<MaterialPipeline<M>>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<MaterialPipeline<M>>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
msaa: Res<Msaa>,
|
||||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
render_materials: Res<RenderAssets<M>>,
|
||||
|
|
|
@ -18,7 +18,7 @@ use bevy_render::{
|
|||
render_asset::RenderAssets,
|
||||
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
|
||||
render_phase::{
|
||||
CachedPipelinePhaseItem, DrawFunctionId, DrawFunctions, EntityPhaseItem,
|
||||
CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, EntityPhaseItem,
|
||||
EntityRenderCommand, PhaseItem, RenderCommandResult, RenderPhase, SetItemPipeline,
|
||||
TrackedRenderPass,
|
||||
},
|
||||
|
@ -1055,7 +1055,7 @@ pub fn queue_shadows(
|
|||
casting_meshes: Query<&Handle<Mesh>, Without<NotShadowCaster>>,
|
||||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<ShadowPipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
view_lights: Query<&ViewLightEntities>,
|
||||
mut view_light_shadow_phases: Query<(&LightEntity, &mut RenderPhase<Shadow>)>,
|
||||
point_light_entities: Query<&CubemapVisibleEntities, With<ExtractedPointLight>>,
|
||||
|
@ -1119,7 +1119,7 @@ pub fn queue_shadows(
|
|||
pub struct Shadow {
|
||||
pub distance: f32,
|
||||
pub entity: Entity,
|
||||
pub pipeline: CachedPipelineId,
|
||||
pub pipeline: CachedRenderPipelineId,
|
||||
pub draw_function: DrawFunctionId,
|
||||
}
|
||||
|
||||
|
@ -1143,9 +1143,9 @@ impl EntityPhaseItem for Shadow {
|
|||
}
|
||||
}
|
||||
|
||||
impl CachedPipelinePhaseItem for Shadow {
|
||||
impl CachedRenderPipelinePhaseItem for Shadow {
|
||||
#[inline]
|
||||
fn cached_pipeline(&self) -> CachedPipelineId {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId {
|
||||
self.pipeline
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,14 @@ use bevy_asset::{load_internal_asset, Handle, HandleUntyped};
|
|||
use bevy_core_pipeline::Opaque3d;
|
||||
use bevy_ecs::{prelude::*, reflect::ReflectComponent};
|
||||
use bevy_reflect::{Reflect, TypeUuid};
|
||||
use bevy_render::mesh::MeshVertexBufferLayout;
|
||||
use bevy_render::render_resource::{
|
||||
PolygonMode, RenderPipelineDescriptor, SpecializedMeshPipeline, SpecializedMeshPipelineError,
|
||||
SpecializedMeshPipelines,
|
||||
};
|
||||
use bevy_render::{
|
||||
mesh::Mesh,
|
||||
mesh::{Mesh, MeshVertexBufferLayout},
|
||||
render_asset::RenderAssets,
|
||||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||
render_resource::{RenderPipelineCache, Shader},
|
||||
render_resource::{
|
||||
PipelineCache, PolygonMode, RenderPipelineDescriptor, Shader, SpecializedMeshPipeline,
|
||||
SpecializedMeshPipelineError, SpecializedMeshPipelines,
|
||||
},
|
||||
view::{ExtractedView, Msaa},
|
||||
RenderApp, RenderStage,
|
||||
};
|
||||
|
@ -109,8 +107,8 @@ fn queue_wireframes(
|
|||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
wireframe_config: Res<WireframeConfig>,
|
||||
wireframe_pipeline: Res<WireframePipeline>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut specialized_pipelines: ResMut<SpecializedMeshPipelines<WireframePipeline>>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<WireframePipeline>>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
msaa: Res<Msaa>,
|
||||
mut material_meshes: QuerySet<(
|
||||
QueryState<(Entity, &Handle<Mesh>, &MeshUniform)>,
|
||||
|
@ -132,7 +130,7 @@ fn queue_wireframes(
|
|||
if let Some(mesh) = render_meshes.get(mesh_handle) {
|
||||
let key = msaa_key
|
||||
| MeshPipelineKey::from_primitive_topology(mesh.primitive_topology);
|
||||
let pipeline_id = specialized_pipelines.specialize(
|
||||
let pipeline_id = pipelines.specialize(
|
||||
&mut pipeline_cache,
|
||||
&wireframe_pipeline,
|
||||
key,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
extern crate core;
|
||||
|
||||
pub mod camera;
|
||||
pub mod color;
|
||||
pub mod mesh;
|
||||
|
@ -36,7 +38,7 @@ use crate::{
|
|||
mesh::MeshPlugin,
|
||||
primitives::{CubemapFrusta, Frustum},
|
||||
render_graph::RenderGraph,
|
||||
render_resource::{RenderPipelineCache, Shader, ShaderLoader},
|
||||
render_resource::{PipelineCache, Shader, ShaderLoader},
|
||||
renderer::render_system,
|
||||
texture::ImagePlugin,
|
||||
view::{ViewPlugin, WindowRenderPlugin},
|
||||
|
@ -146,12 +148,13 @@ impl Plugin for RenderPlugin {
|
|||
.init_resource::<ScratchRenderWorld>()
|
||||
.register_type::<Frustum>()
|
||||
.register_type::<CubemapFrusta>();
|
||||
let render_pipeline_cache = RenderPipelineCache::new(device.clone());
|
||||
|
||||
let pipeline_cache = PipelineCache::new(device.clone());
|
||||
let asset_server = app.world.resource::<AssetServer>().clone();
|
||||
|
||||
let mut render_app = App::empty();
|
||||
let mut extract_stage =
|
||||
SystemStage::parallel().with_system(RenderPipelineCache::extract_shaders);
|
||||
SystemStage::parallel().with_system(PipelineCache::extract_shaders);
|
||||
// don't apply buffers when the stage finishes running
|
||||
// extract stage runs on the app world, but the buffers are applied to the render world
|
||||
extract_stage.set_apply_buffers(false);
|
||||
|
@ -163,7 +166,7 @@ impl Plugin for RenderPlugin {
|
|||
.add_stage(
|
||||
RenderStage::Render,
|
||||
SystemStage::parallel()
|
||||
.with_system(RenderPipelineCache::process_pipeline_queue_system)
|
||||
.with_system(PipelineCache::process_pipeline_queue_system)
|
||||
.with_system(render_system.exclusive_system().at_end()),
|
||||
)
|
||||
.add_stage(RenderStage::Cleanup, SystemStage::parallel())
|
||||
|
@ -171,7 +174,7 @@ impl Plugin for RenderPlugin {
|
|||
.insert_resource(device)
|
||||
.insert_resource(queue)
|
||||
.insert_resource(adapter_info)
|
||||
.insert_resource(render_pipeline_cache)
|
||||
.insert_resource(pipeline_cache)
|
||||
.insert_resource(asset_server)
|
||||
.init_resource::<RenderGraph>();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
render_phase::TrackedRenderPass,
|
||||
render_resource::{CachedPipelineId, RenderPipelineCache},
|
||||
render_resource::{CachedRenderPipelineId, PipelineCache},
|
||||
};
|
||||
use bevy_app::App;
|
||||
use bevy_ecs::{
|
||||
|
@ -162,8 +162,8 @@ pub trait EntityPhaseItem: PhaseItem {
|
|||
fn entity(&self) -> Entity;
|
||||
}
|
||||
|
||||
pub trait CachedPipelinePhaseItem: PhaseItem {
|
||||
fn cached_pipeline(&self) -> CachedPipelineId;
|
||||
pub trait CachedRenderPipelinePhaseItem: PhaseItem {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId;
|
||||
}
|
||||
|
||||
/// A [`PhaseItem`] that can be batched dynamically.
|
||||
|
@ -224,8 +224,8 @@ impl<P: EntityPhaseItem, E: EntityRenderCommand> RenderCommand<P> for E {
|
|||
}
|
||||
|
||||
pub struct SetItemPipeline;
|
||||
impl<P: CachedPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
|
||||
type Param = SRes<RenderPipelineCache>;
|
||||
impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
|
||||
type Param = SRes<PipelineCache>;
|
||||
#[inline]
|
||||
fn render<'w>(
|
||||
_view: Entity,
|
||||
|
@ -233,7 +233,10 @@ impl<P: CachedPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
|
|||
pipeline_cache: SystemParamItem<'w, '_, Self::Param>,
|
||||
pass: &mut TrackedRenderPass<'w>,
|
||||
) -> RenderCommandResult {
|
||||
if let Some(pipeline) = pipeline_cache.into_inner().get(item.cached_pipeline()) {
|
||||
if let Some(pipeline) = pipeline_cache
|
||||
.into_inner()
|
||||
.get_render_pipeline(item.cached_pipeline())
|
||||
{
|
||||
pass.set_render_pipeline(pipeline);
|
||||
RenderCommandResult::Success
|
||||
} else {
|
||||
|
|
|
@ -28,13 +28,13 @@ pub use wgpu::{
|
|||
BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType,
|
||||
BlendComponent, BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBinding,
|
||||
BufferBindingType, BufferDescriptor, BufferSize, BufferUsages, ColorTargetState, ColorWrites,
|
||||
CommandEncoder, CommandEncoderDescriptor, CompareFunction, ComputePassDescriptor,
|
||||
ComputePipelineDescriptor, DepthBiasState, DepthStencilState, Extent3d, Face,
|
||||
Features as WgpuFeatures, FilterMode, FragmentState as RawFragmentState, FrontFace,
|
||||
ImageCopyBuffer, ImageCopyBufferBase, ImageCopyTexture, ImageCopyTextureBase, ImageDataLayout,
|
||||
ImageSubresourceRange, IndexFormat, Limits as WgpuLimits, LoadOp, MapMode, MultisampleState,
|
||||
Operations, Origin3d, PipelineLayout, PipelineLayoutDescriptor, PolygonMode, PrimitiveState,
|
||||
PrimitiveTopology, RenderPassColorAttachment, RenderPassDepthStencilAttachment,
|
||||
CommandEncoder, CommandEncoderDescriptor, CompareFunction, ComputePass, ComputePassDescriptor,
|
||||
ComputePipelineDescriptor as RawComputePipelineDescriptor, DepthBiasState, DepthStencilState,
|
||||
Extent3d, Face, Features as WgpuFeatures, FilterMode, FragmentState as RawFragmentState,
|
||||
FrontFace, ImageCopyBuffer, ImageCopyBufferBase, ImageCopyTexture, ImageCopyTextureBase,
|
||||
ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits as WgpuLimits, LoadOp, MapMode,
|
||||
MultisampleState, Operations, Origin3d, PipelineLayout, PipelineLayoutDescriptor, PolygonMode,
|
||||
PrimitiveState, PrimitiveTopology, RenderPassColorAttachment, RenderPassDepthStencilAttachment,
|
||||
RenderPassDescriptor, RenderPipelineDescriptor as RawRenderPipelineDescriptor,
|
||||
SamplerBindingType, SamplerDescriptor, ShaderModule, ShaderModuleDescriptor, ShaderSource,
|
||||
ShaderStages, StencilFaceState, StencilOperation, StencilState, StorageTextureAccess,
|
||||
|
|
|
@ -168,3 +168,16 @@ pub struct FragmentState {
|
|||
/// The color state of the render targets.
|
||||
pub targets: Vec<ColorTargetState>,
|
||||
}
|
||||
|
||||
/// Describes a compute pipeline.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ComputePipelineDescriptor {
|
||||
pub label: Option<Cow<'static, str>>,
|
||||
pub layout: Option<Vec<BindGroupLayout>>,
|
||||
/// The compiled shader module for this stage.
|
||||
pub shader: Handle<Shader>,
|
||||
pub shader_defs: Vec<String>,
|
||||
/// The name of the entry point in the compiled shader. There must be a
|
||||
/// function with this name in the shader.
|
||||
pub entry_point: Cow<'static, str>,
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use crate::{
|
||||
render_resource::{
|
||||
AsModuleDescriptorError, BindGroupLayout, BindGroupLayoutId, ProcessShaderError,
|
||||
RawFragmentState, RawRenderPipelineDescriptor, RawVertexState, RenderPipeline,
|
||||
RenderPipelineDescriptor, Shader, ShaderImport, ShaderProcessor, ShaderReflectError,
|
||||
AsModuleDescriptorError, BindGroupLayout, BindGroupLayoutId, ComputePipeline,
|
||||
ComputePipelineDescriptor, ProcessShaderError, ProcessedShader,
|
||||
RawComputePipelineDescriptor, RawFragmentState, RawRenderPipelineDescriptor,
|
||||
RawVertexState, RenderPipeline, RenderPipelineDescriptor, Shader, ShaderImport,
|
||||
ShaderProcessor, ShaderReflectError,
|
||||
},
|
||||
renderer::RenderDevice,
|
||||
RenderWorld,
|
||||
|
@ -10,12 +12,61 @@ use crate::{
|
|||
use bevy_asset::{AssetEvent, Assets, Handle};
|
||||
use bevy_ecs::event::EventReader;
|
||||
use bevy_ecs::system::{Res, ResMut};
|
||||
use bevy_utils::{tracing::error, Entry, HashMap, HashSet};
|
||||
use std::{hash::Hash, ops::Deref, sync::Arc};
|
||||
use bevy_utils::{default, tracing::error, Entry, HashMap, HashSet};
|
||||
use std::{hash::Hash, mem, ops::Deref, sync::Arc};
|
||||
use thiserror::Error;
|
||||
use wgpu::{PipelineLayoutDescriptor, ShaderModule, VertexBufferLayout as RawVertexBufferLayout};
|
||||
|
||||
use super::ProcessedShader;
|
||||
enum PipelineDescriptor {
|
||||
RenderPipelineDescriptor(Box<RenderPipelineDescriptor>),
|
||||
ComputePipelineDescriptor(Box<ComputePipelineDescriptor>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Pipeline {
|
||||
RenderPipeline(RenderPipeline),
|
||||
ComputePipeline(ComputePipeline),
|
||||
}
|
||||
|
||||
type CachedPipelineId = usize;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct CachedRenderPipelineId(CachedPipelineId);
|
||||
|
||||
impl CachedRenderPipelineId {
|
||||
pub const INVALID: Self = CachedRenderPipelineId(usize::MAX);
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct CachedComputePipelineId(CachedPipelineId);
|
||||
|
||||
impl CachedComputePipelineId {
|
||||
pub const INVALID: Self = CachedComputePipelineId(usize::MAX);
|
||||
}
|
||||
|
||||
struct CachedPipeline {
|
||||
descriptor: PipelineDescriptor,
|
||||
state: CachedPipelineState,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CachedPipelineState {
|
||||
Queued,
|
||||
Ok(Pipeline),
|
||||
Err(PipelineCacheError),
|
||||
}
|
||||
|
||||
impl CachedPipelineState {
|
||||
pub fn unwrap(&self) -> &Pipeline {
|
||||
match self {
|
||||
CachedPipelineState::Ok(pipeline) => pipeline,
|
||||
CachedPipelineState::Queued => {
|
||||
panic!("Pipeline has not been compiled yet. It is still in the 'Queued' state.")
|
||||
}
|
||||
CachedPipelineState::Err(err) => panic!("{}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ShaderData {
|
||||
|
@ -25,13 +76,6 @@ pub struct ShaderData {
|
|||
dependents: HashSet<Handle<Shader>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct CachedPipelineId(usize);
|
||||
|
||||
impl CachedPipelineId {
|
||||
pub const INVALID: Self = CachedPipelineId(usize::MAX);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ShaderCache {
|
||||
data: HashMap<Handle<Shader>, ShaderData>,
|
||||
|
@ -48,11 +92,11 @@ impl ShaderCache {
|
|||
pipeline: CachedPipelineId,
|
||||
handle: &Handle<Shader>,
|
||||
shader_defs: &[String],
|
||||
) -> Result<Arc<ShaderModule>, RenderPipelineError> {
|
||||
) -> Result<Arc<ShaderModule>, PipelineCacheError> {
|
||||
let shader = self
|
||||
.shaders
|
||||
.get(handle)
|
||||
.ok_or_else(|| RenderPipelineError::ShaderNotLoaded(handle.clone_weak()))?;
|
||||
.ok_or_else(|| PipelineCacheError::ShaderNotLoaded(handle.clone_weak()))?;
|
||||
let data = self.data.entry(handle.clone_weak()).or_default();
|
||||
let n_asset_imports = shader
|
||||
.imports()
|
||||
|
@ -64,7 +108,7 @@ impl ShaderCache {
|
|||
.filter(|import| matches!(import, ShaderImport::AssetPath(_)))
|
||||
.count();
|
||||
if n_asset_imports != n_resolved_asset_imports {
|
||||
return Err(RenderPipelineError::ShaderImportNotYetAvailable);
|
||||
return Err(PipelineCacheError::ShaderImportNotYetAvailable);
|
||||
}
|
||||
|
||||
data.pipelines.insert(pipeline);
|
||||
|
@ -82,7 +126,7 @@ impl ShaderCache {
|
|||
let module_descriptor = match processed.get_module_descriptor() {
|
||||
Ok(module_descriptor) => module_descriptor,
|
||||
Err(err) => {
|
||||
return Err(RenderPipelineError::AsModuleDescriptorError(err, processed));
|
||||
return Err(PipelineCacheError::AsModuleDescriptorError(err, processed));
|
||||
}
|
||||
};
|
||||
entry.insert(Arc::new(
|
||||
|
@ -176,13 +220,13 @@ impl LayoutCache {
|
|||
.collect::<Vec<_>>();
|
||||
render_device.create_pipeline_layout(&PipelineLayoutDescriptor {
|
||||
bind_group_layouts: &bind_group_layouts,
|
||||
..Default::default()
|
||||
..default()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RenderPipelineCache {
|
||||
pub struct PipelineCache {
|
||||
layout_cache: LayoutCache,
|
||||
shader_cache: ShaderCache,
|
||||
device: RenderDevice,
|
||||
|
@ -190,88 +234,101 @@ pub struct RenderPipelineCache {
|
|||
waiting_pipelines: HashSet<CachedPipelineId>,
|
||||
}
|
||||
|
||||
struct CachedPipeline {
|
||||
descriptor: RenderPipelineDescriptor,
|
||||
state: CachedPipelineState,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CachedPipelineState {
|
||||
Queued,
|
||||
Ok(RenderPipeline),
|
||||
Err(RenderPipelineError),
|
||||
}
|
||||
|
||||
impl CachedPipelineState {
|
||||
pub fn unwrap(&self) -> &RenderPipeline {
|
||||
match self {
|
||||
CachedPipelineState::Ok(pipeline) => pipeline,
|
||||
CachedPipelineState::Queued => {
|
||||
panic!("Pipeline has not been compiled yet. It is still in the 'Queued' state.")
|
||||
}
|
||||
CachedPipelineState::Err(err) => panic!("{}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum RenderPipelineError {
|
||||
#[error(
|
||||
"Pipeline cound not be compiled because the following shader is not loaded yet: {0:?}"
|
||||
)]
|
||||
ShaderNotLoaded(Handle<Shader>),
|
||||
#[error(transparent)]
|
||||
ProcessShaderError(#[from] ProcessShaderError),
|
||||
#[error("{0}")]
|
||||
AsModuleDescriptorError(AsModuleDescriptorError, ProcessedShader),
|
||||
#[error("Shader import not yet available.")]
|
||||
ShaderImportNotYetAvailable,
|
||||
}
|
||||
|
||||
impl RenderPipelineCache {
|
||||
impl PipelineCache {
|
||||
pub fn new(device: RenderDevice) -> Self {
|
||||
Self {
|
||||
device,
|
||||
layout_cache: Default::default(),
|
||||
shader_cache: Default::default(),
|
||||
waiting_pipelines: Default::default(),
|
||||
pipelines: Default::default(),
|
||||
layout_cache: default(),
|
||||
shader_cache: default(),
|
||||
waiting_pipelines: default(),
|
||||
pipelines: default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_state(&self, id: CachedPipelineId) -> &CachedPipelineState {
|
||||
pub fn get_render_pipeline_state(&self, id: CachedRenderPipelineId) -> &CachedPipelineState {
|
||||
&self.pipelines[id.0].state
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_descriptor(&self, id: CachedPipelineId) -> &RenderPipelineDescriptor {
|
||||
&self.pipelines[id.0].descriptor
|
||||
pub fn get_compute_pipeline_state(&self, id: CachedComputePipelineId) -> &CachedPipelineState {
|
||||
&self.pipelines[id.0].state
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self, id: CachedPipelineId) -> Option<&RenderPipeline> {
|
||||
if let CachedPipelineState::Ok(pipeline) = &self.pipelines[id.0].state {
|
||||
pub fn get_render_pipeline_descriptor(
|
||||
&self,
|
||||
id: CachedRenderPipelineId,
|
||||
) -> &RenderPipelineDescriptor {
|
||||
match &self.pipelines[id.0].descriptor {
|
||||
PipelineDescriptor::RenderPipelineDescriptor(descriptor) => descriptor,
|
||||
PipelineDescriptor::ComputePipelineDescriptor(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_compute_pipeline_descriptor(
|
||||
&self,
|
||||
id: CachedComputePipelineId,
|
||||
) -> &ComputePipelineDescriptor {
|
||||
match &self.pipelines[id.0].descriptor {
|
||||
PipelineDescriptor::RenderPipelineDescriptor(_) => unreachable!(),
|
||||
PipelineDescriptor::ComputePipelineDescriptor(descriptor) => descriptor,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_render_pipeline(&self, id: CachedRenderPipelineId) -> Option<&RenderPipeline> {
|
||||
if let CachedPipelineState::Ok(Pipeline::RenderPipeline(pipeline)) =
|
||||
&self.pipelines[id.0].state
|
||||
{
|
||||
Some(pipeline)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue(&mut self, descriptor: RenderPipelineDescriptor) -> CachedPipelineId {
|
||||
let id = CachedPipelineId(self.pipelines.len());
|
||||
#[inline]
|
||||
pub fn get_compute_pipeline(&self, id: CachedComputePipelineId) -> Option<&ComputePipeline> {
|
||||
if let CachedPipelineState::Ok(Pipeline::ComputePipeline(pipeline)) =
|
||||
&self.pipelines[id.0].state
|
||||
{
|
||||
Some(pipeline)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue_render_pipeline(
|
||||
&mut self,
|
||||
descriptor: RenderPipelineDescriptor,
|
||||
) -> CachedRenderPipelineId {
|
||||
let id = CachedRenderPipelineId(self.pipelines.len());
|
||||
self.pipelines.push(CachedPipeline {
|
||||
descriptor,
|
||||
descriptor: PipelineDescriptor::RenderPipelineDescriptor(Box::new(descriptor)),
|
||||
state: CachedPipelineState::Queued,
|
||||
});
|
||||
self.waiting_pipelines.insert(id);
|
||||
self.waiting_pipelines.insert(id.0);
|
||||
id
|
||||
}
|
||||
|
||||
pub fn queue_compute_pipeline(
|
||||
&mut self,
|
||||
descriptor: ComputePipelineDescriptor,
|
||||
) -> CachedComputePipelineId {
|
||||
let id = CachedComputePipelineId(self.pipelines.len());
|
||||
self.pipelines.push(CachedPipeline {
|
||||
descriptor: PipelineDescriptor::ComputePipelineDescriptor(Box::new(descriptor)),
|
||||
state: CachedPipelineState::Queued,
|
||||
});
|
||||
self.waiting_pipelines.insert(id.0);
|
||||
id
|
||||
}
|
||||
|
||||
fn set_shader(&mut self, handle: &Handle<Shader>, shader: &Shader) {
|
||||
let pipelines_to_queue = self.shader_cache.set_shader(handle, shader.clone());
|
||||
for cached_pipeline in pipelines_to_queue {
|
||||
self.pipelines[cached_pipeline.0].state = CachedPipelineState::Queued;
|
||||
self.pipelines[cached_pipeline].state = CachedPipelineState::Queued;
|
||||
self.waiting_pipelines.insert(cached_pipeline);
|
||||
}
|
||||
}
|
||||
|
@ -279,28 +336,146 @@ impl RenderPipelineCache {
|
|||
fn remove_shader(&mut self, shader: &Handle<Shader>) {
|
||||
let pipelines_to_queue = self.shader_cache.remove(shader);
|
||||
for cached_pipeline in pipelines_to_queue {
|
||||
self.pipelines[cached_pipeline.0].state = CachedPipelineState::Queued;
|
||||
self.pipelines[cached_pipeline].state = CachedPipelineState::Queued;
|
||||
self.waiting_pipelines.insert(cached_pipeline);
|
||||
}
|
||||
}
|
||||
|
||||
fn process_render_pipeline(
|
||||
&mut self,
|
||||
id: CachedPipelineId,
|
||||
descriptor: &RenderPipelineDescriptor,
|
||||
) -> CachedPipelineState {
|
||||
let vertex_module = match self.shader_cache.get(
|
||||
&self.device,
|
||||
id,
|
||||
&descriptor.vertex.shader,
|
||||
&descriptor.vertex.shader_defs,
|
||||
) {
|
||||
Ok(module) => module,
|
||||
Err(err) => {
|
||||
return CachedPipelineState::Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
let fragment_data = if let Some(fragment) = &descriptor.fragment {
|
||||
let fragment_module = match self.shader_cache.get(
|
||||
&self.device,
|
||||
id,
|
||||
&fragment.shader,
|
||||
&fragment.shader_defs,
|
||||
) {
|
||||
Ok(module) => module,
|
||||
Err(err) => {
|
||||
return CachedPipelineState::Err(err);
|
||||
}
|
||||
};
|
||||
Some((
|
||||
fragment_module,
|
||||
fragment.entry_point.deref(),
|
||||
&fragment.targets,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let vertex_buffer_layouts = descriptor
|
||||
.vertex
|
||||
.buffers
|
||||
.iter()
|
||||
.map(|layout| RawVertexBufferLayout {
|
||||
array_stride: layout.array_stride,
|
||||
attributes: &layout.attributes,
|
||||
step_mode: layout.step_mode,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let layout = if let Some(layout) = &descriptor.layout {
|
||||
Some(self.layout_cache.get(&self.device, layout))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let descriptor = RawRenderPipelineDescriptor {
|
||||
multiview: None,
|
||||
depth_stencil: descriptor.depth_stencil.clone(),
|
||||
label: descriptor.label.as_deref(),
|
||||
layout,
|
||||
multisample: descriptor.multisample,
|
||||
primitive: descriptor.primitive,
|
||||
vertex: RawVertexState {
|
||||
buffers: &vertex_buffer_layouts,
|
||||
entry_point: descriptor.vertex.entry_point.deref(),
|
||||
module: &vertex_module,
|
||||
},
|
||||
fragment: fragment_data
|
||||
.as_ref()
|
||||
.map(|(module, entry_point, targets)| RawFragmentState {
|
||||
entry_point,
|
||||
module,
|
||||
targets,
|
||||
}),
|
||||
};
|
||||
|
||||
let pipeline = self.device.create_render_pipeline(&descriptor);
|
||||
|
||||
CachedPipelineState::Ok(Pipeline::RenderPipeline(pipeline))
|
||||
}
|
||||
|
||||
fn process_compute_pipeline(
|
||||
&mut self,
|
||||
id: CachedPipelineId,
|
||||
descriptor: &ComputePipelineDescriptor,
|
||||
) -> CachedPipelineState {
|
||||
let compute_module = match self.shader_cache.get(
|
||||
&self.device,
|
||||
id,
|
||||
&descriptor.shader,
|
||||
&descriptor.shader_defs,
|
||||
) {
|
||||
Ok(module) => module,
|
||||
Err(err) => {
|
||||
return CachedPipelineState::Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
let layout = if let Some(layout) = &descriptor.layout {
|
||||
Some(self.layout_cache.get(&self.device, layout))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let descriptor = RawComputePipelineDescriptor {
|
||||
label: descriptor.label.as_deref(),
|
||||
layout,
|
||||
module: &compute_module,
|
||||
entry_point: descriptor.entry_point.as_ref(),
|
||||
};
|
||||
|
||||
let pipeline = self.device.create_compute_pipeline(&descriptor);
|
||||
|
||||
CachedPipelineState::Ok(Pipeline::ComputePipeline(pipeline))
|
||||
}
|
||||
|
||||
pub fn process_queue(&mut self) {
|
||||
let pipelines = std::mem::take(&mut self.waiting_pipelines);
|
||||
for id in pipelines {
|
||||
let state = &mut self.pipelines[id.0];
|
||||
match &state.state {
|
||||
let waiting_pipelines = mem::take(&mut self.waiting_pipelines);
|
||||
let mut pipelines = mem::take(&mut self.pipelines);
|
||||
|
||||
for id in waiting_pipelines {
|
||||
let pipeline = &mut pipelines[id];
|
||||
match &pipeline.state {
|
||||
CachedPipelineState::Ok(_) => continue,
|
||||
CachedPipelineState::Queued => {}
|
||||
CachedPipelineState::Err(err) => {
|
||||
match err {
|
||||
RenderPipelineError::ShaderNotLoaded(_)
|
||||
| RenderPipelineError::ShaderImportNotYetAvailable => { /* retry */ }
|
||||
PipelineCacheError::ShaderNotLoaded(_)
|
||||
| PipelineCacheError::ShaderImportNotYetAvailable => { /* retry */ }
|
||||
// shader could not be processed ... retrying won't help
|
||||
RenderPipelineError::ProcessShaderError(err) => {
|
||||
PipelineCacheError::ProcessShaderError(err) => {
|
||||
error!("failed to process shader: {}", err);
|
||||
continue;
|
||||
}
|
||||
RenderPipelineError::AsModuleDescriptorError(err, source) => {
|
||||
PipelineCacheError::AsModuleDescriptorError(err, source) => {
|
||||
log_shader_error(source, err);
|
||||
continue;
|
||||
}
|
||||
|
@ -308,85 +483,21 @@ impl RenderPipelineCache {
|
|||
}
|
||||
}
|
||||
|
||||
let descriptor = &state.descriptor;
|
||||
let vertex_module = match self.shader_cache.get(
|
||||
&self.device,
|
||||
id,
|
||||
&descriptor.vertex.shader,
|
||||
&descriptor.vertex.shader_defs,
|
||||
) {
|
||||
Ok(module) => module,
|
||||
Err(err) => {
|
||||
state.state = CachedPipelineState::Err(err);
|
||||
self.waiting_pipelines.insert(id);
|
||||
continue;
|
||||
pipeline.state = match &pipeline.descriptor {
|
||||
PipelineDescriptor::RenderPipelineDescriptor(descriptor) => {
|
||||
self.process_render_pipeline(id, descriptor)
|
||||
}
|
||||
PipelineDescriptor::ComputePipelineDescriptor(descriptor) => {
|
||||
self.process_compute_pipeline(id, descriptor)
|
||||
}
|
||||
};
|
||||
|
||||
let fragment_data = if let Some(fragment) = &descriptor.fragment {
|
||||
let fragment_module = match self.shader_cache.get(
|
||||
&self.device,
|
||||
id,
|
||||
&fragment.shader,
|
||||
&fragment.shader_defs,
|
||||
) {
|
||||
Ok(module) => module,
|
||||
Err(err) => {
|
||||
state.state = CachedPipelineState::Err(err);
|
||||
self.waiting_pipelines.insert(id);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
Some((
|
||||
fragment_module,
|
||||
fragment.entry_point.deref(),
|
||||
&fragment.targets,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let vertex_buffer_layouts = descriptor
|
||||
.vertex
|
||||
.buffers
|
||||
.iter()
|
||||
.map(|layout| RawVertexBufferLayout {
|
||||
array_stride: layout.array_stride,
|
||||
attributes: &layout.attributes,
|
||||
step_mode: layout.step_mode,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let layout = if let Some(layout) = &descriptor.layout {
|
||||
Some(self.layout_cache.get(&self.device, layout))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let descriptor = RawRenderPipelineDescriptor {
|
||||
multiview: None,
|
||||
depth_stencil: descriptor.depth_stencil.clone(),
|
||||
label: descriptor.label.as_deref(),
|
||||
layout,
|
||||
multisample: descriptor.multisample,
|
||||
primitive: descriptor.primitive,
|
||||
vertex: RawVertexState {
|
||||
buffers: &vertex_buffer_layouts,
|
||||
entry_point: descriptor.vertex.entry_point.deref(),
|
||||
module: &vertex_module,
|
||||
},
|
||||
fragment: fragment_data
|
||||
.as_ref()
|
||||
.map(|(module, entry_point, targets)| RawFragmentState {
|
||||
entry_point,
|
||||
module,
|
||||
targets,
|
||||
}),
|
||||
};
|
||||
|
||||
let pipeline = self.device.create_render_pipeline(&descriptor);
|
||||
state.state = CachedPipelineState::Ok(pipeline);
|
||||
if let CachedPipelineState::Err(_) = pipeline.state {
|
||||
self.waiting_pipelines.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
self.pipelines = pipelines;
|
||||
}
|
||||
|
||||
pub(crate) fn process_pipeline_queue_system(mut cache: ResMut<Self>) {
|
||||
|
@ -503,6 +614,20 @@ fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PipelineCacheError {
|
||||
#[error(
|
||||
"Pipeline cound not be compiled because the following shader is not loaded yet: {0:?}"
|
||||
)]
|
||||
ShaderNotLoaded(Handle<Shader>),
|
||||
#[error(transparent)]
|
||||
ProcessShaderError(#[from] ProcessShaderError),
|
||||
#[error("{0}")]
|
||||
AsModuleDescriptorError(AsModuleDescriptorError, ProcessedShader),
|
||||
#[error("Shader import not yet available.")]
|
||||
ShaderImportNotYetAvailable,
|
||||
}
|
||||
|
||||
struct ErrorSources<'a> {
|
||||
current: Option<&'a (dyn std::error::Error + 'static)>,
|
||||
}
|
||||
|
|
|
@ -1,51 +1,74 @@
|
|||
use crate::render_resource::CachedComputePipelineId;
|
||||
use crate::{
|
||||
mesh::{InnerMeshVertexBufferLayout, MeshVertexBufferLayout, MissingVertexAttributeError},
|
||||
render_resource::{
|
||||
CachedPipelineId, RenderPipelineCache, RenderPipelineDescriptor, VertexBufferLayout,
|
||||
CachedRenderPipelineId, ComputePipelineDescriptor, PipelineCache, RenderPipelineDescriptor,
|
||||
VertexBufferLayout,
|
||||
},
|
||||
};
|
||||
use bevy_utils::{
|
||||
hashbrown::hash_map::RawEntryMut, tracing::error, Entry, HashMap, PreHashMap, PreHashMapExt,
|
||||
default, hashbrown::hash_map::RawEntryMut, tracing::error, Entry, HashMap, PreHashMap,
|
||||
PreHashMapExt,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
use thiserror::Error;
|
||||
|
||||
pub trait SpecializedPipeline {
|
||||
pub trait SpecializedRenderPipeline {
|
||||
type Key: Clone + Hash + PartialEq + Eq;
|
||||
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor;
|
||||
}
|
||||
|
||||
pub struct SpecializedPipelines<S: SpecializedPipeline> {
|
||||
cache: HashMap<S::Key, CachedPipelineId>,
|
||||
pub struct SpecializedRenderPipelines<S: SpecializedRenderPipeline> {
|
||||
cache: HashMap<S::Key, CachedRenderPipelineId>,
|
||||
}
|
||||
|
||||
impl<S: SpecializedPipeline> Default for SpecializedPipelines<S> {
|
||||
impl<S: SpecializedRenderPipeline> Default for SpecializedRenderPipelines<S> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cache: Default::default(),
|
||||
}
|
||||
Self { cache: default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: SpecializedPipeline> SpecializedPipelines<S> {
|
||||
impl<S: SpecializedRenderPipeline> SpecializedRenderPipelines<S> {
|
||||
pub fn specialize(
|
||||
&mut self,
|
||||
cache: &mut RenderPipelineCache,
|
||||
cache: &mut PipelineCache,
|
||||
specialize_pipeline: &S,
|
||||
key: S::Key,
|
||||
) -> CachedPipelineId {
|
||||
) -> CachedRenderPipelineId {
|
||||
*self.cache.entry(key.clone()).or_insert_with(|| {
|
||||
let descriptor = specialize_pipeline.specialize(key);
|
||||
cache.queue(descriptor)
|
||||
cache.queue_render_pipeline(descriptor)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum SpecializedMeshPipelineError {
|
||||
#[error(transparent)]
|
||||
MissingVertexAttribute(#[from] MissingVertexAttributeError),
|
||||
pub trait SpecializedComputePipeline {
|
||||
type Key: Clone + Hash + PartialEq + Eq;
|
||||
fn specialize(&self, key: Self::Key) -> ComputePipelineDescriptor;
|
||||
}
|
||||
|
||||
pub struct SpecializedComputePipelines<S: SpecializedComputePipeline> {
|
||||
cache: HashMap<S::Key, CachedComputePipelineId>,
|
||||
}
|
||||
|
||||
impl<S: SpecializedComputePipeline> Default for SpecializedComputePipelines<S> {
|
||||
fn default() -> Self {
|
||||
Self { cache: default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: SpecializedComputePipeline> SpecializedComputePipelines<S> {
|
||||
pub fn specialize(
|
||||
&mut self,
|
||||
cache: &mut PipelineCache,
|
||||
specialize_pipeline: &S,
|
||||
key: S::Key,
|
||||
) -> CachedComputePipelineId {
|
||||
*self.cache.entry(key.clone()).or_insert_with(|| {
|
||||
let descriptor = specialize_pipeline.specialize(key);
|
||||
cache.queue_compute_pipeline(descriptor)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SpecializedMeshPipeline {
|
||||
|
@ -58,8 +81,9 @@ pub trait SpecializedMeshPipeline {
|
|||
}
|
||||
|
||||
pub struct SpecializedMeshPipelines<S: SpecializedMeshPipeline> {
|
||||
mesh_layout_cache: PreHashMap<InnerMeshVertexBufferLayout, HashMap<S::Key, CachedPipelineId>>,
|
||||
vertex_layout_cache: HashMap<VertexBufferLayout, HashMap<S::Key, CachedPipelineId>>,
|
||||
mesh_layout_cache:
|
||||
PreHashMap<InnerMeshVertexBufferLayout, HashMap<S::Key, CachedRenderPipelineId>>,
|
||||
vertex_layout_cache: HashMap<VertexBufferLayout, HashMap<S::Key, CachedRenderPipelineId>>,
|
||||
}
|
||||
|
||||
impl<S: SpecializedMeshPipeline> Default for SpecializedMeshPipelines<S> {
|
||||
|
@ -75,11 +99,11 @@ impl<S: SpecializedMeshPipeline> SpecializedMeshPipelines<S> {
|
|||
#[inline]
|
||||
pub fn specialize(
|
||||
&mut self,
|
||||
cache: &mut RenderPipelineCache,
|
||||
cache: &mut PipelineCache,
|
||||
specialize_pipeline: &S,
|
||||
key: S::Key,
|
||||
layout: &MeshVertexBufferLayout,
|
||||
) -> Result<CachedPipelineId, SpecializedMeshPipelineError> {
|
||||
) -> Result<CachedRenderPipelineId, SpecializedMeshPipelineError> {
|
||||
let map = self
|
||||
.mesh_layout_cache
|
||||
.get_or_insert_with(layout, Default::default);
|
||||
|
@ -113,7 +137,7 @@ impl<S: SpecializedMeshPipeline> SpecializedMeshPipelines<S> {
|
|||
Ok(*entry.insert(match layout_map.entry(key) {
|
||||
Entry::Occupied(entry) => {
|
||||
if cfg!(debug_assertions) {
|
||||
let stored_descriptor = cache.get_descriptor(*entry.get());
|
||||
let stored_descriptor = cache.get_render_pipeline_descriptor(*entry.get());
|
||||
if stored_descriptor != &descriptor {
|
||||
error!("The cached pipeline descriptor for {} is not equal to the generated descriptor for the given key. This means the SpecializePipeline implementation uses 'unused' MeshVertexBufferLayout information to specialize the pipeline. This is not allowed because it would invalidate the pipeline cache.", std::any::type_name::<S>());
|
||||
}
|
||||
|
@ -121,10 +145,16 @@ impl<S: SpecializedMeshPipeline> SpecializedMeshPipelines<S> {
|
|||
*entry.into_mut()
|
||||
}
|
||||
Entry::Vacant(entry) => {
|
||||
*entry.insert(cache.queue(descriptor))
|
||||
*entry.insert(cache.queue_render_pipeline(descriptor))
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum SpecializedMeshPipelineError {
|
||||
#[error(transparent)]
|
||||
MissingVertexAttribute(#[from] MissingVertexAttributeError),
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel};
|
|||
use bevy_reflect::TypeUuid;
|
||||
use bevy_render::{
|
||||
render_phase::AddRenderCommand,
|
||||
render_resource::{Shader, SpecializedPipelines},
|
||||
render_resource::{Shader, SpecializedRenderPipelines},
|
||||
RenderApp, RenderStage,
|
||||
};
|
||||
|
||||
|
@ -64,7 +64,7 @@ impl Plugin for SpritePlugin {
|
|||
render_app
|
||||
.init_resource::<ImageBindGroups>()
|
||||
.init_resource::<SpritePipeline>()
|
||||
.init_resource::<SpecializedPipelines<SpritePipeline>>()
|
||||
.init_resource::<SpecializedRenderPipelines<SpritePipeline>>()
|
||||
.init_resource::<SpriteMeta>()
|
||||
.init_resource::<ExtractedSprites>()
|
||||
.init_resource::<SpriteAssetEvents>()
|
||||
|
|
|
@ -21,7 +21,7 @@ use bevy_render::{
|
|||
SetItemPipeline, TrackedRenderPass,
|
||||
},
|
||||
render_resource::{
|
||||
BindGroup, BindGroupLayout, RenderPipelineCache, RenderPipelineDescriptor, Shader,
|
||||
BindGroup, BindGroupLayout, PipelineCache, RenderPipelineDescriptor, Shader,
|
||||
SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines,
|
||||
},
|
||||
renderer::RenderDevice,
|
||||
|
@ -291,7 +291,7 @@ pub fn queue_material2d_meshes<M: SpecializedMaterial2d>(
|
|||
transparent_draw_functions: Res<DrawFunctions<Transparent2d>>,
|
||||
material2d_pipeline: Res<Material2dPipeline<M>>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<Material2dPipeline<M>>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
msaa: Res<Msaa>,
|
||||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
render_materials: Res<RenderAssets<M>>,
|
||||
|
|
|
@ -109,7 +109,7 @@ impl SpritePipelineKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl SpecializedPipeline for SpritePipeline {
|
||||
impl SpecializedRenderPipeline for SpritePipeline {
|
||||
type Key = SpritePipelineKey;
|
||||
|
||||
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
|
||||
|
@ -338,8 +338,8 @@ pub fn queue_sprites(
|
|||
mut sprite_meta: ResMut<SpriteMeta>,
|
||||
view_uniforms: Res<ViewUniforms>,
|
||||
sprite_pipeline: Res<SpritePipeline>,
|
||||
mut pipelines: ResMut<SpecializedPipelines<SpritePipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipelines: ResMut<SpecializedRenderPipelines<SpritePipeline>>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
mut image_bind_groups: ResMut<ImageBindGroups>,
|
||||
gpu_images: Res<RenderAssets<Image>>,
|
||||
msaa: Res<Msaa>,
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn build_ui_render(app: &mut App) {
|
|||
|
||||
render_app
|
||||
.init_resource::<UiPipeline>()
|
||||
.init_resource::<SpecializedPipelines<UiPipeline>>()
|
||||
.init_resource::<SpecializedRenderPipelines<UiPipeline>>()
|
||||
.init_resource::<UiImageBindGroups>()
|
||||
.init_resource::<UiMeta>()
|
||||
.init_resource::<ExtractedUiNodes>()
|
||||
|
@ -403,8 +403,8 @@ pub fn queue_uinodes(
|
|||
mut ui_meta: ResMut<UiMeta>,
|
||||
view_uniforms: Res<ViewUniforms>,
|
||||
ui_pipeline: Res<UiPipeline>,
|
||||
mut pipelines: ResMut<SpecializedPipelines<UiPipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipelines: ResMut<SpecializedRenderPipelines<UiPipeline>>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
mut image_bind_groups: ResMut<UiImageBindGroups>,
|
||||
gpu_images: Res<RenderAssets<Image>>,
|
||||
ui_batches: Query<(Entity, &UiBatch)>,
|
||||
|
|
|
@ -62,7 +62,7 @@ impl FromWorld for UiPipeline {
|
|||
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
||||
pub struct UiPipelineKey {}
|
||||
|
||||
impl SpecializedPipeline for UiPipeline {
|
||||
impl SpecializedRenderPipeline for UiPipeline {
|
||||
type Key = UiPipelineKey;
|
||||
/// FIXME: there are no specialization for now, should this be removed?
|
||||
fn specialize(&self, _key: Self::Key) -> RenderPipelineDescriptor {
|
||||
|
|
|
@ -8,7 +8,7 @@ use bevy_render::{
|
|||
render_graph::*,
|
||||
render_phase::*,
|
||||
render_resource::{
|
||||
CachedPipelineId, LoadOp, Operations, RenderPassColorAttachment, RenderPassDescriptor,
|
||||
CachedRenderPipelineId, LoadOp, Operations, RenderPassColorAttachment, RenderPassDescriptor,
|
||||
},
|
||||
renderer::*,
|
||||
view::*,
|
||||
|
@ -102,7 +102,7 @@ impl Node for UiPassNode {
|
|||
pub struct TransparentUi {
|
||||
pub sort_key: FloatOrd,
|
||||
pub entity: Entity,
|
||||
pub pipeline: CachedPipelineId,
|
||||
pub pipeline: CachedRenderPipelineId,
|
||||
pub draw_function: DrawFunctionId,
|
||||
}
|
||||
|
||||
|
@ -127,9 +127,9 @@ impl EntityPhaseItem for TransparentUi {
|
|||
}
|
||||
}
|
||||
|
||||
impl CachedPipelinePhaseItem for TransparentUi {
|
||||
impl CachedRenderPipelinePhaseItem for TransparentUi {
|
||||
#[inline]
|
||||
fn cached_pipeline(&self) -> CachedPipelineId {
|
||||
fn cached_pipeline(&self) -> CachedRenderPipelineId {
|
||||
self.pipeline
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ use bevy::{
|
|||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||
render_resource::{
|
||||
BlendState, ColorTargetState, ColorWrites, Face, FragmentState, FrontFace,
|
||||
MultisampleState, PolygonMode, PrimitiveState, PrimitiveTopology, RenderPipelineCache,
|
||||
RenderPipelineDescriptor, SpecializedPipeline, SpecializedPipelines, TextureFormat,
|
||||
VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
|
||||
MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PrimitiveTopology,
|
||||
RenderPipelineDescriptor, SpecializedRenderPipeline, SpecializedRenderPipelines,
|
||||
TextureFormat, VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
|
||||
},
|
||||
texture::BevyDefault,
|
||||
view::VisibleEntities,
|
||||
|
@ -125,7 +125,7 @@ impl FromWorld for ColoredMesh2dPipeline {
|
|||
}
|
||||
|
||||
// We implement `SpecializedPipeline` to customize the default rendering from `Mesh2dPipeline`
|
||||
impl SpecializedPipeline for ColoredMesh2dPipeline {
|
||||
impl SpecializedRenderPipeline for ColoredMesh2dPipeline {
|
||||
type Key = Mesh2dPipelineKey;
|
||||
|
||||
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
|
||||
|
@ -269,7 +269,7 @@ impl Plugin for ColoredMesh2dPlugin {
|
|||
render_app
|
||||
.add_render_command::<Transparent2d, DrawColoredMesh2d>()
|
||||
.init_resource::<ColoredMesh2dPipeline>()
|
||||
.init_resource::<SpecializedPipelines<ColoredMesh2dPipeline>>()
|
||||
.init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()
|
||||
.add_system_to_stage(RenderStage::Extract, extract_colored_mesh2d)
|
||||
.add_system_to_stage(RenderStage::Queue, queue_colored_mesh2d);
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ pub fn extract_colored_mesh2d(
|
|||
pub fn queue_colored_mesh2d(
|
||||
transparent_draw_functions: Res<DrawFunctions<Transparent2d>>,
|
||||
colored_mesh2d_pipeline: Res<ColoredMesh2dPipeline>,
|
||||
mut pipelines: ResMut<SpecializedPipelines<ColoredMesh2dPipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipelines: ResMut<SpecializedRenderPipelines<ColoredMesh2dPipeline>>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
msaa: Res<Msaa>,
|
||||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
colored_mesh2d: Query<(&Mesh2dHandle, &Mesh2dUniform), With<ColoredMesh2d>>,
|
||||
|
|
|
@ -98,7 +98,7 @@ fn queue_custom(
|
|||
custom_pipeline: Res<CustomPipeline>,
|
||||
msaa: Res<Msaa>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<CustomPipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
render_meshes: Res<RenderAssets<Mesh>>,
|
||||
material_meshes: Query<(Entity, &MeshUniform, &Handle<Mesh>), With<CustomMaterial>>,
|
||||
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent3d>)>,
|
||||
|
|
|
@ -10,6 +10,7 @@ use bevy::{
|
|||
},
|
||||
window::WindowDescriptor,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
const SIZE: (u32, u32) = (1280, 720);
|
||||
const WORKGROUP_SIZE: u32 = 8;
|
||||
|
@ -67,7 +68,7 @@ impl Plugin for GameOfLifeComputePlugin {
|
|||
.add_system_to_stage(RenderStage::Queue, queue_bind_group);
|
||||
|
||||
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();
|
||||
render_graph.add_node("game_of_life", DispatchGameOfLife::default());
|
||||
render_graph.add_node("game_of_life", GameOfLifeNode::default());
|
||||
render_graph
|
||||
.add_node_edge("game_of_life", MAIN_PASS_DEPENDENCIES)
|
||||
.unwrap();
|
||||
|
@ -80,6 +81,7 @@ struct GameOfLifeImageBindGroup(BindGroup);
|
|||
fn extract_game_of_life_image(mut commands: Commands, image: Res<GameOfLifeImage>) {
|
||||
commands.insert_resource(GameOfLifeImage(image.0.clone()));
|
||||
}
|
||||
|
||||
fn queue_bind_group(
|
||||
mut commands: Commands,
|
||||
pipeline: Res<GameOfLifePipeline>,
|
||||
|
@ -100,84 +102,96 @@ fn queue_bind_group(
|
|||
}
|
||||
|
||||
pub struct GameOfLifePipeline {
|
||||
sim_pipeline: ComputePipeline,
|
||||
init_pipeline: ComputePipeline,
|
||||
texture_bind_group_layout: BindGroupLayout,
|
||||
init_pipeline: CachedComputePipelineId,
|
||||
update_pipeline: CachedComputePipelineId,
|
||||
}
|
||||
|
||||
impl FromWorld for GameOfLifePipeline {
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
let render_device = world.resource::<RenderDevice>();
|
||||
|
||||
let shader_source = include_str!("../../assets/shaders/game_of_life.wgsl");
|
||||
let shader = render_device.create_shader_module(&ShaderModuleDescriptor {
|
||||
label: None,
|
||||
source: ShaderSource::Wgsl(shader_source.into()),
|
||||
});
|
||||
|
||||
let texture_bind_group_layout =
|
||||
render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: &[BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: ShaderStages::COMPUTE,
|
||||
ty: BindingType::StorageTexture {
|
||||
access: StorageTextureAccess::ReadWrite,
|
||||
format: TextureFormat::Rgba8Unorm,
|
||||
view_dimension: TextureViewDimension::D2,
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
});
|
||||
|
||||
let pipeline_layout = render_device.create_pipeline_layout(&PipelineLayoutDescriptor {
|
||||
world
|
||||
.resource::<RenderDevice>()
|
||||
.create_bind_group_layout(&BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: &[BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: ShaderStages::COMPUTE,
|
||||
ty: BindingType::StorageTexture {
|
||||
access: StorageTextureAccess::ReadWrite,
|
||||
format: TextureFormat::Rgba8Unorm,
|
||||
view_dimension: TextureViewDimension::D2,
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
});
|
||||
let shader = world
|
||||
.resource::<AssetServer>()
|
||||
.load("shaders/game_of_life.wgsl");
|
||||
let mut pipeline_cache = world.resource_mut::<PipelineCache>();
|
||||
let init_pipeline = pipeline_cache.queue_compute_pipeline(ComputePipelineDescriptor {
|
||||
label: None,
|
||||
bind_group_layouts: &[&texture_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
layout: Some(vec![texture_bind_group_layout.clone()]),
|
||||
shader: shader.clone(),
|
||||
shader_defs: vec![],
|
||||
entry_point: Cow::from("init"),
|
||||
});
|
||||
let init_pipeline = render_device.create_compute_pipeline(&ComputePipelineDescriptor {
|
||||
let update_pipeline = pipeline_cache.queue_compute_pipeline(ComputePipelineDescriptor {
|
||||
label: None,
|
||||
layout: Some(&pipeline_layout),
|
||||
module: &shader,
|
||||
entry_point: "init",
|
||||
});
|
||||
let sim_pipeline = render_device.create_compute_pipeline(&ComputePipelineDescriptor {
|
||||
label: None,
|
||||
layout: Some(&pipeline_layout),
|
||||
module: &shader,
|
||||
entry_point: "update",
|
||||
layout: Some(vec![texture_bind_group_layout.clone()]),
|
||||
shader,
|
||||
shader_defs: vec![],
|
||||
entry_point: Cow::from("update"),
|
||||
});
|
||||
|
||||
GameOfLifePipeline {
|
||||
sim_pipeline,
|
||||
init_pipeline,
|
||||
texture_bind_group_layout,
|
||||
init_pipeline,
|
||||
update_pipeline,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Initialized {
|
||||
Default,
|
||||
No,
|
||||
Yes,
|
||||
enum GameOfLifeState {
|
||||
Loading,
|
||||
Init,
|
||||
Update,
|
||||
}
|
||||
|
||||
struct DispatchGameOfLife {
|
||||
initialized: Initialized,
|
||||
struct GameOfLifeNode {
|
||||
state: GameOfLifeState,
|
||||
}
|
||||
impl Default for DispatchGameOfLife {
|
||||
|
||||
impl Default for GameOfLifeNode {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
initialized: Initialized::Default,
|
||||
state: GameOfLifeState::Loading,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl render_graph::Node for DispatchGameOfLife {
|
||||
fn update(&mut self, _world: &mut World) {
|
||||
match self.initialized {
|
||||
Initialized::Default => self.initialized = Initialized::No,
|
||||
Initialized::No => self.initialized = Initialized::Yes,
|
||||
Initialized::Yes => {}
|
||||
|
||||
impl render_graph::Node for GameOfLifeNode {
|
||||
fn update(&mut self, world: &mut World) {
|
||||
let pipeline = world.resource::<GameOfLifePipeline>();
|
||||
let pipeline_cache = world.resource::<PipelineCache>();
|
||||
|
||||
// if the corresponding pipeline has loaded, transition to the next stage
|
||||
match self.state {
|
||||
GameOfLifeState::Loading => {
|
||||
if let CachedPipelineState::Ok(_) =
|
||||
pipeline_cache.get_compute_pipeline_state(pipeline.init_pipeline)
|
||||
{
|
||||
self.state = GameOfLifeState::Init
|
||||
}
|
||||
}
|
||||
GameOfLifeState::Init => {
|
||||
if let CachedPipelineState::Ok(_) =
|
||||
pipeline_cache.get_compute_pipeline_state(pipeline.update_pipeline)
|
||||
{
|
||||
self.state = GameOfLifeState::Update
|
||||
}
|
||||
}
|
||||
GameOfLifeState::Update => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,22 +201,34 @@ impl render_graph::Node for DispatchGameOfLife {
|
|||
render_context: &mut RenderContext,
|
||||
world: &World,
|
||||
) -> Result<(), render_graph::NodeRunError> {
|
||||
let pipeline = world.resource::<GameOfLifePipeline>();
|
||||
let texture_bind_group = &world.resource::<GameOfLifeImageBindGroup>().0;
|
||||
let pipeline_cache = world.resource::<PipelineCache>();
|
||||
let pipeline = world.resource::<GameOfLifePipeline>();
|
||||
|
||||
let mut pass = render_context
|
||||
.command_encoder
|
||||
.begin_compute_pass(&ComputePassDescriptor::default());
|
||||
|
||||
if let Initialized::No = self.initialized {
|
||||
pass.set_pipeline(&pipeline.init_pipeline);
|
||||
pass.set_bind_group(0, texture_bind_group, &[]);
|
||||
pass.dispatch(SIZE.0 / WORKGROUP_SIZE, SIZE.1 / WORKGROUP_SIZE, 1);
|
||||
}
|
||||
|
||||
pass.set_pipeline(&pipeline.sim_pipeline);
|
||||
pass.set_bind_group(0, texture_bind_group, &[]);
|
||||
pass.dispatch(SIZE.0 / WORKGROUP_SIZE, SIZE.1 / WORKGROUP_SIZE, 1);
|
||||
|
||||
// select the pipeline based on the current state
|
||||
match self.state {
|
||||
GameOfLifeState::Loading => {}
|
||||
GameOfLifeState::Init => {
|
||||
let init_pipeline = pipeline_cache
|
||||
.get_compute_pipeline(pipeline.init_pipeline)
|
||||
.unwrap();
|
||||
pass.set_pipeline(init_pipeline);
|
||||
pass.dispatch(SIZE.0 / WORKGROUP_SIZE, SIZE.1 / WORKGROUP_SIZE, 1);
|
||||
}
|
||||
GameOfLifeState::Update => {
|
||||
let update_pipeline = pipeline_cache
|
||||
.get_compute_pipeline(pipeline.update_pipeline)
|
||||
.unwrap();
|
||||
pass.set_pipeline(update_pipeline);
|
||||
pass.dispatch(SIZE.0 / WORKGROUP_SIZE, SIZE.1 / WORKGROUP_SIZE, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use bevy::{
|
|||
render_component::{ExtractComponent, ExtractComponentPlugin},
|
||||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||
render_resource::{
|
||||
RenderPipelineCache, RenderPipelineDescriptor, SpecializedMeshPipeline,
|
||||
PipelineCache, RenderPipelineDescriptor, SpecializedMeshPipeline,
|
||||
SpecializedMeshPipelineError, SpecializedMeshPipelines,
|
||||
},
|
||||
view::ExtractedView,
|
||||
|
@ -139,7 +139,7 @@ fn queue_custom(
|
|||
custom_pipeline: Res<IsRedPipeline>,
|
||||
msaa: Res<Msaa>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<IsRedPipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
material_meshes: Query<(Entity, &Handle<Mesh>, &MeshUniform, &IsRed)>,
|
||||
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent3d>)>,
|
||||
) {
|
||||
|
|
|
@ -101,7 +101,7 @@ fn queue_custom(
|
|||
custom_pipeline: Res<CustomPipeline>,
|
||||
msaa: Res<Msaa>,
|
||||
mut pipelines: ResMut<SpecializedMeshPipelines<CustomPipeline>>,
|
||||
mut pipeline_cache: ResMut<RenderPipelineCache>,
|
||||
mut pipeline_cache: ResMut<PipelineCache>,
|
||||
meshes: Res<RenderAssets<Mesh>>,
|
||||
material_meshes: Query<
|
||||
(Entity, &MeshUniform, &Handle<Mesh>),
|
||||
|
|
Loading…
Reference in a new issue