diff --git a/src/esp/bindings/SimBindings.cpp b/src/esp/bindings/SimBindings.cpp index 73284ff0a8..ff33d245c8 100644 --- a/src/esp/bindings/SimBindings.cpp +++ b/src/esp/bindings/SimBindings.cpp @@ -409,9 +409,10 @@ void initSimBindings(py::module& m) { [](AbstractReplayRenderer& self, const std::string& filePath) { self.preloadFile(filePath); }, - R"(Load an composite file that the renderer will use in-place of simulation assets to improve memory usage and performance.)") - .def("environment_count", &AbstractReplayRenderer::environmentCount, - "Get the batch size.") + R"(Load a composite file that the renderer will use in-place of simulation assets to improve memory usage and performance.)") + .def_property_readonly("environment_count", + &AbstractReplayRenderer::environmentCount, + "Get the batch size.") .def("sensor_size", &AbstractReplayRenderer::sensorSize, "Get the resolution of a sensor.") .def("clear_environment", &AbstractReplayRenderer::clearEnvironment, @@ -420,7 +421,7 @@ void initSimBindings(py::module& m) { static_cast( &AbstractReplayRenderer::render), - R"(Render all sensors onto the main framebuffer.)") + R"(Render all sensors onto the specified framebuffer.)") .def( "set_sensor_transforms_from_keyframe", &AbstractReplayRenderer::setSensorTransformsFromKeyframe, @@ -430,9 +431,21 @@ void initSimBindings(py::module& m) { .def("set_environment_keyframe", &AbstractReplayRenderer::setEnvironmentKeyframe, R"(Set the keyframe for a specific environment.)") - .def_static("environment_grid_size", - &AbstractReplayRenderer::environmentGridSize, - R"(Dimensions of the environment grid.)"); + .def_static( + "environment_grid_size", &AbstractReplayRenderer::environmentGridSize, + R"(Get the dimensions (tile counts) of the environment grid.)") + .def( + "cuda_color_buffer_device_pointer", + [](AbstractReplayRenderer& self) { + return py::capsule(self.getCudaColorBufferDevicePointer()); + }, + R"(Retrieve the color buffer as a CUDA device pointer.)") + .def( + "cuda_depth_buffer_device_pointer", + [](AbstractReplayRenderer& self) { + return py::capsule(self.getCudaColorBufferDevicePointer()); + }, + R"(Retrieve the depth buffer as a CUDA device pointer.)"); } } // namespace sim diff --git a/src/esp/sim/AbstractReplayRenderer.cpp b/src/esp/sim/AbstractReplayRenderer.cpp index 4dfb2ea736..a09c05c01a 100644 --- a/src/esp/sim/AbstractReplayRenderer.cpp +++ b/src/esp/sim/AbstractReplayRenderer.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. @@ -104,5 +104,15 @@ void AbstractReplayRenderer::render( return doRender(framebuffer); } +const void* AbstractReplayRenderer::getCudaColorBufferDevicePointer() { + ESP_ERROR() << "CUDA device pointer only available with the batch renderer."; + return nullptr; +} + +const void* AbstractReplayRenderer::getCudaDepthBufferDevicePointer() { + ESP_ERROR() << "CUDA device pointer only available with the batch renderer."; + return nullptr; +} + } // namespace sim } // namespace esp diff --git a/src/esp/sim/AbstractReplayRenderer.h b/src/esp/sim/AbstractReplayRenderer.h index 3a2012eac3..ef24a8f27f 100644 --- a/src/esp/sim/AbstractReplayRenderer.h +++ b/src/esp/sim/AbstractReplayRenderer.h @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. @@ -102,6 +102,12 @@ class AbstractReplayRenderer { // Assumes the framebuffer color & depth is cleared void render(Magnum::GL::AbstractFramebuffer& framebuffer); + // Retrieve the color buffer as a CUDA device pointer. */ + virtual const void* getCudaColorBufferDevicePointer(); + + // Retrieve the depth buffer as a CUDA device pointer. */ + virtual const void* getCudaDepthBufferDevicePointer(); + private: /* Implementation of all public API is in the private do*() functions, similarly to how e.g. Magnum plugin interfaces work. The public API does diff --git a/src/esp/sim/BatchReplayRenderer.cpp b/src/esp/sim/BatchReplayRenderer.cpp index cfb4f5f144..a0195e4197 100644 --- a/src/esp/sim/BatchReplayRenderer.cpp +++ b/src/esp/sim/BatchReplayRenderer.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. @@ -244,5 +244,36 @@ void BatchReplayRenderer::doRender( renderer_->draw(framebuffer); } +const void* BatchReplayRenderer::getCudaColorBufferDevicePointer() { +#ifdef ESP_BUILD_WITH_CUDA + CORRADE_ASSERT(standalone_, + "ReplayBatchRenderer::colorCudaBufferDevicePointer(): can use " + "this function only " + "with a standalone renderer", + nullptr); + return static_cast(*renderer_) + .colorCudaBufferDevicePointer(); +#else + ESP_ERROR() << "Failed to retrieve device pointer because CUDA is not " + "available in this build."; + return nullptr; +#endif +} + +const void* BatchReplayRenderer::getCudaDepthBufferDevicePointer() { +#ifdef ESP_BUILD_WITH_CUDA + CORRADE_ASSERT(standalone_, + "ReplayBatchRenderer::getCudaDepthBufferDevicePointer(): can " + "use this function only " + "with a standalone renderer", + nullptr); + return static_cast(*renderer_) + .depthCudaBufferDevicePointer(); +#else + ESP_ERROR() << "Failed to retrieve device pointer because CUDA is not " + "available in this build."; + return nullptr; +#endif +} } // namespace sim } // namespace esp diff --git a/src/esp/sim/BatchReplayRenderer.h b/src/esp/sim/BatchReplayRenderer.h index fbc1de8420..7f113b591b 100644 --- a/src/esp/sim/BatchReplayRenderer.h +++ b/src/esp/sim/BatchReplayRenderer.h @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. @@ -24,6 +24,10 @@ class BatchReplayRenderer : public AbstractReplayRenderer { ~BatchReplayRenderer() override; + const void* getCudaColorBufferDevicePointer() override; + + const void* getCudaDepthBufferDevicePointer() override; + private: void doPreloadFile(Corrade::Containers::StringView filename) override; diff --git a/src/esp/sim/ClassicReplayRenderer.cpp b/src/esp/sim/ClassicReplayRenderer.cpp index b0f29ba876..3b8786ffc1 100644 --- a/src/esp/sim/ClassicReplayRenderer.cpp +++ b/src/esp/sim/ClassicReplayRenderer.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. diff --git a/src/esp/sim/ClassicReplayRenderer.h b/src/esp/sim/ClassicReplayRenderer.h index 168c5e1ddb..c2955337e5 100644 --- a/src/esp/sim/ClassicReplayRenderer.h +++ b/src/esp/sim/ClassicReplayRenderer.h @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. diff --git a/src/tests/BatchReplayRendererTest.cpp b/src/tests/BatchReplayRendererTest.cpp index 6f84a02ba1..f54b467b02 100644 --- a/src/tests/BatchReplayRendererTest.cpp +++ b/src/tests/BatchReplayRendererTest.cpp @@ -1,7 +1,8 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. +#include "Corrade/Utility/Assert.h" #include "Magnum/DebugTools/Screenshot.h" #include "Magnum/Magnum.h" #include "Magnum/Trade/AbstractImageConverter.h" @@ -13,6 +14,7 @@ #include "esp/physics/objectManagers/RigidObjectManager.h" #include "esp/sensor/CameraSensor.h" #include "esp/sensor/Sensor.h" +#include "esp/sim/AbstractReplayRenderer.h" #include "esp/sim/BatchReplayRenderer.h" #include "esp/sim/ClassicReplayRenderer.h" #include "esp/sim/Simulator.h" @@ -186,6 +188,24 @@ void BatchReplayRendererTest::testIntegration() { Cr::Utility::Path::join(screenshotDir, groundTruthImageFile), (Mn::DebugTools::CompareImageToFile{maxThreshold, meanThreshold})); } + + const auto colorPtr = renderer->getCudaColorBufferDevicePointer(); + const auto depthPtr = renderer->getCudaDepthBufferDevicePointer(); + bool isBatchRenderer = + dynamic_cast(renderer.get()); +#ifdef ESP_BUILD_WITH_CUDA + if (isBatchRenderer) { + CORRADE_VERIFY(colorPtr); + CORRADE_VERIFY(depthPtr); + } else { + // Not implemented in ClassicReplayRenderer + CORRADE_VERIFY(!colorPtr); + CORRADE_VERIFY(!depthPtr); + } +#else + CORRADE_VERIFY(!colorPtr); + CORRADE_VERIFY(!depthPtr); +#endif } } // namespace