glamor: * 1/size is faster than / size in VS
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@keithp.com> Signed-off-by: Eric Anholt <eric@anholt.net> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
		
							parent
							
								
									82634d2b69
								
							
						
					
					
						commit
						e977b404d7
					
				| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -160,7 +160,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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +176,7 @@ glamor_set_texture(PixmapPtr    pixmap,
 | 
			
		|||
    glBindTexture(GL_TEXTURE_2D, texture_priv->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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -184,7 +184,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;
 | 
			
		||||
| 
						 | 
				
			
			@ -197,7 +197,7 @@ glamor_set_tiled(PixmapPtr      pixmap,
 | 
			
		|||
                              -gc->patOrg.x,
 | 
			
		||||
                              -gc->patOrg.y,
 | 
			
		||||
                              offset_uniform,
 | 
			
		||||
                              size_uniform);
 | 
			
		||||
                              size_inv_uniform);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PixmapPtr
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue