summary refs log tree commit diff
path: root/src/graphics/texture.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/texture.rs')
-rw-r--r--src/graphics/texture.rs35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/graphics/texture.rs b/src/graphics/texture.rs
index b28d540..da40387 100644
--- a/src/graphics/texture.rs
+++ b/src/graphics/texture.rs
@@ -1,13 +1,18 @@
 #![deny(unsafe_code)]
 use crate::error::*;
-use crate::graphics::Permanent;
+use crate::graphics::{ Permanent, Render };
 use crate::graphics::util::{
   stage_in_buffer, allocate_image, init_image_view,
   begin_transient_commands, end_transient_commands
 };
+use crate::shader_data::TexturePushBlock;
+
+use std::ffi::c_void;
 
 use vulkanalia::{ Device, Instance };
-use vulkanalia::vk::{ self, HasBuilder, InstanceV1_0, DeviceV1_0 };
+use vulkanalia::vk::{
+  self, HasBuilder, InstanceV1_0, DeviceV1_0, DeviceV1_4
+};
 
 
 #[derive(Debug)]
@@ -47,6 +52,32 @@ impl Texture {
     unsafe { device.free_memory(self.image_memory, None) };
     unsafe { device.destroy_image_view(self.image_view, None) };
   }
+
+  #[allow(unsafe_code)]
+  pub fn make_active(&self, device: &Device, render: &Render,
+                     command_buffer: &vk::CommandBuffer)
+  {
+    let template = &render.texture_descriptor_update_template;
+    let layout = &render.pipeline_layout;
+
+    //   Constructing this every time may appear slow, but it's all CPU-side
+    // work, and the real cost we're trying to avoid with push descriptors is
+    // excessive CPU-GPU synchronziation.
+    let image_info = vk::DescriptorImageInfo::builder()
+            .image_view(self.image_view)
+            .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)
+            .build();
+    let push_block = TexturePushBlock { image_info };
+    let push_block_bytes = &raw const push_block as *const c_void;
+
+    //   Please notice the magic constant 1. This is a one-based index into
+    // the array of descriptor set layouts passed to create_pipeline_layout()
+    // in init_pipeline() in render.rs.
+    unsafe {
+      device.cmd_push_descriptor_set_with_template(
+          *command_buffer, *template, *layout, 1, push_block_bytes)
+    };
+  }
 }