Skip to content

Commit

Permalink
WebGPU: Reworked buffer initialization (close #552)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets committed Jul 17, 2024
1 parent 89c0a41 commit a2e5040
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Graphics/GraphicsEngineWebGPU/src/BufferWebGPUImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,17 @@ BufferWebGPUImpl::BufferWebGPUImpl(IReferenceCounters* pRefCounters,
}
}

const auto InitializeBuffer = (pInitData != nullptr && pInitData->pData != nullptr);
wgpuBufferDesc.mappedAtCreation = (pInitData != nullptr && pInitData->pData != nullptr);

m_wgpuBuffer.Reset(wgpuDeviceCreateBuffer(pDevice->GetWebGPUDevice(), &wgpuBufferDesc));
if (!m_wgpuBuffer)
LOG_ERROR_AND_THROW("Failed to create WebGPU buffer ", " '", m_Desc.Name ? m_Desc.Name : "", '\'');

if (InitializeBuffer)
if (wgpuBufferDesc.mappedAtCreation)
{
VERIFY_EXPR(pDevice->GetNumImmediateContexts() == 1);
auto pContext = pDevice->GetImmediateContext(0);
wgpuQueueWriteBuffer(pContext->GetWebGPUQueue(), m_wgpuBuffer, 0, pInitData->pData, StaticCast<size_t>(pInitData->DataSize));
void* pData = wgpuBufferGetMappedRange(m_wgpuBuffer, 0, StaticCast<size_t>(pInitData->DataSize));
memcpy(pData, pInitData->pData, StaticCast<size_t>(pInitData->DataSize));
wgpuBufferUnmap(m_wgpuBuffer);
}
}

Expand Down

0 comments on commit a2e5040

Please sign in to comment.