Giving Vulkan an idiomatic ruby wrapper
  • Ruby 98%
  • GLSL 1.7%
  • Shell 0.3%
Find a file
itspomf 3d7b872e1e Add VkDevice to VkInstance dependency chain
This is a safety measure to address problems with how FFI's finalizers will engage *before* the Scheduler has finished processing, causing the Vulkan instance to be invalidated before the Context's terminate() method has been reached.

This has not been found to be necessary in threaded models, and suggests a problem in the Ruby implementation.
2026-07-13 16:26:01 -04:00
lib Add VkDevice to VkInstance dependency chain 2026-07-13 16:26:01 -04:00
shader Use the lower 16 bits for voxel IDs 2026-07-04 17:43:46 -04:00
.gitignore
aldiag.rb
build-dependencies.sh Cleanup dependency build script 2026-07-05 14:07:36 -04:00
compile-shaders.sh
README.md
vkdiag.rb

Vulkanize

Building out features for tiny game development in ruby, targeting Vulkan as the rendering engine and OpenAL for audio.

Features

This project intends to provide support for Vulkan 1.4 with windowing via GLFW3.

Additionally, it provides a "managed mode" to most created resources, which will automatically handle their cleanup, track relevant linkages (such as the owning VkDevice), and various "ruby-fied" convenience methods, to minimize the need to use FFI and pointers within your own code. All managed objects will be automatically released at program termination, or when garbage-collected.

Ease of Use

To that end, one of the major goals of the project is to ensure that these tools are almost trivial to use, while still retaining the ability to access the raw C specifications of the library at-will. The following code snippet demonstrates the ability to bootstrap Vulkan, GLFW, and basic synchronization privimites in only a few lines of code.

require_relative 'lib/context'

# Set up the main Context as a 640x480 window;
# only use validation layers if debugging is enabled
layers = $DEBUG ? ['VK_LAYER_KHRONOS_validation'] : []
context = Context.new('Test', 640, 480, layers: )

# Initialize the graphics pipeline
pipe = context.make_pipeline(['triangle.vert.spv',
                              'triangle.frag.spv'])

# Begin rendering
context.render(){|cmd|
  pipe.bind( cmd )  # use graphics pipeline
  cmd.draw( 3 )     # draw 3 vertices
}

Requirements

Please be aware that you will need the following libraries available on your PATH (whatever that might be for your OS).

  • Vulkan version 1.4 or later (libvulkan1 or equivalent)
  • SPIRV-Reflect 1.4.304.0 or later (via github)
  • GCC 12.0 or later / a C compiler (cc or equivalent for your platform)
  • GLFW version 3.3 or later (libglfw3 or equivalent)
  • OpenAL version 1.1 or later (libopenal1 or equivalent)
  • Ruby version 3.1 or later (ruby or equivalent)

This project is also tested to work in TruffleRuby v23.1.0 and JRuby 9.4 or later!

Setup

Once you've cloned the repository, you must run the following commands to complete the setup!

# make the build script executable and then call it
chmod +x build-dependencies.sh
./build-dependencies

# do the same for the script that compiles vulkan shaders
chmod +x compile-shaders.sh
./compile-shaders