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

Magnum batch renderer prototype #1798

Merged
merged 11 commits into from
Jul 20, 2022
12 changes: 12 additions & 0 deletions data/test_assets/scenes/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# You have to add the following to your .git/config or global
# ~/.gitconfig to make the binary diffs work (without the comment
# character, of course):
#
# [diff "hex"]
# textconv = hexdump -v -C
# binary = true
#

*.ktx2 binary diff=hex
*.glb binary diff=hex
*.bin binary diff=hex
Binary file added data/test_assets/scenes/batch.0.ktx2
Binary file not shown.
Binary file added data/test_assets/scenes/batch.bin
Binary file not shown.
273 changes: 273 additions & 0 deletions data/test_assets/scenes/batch.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
{
"asset": {
"version": "2.0",
"generator": "Magnum GltfSceneConverter"
},
"extensionsUsed": [
"MAGNUMX_mesh_views",
"KHR_texture_ktx"
],
"extensionsRequired": [
"MAGNUMX_mesh_views",
"KHR_texture_ktx"
],
"buffers": [
{
"uri": "batch.bin",
"byteLength": 1820
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 444
},
{
"buffer": 0,
"byteOffset": 444,
"byteLength": 1356,
"byteStride": 32
},
{
"buffer": 0,
"byteOffset": 456,
"byteLength": 1356,
"byteStride": 32
},
{
"buffer": 0,
"byteOffset": 468,
"byteLength": 1352,
"byteStride": 32
}
],
"accessors": [
{
"bufferView": 0,
"componentType": 5125,
"count": 111,
"type": "SCALAR"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 43,
"type": "VEC3"
},
{
"bufferView": 2,
"componentType": 5126,
"count": 43,
"type": "VEC3"
},
{
"bufferView": 3,
"componentType": 5126,
"count": 43,
"type": "VEC2"
}
],
"images": [
{
"uri": "batch.0.ktx2"
}
],
"samplers": [
{
"wrapS": 10497,
"wrapT": 10497,
"minFilter": 9984,
"magFilter": 9728
}
],
"textures": [
{
"sampler": 0,
"extensions": {
"KHR_texture_ktx": {
"source": 0,
"layer": 0
}
}
},
{
"sampler": 0,
"extensions": {
"KHR_texture_ktx": {
"source": 0,
"layer": 1
}
}
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
}
}
},
{
"pbrMetallicRoughness": {
"baseColorFactor": [0, 1, 1, 1],
"baseColorTexture": {
"index": 1,
"extensions": {
"KHR_texture_transform": {
"scale": [0.5, 0.5],
"offset": [0, 0.5]
}
}
}
}
},
{
"pbrMetallicRoughness": {
"baseColorFactor": [1, 0, 1, 1],
"baseColorTexture": {
"index": 1,
"extensions": {
"KHR_texture_transform": {
"scale": [0.5, 0.5],
"offset": [0.5, 0.5]
}
}
}
}
},
{
"pbrMetallicRoughness": {
"baseColorFactor": [1, 1, 0, 1],
"baseColorTexture": {
"index": 1,
"extensions": {
"KHR_texture_transform": {
"scale": [0.5, 0.5],
"offset": [0, 0]
}
}
}
}
}
],
"meshes": [
{
"primitives": [
{
"indices": 0,
"attributes": {
"POSITION": 1,
"NORMAL": 2,
"TEXCOORD_0": 3
}
}
]
}
],
"nodes": [
{
"children": [1],
"name": "square"
},
{
"mesh": 0,
"extras": {
"meshViewIndexOffset": 0,
"meshViewIndexCount": 6,
"meshViewMaterial": 0
}
},
{
"children": [3],
"name": "circle"
},
{
"mesh": 0,
"extras": {
"meshViewIndexOffset": 24,
"meshViewIndexCount": 96,
"meshViewMaterial": 1
}
},
{
"children": [5],
"name": "triangle"
},
{
"mesh": 0,
"extras": {
"meshViewIndexOffset": 408,
"meshViewIndexCount": 9,
"meshViewMaterial": 2
}
},
{
"children": [7, 8, 9, 10],
"name": "four squares"
},
{
"mesh": 0,
"matrix": [
0.4, 0, 0, 0,
0, 0.4, 0, 0,
0, 0, 0.4, 0,
-0.5, -0.5, 0, 1
],
"extras": {
"meshViewIndexOffset": 0,
"meshViewIndexCount": 6,
"meshViewMaterial": 0
}
},
{
"mesh": 0,
"matrix": [
0.4, 0, 0, 0,
0, 0.4, 0, 0,
0, 0, 0.4, 0,
0.5, -0.5, 0, 1
],
"extras": {
"meshViewIndexOffset": 0,
"meshViewIndexCount": 6,
"meshViewMaterial": 1
}
},
{
"mesh": 0,
"matrix": [
0.4, 0, 0, 0,
0, 0.4, 0, 0,
0, 0, 0.4, 0,
-0.5, 0.5, 0, 1
],
"extras": {
"meshViewIndexOffset": 0,
"meshViewIndexCount": 6,
"meshViewMaterial": 2
}
},
{
"mesh": 0,
"matrix": [
0.4, 0, 0, 0,
0, 0.4, 0, 0,
0, 0, 0.4, 0,
0.5, 0.5, 0, 1
],
"extras": {
"meshViewIndexOffset": 0,
"meshViewIndexCount": 6,
"meshViewMaterial": 3
}
}
],
"scenes": [
{
"nodes": [0, 2, 4, 6]
}
],
"scene": 0
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/cmake/FindMagnumPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# FreeTypeFont - FreeType font
# GlslangShaderConverter - Glslang shader converter
# GltfImporter - glTF importer
# GltfSceneConverter - glTF converter
# HarfBuzzFont - HarfBuzz font
# IcoImporter - ICO importer
# JpegImageConverter - JPEG image converter
Expand Down Expand Up @@ -160,8 +161,8 @@ set(_MAGNUMPLUGINS_PLUGIN_COMPONENTS
AssimpImporter AstcImporter BasisImageConverter BasisImporter DdsImporter
DevIlImageImporter DrFlacAudioImporter DrMp3AudioImporter
DrWavAudioImporter Faad2AudioImporter FreeTypeFont GlslangShaderConverter
GltfImporter HarfBuzzFont IcoImporter JpegImageConverter JpegImporter
KtxImageConverter KtxImporter MeshOptimizerSceneConverter
GltfImporter GltfSceneConverter HarfBuzzFont IcoImporter JpegImageConverter
JpegImporter KtxImageConverter KtxImporter MeshOptimizerSceneConverter
MiniExrImageConverter OpenExrImageConverter OpenExrImporter
OpenGexImporter PngImageConverter PngImporter PrimitiveImporter
SpirvToolsShaderConverter StanfordImporter StanfordSceneConverter
Expand Down Expand Up @@ -379,6 +380,7 @@ foreach(_component ${MagnumPlugins_FIND_COMPONENTS})
INTERFACE_LINK_LIBRARIES Glslang::Glslang)

# GltfImporter has no dependencies
# GltfSceneConverter has no dependencies

# HarfBuzzFont plugin dependencies
elseif(_component STREQUAL HarfBuzzFont)
Expand Down
8 changes: 8 additions & 0 deletions src/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ if(NOT USE_SYSTEM_MAGNUM)
set(MAGNUM_WITH_GLTFIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_ANYIMAGEIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_ANYIMAGECONVERTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_KTXIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_PRIMITIVEIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_STANFORDIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_STBIMAGEIMPORTER ON CACHE BOOL "" FORCE)
Expand All @@ -215,6 +216,13 @@ if(NOT USE_SYSTEM_MAGNUM)
set(MAGNUM_WITH_GLFWAPPLICATION OFF CACHE BOOL "" FORCE)
set(MAGNUM_WITH_EIGEN ON CACHE BOOL "" FORCE) # Eigen integration
set(MAGNUM_WITH_IMGUI ON CACHE BOOL "" FORCE) # ImGui integration
# GltfSceneConverter and KtxImageConverter needed by BatchRendererTest,
# GltfSceneConverter is not in magnum-plugins master yet
#set(MAGNUM_WITH_GLTFSCENECONVERTER ON CACHE BOOL "" FORCE)
# Has to be enabled because otherwise
# find_package(MagnumPlugins OPTIONAL KtxImageConverter)
# with a CMake subproject causes a CMake error. TODO: fix in the Find module
set(MAGNUM_WITH_KTXIMAGECONVERTER ON CACHE BOOL "" FORCE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't expect Habitat users to be doing KTX compression, except in offline tools. (I know we also imagine a load-time preprocessing use case that could invoke this, but I hope to discourage users from this mode of operation.)

Any concern about including this by default in the Habitat runtime, in terms of binary size bloat or whatever? An alternative would be a build switch that is off by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, actually, the reason I put it here is because find_package(MagnumPlugins OPTIONAL_COMPONENTS KtxImageConverter) causes a CMake error otherwise 🔥 Which I have to fix.

But this particular plugin (unlike e.g. Basis, or OpenEXR) is a tiny self-contained 400-line code with no external dependencies that builds fast, so it felt like a good enough tradeoff until I fix the CMake modules.

Will add a TODO there, at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO added.

if(BUILD_PYTHON_BINDINGS)
set(MAGNUM_WITH_PYTHON ON CACHE BOOL "" FORCE) # Python bindings
endif()
Expand Down
1 change: 1 addition & 0 deletions src/esp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ endif()
add_subdirectory(core)
add_subdirectory(geo)
add_subdirectory(gfx)
add_subdirectory(gfx_batch)
add_subdirectory(assets)
add_subdirectory(metadata)
add_subdirectory(io)
Expand Down
1 change: 1 addition & 0 deletions src/esp/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ configure_file(
)

find_package(Corrade REQUIRED Utility)
find_package(MagnumIntegration REQUIRED Eigen)

add_library(
core STATIC
Expand Down
5 changes: 4 additions & 1 deletion src/esp/gfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ 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}/cuda_helpers
${CMAKE_CURRENT_LIST_DIR}/../gfx_batch/cuda_helpers
)

target_link_libraries(gfx PUBLIC ${CUDART_LIBRARY})
Expand Down
Loading