mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
creating ray tracing benchmark
This commit is contained in:
parent
a410650655
commit
83e51cf42e
@ -645,7 +645,12 @@ function(vtkm_benchmarks device_adapter)
|
||||
PROPERTIES HEADER_FILE_ONLY TRUE)
|
||||
|
||||
target_include_directories(${benchmark_prog} PRIVATE ${VTKm_BACKEND_INCLUDE_DIRS})
|
||||
target_link_libraries(${benchmark_prog} PRIVATE vtkm_cont ${VTKm_BACKEND_LIBRARIES})
|
||||
|
||||
if(VTKm_ENABLE_RENDERING)
|
||||
set(VTKM_RENDERING_LIBS vtkm_rendering)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${benchmark_prog} PRIVATE vtkm_cont ${VTKM_RENDERING_LIBS} ${VTKm_BACKEND_LIBRARIES})
|
||||
|
||||
vtkm_setup_msvc_properties(${benchmark_prog})
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/internal/RunTriangulator.h>
|
||||
#include <vtkm/rendering/raytracing/Ray.h>
|
||||
#include <vtkm/rendering/raytracing/RayTracer.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
@ -47,41 +49,65 @@ struct BenchRayTracing
|
||||
{
|
||||
vtkm::rendering::raytracing::RayTracer Tracer;
|
||||
vtkm::rendering::raytracing::Camera RayCamera;
|
||||
// Setup anything that doesn't need to change per run in the constructor
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> Indices;
|
||||
vtkm::rendering::raytracing::Ray<Precision> Rays;
|
||||
vtkm::Id NumberOfTriangles;
|
||||
vtkm::cont::CoordinateSystem Coords;
|
||||
vtkm::cont::DataSet Data;
|
||||
|
||||
VTKM_CONT BenchRayTracing()
|
||||
{
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::cont::DataSet data = maker.Make3DUniformDataSet2();
|
||||
Data = maker.Make3DUniformDataSet2();
|
||||
Coords = Data.GetCoordinateSystem();
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
vtkm::Bounds bounds = data.GetCoordinateSystem().GetBounds();
|
||||
vtkm::Bounds bounds = Data.GetCoordinateSystem().GetBounds();
|
||||
camera.ResetToBounds(bounds);
|
||||
|
||||
vtkm::cont::DynamicCellSet cellset = Data.GetCellSet();
|
||||
vtkm::rendering::internal::RunTriangulator(cellset, Indices, NumberOfTriangles);
|
||||
|
||||
vtkm::rendering::CanvasRayTracer canvas(1920, 1080);
|
||||
RayCamera.SetParameters(camera, canvas);
|
||||
RayCamera.CreateRays(Rays, Coords);
|
||||
|
||||
Rays.Buffers.at(0).InitConst(0.f);
|
||||
|
||||
vtkm::cont::Field field = Data.GetField("pointvar");
|
||||
vtkm::Range range = field.GetRange().GetPortalConstControl().Get(0);
|
||||
|
||||
Tracer.SetData(Coords.GetData(), Indices, field, NumberOfTriangles, range, bounds);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 4>> colors;
|
||||
vtkm::rendering::ColorTable("cool2warm").Sample(100, colors);
|
||||
|
||||
Tracer.SetColorMap(colors);
|
||||
Tracer.Render(Rays);
|
||||
}
|
||||
|
||||
// The overloaded call operator will run the operations being timed and
|
||||
// return the execution time
|
||||
VTKM_CONT
|
||||
vtkm::Float64 operator()() { return 0.05; }
|
||||
vtkm::Float64 operator()()
|
||||
{
|
||||
vtkm::cont::Timer<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> timer;
|
||||
|
||||
RayCamera.CreateRays(Rays, Coords);
|
||||
Tracer.Render(Rays);
|
||||
|
||||
return timer.GetElapsedTime();
|
||||
}
|
||||
|
||||
// The benchmark must also provide a method describing itself, this is
|
||||
// used when printing out run time statistics
|
||||
VTKM_CONT
|
||||
std::string Description() const { return "A ray tracing benchmark"; }
|
||||
};
|
||||
|
||||
// Now use the VTKM_MAKE_BENCHMARK macro to generate a maker functor for
|
||||
// your benchmark. This lets us generate the benchmark functor for each type
|
||||
// we want to test
|
||||
VTKM_MAKE_BENCHMARK(RayTracing, BenchRayTracing);
|
||||
}
|
||||
} // end namespace vtkm::benchmarking
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
using Device = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
|
||||
//using Benchmarks = vtkm::benchmarking::BenchRayTracing<Device>;
|
||||
using TestTypes = vtkm::ListTagBase<vtkm::Float32>;
|
||||
VTKM_RUN_BENCHMARK(RayTracing, vtkm::ListTagBase<vtkm::Float32>());
|
||||
//bool result = Benchmarks::Run();
|
||||
//return result ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet1()
|
||||
|
||||
inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet2()
|
||||
{
|
||||
const vtkm::Id base_size = 128;
|
||||
const vtkm::Id base_size = 256;
|
||||
vtkm::cont::DataSetBuilderUniform dsb;
|
||||
vtkm::Id3 dimensions(base_size, base_size, base_size);
|
||||
vtkm::cont::DataSet dataSet = dsb.Create(dimensions);
|
||||
@ -262,6 +262,7 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet2()
|
||||
for (vtkm::Int32 x = 0; x < base_size; ++x)
|
||||
{
|
||||
vtkm::Int32 index = z * base_size * base_size + y * base_size + x;
|
||||
pointvar[index] = vtkm::Sqrt(vtkm::Float32(x * x + y * y + z * z));
|
||||
}
|
||||
|
||||
dsf.AddPointField(dataSet, "pointvar", pointvar, nVerts);
|
||||
|
@ -107,9 +107,9 @@ void MapperRayTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
|
||||
this->Internals->Rays, camera, *this->Internals->Canvas);
|
||||
|
||||
vtkm::Bounds dataBounds = coords.GetBounds();
|
||||
|
||||
vtkm::cont::Field& field = const_cast<vtkm::cont::Field&>(scalarField);
|
||||
this->Internals->Tracer.SetData(
|
||||
coords.GetData(), indices, scalarField, numberOfTriangles, scalarRange, dataBounds);
|
||||
coords.GetData(), indices, field, numberOfTriangles, scalarRange, dataBounds);
|
||||
|
||||
this->Internals->Tracer.SetColorMap(this->ColorMap);
|
||||
this->Internals->Tracer.Render(this->Internals->Rays);
|
||||
|
@ -234,14 +234,14 @@ public:
|
||||
VTKM_CONT void run(Ray<Precision>& rays,
|
||||
LinearBVH& bvh,
|
||||
vtkm::cont::DynamicArrayHandleCoordinateSystem& coordsHandle,
|
||||
const vtkm::cont::Field* scalarField,
|
||||
vtkm::cont::Field& scalarField,
|
||||
const vtkm::Range& scalarRange)
|
||||
{
|
||||
bool isSupportedField = (scalarField->GetAssociation() == vtkm::cont::Field::ASSOC_POINTS ||
|
||||
scalarField->GetAssociation() == vtkm::cont::Field::ASSOC_CELL_SET);
|
||||
bool isSupportedField = (scalarField.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS ||
|
||||
scalarField.GetAssociation() == vtkm::cont::Field::ASSOC_CELL_SET);
|
||||
if (!isSupportedField)
|
||||
throw vtkm::cont::ErrorBadValue("Field not accociated with cell set or points");
|
||||
bool isAssocPoints = scalarField->GetAssociation() == vtkm::cont::Field::ASSOC_POINTS;
|
||||
bool isAssocPoints = scalarField.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS;
|
||||
|
||||
vtkm::worklet::DispatcherMapField<CalculateNormals, Device>(CalculateNormals(bvh.LeafNodes))
|
||||
.Invoke(rays.HitIdx, rays.Dir, rays.NormalX, rays.NormalY, rays.NormalZ, coordsHandle);
|
||||
@ -251,14 +251,14 @@ public:
|
||||
vtkm::worklet::DispatcherMapField<LerpScalar<Precision>, Device>(
|
||||
LerpScalar<Precision>(
|
||||
bvh.LeafNodes, vtkm::Float32(scalarRange.Min), vtkm::Float32(scalarRange.Max)))
|
||||
.Invoke(rays.HitIdx, rays.U, rays.V, rays.Scalar, *scalarField);
|
||||
.Invoke(rays.HitIdx, rays.U, rays.V, rays.Scalar, scalarField);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::worklet::DispatcherMapField<NodalScalar<Precision>, Device>(
|
||||
NodalScalar<Precision>(
|
||||
bvh.LeafNodes, vtkm::Float32(scalarRange.Min), vtkm::Float32(scalarRange.Max)))
|
||||
.Invoke(rays.HitIdx, rays.Scalar, *scalarField);
|
||||
.Invoke(rays.HitIdx, rays.Scalar, scalarField);
|
||||
}
|
||||
} // Run
|
||||
|
||||
@ -398,14 +398,14 @@ Camera& RayTracer::GetCamera()
|
||||
|
||||
void RayTracer::SetData(const vtkm::cont::DynamicArrayHandleCoordinateSystem& coordsHandle,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>>& indices,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
vtkm::cont::Field& scalarField,
|
||||
const vtkm::Id& numberOfTriangles,
|
||||
const vtkm::Range& scalarRange,
|
||||
const vtkm::Bounds& dataBounds)
|
||||
{
|
||||
CoordsHandle = coordsHandle;
|
||||
Indices = indices;
|
||||
ScalarField = &scalarField;
|
||||
ScalarField = scalarField;
|
||||
NumberOfTriangles = numberOfTriangles;
|
||||
ScalarRange = scalarRange;
|
||||
DataBounds = dataBounds;
|
||||
|
@ -34,13 +34,13 @@ namespace rendering
|
||||
namespace raytracing
|
||||
{
|
||||
|
||||
class RayTracer
|
||||
class VTKM_RENDERING_EXPORT RayTracer
|
||||
{
|
||||
protected:
|
||||
LinearBVH Bvh;
|
||||
Camera camera;
|
||||
vtkm::cont::DynamicArrayHandleCoordinateSystem CoordsHandle;
|
||||
const vtkm::cont::Field* ScalarField;
|
||||
vtkm::cont::Field ScalarField;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> Indices;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> Scalars;
|
||||
vtkm::Id NumberOfTriangles;
|
||||
@ -63,7 +63,7 @@ public:
|
||||
VTKM_CONT
|
||||
void SetData(const vtkm::cont::DynamicArrayHandleCoordinateSystem& coordsHandle,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>>& indices,
|
||||
const vtkm::cont::Field& scalarField,
|
||||
vtkm::cont::Field& scalarField,
|
||||
const vtkm::Id& numberOfTriangles,
|
||||
const vtkm::Range& scalarRange,
|
||||
const vtkm::Bounds& dataBounds);
|
||||
|
Loading…
Reference in New Issue
Block a user