cso: add context cleanup code from st/mesa