Skip to content

Commit c1934dc

Browse files
authored
RenderPassDescriptor: make label lifetime match doc, and make names descriptive. (#2654)
Lifetime names like `<'a, 'b>` mean that the reader must look at how they are used to understand them. By changing them to `'tex` (lifetime of borrows of the texture views the documentation describes) and `'desc` (everything else), and mentioning them in the documentation, it's more obvious which role each one plays. For consistency, I also changed `begin_render_pass()`, `RenderPassColorAttachment`, and `RenderPassDepthStencilAttachment` to use matching lifetime names. Also, this made it clear that the `Label` had the wrong lifetime -- the docs say that the texture views have a different lifetime from “everything else”, but the `Label` in fact had the same lifetime as the texture views, so I changed it to the `'desc` (formerly `'b`) lifetime. (On review of change history, this mismatch was previously introduced in commit 632f828.) This change is definitely safe because I followed the data flow down to `BasePass::new` which promptly calls `to_string()` on the label, thus converting it to owned data.
1 parent ddf1903 commit c1934dc

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

wgpu/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,11 +1170,11 @@ impl<V: Default> Default for Operations<V> {
11701170
/// Corresponds to [WebGPU `GPURenderPassColorAttachment`](
11711171
/// https://gpuweb.github.io/gpuweb/#color-attachments).
11721172
#[derive(Clone, Debug)]
1173-
pub struct RenderPassColorAttachment<'a> {
1173+
pub struct RenderPassColorAttachment<'tex> {
11741174
/// The view to use as an attachment.
1175-
pub view: &'a TextureView,
1175+
pub view: &'tex TextureView,
11761176
/// The view that will receive the resolved output if multisampling is used.
1177-
pub resolve_target: Option<&'a TextureView>,
1177+
pub resolve_target: Option<&'tex TextureView>,
11781178
/// What operations will be performed on this color attachment.
11791179
pub ops: Operations<Color>,
11801180
}
@@ -1186,9 +1186,9 @@ pub struct RenderPassColorAttachment<'a> {
11861186
/// Corresponds to [WebGPU `GPURenderPassDepthStencilAttachment`](
11871187
/// https://gpuweb.github.io/gpuweb/#depth-stencil-attachments).
11881188
#[derive(Clone, Debug)]
1189-
pub struct RenderPassDepthStencilAttachment<'a> {
1189+
pub struct RenderPassDepthStencilAttachment<'tex> {
11901190
/// The view to use as an attachment.
1191-
pub view: &'a TextureView,
1191+
pub view: &'tex TextureView,
11921192
/// What operations will be performed on the depth part of the attachment.
11931193
pub depth_ops: Option<Operations<f32>>,
11941194
/// What operations will be performed on the stencil part of the attachment.
@@ -1389,19 +1389,19 @@ pub struct BindGroupDescriptor<'a> {
13891389
///
13901390
/// For use with [`CommandEncoder::begin_render_pass`].
13911391
///
1392-
/// Note: separate lifetimes are needed because the texture views
1393-
/// have to live as long as the pass is recorded, while everything else doesn't.
1392+
/// Note: separate lifetimes are needed because the texture views (`'tex`)
1393+
/// have to live as long as the pass is recorded, while everything else (`'desc`) doesn't.
13941394
///
13951395
/// Corresponds to [WebGPU `GPURenderPassDescriptor`](
13961396
/// https://gpuweb.github.io/gpuweb/#dictdef-gpurenderpassdescriptor).
13971397
#[derive(Clone, Debug, Default)]
1398-
pub struct RenderPassDescriptor<'a, 'b> {
1398+
pub struct RenderPassDescriptor<'tex, 'desc> {
13991399
/// Debug label of the render pass. This will show up in graphics debuggers for easy identification.
1400-
pub label: Label<'a>,
1400+
pub label: Label<'desc>,
14011401
/// The color attachments of the render pass.
1402-
pub color_attachments: &'b [RenderPassColorAttachment<'a>],
1402+
pub color_attachments: &'desc [RenderPassColorAttachment<'tex>],
14031403
/// The depth and stencil attachment of the render pass, if any.
1404-
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachment<'a>>,
1404+
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachment<'tex>>,
14051405
}
14061406

14071407
/// Describes how the vertex buffer is interpreted.
@@ -2490,10 +2490,10 @@ impl CommandEncoder {
24902490
/// Begins recording of a render pass.
24912491
///
24922492
/// This function returns a [`RenderPass`] object which records a single render pass.
2493-
pub fn begin_render_pass<'a>(
2494-
&'a mut self,
2495-
desc: &RenderPassDescriptor<'a, '_>,
2496-
) -> RenderPass<'a> {
2493+
pub fn begin_render_pass<'pass>(
2494+
&'pass mut self,
2495+
desc: &RenderPassDescriptor<'pass, '_>,
2496+
) -> RenderPass<'pass> {
24972497
let id = self.id.as_ref().unwrap();
24982498
RenderPass {
24992499
id: Context::command_encoder_begin_render_pass(&*self.context, id, desc),

0 commit comments

Comments
 (0)