[PATCH] glamor: * 1/size is faster than / size in VS
Keith Packard
keithp at keithp.com
Fri Jan 16 10:44:27 PST 2015
Pass the inverse of the texture size to glamor vertex shaders so that
we multiply by that instead of dividing by the size as multiplication
is generally faster than division.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
glamor/glamor_copy.c | 8 ++++----
glamor/glamor_program.c | 16 ++++++++--------
glamor/glamor_program.h | 2 +-
glamor/glamor_transform.c | 8 ++++----
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c
index 3320935..ea26361 100644
--- a/glamor/glamor_copy.c
+++ b/glamor/glamor_copy.c
@@ -42,7 +42,7 @@ use_copyarea(PixmapPtr dst, GCPtr gc, glamor_program *prog, void *arg)
glBindTexture(GL_TEXTURE_2D, src->tex);
glUniform2f(prog->fill_offset_uniform, args->dx, args->dy);
- glUniform2f(prog->fill_size_uniform, src->width, src->height);
+ glUniform2f(prog->fill_size_inv_uniform, 1.0f/src->width, 1.0f/src->height);
return TRUE;
}
@@ -51,7 +51,7 @@ static const glamor_facet glamor_facet_copyarea = {
"copy_area",
.vs_vars = "attribute vec2 primitive;\n",
.vs_exec = (GLAMOR_POS(gl_Position, primitive.xy)
- " fill_pos = (fill_offset + primitive.xy) / fill_size;\n"),
+ " fill_pos = (fill_offset + primitive.xy) * fill_size_inv;\n"),
.fs_exec = " gl_FragColor = texture2D(sampler, fill_pos);\n",
.locations = glamor_program_location_fill,
.use = use_copyarea,
@@ -71,7 +71,7 @@ use_copyplane(PixmapPtr dst, GCPtr gc, glamor_program *prog, void *arg)
glBindTexture(GL_TEXTURE_2D, src->tex);
glUniform2f(prog->fill_offset_uniform, args->dx, args->dy);
- glUniform2f(prog->fill_size_uniform, src->width, src->height);
+ glUniform2f(prog->fill_size_inv_uniform, 1.0f/src->width, 1.0f/src->height);
glamor_set_color(dst, gc->fgPixel, prog->fg_uniform);
glamor_set_color(dst, gc->bgPixel, prog->bg_uniform);
@@ -134,7 +134,7 @@ static const glamor_facet glamor_facet_copyplane = {
.version = 130,
.vs_vars = "attribute vec2 primitive;\n",
.vs_exec = (GLAMOR_POS(gl_Position, (primitive.xy))
- " fill_pos = (fill_offset + primitive.xy) / fill_size;\n"),
+ " fill_pos = (fill_offset + primitive.xy) * fill_size_inv;\n"),
.fs_exec = (" uvec4 bits = uvec4(round(texture2D(sampler, fill_pos) * bitmul));\n"
" if ((bits & bitplane) != uvec4(0,0,0,0))\n"
" gl_FragColor = fg;\n"
diff --git a/glamor/glamor_program.c b/glamor/glamor_program.c
index 1d0328f..451e5e3 100644
--- a/glamor/glamor_program.c
+++ b/glamor/glamor_program.c
@@ -40,12 +40,12 @@ const glamor_facet glamor_fill_solid = {
static Bool
use_tile(PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg)
{
- return glamor_set_tiled(pixmap, gc, prog->fill_offset_uniform, prog->fill_size_uniform);
+ return glamor_set_tiled(pixmap, gc, prog->fill_offset_uniform, prog->fill_size_inv_uniform);
}
static const glamor_facet glamor_fill_tile = {
.name = "tile",
- .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) / fill_size;\n",
+ .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) * fill_size_inv;\n",
.fs_exec = " gl_FragColor = texture2D(sampler, fill_pos);\n",
.locations = glamor_program_location_fill,
.use = use_tile,
@@ -56,12 +56,12 @@ use_stipple(PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg)
{
return glamor_set_stippled(pixmap, gc, prog->fg_uniform,
prog->fill_offset_uniform,
- prog->fill_size_uniform);
+ prog->fill_size_inv_uniform);
}
static const glamor_facet glamor_fill_stipple = {
.name = "stipple",
- .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) / fill_size;\n",
+ .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) * fill_size_inv;\n",
.fs_exec = (" float a = texture2D(sampler, fill_pos).w;\n"
" if (a == 0.0)\n"
" discard;\n"
@@ -81,7 +81,7 @@ use_opaque_stipple(PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg)
static const glamor_facet glamor_fill_opaque_stipple = {
.name = "opaque_stipple",
- .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) / fill_size;\n",
+ .vs_exec = " fill_pos = (fill_offset + primitive.xy + pos) * fill_size_inv;\n",
.fs_exec = (" float a = texture2D(sampler, fill_pos).w;\n"
" if (a == 0.0)\n"
" gl_FragColor = bg;\n"
@@ -116,10 +116,10 @@ static glamor_location_var location_vars[] = {
{
.location = glamor_program_location_fill,
.vs_vars = ("uniform vec2 fill_offset;\n"
- "uniform vec2 fill_size;\n"
+ "uniform vec2 fill_size_inv;\n"
"varying vec2 fill_pos;\n"),
.fs_vars = ("uniform sampler2D sampler;\n"
- "uniform vec2 fill_size;\n"
+ "uniform vec2 fill_size_inv;\n"
"varying vec2 fill_pos;\n")
},
{
@@ -336,7 +336,7 @@ glamor_build_program(ScreenPtr screen,
prog->fg_uniform = glamor_get_uniform(prog, glamor_program_location_fg, "fg");
prog->bg_uniform = glamor_get_uniform(prog, glamor_program_location_bg, "bg");
prog->fill_offset_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_offset");
- prog->fill_size_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_size");
+ prog->fill_size_inv_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_size_inv");
prog->font_uniform = glamor_get_uniform(prog, glamor_program_location_font, "font");
prog->bitplane_uniform = glamor_get_uniform(prog, glamor_program_location_bitplane, "bitplane");
prog->bitmul_uniform = glamor_get_uniform(prog, glamor_program_location_bitplane, "bitmul");
diff --git a/glamor/glamor_program.h b/glamor/glamor_program.h
index 56ba03a..fa3877c 100644
--- a/glamor/glamor_program.h
+++ b/glamor/glamor_program.h
@@ -60,7 +60,7 @@ struct _glamor_program {
GLint matrix_uniform;
GLint fg_uniform;
GLint bg_uniform;
- GLint fill_size_uniform;
+ GLint fill_size_inv_uniform;
GLint fill_offset_uniform;
GLint font_uniform;
GLint bitplane_uniform;
diff --git a/glamor/glamor_transform.c b/glamor/glamor_transform.c
index c1df560..ad82dce 100644
--- a/glamor/glamor_transform.c
+++ b/glamor/glamor_transform.c
@@ -158,7 +158,7 @@ glamor_set_texture(PixmapPtr pixmap,
int off_x,
int off_y,
GLint offset_uniform,
- GLint size_uniform)
+ GLint size_inv_uniform)
{
glamor_pixmap_private *texture_priv;
@@ -174,7 +174,7 @@ glamor_set_texture(PixmapPtr pixmap,
glBindTexture(GL_TEXTURE_2D, texture_priv->base.fbo->tex);
glUniform2f(offset_uniform, off_x, off_y);
- glUniform2f(size_uniform, texture->drawable.width, texture->drawable.height);
+ glUniform2f(size_inv_uniform, 1.0f/texture->drawable.width, 1.0f/texture->drawable.height);
return TRUE;
}
@@ -182,7 +182,7 @@ Bool
glamor_set_tiled(PixmapPtr pixmap,
GCPtr gc,
GLint offset_uniform,
- GLint size_uniform)
+ GLint size_inv_uniform)
{
if (!glamor_set_alu(pixmap->drawable.pScreen, gc->alu))
return FALSE;
@@ -195,7 +195,7 @@ glamor_set_tiled(PixmapPtr pixmap,
-gc->patOrg.x,
-gc->patOrg.y,
offset_uniform,
- size_uniform);
+ size_inv_uniform);
}
static PixmapPtr
--
2.1.4
More information about the xorg-devel
mailing list