<div dir="ltr">On 26 August 2013 15:12, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This patch implements pull constant upload, binding table upload, and<br>
surface setup for geometry shaders, by re-using vertex shader code<br>
that was generalized in previous patches.<br>
<br>
Based on work by Eric Anholt <<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>>.<br>
---<br>
src/mesa/drivers/dri/i965/Makefile.sources | 1 +<br>
src/mesa/drivers/dri/i965/brw_context.h | 2 +<br>
src/mesa/drivers/dri/i965/brw_gs_surface_state.c | 123 +++++++++++++++++++++++<br>
src/mesa/drivers/dri/i965/brw_state.h | 3 +<br>
src/mesa/drivers/dri/i965/brw_state_upload.c | 3 +<br>
5 files changed, 132 insertions(+)<br>
create mode 100644 src/mesa/drivers/dri/i965/brw_gs_surface_state.c<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources<br>
index 290cd93..81a16ff 100644<br>
--- a/src/mesa/drivers/dri/i965/Makefile.sources<br>
+++ b/src/mesa/drivers/dri/i965/Makefile.sources<br>
@@ -63,6 +63,7 @@ i965_FILES = \<br>
brw_gs.c \<br>
brw_gs_emit.c \<br>
brw_gs_state.c \<br>
+ brw_gs_surface_state.c \<br>
brw_interpolation_map.c \<br>
brw_lower_texture_gradients.cpp \<br>
brw_misc_state.c \<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
index 35193a6..622b5c8 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
@@ -148,6 +148,7 @@ enum brw_state_id {<br>
BRW_STATE_BATCH,<br>
BRW_STATE_INDEX_BUFFER,<br>
BRW_STATE_VS_CONSTBUF,<br>
+ BRW_STATE_GS_CONSTBUF,<br>
BRW_STATE_PROGRAM_CACHE,<br>
BRW_STATE_STATE_BASE_ADDRESS,<br>
BRW_STATE_VUE_MAP_VS,<br>
@@ -185,6 +186,7 @@ enum brw_state_id {<br>
/** \see brw.state.depth_region */<br>
#define BRW_NEW_INDEX_BUFFER (1 << BRW_STATE_INDEX_BUFFER)<br>
#define BRW_NEW_VS_CONSTBUF (1 << BRW_STATE_VS_CONSTBUF)<br>
+#define BRW_NEW_GS_CONSTBUF (1 << BRW_STATE_GS_CONSTBUF)<br>
#define BRW_NEW_PROGRAM_CACHE (1 << BRW_STATE_PROGRAM_CACHE)<br>
#define BRW_NEW_STATE_BASE_ADDRESS (1 << BRW_STATE_STATE_BASE_ADDRESS)<br>
#define BRW_NEW_VUE_MAP_VS (1 << BRW_STATE_VUE_MAP_VS)<br>
diff --git a/src/mesa/drivers/dri/i965/brw_gs_surface_state.c b/src/mesa/drivers/dri/i965/brw_gs_surface_state.c<br>
new file mode 100644<br>
index 0000000..d3d48ff<br>
--- /dev/null<br>
+++ b/src/mesa/drivers/dri/i965/brw_gs_surface_state.c<br>
@@ -0,0 +1,123 @@<br>
+/*<br>
+ * Copyright © 2013 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "main/mtypes.h"<br>
+#include "program/prog_parameter.h"<br>
+<br>
+#include "brw_context.h"<br>
+#include "brw_state.h"<br>
+<br>
+<br>
+/* Creates a new GS constant buffer reflecting the current GS program's<br>
+ * constants, if needed by the GS program.<br>
+ *<br>
+ * Otherwise, constants go through the CURBEs using the brw_constant_buffer<br>
+ * state atom.<br>
+ */<br>
+static void<br>
+brw_upload_gs_pull_constants(struct brw_context *brw)<br>
+{<br>
+ struct brw_vec4_context_base *vec4_ctx = &brw->gs.base;<br>
+<br>
+ /* BRW_NEW_GEOMETRY_PROGRAM */<br>
+ struct brw_geometry_program *gp =<br>
+ (struct brw_geometry_program *) brw->geometry_program;<br>
+<br>
+ if (!gp)<br>
+ return;<br>
+<br>
+ /* CACHE_NEW_GS_PROG */<br>
+ const struct brw_vec4_prog_data *prog_data = &brw->gs.prog_data->base;<br>
+<br>
+ /* _NEW_PROGRAM_CONSTANTS */<br>
+ brw_upload_vec4_pull_constants(brw, BRW_NEW_GS_CONSTBUF, &gp->program.Base,<br>
+ vec4_ctx, prog_data);<br>
+}<br>
+<br>
+const struct brw_tracked_state brw_gs_pull_constants = {<br>
+ .dirty = {<br>
+ .mesa = (_NEW_PROGRAM_CONSTANTS),<br>
+ .brw = (BRW_NEW_BATCH | BRW_NEW_GEOMETRY_PROGRAM),<br>
+ .cache = CACHE_NEW_GS_PROG,<br>
+ },<br>
+ .emit = brw_upload_gs_pull_constants,<br>
+};<br>
+<br>
+static void<br>
+brw_upload_gs_ubo_surfaces(struct brw_context *brw)<br>
+{<br>
+ struct gl_context *ctx = &brw->ctx;<br>
+ struct brw_vec4_context_base *vec4_ctx = &brw->gs.base;<br>
+<br>
+ /* _NEW_PROGRAM */<br>
+ struct gl_shader_program *prog = ctx->Shader.CurrentGeometryProgram;<br>
+<br>
+ if (!prog)<br>
+ return;<br>
+<br>
+ brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],<br>
+ &vec4_ctx->surf_offset[SURF_INDEX_VEC4_UBO(0)]);<br>
+}<br>
+<br>
+const struct brw_tracked_state brw_gs_ubo_surfaces = {<br>
+ .dirty = {<br>
+ .mesa = (_NEW_PROGRAM |<br>
+ _NEW_BUFFER_OBJECT),<br>
+ .brw = BRW_NEW_BATCH,<br>
+ .cache = 0,<br></blockquote><div><br></div><div>Whoops, I neglected to account for commit 77d8fbc (mesa: add & use a new driver flag for UBO updates instead of _NEW_BUFFER_OBJECT). This should be:<br><br> .dirty = {<br>
.mesa = _NEW_PROGRAM,<br> .brw = BRW_NEW_BATCH | BRW_NEW_UNIFORM_BUFFER,<br> .cache = 0,<br> },<br><br></div><div>I've fixed it in my "gs" branch.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ },<br>
+ .emit = brw_upload_gs_ubo_surfaces,<br>
+};<br>
+<br>
+<br>
+/**<br>
+ * Constructs the binding table for the WM surface state, which maps unit<br>
+ * numbers to surface state objects.<br>
+ */<br>
+static void<br>
+brw_gs_upload_binding_table(struct brw_context *brw)<br>
+{<br>
+ struct brw_vec4_context_base *vec4_ctx = &brw->gs.base;<br>
+<br>
+ /* If there's no GS, skip changing anything. */<br>
+ if (!brw->gs.prog_data)<br>
+ return;<br>
+<br>
+ /* CACHE_NEW_GS_PROG */<br>
+ const struct brw_vec4_prog_data *prog_data = &brw->gs.prog_data->base;<br>
+<br>
+ /* BRW_NEW_SURFACES and BRW_NEW_GS_CONSTBUF */<br>
+ brw_vec4_upload_binding_table(brw, BRW_NEW_GS_BINDING_TABLE, vec4_ctx,<br>
+ prog_data);<br>
+}<br>
+<br>
+const struct brw_tracked_state brw_gs_binding_table = {<br>
+ .dirty = {<br>
+ .mesa = 0,<br>
+ .brw = (BRW_NEW_BATCH |<br>
+ BRW_NEW_GS_CONSTBUF |<br>
+ BRW_NEW_SURFACES),<br>
+ .cache = CACHE_NEW_GS_PROG<br>
+ },<br>
+ .emit = brw_gs_upload_binding_table,<br>
+};<br>
diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h<br>
index 3a2f54f..72ac84c 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_state.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_state.h<br>
@@ -47,6 +47,7 @@ extern const struct brw_tracked_state brw_cc_unit;<br>
extern const struct brw_tracked_state brw_clip_prog;<br>
extern const struct brw_tracked_state brw_clip_unit;<br>
extern const struct brw_tracked_state brw_vs_pull_constants;<br>
+extern const struct brw_tracked_state brw_gs_pull_constants;<br>
extern const struct brw_tracked_state brw_wm_pull_constants;<br>
extern const struct brw_tracked_state brw_constant_buffer;<br>
extern const struct brw_tracked_state brw_curbe_offsets;<br>
@@ -69,11 +70,13 @@ extern const struct brw_tracked_state brw_urb_fence;<br>
extern const struct brw_tracked_state brw_vs_prog;<br>
extern const struct brw_tracked_state brw_vs_samplers;<br>
extern const struct brw_tracked_state brw_vs_ubo_surfaces;<br>
+extern const struct brw_tracked_state brw_gs_ubo_surfaces;<br>
extern const struct brw_tracked_state brw_vs_unit;<br>
extern const struct brw_tracked_state brw_wm_prog;<br>
extern const struct brw_tracked_state brw_renderbuffer_surfaces;<br>
extern const struct brw_tracked_state brw_texture_surfaces;<br>
extern const struct brw_tracked_state brw_wm_binding_table;<br>
+extern const struct brw_tracked_state brw_gs_binding_table;<br>
extern const struct brw_tracked_state brw_vs_binding_table;<br>
extern const struct brw_tracked_state brw_wm_ubo_surfaces;<br>
extern const struct brw_tracked_state brw_wm_unit;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c<br>
index 9638c69..0d77c9e 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c<br>
@@ -202,11 +202,14 @@ static const struct brw_tracked_state *gen7_atoms[] =<br>
*/<br>
&brw_vs_pull_constants,<br>
&brw_vs_ubo_surfaces,<br>
+ &brw_gs_pull_constants,<br>
+ &brw_gs_ubo_surfaces,<br>
&brw_wm_pull_constants,<br>
&brw_wm_ubo_surfaces,<br>
&gen6_renderbuffer_surfaces,<br>
&brw_texture_surfaces,<br>
&brw_vs_binding_table,<br>
+ &brw_gs_binding_table,<br>
&brw_wm_binding_table,<br>
<br>
&brw_fs_samplers,<br>
<span><font color="#888888">--<br>
1.8.4<br>
<br>
</font></span></blockquote></div><br></div></div>