How to run a compute dispatch without blocking rendering

Hi, I have written a compute shader that takes in two meshes, and then calculates the distance to the closest point on the second mesh for every vertex on the first. This is then used to display a “heatmap” in a normal shader to show how close the models are to colliding. The output of the compute shader is a buffer of floats corresponding to the vertices of the first mesh.

My problem is that the calculation takes too long to be done in a frame, and it blocks the render thread when it runs. I dont mind displaying an outdated result while waiting for a fresh one, but I need the calculation to be non blocking. Is there any way to do this without Async Compute support? (The bool is false on Vulkan and DX12 for a quadro rtx 3000)

Without async compute the GPU can either be doing graphics or compute, it cannot do both at the same time. Your options are either find out ways to optimize your compute algorithm so it runs faster, or do the work on the CPU instead using separate threads.

1 Like

Or break your compute dispatch up into chunks so it only computes the heatmap for N vertices per frame. Instead of all of them. Then call it over a few frames until it’s done all the vertices.

(That said - your problem doesn’t sound like the kind of thing that should take very long to compute. Are you doing a brute force check of every vert vs. every other vert? If so, consider some kind of spatial partitioning/binning of your geometry to speed up the search, like a voxel grid, for example)

1 Like

Yea, thats looking to be the way to go. Even when broken up with as few as 128 verts per frame, the length of each threads execution (a 300k loop) is way too long. Im looking into a voxel grid binning to solve the issue. Thank you!

1 Like