Skip to content

Commit

Permalink
fixes for BVH
Browse files Browse the repository at this point in the history
native ptx compiling
fixed async pipeline
  • Loading branch information
gralkapk committed Jul 9, 2024
1 parent e2f0bf6 commit f7972ab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugins/optix_hpg/cmake/configure_optix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function(embed_ptx)
target_link_libraries(${PTX_TARGET} PRIVATE ${EMBED_PTX_PTX_LINK_LIBRARIES})
target_include_directories(${PTX_TARGET} PRIVATE ${EMBED_PTX_PTX_INCLUDE_DIRECTORIES})
set_property(TARGET ${PTX_TARGET} PROPERTY CUDA_PTX_COMPILATION ON)
set_property(TARGET ${PTX_TARGET} PROPERTY CUDA_ARCHITECTURES OFF)
set_property(TARGET ${PTX_TARGET} PROPERTY CUDA_ARCHITECTURES native)
set_property(TARGET ${PTX_TARGET} PROPERTY CXX_STANDARD 17)
target_compile_options(${PTX_TARGET} PRIVATE $<$<CONFIG:Debug>:-lineinfo> -diag-suppress 20012) # warning suppressed due to GLM

Expand Down
2 changes: 1 addition & 1 deletion plugins/optix_hpg/src/optix/AbstractRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AbstractRenderer : public core::view::RendererModule<CallRender3DCUDA, cor

MMOptixSBT sbt_;

OptixPipeline pipeline_;
OptixPipeline pipeline_ = 0;

device::FrameState frame_state_;

Expand Down
6 changes: 6 additions & 0 deletions plugins/optix_hpg/src/optix/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,15 @@ void megamol::optix_hpg::Renderer::on_change_programs(std::tuple<OptixProgramGro

auto const& optix_ctx = get_context();
auto& pipeline = get_pipeline();
cuStreamSynchronize(optix_ctx->GetExecStream());
if (pipeline) {
OPTIX_CHECK_ERROR(optixPipelineDestroy(pipeline));
}

OPTIX_CHECK_ERROR(optixPipelineCreate(optix_ctx->GetOptiXContext(), &optix_ctx->GetPipelineCompileOptions(),
&optix_ctx->GetPipelineLinkOptions(), groups.data(), groups.size(), log.data(), &log_size, &pipeline));

core::utility::log::Log::DefaultLog.WriteInfo("[OptiX]: {}", log);
}


Expand Down
21 changes: 11 additions & 10 deletions plugins/optix_hpg/src/optix/SphereGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ bool megamol::optix_hpg::SphereGeometry::assertData(geocalls::MultiParticleDataC
auto const pl_count = call.GetParticleListCount();

for (auto const& el : particle_data_) {
CUDA_CHECK_ERROR(cuMemFree(el));
CUDA_CHECK_ERROR(cuMemFreeAsync(el, ctx.GetExecStream()));
}
for (auto const& el : color_data_) {
CUDA_CHECK_ERROR(cuMemFree(el));
CUDA_CHECK_ERROR(cuMemFreeAsync(el, ctx.GetExecStream()));
}

particle_data_.resize(pl_count, 0);
Expand Down Expand Up @@ -135,16 +135,17 @@ bool megamol::optix_hpg::SphereGeometry::assertData(geocalls::MultiParticleDataC
color_data[p_idx].a = ca_acc->Get_f(p_idx);
}
// CUDA_CHECK_ERROR(cuMemFree(color_data_));
CUDA_CHECK_ERROR(cuMemAlloc(&color_data_[pl_idx], col_count * sizeof(glm::vec4)));
CUDA_CHECK_ERROR(cuMemAllocAsync(&color_data_[pl_idx], col_count * sizeof(glm::vec4), ctx.GetExecStream()));
CUDA_CHECK_ERROR(cuMemcpyHtoDAsync(
color_data_[pl_idx], color_data.data(), col_count * sizeof(glm::vec4), ctx.GetExecStream()));
}
// CUDA_CHECK_ERROR(cuMemFree(_particle_data));
CUDA_CHECK_ERROR(cuMemAlloc(&particle_data_[pl_idx], p_count * sizeof(device::Particle)));
CUDA_CHECK_ERROR(
cuMemAllocAsync(&particle_data_[pl_idx], p_count * sizeof(device::Particle), ctx.GetExecStream()));
CUDA_CHECK_ERROR(cuMemcpyHtoDAsync(
particle_data_[pl_idx], data.data(), p_count * sizeof(device::Particle), ctx.GetExecStream()));

CUDA_CHECK_ERROR(cuMemAlloc(&bounds_data[pl_idx], p_count * sizeof(box3f)));
CUDA_CHECK_ERROR(cuMemAllocAsync(&bounds_data[pl_idx], p_count * sizeof(box3f), ctx.GetExecStream()));

sphere_module_.ComputeBounds(particle_data_[pl_idx], bounds_data[pl_idx], p_count, ctx.GetExecStream());

Expand Down Expand Up @@ -203,19 +204,19 @@ bool megamol::optix_hpg::SphereGeometry::assertData(geocalls::MultiParticleDataC
ctx.GetOptiXContext(), &accelOptions, build_inputs.data(), build_inputs.size(), &bufferSizes));

CUdeviceptr geo_temp;
CUDA_CHECK_ERROR(cuMemFree(_geo_buffer));
CUDA_CHECK_ERROR(cuMemAlloc(&_geo_buffer, bufferSizes.outputSizeInBytes));
CUDA_CHECK_ERROR(cuMemAlloc(&geo_temp, bufferSizes.tempSizeInBytes));
CUDA_CHECK_ERROR(cuMemFreeAsync(_geo_buffer, ctx.GetExecStream()));
CUDA_CHECK_ERROR(cuMemAllocAsync(&_geo_buffer, bufferSizes.outputSizeInBytes, ctx.GetExecStream()));
CUDA_CHECK_ERROR(cuMemAllocAsync(&geo_temp, bufferSizes.tempSizeInBytes, ctx.GetExecStream()));

OptixTraversableHandle geo_handle = 0;
OPTIX_CHECK_ERROR(optixAccelBuild(ctx.GetOptiXContext(), ctx.GetExecStream(), &accelOptions, build_inputs.data(),
build_inputs.size(), geo_temp, bufferSizes.tempSizeInBytes, _geo_buffer, bufferSizes.outputSizeInBytes,
&_geo_handle, nullptr, 0));

CUDA_CHECK_ERROR(cuMemFree(geo_temp));
CUDA_CHECK_ERROR(cuMemFreeAsync(geo_temp, ctx.GetExecStream()));
// CUDA_CHECK_ERROR(cuMemFree(bounds_data));
for (auto const& el : bounds_data) {
CUDA_CHECK_ERROR(cuMemFree(el));
CUDA_CHECK_ERROR(cuMemFreeAsync(el, ctx.GetExecStream()));
}

//////////////////////////////////////
Expand Down

0 comments on commit f7972ab

Please sign in to comment.