]> git.nega.tv - josh/narcissus/commitdiff
Rename MemoryLocation enum variants
authorJoshua Simmons <josh@nega.tv>
Sun, 20 Nov 2022 22:46:13 +0000 (23:46 +0100)
committerJoshua Simmons <josh@nega.tv>
Sun, 20 Nov 2022 22:46:13 +0000 (23:46 +0100)
Try to be more explicit about what you're getting with each option.

narcissus-gpu/src/backend/vulkan/mod.rs
narcissus-gpu/src/lib.rs
narcissus/src/main.rs

index 73ccf57d2e0514a17c8c619a466cfce1e842b21e..c7e553e89838708888ac0b21631b2a3161aaba6d 100644 (file)
@@ -1258,9 +1258,8 @@ impl VulkanDevice {
 
     fn allocate_memory(&self, desc: &VulkanMemoryDesc) -> VulkanMemory {
         let memory_property_flags = match desc.memory_location {
-            MemoryLocation::Auto => vk::MemoryPropertyFlags::default(),
-            MemoryLocation::PreferHost => vk::MemoryPropertyFlags::HOST_VISIBLE,
-            MemoryLocation::PreferDevice => vk::MemoryPropertyFlags::DEVICE_LOCAL,
+            MemoryLocation::HostMapped => vk::MemoryPropertyFlags::HOST_VISIBLE,
+            MemoryLocation::Device => vk::MemoryPropertyFlags::DEVICE_LOCAL,
         };
 
         let memory_type_index =
@@ -1469,7 +1468,7 @@ impl Device for VulkanDevice {
             .device_fn
             .create_buffer(self.device, &create_info, None, &mut buffer));
 
-        let memory = self.allocate_memory_for_buffer(buffer, desc.memory_location);
+        let memory = self.allocate_memory_for_buffer(buffer, desc.location);
 
         unsafe {
             self.device_fn.bind_buffer_memory2(
@@ -1569,7 +1568,7 @@ impl Device for VulkanDevice {
             .device_fn
             .create_image(self.device, &create_info, None, &mut image));
 
-        let memory = self.allocate_memory_for_image(image, desc.memory_location);
+        let memory = self.allocate_memory_for_image(image, desc.location);
 
         unsafe {
             self.device_fn.bind_image_memory2(
index 33430076b87cab2fb749571b2e639c0267e033a2..bcd5df1495ce84aa86a52334ffe7e4875720ba76 100644 (file)
@@ -62,9 +62,8 @@ pub struct Pipeline(Handle);
 
 #[derive(Clone, Copy, Debug)]
 pub enum MemoryLocation {
-    Auto,
-    PreferHost,
-    PreferDevice,
+    HostMapped,
+    Device,
 }
 
 #[repr(C)]
@@ -180,13 +179,13 @@ impl BufferUsageFlags {
 }
 
 pub struct BufferDesc {
-    pub memory_location: MemoryLocation,
+    pub location: MemoryLocation,
     pub usage: BufferUsageFlags,
     pub size: usize,
 }
 
 pub struct ImageDesc {
-    pub memory_location: MemoryLocation,
+    pub location: MemoryLocation,
     pub usage: ImageUsageFlags,
     pub dimension: ImageDimension,
     pub format: ImageFormat,
index c433417ab8e97d49d1eb393d5635d336b20bc86d..8609474f9dfbd9f9d09f9a97f14a48278b8bc74c 100644 (file)
@@ -133,7 +133,7 @@ where
 {
     let len = data.len() * std::mem::size_of::<T>();
     let buffer = device.create_buffer(&BufferDesc {
-        memory_location: MemoryLocation::PreferHost,
+        location: MemoryLocation::HostMapped,
         usage,
         size: len,
     });
@@ -159,7 +159,7 @@ fn create_image_with_data(
     let buffer = create_buffer_with_data(device, BufferUsageFlags::TRANSFER_SRC, data);
 
     let image = device.create_image(&ImageDesc {
-        memory_location: MemoryLocation::PreferDevice,
+        location: MemoryLocation::Device,
         usage: ImageUsageFlags::SAMPLED | ImageUsageFlags::TRANSFER_DST,
         dimension: ImageDimension::Type2d,
         format: ImageFormat::RGBA8_SRGB,
@@ -230,7 +230,7 @@ struct MappedBuffer<'a> {
 impl<'a> MappedBuffer<'a> {
     pub fn new(device: &'a dyn Device, usage: BufferUsageFlags, len: usize) -> Self {
         let buffer = device.create_buffer(&BufferDesc {
-            memory_location: MemoryLocation::PreferHost,
+            location: MemoryLocation::HostMapped,
             usage,
             size: len,
         });
@@ -498,7 +498,7 @@ pub fn main() {
         if width != depth_width || height != depth_height {
             device.destroy_image(&frame, depth_image);
             depth_image = device.create_image(&ImageDesc {
-                memory_location: MemoryLocation::PreferDevice,
+                location: MemoryLocation::HostMapped,
                 usage: ImageUsageFlags::DEPTH_STENCIL,
                 dimension: ImageDimension::Type2d,
                 format: ImageFormat::DEPTH_F32,