Summary: | [snb] corrupted GLSL built-in function results when using Uniform Buffer contents as arguments | ||
---|---|---|---|
Product: | Mesa | Reporter: | Tomasz Kaźmierczak <tomek-k> |
Component: | Drivers/DRI/i965 | Assignee: | Eric Anholt <eric> |
Status: | RESOLVED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | medium | CC: | wickmarkus |
Version: | git | ||
Hardware: | All | ||
OS: | Linux (All) | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Attachments: |
The expected result
The actual result (the bug) apitrace file a small test program The expected result The actual result (the bug) INTEL_DEBUG=wm |
Description
Tomasz Kaźmierczak
2012-11-14 16:27:00 UTC
Created attachment 70079 [details]
The expected result
Created attachment 70080 [details]
The actual result (the bug)
Do you have any way to get a small program that shows the issue? Is the use of pow() required? How about if you just read the value of one of your uniform values? (If you don't have a small program to demo the bug, then using apitrace would be a great way to get a way to show the problem) Hi, I'll try to create a small test program for that if I find some time, but for now I'm sending an apitrace file. The meshes get loaded in frame 137 and the bug is visible then (they get transformed to their propper positions in the next frame - It's just my app's behaviour, something I still haven't fixed). I didn't mention that, just to not complicate things, but I actually use the pow() function twice - for specular reflections and for gamma correction (the gamma value also comes from a UBO and using it as an argument for pow() magnifies the problem). It is not required to use pow() function in order to reproduce the bug - you can also use normalize() on a vector that comes from a UBO (eg. on a diffuse color), and probably other built-in functions would behave similarly (haven't checked that). However, I only checked that on uniforms that provide color information, and I guess the problem is best visible then. Some comments about the trace: - the trace comes from a program which is a Qt GUI application that uses QGLWidget - don't know whether this has any influence on the bug (eg. the GL context creation or something) - When you replay the trace, you can notice that some pixels on the meshes flicker; this, of course, doesn't happen when the u_SpecularHardness and u_InverseGamma come from the default uniform block - I've looked at the state of the uniforms inside apitrace, and their values are weird: u_DiffuseColor and u_SpecularColor are equal to u_LightPosition (this uniform comes from glUniform() function, not from a UBO), the other material uniforms all have value of 50, which is equal to u_LightPosition.x; similar is with u_CameraPosition and the matrices they all display the same values (all near 0); generally, only the light-related uniforms have propper values (all the light uniforms come from the default uniform block). With such values not many things would be rendered properly, so the apitrace shows wrong UBO uniform values. Created attachment 70334 [details]
apitrace file
Hi again. Adding a small test program (one c++ source and two shader sources). In order to compile, just call: $ g++ main.cpp -o gl3test -lX11 -lGL It draws a triangle whose color is set directly in a fragment shader, and then the gamma correction is applied to the color. The gamma factor comes from a UBO and is an argument to the pow() function used to calculate the gamma correction. I've tried to keep it as simple as possible, so even the vertex transform matrix is hardcoded into the vertex shader. Also attaching new images with the error and the expected result (the expected result has been produced by hardcoding the gamma value into the fragment shader). If you look into the fragment shader source (simple.frag) you can see one line commented out (line 18). If you use line 18 instead of line 16, then the problem is gone, so this demonstrates that the uniform itself contains propper value - it's just the pow() function that reads from somewhere else rather than from the uniform (as mentioned earlier, other built-in functions have the same problem, and it happens only for uniforms that come from UBOs). The source code is based on code copied from here: http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_%28GLX%29 I've added three functions: readShader(), linkProgram() and doTests(). Besides that, I've added the #define GL_GLEXT_PROTOTYPES directive at the begining of the file, so that I didn't have to load the function pointers manually. The program draws 5 frames (one frame per second) and exits. Created attachment 70373 [details]
a small test program
Created attachment 70374 [details]
The expected result
Created attachment 70375 [details]
The actual result (the bug)
I've tried to check this also on a Radeon hardware (HD 5450), but apparently the uniform buffer objects aren't supported by the radeon driver at all. I get exactly the same result here on my HD3000 and both with Mesa 9.0 and Mesa 9.2-devel (git-6dbe94c). But on my HD4000, everything looks fine. So maybe only sandy bridge related. Created attachment 74852 [details]
INTEL_DEBUG=wm
compiled shader for HD3000 on latest git
The patch series I just sent out (also available as the "ubo" branch of git://people.freedesktop.org/~anholt/mesa) fixes some rendering failures on my ivb that could also appear on snb plus should fix some additional snb-specific rendering failures. And it increases performance! Unfortunately, I don't have snb with me in the car right now so I can't tell whether it fixes your problem at the moment, so give it a shot. I might be affected by this bug as well. I uploaded some screenshots from several different configurations of mesa using the Dolphin emulator to demonstrate the problem. http://www.picpaste.com/pics/dolphin-mesa-upstream-master-GLX-GL-biZ548ky.1361088752.png Shows correct rendering with the classic renderer. http://www.picpaste.com/pics/dolphin-mesa-upstream-master-EGL-GLSL-ueIYd0GZ.1361088748.png Shows GLSL branch of dolphin, with UBO's enabled. Here you can see the pixelation and lack of fog(?) http://www.picpaste.com/pics/dolphin-mesa-anholt-ubo-EGL-GLSL-xx0KAkSm.1361088710.png I tried anholt's ubo branch, d8d8a5f3b480. This is also with the GLSL renderer, same results. http://www.picpaste.com/pics/dolphin-mesa-anholt-ubo-disabled-EGL-GLSL-eFv9EILW.1361088665.png This is what happens when disabling UBO's Still using the GLSL renderer, but it's much slower. In a nutshell, disabling GL_ARB_uniform_buffer_object allows for correct GLSL rendering but not as fast. Running Intel Sandybridge, Ubuntu 12.10 x86_64, kernel 3.5.0-24-generic Both the bug and the output of INTEL_DEBUG=wm haven't changed. Thanks for the short trace, tomasz. Found the bug (a debug build of mesa assertion fails on it), made a piglit test, and I'm waiting on this gm45 piglit run to finish before I swap to the snb to fix things. Thanks. Is there any chance that the fix will make it into Mesa 9.1? The patch here fixes the problem in dolphin for me http://lists.freedesktop.org/archives/mesa-dev/2013-February/034936.html commit 7b0731d940c758ca9c1e883cdea454d8787255c1 Author: Eric Anholt <eric@anholt.net> Date: Wed Feb 20 18:00:47 2013 -0800 i965/fs: Fix broken math on values loaded from uniform buffers on gen6. (since it's marked for stable, it'll end up in either 9.1 or 9.1.1) ok, thanks again for the fix |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.