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

Vertex arrays enabled when there's no data passed for them #5133

Closed
unknownbrackets opened this issue Jan 18, 2014 · 3 comments · Fixed by #5134
Closed

Vertex arrays enabled when there's no data passed for them #5133

unknownbrackets opened this issue Jan 18, 2014 · 3 comments · Fixed by #5134

Comments

@unknownbrackets
Copy link
Collaborator

While investigating #5124, I found a workaround: calling gpu->CopyDisplayToOutput(); on savestate load fixed it. Weird. Almost figured that was good enough, but I dug deeper.

I then found that what was "saving" it was glVertexAttribPointer(program->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, texCoords); from DrawActiveTexture(). Otherwise, it crashes on glDrawArrays(glprim[prim], 0, vertexCount); - presumably because there was no data for a_texcoord0 and it was enabled.

So, then I looked into what was enabled. It turns out this is wholly controlled by this line:

if (-1 != glGetAttribLocation(program, "texcoord")) attrMask |= 1 << ATTR_TEXCOORD;

And, indeed, this particular shader does have texturing enabled, therefore it does have a texcoord input parameter. However, the vertex does not have any texture coordinates - I guess it would just use whatever were previously passed (maybe this is the cause of #4617? And the Star Ocean crash maybe?)

Changing it to:

if (-1 != glGetAttribLocation(program, "texcoord") && (vertType & GE_VTYPE_TC_MASK) != 0) attrMask |= 1 << ATTR_TEXCOORD;

Safely works around the crash (although the other attributes might have issues too.) Another viable (and probably better, since I'm not sure what the behavior ought to be?) option is this in the shader:

int doTexture = (vertType & GE_VTYPE_TC_MASK) != 0 && gstate.isTextureMapEnabled() && !gstate.isModeClear();

Anyway, I guess we need to figure out what happens if texturing is enabled and no texcoords are passed, and also if any of the other vertex attributes can have this problem.

-[Unknown]

@hrydgard
Copy link
Owner

Good investigation.

Hm. Texturing being enabled with no texture coordinates in the vertices is a totally valid scenario if (and probably only if) texture coordinate generation is enabled (gstate.getUVGenMode() != GE_TEXMAP_TEXTURE_COORDS (or UNKNOWN)).

The check for enabling that vertex array thus needs to also check the texcoord gen mode, which we don't seem to do atm..

@unknownbrackets
Copy link
Collaborator Author

In this particular case, gstate.getUVGenMode() = GE_TEXMAP_TEXTURE_COORDS. Vertex type is 0x000001e0.

There are 9 flushes per frame like this, and it keeps going. The crash only happens of course in hardware transform.

-[Unknown]

@hrydgard
Copy link
Owner

Okay, that's a game bug then, but one we should tolerate better. Not sure if we should emit 0.0 texcoords from the vertex decoder or generate special vertex shaders that simply write 0.0 for the fragment shader to read.

unknownbrackets added a commit to unknownbrackets/ppsspp that referenced this issue Jan 18, 2014
Can't find any other unprotected attributes (well, position, but that
should always be specified) so this fixes hrydgard#5133.

Also fixes hrydgard#5124 for me.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants