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

nv2a: Update inline_values as rendering side-effect #623

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

abaire
Copy link
Contributor

@abaire abaire commented Jan 8, 2022

This updates the default inline_value for the normal vertex attribute whenever valid values for the normal are passed, mirroring the hardware behavior observed in https://github.com/abaire/nxdk_pgraph_tests/blob/main/tests/lighting_normal_tests.cpp.

Additional tests for all attributes:

I'm not entirely confident that this resolves all possible paths, but it does fix #601

Screenshot_20220110_213034

(note: screenshot was from my dev branch that also includes fix for #599, without which the minimap would be opaque but the lower left panel would still be fixed)

@Shoegzer
Copy link

With this PR, JSRF crashes immediately prior to the main menu (after the loading screen), with the following message in term:

qemu-system-i386: ../hw/xbox/nv2a/pgraph.c:6273: pgraph_bind_vertex_attributes: Assertion attr->gl_type == GL_FLOAT && "Need to convert non-float normal."' failed.

@abaire abaire marked this pull request as draft January 11, 2022 03:58
@abaire
Copy link
Contributor Author

abaire commented Jan 11, 2022

I'm hoping that I'm being overly cautious with that assert so it can probably be removed (though I'm interested in seeing what is actually being used if it's not a float).

Unfortunately it seems like I can no longer get past the loading screen even with a clean build from master so I'm putting this back into draft mode until I can verify that it's safe to remove the assert.

@abaire abaire force-pushed the updates_normal_inline_value branch 2 times, most recently from 356a740 to e01bd12 Compare January 11, 2022 05:13
@abaire
Copy link
Contributor Author

abaire commented Jan 11, 2022

Looks like it uses unsigned byte for normals after the loading screen. Removed the assert and fixed the handling to support arbitrary types instead of assuming they'll always be floats..I also had an error in how I was grabbing the last element, so as an added bonus the coloring is more correct now as well.

Thanks for testing @Shoegzer !

@abaire abaire marked this pull request as ready for review January 11, 2022 05:16
uint32_t element_size = attr->size * attr->count;
const uint8_t* last_entry = d->vram_ptr + start;
if (stride) {
last_entry += stride * (num_elements - 2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking on these. Is it possible that num_elements doesn't actually need the +1 at the top of the function (I'd expect that these should be num_elements - 1, but that definitely reads past the last element)?

Not sure if there's an off-by-one error or just an error in my assumptions based on the naming.

  • In my pgraph test I'm sending a single triangle (3 elements).
  • count is decremented by one before being sent to DRAW_ARRAYS as per spec, but that is handled here so pg->draw_arrays_max_count ends up being correct (3)
  • When the BEGIN_END is ended, the vertex attributes are bound w/ 3 as max_element. The naming and the +1 makes it sound like max_element is expected to be the maximum valid element (2 in my test case) rather than the max count (3) that's being passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing with Gun Valkyrie I feel more confident that the - 2 is wrong and the DRAW_ARRAYS path should be passing max_element rather than count. Added a fix for that in this PR.

@Shoegzer
Copy link

Tested and confirmed the assert/crashing is gone, and the bottom-left panel looks good. I haven't merged your other fix for the map itself, but with this PR alone it now shows:

pic

Nice work!

@abaire abaire marked this pull request as draft January 22, 2022 20:50
@abaire
Copy link
Contributor Author

abaire commented Jan 22, 2022

Just happened to find that this crashes Gun Valkyrie, where a call is made with num_elements == 1

@Shoegzer
Copy link

That's too bad. Not sure what that means in terms of getting this PR merged, though from what you say here:

I also had an error in how I was grabbing the last element, so as an added bonus the coloring is more correct now as well.

Would the panel color still be mostly correct if you avoided the condition for num_elements == 1? If so, would it make any sense to move that part to another PR and merge this one? Happy to help test any workarounds either way.

@abaire abaire force-pushed the updates_normal_inline_value branch 2 times, most recently from 534a2d5 to b90551c Compare January 22, 2022 21:27
@@ -2502,7 +2502,7 @@ DEF_METHOD(NV097, SET_BEGIN_END)
assert(pg->inline_elements_length == 0);

pgraph_bind_vertex_attributes(d, pg->draw_arrays_min_start,
pg->draw_arrays_max_count, false, 0);
pg->draw_arrays_max_count - 1, false, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the usage in pgraph_bind_vertex_attributes, it looks like the expectation is that this should be the last used element rather than the count.

Setting this to count requires a -2 to access the last used element in JSRF (and causes crashes in cases that use inline elements, such as Gun Valkyrie). As far as I can see, providing max_element in this path still works correctly in the games I've tested.

@abaire abaire marked this pull request as ready for review January 22, 2022 21:31
@abaire
Copy link
Contributor Author

abaire commented Jan 22, 2022

That's too bad. Not sure what that means in terms of getting this PR merged, though from what you say here:

I also had an error in how I was grabbing the last element, so as an added bonus the coloring is more correct now as well.

Would the panel color still be mostly correct if you avoided the condition for num_elements == 1? If so, would it make any sense to move that part to another PR and merge this one? Happy to help test any workarounds either way.

I think the crash was due to me working around what I think is a bug elsewhere. To fix the crash I fixed the other bug, so I think this should still be merge-able. It'd be great if you could verify that it still works for you with this latest push and try out as many other games as you can to see if it causes any weird glitches. The underlying fix will affect many more things than lighting but ideally you would not see any actual difference.

@Shoegzer
Copy link

You bet. Tested JSRF and it still works fine. I also tested Halo:CE, Halo 2 and those work as well as before at least. Star Wars KOTOR regressed, however, as eyes are missing from the character select screen (though this issue occurred before until very recently):

PR:
prpic

Master:
masterpic

Side-note since you asked: I have many other discs but I don't want to dump them to non-archival quality (xiso) images for various reasons as mentioned in #238 or I'd test those for you too. Hopefully xemu can support proper isos in the future (though I'm patient and respect priorities).

@abaire abaire marked this pull request as draft January 22, 2022 23:52
@abaire
Copy link
Contributor Author

abaire commented Jan 22, 2022

Ah, that'd almost certainly mean that I'm wrong about the count versus max somehow, or that there's some interesting dependency on the draw mode that needs to be accounted for. I own KOTOR so I'll do some debugging in a few days when I'm back with my hardware.

@abaire abaire force-pushed the updates_normal_inline_value branch from b90551c to e684395 Compare January 24, 2022 17:40
@abaire
Copy link
Contributor Author

abaire commented Jan 24, 2022

Well, the good news is that this seems to have been a simple case of the fix branch being older than the fix for KOTOR. I rebased to the latest master and the eyes now look correct. @Shoegzer would you mind re-verifying with the latest push?

The bad news is that I wrote a much more in-depth test in anticipation of tracking this down and found that the behavior in the case of inline elements is slightly wrong (it should always take the last rendered vertex, the code I wrote takes the last buffered vertex). I also verified that all the other attributes was able to test are supposed to carry over in the same way the normals do (diffuse, specular, tex coords, almost certainly the rest but I can't easily test them with nxdk's Cg-based shaders).

@mborgerson would you be OK to review and merge this PR as is and I'll do a followup?
The handling of the inline elements and additional attributes will add some complexity so I'm inclined to get this part that actually fixes a game in and then expand on it (I don't know if any other games suffer similar problems due to missing carryover).

@mborgerson
Copy link
Member

mborgerson commented Jan 24, 2022

The bad news is that I wrote a much more in-depth test in anticipation of tracking this down and found that the behavior in the case of inline elements is slightly wrong (it should always take the last rendered vertex, the code I wrote takes the last buffered vertex). I also verified that all the other attributes was able to test are supposed to carry over in the same way the normals do (diffuse, specular, tex coords, almost certainly the rest but I can't easily test them with nxdk's Cg-based shaders).

This is what I had expected. Thanks for creating a test case, it is actually good news.

@mborgerson would you be OK to review and merge this PR as is and I'll do a followup? The handling of the inline elements and additional attributes will add some complexity so I'm inclined to get this part that actually fixes a game in and then expand on it (I don't know if any other games suffer similar problems due to missing carryover).

Let's just fix it generally, it should not be too difficult.

By the way, the arrays implementation is flawed. I have a patch for it that notably fixes some sports games, but it needs a couple of remaining improvements. You are welcome to work on it, or I'll return to it shortly

@abaire abaire force-pushed the updates_normal_inline_value branch 2 times, most recently from 5656a56 to 10b29fc Compare January 24, 2022 20:31
@abaire
Copy link
Contributor Author

abaire commented Jan 24, 2022

The bad news is that I wrote a much more in-depth test in anticipation of tracking this down and found that the behavior in the case of inline elements is slightly wrong (it should always take the last rendered vertex, the code I wrote takes the last buffered vertex). I also verified that all the other attributes was able to test are supposed to carry over in the same way the normals do (diffuse, specular, tex coords, almost certainly the rest but I can't easily test them with nxdk's Cg-based shaders).

This is what I had expected. Thanks for creating a test case, it is actually good news.

@mborgerson would you be OK to review and merge this PR as is and I'll do a followup? The handling of the inline elements and additional attributes will add some complexity so I'm inclined to get this part that actually fixes a game in and then expand on it (I don't know if any other games suffer similar problems due to missing carryover).

Let's just fix it generally, it should not be too difficult.

By the way, the arrays implementation is flawed. I have a patch for it that notably fixes some sports games, but it needs a couple of remaining improvements. You are welcome to work on it, or I'll return to it shortly

@abaire abaire closed this Jan 24, 2022
@abaire abaire reopened this Jan 24, 2022
@abaire abaire marked this pull request as ready for review January 24, 2022 20:36
@abaire
Copy link
Contributor Author

abaire commented Jan 24, 2022

Accidentally closed, sorry! This should be ready for review now.

Let's just fix it generally, it should not be too difficult.

Sounds good. PR is updated, all testable cases now work correctly. I can't fully test the inline buffers case because xemu doesn't yet handle all of the attribute setter functions (e.g., SET_DIFFUSE_COLOR w/ 4 floats which my test program uses because I haven't gotten around to making use of floats versus DWORDs conditional).

By the way, the arrays implementation is flawed. I have a patch for it that notably fixes some sports games, but it needs a couple of remaining improvements. You are welcome to work on it, or I'll return to it shortly

Cool, I can take a look, I assume it's fix/arrays? Do you know offhand which games it fixes?

While writing this PR I noticed that there's an off-by one in the call to pgraph_bind_vertex_attributes when handling DRAW_ARRAYS but I've stomped on my comments a couple times now. Mentioning it here in case you haven't read the full conversation history.

@Triticum0
Copy link

It is fix/array and the game it fixes are on this issue #329.

@Shoegzer
Copy link

Well, the good news is that this seems to have been a simple case of the fix branch being older than the fix for KOTOR. I rebased to the latest master and the eyes now look correct. @Shoegzer would you mind re-verifying with the latest push?

I was wondering if this was a rebase issue since the eyes were fixed so recently in master, glad to know it was that simple. In any event, KOTOR eyes are fine now with your PR, and of course JSRF lower-left panel looks good too. Nice.

@abaire abaire force-pushed the updates_normal_inline_value branch from 10b29fc to 409b2ab Compare January 24, 2022 23:39
@abaire abaire changed the title nv2a: Update normal inline_value as rendering side-effect nv2a: Update inline_values as rendering side-effect Jan 28, 2022
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
@abaire abaire force-pushed the updates_normal_inline_value branch 3 times, most recently from 640f925 to 6ab0001 Compare February 15, 2022 20:26
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
hw/xbox/nv2a/pgraph.c Outdated Show resolved Hide resolved
@mborgerson
Copy link
Member

Thanks!

@mborgerson mborgerson merged commit 83d4cbb into xemu-project:master Feb 22, 2022
@abaire abaire deleted the updates_normal_inline_value branch February 23, 2022 19:34
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 this pull request may close these issues.

Jet Set Radio Future [JSRF]: Incorrect rendering of progress indicator panel
4 participants