-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
UBO/SSBO Improvements, Structs, BufferObject and sub data update #1782
Conversation
I am not 100% confident in the correctness of the std140 implementation. |
What is the state of this? I see there are conflicts. |
PR updated to the current master. |
This PR adds 37 Java source files. Please add the JME license (with appropriate year(s)) at the top of each file. |
commit 81fe1e0 Author: riccardobl <riccardo0blb@gmail.com> Date: Sun Apr 3 09:15:45 2022 +0200 fix access to constructor commit ac1d23c Author: riccardobl <riccardo0blb@gmail.com> Date: Sun Apr 3 09:15:18 2022 +0200 Fix shader buffer block managment commit cce6f80 Author: riccardobl <riccardo0blb@gmail.com> Date: Sun Apr 3 09:14:56 2022 +0200 Replace deprecated newInstance, pass exception to runtime exception commit e917c4e Author: riccardobl <riccardo0blb@gmail.com> Date: Sun Apr 3 09:14:47 2022 +0200 fix sub struct padding commit 2f4e006 Author: riccardobl <riccardo0blb@gmail.com> Date: Sun Apr 3 09:14:23 2022 +0200 Fix UBO/SSBO rebinding commit 58a371c Author: riccardobl <riccardo0blb@gmail.com> Date: Sun Apr 3 09:14:04 2022 +0200 Ensure fields are final only when exported commit ef7982d Author: riccardobl <riccardo0blb@gmail.com> Date: Tue Mar 8 21:10:07 2022 +0100 Struct based BufferObjects and Std140 layout commit 4797356 Author: riccardobl <riccardo0blb@gmail.com> Date: Tue Mar 8 20:49:01 2022 +0100 Improved UBO/SSBO support implemented over generic BufferObjects with glBufferSubData support commit 7f93b64 Author: Riccardo Balbo <riccardo@forkforge.net> Date: Thu Apr 2 14:40:41 2020 +0200 Generic BufferObject and memory regions
This PR is now rebased to the current master and with updated licenses |
This PR is made by multiple parts that together are used to reimplement UBOs and SSBOs in a more convenient and performant way. The main concepts are explained below
BufferObject
A BufferObject is a generic memory buffer that exists in OpenGL and from which all the other specialized buffers are derived. In JME we currently have some specialized Buffers (eg. VertexBuffer) but not a generic one.
This is needed to implement UBOs and SSBOs and can be used as parent class for VertexBuffer in a future refactoring, unlocking some performance improvements (see below)
BufferObject layout and sub data update
This PR introduces the concept of buffer layout, this is an abstraction and doesn't exist in OpenGL, nevertheless it can be used in jme to split the buffer in logical regions that can be marked for update and efficiently pushed to the GPU by the renderer while leaving the rest of the buffer untouched.
StructStd140BufferObject
This is an abstraction on top of BufferObject and BufferObject layouts, it generates an updates a BufferObject from a specially defined object that implements the Struct interface. This makes the creation and update of buffer objects user friendly and matches perfectly the glsl side of the code when using UBO/SSBO.
The goal when implementing this was to make it the default way to maintain BufferObjects (even inside the core), for this reason the implementation forces some limitations that are there to avoid any meaningful performance burden that might be caused by a more flexible implementation.
The limitations are:
com.jme3.util.struct.fields.*
are serialized: this permits to track changes to the fields and update only what changesThese limitations can be avoided by creating and maintaining the BufferObject manually with StructUtils, but shouldn't be needed in common usecases.
Usage example
This is an example and unit test for the UBO implementation
Final thoughts
This PR solves all the issues in he current UBO/SSBO implementation and, thanks to the sub data update, should always result in a performance improvement over sparse uniforms.
In future the bufferobject regions could be used to split large vertex buffers and allow a more efficient update (eg. for instances position).
There is an important change from the previous proposal (#1317) in the use of hardcoded
com.jme3.util.struct.fields.*
types, instead of a generic type StructField object, this is used to avoid ambiguity when using StructFields containing immutable types.In the previous proposal, two methods were used:
This is now handled internally by the
com.jme3.util.struct.fields.*
types.