+ /* From the PRM Volume 2 part 1, section 1.4.7:
+ *
+ * Because of a urb corruption caused by allocating a previous gsunit’s
+ * urb entry to vsunit software is required to send a "GS NULL
+ * Fence"(Send URB fence with VS URB size == 1 and GS URB size == 0) plus
+ * a dummy DRAW call before any case where VS will be taking over GS URB
+ * space.
+ *
+ * It is not clear exactly what this means ("URB fence" is a command that
+ * doesn't exist on Gen6). So for now we just do a full pipeline flush as
+ * a workaround.
+ */
+ if (brw->urb.gs_present && !gs_present)
+ brw_emit_mi_flush(brw);
+ brw->urb.gs_present = gs_present;
+}
+
+static void
+upload_urb(struct brw_context *brw)
+{
+ /* BRW_NEW_VS_PROG_DATA */
+ const struct brw_vue_prog_data *vs_vue_prog_data =
+ brw_vue_prog_data(brw->vs.base.prog_data);
+ const unsigned vs_size = MAX2(vs_vue_prog_data->urb_entry_size, 1);
+
+ /* BRW_NEW_GEOMETRY_PROGRAM, BRW_NEW_GS_PROG_DATA */
+ const bool gs_present =
+ brw->ff_gs.prog_active || brw->programs[MESA_SHADER_GEOMETRY];
+
+ /* Whe using GS to do transform feedback only we use the same VUE layout for
+ * VS outputs and GS outputs (as it's what the SF and Clipper expect), so we
+ * can simply make the GS URB entry size the same as for the VS. This may
+ * technically be too large in cases where we have few vertex attributes and
+ * a lot of varyings, since the VS size is determined by the larger of the
+ * two. For now, it's safe.
+ *
+ * For user-provided GS the assumption above does not hold since the GS
+ * outputs can be different from the VS outputs.
+ */
+ unsigned gs_size = vs_size;
+ if (brw->programs[MESA_SHADER_GEOMETRY]) {
+ const struct brw_vue_prog_data *gs_vue_prog_data =
+ brw_vue_prog_data(brw->gs.base.prog_data);
+ gs_size = gs_vue_prog_data->urb_entry_size;
+ assert(gs_size >= 1);
+ }
+
+ gen6_upload_urb(brw, vs_size, gs_present, gs_size);