Hi everyone,
I am trying to make a relatively simple application using OptiX 7. The application is casting rays from viewpoint positions (origin) to a mesh’s vertices (direction) - i.e. with this mesh not being an actual GAS. Its vertex positions just serve to calculate the ray directions.
I have a raygen sbt record, which contains the vertex data and the viewpoint positions needed to create the rays.
struct raygen_record_data
{
float3* vertex_buffer;
float3* viewpoint_buffer;
};
template <typename DataType>
struct sbt_record
{
__align__(OPTIX_SBT_RECORD_ALIGNMENT) char header[OPTIX_SBT_RECORD_HEADER_SIZE];
DataType data;
};
using raygen_sbt_record = sbt_record<raygen_record_data>;
Specifically I have a problem with the ray generation program’s sbt record (for the moment). When I use optixGetSbtDataPointer() and access the data saved I get an illegal memory access error.
The host code for uploading data on the device is the following (I have a global tracer_state object that holds the data, i.e. m_impl):
/// m_impl->m_viewpoints is an std::vector<float3>
int num_viewpoints = m_impl->m_viewpoints.size()
int num_verts = m_impl->m_mesh->number_of_vertices()
int total_rays_to_cast = num_viewpoints * num_verts;
float3* verts = (float3*)malloc(total_rays_to_cast * sizeof(float3));
for (int i = 0; i < num_viewpoints; i++)
{
memcpy(verts + i * num_vertices, m_impl->mesh->vertex_ptr(), num_vertices * sizeof(float3));
}
// device buffer (just like CUDABuffer in the SDK examples)
m_impl->d_mesh_vertices.alloc(total_rays_to_cast * sizeof(float3));
m_impl->d_mesh_vertices.upload(verts, tota_rays_to_cast);
m_impl->d_viewpoint_positions.alloc_and_upload(m_impl->m_viewpoints);
/// raygen sbt record device ptr
m_impl->m_raygen_sbt_buffer.alloc(sizeof(raygen_sbt_record));
raygen_sbt_record raygen_rec;
raygen_rec = {};
raygen_rec.data.vertex_buffer = m_impl->d_mesh_vertices.device_ptr();
raygen_rec.data.viewpoint_buffer = m_impl->d_viewpoint_positions.device_ptr();
/// m_impl->m_raygen_program is the ray generation program group
OPTIX_CHECK(optixSbtRecordPackHeader(m_impl->m_raygen_program, &raygen_rec));
m_impl->m_raygen_sbt_buffer.upload(&raygen_rec, 1);
/// m_impl->m_sbt is the SBT associated with context launch
m_impl->m_sbt.raygenRecord = m_impl->m_raygen_sbt_buffer.device_ptr();
free(verts);
The device code does not do anything at the moment, I just printf things to see
/// \brief Raycasting function
extern "C" __global__ void __raygen__rigid_ray_generation()
{
uint3 launch_dims = optixGetLaunchDimensions();
uint3 launch_idx = optixGetLaunchIndex();
unsigned int idx = launch_idx.x;
unsigned int num_viewpoints = rigid_generation_launch_params.num_viewpoints;
unsigned int num_vertices = rigid_generation_launch_params.num_vertices;
if (idx == 0)
{
printf("Launch dimensions: %u x %u x %u\n", launch_dims.x, launch_dims.y, launch_dims.z);
printf("number of viewpoints: %u\n", num_viewpoints);
printf("number of vertices : %u\n", num_vertices);
}
/// access raygen shader's sbt record
const ray::raygen_record_data* raygen_data = (ray::raygen_record_data*)optixGetSbtDataPointer();
if (idx == 0)
{
printf("raygen sbt: %p\n", raygen_data);
printf("%p", raygen_data->vertex_buffer); // here there is an illegal memory access
}
}
}
I really hope these code snippets are enough. (However, if you need more info I can provide more code). Does anyone see anything obvious that I cannot see?
Thank you in advance,
Perukas