commit c18104bde2e96178c0b768e70b8d74ac14d82c64
parent e3c7be8cdc1b66d9eb1d36eb70dbb175c0186ece
Author: anon <anon@example.com>
Date: Thu, 15 Oct 2026 13:58:45 +0000
Retain native ambient and vertex processing states
Diffstat:
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c
@@ -53,9 +53,9 @@ static struct device_object {
uint32_t min_filter, mag_filter, mip_filter, address, address_u, address_v, color_op, alpha_op;
uint32_t sampler_u, sampler_v;
uint32_t alpha_arg2;
- uint32_t fog_enabled, fog_color, fog_start, fog_end, fog_density;
+ uint32_t fog_enabled, fog_color, fog_start, fog_end, fog_density, fog_vertex_mode;
uint32_t blend, source_blend, destination_blend, depth_write, depth_function, clipping, lighting;
- uint32_t material[17], viewport[6], transforms[3][16];
+ uint32_t ambient, normalize_normals, material[17], viewport[6], transforms[3][16];
int scene;
struct draw_object *owner;
struct surface_object *target;
@@ -1543,7 +1543,10 @@ static uint32_t device_state(struct device_object *device, uint32_t state)
case 132: case 133: case 134: case 135: return 0; /* Coordinate wrapping. */
case 141: case 142: case 145: return 1;
case 136: return device->clipping;
- case 138: case 139: case 140: case 143: case 144:
+ case 139: return device->ambient;
+ case 140: return device->fog_vertex_mode;
+ case 143: return device->normalize_normals;
+ case 138: case 144:
case 147: case 148: case 151: case 152: return 0;
case 146: return 2; /* Specular material uses vertex color 2. */
case 7: return 1; /* Z enable. */
@@ -1634,6 +1637,9 @@ static void device_set_state(void)
else if (state == 23 && value >= 1 && value <= 8) device->depth_function = value;
else if (state == 136 && value <= 1) device->clipping = value;
else if (state == 137 && value <= 1) device->lighting = value;
+ else if (state == 139) device->ambient = value;
+ else if (state == 140 && (value == 0 || value == 3)) device->fog_vertex_mode = value;
+ else if (state == 143 && value <= 1) device->normalize_normals = value;
else if (state == 19 && (value == 1 || value == 2 || value == 5 || value == 6)) device->source_blend = value;
else if (state == 20 && (value == 1 || value == 2 || value == 5 || value == 6)) device->destination_blend = value;
else if (value != device_state(device, state)) {
diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c
@@ -318,7 +318,9 @@ static void transformed_vertex_fog_blends_rgb(uint32_t device, uint32_t target,
assert(!invoke(device, 21, 3, 36u, workspace()) && *memory(workspace()) == 0x3e4ccccd);
assert(!invoke(device, 21, 3, 37u, workspace()) && *memory(workspace()) == 0x3f4ccccd);
assert(!invoke(device, 21, 3, 38u, workspace()) && *memory(workspace()) == 0x3f000000);
- for (unsigned sample = 0; sample < 7; ++sample) {
+ for (unsigned mode = 0; mode <= 3; mode += 3) for (unsigned sample = 0; sample < 7; ++sample) {
+ assert(!invoke(device, 20, 3, 140u, mode));
+ assert(!invoke(device, 21, 3, 140u, workspace()) && *memory(workspace()) == mode);
struct { float xyzw[4]; uint32_t diffuse, specular; } vertices[] = {
{{4, 4, .25f, 1}, 0xff6080a0, (factors[sample][0] << 24) | 0xabcdef},
{{28, 4, .25f, 1}, 0xff6080a0, (factors[sample][1] << 24) | 0xabcdef},
@@ -351,6 +353,7 @@ static void transformed_vertex_fog_blends_rgb(uint32_t device, uint32_t target,
assert(fwrite(rgb, 1, sizeof(rgb), file) == sizeof(rgb));
}
assert(!invoke(device, 20, 3, 28u, 0u));
+ assert(!invoke(device, 20, 3, 140u, 0u));
}
static void vertex_buffer_draws_match_memory_draws(uint32_t draw, uint32_t device, uint32_t target, FILE *file)
@@ -564,6 +567,7 @@ static void transformed_render_states_preserve_rasterization(uint32_t device, ui
{-16, -16, 0, 1, 0xff00ff00}, {48, -16, 0, 1, 0xff00ff00}, {-16, 48, 0, 1, 0xff00ff00}
};
const float depths[] = {-.25f, .5f, 1.25f};
+ const uint32_t ambient[] = {0xff001428, 0x12345678, 0xffffffff};
assert(!invoke(device, 20, 3, 23u, 8u));
for (unsigned lighting = 0; lighting <= 1; ++lighting)
for (unsigned clipping = 0; clipping <= 1; ++clipping) for (unsigned z = 0; z < 3; ++z) {
@@ -571,6 +575,10 @@ static void transformed_render_states_preserve_rasterization(uint32_t device, ui
assert(!invoke(device, 21, 3, 136u, workspace()) && *memory(workspace()) == clipping);
assert(!invoke(device, 20, 3, 137u, lighting));
assert(!invoke(device, 21, 3, 137u, workspace()) && *memory(workspace()) == lighting);
+ assert(!invoke(device, 20, 3, 139u, ambient[z]));
+ assert(!invoke(device, 21, 3, 139u, workspace()) && *memory(workspace()) == ambient[z]);
+ assert(!invoke(device, 20, 3, 143u, lighting));
+ assert(!invoke(device, 21, 3, 143u, workspace()) && *memory(workspace()) == lighting);
assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f800000u, 0u));
for (unsigned i = 0; i < 3; ++i) vertices[i].z = depths[z];
memcpy(memory(input), vertices, sizeof(vertices));
@@ -587,6 +595,8 @@ static void transformed_render_states_preserve_rasterization(uint32_t device, ui
assert(!invoke(target, 32, 2, 0u));
}
assert(!invoke(device, 20, 3, 136u, 1u));
+ assert(!invoke(device, 20, 3, 139u, 0u));
+ assert(!invoke(device, 20, 3, 143u, 0u));
assert(!invoke(device, 20, 3, 23u, 4u));
}
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) == 1449984
+assert len(windows_pixels) == len(linux_pixels) == 1471488
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 483328 pixels agree within one 8-bit channel step; maximum error:", error)
+print("All 490496 pixels agree within one 8-bit channel step; maximum error:", error)