Hi, I’m trying to read data from the GPU to the CPU, sometimes when resize the viewport or start up a new Modal window, I start getting garbage from the GPU, here is the code:
if (StatsReadback->FrameStatsBuffer.IsValid())
{
FRHICommandListImmediate& RHICmdList = FRHICommandListExecutor::GetImmediateCommandList();
//RHICmdList.ImmediateFlush(EImmediateFlushType::FlushRHITwhreadFlushResources);
dovi::FrameStats prev = StatsReadback->Stats;
void* SrcPtr = RHICmdList.LockStructuredBuffer(StatsReadback->FrameStatsBuffer->StructuredBuffer, 0, StatsReadback->FrameStatsBuffer->StructuredBuffer->GetSize(), RLM_ReadOnly);
FMemory::Memcpy(&StatsReadback->Stats, SrcPtr, StatsReadback->FrameStatsBuffer->StructuredBuffer->GetSize());
RHICmdList.UnlockStructuredBuffer(StatsReadback->FrameStatsBuffer->StructuredBuffer);
if (isnan(StatsReadback->Stats.source_min) || isnan(StatsReadback->Stats.source_mid) || isnan(StatsReadback->Stats.source_max))
{
//todo: when resizing the window rapidly we may get nans, should we flush??
StatsReadback->Stats = prev;
}
StatsReadback->FrameStatsBuffer = nullptr;
}
GraphBuilder.QueueBufferExtraction(FrameStats, &StatsReadback->FrameStatsBuffer, FRDGResourceState::EAccess::Read, FRDGResourceState::EPipeline::Compute);
What could be wrong with this code?