Skip to content

Commit d434c3e

Browse files
committed
[fix] render warnings.
1 parent c840f0f commit d434c3e

16 files changed

Lines changed: 117 additions & 96 deletions

File tree

crates/lambda-rs/src/render/bind.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ pub struct BindGroupLayoutBuilder {
135135
samplers: Vec<(u32, BindingVisibility)>,
136136
}
137137

138+
impl Default for BindGroupLayoutBuilder {
139+
fn default() -> Self {
140+
return Self::new();
141+
}
142+
}
143+
138144
impl BindGroupLayoutBuilder {
139145
/// Create a new builder with no bindings.
140146
pub fn new() -> Self {
@@ -300,6 +306,12 @@ pub struct BindGroupBuilder<'a> {
300306
samplers: Vec<(u32, Rc<lambda_platform::wgpu::texture::Sampler>)>,
301307
}
302308

309+
impl<'a> Default for BindGroupBuilder<'a> {
310+
fn default() -> Self {
311+
return Self::new();
312+
}
313+
}
314+
303315
impl<'a> BindGroupBuilder<'a> {
304316
/// Create a new builder with no layout.
305317
pub fn new() -> Self {

crates/lambda-rs/src/render/buffer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use lambda_platform::wgpu::buffer as platform_buffer;
2525
use super::{
2626
gpu::Gpu,
2727
mesh::Mesh,
28-
vertex::Vertex,
2928
RenderContext,
3029
};
3130

@@ -237,6 +236,12 @@ pub struct BufferBuilder {
237236
label: Option<String>,
238237
}
239238

239+
impl Default for BufferBuilder {
240+
fn default() -> Self {
241+
return Self::new();
242+
}
243+
}
244+
240245
impl BufferBuilder {
241246
/// Creates a new buffer builder of type vertex.
242247
pub fn new() -> Self {
@@ -324,7 +329,7 @@ impl BufferBuilder {
324329
) -> Result<Buffer, &'static str> {
325330
let builder = Self::new();
326331
return builder
327-
.with_length(mesh.vertices().len() * std::mem::size_of::<Vertex>())
332+
.with_length(std::mem::size_of_val(mesh.vertices()))
328333
.with_usage(Usage::VERTEX)
329334
.with_properties(Properties::CPU_VISIBLE)
330335
.with_buffer_type(BufferType::Vertex)

crates/lambda-rs/src/render/encoder.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use super::{
4444
},
4545
color_attachments::RenderColorAttachments,
4646
command::IndexFormat,
47-
pipeline,
4847
pipeline::RenderPipeline,
4948
render_pass::RenderPass,
5049
texture::{
@@ -211,9 +210,6 @@ pub struct RenderPassEncoder<'pass> {
211210
#[derive(Clone)]
212211
struct CurrentPipeline {
213212
label: String,
214-
has_color_targets: bool,
215-
expects_depth_stencil: bool,
216-
uses_stencil: bool,
217213
per_instance_slots: Vec<bool>,
218214
}
219215

@@ -374,10 +370,7 @@ impl<'pass> RenderPassEncoder<'pass> {
374370
{
375371
let label = pipeline.pipeline().label().unwrap_or("unnamed").to_string();
376372
self.current_pipeline = Some(CurrentPipeline {
377-
label: label.clone(),
378-
has_color_targets: pipeline.has_color_targets(),
379-
expects_depth_stencil: pipeline.expects_depth_stencil(),
380-
uses_stencil: pipeline.uses_stencil(),
373+
label,
381374
per_instance_slots: pipeline.per_instance_slots().clone(),
382375
});
383376
}
@@ -517,7 +510,7 @@ impl<'pass> RenderPassEncoder<'pass> {
517510
}
518511

519512
let buffer_size = buffer.raw().size();
520-
if buffer_size % element_size != 0 {
513+
if !buffer_size.is_multiple_of(element_size) {
521514
return Err(RenderPassError::Validation(format!(
522515
"Index buffer size {} bytes is not a multiple of element size {} \
523516
for format {:?}",

crates/lambda-rs/src/render/mesh.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ pub struct MeshBuilder {
4747
attributes: Vec<VertexAttribute>,
4848
}
4949

50+
impl Default for MeshBuilder {
51+
fn default() -> Self {
52+
return Self::new();
53+
}
54+
}
55+
5056
impl MeshBuilder {
5157
/// Creates a new mesh builder.
5258
pub fn new() -> Self {

crates/lambda-rs/src/render/mod.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl RenderContextBuilder {
219219
/// reconfiguration with preserved present mode and usage.
220220
pub struct RenderContext {
221221
label: String,
222+
#[allow(dead_code)]
222223
instance: instance::Instance,
223224
surface: targets::surface::WindowSurface,
224225
gpu: gpu::Gpu,
@@ -243,6 +244,11 @@ pub struct RenderContext {
243244
pub type ResourceId = usize;
244245

245246
impl RenderContext {
247+
/// Optional label assigned when constructing the context.
248+
pub fn label(&self) -> &str {
249+
return self.label.as_str();
250+
}
251+
246252
/// Current surface size in pixels.
247253
///
248254
/// This reflects the most recent configured surface dimensions and is used
@@ -428,25 +434,6 @@ impl RenderContext {
428434
return self.depth_format;
429435
}
430436

431-
pub(crate) fn supports_surface_sample_count(
432-
&self,
433-
sample_count: u32,
434-
) -> bool {
435-
return self
436-
.gpu
437-
.supports_sample_count_for_format(self.config.format, sample_count);
438-
}
439-
440-
pub(crate) fn supports_depth_sample_count(
441-
&self,
442-
format: texture::DepthFormat,
443-
sample_count: u32,
444-
) -> bool {
445-
return self
446-
.gpu
447-
.supports_sample_count_for_depth(format, sample_count);
448-
}
449-
450437
/// Device limit: maximum bytes that can be bound for a single uniform buffer binding.
451438
pub fn limit_max_uniform_buffer_binding_size(&self) -> u64 {
452439
return self.gpu.limit_max_uniform_buffer_binding_size();
@@ -519,10 +506,7 @@ impl RenderContext {
519506
targets::surface::SurfaceError::Lost
520507
| targets::surface::SurfaceError::Outdated => {
521508
self.reconfigure_surface(self.size)?;
522-
self
523-
.surface
524-
.acquire_frame()
525-
.map_err(|e| RenderError::Surface(e))?
509+
self.surface.acquire_frame().map_err(RenderError::Surface)?
526510
}
527511
_ => return Err(RenderError::Surface(err)),
528512
},
@@ -836,14 +820,14 @@ impl RenderContext {
836820
command_iter: &mut std::vec::IntoIter<RenderCommand>,
837821
rp_encoder: &mut encoder::RenderPassEncoder<'_>,
838822
initial_viewport: &viewport::Viewport,
839-
render_pipelines: &Vec<RenderPipeline>,
840-
bind_groups: &Vec<bind::BindGroup>,
841-
buffers: &Vec<Rc<buffer::Buffer>>,
823+
render_pipelines: &[RenderPipeline],
824+
bind_groups: &[bind::BindGroup],
825+
buffers: &[Rc<buffer::Buffer>],
842826
min_uniform_buffer_offset_alignment: u32,
843827
) -> Result<(), RenderPassError> {
844828
rp_encoder.set_viewport(initial_viewport);
845829

846-
while let Some(cmd) = command_iter.next() {
830+
for cmd in command_iter.by_ref() {
847831
match cmd {
848832
RenderCommand::EndRenderPass => return Ok(()),
849833
RenderCommand::SetStencilReference { reference } => {
@@ -896,7 +880,7 @@ impl RenderContext {
896880
"Vertex buffer index {buffer} not found for pipeline {pipeline}"
897881
))
898882
})?;
899-
rp_encoder.set_vertex_buffer(buffer as u32, buffer_ref);
883+
rp_encoder.set_vertex_buffer(buffer, buffer_ref);
900884
}
901885
RenderCommand::BindIndexBuffer { buffer, format } => {
902886
let buffer_ref = buffers.get(buffer).ok_or_else(|| {

crates/lambda-rs/src/render/pipeline.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ pub struct RenderPipelineBuilder {
270270
depth_write_enabled: Option<bool>,
271271
}
272272

273+
impl Default for RenderPipelineBuilder {
274+
fn default() -> Self {
275+
return Self::new();
276+
}
277+
}
278+
273279
impl RenderPipelineBuilder {
274280
/// Creates a new render pipeline builder.
275281
pub fn new() -> Self {

crates/lambda-rs/src/render/render_pass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl DepthOperations {
135135
/// The pass defines the initial clear for the color attachment and an optional
136136
/// label. Depth/stencil may be added in a future iteration.
137137
pub struct RenderPass {
138-
clear_color: [f64; 4],
139138
label: Option<String>,
140139
color_operations: ColorOperations,
141140
depth_operations: Option<DepthOperations>,
@@ -148,10 +147,6 @@ impl RenderPass {
148147
/// Destroy the pass. Kept for symmetry with other resources.
149148
pub fn destroy(self, _gpu: &Gpu) {}
150149

151-
pub(crate) fn clear_color(&self) -> [f64; 4] {
152-
return self.clear_color;
153-
}
154-
155150
pub(crate) fn label(&self) -> Option<&str> {
156151
self.label.as_deref()
157152
}
@@ -193,6 +188,12 @@ pub struct RenderPassBuilder {
193188
use_color: bool,
194189
}
195190

191+
impl Default for RenderPassBuilder {
192+
fn default() -> Self {
193+
return Self::new();
194+
}
195+
}
196+
196197
impl RenderPassBuilder {
197198
/// Creates a new render pass builder.
198199
pub fn new() -> Self {
@@ -356,7 +357,6 @@ impl RenderPassBuilder {
356357
);
357358

358359
return RenderPass {
359-
clear_color: self.clear_color,
360360
label: self.label,
361361
color_operations: self.color_operations,
362362
depth_operations: self.depth_operations,

crates/lambda-rs/src/render/scene_math.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub fn compute_model_view_projection_matrix(
192192

193193
/// Compute a full model-view-projection matrix for a rotation around a specific
194194
/// local-space pivot point.
195+
#[allow(clippy::too_many_arguments)]
195196
pub fn compute_model_view_projection_matrix_about_pivot(
196197
camera: &SimpleCamera,
197198
viewport_width: u32,
@@ -246,20 +247,12 @@ mod tests {
246247
let mut expected: [[f32; 4]; 4] = m::identity_matrix(4, 4);
247248
expected = m::rotate_matrix(expected, axis, angle_in_turns);
248249

249-
let mut s: [[f32; 4]; 4] = [[0.0; 4]; 4];
250-
for i in 0..4 {
251-
for j in 0..4 {
252-
s[i][j] = if i == j {
253-
if i == 3 {
254-
1.0
255-
} else {
256-
scale
257-
}
258-
} else {
259-
0.0
260-
};
261-
}
262-
}
250+
let s: [[f32; 4]; 4] = [
251+
[scale, 0.0, 0.0, 0.0],
252+
[0.0, scale, 0.0, 0.0],
253+
[0.0, 0.0, scale, 0.0],
254+
[0.0, 0.0, 0.0, 1.0],
255+
];
263256
expected = expected.multiply(&s);
264257

265258
let t: [[f32; 4]; 4] = m::translation_matrix(translation);

crates/lambda-rs/src/render/shader.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ pub struct ShaderBuilder {
3535
compiler: ShaderCompiler,
3636
}
3737

38+
impl Default for ShaderBuilder {
39+
fn default() -> Self {
40+
return Self::new();
41+
}
42+
}
43+
3844
impl ShaderBuilder {
3945
/// Creates a new shader builder that can be reused for compiling shaders.
4046
pub fn new() -> Self {
@@ -78,4 +84,9 @@ impl Shader {
7884
pub fn as_binary(&self) -> Vec<u32> {
7985
return self.binary.clone();
8086
}
87+
88+
/// Borrow the `VirtualShader` used to compile this shader.
89+
pub fn virtual_shader(&self) -> &VirtualShader {
90+
return &self.virtual_shader;
91+
}
8192
}

crates/lambda-rs/src/render/targets/offscreen.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ impl OffscreenTarget {
6060
}
6161

6262
/// Access the multi-sampled color attachment used for rendering.
63-
pub(crate) fn msaa_color_texture(
64-
&self,
65-
) -> Option<&texture::ColorAttachmentTexture> {
63+
pub fn msaa_color_texture(&self) -> Option<&texture::ColorAttachmentTexture> {
6664
return self.msaa_color.as_ref();
6765
}
6866

@@ -75,7 +73,7 @@ impl OffscreenTarget {
7573
}
7674

7775
/// Optional debug label assigned at creation time.
78-
pub(crate) fn label(&self) -> Option<&str> {
76+
pub fn label(&self) -> Option<&str> {
7977
return self.label.as_deref();
8078
}
8179

@@ -141,6 +139,12 @@ pub struct OffscreenTargetBuilder {
141139
sample_count: u32,
142140
}
143141

142+
impl Default for OffscreenTargetBuilder {
143+
fn default() -> Self {
144+
return Self::new();
145+
}
146+
}
147+
144148
impl OffscreenTargetBuilder {
145149
/// Create a new builder with no attachments configured.
146150
pub fn new() -> Self {
@@ -198,7 +202,7 @@ impl OffscreenTargetBuilder {
198202
let (width, height) = self.resolve_size()?;
199203

200204
let sample_count = self.sample_count.max(1);
201-
if let Err(_) = validation::validate_sample_count(sample_count) {
205+
if validation::validate_sample_count(sample_count).is_err() {
202206
return Err(OffscreenTargetError::UnsupportedSampleCount {
203207
requested: sample_count,
204208
});

0 commit comments

Comments
 (0)