summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-07-04 16:49:31 -0700
committerIrene Knapp <ireneista@irenes.space>2026-07-04 16:49:31 -0700
commitaea6d8b310dede44211fcf994f8ddb42df076d91 (patch)
treea0df2bf481b3fbccd66648634220fed411776fab
parent8eb7bc2dcab860231c26bfe14d4c780449052da3 (diff)
load compiled SPIR-V bytecode (yay)
no way to build it except by hand, as-yet. the tutorial doesn't cover that, we'll need to circle back and write a build.rs

Force-Push: yes
Change-Id: I2b489381f95b4b7505862caa236dea1c60cd9c1a
-rw-r--r--flake.nix3
-rw-r--r--src/error.rs14
-rw-r--r--src/main.rs22
3 files changed, 38 insertions, 1 deletions
diff --git a/flake.nix b/flake.nix
index a883414..e64a945 100644
--- a/flake.nix
+++ b/flake.nix
@@ -38,7 +38,7 @@
 
         buildInputs = buildInputsFor pkgs;
 
-        nativeBuildInputs = with pkgs; [ autoPatchelfHook ];
+        nativeBuildInputs = with pkgs; [ autoPatchelfHook glslang ];
       }).overrideAttrs {
         # This needs to apply only to the top-level derivation, not to the
         # dependencies.
@@ -61,6 +61,7 @@
           cargo
           rustc
           vulkan-tools
+          glslang
         ] ++ buildInputsFor pkgs;
 
         #   This makes cargo run work; mind that you don't let it mask a
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