summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs14
-rw-r--r--src/main.rs22
2 files changed, 36 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 39d52b8..f3f1ca9 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -76,6 +76,20 @@ impl From<vulkanalia::vk::ErrorCode> for Error {
   }
 }
 
+impl From<vulkanalia::bytecode::BytecodeError> for Error {
+  fn from(e: vulkanalia::bytecode::BytecodeError) -> Self {
+    Error {
+      message: match e {
+        vulkanalia::bytecode::BytecodeError::Alloc =>
+            "Unable to allocate buffer for SPIR-V bytecode.".to_string(),
+        vulkanalia::bytecode::BytecodeError::Length(length) =>
+            format!("Compiled SPIR-V bytecode has length {}, \
+                    which means it's corrupt.", length)
+      }
+    }
+  }
+}
+
 pub fn ignore_errors(mut body: impl FnMut() -> Result<()>) -> () {
   if let Err(e) = body() {
     eprintln!("Error: {}", e);
diff --git a/src/main.rs b/src/main.rs
index f4e93cb..62c6025 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ use std::cell::OnceCell;
 use std::collections::{ BTreeMap, BTreeSet, HashSet };
 use std::ffi::{ c_void, CStr };
 use vulkanalia::{ Device, Entry, Instance, Version };
+use vulkanalia::bytecode::Bytecode;
 use vulkanalia::loader::{ LibloadingLoader, LIBRARY };
 use vulkanalia::vk::{ self, Handle, HasBuilder,
                       ApplicationInfo, InstanceCreateInfo,
@@ -180,6 +181,8 @@ impl Surreality {
       self.init_vulkan_swapchain()?;
     }
 
+    self.init_pipeline()?;
+
     Ok(())
   }
 
@@ -638,6 +641,25 @@ impl Surreality {
     Ok(())
   }
 
+  #[allow(unsafe_code)]
+  fn init_pipeline(&mut self) -> Result<()> {
+    // TODO integrate with Cargo
+    let vertex_binary = include_bytes!("../vert.spv");
+    let fragment_binary = include_bytes!("../frag.spv");
+
+    let _ = self.load_spirv_shader_module(vertex_binary)?;
+
+    Ok(())
+  }
+
+  fn load_spirv_shader_module(&mut self, binary: &[u8])
+      -> Result<vk::ShaderModule>
+  {
+    let bytecode = Bytecode::new(binary)?;
+
+    Err(Error { message: "just because".to_string() })
+  }
+
   //   To Vulkan, a "physical" device is the actual GPU, and a "logical"
   // device is per-process state that represents a connection to the GPU.
   // Before we can create a logical device, we must choose which physical