Skip to content

Commit 6cd6561

Browse files
committed
[naga wgsl-in] Minor cleanup to Lowerer::texture_sample_helper.
Use deferred initialization instead of building tuples, so that match arms can provide values by name, not by position within a tuple.
1 parent f739f8e commit 6cd6561

1 file changed

Lines changed: 43 additions & 30 deletions

File tree

  • naga/src/front/wgsl/lower

naga/src/front/wgsl/lower/mod.rs

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,10 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
32763276
Ok((image, image_span))
32773277
}
32783278

3279-
let (image, image_span, gather) = match fun {
3279+
let image;
3280+
let image_span;
3281+
let gather;
3282+
match fun {
32803283
Texture::Gather => {
32813284
let image_or_component = args.next()?;
32823285
let image_or_component_span = ctx.ast_expressions.get_span(image_or_component);
@@ -3287,33 +3290,29 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
32873290
ir::TypeInner::Image {
32883291
class: ir::ImageClass::Depth { .. },
32893292
..
3290-
} => (
3291-
lowered_image_or_component,
3292-
image_or_component_span,
3293-
Some(ir::SwizzleComponent::X),
3294-
),
3293+
} => {
3294+
image = lowered_image_or_component;
3295+
image_span = image_or_component_span;
3296+
gather = Some(ir::SwizzleComponent::X);
3297+
}
32953298
_ => {
3296-
let (image, image_span) = get_image_and_span(self, &mut args, ctx)?;
3297-
(
3298-
image,
3299-
image_span,
3300-
Some(ctx.gather_component(
3301-
lowered_image_or_component,
3302-
image_or_component_span,
3303-
span,
3304-
)?),
3305-
)
3299+
(image, image_span) = get_image_and_span(self, &mut args, ctx)?;
3300+
gather = Some(ctx.gather_component(
3301+
lowered_image_or_component,
3302+
image_or_component_span,
3303+
span,
3304+
)?);
33063305
}
33073306
}
33083307
}
33093308
Texture::GatherCompare => {
3310-
let (image, image_span) = get_image_and_span(self, &mut args, ctx)?;
3311-
(image, image_span, Some(ir::SwizzleComponent::X))
3309+
(image, image_span) = get_image_and_span(self, &mut args, ctx)?;
3310+
gather = Some(ir::SwizzleComponent::X);
33123311
}
33133312

33143313
_ => {
3315-
let (image, image_span) = get_image_and_span(self, &mut args, ctx)?;
3316-
(image, image_span, None)
3314+
(image, image_span) = get_image_and_span(self, &mut args, ctx)?;
3315+
gather = None;
33173316
}
33183317
};
33193318

@@ -3326,34 +3325,48 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
33263325
.then(|| self.expression(args.next()?, ctx))
33273326
.transpose()?;
33283327

3329-
let (level, depth_ref) = match fun {
3330-
Texture::Gather => (ir::SampleLevel::Zero, None),
3328+
let level;
3329+
let depth_ref;
3330+
match fun {
3331+
Texture::Gather => {
3332+
level = ir::SampleLevel::Zero;
3333+
depth_ref = None;
3334+
}
33313335
Texture::GatherCompare => {
33323336
let reference = self.expression(args.next()?, ctx)?;
3333-
(ir::SampleLevel::Zero, Some(reference))
3337+
level = ir::SampleLevel::Zero;
3338+
depth_ref = Some(reference);
33343339
}
33353340

3336-
Texture::Sample => (ir::SampleLevel::Auto, None),
3341+
Texture::Sample => {
3342+
level = ir::SampleLevel::Auto;
3343+
depth_ref = None;
3344+
}
33373345
Texture::SampleBias => {
33383346
let bias = self.expression(args.next()?, ctx)?;
3339-
(ir::SampleLevel::Bias(bias), None)
3347+
level = ir::SampleLevel::Bias(bias);
3348+
depth_ref = None;
33403349
}
33413350
Texture::SampleCompare => {
33423351
let reference = self.expression(args.next()?, ctx)?;
3343-
(ir::SampleLevel::Auto, Some(reference))
3352+
level = ir::SampleLevel::Auto;
3353+
depth_ref = Some(reference);
33443354
}
33453355
Texture::SampleCompareLevel => {
33463356
let reference = self.expression(args.next()?, ctx)?;
3347-
(ir::SampleLevel::Zero, Some(reference))
3357+
level = ir::SampleLevel::Zero;
3358+
depth_ref = Some(reference);
33483359
}
33493360
Texture::SampleGrad => {
33503361
let x = self.expression(args.next()?, ctx)?;
33513362
let y = self.expression(args.next()?, ctx)?;
3352-
(ir::SampleLevel::Gradient { x, y }, None)
3363+
level = ir::SampleLevel::Gradient { x, y };
3364+
depth_ref = None;
33533365
}
33543366
Texture::SampleLevel => {
3355-
let level = self.expression(args.next()?, ctx)?;
3356-
(ir::SampleLevel::Exact(level), None)
3367+
let exact = self.expression(args.next()?, ctx)?;
3368+
level = ir::SampleLevel::Exact(exact);
3369+
depth_ref = None;
33573370
}
33583371
};
33593372

0 commit comments

Comments
 (0)