MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / syncCPUData

Method syncCPUData

Source/Falcor/Scene/Lights/LightCollection.cpp:649–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

647 }
648
649 void LightCollection::syncCPUData(RenderContext* pRenderContext) const
650 {
651 if (mCPUInvalidData == CPUOutOfDateFlags::None) return;
652
653 // If the data has not yet been copied to the staging buffer, we have to do that first.
654 // This should normally have done by calling prepareSyncCPUData().
655 if (!mStagingBufferValid)
656 {
657 logWarning("LightCollection::syncCPUData() performance warning - Call LightCollection::prepareSyncCPUData() ahead of time if possible");
658 prepareSyncCPUData(pRenderContext);
659 }
660
661 // Wait for signal.
662 mpStagingFence->wait();
663
664 FALCOR_ASSERT(mStagingBufferValid);
665 FALCOR_ASSERT(mpTriangleData && mpFluxData);
666 const void* mappedData = mpStagingBuffer->map();
667
668 uint64_t offset = 0;
669 const PackedEmissiveTriangle* triangleData = reinterpret_cast<const PackedEmissiveTriangle*>(reinterpret_cast<uintptr_t>(mappedData) + offset);
670 offset += mpTriangleData->getSize();
671 const EmissiveFlux* fluxData = reinterpret_cast<const EmissiveFlux*>(reinterpret_cast<uintptr_t>(mappedData) + offset);
672 offset += mpFluxData->getSize();
673 FALCOR_ASSERT(offset <= mpStagingBuffer->getSize());
674
675 bool updateTriangleData = is_set(mCPUInvalidData, CPUOutOfDateFlags::TriangleData);
676 bool updateFluxData = is_set(mCPUInvalidData, CPUOutOfDateFlags::FluxData);
677
678 FALCOR_ASSERT(mTriangleCount > 0);
679 FALCOR_ASSERT(mMeshLightTriangles.size() == (size_t)mTriangleCount);
680 for (uint32_t triIdx = 0; triIdx < mTriangleCount; triIdx++)
681 {
682 const auto tri = triangleData[triIdx].unpack();
683 auto& meshLightTri = mMeshLightTriangles[triIdx];
684
685 if (updateTriangleData)
686 {
687 meshLightTri.lightIdx = tri.lightIdx;
688 meshLightTri.normal = tri.normal;
689 meshLightTri.area = tri.area;
690
691 for (uint32_t j = 0; j < 3; j++)
692 {
693 meshLightTri.vtx[j].pos = tri.posW[j];
694 meshLightTri.vtx[j].uv = tri.texCoords[j];
695 }
696 }
697
698 if (updateFluxData)
699 {
700 meshLightTri.flux = fluxData[triIdx].flux;
701 meshLightTri.averageRadiance = fluxData[triIdx].averageRadiance;
702 }
703 }
704
705 mpStagingBuffer->unmap();
706 mCPUInvalidData = CPUOutOfDateFlags::None;

Callers

nothing calls this directly

Calls 7

prepareSyncCPUDataFunction · 0.85
mapMethod · 0.80
unmapMethod · 0.80
logWarningFunction · 0.50
waitMethod · 0.45
getSizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected