Skip to content

Commit 42cd641

Browse files
committed
[fix] warnings inside the platform crate.
1 parent 839f327 commit 42cd641

12 files changed

Lines changed: 94 additions & 65 deletions

File tree

crates/lambda-rs-platform/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,3 @@ wgpu-with-vulkan = ["wgpu"]
5454
wgpu-with-metal = ["wgpu", "wgpu/metal"]
5555
wgpu-with-dx12 = ["wgpu", "wgpu/dx12"]
5656
wgpu-with-gl = ["wgpu", "wgpu/webgl"]
57-
58-
[profile.dev]
59-
crate-type = ["cdylib", "rlib"]
60-
incremental = true

crates/lambda-rs-platform/src/shader/naga.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ impl ShaderCompilerBuilder {
2929
}
3030
}
3131

32+
impl Default for ShaderCompilerBuilder {
33+
fn default() -> Self {
34+
return Self::new();
35+
}
36+
}
37+
3238
/// A shader compiler that uses naga to translate shader sources into SPIR-V.
3339
pub struct ShaderCompiler {}
3440

@@ -90,9 +96,11 @@ impl ShaderCompiler {
9096
.validate(&module)
9197
.expect("Failed to validate shader module.");
9298

93-
let mut options = spv::Options::default();
94-
options.lang_version = (1, 5);
95-
options.flags = spv::WriterFlags::empty();
99+
let options = spv::Options {
100+
lang_version: (1, 5),
101+
flags: spv::WriterFlags::empty(),
102+
..Default::default()
103+
};
96104

97105
let pipeline_options = spv::PipelineOptions {
98106
shader_stage: stage,

crates/lambda-rs-platform/src/wgpu/bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod tests {
111111
multisampled,
112112
} => {
113113
assert_eq!(view_dimension, wgpu::TextureViewDimension::D2);
114-
assert_eq!(multisampled, false);
114+
assert!(!multisampled);
115115
match sample_type {
116116
wgpu::TextureSampleType::Float { filterable } => assert!(filterable),
117117
_ => panic!("expected float sample type"),

crates/lambda-rs-platform/src/wgpu/gpu.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl GpuBuilder {
124124
///
125125
/// Returns an error if no adapter is available, required features are
126126
/// missing, or device creation fails.
127-
pub fn build<'surface, 'window>(
127+
pub fn build<'surface>(
128128
self,
129129
instance: &Instance,
130130
surface: Option<&Surface<'surface>>,
@@ -160,12 +160,17 @@ impl GpuBuilder {
160160
adapter,
161161
device,
162162
queue,
163-
features: descriptor.required_features,
164163
limits: descriptor.required_limits,
165164
});
166165
}
167166
}
168167

168+
impl Default for GpuBuilder {
169+
fn default() -> Self {
170+
return Self::new();
171+
}
172+
}
173+
169174
/// Errors emitted while building a `Gpu`.
170175
#[derive(Debug)]
171176
pub enum GpuBuildError {
@@ -187,13 +192,12 @@ impl From<wgpu::RequestDeviceError> for GpuBuildError {
187192
}
188193

189194
/// Holds the chosen adapter along with its logical device and submission queue
190-
/// plus immutable copies of features and limits used to create the device.
195+
/// plus an immutable copy of the limits used to create the device.
191196
#[derive(Debug)]
192197
pub struct Gpu {
193198
adapter: wgpu::Adapter,
194199
device: wgpu::Device,
195200
queue: wgpu::Queue,
196-
features: wgpu::Features,
197201
limits: wgpu::Limits,
198202
}
199203

@@ -237,11 +241,6 @@ impl Gpu {
237241
&self.queue
238242
}
239243

240-
/// Features that were required and enabled during device creation.
241-
pub(crate) fn features(&self) -> wgpu::Features {
242-
self.features
243-
}
244-
245244
/// Limits captured at device creation time.
246245
pub fn limits(&self) -> GpuLimits {
247246
return GpuLimits {
@@ -307,7 +306,6 @@ mod tests {
307306
use super::*;
308307
use crate::wgpu::{
309308
instance,
310-
surface,
311309
texture,
312310
};
313311

crates/lambda-rs-platform/src/wgpu/instance.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ impl InstanceBuilder {
176176
}
177177
}
178178

179+
impl Default for InstanceBuilder {
180+
fn default() -> Self {
181+
return Self::new();
182+
}
183+
}
184+
179185
#[derive(Debug)]
180186
/// Thin wrapper over `wgpu::Instance` that preserves a user label and exposes
181187
/// a blocking `request_adapter` convenience.

crates/lambda-rs-platform/src/wgpu/pipeline.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ impl ShaderModule {
206206
pub fn raw(&self) -> &wgpu::ShaderModule {
207207
&self.raw
208208
}
209+
210+
/// Optional debug label used during creation.
211+
pub fn label(&self) -> Option<&str> {
212+
return self.label.as_deref();
213+
}
209214
}
210215

211216
/// Wrapper around `wgpu::PipelineLayout`.
@@ -220,6 +225,11 @@ impl PipelineLayout {
220225
pub fn raw(&self) -> &wgpu::PipelineLayout {
221226
return &self.raw;
222227
}
228+
229+
/// Optional debug label used during creation.
230+
pub fn label(&self) -> Option<&str> {
231+
return self.label.as_deref();
232+
}
223233
}
224234

225235
/// Builder for creating a `PipelineLayout`.
@@ -229,6 +239,12 @@ pub struct PipelineLayoutBuilder<'a> {
229239
immediate_data_ranges: Vec<ImmediateDataRange>,
230240
}
231241

242+
impl<'a> Default for PipelineLayoutBuilder<'a> {
243+
fn default() -> Self {
244+
return Self::new();
245+
}
246+
}
247+
232248
/// Align a `u32` value up to the provided power-of-two alignment.
233249
fn align_up_u32(value: u32, alignment: u32) -> u32 {
234250
if alignment == 0 {
@@ -459,10 +475,6 @@ impl RenderPipeline {
459475
pub(crate) fn raw(&self) -> &wgpu::RenderPipeline {
460476
return &self.raw;
461477
}
462-
/// Consume and return the raw pipeline.
463-
pub(crate) fn into_raw(self) -> wgpu::RenderPipeline {
464-
return self.raw;
465-
}
466478
/// Pipeline label if provided.
467479
pub fn label(&self) -> Option<&str> {
468480
return self.label.as_deref();
@@ -480,6 +492,12 @@ pub struct RenderPipelineBuilder<'a> {
480492
sample_count: u32,
481493
}
482494

495+
impl<'a> Default for RenderPipelineBuilder<'a> {
496+
fn default() -> Self {
497+
return Self::new();
498+
}
499+
}
500+
483501
impl<'a> RenderPipelineBuilder<'a> {
484502
/// New builder with defaults.
485503
pub fn new() -> Self {

crates/lambda-rs-platform/src/wgpu/render_pass.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ pub struct RenderPass<'a> {
115115
pub(super) raw: wgpu::RenderPass<'a>,
116116
}
117117

118-
#[derive(Debug)]
119-
struct RenderPassKeepAlive<'a> {
120-
color_attachments: [Option<wgpu::RenderPassColorAttachment<'a>>; 1],
121-
label: Option<String>,
122-
}
123-
124118
impl<'a> RenderPass<'a> {
125119
/// Set the active render pipeline.
126120
pub fn set_pipeline(&mut self, pipeline: &pipeline::RenderPipeline) {
@@ -254,10 +248,8 @@ impl<'a> RenderColorAttachments<'a> {
254248
&mut self,
255249
operations: wgpu::Operations<wgpu::Color>,
256250
) {
257-
for attachment in &mut self.attachments {
258-
if let Some(ref mut a) = attachment {
259-
a.ops = operations;
260-
}
251+
for a in self.attachments.iter_mut().flatten() {
252+
a.ops = operations;
261253
}
262254
}
263255

crates/lambda-rs-platform/src/wgpu/surface.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,6 @@ impl SurfaceConfig {
8484
.collect(),
8585
};
8686
}
87-
88-
pub(crate) fn to_wgpu(&self) -> wgpu::SurfaceConfiguration {
89-
let mut view_formats: Vec<wgpu::TextureFormat> = Vec::new();
90-
for vf in &self.view_formats {
91-
view_formats.push(vf.to_wgpu());
92-
}
93-
return wgpu::SurfaceConfiguration {
94-
usage: self.usage.to_wgpu(),
95-
format: self.format.to_wgpu(),
96-
width: self.width,
97-
height: self.height,
98-
present_mode: self.present_mode.to_wgpu(),
99-
desired_maximum_frame_latency: 2,
100-
alpha_mode: wgpu::CompositeAlphaMode::Opaque,
101-
view_formats,
102-
};
103-
}
10487
}
10588

10689
/// Error wrapper for surface acquisition and presentation errors.
@@ -154,10 +137,10 @@ impl SurfaceBuilder {
154137
/// Safety: we use `create_surface_unsafe` by forwarding raw window/display
155138
/// handles from `winit`. Lambda guarantees the window outlives the surface
156139
/// for the duration of the runtime.
157-
pub fn build<'window>(
140+
pub fn build(
158141
self,
159142
instance: &Instance,
160-
window: &'window WindowHandle,
143+
window: &WindowHandle,
161144
) -> Result<Surface<'static>, CreateSurfaceError> {
162145
// SAFETY: We ensure the raw window/display handles outlive the surface by
163146
// keeping the window alive for the duration of the application runtime.
@@ -192,6 +175,12 @@ impl SurfaceBuilder {
192175
}
193176
}
194177

178+
impl Default for SurfaceBuilder {
179+
fn default() -> Self {
180+
return Self::new();
181+
}
182+
}
183+
195184
/// Opaque error returned when surface creation fails.
196185
#[derive(Debug)]
197186
pub struct CreateSurfaceError;
@@ -351,11 +340,6 @@ impl Frame {
351340
return TextureViewRef { raw: &self.view };
352341
}
353342

354-
/// Consume and return the underlying parts.
355-
pub(crate) fn into_parts(self) -> (wgpu::SurfaceTexture, wgpu::TextureView) {
356-
return (self.texture, self.view);
357-
}
358-
359343
/// Present the frame to the swapchain.
360344
pub fn present(self) {
361345
self.texture.present();

crates/lambda-rs-platform/src/wgpu/texture.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ impl DepthTexture {
253253
return self.format;
254254
}
255255

256+
/// Optional debug label used during creation.
257+
pub fn label(&self) -> Option<&str> {
258+
return self.label.as_deref();
259+
}
260+
256261
/// Convenience: return a `TextureViewRef` for use in render pass attachments.
257262
pub fn view_ref(&self) -> crate::wgpu::surface::TextureViewRef<'_> {
258263
return crate::wgpu::surface::TextureViewRef { raw: &self.view };
@@ -278,6 +283,11 @@ impl ColorAttachmentTexture {
278283
return &self.view;
279284
}
280285

286+
/// Optional debug label used during creation.
287+
pub fn label(&self) -> Option<&str> {
288+
return self.label.as_deref();
289+
}
290+
281291
/// Convenience: return a `TextureViewRef` for use in render pass attachments.
282292
pub fn view_ref(&self) -> crate::wgpu::surface::TextureViewRef<'_> {
283293
return crate::wgpu::surface::TextureViewRef { raw: &self.view };
@@ -371,6 +381,12 @@ pub struct DepthTextureBuilder {
371381
sample_count: u32,
372382
}
373383

384+
impl Default for DepthTextureBuilder {
385+
fn default() -> Self {
386+
return Self::new();
387+
}
388+
}
389+
374390
impl DepthTextureBuilder {
375391
/// Create a builder with no size and `Depth32Float` format.
376392
pub fn new() -> Self {
@@ -514,6 +530,12 @@ pub struct SamplerBuilder {
514530
lod_max: f32,
515531
}
516532

533+
impl Default for SamplerBuilder {
534+
fn default() -> Self {
535+
return Self::new();
536+
}
537+
}
538+
517539
impl SamplerBuilder {
518540
/// Create a new builder with nearest filtering and clamp addressing.
519541
pub fn new() -> Self {

crates/lambda-rs-platform/src/wgpu/vertex.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ pub enum ColorFormat {
1212
}
1313

1414
impl ColorFormat {
15-
pub(crate) fn to_texture_format(self) -> wgpu::TextureFormat {
16-
return match self {
17-
ColorFormat::Rgb32Sfloat => wgpu::TextureFormat::Rgba32Float,
18-
ColorFormat::Rgba8Srgb => wgpu::TextureFormat::Rgba8UnormSrgb,
19-
};
20-
}
21-
2215
pub(crate) fn to_vertex_format(self) -> wgpu::VertexFormat {
2316
return match self {
2417
ColorFormat::Rgb32Sfloat => wgpu::VertexFormat::Float32x3,

0 commit comments

Comments
 (0)