[PATCH 1/2] wined3d: Put local constants into the shader code again
Stefan Dösinger
stefan at codeweavers.com
Tue Mar 12 20:19:23 CDT 2013
This provides a small GPU-side performance boost on dx10+ capable Nvidia
cards - about 5% in World of Tanks on my Geforce 9600, and more in a
dedicated test program.
This is essentially a revert of cd7825c89374fb9dd4c20aef2dbfd258713efe6a,
with proper precision.
Performance data follows. The numbers are from a stand-alone test
program testing a GLSL shader with 21 uniforms or constant immediate
values. The numbers indicate the change in performance when switching
from uniforms to consts. The test program is available at
https://84.112.174.163/~git/perftest file const_gl/const_gl.cpp.
A d3d version of the same test can be found in const_d3d/const_d3d.cpp
CPU GPU
Geforce 9600:
Windows: +30% +19%
Linux: +26% +23%
OSX: +1% +23%
Geforce GTX 460:
Windows: ??? +9%
Linux: +4% +15%
Windows CPU fps jumping between 6000 and 9000 fps,
result therefore inconclusive.
Radeon X1600:
OSX: +0% -7%
Linux: -2% -2%
Windows: -4% -6%
GL results mirror local vs global const performance in d3d
Radeon HD 5770:
Linux: +0% +0%
Windows: +0% +0%
Intel GMA X3100:
OSX: +8% -25%
Linux: +8% +10%
Windows: -1% +0%
(OSX results don't make sense; high res outperforms low res)
Geforce 7400:
Linux(nouveau) +0% +0%
Windows: Can't disable vsync
Geforce 7600:
Linux(nvidia) +0% +0%
---
dlls/wined3d/glsl_shader.c | 37 ++++---------------------------------
1 file changed, 4 insertions(+), 33 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 7d98487..3928b07 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -1253,15 +1253,14 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
shader_addline(buffer, "vec4 tmp0;\n");
shader_addline(buffer, "vec4 tmp1;\n");
- /* Local constants use a different name so they can be loaded once at shader link time
- * They can't be hardcoded into the shader text via LC = {x, y, z, w}; because the
- * float -> string conversion can cause precision loss.
- */
if (!shader->load_local_constsF)
{
LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
{
- shader_addline(buffer, "uniform vec4 %s_lc%u;\n", prefix, lconst->idx);
+ const float *value;
+ value = (const float *)lconst->value;
+ shader_addline(buffer, "const vec4 %s_lc%u = vec4(%.7e, %.7e, %.7e, %.7e);\n",
+ prefix, lconst->idx, value[0], value[1], value[2], value[3]);
}
}
@@ -4457,25 +4456,6 @@ static void shader_glsl_generate_fog_code(struct wined3d_shader_buffer *buffer,
}
/* Context activation is done by the caller. */
-static void hardcode_local_constants(const struct wined3d_shader *shader,
- const struct wined3d_gl_info *gl_info, GLhandleARB programId, const char *prefix)
-{
- const struct wined3d_shader_lconst *lconst;
- GLint tmp_loc;
- const float *value;
- char glsl_name[10];
-
- LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
- {
- value = (const float *)lconst->value;
- snprintf(glsl_name, sizeof(glsl_name), "%s_lc%u", prefix, lconst->idx);
- tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
- GL_EXTCALL(glUniform4fvARB(tmp_loc, 1, value));
- }
- checkGLcall("Hardcoding local constants");
-}
-
-/* Context activation is done by the caller. */
static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context,
struct wined3d_shader_buffer *buffer, const struct wined3d_shader *shader,
const struct ps_compile_args *args, struct ps_np2fixup_info *np2fixup_info)
@@ -5705,15 +5685,6 @@ static void set_glsl_shader_program(const struct wined3d_context *context, struc
*/
shader_glsl_load_vsamplers(gl_info, device->texUnitMap, programId);
shader_glsl_load_psamplers(gl_info, device->texUnitMap, programId);
-
- /* If the local constants do not have to be loaded with the environment constants,
- * load them now to have them hardcoded in the GLSL program. This saves some CPU cycles
- * later
- */
- if (pshader && !pshader->load_local_constsF)
- hardcode_local_constants(pshader, gl_info, programId, "ps");
- if (vshader && !vshader->load_local_constsF)
- hardcode_local_constants(vshader, gl_info, programId, "vs");
}
/* Context activation is done by the caller. */
--
1.8.1.5
More information about the wine-patches
mailing list