+ /* We have two scenarios here:
+ * 1) We are using a geometry shader only to implement transform feedback
+ * for a vertex shader (brw->geometry_program == NULL). In this case, we
+ * only need surfaces for transform feedback in the GS stage.
+ * 2) We have a user-provided geometry shader. In this case we may need
+ * surfaces for transform feedback and/or other stuff, like textures,
+ * in the GS stage.
+ */
+
+ if (!brw->geometry_program) {
+ /* BRW_NEW_VERTEX_PROGRAM */
+ shaderprog = ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
+ if (shaderprog) {
+ /* Skip making a binding table if we don't have anything to put in it */
+ const struct gl_transform_feedback_info *linked_xfb_info =
+ &shaderprog->LinkedTransformFeedback;
+ need_binding_table = linked_xfb_info->NumOutputs > 0;
+ }
+ if (!need_binding_table) {
+ if (brw->ff_gs.bind_bo_offset != 0) {
+ brw->ctx.NewDriverState |= BRW_NEW_BINDING_TABLE_POINTERS;
+ brw->ff_gs.bind_bo_offset = 0;
+ }
+ return;
+ }
+
+ /* Might want to calculate nr_surfaces first, to avoid taking up so much
+ * space for the binding table. Anyway, in this case we know that we only
+ * use BRW_MAX_SOL_BINDINGS surfaces at most.
+ */
+ bind = brw_state_batch(brw, AUB_TRACE_BINDING_TABLE,
+ sizeof(uint32_t) * BRW_MAX_SOL_BINDINGS,
+ 32, &brw->ff_gs.bind_bo_offset);
+
+ /* BRW_NEW_SURFACES */
+ memcpy(bind, brw->ff_gs.surf_offset,
+ BRW_MAX_SOL_BINDINGS * sizeof(uint32_t));
+ } else {
+ /* BRW_NEW_GEOMETRY_PROGRAM */
+ shaderprog = ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
+ if (shaderprog) {
+ /* Skip making a binding table if we don't have anything to put in it */
+ struct brw_stage_prog_data *prog_data = brw->gs.base.prog_data;
+ const struct gl_transform_feedback_info *linked_xfb_info =
+ &shaderprog->LinkedTransformFeedback;
+ need_binding_table = linked_xfb_info->NumOutputs > 0 ||
+ prog_data->binding_table.size_bytes > 0;
+ }
+ if (!need_binding_table) {
+ if (brw->gs.base.bind_bo_offset != 0) {
+ brw->gs.base.bind_bo_offset = 0;
+ brw->ctx.NewDriverState |= BRW_NEW_BINDING_TABLE_POINTERS;
+ }
+ return;
+ }
+
+ /* Might want to calculate nr_surfaces first, to avoid taking up so much
+ * space for the binding table.
+ */
+ bind = brw_state_batch(brw, AUB_TRACE_BINDING_TABLE,
+ sizeof(uint32_t) * BRW_MAX_SURFACES,
+ 32, &brw->gs.base.bind_bo_offset);
+
+ /* BRW_NEW_SURFACES */
+ memcpy(bind, brw->gs.base.surf_offset,
+ BRW_MAX_SURFACES * sizeof(uint32_t));
+ }
+
+ brw->ctx.NewDriverState |= BRW_NEW_BINDING_TABLE_POINTERS;