GL_APPLE_shader_framebuffer_fetch

Hi,

I just saw that Apple will support an extension GL_APPLE_shader_framebuffer_fetch in OpenGL ES 2.0 on all iOS 6 devices which allows programmable blending by using a built-in variable gl_LastFragData[0] in a fragment shader.

Is there any chance that this will be accessible any time soon in Unity?

Thanks

who knows what Unity 4 will bring
I would take it for granted that Unity 3 will not get an iOS 6 upgrade

Aras?

Thinking about it, I’m not sure how much support from Unity is necessary: maybe one doesn’t even have to call any OpenGL function but the variable gl_LastFragData[0] is just available in GLSL fragment shaders on iOS 6.

Well, we learned about this feature at exactly the same time you did, which is to say, “a couple of days ago” :wink:

Features take time to expose, but yeah, if you’re writing raw GLSL yourself, then it should (haven’t checked) “just work”, just write GLSL shader that uses the variable.

If you want shaders written in Cg/HLSL to be able to do this, then it’s more complex for us to implement. We’d need to extend our HLSL2GLSL translator and GLSL Optimizer to “understand” this, and produce valid iOS6 GLSL in the end.

But you know what? Since both of those pieces are open source… hint hint… pull request… GitHub - aras-p/hlsl2glslfork: HLSL to GLSL language translator based on ATI's HLSL2GLSL. Used in Unity. and GitHub - aras-p/glsl-optimizer: GLSL optimizer based on Mesa's GLSL compiler. Used to be used in Unity for mobile shader optimization. :wink:

Thanks for the reply, Aras! And, yes, I do write raw, untamed GLSL code. :slight_smile:

Then I think it should work (well I haven’t checked). All the extension requires is adding an extension statement to your shader, and then using gl_LastFragData.

I haven’t read up about this functionality properly yet, so i might be jumping to conclusions.

But it should open up a whole world of possibilities. Looking forward to it being implemented some time in the future. Aras will this be mapped to unitys the grabpass functionality, or will you keep it as a separate feature?

Right now the hoops I’m jumping through to avoid reading from the frame buffer on IOS are quite inconvenient, worth the performance gain though.

It has nothing to do with GrabPass, I think.

This new feature lets you read the color of the curent pixel in your pixel shader. Common use cases are pretty much what is mentioned in the extension specification: implementing custom blending modes (think all of the Photoshop ones) and doing really simple postprocessing effects that only need to read the current pixel (color correction etc.).

Where can I read the extension specification? I didn’t see it at http://www.khronos.org/registry/gles/ and I didn’t find it in Apple’s developer resources (apart from the WWDC presentation).

I would assume that the only reason apple even added it is the new image processing effects in Core Image, but I might be wrong there :wink:

O well, I found a link to a document that I don’t have access to (I’m in the university developer program): http://developer.apple.com/devcenter/download.action?path=/ios/opengl_es_extensions/apple_shader_framebuffer_fetch.txt
I guess that explains why some people know more than others. :slight_smile:

I agree. :slight_smile:

Correct me if I’m wrong but it seems like a nice speed boost. Shame it does not translate to droid well (unless I’m mistaken and it’s supported there).

In theory all PowerVR GPUs can do it; whether the drivers expose the functionality or not is a different story.

A lot of other GPUs can’t do it and won’t be able to anytime soon, so yeah, not very much “cross platform appeal”.

I just learned that Nvidia’s Tegra chip has been supporting this functionality for a long time (GL_NV_shader_framebuffer_fetch: http://developer.download.nvidia.com/assets/mobile/files/tegra_gles2_development.pdf ); but I assume that not all Tegra-based devices expose it. Khronos now lists the (multi-vendor) extension GL_EXT_shader_framebuffer_fetch: http://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_framebuffer_fetch.txt . Since Qualcomm’s and ARM’s mobile GPUs are tile-based, they are probably also able to implement this without too much effort (at least in future hardware).

UPDATE: I just tried it on an iPod touch 4 with iOS 6 and it works fine except that you have to ask for GL_EXT_shader_framebuffer_fetch instead of GL_APPLE_shader_framebuffer_fetch (I guess Apple used the GL_APPLE_… name in earlier pre-release builds of iOS 6). I also noted that you have to use gl_LastFragData[0] while using gl_LastFragColor results in an error. (GL_NV_shader_framebuffer_fetch allows to use gl_LastFragColor instead of gl_LastFragData[0]).

Hello,

With Unity 5 already out, I would like to know if there are any news/plans implementing the framebuffer fetch function to the Cg language?

I haven’t tested it but I think I saw it mentioned in the release notes, I guess it should already work.

1 Like

Wow, I skimmed through the notes, but couldn’t find it. Will look again than, thank you! :slight_smile:

At least Aras mentioned it in another thread some months ago.

from 4.6.3 release notes:

  • Shaders: Support for GL_EXT_shader_framebuffer_fetch. If you have a pixel shader with an “inout” color, it gets translated to use shader framebuffer fetch on GLES2/GLES3/Metal. Use UNITY_FRAMEBUFFER_FETCH_AVAILABLE macro in shaders to conditionally enclose that.
1 Like