diff --git a/vtkext/CMakeLists.txt b/vtkext/CMakeLists.txt index b4bca7943c..751cb90aaf 100644 --- a/vtkext/CMakeLists.txt +++ b/vtkext/CMakeLists.txt @@ -1,2 +1,2 @@ -add_subdirectory(private) add_subdirectory(public) +add_subdirectory(private) diff --git a/vtkext/private/Rendering/CMakeLists.txt b/vtkext/private/Rendering/CMakeLists.txt index 34472bad10..8f5df67a34 100644 --- a/vtkext/private/Rendering/CMakeLists.txt +++ b/vtkext/private/Rendering/CMakeLists.txt @@ -11,11 +11,6 @@ set(private_headers ${CMAKE_CURRENT_BINARY_DIR}/F3DDefaultHDRI.h) set(shader_files - glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl - glsl/vtkF3DBitonicSortGlobalFlipCS.glsl - glsl/vtkF3DBitonicSortLocalDisperseCS.glsl - glsl/vtkF3DBitonicSortLocalSortCS.glsl - glsl/vtkF3DBitonicSortFunctions.glsl glsl/vtkF3DComputeDepthCS.glsl) foreach(file IN LISTS shader_files) @@ -46,7 +41,7 @@ set(classes # Needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10675 if(NOT ANDROID AND NOT EMSCRIPTEN AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240203) - set(classes ${classes} vtkF3DBitonicSort vtkF3DPointSplatMapper) + set(classes ${classes} vtkF3DPointSplatMapper) endif() if(NOT VTK_VERSION VERSION_GREATER_EQUAL 9.2.20220907) diff --git a/vtkext/private/Rendering/Testing/CMakeLists.txt b/vtkext/private/Rendering/Testing/CMakeLists.txt index 6ce40e049b..54ae787858 100644 --- a/vtkext/private/Rendering/Testing/CMakeLists.txt +++ b/vtkext/private/Rendering/Testing/CMakeLists.txt @@ -11,12 +11,6 @@ list(APPEND VTKExtensionsRenderingTests_list TestF3DCachedTexturesPrint.cxx ) -# Also needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10675 -if(NOT ANDROID AND NOT EMSCRIPTEN AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240203) - list(APPEND VTKExtensionsRenderingTests_list - TestF3DBitonicSort.cxx) -endif() - vtk_add_test_cxx(VTKExtensionsRenderingTests tests NO_DATA NO_VALID NO_OUTPUT ${VTKExtensionsRenderingTests_list} diff --git a/vtkext/private/Rendering/vtk.module b/vtkext/private/Rendering/vtk.module index 936681dabb..df3fdd710e 100644 --- a/vtkext/private/Rendering/vtk.module +++ b/vtkext/private/Rendering/vtk.module @@ -15,6 +15,7 @@ PRIVATE_DEPENDS VTK::InteractionWidgets VTK::RenderingCore f3d::VTKExtensionsCore + f3d::vtkext OPTIONAL_DEPENDS VTK::RenderingExternal VTK::RenderingRayTracing diff --git a/vtkext/public/module/CMakeLists.txt b/vtkext/public/module/CMakeLists.txt index 88b9637396..a9d99d9a13 100644 --- a/vtkext/public/module/CMakeLists.txt +++ b/vtkext/public/module/CMakeLists.txt @@ -1,6 +1,32 @@ +set(shader_files + glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl + glsl/vtkF3DBitonicSortGlobalFlipCS.glsl + glsl/vtkF3DBitonicSortLocalDisperseCS.glsl + glsl/vtkF3DBitonicSortLocalSortCS.glsl + glsl/vtkF3DBitonicSortFunctions.glsl) + +foreach(file IN LISTS shader_files) + vtk_encode_string( + INPUT "${file}" + HEADER_OUTPUT header + SOURCE_OUTPUT source) + list(APPEND sources + "${source}") + list(APPEND private_headers + "${header}") +endforeach() + set(classes vtkF3DFaceVaryingPointDispatcher ) +# Needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10675 +if(NOT ANDROID AND NOT EMSCRIPTEN AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240203) + set(classes ${classes} vtkF3DBitonicSort) +endif() + vtk_module_add_module(f3d::vtkext - CLASSES ${classes}) + CLASSES ${classes} + SOURCES ${sources} + PRIVATE_HEADERS ${private_headers} + ) diff --git a/vtkext/public/module/Testing/CMakeLists.txt b/vtkext/public/module/Testing/CMakeLists.txt index 256d3c65d4..c1c907852e 100644 --- a/vtkext/public/module/Testing/CMakeLists.txt +++ b/vtkext/public/module/Testing/CMakeLists.txt @@ -3,8 +3,16 @@ if(VTK_VERSION VERSION_LESS_EQUAL 9.1.0) cmake_policy(SET CMP0115 OLD) endif() -#vtk_add_test_cxx(VTKExtensionsCoreTests tests -# NO_DATA NO_VALID NO_OUTPUT -# TestF3DLog.cxx -# ${F3D_SOURCE_DIR}/testing/ ${CMAKE_BINARY_DIR}/Testing/Temporary/) -#vtk_test_cxx_executable(VTKExtensionsCoreTests tests) +set(vtkextTests_list) + +# Also needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10675 +if(NOT ANDROID AND NOT EMSCRIPTEN AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240203) + list(APPEND vtkextTests_list + TestF3DBitonicSort.cxx) +endif() + +vtk_add_test_cxx(vtkextTests tests + NO_DATA NO_VALID NO_OUTPUT + ${vtkextTests_list} + ${F3D_SOURCE_DIR}/testing/ ${CMAKE_BINARY_DIR}/Testing/Temporary/) +vtk_test_cxx_executable(vtkextTests tests) diff --git a/vtkext/public/module/Testing/TestF3DBitonicSort.cxx b/vtkext/public/module/Testing/TestF3DBitonicSort.cxx new file mode 100644 index 0000000000..f5eca637f4 --- /dev/null +++ b/vtkext/public/module/Testing/TestF3DBitonicSort.cxx @@ -0,0 +1,107 @@ +#include +#include +#include + +#include "vtkF3DBitonicSort.h" +#include "vtkF3DBitonicSortFunctions.h" +#include "vtkF3DBitonicSortGlobalDisperseCS.h" +#include "vtkF3DBitonicSortGlobalFlipCS.h" +#include "vtkF3DBitonicSortLocalDisperseCS.h" +#include "vtkF3DBitonicSortLocalSortCS.h" + +#include +#include + +int TestF3DBitonicSort(int argc, char* argv[]) +{ + // Turn off VTK error reporting to avoid unwanted failure detection by ctest + vtkObject::GlobalWarningDisplayOff(); + + // we need an OpenGL context + vtkNew renWin; + renWin->OffScreenRenderingOn(); + renWin->Start(); + + if (!vtkShader::IsComputeShaderSupported()) + { + std::cerr << "Compute shaders are not supported on this system, skipping the test.\n"; + return EXIT_SUCCESS; + } + + constexpr int nbElements = 10000; + + // fill CPU keys and values buffers + std::vector keys(nbElements); + std::vector values(nbElements); + + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_real_distribution dist(0.0, 1.0); + + std::generate(std::begin(keys), std::end(keys), [&]() { return dist(rng); }); + std::fill(std::begin(values), std::end(values), 0); // we do not care about the values + + // upload these buffers to the GPU + vtkNew bufferKeys; + vtkNew bufferValues; + + bufferKeys->Upload(keys, vtkOpenGLBufferObject::ArrayBuffer); + bufferValues->Upload(values, vtkOpenGLBufferObject::ArrayBuffer); + + // sort + vtkNew sorter; + + // check invalid workgroup size + if (sorter->Initialize(-1, VTK_FLOAT, VTK_FLOAT)) + { + std::cerr << "The invalid workgroup size is not failing" << std::endl; + return EXIT_FAILURE; + } + + // check invalid types + if (sorter->Initialize(128, VTK_CHAR, VTK_FLOAT)) + { + std::cerr << "The invalid key type is not failing" << std::endl; + return EXIT_FAILURE; + } + + if (sorter->Initialize(128, VTK_FLOAT, VTK_CHAR)) + { + std::cerr << "The invalid key type is not failing" << std::endl; + return EXIT_FAILURE; + } + + if (sorter->Run( + vtkOpenGLRenderWindow::SafeDownCast(renWin), nbElements, bufferKeys, bufferValues)) + { + std::cerr << "Uninitialized run is not failing" << std::endl; + return EXIT_FAILURE; + } + + if (!sorter->Initialize(128, VTK_DOUBLE, VTK_INT)) + { + std::cerr << "Valid Initialize call failed" << std::endl; + return EXIT_FAILURE; + } + + if (!sorter->Run( + vtkOpenGLRenderWindow::SafeDownCast(renWin), nbElements, bufferKeys, bufferValues)) + { + std::cerr << "Sorter Run call failed" << std::endl; + return EXIT_FAILURE; + } + + // download sorted key buffer to CPU + bufferKeys->Download(keys.data(), keys.size()); + + // check if correctly sorted + for (int i = 1; i < nbElements; i++) + { + if (keys[i - 1] > keys[i]) + { + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/vtkext/private/Rendering/glsl/vtkF3DBitonicSortFunctions.glsl b/vtkext/public/module/glsl/vtkF3DBitonicSortFunctions.glsl similarity index 100% rename from vtkext/private/Rendering/glsl/vtkF3DBitonicSortFunctions.glsl rename to vtkext/public/module/glsl/vtkF3DBitonicSortFunctions.glsl diff --git a/vtkext/private/Rendering/glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl b/vtkext/public/module/glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl similarity index 100% rename from vtkext/private/Rendering/glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl rename to vtkext/public/module/glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl diff --git a/vtkext/private/Rendering/glsl/vtkF3DBitonicSortGlobalFlipCS.glsl b/vtkext/public/module/glsl/vtkF3DBitonicSortGlobalFlipCS.glsl similarity index 100% rename from vtkext/private/Rendering/glsl/vtkF3DBitonicSortGlobalFlipCS.glsl rename to vtkext/public/module/glsl/vtkF3DBitonicSortGlobalFlipCS.glsl diff --git a/vtkext/private/Rendering/glsl/vtkF3DBitonicSortLocalDisperseCS.glsl b/vtkext/public/module/glsl/vtkF3DBitonicSortLocalDisperseCS.glsl similarity index 100% rename from vtkext/private/Rendering/glsl/vtkF3DBitonicSortLocalDisperseCS.glsl rename to vtkext/public/module/glsl/vtkF3DBitonicSortLocalDisperseCS.glsl diff --git a/vtkext/private/Rendering/glsl/vtkF3DBitonicSortLocalSortCS.glsl b/vtkext/public/module/glsl/vtkF3DBitonicSortLocalSortCS.glsl similarity index 100% rename from vtkext/private/Rendering/glsl/vtkF3DBitonicSortLocalSortCS.glsl rename to vtkext/public/module/glsl/vtkF3DBitonicSortLocalSortCS.glsl diff --git a/vtkext/public/module/vtk.module b/vtkext/public/module/vtk.module index 2e185cedc7..9c8461dfb8 100644 --- a/vtkext/public/module/vtk.module +++ b/vtkext/public/module/vtk.module @@ -6,5 +6,7 @@ DEPENDS VTK::CommonExecutionModel PRIVATE_DEPENDS VTK::CommonCore + VTK::RenderingOpenGL2 TEST_DEPENDS VTK::TestingCore + VTK::RenderingOpenGL2 diff --git a/vtkext/private/Rendering/vtkF3DBitonicSort.cxx b/vtkext/public/module/vtkF3DBitonicSort.cxx similarity index 100% rename from vtkext/private/Rendering/vtkF3DBitonicSort.cxx rename to vtkext/public/module/vtkF3DBitonicSort.cxx diff --git a/vtkext/private/Rendering/vtkF3DBitonicSort.h b/vtkext/public/module/vtkF3DBitonicSort.h similarity index 100% rename from vtkext/private/Rendering/vtkF3DBitonicSort.h rename to vtkext/public/module/vtkF3DBitonicSort.h