   Writing to a dynamic vertex buffer
Hello everyone, I'm currently instancing a set of primitives (cubes, spheres, etc) with modulo arithmetic and I'm having wit the DataStream.WriteRange<> method. I'm using this to write to the InstanceBuffer:DataStream dsInstances = instanceBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);  if (instancesStart + instancesCount < instancesMax)  { dsInstances.Position = instancesStart; dsInstances.WriteRange<VertexPrimitiveInstance>(instances, instancesStart, instancesCount);  }  else  { dsInstances.Position = instancesStart; dsInstances.WriteRange<VertexPrimitiveInstance>(instances, instancesStart, instancesMax - instancesStart); dsInstances.Position = 0; dsInstances.WriteRange<VertexPrimitiveInstance>(instances, 0, instancesCount - (instancesMax - instancesStart));  }  instanceBuffer.Unmap();  I see nothing the first loop around from 0 to InstancesMax.  However, I start seeing my objects once I've written all values to the buffer at least once.  Then I get some very strange flicker and occasionally deformed geometry. If I change the above to write the entire array of VertexPrimitiveInstances to the buffer, I get no flicker.  DataStream dsInstances = instanceBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);  dsInstances.Position = 0;  dsInstances.WriteRange<VertexPrimitiveInstance>(instances);  instanceBuffer.Unmap();   I presume that the second method is far slower than the first (if if worked) and is thus undesirable.  Am I using WriteRange wrong, or am I wrong in thinking I should only set the vertices that are changing (like I did in XNA)?
  Mapping with WRITE_DISCARD invalidates the contents of the buffer, so you'll have to update the entire buffer as you do in the second method.You're effectively given a new buffer, which avoids stalls when the GPU is still using the resource.   ;Mapping with WRITE_DISCARD invalidates the contents of the buffer, so you'll have to update the entire buffer as you do in the second method.You're effectively given a new buffer, which avoids stalls when the GPU is still using the resource. Right, and I think I'm okay with doing.  The vertices that I'm setting in the first method are the only vertices that I'm trying to drawn that frame.;Hah, setting DataStream.Position sets the byte location to write at, I was using the index in the array.  I need to multiply the position by the size of the instance.