Skip to content

Commit

Permalink
Move BitonicSort to vtkext
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Mar 13, 2024
1 parent 33b03d1 commit 6c67d75
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 19 deletions.
2 changes: 1 addition & 1 deletion vtkext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(private)
add_subdirectory(public)
add_subdirectory(private)
7 changes: 1 addition & 6 deletions vtkext/private/Rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions vtkext/private/Rendering/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions vtkext/private/Rendering/vtk.module
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ PRIVATE_DEPENDS
VTK::InteractionWidgets
VTK::RenderingCore
f3d::VTKExtensionsCore
f3d::vtkext
OPTIONAL_DEPENDS
VTK::RenderingExternal
VTK::RenderingRayTracing
Expand Down
28 changes: 27 additions & 1 deletion vtkext/public/module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
18 changes: 13 additions & 5 deletions vtkext/public/module/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
107 changes: 107 additions & 0 deletions vtkext/public/module/Testing/TestF3DBitonicSort.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <vtkOpenGLBufferObject.h>
#include <vtkOpenGLRenderWindow.h>
#include <vtkShader.h>

#include "vtkF3DBitonicSort.h"
#include "vtkF3DBitonicSortFunctions.h"
#include "vtkF3DBitonicSortGlobalDisperseCS.h"
#include "vtkF3DBitonicSortGlobalFlipCS.h"
#include "vtkF3DBitonicSortLocalDisperseCS.h"
#include "vtkF3DBitonicSortLocalSortCS.h"

#include <algorithm>
#include <random>

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<vtkRenderWindow> 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<double> keys(nbElements);
std::vector<int> values(nbElements);

std::random_device dev;
std::mt19937 rng(dev());
std::uniform_real_distribution<double> 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<vtkOpenGLBufferObject> bufferKeys;
vtkNew<vtkOpenGLBufferObject> bufferValues;

bufferKeys->Upload(keys, vtkOpenGLBufferObject::ArrayBuffer);
bufferValues->Upload(values, vtkOpenGLBufferObject::ArrayBuffer);

// sort
vtkNew<vtkF3DBitonicSort> 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;
}
2 changes: 2 additions & 0 deletions vtkext/public/module/vtk.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ DEPENDS
VTK::CommonExecutionModel
PRIVATE_DEPENDS
VTK::CommonCore
VTK::RenderingOpenGL2
TEST_DEPENDS
VTK::TestingCore
VTK::RenderingOpenGL2
File renamed without changes.
File renamed without changes.

0 comments on commit 6c67d75

Please sign in to comment.