Hey David!
Thank you for your answer. I have never used Nsight VSE with OptiX, there isnât a tutorial to get started with OptiX debugging? Do you have a recommendation on how a total newbie can get into Nsight? Since I only get the error message " 0x000002a5624ca2a0 "CUDA error on synchronize with error âan illegal memory access was encounteredâ " I guess Nsight would be the way to figure out were it exactly happens.
I guess you canât see from the error code if this is because I messed up in pipeline/sbt creation or if itâs related to my device programs?
I went several times carefully through the sbt und pipeline creation and couldnât find any obvious errors.
I still donât fully understand the setup of the sbt, but I think I modified the example correctly.
void Scene::createPTXModule()
{
OptixModuleCompileOptions module_compile_options = {};
module_compile_options.optLevel = OPTIX_COMPILE_OPTIMIZATION_DEFAULT;
module_compile_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_LINEINFO;
m_pipeline_compile_options = {};
m_pipeline_compile_options.usesMotionBlur = false;
m_pipeline_compile_options.traversableGraphFlags = OPTIX_TRAVERSABLE_GRAPH_FLAG_ALLOW_SINGLE_LEVEL_INSTANCING;
m_pipeline_compile_options.numPayloadValues = whitted::NUM_PAYLOAD_VALUES;
m_pipeline_compile_options.numAttributeValues = 2; // TODO
m_pipeline_compile_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE; // should be OPTIX_EXCEPTION_FLAG_STACK_OVERFLOW;
m_pipeline_compile_options.pipelineLaunchParamsVariableName = "params";
const std::string ptx = getPtxString(nullptr, "whitted.cu");
m_ptx_module = {};
char log[2048];
size_t sizeof_log = sizeof(log);
OPTIX_CHECK_LOG(optixModuleCreateFromPTX(
m_context,
&module_compile_options,
&m_pipeline_compile_options,
ptx.c_str(),
ptx.size(),
log,
&sizeof_log,
&m_ptx_module
));
}
void Scene::createProgramGroups()
{
OptixProgramGroupOptions program_group_options = {};
char log[2048];
size_t sizeof_log = sizeof(log);
//
// Ray generation
//
{
OptixProgramGroupDesc raygen_prog_group_desc = {};
raygen_prog_group_desc.kind = OPTIX_PROGRAM_GROUP_KIND_RAYGEN;
raygen_prog_group_desc.raygen.module = m_ptx_module;
raygen_prog_group_desc.raygen.entryFunctionName = "__raygen__therm";
OPTIX_CHECK_LOG(optixProgramGroupCreate(
m_context,
&raygen_prog_group_desc,
1, // num program groups
&program_group_options,
log,
&sizeof_log,
&m_raygen_prog_group
)
);
}
//
// Miss
//
{
OptixProgramGroupDesc miss_prog_group_desc = {};
miss_prog_group_desc.kind = OPTIX_PROGRAM_GROUP_KIND_MISS;
miss_prog_group_desc.miss.module = m_ptx_module;
miss_prog_group_desc.miss.entryFunctionName = "__miss__therm";
sizeof_log = sizeof(log);
OPTIX_CHECK_LOG(optixProgramGroupCreate(
m_context,
&miss_prog_group_desc,
1, // num program groups
&program_group_options,
log,
&sizeof_log,
&m_therm_miss_group
)
);
}
//
// Hit group
//
{
OptixProgramGroupDesc hit_prog_group_desc = {};
hit_prog_group_desc.kind = OPTIX_PROGRAM_GROUP_KIND_HITGROUP;
hit_prog_group_desc.hitgroup.moduleCH = m_ptx_module;
hit_prog_group_desc.hitgroup.entryFunctionNameCH = "__closesthit__therm";
sizeof_log = sizeof(log);
OPTIX_CHECK_LOG(optixProgramGroupCreate(
m_context,
&hit_prog_group_desc,
1, // num program groups
&program_group_options,
log,
&sizeof_log,
&m_therm_hit_group
)
);
}
}
void Scene::createPipeline()
{
OptixProgramGroup program_groups[] =
{
m_raygen_prog_group,
m_therm_miss_group,
m_therm_hit_group
};
OptixPipelineLinkOptions pipeline_link_options = {};
pipeline_link_options.maxTraceDepth = 3;
pipeline_link_options.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_FULL;
pipeline_link_options.overrideUsesMotionBlur = false;
char log[2048];
size_t sizeof_log = sizeof( log );
OPTIX_CHECK_LOG( optixPipelineCreate(
m_context,
&m_pipeline_compile_options,
&pipeline_link_options,
program_groups,
sizeof( program_groups ) / sizeof( program_groups[0] ),
log,
&sizeof_log,
&m_pipeline
) );
}
void Scene::createSBT()
{
{
const size_t raygen_record_size = sizeof( EmptyRecord );
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>( &m_sbt.raygenRecord ), raygen_record_size ) );
EmptyRecord rg_sbt;
OPTIX_CHECK( optixSbtRecordPackHeader( m_raygen_prog_group, &rg_sbt ) );
CUDA_CHECK( cudaMemcpy(
reinterpret_cast<void*>( m_sbt.raygenRecord ),
&rg_sbt,
raygen_record_size,
cudaMemcpyHostToDevice
) );
}
{
const size_t miss_record_size = sizeof( EmptyRecord );
CUDA_CHECK( cudaMalloc(
reinterpret_cast<void**>( &m_sbt.missRecordBase ),
miss_record_size*whitted::RAY_TYPE_COUNT
) );
EmptyRecord ms_sbt[ whitted::RAY_TYPE_COUNT ];
OPTIX_CHECK( optixSbtRecordPackHeader( m_therm_miss_group, &ms_sbt[0] ) );
CUDA_CHECK( cudaMemcpy(
reinterpret_cast<void*>( m_sbt.missRecordBase ),
ms_sbt,
miss_record_size*whitted::RAY_TYPE_COUNT,
cudaMemcpyHostToDevice
) );
m_sbt.missRecordStrideInBytes = static_cast<uint32_t>( miss_record_size );
m_sbt.missRecordCount = whitted::RAY_TYPE_COUNT;
}
{
std::vector<HitGroupRecord> hitgroup_records;
for( const auto mesh : m_meshes )
{
for( size_t i = 0; i < mesh->material_idx.size(); ++i )
{
HitGroupRecord rec = {};
OPTIX_CHECK( optixSbtRecordPackHeader( m_therm_hit_group, &rec ) );
rec.data.geometry_data.type = GeometryData::TRIANGLE_MESH;
rec.data.geometry_data.triangle_mesh.positions = mesh->positions[i];
rec.data.geometry_data.triangle_mesh.normals = mesh->normals[i];
rec.data.geometry_data.triangle_mesh.texcoords = mesh->texcoords[i];
rec.data.geometry_data.triangle_mesh.indices = mesh->indices[i];
const int32_t mat_idx = mesh->material_idx[i];
if( mat_idx >= 0 )
rec.data.material_data.pbr = m_materials[ mat_idx ];
else
rec.data.material_data.pbr = MaterialData::Pbr();
hitgroup_records.push_back( rec );
}
}
const size_t hitgroup_record_size = sizeof( HitGroupRecord );
CUDA_CHECK( cudaMalloc(
reinterpret_cast<void**>( &m_sbt.hitgroupRecordBase ),
hitgroup_record_size*hitgroup_records.size()
) );
CUDA_CHECK( cudaMemcpy(
reinterpret_cast<void*>( m_sbt.hitgroupRecordBase ),
hitgroup_records.data(),
hitgroup_record_size*hitgroup_records.size(),
cudaMemcpyHostToDevice
) );
m_sbt.hitgroupRecordStrideInBytes = static_cast<unsigned int>( hitgroup_record_size );
m_sbt.hitgroupRecordCount = static_cast<unsigned int>( hitgroup_records.size() );
}
}
Thanks again for your help and patience.
I hope you can point me in the right direction.