Intel® Embree Ray Tracing Kernels
Discussion forum on the open source ray tracing kernels for fast photo-realistic rendering on Intel® CPU(s)

Embree Reference Counting

DBS4261
Novice
221 Views

HI folks, the Embree documentation is rather unclear about how the reference counting is used as well as what increments the count. There are two situations shown in the following code block. First, when I attach a buffer to a geometry, does the buffers reference count get incremented? My impression based on the API is that I create the buffer, then attach it, then clean up my end, and the buffer will be deallocated once the geometry reference count falls to zero. The same applies to creating a geometry, attaching it to a scene, and then cleaning up my reference. Does the scene keep the geometry and the buffers attached to the geometry alive?

unsigned int CreateGeometry(RTCScene scene, std::span<unsigned int> indices, std::span<float> vertices) {
    auto device = rtcGetSceneDevice(scene);
    auto geom = rtcNewGeometry(device, RTC_GEOMETRY_TYPE_TRIANGLE);
    
    auto index_buffer = rtcNewSharedBuffer(device, indices.data(), indices.size_bytes());
    rtcSetGeometryBuffer(geom, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3,
        index_buffer, 0, sizeof(unsigned int) * 3, indices.size() / 3);
    rtcReleaseBuffer(index_buffer);
    
    auto vertex_buffer = rtcNewSharedBuffer(device, vertices.data(), vertices.size_bytes());
    rtcSetGeometryBuffer(geom, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3,
        vertex_buffer, 0, sizeof(float) * 3, vertices.size() / 3);
    rtcReleaseBuffer(vertex_buffer);

    unsigned int id = rtcAttachGeometry(scene, geom);
    rtcReleaseGeometry(geom);
    return id;
}

 Next up, after calling this `CreateGeometry` function, I call `rtcGetGeometry(scene, id)`. Does the geometry handle returned need to be released when I am done with it?

0 Kudos
0 Replies
Reply