KhronosGroup/WebGL

Texture feedback restrictions are over zealous

greggman opened this issue · 6 comments

Maybe this should be filed as a bug on each browser but there probably needs to have cts tests if changed.

AFAIK, browsers don't let you bind the same texture as a both a input to a shader and as an attachment to a framebuffer in the same draw call.

In OpenGL though, based on the TEXTURE_MIN_LOD, TEXTURE_MAX_LOD, TEXTURE_BASE_LEVEL, TEXTURE_MAX_LEVEL settings, it's possible to read from one mip level and render to another mip level. It's also possible in a 2D array to read from one layer and render to another layer.

WebGL2 has been shipping for several years now so maybe this doesn't need to be relaxed but I tested in native OpenGL and it works fine. Feedback in OpenGL is not an error, it's just undefined, but those situations described above (one mip level to another mip level, one layer to another layer) are not feedback issues.

Thanks for filing this. I recall this being raised a while back (by Google's Filament team maybe?) as it makes manually generating mipmaps difficult. Is it possible to set up the texture's parameters so that API-side validation code can ensure as much as possible that the fragment shader won't sample from the same level being rendered to?

For context, before these restrictions were enforced, there were a fair number of WebGL applications which did have rendering feedback loops and which didn't work on mobile devices. Ensuring that these apps did proper ping-ponging between textures made them more portable.

It is possible to setup texture parameters so the API-side validation code can ensure there's no feedback.

For example TEXTURE_MIN_LOD = 2, TEXTURE_MAX_LOD = 2 means you can only access mip level 2. So you're free to render to any other level without feedback

Similarly TEXTURE_BASE_LAYER = 2, TEXTURE_MAX_LAYER = 2 means, for a 2d-array, you can only access layer 2, so you're free to render to any other layer without feedback.

kdashg commented

Is this covered by #3142?

kdashg commented

The linked browser bugs there seem to mostly have been fixed now.

Well, my test doesn't run, maybe it has a bug. Both Firefox and Chrome complain there's a feedback loop

https://jsgist.org/?src=137493160103a6bc85bff8d47eb50045

Wrote a similar test in OpenGL. It worked.

I see, ok. If I set TEXTURE_MAX_LEVEL instead of TEXTURE_MAX_LOD it works.