The idea is that we can avoid flushing the job when the current draw call reads from the output of a previous TF draw, and instead use built-in hardware support to flush the TF writes before we emit the read. The series implements this in the following way:
The first patch marks resources written by TF in each job. We need this so we can then identify when we read from them in the same job and activate the optimization. I decided to use another set for this so we don't have to wrap our pipe_resources only for this, which would require to allocate memory for the wrapper object and wold be a more intrusive. Since we only need to do this tracking for this particular optimization I think this should be okay.
The second patch detects reads from previous TF writes in the same job by checking the current draw state against the list of resources written by TF in the same job and emits the 'wait for transform feedback' command if needed.
The third patch modifies v3d_flush_jobs_writing_resource() to skip the flush for the cases where we should be emitting 'wait for transform feedback'. The only case where we don't want to do this is when the TF write -> read dependency doesn't come from a new draw call, but from the user mapping the TF buffer, in which case we always need to flush. This is handled by adding a new parameter to v3d_flush_jobs_writing_resource() to indicate whether we want to skip any write flush optimizations.