aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 0230403eeac1663394c3818685921d01f5651b96
parent 44d5e433e63565f8f9af2edbc08d698cc0bcf62c
Author: anon <anon@example.com>
Date:   Fri, 16 Oct 2026 06:45:25 +0000

Support triangle fans in native Direct3D draws

Diffstat:
Mdecompiled/runtime/linux_graphics.c | 6++++--
Mdecompiled/tests/devices.c | 9+++++----
Mtools/reconstruction/test_portable_devices.py | 4++--
3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c @@ -1747,7 +1747,7 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin { unsigned texture_count = (fvf >> 8) & 15, format = fvf & ~0x300u; int untransformed = texture_count >= 1 && (format == 0x12 || format == 0x52 || format == 0x42); - if ((primitive != 4 && primitive != 5) || texture_count > 2 || + if ((primitive != 4 && primitive != 5 && primitive != 6) || texture_count > 2 || (format != 0x44 && format != 0xc4 && !untransformed) || flags) { fprintf(stderr, "Unsupported Direct3D draw primitive=%u fvf=%08x flags=%08x cull=%u\n", primitive, fvf, flags, device->cull); exit(3); } @@ -1859,7 +1859,9 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin } if (primitive == 4) for (uint32_t i = 0; i < element_count; ++i) indices[i] = input_indices ? MEM16(input_indices + i * 2) : i; else for (uint32_t i = 0; i < element_count - 2; ++i) { - uint32_t a = i + (i & 1), b = i + !(i & 1), c = i + 2; + /* Fans share vertex zero; strips alternate winding for each triangle. */ + uint32_t a = primitive == 6 ? 0 : i + (i & 1); + uint32_t b = primitive == 6 ? i + 1 : i + !(i & 1), c = i + 2; indices[i * 3] = input_indices ? MEM16(input_indices + a * 2) : a; indices[i * 3 + 1] = input_indices ? MEM16(input_indices + b * 2) : b; indices[i * 3 + 2] = input_indices ? MEM16(input_indices + c * 2) : c; diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c @@ -443,12 +443,13 @@ static void vertex_buffer_draws_match_memory_draws(uint32_t draw, uint32_t devic const unsigned strides[] = {20, 24, 28, 32}; const float positions[][4] = {{4,4,.25f,1}, {28,4,.25f,1}, {4,28,.25f,1}, {28,28,.25f,1}}; const unsigned list[] = {0,1,2,2,1,3}; + const unsigned fan[] = {0,1,3,2}; uint32_t d3d = query(draw, iid), desc = workspace() + 128, input = workspace() + 512; assert(!invoke(device, 20, 3, 27u, 0u)); assert(!invoke(device, 20, 3, 14u, 1u)); assert(!invoke(device, 20, 3, 23u, 4u)); for (unsigned format = 0; format < 4; ++format) - for (unsigned primitive = 4; primitive <= 5; ++primitive) for (unsigned reverse = 0; reverse <= 1; ++reverse) { + for (unsigned primitive = 4; primitive <= 6; ++primitive) for (unsigned reverse = 0; reverse <= 1; ++reverse) { unsigned stride = strides[format], count = primitive == 4 ? 6 : 4; uint32_t description[] = {16, 0x800, formats[format], 8}; memcpy(memory(desc), description, 16); @@ -459,7 +460,7 @@ static void vertex_buffer_draws_match_memory_draws(uint32_t draw, uint32_t devic for (unsigned i = 0; i < count; ++i) { unsigned char *vertex = original + (i + 2) * stride; float position[4]; - memcpy(position, positions[primitive == 4 ? list[i] : i], 16); + memcpy(position, positions[primitive == 4 ? list[i] : primitive == 6 ? fan[i] : i], 16); if (reverse) { float x = position[0]; position[0] = position[1]; position[1] = x; } memcpy(vertex, position, 16); uint32_t color = 0xff5a96d2, specular = 0xffffffff; @@ -516,7 +517,7 @@ static void indexed_vertex_buffers_use_relative_indices(uint32_t draw, uint32_t const uint32_t formats[] = {0x44, 0xc4, 0x144, 0x1c4}; const unsigned strides[] = {20, 24, 28, 32}; const float positions[][4] = {{4,28,.25f,1}, {4,4,.25f,1}, {28,28,.25f,1}, {28,4,.25f,1}}; - const uint16_t lists[][6] = {{1,3,0,0,3,2}, {1,3,0,2}}; + const uint16_t lists[][6] = {{1,3,0,0,3,2}, {1,3,0,2}, {1,3,2,0}}; uint32_t d3d = query(draw, iid), desc = workspace() + 128, elements = workspace() + 512; for (unsigned format = 0; format < 4; ++format) for (unsigned start = 0; start <= 2; start += 2) { uint32_t description[] = {16, 0x800, formats[format], 6}; @@ -534,7 +535,7 @@ static void indexed_vertex_buffers_use_relative_indices(uint32_t draw, uint32_t if (formats[format] & 0x100) memset(memory(vertex + strides[format] - 8), 0, 8); } assert(!invoke(buffer, 4, 1)); - for (unsigned primitive = 4; primitive <= 5; ++primitive) for (unsigned cull = 1; cull <= 3; ++cull) { + for (unsigned primitive = 4; primitive <= 6; ++primitive) for (unsigned cull = 1; cull <= 3; ++cull) { memcpy(memory(elements), lists[primitive - 4], 12); assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f800000u, 0u)); assert(!invoke(device, 20, 3, 22u, cull)); diff --git a/tools/reconstruction/test_portable_devices.py b/tools/reconstruction/test_portable_devices.py @@ -25,8 +25,8 @@ actual = subprocess.check_output(wsl + ["env", "GALLIUM_DRIVER=d3d12", linux_wor assert actual == expected, (expected, actual) windows_pixels = (work / "reference.rgb").read_bytes() linux_pixels = (work / "native.rgb").read_bytes() -assert len(windows_pixels) == len(linux_pixels) == 7993344 +assert len(windows_pixels) == len(linux_pixels) == 8214528 error = max(abs(a - b) for a, b in zip(windows_pixels, linux_pixels)) assert error <= 1, error print("Windows == Linux: " + actual.strip()) -print("All 2664448 pixels agree within one 8-bit channel step; maximum error:", error) +print("All 2738176 pixels agree within one 8-bit channel step; maximum error:", error)