[PATCH xserver 18/19] glamor: Cut down a bunch of conditional handling for RepeatFix.

Eric Anholt eric at anholt.net
Wed Jan 27 17:56:47 PST 2016


For hardware that doesn't do actual jumps for conditionals (i915,
current vc4 driver), this reduces the number of texture fetches
performed (assuming the driver isn't really smart about noticing that
the same sampler is used on each side of an if).

No performance difference on i965 with x11perf -magpixwin100 (n=40).

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 glamor/glamor_render.c | 50 +++++++++++++++++++-------------------------------
 1 file changed, 19 insertions(+), 31 deletions(-)

diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index ed425f5..da45920 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -105,19 +105,18 @@ glamor_create_composite_fs(struct shader_key *key)
     /* The texture and the pixmap size is not match eaxctly, so can't sample it directly.
      * rel_sampler will recalculate the texture coords.*/
     const char *rel_sampler =
-        " vec4 rel_sampler(sampler2D tex_image, vec2 tex, vec4 wh, int repeat, int set_alpha)\n"
+        " vec4 rel_sampler(sampler2D tex_image, vec2 tex, vec4 wh, int repeat)\n"
         "{\n"
-        "	tex = rel_tex_coord(tex, wh, repeat);\n"
-        "	if (repeat == RepeatFix + RepeatNone) {\n"
-        "		if (!(tex.x >= 0.0 && tex.x < 1.0 \n"
-        "		    && tex.y >= 0.0 && tex.y < 1.0))\n"
-        "			return vec4(0.0, 0.0, 0.0, set_alpha);\n"
-        "		tex = (fract(tex) / wh.xy);\n"
+        "	if (repeat >= RepeatFix) {\n"
+        "		tex = rel_tex_coord(tex, wh, repeat);\n"
+        "		if (repeat == RepeatFix + RepeatNone) {\n"
+        "			if (!(tex.x >= 0.0 && tex.x < 1.0 && \n"
+        "			      tex.y >= 0.0 && tex.y < 1.0))\n"
+        "				return vec4(0.0, 0.0, 0.0, 0.0);\n"
+        "			tex = (fract(tex) / wh.xy);\n"
+        "		}\n"
         "	}\n"
-        "	if (set_alpha != 1)\n"
-        "		return texture2D(tex_image, tex);\n"
-        "	else\n"
-        "		return vec4(texture2D(tex_image, tex).rgb, 1.0);\n"
+        "	return texture2D(tex_image, tex);\n"
         "}\n";
 
     const char *source_solid_fetch =
@@ -132,11 +131,8 @@ glamor_create_composite_fs(struct shader_key *key)
         "uniform vec4 source_wh;"
         "vec4 get_source()\n"
         "{\n"
-        "	if (source_repeat_mode < RepeatFix)\n"
-        "		return texture2D(source_sampler, source_texture);\n"
-        "	else \n"
-        "		return rel_sampler(source_sampler, source_texture,\n"
-        "				   source_wh, source_repeat_mode, 0);\n"
+        "	return rel_sampler(source_sampler, source_texture,\n"
+        "			   source_wh, source_repeat_mode);\n"
         "}\n";
     const char *source_pixmap_fetch =
         "varying vec2 source_texture;\n"
@@ -144,11 +140,9 @@ glamor_create_composite_fs(struct shader_key *key)
         "uniform vec4 source_wh;\n"
         "vec4 get_source()\n"
         "{\n"
-        "	if (source_repeat_mode < RepeatFix) \n"
-        "		return vec4(texture2D(source_sampler, source_texture).rgb, 1);\n"
-        "	else \n"
-        "		return rel_sampler(source_sampler, source_texture,\n"
-        "				   source_wh, source_repeat_mode, 1);\n"
+        "	return vec4(rel_sampler(source_sampler, source_texture,\n"
+        "				source_wh, source_repeat_mode).rgb,\n"
+        "				1.0);\n"
         "}\n";
     const char *mask_none =
         "vec4 get_mask()\n"
@@ -167,11 +161,8 @@ glamor_create_composite_fs(struct shader_key *key)
         "uniform vec4 mask_wh;\n"
         "vec4 get_mask()\n"
         "{\n"
-        "	if (mask_repeat_mode < RepeatFix) \n"
-        "		return texture2D(mask_sampler, mask_texture);\n"
-        "	else \n"
-        "		return rel_sampler(mask_sampler, mask_texture,\n"
-        "				   mask_wh, mask_repeat_mode, 0);\n"
+        "	return rel_sampler(mask_sampler, mask_texture,\n"
+        "			   mask_wh, mask_repeat_mode);\n"
         "}\n";
     const char *mask_pixmap_fetch =
         "varying vec2 mask_texture;\n"
@@ -179,11 +170,8 @@ glamor_create_composite_fs(struct shader_key *key)
         "uniform vec4 mask_wh;\n"
         "vec4 get_mask()\n"
         "{\n"
-        "	if (mask_repeat_mode < RepeatFix) \n"
-        "		return vec4(texture2D(mask_sampler, mask_texture).rgb, 1);\n"
-        "	else \n"
-        "		return rel_sampler(mask_sampler, mask_texture,\n"
-        "				   mask_wh, mask_repeat_mode, 1);\n"
+        "	return vec4(rel_sampler(mask_sampler, mask_texture,\n"
+        "				mask_wh, mask_repeat_mode).rgb, 1.0);\n"
         "}\n";
 
     const char *dest_swizzle_default =
-- 
2.6.4



More information about the xorg-devel mailing list