commit 10ba94eca5cd778ccd247c7871f5b80fe8a6a898
parent 9507c764c0d10de210e48b9bb9d716dc77673f56
Author: anon <anon@example.com>
Date: Thu, 15 Oct 2026 15:12:49 +0000
Select native texture color and alpha arguments
Diffstat:
5 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/decompiled/runtime/gl_renderer.c b/decompiled/runtime/gl_renderer.c
@@ -10,6 +10,7 @@ static GLuint program, vertex_array, vertex_buffer, index_buffer;
static GLuint samplers[2];
static GLint texture_enabled[2], texture_alpha[2], texture_color_op[2], texture_alpha_op[2];
static GLint texture_color_arg2[2], texture_alpha_arg2[2];
+static GLint texture_color_arg1[2], texture_alpha_arg1[2];
static GLint fog_enabled, fog_color;
static int depth_write = 1;
static uint32_t depth_function = 4;
@@ -67,8 +68,11 @@ int gl_renderer_initialize(void)
"uniform bool fog_enabled; uniform vec3 fog_color;\n"
"uniform sampler2D image0, image1;\n"
"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"
"void combine(int s, vec4 t) { vec3 c=color_arg2[s]==0 ? color.rgb : pixel.rgb;"
"float a=alpha_arg2[s]==0 ? color.a : pixel.a; if(!has_alpha[s]) t.a=1.0;"
+ "t.rgb=color_arg1[s]==0 ? color.rgb : color_arg1[s]==1 ? pixel.rgb : t.rgb;"
+ "t.a=alpha_arg1[s]==0 ? color.a : alpha_arg1[s]==1 ? pixel.a : t.a;"
"pixel.rgb=color_op[s]==4 ? t.rgb*c : color_op[s]==7 ? min(vec3(1.0),t.rgb+c) : t.rgb;"
"if(alpha_op[s]!=1) pixel.a=alpha_op[s]==3 ? a : alpha_op[s]==4 ? t.a*a : t.a; }\n"
"void main() { pixel=color; if(textured[0]) { combine(0,texture(image0,uv));"
@@ -111,6 +115,8 @@ int gl_renderer_initialize(void)
texture_alpha_op[i] = glGetUniformLocation(program, i ? "alpha_op[1]" : "alpha_op[0]");
texture_color_arg2[i] = glGetUniformLocation(program, i ? "color_arg2[1]" : "color_arg2[0]");
texture_alpha_arg2[i] = glGetUniformLocation(program, i ? "alpha_arg2[1]" : "alpha_arg2[0]");
+ texture_color_arg1[i] = glGetUniformLocation(program, i ? "color_arg1[1]" : "color_arg1[0]");
+ texture_alpha_arg1[i] = glGetUniformLocation(program, i ? "alpha_arg1[1]" : "alpha_arg1[0]");
}
fog_enabled = glGetUniformLocation(program, "fog_enabled");
fog_color = glGetUniformLocation(program, "fog_color");
@@ -383,7 +389,7 @@ void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *stat
glUniform1i(texture_enabled[stage], state != NULL);
glActiveTexture(GL_TEXTURE0 + stage);
glBindSampler(stage, samplers[stage]);
- if (state) {
+ if (state && state->image) {
make_resident(state->image);
if (state->image->mip_dirty) {
unsigned level = 0;
@@ -405,12 +411,16 @@ void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *stat
glSamplerParameteri(samplers[stage], GL_TEXTURE_MAG_FILTER, state->mag_linear ? GL_LINEAR : GL_NEAREST);
glSamplerParameteri(samplers[stage], GL_TEXTURE_WRAP_S, state->clamp_u ? GL_CLAMP_TO_EDGE : GL_REPEAT);
glSamplerParameteri(samplers[stage], GL_TEXTURE_WRAP_T, state->clamp_v ? GL_CLAMP_TO_EDGE : GL_REPEAT);
+ } else glBindTexture(GL_TEXTURE_2D, 0);
+ if (state) {
glUniform1i(texture_alpha[stage], state->alpha);
glUniform1i(texture_color_op[stage], state->color_op);
glUniform1i(texture_alpha_op[stage], state->alpha_op);
glUniform1i(texture_color_arg2[stage], state->color_arg2);
glUniform1i(texture_alpha_arg2[stage], state->alpha_arg2);
- } else glBindTexture(GL_TEXTURE_2D, 0);
+ glUniform1i(texture_color_arg1[stage], state->color_arg1);
+ glUniform1i(texture_alpha_arg1[stage], state->alpha_arg1);
+ }
glActiveTexture(GL_TEXTURE0);
check_graphics("texture binding");
}
diff --git a/decompiled/runtime/gl_renderer.h b/decompiled/runtime/gl_renderer.h
@@ -16,6 +16,7 @@ struct gl_texture_state {
struct gl_target *image;
int min_linear, mag_linear, clamp_u, clamp_v, alpha, color_op, alpha_op, mip_point;
int color_arg2, alpha_arg2;
+ int color_arg1, alpha_arg1;
};
int gl_renderer_initialize(void);
diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c
@@ -52,7 +52,7 @@ struct device_light {
struct texture_stage {
uint32_t min_filter, mag_filter, mip_filter, address, address_u, address_v, color_op, alpha_op;
uint32_t sampler_u, sampler_v, texture_transform, texture_coordinate;
- uint32_t color_arg2, alpha_arg2;
+ uint32_t color_arg1, alpha_arg1, color_arg2, alpha_arg2;
struct surface_object *texture;
};
static struct device_object {
@@ -1342,6 +1342,7 @@ static void create_device(void)
stage->color_op = i ? 1 : 4;
stage->alpha_op = i ? 1 : 2;
stage->color_arg2 = stage->alpha_arg2 = 1;
+ stage->color_arg1 = stage->alpha_arg1 = 2;
}
device->source_blend = 2;
device->destination_blend = 1;
@@ -1829,12 +1830,12 @@ 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];
- if (stage->texture && stage->color_op != 1) {
- struct gl_texture_state state = {stage->texture->target,
+ if (stage->color_op != 1 && (stage->texture || stage->color_arg1 != 2)) {
+ struct gl_texture_state state = {stage->texture ? stage->texture->target : NULL,
stage->min_filter == 2, stage->mag_filter == 2,
stage->sampler_u == 3, stage->sampler_v == 3,
- stage->texture->alpha, stage->color_op, stage->alpha_op, stage->mip_filter == 2,
- stage->color_arg2, stage->alpha_arg2};
+ stage->texture && stage->texture->alpha, stage->color_op, stage->alpha_op, stage->mip_filter == 2,
+ stage->color_arg2, stage->alpha_arg2, stage->color_arg1, stage->alpha_arg1};
gl_renderer_set_texture(i, &state);
} else gl_renderer_set_texture(i, NULL);
}
@@ -1908,7 +1909,8 @@ static uint32_t texture_stage_state(struct texture_stage *stage, uint32_t state)
{
switch (state) {
case 1: return stage->color_op;
- case 2: case 5: return 2; /* Texture argument. */
+ case 2: return stage->color_arg1;
+ case 5: return stage->alpha_arg1;
case 3: return stage->color_arg2;
case 6: return stage->alpha_arg2;
case 4: return stage->alpha_op;
@@ -1966,6 +1968,8 @@ static void device_set_texture_state(void)
else if (state == 1 && (value == 1 || value == 2 || value == 4 || value == 7)) 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 <= 2) device->stages[stage].color_arg1 = value;
+ else if (state == 5 && value <= 2) device->stages[stage].alpha_arg1 = value;
else if (state == 3 && value <= 1) device->stages[stage].color_arg2 = value;
else if (state == 6 && value <= 1) device->stages[stage].alpha_arg2 = value;
else if (value != texture_stage_state(&device->stages[stage], state)) {
diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c
@@ -1077,7 +1077,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 sample = 0; sample < 64; ++sample) {
+ for (unsigned sample = 0; sample < 256; ++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},
{32,0,.25f,.5f,0x8080c0a0, 1.75f,.125f, -.125f,-.375f},
@@ -1090,10 +1090,10 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32
memcpy(memory(input + i * 32 + 12), &vertices[i].color, 20);
}
for (unsigned stage = 0; stage < 2; ++stage) {
- uint32_t texture = textures[sample & 16 ? 0 : stage];
+ uint32_t texture = sample >= 192 ? 0 : textures[sample & 16 ? 0 : stage];
assert(!invoke(device, 35, 3, stage, texture));
assert(!invoke(device, 34, 3, stage, workspace()) && *memory(workspace()) == texture);
- assert(invoke(texture, 2, 1) > 0);
+ if (texture) assert(invoke(texture, 2, 1) > 0);
assert(!invoke(device, 37, 4, stage, 11u, stage));
assert(!invoke(device, 37, 4, stage, 24u, sample & 32 ? 2u : 0u));
const float matrix[] = {2,0,0,0, 0,1,0,0, .125f,.375f,1,0, 0,0,0,1};
@@ -1105,6 +1105,9 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32
assert(!invoke(device, 37, 4, stage, 12u, stage ? 3u : 1u));
assert(!invoke(device, 37, 4, stage, 13u, stage ? 3u : 1u));
assert(!invoke(device, 37, 4, stage, 14u, stage ? 3u : 1u));
+ assert(!invoke(device, 37, 4, stage, 2u, (sample / 64) % 3));
+ assert(!invoke(device, 37, 4, stage, 5u, sample & 16 ? ((sample / 64) % 3 + 1) % 3 : (sample / 64) % 3));
+ assert(!invoke(device, 36, 4, stage, 2u, workspace()) && *memory(workspace()) == (sample / 64) % 3);
const uint32_t operations[] = {4, 7, 2, 1};
assert(!invoke(device, 37, 4, stage, 1u, stage ? operations[(sample >> 2) & 3] : 4u));
assert(!invoke(device, 37, 4, stage, 4u, stage ? (sample & 3) + 1 : 4u));
@@ -1133,6 +1136,8 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32
assert(!invoke(target, 32, 2, 0u));
assert(fwrite(rgb, 1, sizeof(rgb), file) == sizeof(rgb));
}
+ assert(!invoke(device, 35, 3, 0u, textures[0]));
+ assert(!invoke(device, 35, 3, 1u, textures[0]));
assert(!invoke(device, 35, 3, 0u, 0u));
assert(invoke(textures[0], 2, 1) == 1);
assert(!invoke(device, 35, 3, 1u, 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) == 4184064
+assert len(windows_pixels) == len(linux_pixels) == 4773888
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 1394688 pixels agree within one 8-bit channel step; maximum error:", error)
+print("All 1591296 pixels agree within one 8-bit channel step; maximum error:", error)