Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions crates/lambda-rs-args/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::needless_return)]
#![allow(clippy::items_after_test_module)]
//! # Lambda Args
//! Lambda Args is a simple argument parser for Rust. It is designed to be
//! simple to use and primarily for use in lambda command line applications.
Expand Down Expand Up @@ -72,42 +73,42 @@ pub enum ArgumentValue {
String(String),
}

impl Into<String> for ArgumentValue {
fn into(self) -> String {
return match self {
impl From<ArgumentValue> for String {
fn from(value: ArgumentValue) -> Self {
return match value {
ArgumentValue::String(val) => val,
_ => panic!("Cannot convert {:?} into a String.", self),
other => panic!("Cannot convert {:?} into a String.", other),
};
}
}

impl Into<i64> for ArgumentValue {
fn into(self) -> i64 {
return match self {
impl From<ArgumentValue> for i64 {
fn from(value: ArgumentValue) -> Self {
return match value {
ArgumentValue::Integer(val) => val,
ArgumentValue::Float(val) => val as i64,
ArgumentValue::Double(val) => val as i64,
_ => panic!("Cannot convert {:?} into an i64", self),
other => panic!("Cannot convert {:?} into an i64", other),
};
}
}

impl Into<f32> for ArgumentValue {
fn into(self) -> f32 {
return match self {
impl From<ArgumentValue> for f32 {
fn from(value: ArgumentValue) -> Self {
return match value {
ArgumentValue::Float(val) => val,
_ => panic!("Cannot convert {:?} into a f32", self),
other => panic!("Cannot convert {:?} into a f32", other),
};
}
}

impl Into<f64> for ArgumentValue {
fn into(self) -> f64 {
return match self {
impl From<ArgumentValue> for f64 {
fn from(value: ArgumentValue) -> Self {
return match value {
ArgumentValue::Double(val) => val,
ArgumentValue::Float(val) => val as f64,
ArgumentValue::Integer(val) => val as f64,
_ => panic!("Cannot convert {:?} into a f64", self),
other => panic!("Cannot convert {:?} into a f64", other),
};
}
}
Expand Down Expand Up @@ -194,7 +195,7 @@ impl Argument {
}

pub fn arg_type(&self) -> ArgumentType {
return self.arg_type.clone();
return self.arg_type;
}

/// Canonical name used for matching and display (e.g., `--output`).
Expand Down Expand Up @@ -406,11 +407,12 @@ impl ArgumentParser {
format!(" (aliases: {})", arg.aliases().join(", "))
};
out.push_str(&format!(
" {}{}\n {}{}{}\n",
" {}{}\n {}{}{}{}\n",
arg.name(),
sep,
desc,
format!("{}{}", req, def),
req,
def,
aliases
));
}
Expand Down Expand Up @@ -583,13 +585,13 @@ impl ArgumentParser {
if matches!(pre.0.arg_type(), ArgumentType::Count) {
let index = pre.2;
let current = match &parsed_arguments[index].value {
ArgumentValue::Integer(v) => *v as i64,
ArgumentValue::Integer(v) => *v,
_ => 0,
};
let found = self.args.get_mut(&canon).unwrap();
parsed_arguments[index] = ParsedArgument::new(
found.0.name.as_str(),
ArgumentValue::Integer((current + 1) as i64),
ArgumentValue::Integer(current + 1),
);
found.1 = true;
} else if matches!(pre.0.arg_type(), ArgumentType::Boolean) {
Expand Down Expand Up @@ -619,7 +621,7 @@ impl ArgumentParser {
return Err(ArgsError::UnknownArgument(msg));
};
let pre = self.args.get(&canon_name).unwrap();
if pre.1 == true {
if pre.1 {
return Err(ArgsError::DuplicateArgument(pre.0.name.clone()));
}
// Boolean flags can be set by presence alone
Expand All @@ -636,12 +638,12 @@ impl ArgumentParser {
let index = pre.2;
let found = self.args.get_mut(&canon_name).unwrap();
let current = match &parsed_arguments[index].value {
ArgumentValue::Integer(v) => *v as i64,
ArgumentValue::Integer(v) => *v,
_ => 0,
};
parsed_arguments[index] = ParsedArgument::new(
found.0.name.as_str(),
ArgumentValue::Integer((current + 1) as i64),
ArgumentValue::Integer(current + 1),
);
found.1 = true;
continue;
Expand Down Expand Up @@ -1022,12 +1024,12 @@ mod tests {
Argument::new("--verbose").with_type(ArgumentType::Boolean),
);
let p = parser.parse(&argv(&["--verbose"])).unwrap();
assert_eq!(p.get_bool("--verbose").unwrap(), true);
assert!(p.get_bool("--verbose").unwrap());
let parser2 = ArgumentParser::new("app").with_argument(
Argument::new("--verbose").with_type(ArgumentType::Boolean),
);
let p2 = parser2.parse(&argv(&["--no-verbose"])).unwrap();
assert_eq!(p2.get_bool("--verbose").unwrap(), false);
assert!(!p2.get_bool("--verbose").unwrap());
}

#[test]
Expand Down Expand Up @@ -1279,12 +1281,12 @@ impl ArgumentParser {

fn assign_next_positional(
&mut self,
out: &mut Vec<ParsedArgument>,
out: &mut [ParsedArgument],
value: &str,
) -> Result<(), ArgsError> {
for pname in self.positionals.clone() {
if let Some(entry) = self.args.get_mut(&pname) {
if entry.1 == false {
if !entry.1 {
let parsed = parse_value(&entry.0, value)?;
let idx = entry.2;
out[idx] = ParsedArgument::new(entry.0.name.as_str(), parsed);
Expand All @@ -1300,7 +1302,7 @@ impl ArgumentParser {
})
}

fn get_present(&self, out: &Vec<ParsedArgument>, name: &str) -> bool {
fn get_present(&self, out: &[ParsedArgument], name: &str) -> bool {
let canon = if self.args.contains_key(name) {
name.to_string()
} else if let Some(n) = self.aliases.get(name) {
Expand Down
4 changes: 0 additions & 4 deletions crates/lambda-rs-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,3 @@ wgpu-with-vulkan = ["wgpu"]
wgpu-with-metal = ["wgpu", "wgpu/metal"]
wgpu-with-dx12 = ["wgpu", "wgpu/dx12"]
wgpu-with-gl = ["wgpu", "wgpu/webgl"]

[profile.dev]
crate-type = ["cdylib", "rlib"]
incremental = true
14 changes: 11 additions & 3 deletions crates/lambda-rs-platform/src/shader/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ impl ShaderCompilerBuilder {
}
}

impl Default for ShaderCompilerBuilder {
fn default() -> Self {
return Self::new();
}
}

/// A shader compiler that uses naga to translate shader sources into SPIR-V.
pub struct ShaderCompiler {}

Expand Down Expand Up @@ -90,9 +96,11 @@ impl ShaderCompiler {
.validate(&module)
.expect("Failed to validate shader module.");

let mut options = spv::Options::default();
options.lang_version = (1, 5);
options.flags = spv::WriterFlags::empty();
let options = spv::Options {
lang_version: (1, 5),
flags: spv::WriterFlags::empty(),
..Default::default()
};

let pipeline_options = spv::PipelineOptions {
shader_stage: stage,
Expand Down
2 changes: 1 addition & 1 deletion crates/lambda-rs-platform/src/wgpu/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mod tests {
multisampled,
} => {
assert_eq!(view_dimension, wgpu::TextureViewDimension::D2);
assert_eq!(multisampled, false);
assert!(!multisampled);
match sample_type {
wgpu::TextureSampleType::Float { filterable } => assert!(filterable),
_ => panic!("expected float sample type"),
Expand Down
18 changes: 8 additions & 10 deletions crates/lambda-rs-platform/src/wgpu/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl GpuBuilder {
///
/// Returns an error if no adapter is available, required features are
/// missing, or device creation fails.
pub fn build<'surface, 'window>(
pub fn build<'surface>(
self,
instance: &Instance,
surface: Option<&Surface<'surface>>,
Expand Down Expand Up @@ -160,12 +160,17 @@ impl GpuBuilder {
adapter,
device,
queue,
features: descriptor.required_features,
limits: descriptor.required_limits,
});
}
}

impl Default for GpuBuilder {
fn default() -> Self {
return Self::new();
}
}

/// Errors emitted while building a `Gpu`.
#[derive(Debug)]
pub enum GpuBuildError {
Expand All @@ -187,13 +192,12 @@ impl From<wgpu::RequestDeviceError> for GpuBuildError {
}

/// Holds the chosen adapter along with its logical device and submission queue
/// plus immutable copies of features and limits used to create the device.
/// plus an immutable copy of the limits used to create the device.
#[derive(Debug)]
pub struct Gpu {
adapter: wgpu::Adapter,
device: wgpu::Device,
queue: wgpu::Queue,
features: wgpu::Features,
limits: wgpu::Limits,
}

Expand Down Expand Up @@ -237,11 +241,6 @@ impl Gpu {
&self.queue
}

/// Features that were required and enabled during device creation.
pub(crate) fn features(&self) -> wgpu::Features {
self.features
}

/// Limits captured at device creation time.
pub fn limits(&self) -> GpuLimits {
return GpuLimits {
Expand Down Expand Up @@ -307,7 +306,6 @@ mod tests {
use super::*;
use crate::wgpu::{
instance,
surface,
texture,
};

Expand Down
6 changes: 6 additions & 0 deletions crates/lambda-rs-platform/src/wgpu/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ impl InstanceBuilder {
}
}

impl Default for InstanceBuilder {
fn default() -> Self {
return Self::new();
}
}

#[derive(Debug)]
/// Thin wrapper over `wgpu::Instance` that preserves a user label and exposes
/// a blocking `request_adapter` convenience.
Expand Down
26 changes: 22 additions & 4 deletions crates/lambda-rs-platform/src/wgpu/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ impl ShaderModule {
pub fn raw(&self) -> &wgpu::ShaderModule {
&self.raw
}

/// Optional debug label used during creation.
pub fn label(&self) -> Option<&str> {
return self.label.as_deref();
}
}

/// Wrapper around `wgpu::PipelineLayout`.
Expand All @@ -220,6 +225,11 @@ impl PipelineLayout {
pub fn raw(&self) -> &wgpu::PipelineLayout {
return &self.raw;
}

/// Optional debug label used during creation.
pub fn label(&self) -> Option<&str> {
return self.label.as_deref();
}
}

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

impl<'a> Default for PipelineLayoutBuilder<'a> {
fn default() -> Self {
return Self::new();
}
}

/// Align a `u32` value up to the provided power-of-two alignment.
fn align_up_u32(value: u32, alignment: u32) -> u32 {
if alignment == 0 {
Expand Down Expand Up @@ -459,10 +475,6 @@ impl RenderPipeline {
pub(crate) fn raw(&self) -> &wgpu::RenderPipeline {
return &self.raw;
}
/// Consume and return the raw pipeline.
pub(crate) fn into_raw(self) -> wgpu::RenderPipeline {
return self.raw;
}
/// Pipeline label if provided.
pub fn label(&self) -> Option<&str> {
return self.label.as_deref();
Expand All @@ -480,6 +492,12 @@ pub struct RenderPipelineBuilder<'a> {
sample_count: u32,
}

impl<'a> Default for RenderPipelineBuilder<'a> {
fn default() -> Self {
return Self::new();
}
}

impl<'a> RenderPipelineBuilder<'a> {
/// New builder with defaults.
pub fn new() -> Self {
Expand Down
12 changes: 2 additions & 10 deletions crates/lambda-rs-platform/src/wgpu/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ pub struct RenderPass<'a> {
pub(super) raw: wgpu::RenderPass<'a>,
}

#[derive(Debug)]
struct RenderPassKeepAlive<'a> {
color_attachments: [Option<wgpu::RenderPassColorAttachment<'a>>; 1],
label: Option<String>,
}

impl<'a> RenderPass<'a> {
/// Set the active render pipeline.
pub fn set_pipeline(&mut self, pipeline: &pipeline::RenderPipeline) {
Expand Down Expand Up @@ -254,10 +248,8 @@ impl<'a> RenderColorAttachments<'a> {
&mut self,
operations: wgpu::Operations<wgpu::Color>,
) {
for attachment in &mut self.attachments {
if let Some(ref mut a) = attachment {
a.ops = operations;
}
for a in self.attachments.iter_mut().flatten() {
a.ops = operations;
}
}

Expand Down
Loading
Loading