Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan in Processing (draft) #948

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Vulkan in Processing (draft) #948

wants to merge 5 commits into from

Conversation

TeoJT
Copy link

@TeoJT TeoJT commented Feb 15, 2025

(I'm new to PRs so let me know if you see any mistakes ^^")

This is my attempt at making a Vulkan-based renderer for Processing, using LWJGL to access a Vulkan binding. It's part of my final year dissertation where I compare OpenGL and Vulkan renderer speeds so a lot of code is still very messy.

I was also originally planning to release it as a library for Processing, but it appears that moving away from JOGL/OpenGL is now on Processing's roadmap (#881)

The new renderer can be accessed by using PV2D/PV3D in the size() function:

void setup() {
  size(512, 512, PV2D);
}

It works by translating OpenGL commands (through the PGL abstraction layer) to Vulkan commands through a thin OpenGL-to-Vulkan translation layer (under a new package named GL2VK). This layer is optimised for Processing (mostly the immediate and retained modes in Processing). These commands are passed to separate threads (called ThreadNodes) which offload the main thread from potentially expensive operations.
There is also a shader converter which translates OpenGL shaders to Vulkan shaders.

Also, it uses GLFW to create a window and receive mouse inputs... no AWT!

@hx2A
Copy link
Collaborator

hx2A commented Feb 15, 2025

Wow, @TeoJT , this is an amazing PR!!! Thank you for your hard work here.

It looks like your PGraphicsVulkan class inherits from PGraphicsOpenGL to benefit from all of the geometry and style functionality as well as the tessellation code, and then intercepts what would otherwise go through PGL to use Vulkan instead. Is that correct?

You mention mouse events, does it handle keyboard events also?

How much testing have you done? In general, does it work well?

I can't wait to give this a try!

@TeoJT
Copy link
Author

TeoJT commented Feb 15, 2025

Thanks for the kind words @hx2A :)

You're correct; I effectively haven't touched any (or at least most) of the PGraphicsOpenGL code and linked PGL to GL2VK, which uses Vulkan instead.

It only uses some quick 'n dirty code for mouse events and there's no keyboard or scrollwheel events sadly. The window also cannot be resized yet.

I've mostly tested using the performance example sketches;
DynamicParticlesImmediate, Esfera, LineRendering, QuadRendering, StaticParticlesImmediate, TextRendering all work perfectly.
There's a bug with retained mode so DynamicParticlesRetained, CubicGridRetained, and StaticParticlesRetained work but don't display correctly. CubicGridImmediate doesn't display correctly too for some reason.
Also MeshTweening works which proves that custom shaders works to an extent.

It generally works well on basic sketches as long as you don't use PGraphics, and make sure you call background(0) in the draw loop. It performs on average x1.5 faster than the OpenGL renderer, sometimes even higher.

Let me know how it goes for you!

@TeoJT
Copy link
Author

TeoJT commented Feb 15, 2025

Update- just added mouse clicking and keyboard input just now with GLFW.

@SableRaf SableRaf requested a review from Stefterv February 20, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants