"D3D11 buffer map failed"

Hi, when I interop Optix with D3D11, I come cross a error: D3D11 buffer map failed.-2147024809, [12255404])" …
my work is as follows:
(1) I define a ID3D11buffer * g_pGlobalVBuffer and create it.

D3D11_BUFFER_DESC bufDesc;
	bufDesc.Usage = D3D11_USAGE_DEFAULT;
	bufDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER ;//|*/ D3D11_BIND_SHADER_RESOURCE;
	bufDesc.ByteWidth = data_length;
	bufDesc.CPUAccessFlags = 0;
	bufDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
	bufDesc.StructureByteStride = 3 * sizeof(float) ;

	D3D11_SUBRESOURCE_DATA subData;
	subData.pSysMem = somebuffer;//&(g_pGLMmodel->vertices[3]);
	subData.SysMemPitch = 0;
	subData.SysMemSlicePitch = 0;

	g_piDevice->CreateBuffer(&bufDesc, &subData, &g_pGlobalVBuffer);

Up to now, the g_pGlobalVBuffer has been create successfully.
(2) Create a Optix::Buffer m_vbuffer via above ID3D11Buffer *;

m_vbuffer = m_context->createBufferFromD3D11Resource( RT_BUFFER_INPUT, g_pGlobalVBuffer);
   m_vbuffer->setFormat(RT_FORMAT_FLOAT3);
   m_vbuffer->setSize(num_vertices);

Up to this poiont, the m_vbuffer is created successfully also.
(3) Binding the m_vbuffer to a device variable in .cu

//mesh is Geometry object, 
//rtBuffer<float3> vertex_buffer;  has been defined in .cu file
mesh[ "vertex_buffer" ]->set( m_vbuffer ); 

(4) when launching, I catch a exception:

try
	{
		m_context->launch( rtpass,
			static_cast<unsigned int>(buffer_width),
			static_cast<unsigned int>(buffer_height) );
	}
	catch( Exception& e ){
		// sutilReportError( e.getErrorString().c_str() );
		exit(2);
	}

exception:
m_message=“Invalid value (Details: Function “_rtContextLaunch2D” caught exception: D3D11 buffer map failed.-2147024809, [12255404])” …

Any one can tell what’s the reason for the exception?

In the programming guide of OptiX 3.5, there is still the note, that D3D11_CPU_ACCESS_READ is needed. However, in 2012 I was able to map it without. But any way, I would try to do it the official way first.

I’m also not sure, if you can write into the vertex buffer. Maybe it could work for you to first write into a staging buffer and then copy it with d3d into the correct position.

here is the old thread with more info how i did it:
https://devtalk.nvidia.com/default/topic/523462/direct3d-10-interop

Hi:
I find the real source of the exception is the following codes:

Acceleration acceleration = m_context->createAcceleration("Sbvh","Bvh");
  
  acceleration->setProperty( "vertex_buffer_name", "vertex_buffer");

Does Optix have the restriction that rtBuffer created from d3d can not be assigned to “vertex_buffer_name” of a acceleration?

The programming guide says that “Direct3D buffer objects can be read and written by OptiX program objects” (Section 6.2, first paragraph).

An acceleration structure is not a programming object, so i would guess that it’s not possible.

however it could work to have a separate kernel just to copy the buffer.

Setting Acceleration property “vertex_buffer_name” is just an optimization for triangles. The Sbvh build could optimize something quicker then, but it’s actually not required. The OptiX Programming Guide table 3.5.3. Properties says this:
“vertex_buffer_name” | Sbvh TriangleKdTree | The name of the buffer variable holding triangle vertex data. Each vertex consists of 3 floats. Mandatory for TriangleKdTree, optional for Sbvh (but recommended if the geometry consists of triangles). The default is “vertex_buffer”.

Otherwise it’ll use the standard bounding box program you provided, like the other BVH based acceleration structure builders. If the more optimized Sbvh build routine is trying to read the buffer by mapping it on the host and you didn’t grant CPU read access on the D3D side, that could be the culprit.
Or just try without assigning that Acceleration property.

(I always start with the Bvh builder when developing something and when time has come for optimizations I try other builders.)