]> git.nega.tv - josh/narcissus/commitdiff
Add Default impls for subresource structs
authorJoshua Simmons <josh@nega.tv>
Wed, 16 Nov 2022 23:33:21 +0000 (00:33 +0100)
committerJoshua Simmons <josh@nega.tv>
Wed, 16 Nov 2022 23:33:21 +0000 (00:33 +0100)
narcissus-gpu/src/lib.rs
narcissus/src/main.rs

index 37473c3e76b0f23485b24e70d23f08c7eca000ed..781483d8cafe9e7fffc7d20a9863b0460a8ee48b 100644 (file)
@@ -120,6 +120,17 @@ pub struct ImageSubresourceLayers {
     pub array_layer_count: u32,
 }
 
+impl Default for ImageSubresourceLayers {
+    fn default() -> Self {
+        Self {
+            aspect: ImageAspectFlags::COLOR,
+            mip_level: 0,
+            base_array_layer: 0,
+            array_layer_count: 1,
+        }
+    }
+}
+
 pub struct ImageSubresourceRange {
     pub aspect: ImageAspectFlags,
     pub base_mip_level: u32,
@@ -128,6 +139,18 @@ pub struct ImageSubresourceRange {
     pub array_layer_count: u32,
 }
 
+impl Default for ImageSubresourceRange {
+    fn default() -> Self {
+        Self {
+            aspect: ImageAspectFlags::COLOR,
+            base_mip_level: 0,
+            mip_level_count: 1,
+            base_array_layer: 0,
+            array_layer_count: 1,
+        }
+    }
+}
+
 flags_def!(BufferUsageFlags);
 impl BufferUsageFlags {
     pub const UNIFORM: Self = Self(1 << 0);
index 7010930f8ef04190c9713f801a5da6bf75b9ab5b..277d13c3f1da4ea8ea59fdf66028cb92c3c46600 100644 (file)
@@ -157,6 +157,7 @@ fn create_image_with_data(
     let frame = device.begin_frame();
 
     let buffer = create_buffer_with_data(device, BufferUsageFlags::TRANSFER_SRC, data);
+
     let image = device.create_image(&ImageDesc {
         memory_location: MemoryLocation::PreferDevice,
         usage: ImageUsageFlags::SAMPLED | ImageUsageFlags::TRANSFER_DST,
@@ -181,13 +182,7 @@ fn create_image_with_data(
             prev_layout: ImageLayout::Optimal,
             next_layout: ImageLayout::Optimal,
             image,
-            subresource_range: ImageSubresourceRange {
-                aspect: ImageAspectFlags::COLOR,
-                base_mip_level: 0,
-                mip_level_count: 1,
-                base_array_layer: 0,
-                array_layer_count: 1,
-            },
+            subresource_range: default(),
         }],
     );
 
@@ -200,12 +195,7 @@ fn create_image_with_data(
             buffer_offset: 0,
             buffer_row_length: 0,
             buffer_image_height: 0,
-            image_subresource_layers: ImageSubresourceLayers {
-                aspect: ImageAspectFlags::COLOR,
-                mip_level: 0,
-                base_array_layer: 0,
-                array_layer_count: 1,
-            },
+            image_subresource_layers: default(),
             image_offset: Offset3d { x: 0, y: 0, z: 0 },
             image_extent: Extent3d {
                 width,
@@ -224,13 +214,7 @@ fn create_image_with_data(
             prev_layout: ImageLayout::Optimal,
             next_layout: ImageLayout::Optimal,
             image,
-            subresource_range: ImageSubresourceRange {
-                aspect: ImageAspectFlags::COLOR,
-                base_mip_level: 0,
-                mip_level_count: 1,
-                base_array_layer: 0,
-                array_layer_count: 1,
-            },
+            subresource_range: default(),
         }],
     );