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

Fix Compressed 3D Textures failing on Android and Meta Quest #29566

Conversation

RenaudRohlinger
Copy link
Collaborator

@RenaudRohlinger RenaudRohlinger commented Oct 6, 2024

Fixed #29539

Description
On Android and Oculus devices, calling gl.compressedTexSubImage3D with the extra srcOffset and srcLengthOverride parameters to default (0,0) results in the following error:
[.WebGL-0x2032d0d00]GL ERROR :GL_INVALID_VALUE : glCompressedTexSubImage3D: size is not correct for dimensions

The function gl.compressedTexSubImage3D was being called with two extra parameters (0, 0) at the end:

gl.compressedTexSubImage3D(
  gl.TEXTURE_2D_ARRAY,
  i,
  0,
  0,
  0,
  mipmap.width,
  mipmap.height,
  image.depth,
  glFormat,
  mipmap.data,
  0, // Optional parameter (srcOffset)
  0  // Optional parameter (srcLengthOverride)
);

When supplying image data directly via an ArrayBufferView (e.g., mipmap.data), the function's signature does not require srcOffset and srcLengthOverride parameters. These extra parameters are only valid when specifying a sub-range of the source data. Including them with default values (0, 0) can cause issues on platforms that strictly adhere to the OpenGL ES specification, which does not support these parameters in the same way based on my understanding of the code: https://chromium.googlesource.com/chromium/src/+/6682b1c4aac00aee61b09ba8f6084f1790429315/gpu/command_buffer/service/gles2_cmd_decoder.cc

While some platforms may read these extra parameters as offset and length override, Android and Oculus implementations probably strictly follow the OpenGL ES standards, leading to a GL_INVALID_VALUE error.

The gl.compressedTexSubImage3D API can be confusing due to the multiple ways to call it between WebGL and OpenGL ES, which might have caused this issue. More here:
https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/compressedTexSubImage3D
https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glCompressedTexSubImage3D.xhtml

Since both optional parameters were not currently being used I believe it should be safe for the moment to simply remove them in order to fix #29539.

This contribution is funded by Utsubo

Copy link

github-actions bot commented Oct 6, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 688.13
170.5
688.12
170.5
-8 B
-1 B
WebGPU 807.64
217.52
807.64
217.51
-4 B
-6 B
WebGPU Nodes 807.15
217.38
807.15
217.38
-4 B
-6 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 462.85
111.78
462.84
111.78
-8 B
-1 B
WebGPU 535.43
144.5
535.43
144.5
-4 B
-5 B
WebGPU Nodes 491.54
134.24
491.54
134.24
-4 B
-5 B

@Mugen87 Mugen87 added this to the r170 milestone Oct 6, 2024
@RenaudRohlinger
Copy link
Collaborator Author

Does this PR fixes the issue on your device @Mugen87? 👀

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 6, 2024

I can easier test with updated builds on dev after the merge. Or you update the builds once in this PR so we can use the following URL for testing:

https://rawcdn.githack.com/RenaudRohlinger/three.js/utsubo/fix/webgl-compressed-texture-3d/examples/webgl_texture2darray_compressed.html

@RenaudRohlinger
Copy link
Collaborator Author

Well, pretty safe to merge anyway, let's try! 😁

@RenaudRohlinger RenaudRohlinger merged commit b7712d3 into mrdoob:dev Oct 6, 2024
12 checks passed
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.

CompressedArrayTexture Broken on Android/Meta Quest Headset
2 participants