+static const GLuint stage_to_bt_edit[] = {
+ [MESA_SHADER_VERTEX] = _3DSTATE_BINDING_TABLE_EDIT_VS,
+ [MESA_SHADER_GEOMETRY] = _3DSTATE_BINDING_TABLE_EDIT_GS,
+ [MESA_SHADER_FRAGMENT] = _3DSTATE_BINDING_TABLE_EDIT_PS,
+};
+
+static uint32_t
+reserve_hw_bt_space(struct brw_context *brw, unsigned bytes)
+{
+ /* From the Broadwell PRM, Volume 16, "Workarounds",
+ * WaStateBindingTableOverfetch:
+ * "HW over-fetches two cache lines of binding table indices. When
+ * using the resource streamer, SW needs to pad binding table pointer
+ * updates with an additional two cache lines."
+ *
+ * Cache lines are 64 bytes, so we subtract 128 bytes from the size of
+ * the binding table pool buffer.
+ */
+ if (brw->hw_bt_pool.next_offset + bytes >= brw->hw_bt_pool.bo->size - 128) {
+ gen7_reset_hw_bt_pool_offsets(brw);
+ }
+
+ uint32_t offset = brw->hw_bt_pool.next_offset;
+
+ /* From the Haswell PRM, Volume 2b: Command Reference: Instructions,
+ * 3DSTATE_BINDING_TABLE_POINTERS_xS:
+ *
+ * "If HW Binding Table is enabled, the offset is relative to the
+ * Binding Table Pool Base Address and the alignment is 64 bytes."
+ */
+ brw->hw_bt_pool.next_offset += ALIGN(bytes, 64);
+
+ return offset;
+}
+