Ealrann
Ealrann

Reputation: 397

How bad is it to update a UniformBuffer during its use?

I need to update a UniformBuffer (device local, readonly in shaders) every frame or so. I'm not an expert but my understanding is that I need either to:

But, let's say I don't synchronize, and simply push some fresh data in the same buffer, at the same location (offset):

How bad would it be?

Note: This question is only intended to get a better understanding of Vulkan, but definitely not to propagate bad practices.

Upvotes: 0

Views: 129

Answers (1)

Columbo
Columbo

Reputation: 6776

It's undefined behaviour:

Execution and memory dependencies are used to solve data hazards, i.e. to ensure that read and write operations occur in a well-defined order. Write-after-read hazards can be solved with just an execution dependency, but read-after-write and write-after-write hazards need appropriate memory dependencies to be included between them. If an application does not include dependencies to solve these hazards, the results and execution orders of memory accesses are undefined.

Putting aside any 'Nasal Demons' intepretation of undefined behaviour, in practice I think there's a good chance that there will be rare glitches in your rendering when you're unlucky enough that the write and the read clash. It seems unlikely to me that you could cause a crash, but you could never be 100% confident of that.

Upvotes: 1

Related Questions