Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add depth unprojection support to batch renderer #2129

Merged
merged 34 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a2a79fe
Add API to render any sensor type (GPU-to-CPU).
0mdc Mar 22, 2023
329dc3c
Format fix.
0mdc Mar 22, 2023
e06d3ef
Change function docs.
0mdc Mar 22, 2023
3919c75
Change CORRADE_ASSERT by ESP_CHECK.
0mdc Mar 22, 2023
dfc6e05
Remove unused include.
0mdc Mar 23, 2023
e252c1b
Merge remote-tracking branch 'origin/main' into batch-renderer-gpu-cp…
0mdc Jun 6, 2023
bc980bf
Formatting change.
0mdc Jun 6, 2023
003b5c6
Formatting changes.
0mdc Jun 6, 2023
0510c2a
Move DepthUnprojection to gfx_batch.
0mdc Jun 7, 2023
3323b3c
Split shaders into gfx and gfx_batch. Move depth shader to gfx_batch.
0mdc Jun 8, 2023
7e89f54
Add CPU depth unprojection to batch renderer + test.
0mdc Jun 11, 2023
b409018
Add depth unprojection batch replay renderer test.
0mdc Jun 11, 2023
7833b84
Merge remote-tracking branch 'upstream/main' into batch-renderer-dept…
0mdc Jun 13, 2023
4b15805
Change replay renderer render api arguments to keywords.
0mdc Jun 8, 2023
18bf1e9
Review pass.
0mdc Jun 12, 2023
43fe831
Merge remote-tracking branch 'upstream/main' into batch-renderer-dept…
0mdc Jun 13, 2023
69a2ef1
Format fixes.
0mdc Jun 13, 2023
2ea51d1
Fix cuda test.
0mdc Jun 13, 2023
1bfc7cb
Fix clang tidy warning and typos.
0mdc Jun 13, 2023
6b75d20
Merge remote-tracking branch 'upstream/main' into batch-renderer-dept…
0mdc Jun 14, 2023
eb53c60
Minor changes and formatting fixes.
0mdc Jun 17, 2023
8c5e673
Merge remote-tracking branch 'upstream/main' into batch-renderer-dept…
0mdc Jun 17, 2023
3822919
Move new pbr shaders to gfx.
0mdc Jun 17, 2023
0b1f7f5
Cleanup in BatchReplayRenderer::doRender().
0mdc Jun 17, 2023
258f569
Merge remote-tracking branch 'upstream/main' into batch-renderer-dept…
0mdc Jun 17, 2023
7f2091c
Find OpenExr packages only if building with background renderer.
0mdc Jun 19, 2023
144f61b
Remove CORRADE_USE_PEDANTIC_FLAGS.
0mdc Jun 19, 2023
aec3341
Add depth unprojection overload for strided arrays. Review pass.
0mdc Jun 22, 2023
204f7f8
Find OpenEXR plugins and link to them correctly.
mosra Jun 25, 2023
2a1b2dc
Put camera unprojection together with other per-scene data.
mosra Jun 25, 2023
52ce19e
Add bounds assertions, no need to return these by reference.
mosra Jun 25, 2023
0f145ba
The DepthUnprojectionTest no longer needs the whole gfx library.
mosra Jun 25, 2023
470f6ce
Remove useless and completely untested unprojectDepth() overload.
mosra Jun 25, 2023
46b8286
Reduce iterations for baseline depth unprojection benchmark.
mosra Jun 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ We also use pre-commit hooks to ensure linting and style enforcement. Install th

## Documentation
- Our documentation style is based on Magnum / Corrade and uses [a similar build system](https://mcss.mosra.cz/documentation/doxygen/).
- A good example of the documentation style is in esp::gfx::DepthUnprojection (DepthUnprojection.h).
- The gfx_batch library is a good example of the documentation style.
- Documentation of PRs is highly encouraged!

## Development Tips
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/cmake/FindMagnumPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ foreach(_component ${MagnumPlugins_FIND_COMPONENTS})
# config if appropriate
find_package(OpenEXR REQUIRED MODULE)
set_property(TARGET MagnumPlugins::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenEXR::IlmImf)
INTERFACE_LINK_LIBRARIES OpenEXR::OpenEXR)

# No special setup for the OpenDdl library
# OpenGexImporter has no dependencies
Expand Down
17 changes: 3 additions & 14 deletions src/esp/gfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set(
gfx_SOURCES
CubeMap.cpp
CubeMap.h
DepthUnprojection.cpp
DepthUnprojection.h
Drawable.cpp
Drawable.h
DrawableGroup.cpp
Expand Down Expand Up @@ -108,10 +106,8 @@ find_package(MagnumPlugins REQUIRED GltfImporter StbImageImporter StbImageConver
find_package(MagnumIntegration REQUIRED Eigen)

find_package(Corrade REQUIRED Utility)
# TODO: enable the following flag and fix the compilation warnings
# set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
corrade_add_resource(ShaderResources ../../shaders/Shaders.conf)
list(APPEND gfx_SOURCES ${ShaderResources})
corrade_add_resource(GfxShaderResources ../../shaders/gfx/Shaders.conf)
list(APPEND gfx_SOURCES ${GfxShaderResources})

corrade_add_resource(PbrImageResources ../../../data/pbr/PbrImages.conf)
list(APPEND gfx_SOURCES ${PbrImageResources})
Expand All @@ -122,14 +118,6 @@ add_library(
)

if(BUILD_WITH_CUDA)
# We currently don't directly depend on gfx_batch for anything, just taking
# the header-only CUDA helpers from there, so gfx_batch isn't in
# target_link_libraries().
target_include_directories(
gfx PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
${CMAKE_CURRENT_LIST_DIR}/../gfx_batch/cuda_helpers
)

target_link_libraries(gfx PUBLIC ${CUDART_LIBRARY})
endif()

Expand All @@ -138,6 +126,7 @@ target_link_libraries(
PUBLIC assets
core
io
gfx_batch
physics
Magnum::AnyImageImporter
Magnum::AnySceneImporter
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/DoubleSphereCameraShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// compiled into static library, it must be explicitly initialized via this
// macro, and should be called *outside* of any namespace.
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace Mn = Magnum;
Expand All @@ -28,7 +28,7 @@ namespace gfx {
DoubleSphereCameraShader::DoubleSphereCameraShader(
CubeMapShaderBase::Flags flags)
: CubeMapShaderBase(flags) {
if (!Cr::Utility::Resource::hasGroup("default-shaders")) {
if (!Cr::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

Expand All @@ -40,7 +40,7 @@ DoubleSphereCameraShader::DoubleSphereCameraShader(

// this is not the file name, but the group name in the config file
// see Shaders.conf in the shaders folder
const Cr::Utility::Resource rs{"default-shaders"};
const Cr::Utility::Resource rs{"gfx-shaders"};

Mn::GL::Shader vert{glVersion, Mn::GL::Shader::Type::Vertex};
Mn::GL::Shader frag{glVersion, Mn::GL::Shader::Type::Fragment};
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/EquirectangularShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// When the resource is compiled into static library, it must be explicitly
// initialized via this macro, and should be called *outside* of any namespace.
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace Mn = Magnum;
Expand All @@ -33,7 +33,7 @@ EquirectangularShader::EquirectangularShader(Flags flags)
"EquirectangularShader::EquirectangularShader(): shader "
"flags cannot be empty.", );

if (!Cr::Utility::Resource::hasGroup("default-shaders")) {
if (!Cr::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

Expand All @@ -45,7 +45,7 @@ EquirectangularShader::EquirectangularShader(Flags flags)

// this is not the file name, but the group name in the config file
// see Shaders.conf in the shaders folder
const Cr::Utility::Resource rs{"default-shaders"};
const Cr::Utility::Resource rs{"gfx-shaders"};

Mn::GL::Shader vert{glVersion, Mn::GL::Shader::Type::Vertex};
Mn::GL::Shader frag{glVersion, Mn::GL::Shader::Type::Fragment};
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/GaussianFilterShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Cr = Corrade;
namespace Mn = Magnum;

static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace esp {
Expand All @@ -29,11 +29,11 @@ enum {
};

GaussianFilterShader::GaussianFilterShader() {
if (!Corrade::Utility::Resource::hasGroup("default-shaders")) {
if (!Corrade::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

const Corrade::Utility::Resource rs{"default-shaders"};
const Corrade::Utility::Resource rs{"gfx-shaders"};

#ifdef MAGNUM_TARGET_WEBGL
Mn::GL::Version glVersion = Mn::GL::Version::GLES300;
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/PTexMeshShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// compiled into static library, it must be explicitly initialized via this
// macro, and should be called // *outside* of any namespace.
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace Mn = Magnum;
Expand All @@ -40,12 +40,12 @@ enum TextureBindingPointIndex : uint8_t {
PTexMeshShader::PTexMeshShader() {
MAGNUM_ASSERT_GL_VERSION_SUPPORTED(Mn::GL::Version::GL410);

if (!Corrade::Utility::Resource::hasGroup("default-shaders")) {
if (!Corrade::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

// this is not the file name, but the group name in the config file
const Corrade::Utility::Resource rs{"default-shaders"};
const Corrade::Utility::Resource rs{"gfx-shaders"};

Mn::GL::Shader vert{Mn::GL::Version::GL410, Mn::GL::Shader::Type::Vertex};
Mn::GL::Shader geom{Mn::GL::Version::GL410, Mn::GL::Shader::Type::Geometry};
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/PbrEquiRectangularToCubeMapShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// compiled into static library, it must be explicitly initialized via this
// macro, and should be called *outside* of any namespace.
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace Mn = Magnum;
Expand All @@ -33,7 +33,7 @@ enum {
};

PbrEquiRectangularToCubeMapShader::PbrEquiRectangularToCubeMapShader() {
if (!Corrade::Utility::Resource::hasGroup("default-shaders")) {
if (!Corrade::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

Expand All @@ -45,7 +45,7 @@ PbrEquiRectangularToCubeMapShader::PbrEquiRectangularToCubeMapShader() {

// this is not the file name, but the group name in the config file
// see Shaders.conf in the shaders folder
const Cr::Utility::Resource rs{"default-shaders"};
const Cr::Utility::Resource rs{"gfx-shaders"};

Mn::GL::Shader vert{glVersion, Mn::GL::Shader::Type::Vertex};
Mn::GL::Shader frag{glVersion, Mn::GL::Shader::Type::Fragment};
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/PbrPrecomputedMapShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// compiled into static library, it must be explicitly initialized via this
// macro, and should be called *outside* of any namespace.
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace Mn = Magnum;
Expand All @@ -41,7 +41,7 @@ PbrPrecomputedMapShader::PbrPrecomputedMapShader(Flags flags) : flags_(flags) {
"Flag::IrradianceMap and "
"Flag::PrefilteredMap are mutually exclusive.", );

if (!Corrade::Utility::Resource::hasGroup("default-shaders")) {
if (!Corrade::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

Expand All @@ -53,7 +53,7 @@ PbrPrecomputedMapShader::PbrPrecomputedMapShader(Flags flags) : flags_(flags) {

// this is not the file name, but the group name in the config file
// see Shaders.conf in the shaders folder
const Cr::Utility::Resource rs{"default-shaders"};
const Cr::Utility::Resource rs{"gfx-shaders"};

Mn::GL::Shader vert{glVersion, Mn::GL::Shader::Type::Vertex};
Mn::GL::Shader frag{glVersion, Mn::GL::Shader::Type::Fragment};
Expand Down
6 changes: 3 additions & 3 deletions src/esp/gfx/PbrShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// compiled into static library, it must be explicitly initialized via this
// macro, and should be called *outside* of any namespace.
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(ShaderResources)
CORRADE_RESOURCE_INITIALIZE(GfxShaderResources)
}

namespace Mn = Magnum;
Expand All @@ -41,7 +41,7 @@ namespace gfx {

PbrShader::PbrShader(Flags originalFlags, unsigned int lightCount)
: flags_(originalFlags), lightCount_(lightCount) {
if (!Cr::Utility::Resource::hasGroup("default-shaders")) {
if (!Cr::Utility::Resource::hasGroup("gfx-shaders")) {
importShaderResources();
}

Expand Down Expand Up @@ -74,7 +74,7 @@ PbrShader::PbrShader(Flags originalFlags, unsigned int lightCount)

// this is not the file name, but the group name in the config file
// see Shaders.conf in the shaders folder
const Cr::Utility::Resource rs{"default-shaders"};
const Cr::Utility::Resource rs{"gfx-shaders"};

Mn::GL::Shader vert{glVersion, Mn::GL::Shader::Type::Vertex};
Mn::GL::Shader frag{glVersion, Mn::GL::Shader::Type::Fragment};
Expand Down
18 changes: 9 additions & 9 deletions src/esp/gfx/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "RenderTarget.h"
#include "esp/sensor/VisualSensor.h"

#include "esp/gfx/DepthUnprojection.h"
#include "esp/gfx_batch/DepthUnprojection.h"

#ifdef ESP_BUILD_WITH_CUDA
#include <cuda_gl_interop.h>
Expand All @@ -46,7 +46,7 @@ const Mn::GL::Framebuffer::ColorAttachment UnprojectedDepthBufferAttachment =
struct RenderTarget::Impl {
Impl(const Mn::Vector2i& size,
const Mn::Vector2& depthUnprojection,
DepthShader* depthShader,
gfx_batch::DepthShader* depthShader,
Flags flags,
const sensor::VisualSensor* visualSensor)
: colorBuffer_{},
Expand All @@ -61,8 +61,9 @@ struct RenderTarget::Impl {
flags_{flags},
visualSensor_{visualSensor} {
if (depthShader_) {
CORRADE_INTERNAL_ASSERT(depthShader_->flags() &
DepthShader::Flag::UnprojectExistingDepth);
CORRADE_INTERNAL_ASSERT(
depthShader_->flags() &
gfx_batch::DepthShader::Flag::UnprojectExistingDepth);
}

if (flags_ & Flag::RgbaAttachment) {
Expand Down Expand Up @@ -148,7 +149,7 @@ struct RenderTarget::Impl {
CORRADE_INTERNAL_ASSERT(depthShader_ != nullptr);
CORRADE_ASSERT(
flags_ & Flag::DepthTextureAttachment,
"RenderTarget::Impl::unporojectDepthGPU(): this render target "
"RenderTarget::Impl::unprojectDepthGPU(): this render target "
"was not created with depth texture enabled.", );
initDepthUnprojector();

Expand Down Expand Up @@ -220,8 +221,7 @@ struct RenderTarget::Impl {
Mn::GL::PixelFormat::DepthComponent, Mn::GL::PixelType::Float,
view.size(), view.data()};
framebuffer_.read(framebuffer_.viewport(), depthBufferView);
unprojectDepth(depthUnprojection_,
Cr::Containers::arrayCast<Mn::Float>(view.data()));
gfx_batch::unprojectDepth(depthUnprojection_, view.pixels<Mn::Float>());
}
}

Expand Down Expand Up @@ -353,7 +353,7 @@ struct RenderTarget::Impl {
Mn::GL::Framebuffer framebuffer_;

Mn::Vector2 depthUnprojection_;
DepthShader* depthShader_;
gfx_batch::DepthShader* depthShader_;
Mn::GL::Renderbuffer unprojectedDepth_;
Mn::GL::Mesh depthUnprojectionMesh_;
Mn::GL::Framebuffer depthUnprojectionFrameBuffer_;
Expand All @@ -371,7 +371,7 @@ struct RenderTarget::Impl {

RenderTarget::RenderTarget(const Mn::Vector2i& size,
const Mn::Vector2& depthUnprojection,
DepthShader* depthShader,
gfx_batch::DepthShader* depthShader,
Flags flags,
const sensor::VisualSensor* visualSensor)
: pimpl_(spimpl::make_unique_impl<Impl>(size,
Expand Down
8 changes: 5 additions & 3 deletions src/esp/gfx/RenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@

#include "esp/core/Esp.h"

#include "esp/gfx/DepthUnprojection.h"
mosra marked this conversation as resolved.
Show resolved Hide resolved
#include "esp/gfx/Renderer.h"

namespace esp {

namespace sensor {
class VisualSensor;
}
namespace gfx_batch {
class DepthShader;
}

namespace gfx {

Expand Down Expand Up @@ -70,15 +72,15 @@ class RenderTarget {
*/
RenderTarget(const Magnum::Vector2i& size,
const Magnum::Vector2& depthUnprojection,
DepthShader* depthShader,
gfx_batch::DepthShader* depthShader,
Flags flags = {Flag::RgbaAttachment | Flag::ObjectIdAttachment |
Flag::DepthTextureAttachment},
const sensor::VisualSensor* visualSensor = nullptr);

/**
* @brief Constructor
* @param size The size of the underlying framebuffers in WxH
* @param depthUnprojection Depth unrpojection parameters. See @ref
* @param depthUnprojection Depth unprojection parameters. See @ref
* calculateDepthUnprojection()
* @param visualSensor (optional) The visual sensor for this render
* target
Expand Down
11 changes: 6 additions & 5 deletions src/esp/gfx/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#include <Magnum/ResourceManager.h>

#include "esp/core/Check.h"
#include "esp/gfx/DepthUnprojection.h"
#include "esp/gfx/GaussianFilterShader.h"
#include "esp/gfx/RenderTarget.h"
#include "esp/gfx/TextureVisualizerShader.h"
#include "esp/gfx_batch/DepthUnprojection.h"
#include "esp/sensor/VisualSensor.h"
#include "esp/sim/Simulator.h"

Expand Down Expand Up @@ -336,8 +336,8 @@ struct Renderer::Impl {
"depthUnprojection matrix", );

if (!depthShader_) {
depthShader_ = std::make_unique<DepthShader>(
DepthShader::Flag::UnprojectExistingDepth);
depthShader_ = std::make_unique<gfx_batch::DepthShader>(
gfx_batch::DepthShader::Flag::UnprojectExistingDepth);
}

RenderTarget::Flags renderTargetFlags = {};
Expand Down Expand Up @@ -381,7 +381,7 @@ struct Renderer::Impl {
WindowlessContext* context_;
bool contextIsOwned_ = true;
// TODO: shall we use shader resource manager from now?
std::unique_ptr<DepthShader> depthShader_;
std::unique_ptr<gfx_batch::DepthShader> depthShader_;
const Flags flags_;
#ifdef ESP_BUILD_WITH_BACKGROUND_RENDERER
std::unique_ptr<BackgroundRenderer> backgroundRenderer_ = nullptr;
Expand Down Expand Up @@ -431,7 +431,8 @@ struct Renderer::Impl {
if (type == RendererShaderType::DepthShader) {
shaderManager_.set<Mn::GL::AbstractShaderProgram>(
shader.key(),
new DepthShader{DepthShader::Flag::UnprojectExistingDepth},
new gfx_batch::DepthShader{
gfx_batch::DepthShader::Flag::UnprojectExistingDepth},
Mn::ResourceDataState::Final, Mn::ResourcePolicy::Resident);
} else if (type == RendererShaderType::DepthTextureVisualizer) {
shaderManager_.set<Mn::GL::AbstractShaderProgram>(
Expand Down
Loading