st/mesa: factor ucp-lowering logic into helper