commit 02b1790402add209e50fc36c2ac19a7cfaf3585a
parent 0230403eeac1663394c3818685921d01f5651b96
Author: anon <anon@example.com>
Date: Fri, 16 Oct 2026 06:48:14 +0000
Implement texture argument alpha replication
Diffstat:
4 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/decompiled/runtime/gl_renderer.c b/decompiled/runtime/gl_renderer.c
@@ -73,7 +73,9 @@ int gl_renderer_initialize(void)
"uniform bool textured[2], has_alpha[2]; uniform int color_op[2], alpha_op[2], color_arg2[2], alpha_arg2[2];\n"
"uniform int color_arg1[2], alpha_arg1[2];\n"
"uniform vec4 texture_factor;\n"
- "vec4 argument(int a, vec4 t) { return a==0 ? color : a==1 ? pixel : a==2 ? t : texture_factor; }\n"
+ "vec4 argument(int a, vec4 t) { int source=a&15;"
+ "vec4 value=source==0 ? color : source==1 ? pixel : source==2 ? t : texture_factor;"
+ "return (a&32)!=0 ? vec4(value.a) : value; }\n"
"void combine(int s, vec4 t) { if(!has_alpha[s]) t.a=1.0;"
"vec3 c1=argument(color_arg1[s],t).rgb, c2=argument(color_arg2[s],t).rgb;"
"float a1=argument(alpha_arg1[s],t).a, a2=argument(alpha_arg2[s],t).a;"
diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c
@@ -1868,7 +1868,7 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin
}
for (unsigned i = 0; i < 2; ++i) {
struct texture_stage *stage = &device->stages[i];
- int needs_texture = stage->color_arg1 == 2 || (stage->color_op != 2 && stage->color_arg2 == 2);
+ int needs_texture = (stage->color_arg1 & 15) == 2 || (stage->color_op != 2 && (stage->color_arg2 & 15) == 2);
if (stage->color_op != 1 && (stage->texture || !needs_texture)) {
struct gl_texture_state state = {stage->texture ? stage->texture->target : NULL,
stage->min_filter == 2, stage->mag_filter == 2,
@@ -2007,10 +2007,10 @@ static void device_set_texture_state(void)
else if (state == 1 && (value == 1 || value == 2 || value == 4 || value == 7 || value == 20)) device->stages[stage].color_op = value;
else if (state == 4 && (value >= 1 && value <= 4)) device->stages[stage].alpha_op = value;
/* CURRENT selects the preceding stage; DIFFUSE selects vertex color. */
- else if (state == 2 && value <= 3) device->stages[stage].color_arg1 = value;
- else if (state == 5 && value <= 3) device->stages[stage].alpha_arg1 = value;
- else if (state == 3 && value <= 3) device->stages[stage].color_arg2 = value;
- else if (state == 6 && value <= 3) device->stages[stage].alpha_arg2 = value;
+ else if (state == 2 && (value & ~0x20u) <= 3) device->stages[stage].color_arg1 = value;
+ else if (state == 5 && (value & ~0x20u) <= 3) device->stages[stage].alpha_arg1 = value;
+ else if (state == 3 && (value & ~0x20u) <= 3) device->stages[stage].color_arg2 = value;
+ else if (state == 6 && (value & ~0x20u) <= 3) device->stages[stage].alpha_arg2 = value;
else if (value != texture_stage_state(&device->stages[stage], state)) {
fprintf(stderr, "Unsupported texture-stage state %u value=%08x\n", state, value); exit(3);
}
diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c
@@ -1100,6 +1100,7 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32
assert(!invoke(device, 20, 3, 27u, 1u));
assert(!invoke(device, 20, 3, 19u, 5u));
assert(!invoke(device, 20, 3, 20u, 6u));
+ for (unsigned replicate = 0; replicate < 4; ++replicate)
for (unsigned sample = 0; sample < 576; ++sample) {
struct vertex { float x, y, z, rhw; uint32_t color; float u, v, u1, v1; } vertices[] = {
{0,0,.25f,1,0x4080c0a0, -.25f,.125f, .875f,-.375f},
@@ -1136,6 +1137,9 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32
}
const uint32_t arguments[] = {0, 1, 2, 0, 3, 2, 2};
unsigned first_argument = sample >= 448 ? (sample >> 2) & 3 : arguments[sample / 64];
+ if (replicate & 1) first_argument |= 0x20;
+ unsigned second_argument = sample >= 256 ? sample & 3 : sample & 16 ? 0 : 1;
+ if (replicate & 2) second_argument |= 0x20;
for (unsigned stage = 0; stage < 2; ++stage) {
uint32_t texture = sample >= 192 && sample < 256 ? 0 : textures[sample & 16 ? 0 : stage];
assert(!invoke(device, 35, 3, stage, texture));
@@ -1158,8 +1162,9 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32
const uint32_t operations[] = {4, 7, 2, 1};
assert(!invoke(device, 37, 4, stage, 1u, sample >= 448 && (stage || (sample & 16)) ? 20u : stage ? operations[(sample >> 2) & 3] : 4u));
assert(!invoke(device, 37, 4, stage, 4u, stage ? (sample & 3) + 1 : 4u));
- assert(!invoke(device, 37, 4, stage, 3u, sample >= 256 ? sample & 3 : sample & 16 ? 0u : 1u));
- assert(!invoke(device, 37, 4, stage, 6u, sample >= 256 ? 3u : sample & 16 ? 0u : 1u));
+ assert(!invoke(device, 37, 4, stage, 3u, second_argument));
+ assert(!invoke(device, 36, 4, stage, 3u, workspace()) && *memory(workspace()) == second_argument);
+ assert(!invoke(device, 37, 4, stage, 6u, (sample >= 256 ? 3u : sample & 16 ? 0u : 1u) | (replicate & 2 ? 0x20u : 0u)));
}
assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f800000u, 0u));
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) == 8214528
+assert len(windows_pixels) == len(linux_pixels) == 13522944
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 2738176 pixels agree within one 8-bit channel step; maximum error:", error)
+print("All 4507648 pixels agree within one 8-bit channel step; maximum error:", error)