Steps to reproduce:
1. Open the user's attached project "MotionVectorsBug.zip"
2. Open "Scene/ShaderCalibration.unity"
3. Right-click on the game view tab and attach renderdoc
4. Enter play mode and observe the batch count in the statistics overlay. There should be ~70 batches with ~1850 saved by batching.
5. Take a renderdoc capture
6. Open the capture, and in the Event Browser find UIR.DrawChain->UniversalRenderPipeline.RenderSingleCameraInternal: Main Camera->ScriptableRenderer.Execute->DrawOpaqueObjects. Each call in the list after the first should be a simple DrawInstancedIndexed call that does not bind any new data.
7. Click the "Toggle Motion Vectors" button in the bottom left of the game view
8. The batch count should now be ~9000 with ~9000 saved by batching, and the frame times should increase by a few milliseconds
9. Take another renderdoc capture
10. Open the capture and find DrawOpaqueObjects in the event list again. Every call in the list should now needlessly rebind the exact same constant buffer to the vertex and pixel stages
Expected results: Enabling Motion Vector Per Object Data on a ScriptableRenderContext.DrawRenderers does not break static batching
Actual Results: Enabling Motion Vector Per Object Data on a ScriptableRenderContext.DrawRenderers breaks static batching
Reproducible in: URP 14.0.8 (2022.3.5f1)
Could not test on 2021.3.28f1, 2023.1.5f1, 2023.2.0b1 and 2023.3.0a1 due to the project using a modified version of URP package
Environment tested on: Windows 10
Notes:
-The example project includes a scene with several thousand static batched cubes, a slightly modified URP that adds the ability to toggle requiring PerObjectData.MotionVectors on the DrawObjectsPass class, and a simple shader that uses the unity_MatrixPreviousM and unity_MatrixPreviousMI matrices
-Adding MotionVectors to the DrawingSettings.perObjectData flags used by ScriptableRenderContext.DrawRenderers breaks static batching for objects whose shaders utilize the unity_MatrixPreviousM or unity_MatrixPreviousMI matrices. Enabling this flag causes each draw call for static batched objects to rebind the same UnityPerDraw constant buffer over and over. For static-batched objects, the previous frame matrices should not change and should be treated the same way as the current frame's object-to-world and world-to-object matrices which do not require rebinding the UnityPerDraw constant buffer.