Add GPUResourceMapMode.NoWait flag to control buffer data reading

c68b75a298
This commit is contained in:
Wojtek Figat
2025-07-30 08:42:26 +02:00
parent c68b75a298
commit 8fcbef863e
4 changed files with 12 additions and 5 deletions

View File

@@ -340,8 +340,15 @@ API_ENUM(Attributes="Flags") enum class GPUResourceMapMode
/// The resource is mapped for reading and writing.
/// </summary>
ReadWrite = Read | Write,
/// <summary>
/// Flag that indicates mapping should fail with no data if the resource is still used by the GPU. Otherwise, CPU will wait for the GPU execution.
/// </summary>
NoWait = 0x04,
};
DECLARE_ENUM_OPERATORS(GPUResourceMapMode);
/// <summary>
/// Primitives types.
/// </summary>

View File

@@ -29,12 +29,12 @@ void* GPUBufferDX11::Map(GPUResourceMapMode mode)
map.pData = nullptr;
D3D11_MAP mapType;
UINT mapFlags = 0;
switch (mode)
switch (mode & GPUResourceMapMode::ReadWrite)
{
case GPUResourceMapMode::Read:
mapType = D3D11_MAP_READ;
//if (_desc.Usage == GPUResourceUsage::StagingReadback && isMainThread)
// mapFlags = D3D11_MAP_FLAG_DO_NOT_WAIT;
if (EnumHasAnyFlags(mode, GPUResourceMapMode::NoWait))
mapFlags = D3D11_MAP_FLAG_DO_NOT_WAIT;
break;
case GPUResourceMapMode::Write:
mapType = D3D11_MAP_WRITE_DISCARD;

View File

@@ -649,7 +649,7 @@ bool DynamicDiffuseGlobalIlluminationPass::RenderInner(RenderContext& renderCont
// Update stats
{
StatsData stats;
if (void* mapped = ddgiData.StatsRead->Map(GPUResourceMapMode::Read))
if (void* mapped = ddgiData.StatsRead->Map(GPUResourceMapMode::Read | GPUResourceMapMode::NoWait))
{
Platform::MemoryCopy(&stats, mapped, sizeof(stats));
ddgiData.StatsRead->Unmap();

View File

@@ -976,7 +976,7 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co
{
// Get the last counter value (accept staging readback delay or not available data yet)
notReady = true;
auto data = (uint32*)_culledObjectsSizeBuffer->Map(GPUResourceMapMode::Read);
auto data = (uint32*)_culledObjectsSizeBuffer->Map(GPUResourceMapMode::Read | GPUResourceMapMode::NoWait);
if (data)
{
uint32 counter = data[surfaceAtlasData.CulledObjectsCounterIndex];