Skip to content

Commit d91694b

Browse files
committed
Merge branch 'master' into gpu_blit_filter
2 parents 9973549 + d615dde commit d91694b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1014
-140
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ option(NBL_BUILD_EXAMPLES "Enable building examples" ON)
268268

269269
option(NBL_BUILD_TOOLS "Enable building tools (just convert2BAW as for now)" ON)
270270

271-
option(NBL_BUILD_MITSUBA_LOADER "Enable nbl::ext::MitsubaLoader?" ON)
271+
option(NBL_BUILD_MITSUBA_LOADER "Enable nbl::ext::MitsubaLoader?" OFF) # TODO: once it compies turn this ON by default!
272272

273273
option(NBL_BUILD_OPTIX "Enable nbl::ext::OptiX?" OFF)
274274
if(NBL_COMPILE_WITH_CUDA)

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,59 @@ If you want to use git (without a submodule) then you can use `ExternalProject_A
414414

415415
I recommend you use `ExternalProject_Add` instead of `add_subdirectory` for **Nabla** as we haven't tested its use by *3rdparty* applications that use *CMake* to build themselves yet.
416416

417+
# Caveats and Particular Behaviour
418+
419+
## Hardcoded Caps
420+
421+
### Max Descriptor Sets is always 4
422+
423+
## Debugging with RenderDoc
424+
425+
### Non-programmatic OpenGL catpures will be delimited inconsistently
426+
427+
Due to our no-pollution opengl state isolation policy, we have 1 queue or swapchain = 1 thread = 1 gl context + 1 master context and thread for device calls.
428+
429+
Renderdoc therefore serializes all calls, and presents them inside the capture in interleaved order (records them on a single timeline "as they happened").
430+
431+
Furthermore it has no idea what constitutes a frame, because swap-buffers call happens on a separate thread than all the other API calls. **So use the `IGPUQueue` start/end capture methods!**
432+
433+
### RenderDoc flips images for display in the ImageViewer tab on OpenGL captures
434+
435+
Ctrl+F `localRenderer in https://github.com/baldurk/renderdoc/blob/4103f6a5455b9734e9bf74e254577f5c03188136/renderdoc/core/image_viewer.cpp
436+
437+
### OpenGL/Vulkan Inconsistencies
438+
439+
In certain cases same calls to Vulkan and OpenGL might result in y-flipped image relevant to the other API.
440+
441+
Both APIs write (-1,-1) in NDC space to (0,0) in image space (two wrongs make right), and memory-wise (0,0) always represents the lowest byte in memory.
442+
443+
This inconsistency comes from swapchain presentation. When presenting the swapchain, the image location (0,0) corresponds to **bottom-left** in OpenGL and **top-left** in Vulkan.
444+
445+
#### Solution by Surface Transforms
446+
447+
We solve this inconsistency by using [surface transforms](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSurfaceTransformFlagBitsKHR.html); This transforms are relative to `presentation engine’s natural orientation`. and we report `HORIZONTAL_MIRROR_180` support in our OpenGL backend and defer handling these rotations (relative to natural orientaion) to the user.
448+
449+
We provide helper functions in both GLSL and C++ Nabla codebase to consider surface transforms, See [surface_transform.glsl](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/builtin/glsl/utils/surface_transform.glsl)
450+
451+
Note that it is common to apply surface transformation to projection matrices to account for this fact. See [getSurfaceTransformationMatrix](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/video/surface/ISurface.h) and [Android Developers Guide to Pre-rotation](https://developer.android.com/games/optimize/vulkan-prerotation)
452+
453+
Use [`ISwapchain getSurfaceTransform()`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/video/ISwapchain.h) to get the transformation from swapchain.
454+
455+
- When generating projection matricies, take into account the aspect ratio (which is changed when rotating 90 or 270 degrees). For this, we have helper functions in both GLSL and the ISurface class:
456+
- [`float getTransformedAspectRatio(const E_SURFACE_TRANSFORM_FLAGS transform, uint32_t w, uint32_t h)`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/video/surface/ISurface.h)
457+
- [`nbl_glsl_surface_transform_transformedExtents`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/builtin/glsl/utils/surface_transform.glsl)
458+
459+
- On the swapchain rendering pass, perform **one** of the following transforms:
460+
- If rendering **directly to the swapchain**, you can apply the (post) transform matrix to your projection or combined view-projection matrix **for rendering** (don't pre-multiply with projection matrix for use outside rendering):
461+
- [`matrix4SIMD ISurface::getSurfaceTransformationMatrix(const E_SURFACE_TRANSFORM_FLAGS transform)`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/video/surface/ISurface.h)
462+
- [`nbl_glsl_surface_transform_applyToNDC`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/builtin/glsl/utils/surface_transform.glsl) (This takes in an NDC coordinate and multiplies it with the transform matrix in one function)
463+
464+
- If using `imageStore` to write **directly to the swapchain**, you can either:
465+
- Apply a transform to the screen-space coordinates being written to the swapchain:
466+
- [`nbl_glsl_surface_transform_applyToScreenSpaceCoordinate`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/builtin/glsl/utils/surface_transform.glsl)
467+
- Apply an **inverse** transform to the screen-space coordinates (taken from `gl_GlobalInvocationID.xy`) before turning them into UV/world-space coordinates for rendering:
468+
- [`nbl_glsl_surface_transform_applyInverseToScreenSpaceCoordinate`](https://github.com/Devsh-Graphics-Programming/Nabla/tree/master/include/nbl/builtin/glsl/utils/surface_transform.glsl)
469+
417470
## Automated Builds (TODO)
418471

419472
## License

cmake/common.cmake

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE
3939
if(ANDROID)
4040
add_library(${EXECUTABLE_NAME} SHARED main.cpp ${_EXTRA_SOURCES})
4141
else()
42-
if(NOT NBL_STATIC_BUILD)
43-
set(NBL_CONFIG_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
44-
set(NBL_CONFIG_OUTPUT_FILE ${NBL_CONFIG_OUTPUT_DIRECTORY}/${EXECUTABLE_NAME}$<IF:$<CONFIG:Release>,,$<IF:$<CONFIG:Debug>,_d,_rwdi>>.exe.config)
45-
46-
add_custom_command(OUTPUT "${NBL_CONFIG_OUTPUT_FILE}"
47-
COMMAND ${CMAKE_COMMAND} -DNBL_ROOT_PATH:PATH=${NBL_ROOT_PATH} -DNBL_GEN_DIRECTORY:PATH=${NBL_CONFIG_OUTPUT_DIRECTORY} -DNBL_DLL_PATH:FILEPATH=$<TARGET_FILE:Nabla> -DNBL_TARGET_PATH:FILEPATH=$<TARGET_FILE:${EXECUTABLE_NAME}> -P ${NBL_ROOT_PATH}/cmake/scripts/nbl/applicationMSVCConfig.cmake
48-
COMMENT "Launching ${EXECUTABLE_NAME}.exe.config generation script!"
49-
VERBATIM
50-
)
51-
52-
add_custom_target(${EXECUTABLE_NAME}_with_config ALL DEPENDS ${NBL_CONFIG_OUTPUT_FILE} ${NBL_ROOT_PATH}/cmake/scripts/nbl/applicationMSVCConfig.cmake)
53-
endif()
54-
5542
set(NBL_EXECUTABLE_SOURCES
5643
main.cpp
5744
${_EXTRA_SOURCES}
@@ -61,19 +48,22 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE
6148

6249
if(NBL_DYNAMIC_MSVC_RUNTIME)
6350
set_property(TARGET ${EXECUTABLE_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
51+
52+
if(WIN32 AND MSVC)
53+
set(_NABLA_OUTPUT_DIR_ "${NBL_ROOT_PATH_BINARY}/src/nbl/$<CONFIG>/devshgraphicsprogramming.nabla")
54+
55+
target_link_options(${EXECUTABLE_NAME} PUBLIC "/DELAYLOAD:$<TARGET_FILE_NAME:Nabla>")
56+
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC
57+
_NABLA_DLL_NAME_="$<TARGET_FILE_NAME:Nabla>";_NABLA_OUTPUT_DIR_="${_NABLA_OUTPUT_DIR_}";_NABLA_INSTALL_DIR_="${CMAKE_INSTALL_PREFIX}"
58+
)
59+
endif()
6460
else()
6561
set_property(TARGET ${EXECUTABLE_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
6662
endif()
6763
endif()
6864

6965
# EXTRA_SOURCES is var containing non-common names of sources (if any such sources, then EXTRA_SOURCES must be set before including this cmake code)
70-
if(NBL_STATIC_BUILD)
71-
add_dependencies(${EXECUTABLE_NAME} Nabla)
72-
else()
73-
add_dependencies(${EXECUTABLE_NAME}_with_config Nabla_with_manifest)
74-
#target_link_options(${EXECUTABLE_NAME} PRIVATE "/manifestdependency:\"type='win32' name='devshgraphicsprogramming.nabla' version='1.2.3.4' processorArchitecture='x86' language='*'\"")
75-
endif()
76-
66+
add_dependencies(${EXECUTABLE_NAME} Nabla)
7767
get_target_property(NBL_EGL_INCLUDE_DIRECORIES egl INCLUDE_DIRECTORIES)
7868

7969
target_include_directories(${EXECUTABLE_NAME}
@@ -324,6 +314,12 @@ function(nbl_install_headers _HEADERS _BASE_HEADERS_DIR)
324314
endforeach()
325315
endfunction()
326316

317+
function(nbl_install_file _FILE _RELATIVE_DESTINATION)
318+
install(FILES ${_FILE} DESTINATION include/${_RELATIVE_DESTINATION} CONFIGURATIONS Release)
319+
install(FILES ${_FILE} DESTINATION debug/include/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug)
320+
install(FILES ${_FILE} DESTINATION relwithdebinfo/include/${_RELATIVE_DESTINATION} CONFIGURATIONS RelWithDebInfo)
321+
endfunction()
322+
327323
function(nbl_install_config_header _CONF_HDR_NAME)
328324
nbl_get_conf_dir(dir_deb Debug)
329325
nbl_get_conf_dir(dir_rel Release)

cmake/install/nbl/sharedDefines.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
Those defines are included to the installed define.h header
3+
if the library has been built as DLL.
4+
*/
5+
6+
#define _NABLA_DLL_NAME_ "@_NABLA_DLL_NAME_@"
7+
#define _NABLA_INSTALL_DIR_ @_NABLA_INSTALL_DIR_@

cmake/scripts/nbl/nablaHeader.cmake renamed to cmake/scripts/nbl/nablaDefines.cmake

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ else()
3838
message(FATAL_ERROR "NBL_GEN_DIRECTORY variable must be specified for this script!")
3939
endif()
4040

41-
file(READ "${NBL_ROOT_PATH}/include/nabla.h.in" NBL_NABLA_IMPORT_HEADER_CODE)
42-
file(READ "${NBL_WRAPPER_FILE}" NBL_WRAPPER_CODE)
41+
if(NOT DEFINED _NABLA_DLL_NAME_)
42+
message(FATAL_ERROR "_NABLA_DLL_NAME_ variable must be specified for this script!")
43+
endif()
4344

44-
string(APPEND NBL_NABLA_HEADER "${NBL_WRAPPER_CODE}")
45-
string(APPEND NBL_NABLA_HEADER "${NBL_NABLA_IMPORT_HEADER_CODE}")
45+
if(NOT DEFINED _NABLA_INSTALL_DIR_)
46+
message(FATAL_ERROR "_NABLA_INSTALL_DIR_ variable must be specified for this script!")
47+
endif()
48+
49+
configure_file("${NBL_ROOT_PATH}/cmake/install/nbl/sharedDefines.h.in" "${NBL_GEN_DIRECTORY}/define.h")
50+
file(READ "${NBL_WRAPPER_FILE}" NBL_WRAPPER_CODE)
51+
file(READ "${NBL_GEN_DIRECTORY}/define.h" NBL_WRAPPER_CODE_2)
4652

47-
file(WRITE "${NBL_GEN_DIRECTORY}/nabla.h.in" "${NBL_NABLA_HEADER}")
48-
configure_file("${NBL_GEN_DIRECTORY}/nabla.h.in" "${NBL_GEN_DIRECTORY}/nabla.h") # TODO: replace it with string(CONFIGURE ...) when CMake dev team fix this utility
53+
string(APPEND NBL_NABLA_INSTALL_HEADER "${NBL_WRAPPER_CODE}${NBL_WRAPPER_CODE_2}")
54+
file(WRITE "${NBL_GEN_DIRECTORY}/define.h" "${NBL_NABLA_INSTALL_HEADER}")

include/nbl/asset/IAccelerationStructure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "nbl/asset/format/EFormat.h"
1212
#include "aabbox3d.h"
1313
#define uint uint32_t
14+
#include <compare>
1415
#include "nbl/builtin/glsl/utils/acceleration_structures.glsl"
1516
#undef uint
1617

include/nbl/asset/IBuffer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ struct NBL_API SBufferBinding
6262
template<typename BufferType>
6363
struct NBL_API SBufferRange
6464
{
65+
// Temp Fix, If you want to uncomment this then fix every example having compile issues -> add core::smart_refctd_ptr around the buffer to be an r-value ref
66+
// SBufferRange(const size_t& _offset, const size_t& _size, core::smart_refctd_ptr<BufferType>&& _buffer)
67+
// : offset(_offset), size(_size), buffer(core::smart_refctd_ptr<BufferType>(_buffer)) {}
68+
// SBufferRange() : offset(0ull), size(0ull), buffer(nullptr) {}
69+
6570
inline bool isValid() const
6671
{
6772
return buffer && size && (offset+size<=buffer->getSize());
@@ -70,6 +75,7 @@ struct NBL_API SBufferRange
7075
size_t offset = 0ull;
7176
size_t size = 0ull;
7277
core::smart_refctd_ptr<BufferType> buffer = nullptr;
78+
7379
inline bool operator==(const SBufferRange<BufferType>& rhs) const { return buffer==rhs.buffer && offset==rhs.offset && size==rhs.size; }
7480
inline bool operator!=(const SBufferRange<BufferType>& rhs) const { return !operator==(rhs); }
7581
};

include/nbl/asset/ICPUAnimationLibrary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class NBL_API ICPUAnimationLibrary final : public IAnimationLibrary<ICPUBuffer>,
9999
SBufferBinding<ICPUBuffer> _keyframeStorageBinding = {m_keyframeStorageBinding.offset,_depth>0u ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_keyframeStorageBinding.buffer->clone(_depth-1u)):m_keyframeStorageBinding.buffer};
100100
SBufferBinding<ICPUBuffer> _timestampStorageBinding = {m_timestampStorageBinding.offset,_depth>0u ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_timestampStorageBinding.buffer->clone(_depth-1u)):m_timestampStorageBinding.buffer};
101101

102-
SBufferRange<ICPUBuffer> _animationStorageRange = {m_animationStorageRange.offset,m_animationStorageRange.size,_depth>0u&&m_animationStorageRange.buffer ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_animationStorageRange.buffer->clone(_depth-1u)):m_animationStorageRange.buffer};
102+
SBufferRange<ICPUBuffer> _animationStorageRange = {m_animationStorageRange.offset,m_animationStorageRange.size,_depth>0u&&m_animationStorageRange.buffer ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_animationStorageRange.buffer->clone(_depth-1u)):core::smart_refctd_ptr(m_animationStorageRange.buffer)};
103103

104104
auto cp = core::make_smart_refctd_ptr<ICPUAnimationLibrary>(std::move(_keyframeStorageBinding),std::move(_timestampStorageBinding),m_keyframeCount,std::move(_animationStorageRange));
105105
clone_common(cp.get());

include/nbl/asset/IDescriptorSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define _NBL_ASSET_I_DESCRIPTOR_SET_H_INCLUDED_
77

88
#include <algorithm>
9+
#include <compare>
910

1011

1112
#include "nbl/core/declarations.h"

0 commit comments

Comments
 (0)