[Mesa-dev] [PATCH 00/11] GL_ATI_fragment_shader support for Gallium

Miklós Máté mtmkls at gmail.com
Tue Dec 15 15:05:33 PST 2015


This series aims to improve the looks of Star Wars: Knights of the Old Republic (via Wine), but features some additional cleanup as well. The main component of the series is the implementation of GL_ATI_fragment_shader for all Gallium drivers (though I could only test it with radeonsi, llvmpipe, and softpipe). If this extension is available, the game uses it quite extensively: perhaps the most notable effect is the animated water ripples, but it also fixes the grass, improves the specular on wet characters (e.g. the Selkath) and it is used for regular texturing almost everywhere. The game has two optional post-process effects that also depend on this extension: framebuffer effects (light bloom, distortion), and soft shadows. Patches 5&6 are needed to fix crashing with post-processing. With current fglrx the grass is wrong, and post-process crashes, but my previous Radeon cards ran this game perfectly on Windows.

One other game that can use GL_ATI_fragment_shader is Doom 3, if r_renderer="r200" instead of "best" (which means "arb2", if GL_ARB_fragment_program is available). By default image_useNormalCompression=0, which results in wrong lighting and makes the specular overbright with r200. Setting it to 1 fixes r200, but messes up arb2, setting it to 2 fixes both. The light interaction is the same in r200 and arb2, but r200 doesn't have the heathaze shader. Later idTech4 games don't support r200 anymore: in Quake 4 everything is green, in Prey the organic walls are black, and ETQW has a completely revised renderer. I verified these with fglrx.

The series is based on the 11.0 branch of Mesa. Patches 1-4 implement GL_ATI_fragment_shader, 5-6 fix crashing in post-process of KotOR, 7-11 are various cleanups. There are a few TODO comments where I wasn't entirely sure, and the two RFC patches are more like ideas than solutions, but most of the code should be fine.

After this series the following issues remain in KotOR that I've been unable to fix:

1. Enabling soft shadows makes all characters disappear. When drawing the post-process effects the game switches between scratch framebuffers and the real one with glXMakeContextCurrent() several times. The scratch buffers have no depth, and after switching back to the real one the depth buffer is lost, so all subsequent depth tests fail.

2. Enabling MSAA results in black screen when post-process is enabled, only the light bloom is visible. I don't know how to debug this.

3. Post-process filters are extremely slow. Normally the game runs around 80fps (cpu-bound), but drops to 15fps with framebuffer effects, 20fps with soft shadows, 9fps with both. I've tried to profile this with apitrace, and found a bottleneck (see patch 10) that cost 5ms per call, but it turned out that it's not the real bottleneck. Both capturing and replaying are very slow compared to the game (15fps), so the profiler basically measures its own latency. I've tried to find the real culprit by adding time measurement to the calls made when drawing the post-process effects, but haven't found anything yet.

Screenshot gallery:

Fixed-function: http://postimg.org/image/5de014vd5/
With grass: http://postimg.org/image/u7xhv7g7d/
With ATIfs: http://postimg.org/image/jijt2y4eh/

Kashyyyk Shadowlands
Fixed-function: http://postimg.org/image/mchb7drbv/
ATIfs without fog: http://postimg.org/image/dk0cjp66z/
ATIfs with apply_fog(): http://postimg.org/image/rcerfbwyj/

Fixed-function: http://postimg.org/image/4l13f6mjf/
ATIfs: http://postimg.org/image/nat2vxfa3/
Framebuffer effects: http://postimg.org/image/vhl2ni5cr/

Stealth Mission
Without framebuffer effects: http://postimg.org/image/xcy12i7v3/
With framebuffer effects: http://postimg.org/image/75wu6jplb/

Hard: http://postimg.org/image/ycjqkgxn3/
Soft: http://postimg.org/image/lmk3l4f2n/

Miklós Máté (11):
  mesa: Don't leak ATIfs instructions in DeleteFragmentShader
  mesa: optionally associate a gl_program to ati_fragment_shader
  st/mesa: implement GL_ATI_fragment_shader
  st/mesa: enable GL_ATI_fragment_shader
  [RFC] mesa: allow binding framebuffer without depth&stencil
  st/mesa: fix handling the fallback texture
  program: fix comment about the fog formula
  mesa: improve debug log in atifragshader
  swrast: move two global defines to the only place where they are used
  [RFC] mesa: optimize out the realloc from glCopyTexImagexD()
  program: Remove extra reference_program()

 src/mesa/Makefile.sources                 |   1 +
 src/mesa/drivers/common/driverfuncs.c     |   3 +
 src/mesa/main/atifragshader.c             |  18 +-
 src/mesa/main/context.c                   |  10 +-
 src/mesa/main/dd.h                        |   6 +-
 src/mesa/main/mtypes.h                    |   3 +-
 src/mesa/main/state.c                     |  14 +-
 src/mesa/main/teximage.c                  |  29 ++
 src/mesa/program/ir_to_mesa.cpp           |   2 -
 src/mesa/program/prog_statevars.c         |   2 +-
 src/mesa/state_tracker/st_atifs_to_tgsi.c | 798 ++++++++++++++++++++++++++++++
 src/mesa/state_tracker/st_atifs_to_tgsi.h |  49 ++
 src/mesa/state_tracker/st_atom_constbuf.c |  14 +
 src/mesa/state_tracker/st_atom_sampler.c  |   6 +-
 src/mesa/state_tracker/st_cb_drawpixels.c |   1 +
 src/mesa/state_tracker/st_cb_program.c    |  35 +-
 src/mesa/state_tracker/st_extensions.c    |   1 +
 src/mesa/state_tracker/st_program.c       |  22 +
 src/mesa/state_tracker/st_program.h       |   1 +
 src/mesa/swrast/s_atifragshader.c         |   2 +
 20 files changed, 1001 insertions(+), 16 deletions(-)
 create mode 100644 src/mesa/state_tracker/st_atifs_to_tgsi.c
 create mode 100644 src/mesa/state_tracker/st_atifs_to_tgsi.h


More information about the mesa-dev mailing list