Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helide device updates + CTS tweaks #78

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions cts/header/PrimitiveGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,9 @@ class PrimitiveGenerator
size_t primitiveCount);

template <typename T>
std::vector<T> shuffleVector(std::vector<T> vector)
void shuffleVector(std::vector<T> &vector)
{
size_t size = vector.size();
size_t counter = 0;
for (auto it = vector.begin(); it != vector.end(); ++it) {
size_t randomIndex = static_cast<size_t>(std::round(getRandomFloat(0, static_cast<float>(size - 1))));
std::iter_swap(it, it + (randomIndex - counter));
++counter;
}
return vector;
std::shuffle(vector.begin(), vector.end(), m_rng);
}

private:
Expand Down
31 changes: 13 additions & 18 deletions cts/src/SceneGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void SceneGenerator::commit()

// build this scene top-down to stress commit ordering guarantees
// setup lighting, material and empty geometry
setDefaultLight(m_world);
setDefaultLight(m_world);

auto surface = anari::newObject<anari::Surface>(d);
auto geom = anari::newObject<anari::Geometry>(d, geometrySubtype.c_str());
Expand Down Expand Up @@ -154,7 +154,7 @@ void SceneGenerator::commit()

if (primitiveMode == "indexed") {
// shuffle indices vector to create a more useful test case
indices = generator.shuffleVector(indices);
generator.shuffleVector(indices);
indiciCount = indices.size();
anari::setAndReleaseParameter(d,
geom,
Expand Down Expand Up @@ -184,7 +184,7 @@ void SceneGenerator::commit()

if (primitiveMode == "indexed") {
// shuffle indices vector to create a more useful test case
indices = generator.shuffleVector(indices);
generator.shuffleVector(indices);
indiciCount = indices.size();
anari::setAndReleaseParameter(d,
geom,
Expand All @@ -208,7 +208,7 @@ void SceneGenerator::commit()
}

// shuffle indices vector to create a more useful test case
indices = generator.shuffleVector(indices);
generator.shuffleVector(indices);
anari::setAndReleaseParameter(d,
geom,
"primitive.index",
Expand All @@ -225,12 +225,11 @@ void SceneGenerator::commit()

if (primitiveMode == "indexed") {
std::vector<uint32_t> indices;
for (size_t i = 0; i < vertices.size() / 2; i += 1) {
indices.push_back(static_cast<uint32_t>(i) * 2);
}
for (uint32_t i = 0; i < vertices.size() / 2; i++)
indices.push_back(i * 2);

// shuffle indices vector to create a more useful test case
indices = generator.shuffleVector(indices);
generator.shuffleVector(indices);
indiciCount = indices.size();
anari::setAndReleaseParameter(d,
geom,
Expand All @@ -249,13 +248,11 @@ void SceneGenerator::commit()

if (primitiveMode == "indexed") {
std::vector<glm::uvec2> indices;
for (size_t i = 0; i < vertices.size(); i += 2) {
indices.push_back(
glm::vec2(static_cast<uint32_t>(i), static_cast<uint32_t>(i + 1)));
}
for (uint32_t i = 0; i < vertices.size(); i += 2)
indices.emplace_back(i, i + 1);

// shuffle indices vector to create a more useful test case
indices = generator.shuffleVector(indices);
generator.shuffleVector(indices);
indiciCount = indices.size();
anari::setAndReleaseParameter(d,
geom,
Expand All @@ -273,13 +270,11 @@ void SceneGenerator::commit()

if (primitiveMode == "indexed") {
std::vector<glm::uvec2> indices;
for (size_t i = 0; i < vertices.size(); i += 2) {
indices.push_back(glm::vec2(
static_cast<uint32_t>(i), static_cast<uint32_t>(i + 1)));
}
for (uint32_t i = 0; i < vertices.size(); i += 2)
indices.emplace_back(i, i + 1);

// shuffle indices vector to create a more useful test case
indices = generator.shuffleVector(indices);
generator.shuffleVector(indices);
indiciCount = indices.size();
anari::setAndReleaseParameter(d,
geom,
Expand Down
7 changes: 7 additions & 0 deletions libs/helide/HelideDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,21 @@ HelideDevice::HelideDevice(ANARIStatusCallback cb, const void *ptr)
: helium::BaseDevice(cb, ptr)
{
m_state = std::make_unique<HelideGlobalState>(this_device());
deviceCommitParameters();
}

HelideDevice::HelideDevice(ANARILibrary l) : helium::BaseDevice(l)
{
m_state = std::make_unique<HelideGlobalState>(this_device());
deviceCommitParameters();
}

HelideDevice::~HelideDevice()
{
auto &state = *deviceState();

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

rtcReleaseDevice(state.embreeDevice);

// NOTE: These object leak warnings are not required to be done by
Expand Down Expand Up @@ -343,6 +348,8 @@ void HelideDevice::initDevice()
if (m_initialized)
return;

reportMessage(ANARI_SEVERITY_DEBUG, "initializing helide device (%p)", this);

auto &state = *deviceState();

state.embreeDevice = rtcNewDevice(nullptr);
Expand Down
5 changes: 2 additions & 3 deletions libs/helide/scene/surface/geometry/Cone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ void Cone::commit()
m_index->addCommitObserver(this);
m_vertexPosition->addCommitObserver(this);

const float *radius = nullptr;
if (m_vertexRadius)
radius = m_vertexRadius->beginAs<float>();
const float *radius =
m_vertexRadius ? m_vertexRadius->beginAs<float>() : nullptr;
m_globalRadius = getParam<float>("radius", 1.f);

const auto numCones =
Expand Down
6 changes: 2 additions & 4 deletions libs/helide/scene/surface/geometry/Curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ void Curve::commit()
m_index->addCommitObserver(this);
m_vertexPosition->addCommitObserver(this);

const float *radius = nullptr;
if (m_vertexRadius)
radius = m_vertexRadius->beginAs<float>();
const float *radius =
m_vertexRadius ? m_vertexRadius->beginAs<float>() : nullptr;
m_globalRadius = getParam<float>("radius", 1.f);

const auto numSegments =
Expand Down Expand Up @@ -74,7 +73,6 @@ void Curve::commit()
sizeof(uint32_t),
numSegments);
std::iota(idx, idx + numSegments, 0);
std::transform(idx, idx + numSegments, idx, [](auto &i) { return i * 2; });
}

rtcCommitGeometry(embreeGeometry());
Expand Down
10 changes: 5 additions & 5 deletions libs/helide/scene/surface/geometry/Cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ void Cylinder::commit()
m_index->addCommitObserver(this);
m_vertexPosition->addCommitObserver(this);

const float *radius = nullptr;
if (m_radius)
radius = m_radius->beginAs<float>();
const float *radius = m_radius ? m_radius->beginAs<float>() : nullptr;
m_globalRadius = getParam<float>("radius", 1.f);

const auto numCylinders =
Expand All @@ -55,8 +53,10 @@ void Cylinder::commit()
const auto *v = m_vertexPosition->beginAs<float3>();
uint32_t cID = 0;
std::for_each(begin, end, [&](const uint2 &idx) {
vr[cID + 0] = float4(v[idx.x], radius ? radius[cID] : m_globalRadius);
vr[cID + 1] = float4(v[idx.y], radius ? radius[cID] : m_globalRadius);
vr[cID + 0] =
float4(v[idx.x], radius ? radius[cID / 2] : m_globalRadius);
vr[cID + 1] =
float4(v[idx.y], radius ? radius[cID / 2] : m_globalRadius);
cID += 2;
});
} else {
Expand Down