aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2016-03-15 10:51:55 -0700
committerKenneth Graunke <[email protected]>2016-03-16 23:57:11 -0700
commit9c1e01c4a883ac4a738f6f8c17c0236621101e28 (patch)
tree95e41d3ec1ace577cc60f381ce94f9ba06e6a167 /src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
parent0fe254168be26e71777dc2648e86976bdcd2e707 (diff)
meta: Don't use integer handles for shaders or programs.
Previously, we gave our internal clear/blit shaders actual GL handles and stored them in the shader/program hash table. We used ordinary GL API entrypoints to work with them. We thought this shouldn't be a problem because GL doesn't allow applications to invent their own names for shaders or programs. GL allocates all names via glCreateShader and glCreateProgram. However, having them in the hash table is a bit risky: if a broken application guesses the name of our shaders or programs, it could alter them, potentially screwing up future meta operations. Also, test cases can observe the programs in the hash table. Running a single dEQP process that executes the following test list: dEQP-GLES3.functional.negative_api.buffer.clear dEQP-GLES3.functional.negative_api.shader.compile_shader dEQP-GLES3.functional.negative_api.shader.delete_shader would result in the last two tests breaking. The compile_shader test calls glCompileShader(9) straight away, and since it hasn't even created any shaders or programs, it expects to get a GL_INVALID_VALUE error because there's no such name. However, because the clear test ran first, it created Meta programs, so an object named "9" did exist. This patch reworks Meta to work with gl_shader and gl_shader_program pointers directly. These internal programs have bogus names, and are never stored in the hash tables, so they're invisible to applications. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94485 Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c')
-rw-r--r--src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c59
1 files changed, 32 insertions, 27 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 5b0c2e9bdd5..7e0424846a5 100644
--- a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
+++ b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
@@ -193,6 +193,9 @@ static const char *fs_tmpl =
" %s;\n"
"}\n";
+#define get_uniform_loc(sh_prog, name) \
+ _mesa_program_resource_location(sh_prog, GL_UNIFORM, name)
+
/**
* Setup uniforms telling the coordinates of the destination rectangle in the
* native w-tiled space. These are needed to ignore pixels that lie outside.
@@ -201,12 +204,13 @@ static const char *fs_tmpl =
* 16x2 y-tiled).
*/
static void
-setup_bounding_rect(GLuint prog, const struct blit_dims *dims)
+setup_bounding_rect(struct gl_shader_program *sh_prog,
+ 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(get_uniform_loc(sh_prog, "dst_x0"), dims->dst_x0);
+ _mesa_Uniform1i(get_uniform_loc(sh_prog, "dst_x1"), dims->dst_x1);
+ _mesa_Uniform1i(get_uniform_loc(sh_prog, "dst_y0"), dims->dst_y0);
+ _mesa_Uniform1i(get_uniform_loc(sh_prog, "dst_y1"), dims->dst_y1);
}
/**
@@ -215,14 +219,15 @@ 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(struct gl_shader_program *sh_prog,
+ const struct blit_dims *dims)
{
- _mesa_Uniform1f(_mesa_GetUniformLocation(prog, "draw_rect_w"),
+ _mesa_Uniform1f(get_uniform_loc(sh_prog, "draw_rect_w"),
dims->dst_x1 - dims->dst_x0);
- _mesa_Uniform1f(_mesa_GetUniformLocation(prog, "draw_rect_h"),
+ _mesa_Uniform1f(get_uniform_loc(sh_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(get_uniform_loc(sh_prog, "dst_x_off"), dims->dst_x0);
+ _mesa_Uniform1f(get_uniform_loc(sh_prog, "dst_y_off"), dims->dst_y0);
}
/**
@@ -241,7 +246,7 @@ setup_drawing_rect(GLuint prog, const struct blit_dims *dims)
* src_x = src_x0 + (dst_x1 -dst_x - 0.5) * scale
*/
static void
-setup_coord_coeff(GLuint prog, GLuint multiplier, GLuint offset,
+setup_coord_coeff(GLuint multiplier, GLuint offset,
int src_0, int src_1, int dst_0, int dst_1, bool mirror)
{
const float scale = ((float)(src_1 - src_0)) / (dst_1 - dst_0);
@@ -265,22 +270,21 @@ setup_coord_coeff(GLuint prog, 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(struct gl_shader_program *sh_prog,
+ const struct blit_dims *dims)
{
- setup_coord_coeff(prog,
- _mesa_GetUniformLocation(prog, "src_x_scale"),
- _mesa_GetUniformLocation(prog, "src_x_off"),
+ setup_coord_coeff(get_uniform_loc(sh_prog, "src_x_scale"),
+ get_uniform_loc(sh_prog, "src_x_off"),
dims->src_x0, dims->src_x1, dims->dst_x0, dims->dst_x1,
dims->mirror_x);
- setup_coord_coeff(prog,
- _mesa_GetUniformLocation(prog, "src_y_scale"),
- _mesa_GetUniformLocation(prog, "src_y_off"),
+ setup_coord_coeff(get_uniform_loc(sh_prog, "src_y_scale"),
+ get_uniform_loc(sh_prog, "src_y_off"),
dims->src_y0, dims->src_y1, dims->dst_y0, dims->dst_y1,
dims->mirror_y);
}
-static GLuint
+static struct gl_shader_program *
setup_program(struct brw_context *brw, bool msaa_tex)
{
struct gl_context *ctx = &brw->ctx;
@@ -291,21 +295,22 @@ setup_program(struct brw_context *brw, bool msaa_tex)
_mesa_meta_setup_vertex_objects(&brw->ctx, &blit->VAO, &blit->buf_obj, true,
2, 2, 0);
- GLuint *prog_id = &brw->meta_stencil_blit_programs[msaa_tex];
+ struct gl_shader_program **sh_prog_p =
+ &brw->meta_stencil_blit_programs[msaa_tex];
- if (*prog_id) {
- _mesa_UseProgram(*prog_id);
- return *prog_id;
+ if (*sh_prog_p) {
+ _mesa_meta_use_program(ctx, *sh_prog_p);
+ return *sh_prog_p;
}
fs_source = ralloc_asprintf(NULL, fs_tmpl, sampler->sampler,
sampler->fetch);
_mesa_meta_compile_and_link_program(ctx, vs_source, fs_source,
"i965 stencil blit",
- prog_id);
+ sh_prog_p);
ralloc_free(fs_source);
- return *prog_id;
+ return *sh_prog_p;
}
/**
@@ -425,7 +430,7 @@ brw_meta_stencil_blit(struct brw_context *brw,
struct gl_context *ctx = &brw->ctx;
struct blit_dims dims = *orig_dims;
struct fb_tex_blit_state blit;
- GLuint prog;
+ struct gl_shader_program *prog;
struct gl_framebuffer *drawFb = NULL;
struct gl_renderbuffer *rb = NULL;
GLenum target;
@@ -467,7 +472,7 @@ brw_meta_stencil_blit(struct brw_context *brw,
setup_drawing_rect(prog, &dims);
setup_coord_transform(prog, orig_dims);
- _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_num_samples"),
+ _mesa_Uniform1i(get_uniform_loc(prog, "dst_num_samples"),
dst_mt->num_samples);
prepare_vertex_data(ctx, ctx->Meta->Blit.buf_obj);