WebRender broken on Android Emulator when 'use_optimized_shaders' is false
Categories
(Core :: Graphics: WebRender, defect)
Tracking
()
People
(Reporter: mukilanthiagarajan, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(2 files)
This issue was discovered when working on Servo. More details about the issue can be found in this PR.
Android Platform Details:
build-tools v34.0.0
cmdline-tools v14.0.0 rc1
emulator v34.2.9
ndk v26.1.10909125
platform-tools v35.0.0
platforms android-34
AVD Image: system-images;android-34;google_apis;x86_64
Host: NixOS 23.11 x86_64
Steps to reproduce (commands are executed from gfx/wr/wrench):
- Build wrench from mozilla-central (I used changeset 812640:5d65a6e7c95f) using
cargo apk build --target x86_64-linux-android --lib
- Install the built APK using
adb install -r ../target/debug/apk/wrench.apk
- Create the required
args
file and the test frame definition YAML. I had to tweak the instructions in wrench/android.txt to make this work on platform 34
$ adb root
$ adb shell
emu64xa:/ # mkdir /data/data/org.mozilla.wrench/files
emu64xa:/ # mkdir /data/data/org.mozilla.wrench/files/wrench/
emu64xa:/ # echo "load /data/data/org.mozilla.wrench/files/wrench/rounded-rects.yaml" >/data/data/org.mozilla.wrench/files/wrench/args
emu64xa:/ # echo "env: WRENCH_REFTEST_CONDITION_EMULATOR=1" >>/data/data/org.mozilla.wrench/files/wrench/args
emu64xa:/ # exit
$ adb push reftests/aa/rounded-rects.yaml /data/data/org.mozilla.wrench/files/wrench/
- Launch Wrench. Since Wrench uses optimized shaders by default, we should be able to see the 3 rounded rectangles (red, green and blue) on white background. This is the expected result
- Overwrite the args file to include the
--unoptimized-shaders
option
emu64xa:/ # echo "--use-unoptimized-shaders" >/data/data/org.mozilla.wrench/files/wrench/args
emu64xa:/ # echo "load /data/data/org.mozilla.wrench/files/wrench/rounded-rects.yaml" >>/data/data/org.mozilla.wrench/files/wrench/args
emu64xa:/ # echo "env: WRENCH_REFTEST_CONDITION_EMULATOR=1" >>/data/data/org.mozilla.wrench/files/wrench/args
- Launch Wrench. Instead of the expected rounder rectangles with colors, we see black regions on a white background.
Additional information
As noted in the Servo PR, this seems to be due to a bug in the Android Emulator's OpenGL translation layer goldfish-opengl
. I'm reproducing the theory from the PR here:
Android's OpenGL emulation layer (goldfish-opengl) has logic to preprocess shader sources, which looks for samplers of the type samplerExternalOES
and does a simple textual replacement to change the type to sampler2D
before compilation. It also marks the sampler as 'replaced' so it can emulate the correct type at runtime.
However, this logic can lead to false positives when the sampler is declared inside conditional macros. Hence, the sampler's type can be incorrectly marked as samplerExternalOES
even though the #if, #ifdef conditional logic would have declared the type as sampler2D. This seems to be a known limitation.
WebRender (in particular the shared.glsl include) has such conditional declaration of the texture units used from the shaders. In particular, the sampler sColor0
here is declared within ifdefs
to have different types depending on the flags enabled.
WebRender also maintain two versions of the shaders in its cache:
- An unoptimized version with all the conditional logic preserved in the source until the shader is compiled at runtime on Android, when the shader is actually used.
- Multiple "optimized versions" for combinations of features, produced during WebRender build. Thus the optimized versions eliminate most of the conditional declarations at build time.
When WebRender uses the unoptimized versions of the shaders, the conditional GLSL source is evaluated at runtime by the Android emulator and thus ends up with the incorrect type for the sColor0
sampler unit, which breaks the texture sampling in the fragment shader, causing it to always return Vec4(0, 0, 0, 1) and rendering elements on the page black. The optimized version of shaders are not affected because the sampler declarations are unconditional.
Reporter | ||
Comment 1•2 months ago
|
||
Comment 2•2 months ago
|
||
The severity field is not set for this bug.
:gw, could you have a look please?
For more information, please visit BugBot documentation.
Updated•2 months ago
|
Description
•