Skip to content

Commit

Permalink
Let helium count objects
Browse files Browse the repository at this point in the history
  • Loading branch information
szellmann committed Nov 17, 2024
1 parent 44f77bd commit b27cc3f
Show file tree
Hide file tree
Showing 28 changed files with 8 additions and 237 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ if (hip)
endif()

set(SOURCES
array/Array1D.cpp
array/Array2D.cpp
array/Array3D.cpp
array/ObjectArray.cpp
camera/Camera.cpp
camera/Matrix.cpp
camera/Orthographic.cpp
Expand Down
6 changes: 0 additions & 6 deletions Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ VisionarayGlobalState *Object::deviceState() const
UnknownObject::UnknownObject(ANARIDataType type, VisionarayGlobalState *s)
: Object(type, s)
{
s->objectCounts.unknown++;
}

UnknownObject::~UnknownObject()
{
deviceState()->objectCounts.unknown--;
}

bool UnknownObject::isValid() const
Expand Down
2 changes: 1 addition & 1 deletion Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Object : public helium::BaseObject
struct UnknownObject : public Object
{
UnknownObject(ANARIDataType type, VisionarayGlobalState *s);
~UnknownObject() override;
~UnknownObject() override = default;
bool isValid() const override;
};

Expand Down
37 changes: 1 addition & 36 deletions VisionarayDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,42 +295,7 @@ VisionarayDevice::~VisionarayDevice()

reportMessage(ANARI_SEVERITY_DEBUG, "destroying visionaray device (%p)", this);

// NOTE: These object leak warnings are not required to be done by
// implementations as the debug layer in the SDK is far more
// comprehensive and designed for detecting bugs like this. However
// these simple checks are very straightforward to implement and do not
// really add substantial code complexity, so they are provided out of
// convenience.

auto reportLeaks = [&](auto &count, const char *handleType) {
auto c = count.load();
if (c != 0) {
reportMessage(ANARI_SEVERITY_WARNING,
"detected %zu leaked %s objects",
c,
handleType);
}
};

reportLeaks(state.objectCounts.frames, "ANARIFrame");
reportLeaks(state.objectCounts.cameras, "ANARICamera");
reportLeaks(state.objectCounts.renderers, "ANARIRenderer");
reportLeaks(state.objectCounts.worlds, "ANARIWorld");
reportLeaks(state.objectCounts.instances, "ANARIInstance");
reportLeaks(state.objectCounts.groups, "ANARIGroup");
reportLeaks(state.objectCounts.surfaces, "ANARISurface");
reportLeaks(state.objectCounts.geometries, "ANARIGeometry");
reportLeaks(state.objectCounts.materials, "ANARIMaterial");
reportLeaks(state.objectCounts.samplers, "ANARISampler");
reportLeaks(state.objectCounts.volumes, "ANARIVolume");
reportLeaks(state.objectCounts.spatialFields, "ANARISpatialField");
reportLeaks(state.objectCounts.arrays, "ANARIArray");

if (state.objectCounts.unknown != 0) {
reportMessage(ANARI_SEVERITY_WARNING,
"detected %zu leaked ANARIObject objects created by unknown subtypes",
state.objectCounts.unknown.load());
}
// TODO: clear context?!
}

void VisionarayDevice::initDevice()
Expand Down
21 changes: 0 additions & 21 deletions VisionarayGlobalState.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

// std
#include <atomic>
// helium
#include "helium/BaseGlobalDeviceState.h"
// visionaray
Expand All @@ -18,25 +16,6 @@ struct VisionarayGlobalState : public helium::BaseGlobalDeviceState
{
thread_pool threadPool;

struct ObjectCounts
{
std::atomic<size_t> frames{0};
std::atomic<size_t> cameras{0};
std::atomic<size_t> renderers{0};
std::atomic<size_t> worlds{0};
std::atomic<size_t> instances{0};
std::atomic<size_t> groups{0};
std::atomic<size_t> surfaces{0};
std::atomic<size_t> geometries{0};
std::atomic<size_t> materials{0};
std::atomic<size_t> samplers{0};
std::atomic<size_t> volumes{0};
std::atomic<size_t> spatialFields{0};
std::atomic<size_t> lights{0};
std::atomic<size_t> arrays{0};
std::atomic<size_t> unknown{0};
} objectCounts;

struct ObjectUpdates
{
helium::TimeStamp lastBLSReconstructSceneRequest{0};
Expand Down
21 changes: 0 additions & 21 deletions array/Array1D.cpp

This file was deleted.

10 changes: 1 addition & 9 deletions array/Array1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@

#pragma once

#include "../VisionarayGlobalState.h"
// helium
#include "helium/array/Array1D.h"

namespace visionaray {

using Array1DMemoryDescriptor = helium::Array1DMemoryDescriptor;

struct Array1D : public helium::Array1D
{
Array1D(VisionarayGlobalState *state, const Array1DMemoryDescriptor &d);
~Array1D() override;
};
using Array1D = helium::Array1D;

} // namespace visionaray

VISIONARAY_ANARI_TYPEFOR_SPECIALIZATION(visionaray::Array1D *, ANARI_ARRAY1D);
22 changes: 0 additions & 22 deletions array/Array2D.cpp

This file was deleted.

10 changes: 1 addition & 9 deletions array/Array2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@

#pragma once

#include "../VisionarayGlobalState.h"
// helium
#include "helium/array/Array2D.h"

namespace visionaray {

using Array2DMemoryDescriptor = helium::Array2DMemoryDescriptor;

struct Array2D : public helium::Array2D
{
Array2D(VisionarayGlobalState *state, const Array2DMemoryDescriptor &d);
~Array2D() override;
};
using Array2D = helium::Array2D;

} // namespace visionaray

VISIONARAY_ANARI_TYPEFOR_SPECIALIZATION(visionaray::Array2D *, ANARI_ARRAY2D);
21 changes: 0 additions & 21 deletions array/Array3D.cpp

This file was deleted.

10 changes: 1 addition & 9 deletions array/Array3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@

#pragma once

#include "../VisionarayGlobalState.h"
// helium
#include "helium/array/Array3D.h"

namespace visionaray {

using Array3DMemoryDescriptor = helium::Array3DMemoryDescriptor;

struct Array3D : public helium::Array3D
{
Array3D(VisionarayGlobalState *state, const Array3DMemoryDescriptor &d);
~Array3D() override;
};
using Array3D = helium::Array3D;

} // namespace visionaray

VISIONARAY_ANARI_TYPEFOR_SPECIALIZATION(visionaray::Array3D *, ANARI_ARRAY3D);
23 changes: 0 additions & 23 deletions array/ObjectArray.cpp

This file was deleted.

10 changes: 1 addition & 9 deletions array/ObjectArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@

#pragma once

#include "../VisionarayGlobalState.h"
#include "Array1D.h"
// helium
#include "helium/array/ObjectArray.h"

namespace visionaray {

struct ObjectArray : public helium::ObjectArray
{
ObjectArray(VisionarayGlobalState *state, const Array1DMemoryDescriptor &d);
~ObjectArray() override;
};
using ObjectArray = helium::ObjectArray;

} // namespace visionaray

VISIONARAY_ANARI_TYPEFOR_SPECIALIZATION(visionaray::ObjectArray *, ANARI_ARRAY1D);
6 changes: 0 additions & 6 deletions camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ namespace visionaray {
Camera::Camera(VisionarayGlobalState *s) : Object(ANARI_CAMERA, s)
{
vcam = dco::createCamera();
s->objectCounts.cameras++;
}

Camera::~Camera()
{
deviceState()->objectCounts.cameras--;
}

Camera *Camera::createInstance(std::string_view type, VisionarayGlobalState *s)
Expand Down
2 changes: 1 addition & 1 deletion camera/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace visionaray {
struct Camera : public Object
{
Camera(VisionarayGlobalState *s);
~Camera() override;
virtual ~Camera() = default;

virtual void commit() override;

Expand Down
2 changes: 0 additions & 2 deletions frame/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Frame::Frame(VisionarayGlobalState *s) : helium::BaseFrame(s)
{
vframe = dco::createFrame();
vframe.frameID = deviceState()->dcos.frames.alloc(vframe);
s->objectCounts.frames++;
#ifdef WITH_CUDA
CUDA_SAFE_CALL(cudaEventCreate(&m_eventStart));
CUDA_SAFE_CALL(cudaEventCreate(&m_eventStop));
Expand Down Expand Up @@ -64,7 +63,6 @@ Frame::~Frame()
HIP_SAFE_CALL(hipEventDestroy(m_eventStop));
#endif
deviceState()->dcos.frames.free(vframe.frameID);
deviceState()->objectCounts.frames--;
}

bool Frame::isValid() const
Expand Down
10 changes: 0 additions & 10 deletions renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ Renderer::Renderer(VisionarayGlobalState *s)
: Object(ANARI_RENDERER, s)
, m_clipPlanes(this)
{
s->objectCounts.renderers++;

Array1DMemoryDescriptor md;
md.elementType = ANARI_FLOAT32_VEC3;
md.numItems = 4;
}

Renderer::~Renderer()
{
deviceState()->objectCounts.renderers--;
}

void Renderer::commit()
Expand Down
2 changes: 1 addition & 1 deletion renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct VisionarayRenderer
struct Renderer : public Object
{
Renderer(VisionarayGlobalState *s);
~Renderer() override;
virtual ~Renderer() = default;

virtual void commit() override;

Expand Down
2 changes: 0 additions & 2 deletions scene/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ Group::Group(VisionarayGlobalState *s)
, m_volumeData(this)
, m_lightData(this)
{
s->objectCounts.groups++;
}

Group::~Group()
{
cleanup();
deviceState()->objectCounts.groups--;
}

bool Group::getProperty(
Expand Down
3 changes: 0 additions & 3 deletions scene/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ Instance::Instance(VisionarayGlobalState *s) : Object(ANARI_INSTANCE, s)
vinstance.type = dco::Instance::Transform;
vinstance.instID
= deviceState()->dcos.instances.alloc(vinstance);
s->objectCounts.instances++;
}

Instance::~Instance()
{
deviceState()->dcos.instances.free(vinstance.instID);

deviceState()->objectCounts.instances--;
}

Instance *Instance::createInstance(
Expand Down
3 changes: 0 additions & 3 deletions scene/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ World::World(VisionarayGlobalState *s)
, m_zeroLightData(this)
, m_instanceData(this)
{
s->objectCounts.worlds++;

m_zeroGroup = new Group(s);
m_zeroInstance = new Instance(s);
m_zeroInstance->setParamDirect("group", m_zeroGroup.ptr);
Expand All @@ -26,7 +24,6 @@ World::World(VisionarayGlobalState *s)
World::~World()
{
cleanup();
deviceState()->objectCounts.worlds--;
}

bool World::getProperty(
Expand Down
Loading

0 comments on commit b27cc3f

Please sign in to comment.