Perhaps, what we are missing here is - add tracking for the pipeline stages each resource is requeted in? I.e. img.transit() would receive an extra parameter of PipelineStage (a bit mask), and it would return a pair of (barrier, old_stage_mask) for us to use. If mixing barriers of multiple transit() results, we'd be ORRing the stages, e.g. old_stage_mask1 | old_stage_mask2.
Benefits: We can merge barriers with ORRing the stages.
As an extra we could extend the resources to track the previous stage and state it had and could transit back if needed.
From https://github.com/szeged/webrender/pull/308#discussion_r323830142:
Benefits: We can merge barriers with ORRing the stages. As an extra we could extend the resources to track the previous stage and state it had and could transit back if needed.