[Mesa-dev] [RFC PATCH 2/2] i965/gs: Precompile geometry shaders.
Paul Berry
stereotype441 at gmail.com
Wed Oct 23 19:29:08 CEST 2013
---
src/mesa/drivers/dri/i965/brw_context.h | 6 ++++++
src/mesa/drivers/dri/i965/brw_shader.cpp | 4 ++++
src/mesa/drivers/dri/i965/brw_vec4_gs.c | 34 ++++++++++++++++++++++++++++++++
src/mesa/drivers/dri/i965/brw_vec4_gs.h | 4 ++++
4 files changed, 48 insertions(+)
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 0229cc5..39f45c6 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1630,6 +1630,12 @@ brw_vertex_program_const(const struct gl_vertex_program *p)
return (const struct brw_vertex_program *) p;
}
+static INLINE struct brw_geometry_program *
+brw_geometry_program(struct gl_geometry_program *p)
+{
+ return (struct brw_geometry_program *) p;
+}
+
static INLINE struct brw_fragment_program *
brw_fragment_program(struct gl_fragment_program *p)
{
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 5992a1c..67084a7 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -26,6 +26,7 @@ extern "C" {
#include "brw_context.h"
}
#include "brw_vs.h"
+#include "brw_vec4_gs.h"
#include "brw_fs.h"
#include "glsl/ir_optimization.h"
#include "glsl/glsl_parser_extras.h"
@@ -70,6 +71,9 @@ brw_shader_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
if (brw->precompile && !brw_fs_precompile(ctx, prog))
return false;
+ if (brw->precompile && !brw_gs_precompile(ctx, prog))
+ return false;
+
if (brw->precompile && !brw_vs_precompile(ctx, prog))
return false;
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs.c b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
index b48422c..620be79 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs.c
@@ -306,6 +306,40 @@ const struct brw_tracked_state brw_gs_prog = {
bool
+brw_gs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
+{
+ struct brw_context *brw = brw_context(ctx);
+ struct brw_gs_prog_key key;
+ uint32_t old_prog_offset = brw->gs.base.prog_offset;
+ struct brw_gs_prog_data *old_prog_data = brw->gs.prog_data;
+ bool success;
+
+ if (!prog->_LinkedShaders[MESA_SHADER_GEOMETRY])
+ return true;
+
+ struct gl_geometry_program *gp = (struct gl_geometry_program *)
+ prog->_LinkedShaders[MESA_SHADER_GEOMETRY]->Program;
+ struct brw_geometry_program *bgp = brw_geometry_program(gp);
+
+ memset(&key, 0, sizeof(key));
+
+ brw_vec4_setup_prog_key_for_precompile(ctx, &key.base, bgp->id, &gp->Base);
+
+ /* Assume that the set of varyings coming in from the vertex shader exactly
+ * matches what the geometry shader requires.
+ */
+ key.input_varyings = gp->Base.InputsRead;
+
+ success = do_gs_prog(brw, prog, bgp, &key);
+
+ brw->gs.base.prog_offset = old_prog_offset;
+ brw->gs.prog_data = old_prog_data;
+
+ return success;
+}
+
+
+bool
brw_gs_prog_data_compare(const void *in_a, const void *in_b)
{
const struct brw_gs_prog_data *a = in_a;
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs.h b/src/mesa/drivers/dri/i965/brw_vec4_gs.h
index 8b979ac..b209d80 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_gs.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4_gs.h
@@ -30,6 +30,10 @@
extern "C" {
#endif
+struct gl_context;
+struct gl_shader_program;
+
+bool brw_gs_precompile(struct gl_context *ctx, struct gl_shader_program *prog);
bool brw_gs_prog_data_compare(const void *a, const void *b);
void brw_gs_prog_data_free(const void *in_prog_data);
--
1.8.4.1
More information about the mesa-dev
mailing list