Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove render_resource_wrapper #15441

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/bevy_render/src/render_resource/bind_group.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::renderer::WgpuWrapper;
use crate::{
define_atomic_id,
render_asset::RenderAssets,
render_resource::{resource_macros::*, BindGroupLayout, Buffer, Sampler, TextureView},
render_resource::{BindGroupLayout, Buffer, Sampler, TextureView},
renderer::RenderDevice,
texture::GpuImage,
};
use alloc::sync::Arc;
use bevy_ecs::system::{SystemParam, SystemParamItem};
pub use bevy_render_macros::AsBindGroup;
use core::ops::Deref;
Expand All @@ -13,7 +15,6 @@ use thiserror::Error;
use wgpu::{BindGroupEntry, BindGroupLayoutEntry, BindingResource};

define_atomic_id!(BindGroupId);
render_resource_wrapper!(ErasedBindGroup, wgpu::BindGroup);

/// Bind groups are responsible for binding render resources (e.g. buffers, textures, samplers)
/// to a [`TrackedRenderPass`](crate::render_phase::TrackedRenderPass).
Expand All @@ -24,7 +25,7 @@ render_resource_wrapper!(ErasedBindGroup, wgpu::BindGroup);
#[derive(Clone, Debug)]
pub struct BindGroup {
id: BindGroupId,
value: ErasedBindGroup,
value: Arc<WgpuWrapper<wgpu::BindGroup>>,
}

impl BindGroup {
Expand All @@ -39,7 +40,7 @@ impl From<wgpu::BindGroup> for BindGroup {
fn from(value: wgpu::BindGroup) -> Self {
BindGroup {
id: BindGroupId::new(),
value: ErasedBindGroup::new(value),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_render/src/render_resource/bind_group_layout.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{define_atomic_id, render_resource::resource_macros::*};
use crate::define_atomic_id;
use crate::renderer::WgpuWrapper;
use alloc::sync::Arc;
use core::ops::Deref;

define_atomic_id!(BindGroupLayoutId);
render_resource_wrapper!(ErasedBindGroupLayout, wgpu::BindGroupLayout);

#[derive(Clone, Debug)]
pub struct BindGroupLayout {
id: BindGroupLayoutId,
value: ErasedBindGroupLayout,
value: Arc<WgpuWrapper<wgpu::BindGroupLayout>>,
}

impl PartialEq for BindGroupLayout {
Expand All @@ -32,7 +33,7 @@ impl From<wgpu::BindGroupLayout> for BindGroupLayout {
fn from(value: wgpu::BindGroupLayout) -> Self {
BindGroupLayout {
id: BindGroupLayoutId::new(),
value: ErasedBindGroupLayout::new(value),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_render/src/render_resource/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{define_atomic_id, render_resource::resource_macros::render_resource_wrapper};
use crate::define_atomic_id;
use crate::renderer::WgpuWrapper;
use alloc::sync::Arc;
use core::ops::{Bound, Deref, RangeBounds};

define_atomic_id!(BufferId);
render_resource_wrapper!(ErasedBuffer, wgpu::Buffer);

#[derive(Clone, Debug)]
pub struct Buffer {
id: BufferId,
value: ErasedBuffer,
value: Arc<WgpuWrapper<wgpu::Buffer>>,
size: wgpu::BufferAddress,
}

Expand Down Expand Up @@ -48,7 +49,7 @@ impl From<wgpu::Buffer> for Buffer {
Buffer {
id: BufferId::new(),
size: value.size(),
value: ErasedBuffer::new(value),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_render/src/render_resource/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::ShaderDefVal;
use crate::renderer::WgpuWrapper;
use crate::{
define_atomic_id,
render_resource::{resource_macros::render_resource_wrapper, BindGroupLayout, Shader},
render_resource::{BindGroupLayout, Shader},
};
use alloc::borrow::Cow;
use alloc::sync::Arc;
use bevy_asset::Handle;
use core::ops::Deref;
use wgpu::{
Expand All @@ -12,7 +14,6 @@ use wgpu::{
};

define_atomic_id!(RenderPipelineId);
render_resource_wrapper!(ErasedRenderPipeline, wgpu::RenderPipeline);

/// A [`RenderPipeline`] represents a graphics pipeline and its stages (shaders), bindings and vertex buffers.
///
Expand All @@ -21,7 +22,7 @@ render_resource_wrapper!(ErasedRenderPipeline, wgpu::RenderPipeline);
#[derive(Clone, Debug)]
pub struct RenderPipeline {
id: RenderPipelineId,
value: ErasedRenderPipeline,
value: Arc<WgpuWrapper<wgpu::RenderPipeline>>,
}

impl RenderPipeline {
Expand All @@ -35,7 +36,7 @@ impl From<wgpu::RenderPipeline> for RenderPipeline {
fn from(value: wgpu::RenderPipeline) -> Self {
RenderPipeline {
id: RenderPipelineId::new(),
value: ErasedRenderPipeline::new(value),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
Expand All @@ -50,7 +51,6 @@ impl Deref for RenderPipeline {
}

define_atomic_id!(ComputePipelineId);
render_resource_wrapper!(ErasedComputePipeline, wgpu::ComputePipeline);

/// A [`ComputePipeline`] represents a compute pipeline and its single shader stage.
///
Expand All @@ -59,7 +59,7 @@ render_resource_wrapper!(ErasedComputePipeline, wgpu::ComputePipeline);
#[derive(Clone, Debug)]
pub struct ComputePipeline {
id: ComputePipelineId,
value: ErasedComputePipeline,
value: Arc<WgpuWrapper<wgpu::ComputePipeline>>,
}

impl ComputePipeline {
Expand All @@ -74,7 +74,7 @@ impl From<wgpu::ComputePipeline> for ComputePipeline {
fn from(value: wgpu::ComputePipeline) -> Self {
ComputePipeline {
id: ComputePipelineId::new(),
value: ErasedComputePipeline::new(value),
value: Arc::new(WgpuWrapper::new(value)),
}
}
}
Expand Down
24 changes: 10 additions & 14 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::renderer::WgpuWrapper;
use crate::{
render_resource::*,
renderer::{RenderAdapter, RenderDevice},
Expand Down Expand Up @@ -27,11 +28,6 @@ use wgpu::{
VertexBufferLayout as RawVertexBufferLayout,
};

use crate::render_resource::resource_macros::*;

render_resource_wrapper!(ErasedShaderModule, ShaderModule);
render_resource_wrapper!(ErasedPipelineLayout, PipelineLayout);

/// A descriptor for a [`Pipeline`].
///
/// Used to store an heterogenous collection of render and compute pipeline descriptors together.
Expand Down Expand Up @@ -126,7 +122,7 @@ impl CachedPipelineState {
#[derive(Default)]
struct ShaderData {
pipelines: HashSet<CachedPipelineId>,
processed_shaders: HashMap<Box<[ShaderDefVal]>, ErasedShaderModule>,
processed_shaders: HashMap<Box<[ShaderDefVal]>, Arc<WgpuWrapper<ShaderModule>>>,
resolved_imports: HashMap<ShaderImport, AssetId<Shader>>,
dependents: HashSet<AssetId<Shader>>,
}
Expand Down Expand Up @@ -225,7 +221,7 @@ impl ShaderCache {
pipeline: CachedPipelineId,
id: AssetId<Shader>,
shader_defs: &[ShaderDefVal],
) -> Result<ErasedShaderModule, PipelineCacheError> {
) -> Result<Arc<WgpuWrapper<ShaderModule>>, PipelineCacheError> {
let shader = self
.shaders
.get(&id)
Expand Down Expand Up @@ -338,7 +334,7 @@ impl ShaderCache {
return Err(PipelineCacheError::CreateShaderModule(description));
}

entry.insert(ErasedShaderModule::new(shader_module))
entry.insert(Arc::new(WgpuWrapper::new(shader_module)))
}
};

Expand Down Expand Up @@ -410,7 +406,7 @@ impl ShaderCache {
type LayoutCacheKey = (Vec<BindGroupLayoutId>, Vec<PushConstantRange>);
#[derive(Default)]
struct LayoutCache {
layouts: HashMap<LayoutCacheKey, ErasedPipelineLayout>,
layouts: HashMap<LayoutCacheKey, Arc<WgpuWrapper<PipelineLayout>>>,
}

impl LayoutCache {
Expand All @@ -419,7 +415,7 @@ impl LayoutCache {
render_device: &RenderDevice,
bind_group_layouts: &[BindGroupLayout],
push_constant_ranges: Vec<PushConstantRange>,
) -> ErasedPipelineLayout {
) -> Arc<WgpuWrapper<PipelineLayout>> {
let bind_group_ids = bind_group_layouts.iter().map(BindGroupLayout::id).collect();
self.layouts
.entry((bind_group_ids, push_constant_ranges))
Expand All @@ -428,13 +424,13 @@ impl LayoutCache {
.iter()
.map(BindGroupLayout::value)
.collect::<Vec<_>>();
ErasedPipelineLayout::new(render_device.create_pipeline_layout(
Arc::new(WgpuWrapper::new(render_device.create_pipeline_layout(
&PipelineLayoutDescriptor {
bind_group_layouts: &bind_group_layouts,
push_constant_ranges,
..default()
},
))
)))
})
.clone()
}
Expand Down Expand Up @@ -746,7 +742,7 @@ impl PipelineCache {
multiview: None,
depth_stencil: descriptor.depth_stencil.clone(),
label: descriptor.label.as_deref(),
layout: layout.as_deref(),
layout: layout.as_ref().map(|layout| -> &PipelineLayout { layout }),
bes marked this conversation as resolved.
Show resolved Hide resolved
multisample: descriptor.multisample,
primitive: descriptor.primitive,
vertex: RawVertexState {
Expand Down Expand Up @@ -814,7 +810,7 @@ impl PipelineCache {

let descriptor = RawComputePipelineDescriptor {
label: descriptor.label.as_deref(),
layout: layout.as_deref(),
layout: layout.as_ref().map(|layout| -> &PipelineLayout { layout }),
module: &compute_module,
entry_point: &descriptor.entry_point,
// TODO: Expose this somehow
Expand Down
Loading