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

example-runner-wgpu: bump android_logger to unbreak Android logging. #1033

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

eddyb
Copy link
Contributor

@eddyb eddyb commented Apr 15, 2023

I don't fully understand what was wrong with this before, but it acted like == Info instead of >= Info or <= Info (neither warn/error nor debug/trace, were present, and this seems impossible given the code of android_logger 0.11.3, but maybe it was doing both <= Info and >= Info, just in two different places?).

With this PR, warn/error logging can also be seen, and I get this on my Android-based VR headset:

--------- beginning of main
04-14 14:43:25.916 11925 11925 I ple_runner_wgp: Late-enabling -Xcheck:jni
04-14 14:43:25.951 11925 11925 E ple_runner_wgp: Unknown bits set in runtime_flags: 0x8000
04-14 14:43:25.995 11925 11925 W System  : ClassLoader referenced unknown path: 
04-14 14:43:26.047 11925 11950 D vulkan  : searching for layers in '/data/app/rust.example_runner_wgpu-bfL6xwGnSgxGZ0IesoqcBg==/lib/arm64'
04-14 14:43:26.048 11925 11925 D android_activity::nat..: Start: 0x7a6cc648c0
04-14 14:43:26.048 11925 11950 D vulkan  : searching for layers in '/data/app/rust.example_runner_wgpu-bfL6xwGnSgxGZ0IesoqcBg==/base.apk!/lib/arm64-v8a'
04-14 14:43:26.048 11925 11950 I wgpu_hal::vulkan::ins..: Unable to find extension: VK_EXT_debug_utils
04-14 14:43:26.048 11925 11950 W wgpu_hal::vulkan::ins..: Unable to find layer: VK_LAYER_KHRONOS_validation
04-14 14:43:26.051 11925 11925 W Thread-1: type=1400 audit(0.0:321): avc: denied { ioctl } for path="/dev/kgsl-3d0" dev="tmpfs" ino=1206 ioctlcmd=0x958 scontext=u:r:untrusted_app:s0:c94,c256,c512,c768 tcontext=u:object_r:gpu_device:s0 tclass=chr_file permissive=0
04-14 14:43:26.052 11925 11950 I AdrenoVK-0: ===== BEGIN DUMP OF OVERRIDDEN SETTINGS =====
04-14 14:43:26.052 11925 11950 I AdrenoVK-0: ===== END DUMP OF OVERRIDDEN SETTINGS =====
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: QUALCOMM build          : d66bb48e17, I18aabff2be
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Build Date              : 11/28/22
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Shader Compiler Version : E031.41.07.00
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Local Branch            : 
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Remote Branch           : refs/tags/AU_LINUX_ANDROID_LA.UM.8.12.C3.10.00.00.670.284
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Remote Branch           : NONE
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Reconstruct Branch      : NOTHING
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Build Config            : S P 8.0.12 AArch64
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Driver Path             : /vendor/lib64/hw/vulkan.kona.so
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Driver Version          : 0687.0
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: PFP                     : 0x016dd110
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: ME                      : 0x00000000
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Application Name    : wgpu
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Application Version : 0x00000001
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Engine Name         : wgpu-hal
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Engine Version      : 0x00000002
04-14 14:43:26.054 11925 11950 I AdrenoVK-0: Api Version         : 0x004030ee
04-14 14:43:26.054 11925 11950 I wgpu_hal::vulkan::ins..: Instance version: 0x401000
04-14 14:43:26.054 11925 11950 I wgpu_hal::vulkan::ins..: Enabling device properties2
04-14 14:43:26.057 11925 11950 I wgpu_core::instance: Adapter Vulkan AdapterInfo { name: "Adreno (TM) 650", vendor: 20803, device: 100990978, device_type: IntegratedGpu, driver: "Qualcomm Technologies Inc. Adreno Vulkan Driver", driver_info: "Driver Build: d66bb48e17, I18aabff2be, 1669663408\nDate: 11/28/22\nCompiler Version: E031.41.07.00\nDriver Branch: \n", backend: Vulkan }
04-14 14:43:26.057 11925 11950 W wgpu_core::instance: Missing downlevel flags: SURFACE_VIEW_FORMATS
04-14 14:43:26.057 11925 11950 W wgpu_core::instance: The underlying API or device in use does not support enough features to be a fully compliant implementation of WebGPU. A subset of the features can still be used. If you are running this program on native and not in a browser and wish to limit the features you use to the supported subset, call Adapter::downlevel_properties or Device::downlevel_properties to get a listing of the features the current platform supports.
04-14 14:43:26.057 11925 11950 I wgpu_core::instance: DownlevelCapabilities {
04-14 14:43:26.057 11925 11950 I wgpu_core::instance:     flags: COMPUTE_SHADERS | FRAGMENT_WRITABLE_STORAGE | INDIRECT_EXECUTION | BASE_VERTEX | READ_ONLY_DEPTH_STENCIL | NON_POWER_OF_TWO_MIPMAPPED_TEXTURES | CUBE_ARRAY_TEXTURES | COMPARISON_SAMPLERS | INDEPENDENT_BLEND | VERTEX_STORAGE | ANISOTROPIC_FILTERING | FRAGMENT_STORAGE | MULTISAMPLED_SHADING | DEPTH_TEXTURE_AND_BUFFER_COPIES | WEBGPU_TEXTURE_FORMAT_SUPPORT | BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED | UNRESTRICTED_INDEX_BUFFER | FULL_DRAW_INDEX_UINT32 | DEPTH_BIAS_CLAMP | VIEW_FORMATS | UNRESTRICTED_EXTERNAL_TEXTURE_COPIES,
04-14 14:43:26.057 11925 11950 I wgpu_core::instance:     limits: DownlevelLimits,
04-14 14:43:26.057 11925 11950 I wgpu_core::instance:     shader_model: Sm5,
04-14 14:43:26.057 11925 11950 I wgpu_core::instance: }
04-14 14:43:26.057 11925 11950 D wgpu_hal::vulkan::ada..: Supported extensions: ["VK_KHR_swapchain", "VK_KHR_image_format_list", "VK_KHR_imageless_framebuffer", "VK_KHR_driver_properties", "VK_KHR_timeline_semaphore", "VK_EXT_image_robustness", "VK_EXT_robustness2"]
04-14 14:43:26.059 11925 11950 W wgpu_hal::vulkan: Unrecognized device error ERROR_INITIALIZATION_FAILED
04-14 14:43:26.059 11925 11950 E wgpu::backend::direct: Error in Adapter::request_device: Not enough memory left
04-14 14:43:26.059 11925 11949 I RustStdoutStderr: thread '<unnamed>' panicked at 'Failed to create device: RequestDeviceError', examples/runners/wgpu/src/graphics.rs:89:10
04-14 14:43:26.059 11925 11949 I RustStdoutStderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
04-14 14:43:26.059 11925 11950 I wgpu_core::hub: Dropping Global

There's still a bunch of wonkery here, Not enough memory left should be "device lost" or something instead, or ERROR_INITIALIZATION_FAILED be used as indication that a fallback should be used, etc.

The explanation for why there is even an error is that VK_KHR_timeline_semaphore is broken in AdrenoVK on this headset (Oculus Quest 2) with the latest update, because the userspace AdrenoVK component advertises it but it's blocked by SELinux(?) - the path="/dev/kgsl-3d0" ... ioctlcmd=0x958 message, which AFAICT is IOCTL_KGSL_TIMELINE_CREATE.

I am also not the first to run into this, e.g.: https://communityforums.atmeta.com/t5/Quest-Development/Issue-with-VK-KHR-timeline-semaphore/td-p/1027690

By locally patching wgpu (not included in this PR), I was able to get this:

com.oculus.shellenv-20230414-150104.mp4

@eddyb eddyb enabled auto-merge (rebase) April 15, 2023 07:32
@eddyb
Copy link
Contributor Author

eddyb commented Apr 15, 2023

EDIT: most of the comment hidden because I opened a separate PR:


With a few more hacks, I was able to get the "mouse" example to kinda work too:

(click to reveal hacky patch and video)
diff --git a/Cargo.toml b/Cargo.toml
index 2035cee7e7..35e8298359 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -52,3 +52,11 @@ codegen-units = 256
 opt-level = 3
 incremental = true
 codegen-units = 256
+
+# HACK(eddyb) we override the `wgpu`->`naga` git dependency, with our own, so
+# that we can upgrade to newer `naga` than `wgpu` (and/or use our own patches).
+[patch."https://github.com/gfx-rs/naga".naga]
+git = "https://github.com/EmbarkStudios/naga"
+# rev = "53d62b9ede64898681c0dbc70d04296caf90ed16"
+# HACK(eddyb) using https://github.com/gfx-rs/naga/pull/2290 before it's merged.
+branch = "spv-in-break-if"
diff --git a/examples/runners/wgpu/src/graphics.rs b/examples/runners/wgpu/src/graphics.rs
index 9a5bd43263..c857de5bc8 100644
--- a/examples/runners/wgpu/src/graphics.rs
+++ b/examples/runners/wgpu/src/graphics.rs
@@ -3,7 +3,10 @@ use crate::maybe_watch;
 use super::Options;
 use shared::ShaderConstants;
 use winit::{
-    event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent},
+    event::{
+        ElementState, Event, KeyboardInput, MouseButton, Touch, TouchPhase, VirtualKeyCode,
+        WindowEvent,
+    },
     event_loop::{ControlFlow, EventLoop, EventLoopBuilder},
     window::Window,
 };
@@ -297,7 +300,40 @@ async fn run(
                 }
             }
             Event::WindowEvent {
-                event: WindowEvent::CursorMoved { position, .. },
+                event:
+                    WindowEvent::Touch(Touch {
+                        phase: phase @ (TouchPhase::Started | TouchPhase::Ended | TouchPhase::Cancelled),
+                        ..
+                    }),
+                ..
+            } => {
+                // FIXME(eddyb) deduplicate!
+                let button = MouseButton::Left;
+                let mask = 1 << mouse_button_index(button);
+                match phase {
+                    TouchPhase::Started => {
+                        mouse_button_pressed |= mask;
+                        mouse_button_press_since_last_frame |= mask;
+
+                        if button == MouseButton::Left {
+                            drag_start_x = cursor_x;
+                            drag_start_y = cursor_y;
+                            drag_end_x = cursor_x;
+                            drag_end_y = cursor_y;
+                        }
+                    }
+                    TouchPhase::Moved => unreachable!(),
+                    TouchPhase::Ended | TouchPhase::Cancelled => mouse_button_pressed &= !mask,
+                }
+            }
+            Event::WindowEvent {
+                event:
+                    WindowEvent::CursorMoved { position, .. }
+                    | WindowEvent::Touch(Touch {
+                        phase: TouchPhase::Moved,
+                        location: position,
+                        ..
+                    }),
                 ..
             } => {
                 cursor_x = position.x as f32;
diff --git a/examples/runners/wgpu/src/lib.rs b/examples/runners/wgpu/src/lib.rs
index 4bdb7cd9cc..c19515d61b 100644
--- a/examples/runners/wgpu/src/lib.rs
+++ b/examples/runners/wgpu/src/lib.rs
@@ -153,7 +153,7 @@ fn maybe_watch(
 #[derive(StructOpt)]
 #[structopt(name = "example-runner-wgpu")]
 pub struct Options {
-    #[structopt(short, long, default_value = "Sky")]
+    #[structopt(short, long, default_value = "Mouse")]
     shader: RustGPUShader,
 }
 
com.oculus.shellenv-20230415-101759.mp4

Looking at it, this shader should probably just have an extra bit to control whether to show the "cursor" UI at all (but this isn't something shadertoy ever accounted for, and my data model here mostly matches theirs).

@eddyb
Copy link
Contributor Author

eddyb commented Apr 15, 2023

Opened a PR to wgpu which would neatly solve the broken VK_KHR_timeline_semaphore issue:

@eddyb eddyb merged commit c4c736c into EmbarkStudios:main Apr 17, 2023
@eddyb eddyb deleted the android-logger branch April 17, 2023 07:35
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