When using DispatchCompute in a command buffer, the render target set using SetRenderTarget is removed. This is unfortunate, since in my use case this means a large increase of render context switches, leading to frame rate drops.
Is this intended behaviour? Does the compute shader somehow require a render target switch? Or is this a bug?
This is the shortened version of the code in question, called every frame:
_commandBuffer.SetRenderTarget(PaintTexture);
_commandBuffer.ClearRenderTarget(true, true, Color.clear);
foreach (var projector in PaintProjector.Manifest)
{
_commandBuffer.DrawMesh(PaintMesh, Matrix4x4.identity, updatedProjectorMaterial);
_commandBuffer.DispatchCompute(...);
}
Graphics.ExecuteCommandBuffer(_commandBuffer);
_commandBuffer.Clear();
When SetRenderTarget is outside the loop and DispatchCompute is commented out, it works as expected. When DispatchCompute is called, the render target is cleared after the first execution of the loop. When I call SetRenderTarget within the loop, after every DispatchCompute, it works, but with a very high performance cost.
↧