From 7d10fbbd0052579b20be66d746e9dcf8749cd6e0 Mon Sep 17 00:00:00 2001 From: Zhixing Zhang Date: Thu, 1 Dec 2022 03:20:29 -0800 Subject: [PATCH 1/5] Allow custom depth texture usage --- .../src/core_3d/camera_3d.rs | 30 +++++++++++++++++-- crates/bevy_core_pipeline/src/core_3d/mod.rs | 7 ++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs index d722f411a21d6..7ba7ebca72e4a 100644 --- a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs +++ b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs @@ -5,20 +5,46 @@ use bevy_render::{ camera::{Camera, CameraRenderGraph, Projection}, extract_component::ExtractComponent, primitives::Frustum, - render_resource::LoadOp, + render_resource::{LoadOp, TextureUsages}, view::VisibleEntities, }; use bevy_transform::prelude::{GlobalTransform, Transform}; use serde::{Deserialize, Serialize}; /// Configuration for the "main 3d render graph". -#[derive(Component, Reflect, Clone, Default)] +#[derive(Component, Reflect, Clone)] #[reflect(Component)] pub struct Camera3d { /// The clear color operation to perform for the main 3d pass. pub clear_color: ClearColorConfig, /// The depth clear operation to perform for the main 3d pass. pub depth_load_op: Camera3dDepthLoadOp, + /// The texture usages for the depth texture created for the main 3d pass. + pub depth_texture_usages: Camera3dDepthTextureUsage, +} + +impl Default for Camera3d { + fn default() -> Self { + Self { + clear_color: ClearColorConfig::Default, + depth_load_op: Default::default(), + depth_texture_usages: TextureUsages::RENDER_ATTACHMENT.into(), + } + } +} + +#[derive(Clone, Copy, Reflect)] +pub struct Camera3dDepthTextureUsage(u32); + +impl From for Camera3dDepthTextureUsage { + fn from(value: TextureUsages) -> Self { + Self(value.bits()) + } +} +impl From for TextureUsages { + fn from(value: Camera3dDepthTextureUsage) -> Self { + Self::from_bits_truncate(value.0) + } } /// The depth clear operation to perform for the main 3d pass. diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index 8dc51d760ac1c..55e06b86aadb4 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -34,7 +34,6 @@ use bevy_render::{ }, render_resource::{ CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, - TextureUsages, }, renderer::RenderDevice, texture::TextureCache, @@ -259,7 +258,7 @@ pub fn prepare_core_3d_depth_textures( msaa: Res, render_device: Res, views_3d: Query< - (Entity, &ExtractedCamera), + (Entity, &ExtractedCamera, &Camera3d), ( With>, With>, @@ -268,7 +267,7 @@ pub fn prepare_core_3d_depth_textures( >, ) { let mut textures = HashMap::default(); - for (entity, camera) in &views_3d { + for (entity, camera, camera_3d) in &views_3d { if let Some(physical_target_size) = camera.physical_target_size { let cached_texture = textures .entry(camera.target.clone()) @@ -287,7 +286,7 @@ pub fn prepare_core_3d_depth_textures( dimension: TextureDimension::D2, format: TextureFormat::Depth32Float, /* PERF: vulkan docs recommend using 24 * bit depth for better performance */ - usage: TextureUsages::RENDER_ATTACHMENT, + usage: camera_3d.depth_texture_usages.into(), }, ) }) From 2a62c97058d680200b4d5db18b9ccc41e6235387 Mon Sep 17 00:00:00 2001 From: Zhixing Zhang Date: Tue, 31 Jan 2023 23:34:50 -0800 Subject: [PATCH 2/5] fixes --- crates/bevy_core_pipeline/src/core_3d/camera_3d.rs | 2 +- crates/bevy_core_pipeline/src/core_3d/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs index 4329a9bb4b3ee..49bd25ec67540 100644 --- a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs +++ b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs @@ -12,7 +12,7 @@ use bevy_transform::prelude::{GlobalTransform, Transform}; use serde::{Deserialize, Serialize}; /// Configuration for the "main 3d render graph". -#[derive(Component, Reflect, Clone, Default, ExtractComponent)] +#[derive(Component, Reflect, Clone, ExtractComponent)] #[extract_component_filter(With)] #[reflect(Component)] pub struct Camera3d { diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index 357a1ccb809b9..a196a7e782712 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -34,7 +34,7 @@ use bevy_render::{ RenderPhase, }, render_resource::{ - CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, + CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages }, renderer::RenderDevice, texture::TextureCache, From 1a2ac99ef1a1afd714df771f9e3288c91ae76fd0 Mon Sep 17 00:00:00 2001 From: Zhixing Zhang Date: Wed, 1 Feb 2023 00:12:08 -0800 Subject: [PATCH 3/5] Update mod.rs --- crates/bevy_core_pipeline/src/core_3d/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index a196a7e782712..c64f4920bed70 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -34,7 +34,8 @@ use bevy_render::{ RenderPhase, }, render_resource::{ - CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages + CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, + TextureUsages }, renderer::RenderDevice, texture::TextureCache, From b2a4d77eda9e653d3a022c141e9d94aff351812c Mon Sep 17 00:00:00 2001 From: Zhixing Zhang Date: Tue, 14 Feb 2023 16:14:47 -0800 Subject: [PATCH 4/5] Update mod.rs --- crates/bevy_core_pipeline/src/core_3d/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index c64f4920bed70..85deac591b754 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -35,7 +35,7 @@ use bevy_render::{ }, render_resource::{ CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, - TextureUsages + TextureUsages, }, renderer::RenderDevice, texture::TextureCache, From 23221356aae1b380d1e7777ed89cd2dc7c3676ed Mon Sep 17 00:00:00 2001 From: Zhixing Zhang Date: Thu, 4 May 2023 16:19:42 -0700 Subject: [PATCH 5/5] Fix depth prepass --- crates/bevy_core_pipeline/src/core_3d/camera_3d.rs | 2 +- crates/bevy_core_pipeline/src/core_3d/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs index d57ef37fd7b88..e7c7b65c22a4c 100644 --- a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs +++ b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs @@ -8,7 +8,7 @@ use bevy_render::{ camera::{Camera, CameraRenderGraph, Projection}, extract_component::ExtractComponent, primitives::Frustum, - render_resource::LoadOp, + render_resource::{LoadOp, TextureUsages}, view::{ColorGrading, VisibleEntities}, }; use bevy_transform::prelude::{GlobalTransform, Transform}; diff --git a/crates/bevy_core_pipeline/src/core_3d/mod.rs b/crates/bevy_core_pipeline/src/core_3d/mod.rs index 341b597201a9b..91b7f529e19b2 100644 --- a/crates/bevy_core_pipeline/src/core_3d/mod.rs +++ b/crates/bevy_core_pipeline/src/core_3d/mod.rs @@ -275,7 +275,7 @@ pub fn prepare_core_3d_depth_textures( .entry(camera.target.clone()) .or_insert_with(|| { // Default usage required to write to the depth texture - let mut usage = TextureUsages::RENDER_ATTACHMENT; + let mut usage = camera_3d.depth_texture_usages.into(); if depth_prepass.is_some() { // Required to read the output of the prepass usage |= TextureUsages::COPY_SRC; @@ -296,7 +296,7 @@ pub fn prepare_core_3d_depth_textures( dimension: TextureDimension::D2, // PERF: vulkan docs recommend using 24 bit depth for better performance format: TextureFormat::Depth32Float, - usage: camera_3d.depth_texture_usages.into(), + usage, view_formats: &[], };