I want to clone a mesh in DX11, then modify the vertex structure like adding some information for each vertex and render. But I have no idea how to do it in DX11? in DX9, we can use clone function but in DX11, how to do it?
I assume that when you say "DX9", you're talking about the ID3DXMesh class? I'm not sure what you're using now for managing your meshes, but cloning a mesh is pretty simple:
Make sure that you have the original mesh data available in CPU memory. If you already loaded it into a vertex buffer, you can copy it to a staging buffer and Map that to get a pointer to the data.
Allocate enough CPU memory to fit however many vertices you have, using the new vertex layout
For each element in the new vertex layout, check if that element exists in the old layout. If it exists, store the byte offset of the element in the old layout. If it doesn't exist, store some value indicating that it doesn't exist (for instance, you could use -1). You can store this all in an array or std::vector containing one integer per new vertex element.
Loop over all vertices. For each vertex, loop over your table of offsets that you built in the previous step. If the the element exists in the old layout, copy the data from the old vertex data to the new vertex data using the offset that you stored. When you're done with all elements, advance your pointers to the vertex data by the strides so that they point to the start of the next vertex
I can iterate through all vertices, but how can I know which vertex belongs to the same triangle in DX11? because in DX9 we can loop over all triangles, then use the index buffer and vertex buffer to modify it such as add an incremental primitive's ID into 3l vertices which belongs to the same triangle in a mesh.