The tricky thing about creating an execute buffer is figuring out how much memory to allocate for it. There are two basic strategies for determining the correct size:
·Add the sizes of the vertices, opcodes, and data you will be putting into the buffer.
·Allocate a buffer of an arbitrary size and fill it from both ends, putting the vertices at the beginning and the opcodes at the end. When the buffer is nearly full, execute it and allocate another.
The hardware determines the size of the execute buffer. You can retrieve this size by calling the IDirect3DDevice2::GetCaps method and examining the dwMaxBufferSize member of the D3DDEVICEDESC structure. Typically, 64 KB is a good size for execute buffers when you are using a software driver, because this size makes the best use of the secondary cache. When your application can take advantage of hardware acceleration, however, it should use smaller execute buffers to take advantage of the primary cache.
After filling in D3DEXECUTEBUFFERDESC structure describing your execute buffer, you can call the IDirect3DDevice::CreateExecuteBuffer to create it.
For an example of calculating the size of the execute buffer and creating it, see Creating the Scene, in the Direct3D Execute-Buffer Tutorial.