-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Implement motion vectors in compatibility renderer #97151
base: master
Are you sure you want to change the base?
Conversation
Yes, motion vectors should be a specialization for now. Then the version will only be compiled when it is actually used.
Not from scene.glsl, no. We will have to do something in the actual particle system. I think that we handled this case already in the RD renderers. Most likely we will need to duplicate the particle buffer to effectively clear the history
I can't think of any reason why one struct would work but not another. We should try to get it working though as the bool will likely create a dynamic branch which we really don't want |
modules/openxr/extensions/openxr_fb_space_warp_extension_wrapper.cpp
Outdated
Show resolved
Hide resolved
174904d
to
6af033e
Compare
6af033e
to
65211d2
Compare
modules/openxr/extensions/openxr_fb_space_warp_extension_wrapper.cpp
Outdated
Show resolved
Hide resolved
258736c
to
c554b2d
Compare
69daeba
to
a52b386
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is looking really great to me :-)
I'm going to test the latest version soon, but in the meantime, I have some notes on the public APIs this adds. Some of this will need discussion with the rest of the XR team.
Doing some testing with AppSW via GodotVR/godot_openxr_vendors#222, I'm getting this message spammed to logs: I don't see why we should be seeing this unhandled type, I think this is meant to be something that the application logs via OpenGL? And I don't think Godot is doing it. Maybe it's something from the OpenXR runtime? But just this getting sent to the log so often is going to have a negative affect on performance. One option could be updating These appear to be the types we're not handling:
|
@dsnopek it's of type "Marker" and severity "Notification", I noticed this recently and added the code to make it actually share the log and this is what it shared:
Edit: It logged this as well
I can add the code to this PR so that its actually logged like above, but yes I'm thinking I'll have to figure out whats causing this and try to stop it. Since it's Marker/Notification I'm assuming what causes this is not actually a problem, but the log itself would be an issue. |
@devloglogan @dsnopek I've seen those errors for some time now, even before we added support for OpenXR debug logging (which is turned off by default anyway). |
1f0f05b
to
a50a1ee
Compare
I'm opening this PR since the XR_FB_space_warp code has been removed and it's in a now arguably merge-able state. :) |
a50a1ee
to
a329caf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a general architectural standpoint, I think this makes sense. Before merging I would like to see some performance testing on mobile devices as I suspect that the shader changes might cause a slight regression in performance for the non motion vector case.
The API for passing in the external motion vector buffer is very awkward in light of the fact that the old override API already has a slot for the depth buffer and the velocity buffer. I don't think overlapping with the old API is great as it is layering on technical debt. I suspect we can merge this with the existing override API to streamline things and avoid creating a new, conflicting API surface.
The one outstanding question I have is how this will work in the Mobile renderer. I suspect that doing a pre-pass is fine for two reasons:
- We have to have it anyway if we are going to support space warp.
- We can likely set it up so the vertex workload of the main pass fully overlaps with the fragment workload in the motion vector pass. This would minimize the performance impact of the pass. If other consumers of motion vectors are okay with a low res pass, then it could be really good.
The thing is, it's a different depth buffer (at a different size). On the pre-existing one, the color and depth texture there are for the color pass: render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture) On the new one, they are for the motion vector pass: void render_target_set_motion_vectors_target(RID p_render_target, RID p_motion_vectors_texture, RID p_depth_texture, Size2i p_size, int p_view_count) And the But now that I'm looking at this again, we might not need to pass |
@dsnopek I would just add a parameter to the existing function for the velocity depth texture. |
Ah, ok, that makes sense! Then we can just have a new method for setting the motion vector target size. |
a329caf
to
9cfd2e0
Compare
9526944
to
17c1d3d
Compare
@dsnopek @BastiaanOlij I've added @clayjohn I've made changes to address your suggestions, thanks for the review! |
17c1d3d
to
d0e5a9b
Compare
d0e5a9b
to
853545b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no more notes. :-) This is looking great to me!
modules/openxr/extensions/openxr_extension_wrapper_extension.cpp
Outdated
Show resolved
Hide resolved
853545b
to
24a0e50
Compare
@AThousandShips thanks so much for the review! I've applied all your suggestions :) |
This'll need to be rebased now that PR #98831 was merged (sorry :-)) |
24a0e50
to
db761a1
Compare
@dsnopek No worries, rebased. :) |
db761a1
to
b5c7820
Compare
This PR implements motion vectors in the compatibility renderer, primarily for use with the
XR_FB_space_warp
OpenXR extension.For testing purposes, this PR currently implements this extension as well. Eventually this logic will be handled via GDExtension in godot_openxr_vendors. This PR will remain as a draft until that's the case.Edit: Space warp functionality has been relocated to GodotVR/godot_openxr_vendors#222.
Technical details
I've tried to emulate how motion vectors are implemented in the Forward+ renderer where possible, but it's worth noting that space warp requires 3D motion vectors. Whereas the Forward+ renderer is rendering 2D motion vectors for TAA.
Motion vectors are rendered in a new, separate render pass. Why this was done:
XR_META_recommended_layer_resolution
OpenXR extension, since all attachments would then have to be of the same resolution.The vertex shader code in
scene.glsl
has been placed in a newvertex_shader()
function. When motion vectors are used, it will run the vertex shader on both previous and current vertex data. The scene state data and multiview data have been duplicated to hold the previous frame’s data. The vertex shader outputs both the previous and current clip positions, which are used to calculate motion vectors in the fragment shader.For skeletons,
GLES::MeshInstance::Surface
now stores two vertex buffers, generating the second one on demand when motion vectors are enabled. The VBOs will alternate between current/previous, and the previous VBO is used to populate newscene.glsl
vertex attribs at locations 16/17.Similarly, for multimeshes/particles,
GLES::MultiMesh
now also stores two vertex buffers with the secondary one generated on demand. Newscene.glsl
vertex attribs (location 18 to 21) store the previous data, and the setup for both the current/previous vertex attribs is now done in a newGLES3::MeshStorage::multimesh_vertex_attrib_setup()
function.Issues that need to be addressed
There are a couple things that need to be ironed out that I would really appreciate some input on from those who have a bit more rendering know how.
This implementation of motion vectors requires the GPU to have a max vertex attribute value of at least 22. This requirement is met on Quest hardware (or any other headset which uses the Qualcomm XR-series chips), and we check it before running the motion vector pass. But when opening the editor on desktop some errors might be thrown fromShaderGLES3::_initialize_version()
, which attempts to compile all shader variants at startup, including the motion vector variant of scene.glsl. What is the best way to prevent it from compiling this variant if there aren’t enough vertex attributes?In non-one-shot particle systems, it's possible for a particle instance to go from the end of its lifetime one frame to the beginning of its lifetime the next frame. At the moment this causes an undesired result on the motion vector texture (we should draw nothing for the particle on these frames). Is there a way we can determine if this is the case inscene.glsl
?As mentioned above the vertex shader inscene.glsl
has moved into a newvertex_shader()
function. For multiview data, I'm currently passing in a boolean value indicating whether to usemultiview_data_block.prev_data
ormultiview_data_block.data
. I'd rather just pass in theMultiviewData
structs themselves rather than the boolean, similar to how the SceneData structs are passed in. However, doing this seems to cause anything using multiview data to just not be rendered. What I have in the PR works, so maybe it's not a big deal, but if anybody has ideas on how to fix this I'd appreciate it!UPDATED (2024-10-28): I believe all of the areas of concern have been addressed. While technically the second point regarding particle systems still exists, I don't think this is something that needs to be addressed in this PR. Beyond just particles, there should be a way to exclude objects from being drawn to motion vectors (Ex: when an object is teleporting rather than moving smoothly). This is something the current Vulkan motion vectors implementation could benefit from. I think a fix for this warrants its own PR.
Contributed with ❤️ by W4Games