Am 24.07.2012 20:38, schrieb David:
I am writing a game engine, well I was using a float[] array to store my
vertices, this worked well, but I have to send more and more uv
coordinates (and other information) which needn't be stored as `float`'s
so I moved from a float-Array to a Vertex Array:
https://github.com/Dav1dde/BraLa/blob/master/brala/dine/builder/tessellator.d#L30


align(1) struct Vertex {
     float x;
     float y;
     float z;
     float nx;
     float ny;
     float nz;
     float u_terrain;
     float v_terrain;
     float u_biome;
     float v_biome;
}

Everything is still a float, so it's easier. Nothing wrong with that or?
Well this change decreases my performance by 1000%. My frame rate drops
from ~12ms per frame to ~120ms per frame. I tried to find the bottleneck
with `perf` but no results (the time is not spent in the game/engine).

The commit:
https://github.com/Dav1dde/BraLa/commit/02a37a0e46f195f5a46404747d659d26490e6c32


I hope you can see anything wrong. I have no idea!

Check the dissassembly view of this line:
buffer[elements++] = Vertex(x, y, z, nx, ny, nz, u, v, u_biome, v_biome);

If you are using an old version of dmd it will allocate an block of memory which has the size of Vertex, then it will fill the date into that block of memory, and then memcpy it to your buffer array.

You could try working around this by doing:

buffer[elements++].__ctor(x, y, z, nx, ny, nz, u, v, u_biome, v_biome);

Kind Regards
Benjamin Thaut

Reply via email to