meta: Merge compiling and linking of blit program
authorTopi Pohjolainen <topi.pohjolainen@intel.com>
Thu, 17 Apr 2014 23:21:13 +0000 (02:21 +0300)
committerTopi Pohjolainen <topi.pohjolainen@intel.com>
Mon, 12 May 2014 14:48:45 +0000 (17:48 +0300)
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/common/meta.c
src/mesa/drivers/common/meta.h
src/mesa/drivers/common/meta_blit.c

index b4c30564f931e609166905d8a765fdec3e41c597..3ef3f79714e12f82990adb8dcce3be1003d1e313 100644 (file)
@@ -204,6 +204,31 @@ _mesa_meta_link_program_with_debug(struct gl_context *ctx, GLuint program)
    return 0;
 }
 
+void
+_mesa_meta_compile_and_link_program(struct gl_context *ctx,
+                                    const char *vs_source,
+                                    const char *fs_source,
+                                    const char *name,
+                                    GLuint *program)
+{
+   GLuint vs = _mesa_meta_compile_shader_with_debug(ctx, GL_VERTEX_SHADER,
+                                                    vs_source);
+   GLuint fs = _mesa_meta_compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER,
+                                                    fs_source);
+
+   *program = _mesa_CreateProgram();
+   _mesa_AttachShader(*program, fs);
+   _mesa_DeleteShader(fs);
+   _mesa_AttachShader(*program, vs);
+   _mesa_DeleteShader(vs);
+   _mesa_BindAttribLocation(*program, 0, "position");
+   _mesa_BindAttribLocation(*program, 1, "texcoords");
+   _mesa_meta_link_program_with_debug(ctx, *program);
+   _mesa_ObjectLabel(GL_PROGRAM, *program, -1, name);
+
+   _mesa_UseProgram(*program);
+}
+
 /**
  * Generate a generic shader to blit from a texture to a framebuffer
  *
@@ -219,10 +244,8 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
 {
    const char *vs_source;
    char *fs_source;
-   GLuint vs, fs;
    void *const mem_ctx = ralloc_context(NULL);
    struct blit_shader *shader = choose_blit_shader(target, table);
-   char *name;
 
    assert(shader != NULL);
 
@@ -282,22 +305,12 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
                                   shader->texcoords);
    }
 
-   vs = _mesa_meta_compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_source);
-   fs = _mesa_meta_compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_source);
 
-   shader->shader_prog = _mesa_CreateProgram();
-   _mesa_AttachShader(shader->shader_prog, fs);
-   _mesa_DeleteShader(fs);
-   _mesa_AttachShader(shader->shader_prog, vs);
-   _mesa_DeleteShader(vs);
-   _mesa_BindAttribLocation(shader->shader_prog, 0, "position");
-   _mesa_BindAttribLocation(shader->shader_prog, 1, "texcoords");
-   _mesa_meta_link_program_with_debug(ctx, shader->shader_prog);
-   name = ralloc_asprintf(mem_ctx, "%s blit", shader->type);
-   _mesa_ObjectLabel(GL_PROGRAM, shader->shader_prog, -1, name);
+   _mesa_meta_compile_and_link_program(ctx, vs_source, fs_source,
+                                       ralloc_asprintf(mem_ctx, "%s blit",
+                                                       shader->type),
+                                       &shader->shader_prog);
    ralloc_free(mem_ctx);
-
-   _mesa_UseProgram(shader->shader_prog);
 }
 
 /**
index 32b71fae70930c2ca50c396c8b810bf42cd3b4d5..fdd8714a7a9280ac419d49fd0b5c1a74806103ed 100644 (file)
@@ -455,6 +455,13 @@ _mesa_meta_compile_shader_with_debug(struct gl_context *ctx, GLenum target,
 GLuint
 _mesa_meta_link_program_with_debug(struct gl_context *ctx, GLuint program);
 
+void
+_mesa_meta_compile_and_link_program(struct gl_context *ctx,
+                                    const char *vs_source,
+                                    const char *fs_source,
+                                    const char *name,
+                                    GLuint *program);
+
 GLboolean
 _mesa_meta_alloc_texture(struct temp_texture *tex,
                          GLsizei width, GLsizei height, GLenum intFormat);
index c3dc146147c9bc52211767ad5c388bd061cd144f..14ecf8f11eda1b2fbb3715cd3953b52ef36414cd 100644 (file)
@@ -62,7 +62,6 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
 {
    const char *vs_source;
    char *fs_source;
-   GLuint vs, fs;
    void *mem_ctx;
    enum blit_msaa_shader shader_index;
    bool dst_is_msaa = false;
@@ -314,21 +313,10 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
                                   sample_resolve);
    }
 
-   vs = _mesa_meta_compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_source);
-   fs = _mesa_meta_compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_source);
-
-   blit->msaa_shaders[shader_index] = _mesa_CreateProgram();
-   _mesa_AttachShader(blit->msaa_shaders[shader_index], fs);
-   _mesa_DeleteShader(fs);
-   _mesa_AttachShader(blit->msaa_shaders[shader_index], vs);
-   _mesa_DeleteShader(vs);
-   _mesa_BindAttribLocation(blit->msaa_shaders[shader_index], 0, "position");
-   _mesa_BindAttribLocation(blit->msaa_shaders[shader_index], 1, "texcoords");
-   _mesa_meta_link_program_with_debug(ctx, blit->msaa_shaders[shader_index]);
-   _mesa_ObjectLabel(GL_PROGRAM, blit->msaa_shaders[shader_index], -1, name);
-   ralloc_free(mem_ctx);
+   _mesa_meta_compile_and_link_program(ctx, vs_source, fs_source, name,
+                                       &blit->msaa_shaders[shader_index]);
 
-   _mesa_UseProgram(blit->msaa_shaders[shader_index]);
+   ralloc_free(mem_ctx);
 }
 
 static void