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

Function buffer_to_numpy

Source/Falcor/Core/API/Buffer.cpp:386–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384#endif
385
386inline pybind11::ndarray<pybind11::numpy> buffer_to_numpy(const Buffer& self)
387{
388 size_t bufferSize = self.getSize();
389 void* cpuData = new uint8_t[bufferSize];
390 self.getBlob(cpuData, 0, bufferSize);
391
392 pybind11::capsule owner(cpuData, [](void* p) noexcept { delete[] reinterpret_cast<uint8_t*>(p); });
393
394 if (auto dtype = resourceFormatToDtype(self.getFormat()))
395 {
396 uint32_t channelCount = getFormatChannelCount(self.getFormat());
397 if (channelCount == 1)
398 {
399 pybind11::size_t shape[1] = {self.getElementCount()};
400 return pybind11::ndarray<pybind11::numpy>(cpuData, 1, shape, owner, nullptr, *dtype, pybind11::device::cpu::value);
401 }
402 else
403 {
404 pybind11::size_t shape[2] = {self.getElementCount(), channelCount};
405 return pybind11::ndarray<pybind11::numpy>(cpuData, 2, shape, owner, nullptr, *dtype, pybind11::device::cpu::value);
406 }
407 }
408 else
409 {
410 pybind11::size_t shape[1] = {bufferSize};
411 return pybind11::ndarray<pybind11::numpy>(
412 cpuData, 1, shape, owner, nullptr, pybind11::dtype<uint8_t>(), pybind11::device::cpu::value
413 );
414 }
415}
416
417inline void buffer_from_numpy(Buffer& self, pybind11::ndarray<pybind11::numpy> data)
418{

Callers

nothing calls this directly

Calls 5

resourceFormatToDtypeFunction · 0.85
getFormatChannelCountFunction · 0.85
getBlobMethod · 0.80
getFormatMethod · 0.80
getSizeMethod · 0.45

Tested by

no test coverage detected