[Mesa-dev] [PATCH 05/22] i965/meta: Use explicit uniform locations in stencil blit shaders
Iago Toral
itoral at igalia.com
Thu Feb 18 15:35:39 UTC 2016
On Thu, 2016-02-18 at 16:34 +0100, Iago Toral wrote:
> On Wed, 2016-02-17 at 17:57 -0800, Ian Romanick wrote:
> > From: Ian Romanick <ian.d.romanick at intel.com>
> >
> > Skip all this _mesa_GetUniformLocation nonsense. We can just tell the
> > linker where to put the uniforms.
> >
> > This makes the text size slightly larger (at least on x64) because
> > "layout(location=X)" is quite a few characters, and it is repeated 13
> > times.
> >
> > text data bss dec hex filename
> > 5127112 209888 28120 5365120 51dd80 before-64/lib64/i965_dri.so
> > 5127144 209888 28120 5365152 51dda0 after-64/lib64/i965_dri.so
> >
> > Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> > ---
> > src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c | 107 +++++++++++++++-------
> > 1 file changed, 72 insertions(+), 35 deletions(-)
> >
> > diff --git a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
> > index b1a4950..de0db5d 100644
> > --- a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
> > +++ b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
> > @@ -92,6 +92,29 @@ static const struct sampler_and_fetch {
> > " out_color = texelFetch(texSampler, txl_coords, sample_index)" }
> > };
> >
> > +#define stringify(x) # x
> > +#define stringify_value(x) stringify(x)
> > +
> > +#define DECLARE_UNIFORM(type, name) \
> > + "layout(location=" stringify_value(name ## _loc) ")uniform " # type " " # name ";\n"
> > +
> > +/* We can't use an enum for this because of the preprocessor stringify
> > + * techinique.
> > + */
> > +#define src_x_scale_loc 0
> > +#define src_y_scale_loc 1
> > +#define src_x_off_loc 2
> > +#define src_y_off_loc 3
> > +#define dst_x_off_loc 4
> > +#define dst_y_off_loc 5
> > +#define draw_rect_w_loc 6
> > +#define draw_rect_h_loc 7
> > +#define dst_x0_loc 8
> > +#define dst_x1_loc 9
> > +#define dst_y0_loc 10
> > +#define dst_y1_loc 11
> > +#define dst_num_samples_loc 12
> > +
> > /**
> > * Translating Y-tiled to W-tiled:
> > *
> > @@ -100,20 +123,37 @@ static const struct sampler_and_fetch {
> > */
> > static const char *fs_tmpl =
> > "#version 130\n"
> > + /* GL_ARB_explicit_uniform_location requires either GLSL 3.30 or
> > + * GL_ARB_explicit_attrib_location, and only the later is universally
> > + * supported.
> > + */
> > + "#extension GL_ARB_explicit_attrib_location: require\n"
> > + "#extension GL_ARB_explicit_uniform_location: require\n"
> > "%s"
> > - "uniform float src_x_scale;\n"
> > - "uniform float src_y_scale;\n"
> > - "uniform float src_x_off;\n" /* Top right coordinates of the source */
> > - "uniform float src_y_off;\n" /* rectangle in W-tiled space. */
> > - "uniform float dst_x_off;\n" /* Top right coordinates of the target */
> > - "uniform float dst_y_off;\n" /* rectangle in Y-tiled space. */
> > - "uniform float draw_rect_w;\n" /* This is the unnormalized size of the */
> > - "uniform float draw_rect_h;\n" /* drawing rectangle in Y-tiled space. */
> > - "uniform int dst_x0;\n" /* This is the bounding rectangle in the W-tiled */
> > - "uniform int dst_x1;\n" /* space that will be used to skip pixels lying */
> > - "uniform int dst_y0;\n" /* outside. In some cases the Y-tiled rectangle */
> > - "uniform int dst_y1;\n" /* is larger. */
> > - "uniform int dst_num_samples;\n"
> > + DECLARE_UNIFORM(float, src_x_scale)
> > + DECLARE_UNIFORM(float, src_y_scale)
> > +
> > + /* Top right coordinates of the source rectangle in W-tiled space. */
> > + DECLARE_UNIFORM(float, src_x_off)
> > + DECLARE_UNIFORM(float, src_y_off)
> > +
> > + /* Top right coordinates of the target rectangle in Y-tiled space. */
> > + DECLARE_UNIFORM(float, dst_x_off)
> > + DECLARE_UNIFORM(float, dst_y_off)
> > +
> > + /* Unnormalized size of the drawing rectangle in Y-tiled space. */
> > + DECLARE_UNIFORM(float, draw_rect_w)
> > + DECLARE_UNIFORM(float, draw_rect_h)
> > +
> > + /* Bounding rectangle in the W-tiled space that will be used to skip pixels
> > + * lying outside. In some cases the Y-tiled rectangle is larger.
> > + */
> > + DECLARE_UNIFORM(int, dst_x0)
> > + DECLARE_UNIFORM(int, dst_x1)
> > + DECLARE_UNIFORM(int, dst_y0)
> > + DECLARE_UNIFORM(int, dst_y1)
> > +
> > + DECLARE_UNIFORM(int, dst_num_samples)
> > "in vec2 tex_coords;\n"
> > "ivec2 txl_coords;\n"
> > "int sample_index;\n"
> > @@ -200,12 +240,12 @@ static const char *fs_tmpl =
> > * 16x2 y-tiled).
> > */
> > static void
> > -setup_bounding_rect(GLuint prog, const struct blit_dims *dims)
> > +setup_bounding_rect(const struct blit_dims *dims)
> > {
> > - _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_x0"), dims->dst_x0);
> > - _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_x1"), dims->dst_x1);
> > - _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_y0"), dims->dst_y0);
> > - _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_y1"), dims->dst_y1);
> > + _mesa_Uniform1i(dst_x0_loc, dims->dst_x0);
> > + _mesa_Uniform1i(dst_x1_loc, dims->dst_x1);
> > + _mesa_Uniform1i(dst_y0_loc, dims->dst_y0);
> > + _mesa_Uniform1i(dst_y1_loc, dims->dst_y1);
> > }
> >
> > /**
> > @@ -214,14 +254,12 @@ setup_bounding_rect(GLuint prog, const struct blit_dims *dims)
> > * between destination and source that may have differing offsets.
> > */
> > static void
> > -setup_drawing_rect(GLuint prog, const struct blit_dims *dims)
> > +setup_drawing_rect(const struct blit_dims *dims)
> > {
> > - _mesa_Uniform1f(_mesa_GetUniformLocation(prog, "draw_rect_w"),
> > - dims->dst_x1 - dims->dst_x0);
> > - _mesa_Uniform1f(_mesa_GetUniformLocation(prog, "draw_rect_h"),
> > - dims->dst_y1 - dims->dst_y0);
> > - _mesa_Uniform1f(_mesa_GetUniformLocation(prog, "dst_x_off"), dims->dst_x0);
> > - _mesa_Uniform1f(_mesa_GetUniformLocation(prog, "dst_y_off"), dims->dst_y0);
> > + _mesa_Uniform1f(draw_rect_w_loc, dims->dst_x1 - dims->dst_x0);
> > + _mesa_Uniform1f(draw_rect_h_loc, dims->dst_y1 - dims->dst_y0);
> > + _mesa_Uniform1f(dst_x_off_loc, dims->dst_x0);
> > + _mesa_Uniform1f(dst_y_off_loc, dims->dst_y0);
> > }
> >
> > /**
> > @@ -264,15 +302,15 @@ setup_coord_coeff(GLuint multiplier, GLuint offset,
> > * destination rectangle is adjusted for possible msaa and Y-tiling.
> > */
> > static void
> > -setup_coord_transform(GLuint prog, const struct blit_dims *dims)
> > +setup_coord_transform(const struct blit_dims *dims)
> > {
> > - setup_coord_coeff(_mesa_GetUniformLocation(prog, "src_x_scale"),
> > - _mesa_GetUniformLocation(prog, "src_x_off"),
> > + setup_coord_coeff(src_x_scale_loc,
> > + src_x_off_loc,
> > dims->src_x0, dims->src_x1, dims->dst_x0, dims->dst_x1,
> > dims->mirror_x);
> >
> > - setup_coord_coeff(_mesa_GetUniformLocation(prog, "src_y_scale"),
> > - _mesa_GetUniformLocation(prog, "src_y_off"),
> > + setup_coord_coeff(src_y_scale_loc,
> > + src_y_off_loc,
> > dims->src_y0, dims->src_y1, dims->dst_y0, dims->dst_y1,
> > dims->mirror_y);
> > }
> > @@ -453,12 +491,11 @@ brw_meta_stencil_blit(struct brw_context *brw,
> > GL_STENCIL_INDEX);
> >
> > prog = setup_program(brw, target != GL_TEXTURE_2D);
>
> I think with the changes done in this patch we no longer require the
> prog local variable in this function and we should probably make
> setup_program return void instead.
Ah, you do this in the next patch, never mind :)
> > - setup_bounding_rect(prog, orig_dims);
> > - setup_drawing_rect(prog, &dims);
> > - setup_coord_transform(prog, orig_dims);
> > + setup_bounding_rect(orig_dims);
> > + setup_drawing_rect(&dims);
> > + setup_coord_transform(orig_dims);
> >
> > - _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_num_samples"),
> > - dst_mt->num_samples);
> > + _mesa_Uniform1i(dst_num_samples_loc, dst_mt->num_samples);
> >
> > prepare_vertex_data(ctx, ctx->Meta->Blit.buf_obj);
> > _mesa_set_viewport(ctx, 0, dims.dst_x0, dims.dst_y0,
>
More information about the mesa-dev
mailing list