Vulkan synchronization fixes (#2386)

* Fix out of bounds index for unknown device types

* Vulkan: Insert barrier before image host reads

* Vulkan: Make commands wait for the wait semaphore

Making commands wait at BOTTOM_OF_PIPE is a no-op, resulting in instant execution

* Vulkan: Insert barrier between views/dispatches instead of waiting on the host

* Vulkan: Fix determination of access flag from image layout

This fixes two write-after-write races with copy commands after a layout transition to VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL

* Add BGFX_MAX_FRAME_LATENCY define

Affected backends either used a magic value of 3 or defined their own XX_MAX_FRAMES_IN_FLIGHT to be 3

* Vulkan: Include indirect draw in pipeline barrier

* Vulkan: honor init.resolution.numBackBuffers for swapchain size

* Make max frame latency configurable at compile time
This commit is contained in:
pezcode
2021-02-12 05:29:52 +01:00
committed by GitHub
parent 0123d43c96
commit f983367d75
9 changed files with 89 additions and 50 deletions

View File

@@ -569,7 +569,7 @@ namespace bgfx { namespace webgpu
m_cmd.init(m_queue);
//BGFX_FATAL(NULL != m_cmd.m_commandQueue, Fatal::UnableToInitialize, "Unable to create Metal device.");
for (uint8_t ii = 0; ii < WEBGPU_MAX_FRAMES_IN_FLIGHT; ++ii)
for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_FRAME_LATENCY; ++ii)
{
BX_TRACE("Create scratch buffer %d", ii);
m_scratchBuffers[ii].create(BGFX_CONFIG_MAX_DRAW_CALLS * 128);
@@ -2372,9 +2372,9 @@ namespace bgfx { namespace webgpu
CommandQueueWgpu m_cmd;
StagingBufferWgpu m_uniformBuffers[WEBGPU_NUM_UNIFORM_BUFFERS];
ScratchBufferWgpu m_scratchBuffers[WEBGPU_MAX_FRAMES_IN_FLIGHT];
ScratchBufferWgpu m_scratchBuffers[BGFX_CONFIG_MAX_FRAME_LATENCY];
BindStateCacheWgpu m_bindStateCache[WEBGPU_MAX_FRAMES_IN_FLIGHT];
BindStateCacheWgpu m_bindStateCache[BGFX_CONFIG_MAX_FRAME_LATENCY];
uint8_t m_frameIndex;
@@ -3800,7 +3800,7 @@ namespace bgfx { namespace webgpu
{
m_queue = _queue;
#if BGFX_CONFIG_MULTITHREADED
//m_framesSemaphore.post(WEBGPU_MAX_FRAMES_IN_FLIGHT);
//m_framesSemaphore.post(BGFX_CONFIG_MAX_FRAME_LATENCY);
#endif
}
@@ -3838,7 +3838,7 @@ namespace bgfx { namespace webgpu
{
if (_endFrame)
{
m_releaseWriteIndex = (m_releaseWriteIndex + 1) % WEBGPU_MAX_FRAMES_IN_FLIGHT;
m_releaseWriteIndex = (m_releaseWriteIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY;
//m_encoder.addCompletedHandler(commandBufferFinishedCallback, this);
}
@@ -3898,7 +3898,7 @@ namespace bgfx { namespace webgpu
//m_framesSemaphore.wait();
#endif
m_releaseReadIndex = (m_releaseReadIndex + 1) % WEBGPU_MAX_FRAMES_IN_FLIGHT;
m_releaseReadIndex = (m_releaseReadIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY;
for (wgpu::Buffer& buffer : m_release[m_releaseReadIndex])
{
@@ -4044,7 +4044,7 @@ namespace bgfx { namespace webgpu
updateResolution(_render->m_resolution);
m_frameIndex = 0; // (m_frameIndex + 1) % WEBGPU_MAX_FRAMES_IN_FLIGHT;
m_frameIndex = 0; // (m_frameIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY;
ScratchBufferWgpu& scratchBuffer = m_scratchBuffers[m_frameIndex];
scratchBuffer.begin();