Skip to content

Conversation

@svillar
Copy link
Contributor

@svillar svillar commented Jan 16, 2026

df0854f

[OpenXR] Hit testing returns empty results mixed with actual data
https://bugs.webkit.org/show_bug.cgi?id=305641

Reviewed by Fujii Hironori and Dan Glastonbury.

The OpenXRHitTestManager can call xrRaycastANDROID with specific
parameters to first determine how many results are available and then
use that number to size the Vector where the actual results will be
stored. This way we don't need to ask always for the max allowed number
of results (most of them would be empty/zero) but instead for the exact
number of available hit test results.

No new tests as this is specific to OpenXR.

* Source/WebKit/UIProcess/XR/openxr/OpenXRHitTestManager.cpp:
(WebKit::OpenXRHitTestManager::requestHitTest):

Canonical link: https://commits.webkit.org/305809@main

4f74b4c

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe 🛠 win
🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl 🧪 ios-wk2 🧪 api-mac ✅ 🧪 api-wpe
🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 wpe-cairo-libwebrtc
🧪 api-ios ✅ 🛠 gtk
🛠 vision 🧪 mac-wk2 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ⏳ 🧪 vision-wk2 🧪 mac-wk2-stress 🛠 playstation
✅ 🛠 tv 🧪 mac-intel-wk2
✅ 🛠 tv-sim ✅ 🛠 mac-safer-cpp
🛠 watch
✅ 🛠 watch-sim

@svillar svillar requested a review from cdumez as a code owner January 16, 2026 15:43
@svillar svillar self-assigned this Jan 16, 2026
@svillar svillar added the WebXR For bugs in WebXR label Jan 16, 2026
@svillar svillar requested a review from fujii January 16, 2026 15:47
Copy link
Contributor

@djg djg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@fujii fujii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you change constexpr int maxHitTestResults = 2 to increase the number? If you don't change, I don't understand what this change means.

@fujii
Copy link
Contributor

fujii commented Jan 17, 2026

Ah, I understand the problem.

    for (const auto xrResult : xrResults)
        results.append(XrPosefToPose(xrResult.pose));

This code always copies two items. It should check xrHitResults.resultsCountOutput.
I think the following change should be enough.

    for (auto i = 0; i < xrHitResults.resultsCountOutput; i++)
        results.append(XrPosefToPose(xrResults[i].pose));

If you want to use Vector for xrResults, we shouldn't use for loop here.
Vector::map is the efficient way to do the same.

@svillar
Copy link
Contributor Author

svillar commented Jan 19, 2026

Ah, I understand the problem.

    for (const auto xrResult : xrResults)
        results.append(XrPosefToPose(xrResult.pose));

This code always copies two items. It should check xrHitResults.resultsCountOutput. I think the following change should be enough.

    for (auto i = 0; i < xrHitResults.resultsCountOutput; i++)
        results.append(XrPosefToPose(xrResults[i].pose));

That would be fine but you'd still be allocating a vector of size maxHitTestResults which is larger than the one required, I know it is not a big deal because the number of results is small.

If you want to use Vector for xrResults, we shouldn't use for loop here. Vector::map is the efficient way to do the same.

OK will change that.

@svillar svillar force-pushed the openxr_hittest_count branch from 31a5281 to f11b888 Compare January 19, 2026 09:33
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 19, 2026
@svillar svillar removed the merging-blocked Applied to prevent a change from being merged label Jan 19, 2026
@svillar svillar force-pushed the openxr_hittest_count branch from f11b888 to 4f74b4c Compare January 19, 2026 09:51
@svillar svillar added the merge-queue Applied to send a pull request to merge-queue label Jan 19, 2026
https://bugs.webkit.org/show_bug.cgi?id=305641

Reviewed by Fujii Hironori and Dan Glastonbury.

The OpenXRHitTestManager can call xrRaycastANDROID with specific
parameters to first determine how many results are available and then
use that number to size the Vector where the actual results will be
stored. This way we don't need to ask always for the max allowed number
of results (most of them would be empty/zero) but instead for the exact
number of available hit test results.

No new tests as this is specific to OpenXR.

* Source/WebKit/UIProcess/XR/openxr/OpenXRHitTestManager.cpp:
(WebKit::OpenXRHitTestManager::requestHitTest):

Canonical link: https://commits.webkit.org/305809@main
@webkit-commit-queue
Copy link
Collaborator

Committed 305809@main (df0854f): https://commits.webkit.org/305809@main

Reviewed commits have been landed. Closing PR #56710 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit df0854f into WebKit:main Jan 19, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WebXR For bugs in WebXR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants