-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
994 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[codespell] | ||
skip = ./testing/**/*,./.git/**/*,./**/*.patch,./external/cxxopts/cxxopts.hpp,./external/nlohmann_json/nlohmann/json.hpp | ||
ignore-words-list=nnumber,unknwn,dota,modle | ||
ignore-words-list=nnumber,unknwn,dota,modle,inout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
a4cb9c6c90c18a31e225aa4a18df6a591bf8cd3b | ||
be69fa3a50de292857e69702885576ac6f114805 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
library/VTKExtensions/Rendering/Testing/TestF3DBitonicSort.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#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> | ||
#include <sstream> | ||
|
||
int TestF3DBitonicSort(int argc, char* argv[]) | ||
{ | ||
// 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; | ||
sorter->Initialize(128, VTK_DOUBLE, VTK_INT); | ||
sorter->Run(vtkOpenGLRenderWindow::SafeDownCast(renWin), nbElements, bufferKeys, bufferValues); | ||
|
||
// 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; | ||
} |
42 changes: 42 additions & 0 deletions
42
library/VTKExtensions/Rendering/glsl/vtkF3DBitonicSortFunctions.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
ivec2 disperse(uint t, uint h) | ||
{ | ||
uint q = (t / h) * 2 * h; | ||
|
||
uint x = q + t % h; | ||
uint y = q + t % h + h; | ||
|
||
return ivec2(x, y); | ||
} | ||
|
||
ivec2 flip(uint t, uint h) | ||
{ | ||
uint q = (t / h) * 2 * h; | ||
|
||
uint x = q + t % h; | ||
uint y = q + 2 * h - (t % h) - 1; | ||
|
||
return ivec2(x, y); | ||
} | ||
|
||
void swap_key(inout KeyType key1, inout KeyType key2) | ||
{ | ||
KeyType tmp = key1; | ||
key1 = key2; | ||
key2 = tmp; | ||
} | ||
|
||
void swap_value(inout ValueType value1, inout ValueType value2) | ||
{ | ||
ValueType tmp = value1; | ||
value1 = value2; | ||
value2 = tmp; | ||
} | ||
|
||
void compare_and_swap(ivec2 idx) | ||
{ | ||
if (key[idx.x] > key[idx.y] && idx.y < count) | ||
{ | ||
swap_key(key[idx.x], key[idx.y]); | ||
swap_value(value[idx.x], value[idx.y]); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
library/VTKExtensions/Rendering/glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#version 430 | ||
|
||
//VTK::BitonicDefines::Dec | ||
|
||
layout(local_size_x = WorkgroupSize) in; | ||
layout(std430) buffer; | ||
|
||
layout(binding = 0) buffer Keys | ||
{ | ||
KeyType key[]; | ||
}; | ||
|
||
layout(binding = 1) buffer Values | ||
{ | ||
ValueType value[]; | ||
}; | ||
|
||
layout(location = 0) uniform int count; | ||
layout(location = 1) uniform int height; | ||
|
||
//VTK::BitonicFunctions::Dec | ||
|
||
void main() | ||
{ | ||
compare_and_swap(disperse(gl_GlobalInvocationID.x, height)); | ||
} |
26 changes: 26 additions & 0 deletions
26
library/VTKExtensions/Rendering/glsl/vtkF3DBitonicSortGlobalFlipCS.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#version 430 | ||
|
||
//VTK::BitonicDefines::Dec | ||
|
||
layout(local_size_x = WorkgroupSize) in; | ||
layout(std430) buffer; | ||
|
||
layout(binding = 0) buffer Keys | ||
{ | ||
KeyType key[]; | ||
}; | ||
|
||
layout(binding = 1) buffer Values | ||
{ | ||
ValueType value[]; | ||
}; | ||
|
||
layout(location = 0) uniform int count; | ||
layout(location = 1) uniform int height; | ||
|
||
//VTK::BitonicFunctions::Dec | ||
|
||
void main() | ||
{ | ||
compare_and_swap(flip(gl_GlobalInvocationID.x, height)); | ||
} |
Oops, something went wrong.