HALF_FLOAT textures on Android

275 views
Skip to first unread message

Evgeny Demidov

unread,
Apr 18, 2019, 2:06:56 PM4/18/19
to WebGL Dev List
"R16F, RG16F, RGBA16F, R32F, RG32F, and RGBA32F all become valid render target formats when the EXT_color_buffer_float extension (WebGL 2.0) is enabled.
They should all be well supported on all platforms - though Android will probably only support the 16-bit formats." Ken Russell

if they "only support the 16-bit formats". How do they set Uint16Array HALF_FLOAT data then? I know it is easy with one simple shader but this is not very convenient. Or do they use FLOAT textures (e.g. in TensorFlow.js) ?

Any news about Float16Array discussion? JS progresses rapidly now. x2 accelerations (for free), remember ML, tensor cores and so on...   :)

Evgeny

Jeff Gilbert

unread,
Apr 18, 2019, 2:09:41 PM4/18/19
to webgl-d...@googlegroups.com
You can upload Float32Arrays into HALF_FLOAT textures.

--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evgeny Demidov

unread,
Apr 18, 2019, 2:13:31 PM4/18/19
to WebGL Dev List
just tested on Canary
   gl.texSubImage2D(gl.TEXTURE_2D, 0, 0,0, n,n, gl.RED, gl.HALF_FLOAT,pix)
with Float32Array pix and get

INVALID_OPERATION: texSubImage2D: type HALF_FLOAT_OES but ArrayBufferView is not NULL and not Uint16Array
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-d...@googlegroups.com.

Jeff Gilbert

unread,
Apr 18, 2019, 2:15:55 PM4/18/19
to webgl-d...@googlegroups.com
Guess we should really fix that. That's ES3's solution.

To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.

Evgeny Demidov

unread,
Apr 18, 2019, 2:32:51 PM4/18/19
to WebGL Dev List
in Firefox
Error: WebGL warning: texSubImage2D: ArrayBufferView type not compatible with `type`.

Old working true HALF_FLOAT texture test with Uint16Array

Evgeny

Evgeny Demidov

unread,
Apr 18, 2019, 2:39:05 PM4/18/19
to WebGL Dev List
It would be nice if one can upload Float32Arrays into HALF_FLOAT textures, Compute SSBO buffers and back! :)
May be it works on Android?

Evgeny Demidov

unread,
Apr 18, 2019, 5:27:16 PM4/18/19
to WebGL Dev List
can you make Float16ArrayANGLE extension?
For Android, TF.js PoseNet Model and Google Pixel :)

Jeff Gilbert

unread,
Apr 18, 2019, 5:42:38 PM4/18/19
to webgl-d...@googlegroups.com
So in WebGL2, this is how it's done:
https://jsfiddle.net/jLzeq35a/

You can upload RED+FLOAT into R16F internalFormat textures.

Ken Russell

unread,
Apr 18, 2019, 6:38:33 PM4/18/19
to WebGL Dev List
Good point Jeff.

Evgeny, we would rather not change WebGL 1.0's semantics further given that WebGL 2.0 provides a solution to this issue. Does using WebGL 2.0 work for you?

Evgeny Demidov

unread,
Apr 19, 2019, 9:25:10 AM4/19/19
to WebGL Dev List
You will laugh "these Russians will always break something or lose" :)
I can upload RED+FLOAT into R16F internalFormat textures but can not get data back
https://www.ibiblio.org/e-notes/webgl/gpu/HALF_FLOATtest.htm
I get from
gl.readPixels(0,0, n,n, gl.RED, gl.FLOAT, pix)

ERROR :GL_INVALID_OPERATION : glReadPixels: format and type incompatible with the current read framebuffer

or for gl.HALF_FLOAT
readPixels: type HALF_FLOAT but ArrayBufferView not Uint16Array

Evgeny

Evgeny Demidov

unread,
Apr 19, 2019, 10:47:11 AM4/19/19
to WebGL Dev List
Fortunately reading from HALF_FLOAT textures is not very important for matrix multiplications (Android, PoseNet TF.js Model and Google Pixel).
For NxN matrix multiplications C = AxB there are N^3 A,B readings and only N^2 C writings. Therefore shader can read HALF_FLOAT and write FLOAT values.

It may be caveats with HALF_FLOAT 32bit stride alignment on different GPU. E.g. I get acceleration with HALF_FLOAT on Nvidia and didn't get on Intel GPU.

SSBO buffers need to test too. Now Compute shaders read/write with 32bit stride but how it will read/write vec4 HALF_FLOAT data?

Evgeny

Jeff Gilbert

unread,
Apr 19, 2019, 12:52:47 PM4/19/19
to webgl-d...@googlegroups.com
You're gonna need to read that back as RGBA/FLOAT or the implementation color read format/type, which is probably RED/HALF_FLOAT. ReadPixels format/type are restricted to these two combos.

--

Evgeny Demidov

unread,
Apr 19, 2019, 11:18:58 PM4/19/19
to WebGL Dev List
Thank you Jeff. All works fine for RGBA16F textures and RGBA/FLOAT ReadPixels format/type.

Evgeny

Jeff Gilbert

unread,
Apr 19, 2019, 11:59:55 PM4/19/19
to webgl-d...@googlegroups.com
Just to be extra clear, you can call ReadPixels(RGBA, FLOAT) on an
R16F texture, but it might be worth it to you to read directly as
RED/HALF_FLOAT, if expanding R16F to RGBA/FLOAT is too slow:
https://jsfiddle.net/a4Lep9cj/5/

Evgeny Demidov

unread,
Apr 20, 2019, 1:36:22 AM4/20/19
to WebGL Dev List
what is the use of
console.assert(g.checkFramebufferStatus(g.FRAMEBUFFER) == g.FRAMEBUFFER_COMPLETE);
console.assert(!g.getError());
if all the same I see ERRORs messages in console
I'm using alert() usually but not sure what is better 

Jeff Gilbert

unread,
Apr 20, 2019, 1:42:39 AM4/20/19
to webgl-d...@googlegroups.com
It's a less common conditional version of console.log:

On my Windows+Firefox, I get no errors.

Evgeny Demidov

unread,
Apr 20, 2019, 1:59:51 AM4/20/19
to webgl-d...@googlegroups.com
if I deliberately add an error (say "t" -> "t1") I get in Firefox
Assertion failed: jeff.htm:10:1
Assertion failed: jeff.htm:15:1
Via RGBA/FLOAT: 0 jeff.htm:25:1
Error: WebGL warning: texImage2D: Invalid internalformat: 0x0000 jeff.htm:9:1

it is likely just duplication?

Evgeny Demidov

unread,
Apr 20, 2019, 3:07:46 AM4/20/19
to WebGL Dev List
Thank you, it is obvious but I missed (again :) that I can read pixels from "RED" FBO as RGBA
and really it may be a little slower.


On Saturday, April 20, 2019 at 6:59:55 AM UTC+3, Jeff Gilbert wrote:
Reply all
Reply to author
Forward
0 new messages