I get the following error on launch:
Invalid context (Details: Function "_rtContextLaunch1D" caught exception: Cannot map CUDA interop buffers, [14614601])
- using GTX 980 + GTX 670 (not used), Win7 64bit, Visual Studio 12 64bit, cuda 7,
- when setting the vertex/index buffer names for the Sbvh builder. Without setting these, everything seems to work fine.
- using this code:
void Optix::init(
int const idevice
, ::glm::vec3 const* const vertexbuffer
, int const numVertices
, ::glm::ivec3 const* const indexbuffer
, int const numIndices
, gl::Texture const& positions
)
{
try {
using detail::ptxpath;
using namespace ::gpu;
m_context = optix::Context::create();
this->idevice = idevice;
// set device
m_context->setDevices(&idevice, &idevice+1);
cutsizes = m_context->createBufferForCUDA(RT_BUFFER_INPUT, RT_FORMAT_INT);
m_context["cutsizes"]->setBuffer(cutsizes);
data = m_context->createBufferForCUDA(RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_UNSIGNED_INT);
m_context["data"]->setBuffer(data);
//initialized later
m_context->setRayTypeCount(1);
m_context->setEntryPointCount(1);
m_context->setRayGenerationProgram(0, m_context->createProgramFromPTXFile(detail::ptxpath("shadow_request"), "shadow_request"));
m_context->setExceptionProgram(0, m_context->createProgramFromPTXFile(detail::ptxpath("shadow_request"), "exception"));
m_context->setMissProgram(0, m_context->createProgramFromPTXFile(detail::ptxpath("shadow_request"), "miss"));
optix::Material opaque = m_context->createMaterial();
opaque->setAnyHitProgram(0, m_context->createProgramFromPTXFile(detail::ptxpath("shadow_request"), "any_hit"));
auto vb = m_context->createBufferForCUDA(RT_BUFFER_INPUT);
{
vb->setFormat(RT_FORMAT_FLOAT3);
auto const ptr = vertexbuffer;
MLIB_ERROR_ASSERT(ptr);
auto const p = reinterpret_cast<CUdeviceptr>(ptr);
vb->setDevicePointer(idevice, p);
vb->setSize(numVertices);
vb->validate();
}
auto index_buffer = m_context->createBufferForCUDA(RT_BUFFER_INPUT);
{
index_buffer->setFormat(RT_FORMAT_INT3);
auto const ptr = indexbuffer;
MLIB_ERROR_ASSERT(ptr);
auto const p = reinterpret_cast<CUdeviceptr>(ptr);
index_buffer->setDevicePointer(idevice, p);
index_buffer->setSize(numIndices);
index_buffer->validate();
}
//mesh
auto geo = m_context->createGeometry();
geo->setPrimitiveCount(numIndices);
geo["vb"]->setBuffer(vb);
geo["ib"]->setBuffer(index_buffer);
geo->setIntersectionProgram(
m_context->createProgramFromPTXFile(ptxpath("triangle_mesh_small"), "mesh_intersect")
);
geo->setBoundingBoxProgram(
m_context->createProgramFromPTXFile(ptxpath("triangle_mesh_small"), "mesh_bounds")
);
auto const beg = &opaque;
auto const end = &opaque + 1;
auto instance = m_context->createGeometryInstance(geo, beg, end);
instance->setMaterialCount(end - beg);
for (auto i = 0; i < end - beg; ++i)
{
instance->setMaterial(i, beg[i]);
}
auto geogroup = m_context->createGeometryGroup();
geogroup->setChildCount(1);
geogroup->setChild(0, instance);
auto accel = m_context->createAcceleration("Sbvh", "Bvh");
//auto accel = m_context->createAcceleration("NoAccel", "NoAccel");
// if enabled, fails, otherwise just works
accel->setProperty("vertex_buffer_name", "vb");
accel->setProperty("index_buffer_name", "ib");
geogroup->setAcceleration(accel);
accel->markDirty();
accel->validate();
m_context["shadow_casters"]->set(geogroup);
}
catch (optix::Exception& e)
{
MLIB_ERROR_SIGNAL(::mlib::error::Exception(e.getErrorString()));
}
}
Also, the exact same vertex/index buffers just work when using optix prime:
void init(
::cuda::Context const* const context
, int const numTriangles
, ::glm::ivec3 const* const indices
, int const numVertices
, ::glm::vec3 const* const vertices
)
{
try {
using namespace ::gpu;
using namespace optix::prime;
using namespace ::glm;
rtContext = optix::prime::Context::create(RTP_CONTEXT_TYPE_CUDA);
auto const device = unsigned(context->deviceId);
rtContext->setCudaDeviceNumbers(1, &device);
auto inds = rtContext->createBufferDesc(
RTP_BUFFER_FORMAT_INDICES_INT3
, RTP_BUFFER_TYPE_CUDA_LINEAR
, const_cast<ivec3*>(indices)
);
inds->setRange(0, numTriangles);
auto verts = rtContext->createBufferDesc(
RTP_BUFFER_FORMAT_VERTEX_FLOAT3
, RTP_BUFFER_TYPE_CUDA_LINEAR
, const_cast<vec3*>(vertices)
);
verts->setRange(0, numVertices);
model = rtContext->createModel();
model->setTriangles(inds, verts);
model->update(RTP_MODEL_HINT_NONE);
}
catch (optix::prime::Exception& e)
{
MLIB_ERROR_SIGNAL(::mlib::error::Exception(e.getErrorString()));
}
}
The buffers are pure CUDA buffers.
Any idea what might be going wrong here?