Skip to content

Add android support #83

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

Merged
merged 2 commits into from
Jul 12, 2021
Merged

Conversation

zmerp
Copy link
Contributor

@zmerp zmerp commented Jun 27, 2021

This is inspired from @blaind's work: https://github.com/blaind/bevy_openxr/blob/main/crates/bevy_openxr/src/platform/oculus_android/mod.rs

While @blaind work is known to be working, I didn't provide any testing for this code. If you want, I'm ok for waiting to have a working example before merging.

@Ralith
Copy link
Owner

Ralith commented Jun 29, 2021

Thanks! An initial concern: as illustrated in the linked reference, don't we also need an xrInitializeLoaderKHR call?

As I'm not qualified to review JNI esoterica myself, I'd like success reports from manual testing on android at minimum.

@zmerp
Copy link
Contributor Author

zmerp commented Jun 29, 2021

Yes, in the work I'm doing on bevy I'm also sending the same Java pointers to the loader using the extension. It is easy enough to do with the function pointers and it doesn't require extra modifications to openxrs. I could also contribute it directly to openxrs (inside the entry creation call), but I should definitely have something running first (which I'm deferring because I currently don't have the software + hardware ready).

@zmerp
Copy link
Contributor Author

zmerp commented Jul 3, 2021

I added Entry::initialize_android_loader() and updated the vulkan example for android support.

This PR is now ready for review, with some caveats:

  • I tested this on the Oculus Quest 1 and Quest 2 but I'm still waiting reports about the Oculus Go
  • It requires cargo-apk from this PR
  • Due to the lack khr_vulkan_enablesupport, the vulkan example now has much more boilerplate.

@zmerp zmerp changed the title Add android support in Entry::create_instance Add android support Jul 3, 2021
Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks, left some comments. Please split the changes to the example out into a separate PR (or, if you're comfortable with history rewrites, maintain them in a separate commit) so that they can be easily reverted once Oculus updates their runtimes.


// Initialize OpenXR with the extensions we've found!
let mut enabled_extensions = xr::ExtensionSet::default();
enabled_extensions.khr_vulkan_enable2 = true;
enabled_extensions.khr_vulkan_enable = available_extensions.khr_vulkan_enable;
Copy link
Owner

Choose a reason for hiding this comment

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

We should not enable version 1 if version 2 is available. Additionally, a comment should be added documenting that the fallback path is a temporary compatibility measure for Oculus runtimes.

panic!("{}", res);
}
let vk_instance_exts =
String::from_utf8_unchecked(buffer[0..data_len as usize - 1].to_vec())
Copy link
Owner

Choose a reason for hiding this comment

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

This should use str::from_utf8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove this code when I add proper support for khr_vulkan_enable.

buffer.len() as _,
&mut data_len as _,
&mut buffer as *mut _ as _,
);
Copy link
Owner

Choose a reason for hiding this comment

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

This (and the later call for device extensions) should use the proper two-call pattern and a Vec buffer to ensure sufficient space is allocated. It's fine to copy the internal helpers to accomplish this (though we might want to consider bundling them into the sys crate).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove this code when I add proper support for khr_vulkan_enable.

@zmerp
Copy link
Contributor Author

zmerp commented Jul 5, 2021

I'm going to add here commits related to the implementation of the khr_vulkan_enable wrapper, for the sake of testing. I'll rebase later.

@zmerp
Copy link
Contributor Author

zmerp commented Jul 5, 2021

The Oculus Go is probably compatible with OpenXR and this crate (I'm waiting for some last reports). The problem is that it supports only Vulkan 1.0 so the example doesn't run without heavy modifications, so I'm not listing it as compatible (but it will be compatible on bevy).

@Ralith
Copy link
Owner

Ralith commented Jul 5, 2021

It might not be too bad to refactor the example to use the multiview extension explicitly assuming the Go implements it, but I'm just as happy to keep things more concise/modern.

@zmerp
Copy link
Contributor Author

zmerp commented Jul 5, 2021

I'm ok with keeping the example on Vulkan 1.1 (without Oculus Go support). Another argument is that the cargo-apk metadata was a mashup of old and new entries for the sake of the Oculus Go support, when the user would probably decide to maintain separate Cargo.toml files for different headsets.

Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks!

@zmerp zmerp force-pushed the android-create-instance branch 3 times, most recently from 653152f to 04f905e Compare July 12, 2021 11:02
@zmerp zmerp force-pushed the android-create-instance branch 2 times, most recently from c547de4 to bb1f7e6 Compare July 12, 2021 19:43
@zmerp zmerp force-pushed the android-create-instance branch from bb1f7e6 to 46c7644 Compare July 12, 2021 20:02
@zmerp
Copy link
Contributor Author

zmerp commented Jul 12, 2021

I fixed the examples README with the crates.io link for cargo-apk. I think now it's all ready for merging.

@Ralith Ralith merged commit 5d042f4 into Ralith:master Jul 12, 2021
@zmerp zmerp deleted the android-create-instance branch July 12, 2021 23:30
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