Hi, I’m trying to use GraphicsFence in my game and I encountered the following bug:
When I try to check GraphicsFence passed property, unity throws the following error:
Which is strange considering that SystemInfo.supportsGraphicsFence returns true. Also, my computer’s GPU supports compute shaders, whics according to the documentation means that my GPU should also support GraphicsFence.
Should I file a bug report and is there currently any solution to this?
Here’s a minimal reproduction code:
using UnityEngine;
using UnityEngine.Rendering;
public class Test : MonoBehaviour
{
GraphicsFence fence;
private void Awake()
{
CreateFence();
}
private void Update()
{
if (fence.passed)
{
CreateFence();
}
}
void CreateFence()
{
Debug.Log(SystemInfo.supportsGraphicsFence);
fence = Graphics.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.ComputeProcessing);
}
}
Hi, sorry for my very very late reply, and thanks for your answer!
Do you happen to have more information about which platforms actually support it? (Unity documentation doesn’t provide any)
I’m assuming async compute is needed because I’m using GraphicsFenceType.AsyncQueueSynchronisation. The other option GraphicsFenceType.CPUSynchronisation would do just fine for me (I just need to measure how many times per second a compute shader has run), but sadly it seems to be unsupported. Are there any other ways to achieve a similar effect that wouldn’t involve GraphicsFence and async compute?
Can’t you just count how many dispatch calls you’ve made on the CPU? Or are you talking about a built-in compute shader that is called behind the scenes?
That’s what I’m doing for now, though I’d expect this value to be inaccurate - e.g. if I call Dispatch 100 times per second, but the compute kernel takes, say, 0.2 seconds to run, executing all 100 of them would actually take 20 seconds, so the actual result should be 5 executions per second.
Is this correct, or am I misunderstanding how Dispatch() works?
Usually those dispatch calls would be part of a frame that you are rendering, and the CPU will wait for the GPU if it gets more than a few frames ahead unless you run them as async compute.
So if your game ran at 10 FPS and you were dispatching 3 calls per frame, your compute shader would have run 30 times per second. This doesn’t mean that the shader took 1/30s to run, though, because those 10 FPS include the time it takes to render the rest of the frame and may even include some wait time if vsync is enabled.
So if you are trying to do GPU profiling, you are right, this approach would be too inaccurate for that. You could use GPU queries for that but I don’t know if Unity has support for them. I know that the Unity profiler can also be called via an API but that only works within the editor.
Hi, is there an option in Unity to control how many frames CPU can get ahead of the GPU?
I’m pretty sure I’ve seen it somewhere, but now I can’t find it…