I'm trying to share resources across different command queues. Obviously I want to keep the sharing to a minimum but at some point something needs to be shared. Afaik there's no mutex object in dx12, but does using fences work? Here's my current plan that seems to work, but I'm wondering if it could be better or what other people do. I want the compute queue to run as fast as possible, and as many times as it can, but I also want the draw queue to stop it when drawing needs to happen.
F0 <- 1
F1 <- 0
Compute loop:
* queue->Set F1 = 1
* queue->Wait for F0 == 1
* Exec command list
* queue->Set F1 = 0
Draw loop:
* cpu->Set F0 = 0, this should stop new computes from starting
* queue->Wait for F1 == 0, this should wait until the currently executing compute command list is finished
* Exec command list, compute queue should not be executing anything at this point
* queue->Set F0 = 1, compute queue can run again
I'm pretty sure there's a deadlock in there somewhere but whatever.
Should/could I do this with one fence instead of two? If I have a bunch of command lists pending inside the compute queue, I want the draw queue to take priority so that I can stack a bunch of stuff into compute but maintain priority for drawing. Obviously this will fall apart if a compute command list takes too long and the draw queue waits for it, so I want compute command lists to be pretty fast relative to draws.
I think setting the queue priority would let me do this -- i.e. if two command queues are waiting on the same fence, the one with higher priority should get it? But all the documentation says is
so idk :(.