在使用期间更新 UniformBuffer 有多糟糕?
How bad is it to update a UniformBuffer during its use?
我需要每帧左右更新一个 UniformBuffer(设备本地,在着色器中只读)。我不是专家,但我的理解是我需要:
- 同步(Fence...),确保在使用时不要写入缓冲区。
- 写入不同的buffer/offset,更新DescriptorSet,重新记录CommandBuffer。
但是,假设我不同步,只是将一些新数据推送到同一缓冲区的同一位置(偏移量):
会有多糟糕?
注意:此问题只是为了更好地了解Vulkan,绝非传播不良做法。
这是未定义的行为:
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.
撇开对未定义行为的任何 'Nasal Demons' 解释,在实践中,我认为当您不幸导致写入和读取冲突时,渲染中很可能会出现罕见的故障。在我看来,您不太可能导致崩溃,但您永远无法对此有 100% 的信心。
我需要每帧左右更新一个 UniformBuffer(设备本地,在着色器中只读)。我不是专家,但我的理解是我需要:
- 同步(Fence...),确保在使用时不要写入缓冲区。
- 写入不同的buffer/offset,更新DescriptorSet,重新记录CommandBuffer。
但是,假设我不同步,只是将一些新数据推送到同一缓冲区的同一位置(偏移量):
会有多糟糕?
注意:此问题只是为了更好地了解Vulkan,绝非传播不良做法。
这是未定义的行为:
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.
撇开对未定义行为的任何 'Nasal Demons' 解释,在实践中,我认为当您不幸导致写入和读取冲突时,渲染中很可能会出现罕见的故障。在我看来,您不太可能导致崩溃,但您永远无法对此有 100% 的信心。