Hi, I just downloaded the latest version of unity 5.6 beta because I wanted to try out the DrawMeshInstancedIndirect method that wasn’t available in 5.5. Since this version JUST came out I don’t know if it’s a bug that wasn’t here in previous 5.6 versions, or I’m doing something wrong.
I’m instancing large amounts of grass, and after a few seconds of playback the fps start to drop down until an out of video memory error pops up and I have to restart my pc.
Because of that I thought that I was forgetting to release some buffer, but it wasn’t the case. Also in the profiler (when it starts to freeze) I noticed in the CPU a few spikes in the “others” category…and I don’t know what “others” is. I will attach some screenshots from the profiler, as well as the code that I’m using to initialize everything. The code sample is using DrawInstanced in the update loop, but also tried with a command buffer and the result is the same. And btw using Graphics.DrawMeshInstancedIndirect causes the camera.renderskybox to take like 6ms to render it (4.5 in this screenshot), this doesn’t happen when I use a command buffer.
public PointGenerator point_generator;
public int matrix_instance_count = 1023;
ComputeBuffer grass_render_args;
ComputeBuffer grass_positions_buffer;
public Material grass_instancing_mat;
public Mesh grass_mesh_LOD0;
void Start()
{
SetupGrassBuffers();
//SetupCommandBuffer();
}
void Update()
{
Graphics.DrawMeshInstancedIndirect(grass_mesh_LOD0, 0, grass_instancing_mat, new Bounds(Vector3.zero,new Vector3(100,10,100)), grass_render_args);
}
void SetupGrassBuffers()
{
List<Vector3> positions = new List<Vector3>();
int grass_instance_count = 625;
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 2f,5f));
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 5f,10f));
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 10f,15f));
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 10f,15f));
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 10f,15f));
for(int i=5; i< 15; i++)
{
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 2f,5f));
}
for(int i=15; i< 20; i++)
{
positions.AddRange(point_generator.GenerateRandomPoints(grass_instance_count, 15f,20f));
}
//######################################
//######################################
grass_positions_buffer = new ComputeBuffer(positions.Count,sizeof(float)*3);
grass_positions_buffer.SetData(positions.ToArray());
grass_instancing_mat.SetBuffer("positions_buffer", grass_positions_buffer);
//######################################
//######################################
grass_render_args = new ComputeBuffer(1,5 * sizeof(int),ComputeBufferType.IndirectArguments);
int mesh_index_count = grass_mesh_LOD0.GetIndices(0).Length;
int instance_count = positions.Count;
int start_index_location = 0;
int base_vertex_location = 0;
int start_instance_location = 0;
grass_render_args.SetData(new int[]{mesh_index_count, instance_count, start_index_location, base_vertex_location, start_instance_location});
}
void OnDisable()
{
grass_positions_buffer.Release();
grass_render_args.Release();
}

