Bug 109853

Summary: [WEBGL] Implement OES_texture_half_float in WebKit
Product: WebKit Reporter: Nayan Kumar K <nayankk>
Component: WebGLAssignee: Nayan Kumar K <nayankk>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: bajones, bfulgham, dino, gman, kbr, zmo
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 110818, 110936, 111194    
Bug Blocks: 111196, 111197    
Attachments:
Description Flags
An attemp to implement OES_texture_half_float kbr: review-

Description Nayan Kumar K 2013-02-14 12:35:38 PST
OES_texture_half_float is now a community approved WebGL extension - http://www.khronos.org/registry/webgl/extensions/OES_texture_half_float/. Implement the support for OES_texture_half_float in WebKit.
Comment 1 Nayan Kumar K 2013-02-14 12:51:07 PST
Created attachment 188407 [details]
An attemp to implement OES_texture_half_float
Comment 2 Nayan Kumar K 2013-02-14 12:58:12 PST
PFA a WIP patch to implement OES_texture_half_float. Code closely follows the implementation of OES_texture_float. However, I still do not see the expected results. Am I missing something? Please help.

BTW, OES_texture_half_float expects the texture data in 16-bit floating point representation. However, the only floating point TypedArray representation is Float32Array. Shouldn't we need something like Float16Array to support OES_texture_half_float?

Thanks,
Comment 3 Kenneth Russell 2013-02-14 19:30:28 PST
(In reply to comment #2)
> PFA a WIP patch to implement OES_texture_half_float. Code closely follows the implementation of OES_texture_float. However, I still do not see the expected results. Am I missing something? Please help.
> 
> BTW, OES_texture_half_float expects the texture data in 16-bit floating point representation. However, the only floating point TypedArray representation is Float32Array. Shouldn't we need something like Float16Array to support OES_texture_half_float?

The working group discussed this and decided not to add such a type. No CPU supports 16-bit floating point values efficiently, so the performance of Float16Array would be very poor. For this reason, the WebGL extension OES_texture_half_float does not support uploading data from typed arrays, only HTML elements.

I'll comment on the patch separately.
Comment 4 Kenneth Russell 2013-02-14 19:45:07 PST
Comment on attachment 188407 [details]
An attemp to implement OES_texture_half_float

View in context: https://bugs.webkit.org/attachment.cgi?id=188407&action=review

> Source/WebCore/html/canvas/WebGLRenderingContext.cpp:5125
> +    case GraphicsContext3D::HALF_FLOAT_OES: // OES_texture_half_float

This is incorrect; per the spec, only NULL is allowed when calling the overload taking ArrayBufferView with HALF_FLOAT_OES type.

> Source/WebCore/platform/graphics/GraphicsContext3D.cpp:646
> +template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatR16F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)

All of these conversions are incorrect. You need to define a GC3DhalfFloat typedef (probably to short) and add routines which create half-floats. Because the WebGL OES_texture_half_float extension doesn't support typed arrays being passed in, you don't need the unpacking routines; you'll never see one of the half-float formats used as a source, only a destination. However, you need to support all of the formats of HTML elements. I think this amounts to just doing unsigned byte to half-float conversion but am not sure.

For references see

http://en.wikipedia.org/wiki/Half-precision_floating-point_format
ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf

I think the conversion you need (uint8 to half float) is essentially just an unsigned cast because the low 8 bits of the half-float are the mantissa and you won't have an exponent. Again, I'm not 100% sure.

> LayoutTests/fast/canvas/webgl/oes-texture-half-float.html:5
> +<title>WebGL OES_texture_float Conformance Tests</title>

You'll need to modify this test more extensively for half-float. In particular, you can only upload HTML elements, not typed arrays. You still should test that rendering to a half-float texture, when supported, preserves the extended range.
Comment 5 Nayan Kumar K 2013-02-15 10:53:10 PST
> The working group discussed this and decided not to add such a type. No CPU supports 16-bit floating point values efficiently, so the performance of Float16Array would be very poor. For this reason, the WebGL extension OES_texture_half_float does not support uploading data from typed arrays, only HTML elements.
> 
> I'll comment on the patch separately.

Thanks for the pointers. I will modify the patch accordingly and resubmit.
Comment 6 Brent Fulgham 2014-01-09 19:50:11 PST
I think this support is now landed in WebKit. We can probably close this patch out.
Comment 7 Brent Fulgham 2014-01-10 10:45:57 PST

*** This bug has been marked as a duplicate of bug 124871 ***