commit e778246f47c25ee9ebb2ec6e7e5510786773781d
parent 7cc52bab0c496895fa8761a55bf85c6e1ab71fe3
Author: anon <anon@example.com>
Date: Sat, 17 Oct 2026 19:59:16 +0000
Avoid the temporary vertex copy in GPU transformed draws
Diffstat:
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/runtime/linux_graphics.c b/src/runtime/linux_graphics.c
@@ -1971,14 +1971,15 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin
for (uint32_t i = 0; i < count; ++i) {
memset(vertices[i].specular, 0, sizeof(vertices[i].specular));
if (untransformed) {
- float input_vertex[11], position[4], camera[4], projected[4], normal[3], diffuse[4];
- memcpy(input_vertex, (void *)ADDR(input + i * stride), stride);
- memcpy(position, input_vertex, 12); position[3] = 1;
+ const unsigned char *vertex = (const unsigned char *)ADDR(input + i * stride);
if (gpu_transform) {
- memcpy(vertices[i].position, position, 16);
- if (fvf & 0x10) memcpy(vertices[i].specular, input_vertex + 3, 12);
+ /* GPU inputs can go directly to the draw buffer without a temporary vertex. */
+ memcpy(vertices[i].position, vertex, 12);
+ vertices[i].position[3] = 1;
+ if (fvf & 0x10) memcpy(vertices[i].specular, vertex + 12, 12);
if (fvf & 0x40) {
- uint32_t color = MEM32(input + i * stride + (fvf & 0x10 ? 24 : 12));
+ uint32_t color;
+ memcpy(&color, vertex + (fvf & 0x10 ? 24 : 12), 4);
vertices[i].color[0] = ((color >> 16) & 255) / 255.0f;
vertices[i].color[1] = ((color >> 8) & 255) / 255.0f;
vertices[i].color[2] = (color & 255) / 255.0f;
@@ -1991,10 +1992,13 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin
unsigned coordinate = device->stages[stage].texture_coordinate;
uv[0] = uv[1] = 0;
if (coordinate < texture_count)
- memcpy(uv, (const unsigned char *)input_vertex + stride - texture_count * 8 + coordinate * 8, 8);
+ memcpy(uv, vertex + stride - texture_count * 8 + coordinate * 8, 8);
}
continue;
}
+ float input_vertex[11], position[4], camera[4], projected[4], normal[3], diffuse[4];
+ memcpy(input_vertex, vertex, stride);
+ memcpy(position, input_vertex, 12); position[3] = 1;
transform_vector(position, world_view, camera);
transform_vector(camera, (const float *)device->transforms[2], projected);
float w = projected[3], width = device->target->width, height = device->target->height;