Add state caching for stencil test.