Support optional clear color in ColorAttachment. (#11884)
This represents when the user has configured `ClearColorConfig::None` in their application. If the clear color is `None`, we will always `Load` instead of attempting to clear the attachment on the first call. Fixes #11883.
This commit is contained in:
parent
149d48f586
commit
9505f6e6a9
@ -836,16 +836,18 @@ pub fn prepare_prepass_textures(
|
|||||||
});
|
});
|
||||||
|
|
||||||
commands.entity(entity).insert(ViewPrepassTextures {
|
commands.entity(entity).insert(ViewPrepassTextures {
|
||||||
depth: cached_depth_texture.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
|
depth: cached_depth_texture.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
|
||||||
normal: cached_normals_texture.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
|
normal: cached_normals_texture
|
||||||
|
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
|
||||||
// Red and Green channels are X and Y components of the motion vectors
|
// Red and Green channels are X and Y components of the motion vectors
|
||||||
// Blue channel doesn't matter, but set to 0.0 for possible faster clear
|
// Blue channel doesn't matter, but set to 0.0 for possible faster clear
|
||||||
// https://gpuopen.com/performance/#clears
|
// https://gpuopen.com/performance/#clears
|
||||||
motion_vectors: cached_motion_vectors_texture
|
motion_vectors: cached_motion_vectors_texture
|
||||||
.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
|
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
|
||||||
deferred: cached_deferred_texture.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
|
deferred: cached_deferred_texture
|
||||||
|
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
|
||||||
deferred_lighting_pass_id: cached_deferred_lighting_pass_id_texture
|
deferred_lighting_pass_id: cached_deferred_lighting_pass_id_texture
|
||||||
.map(|t| ColorAttachment::new(t, None, Color::BLACK)),
|
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
|
||||||
size,
|
size,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use wgpu::{
|
|||||||
pub struct ColorAttachment {
|
pub struct ColorAttachment {
|
||||||
pub texture: CachedTexture,
|
pub texture: CachedTexture,
|
||||||
pub resolve_target: Option<CachedTexture>,
|
pub resolve_target: Option<CachedTexture>,
|
||||||
clear_color: Color,
|
clear_color: Option<Color>,
|
||||||
is_first_call: Arc<AtomicBool>,
|
is_first_call: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ impl ColorAttachment {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
texture: CachedTexture,
|
texture: CachedTexture,
|
||||||
resolve_target: Option<CachedTexture>,
|
resolve_target: Option<CachedTexture>,
|
||||||
clear_color: Color,
|
clear_color: Option<Color>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
texture,
|
texture,
|
||||||
@ -43,10 +43,9 @@ impl ColorAttachment {
|
|||||||
view: &resolve_target.default_view,
|
view: &resolve_target.default_view,
|
||||||
resolve_target: Some(&self.texture.default_view),
|
resolve_target: Some(&self.texture.default_view),
|
||||||
ops: Operations {
|
ops: Operations {
|
||||||
load: if first_call {
|
load: match (self.clear_color, first_call) {
|
||||||
LoadOp::Clear(self.clear_color.into())
|
(Some(clear_color), true) => LoadOp::Clear(clear_color.into()),
|
||||||
} else {
|
(None, _) | (Some(_), false) => LoadOp::Load,
|
||||||
LoadOp::Load
|
|
||||||
},
|
},
|
||||||
store: StoreOp::Store,
|
store: StoreOp::Store,
|
||||||
},
|
},
|
||||||
@ -67,10 +66,9 @@ impl ColorAttachment {
|
|||||||
view: &self.texture.default_view,
|
view: &self.texture.default_view,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: Operations {
|
ops: Operations {
|
||||||
load: if first_call {
|
load: match (self.clear_color, first_call) {
|
||||||
LoadOp::Clear(self.clear_color.into())
|
(Some(clear_color), true) => LoadOp::Clear(clear_color.into()),
|
||||||
} else {
|
(None, _) | (Some(_), false) => LoadOp::Load,
|
||||||
LoadOp::Load
|
|
||||||
},
|
},
|
||||||
store: StoreOp::Store,
|
store: StoreOp::Store,
|
||||||
},
|
},
|
||||||
|
@ -493,8 +493,9 @@ pub fn prepare_view_targets(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let clear_color = match camera.clear_color {
|
let clear_color = match camera.clear_color {
|
||||||
ClearColorConfig::Custom(color) => color,
|
ClearColorConfig::Custom(color) => Some(color),
|
||||||
_ => clear_color_global.0,
|
ClearColorConfig::None => None,
|
||||||
|
_ => Some(clear_color_global.0),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (a, b, sampled) = textures
|
let (a, b, sampled) = textures
|
||||||
|
Loading…
Reference in New Issue
Block a user