Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated frag shader may assign alpha channel of dot product statement #54

Closed
HadetTheUndying opened this issue Oct 30, 2020 · 2 comments
Labels
bug Something isn't working graphics

Comments

@HadetTheUndying
Copy link

HadetTheUndying commented Oct 30, 2020

https://xemu.app/titles/4d530046/#Phantom-Dust

Title "Phantom Dust" will crash when entering campaign.

Failing Fragment Shader from "Phantom Dust"
#version 330

struct VertexData {
  float inv_w;
  vec4 D0;
  vec4 D1;
  vec4 B0;
  vec4 B1;
  float Fog;
  vec4 T0;
  vec4 T1;
  vec4 T2;
  vec4 T3;
};
noperspective in VertexData g_vtx;
#define vtx g_vtx

out vec4 fragColor;

uniform vec4 fogColor;
float sign1(float x) {
    x *= 255.0;
    return (x-128.0)/127.0;
}
float sign2(float x) {
    x *= 255.0;
    if (x >= 128.0) return (x-255.5)/127.5;
               else return (x+0.5)/127.5;
}
float sign3(float x) {
    x *= 255.0;
    if (x >= 128.0) return (x-256.0)/127.0;
               else return (x)/127.0;
}
vec3 dotmap_zero_to_one(vec3 col) {
    return col;
}
vec3 dotmap_minus1_to_1_d3d(vec3 col) {
    return vec3(sign1(col.r),sign1(col.g),sign1(col.b));
}
vec3 dotmap_minus1_to_1_gl(vec3 col) {
    return vec3(sign2(col.r),sign2(col.g),sign2(col.b));
}
vec3 dotmap_minus1_to_1(vec3 col) {
    return vec3(sign3(col.r),sign3(col.g),sign3(col.b));
}
vec3 dotmap_hilo_1(vec3 col) {
    return col;
}
vec3 dotmap_hilo_hemisphere_d3d(vec3 col) {
    return col;
}
vec3 dotmap_hilo_hemisphere_gl(vec3 col) {
    return col;
}
vec3 dotmap_hilo_hemisphere(vec3 col) {
    return col;
}
uniform ivec4 clipRegion[1];
uniform sampler2DRect texSamp0;
uniform sampler2DRect texSamp1;
uniform vec4 c0_0;
uniform vec4 c0_1;
void main() {
/*  Window-clip (Inclusive) */
bool clipContained = false;
for (int i = 0; i < 1; i++) {
  bvec4 clipTest = bvec4(lessThan(gl_FragCoord.xy, clipRegion[i].xy),
                         greaterThan(gl_FragCoord.xy, clipRegion[i].zw));
  if (!any(clipTest)) {
    clipContained = true;
    break;
  }
}
if (!clipContained) { discard; }
vec4 pD0 = vtx.D0 / vtx.inv_w;
vec4 pD1 = vtx.D1 / vtx.inv_w;
vec4 pB0 = vtx.B0 / vtx.inv_w;
vec4 pB1 = vtx.B1 / vtx.inv_w;
vec4 pFog = vec4(fogColor.rgb, clamp(vtx.Fog / vtx.inv_w, 0.0, 1.0));
vec4 pT0 = vtx.T0 / vtx.inv_w;
vec4 pT1 = vtx.T1 / vtx.inv_w;
vec4 pT2 = vtx.T2 / vtx.inv_w;
vec4 pT3 = vtx.T3 / vtx.inv_w;

vec4 v0 = pD0;
vec4 v1 = pD1;
vec4 t0 = textureProj(texSamp0, pT0.xyw);
vec4 t1 = textureProj(texSamp1, pT1.xyw);
vec4 t2 = vec4(0.0); /* PS_TEXTUREMODES_NONE */
vec4 t3 = vec4(0.0); /* PS_TEXTUREMODES_NONE */
vec4 r1;
vec4 r0;
r0.a = t0.a;
// Stage 0
r1.rgb = clamp(vec3(((t0.rgb * c0_0.rgb) + (t1.rgb * c0_0.aaa))), -1.0, 1.0);
// Stage 1
r0.rgb = clamp(vec3(dot(r1.rgb, c0_1.rgb)), -1.0, 1.0);
r0.a = r0.b;
dot(vec4(0.0).rgb, vec4(0.0).rgb).a = dot(vec4(0.0).rgb, vec4(0.0).rgb).b;
// Stage 2
r1.rgb = clamp(vec3(((r0.a >= 0.5) ? vec3((r1.rgb * (1.0 - clamp(vec4(0.0).rgb, 0.0, 1.0)))) : vec3((vec4(0.0).rgb * vec4(0.0).rgb)))), -1.0, 1.0);
r0.a = clamp((((2.0 * max(r0.a, 0.0) - 1.0) * (1.0 - clamp(vec4(0.0).a, 0.0, 1.0)))), -1.0, 1.0);
// Final Combiner
fragColor.rgb = max(r1.rgb, 0.0) + mix(vec3(max(vec4(0.0).rgb, 0.0)), vec3(max(vec4(0.0).rgb, 0.0)), vec3(max(vec4(0.0).rgb, 0.0)));
fragColor.a = max(r0.a, 0.0);
}


nv2a: fragment shader compilation failed: 0:100(1): error: cannot access field `a' of non-structure / non-vector
0:100(1): error: type mismatch
0:100(39): error: cannot access field `b' of non-structure / non-vector
0:100(39): error: type mismatch

[1]    12153 abort      ./xemu

@mborgerson mborgerson changed the title Phantom Crash crashes on loading a Stage Fragment shader may try to assign to alpha channel of a dot product expression Oct 30, 2020
@mborgerson mborgerson added bug Something isn't working graphics labels Oct 30, 2020
@mborgerson mborgerson changed the title Fragment shader may try to assign to alpha channel of a dot product expression Generated frag shader may assign alpha channel of dot product statement Oct 30, 2020
@abaire
Copy link
Contributor

abaire commented Mar 19, 2022

It'd be interesting to re-test this with #720 which makes some significant changes to the combiner generation. If this is still reproducible, I'd be very interested to look at a log of the pgraph trace around the time of the crash; the vectors being dotted don't make any sense since they're set to the combiner zero constant.

I own this game but I'm getting a crash when attempting to get past the start screen so I can't verify at the moment (could be dump related, HDD image related, or the fact that I'm running it off my dev branch to have more debugging output).

@HadetTheUndying
Copy link
Author

It'd be interesting to re-test this with #720 which makes some significant changes to the combiner generation. If this is still reproducible, I'd be very interested to look at a log of the pgraph trace around the time of the crash; the vectors being dotted don't make any sense since they're set to the combiner zero constant.

I own this game but I'm getting a crash when attempting to get past the start screen so I can't verify at the moment (could be dump related, HDD image related, or the fact that I'm running it off my dev branch to have more debugging output).

Can confirm #720 fixes. The game is fully playable and running really well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graphics
Projects
None yet
Development

No branches or pull requests

3 participants