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

Fix invalid data length calculated in get_query_pool_results() when called with WITH_AVAILABILITY flag #640

Closed
wants to merge 3 commits into from

Conversation

matszczygiel
Copy link

Fixes #639

@MarijnS95
Copy link
Collaborator

Can you include a concise description of this issue - and why this solution is correct - in the commit message?

@MarijnS95
Copy link
Collaborator

Don't forget to add it to the changelog either.

@Ralith
Copy link
Collaborator

Ralith commented Jul 11, 2022

Note that we're still passing mem::size_of::<T>() as the stride. This means that for WITH_AVAILABILITY, T should probably be (u32, vk::Bool32) or similar, unlike your example in #639. Might bear documenting this explicitly.

@MarijnS95
Copy link
Collaborator

@Ralith I wondered if it makes sense to perhaps change the function signature to deal specifically with WITH_AVAILABILITY and WITH_STATUS? From your example I take it the stride should also be 8 (for u32 + bool32) here otherwise subsequent values start overwriting the availability/status result?

@Ralith
Copy link
Collaborator

Ralith commented Jul 11, 2022

mem::size_of::<(u32, vk::Bool32)>() is 8, so using that as T should Just Work without any additional measures in the interface--even without the change proposed in this PR.

@Ralith
Copy link
Collaborator

Ralith commented Jul 11, 2022

I think we should either add a stride argument or further remove the query_count argument, because I don't think it's useful to have a query count different than data.len() otherwise, unless we set stride to query_count / data.len(), but that seems a bit magical.

I lean towards dropping query_count in the spirit of greater type safety personally. Adding (or dynamically computing) stride would make it easier to select flags dynamically and decode results after the fact, but it's difficult to imagine a case where that is preferable.

@MarijnS95
Copy link
Collaborator

mem::size_of::<(u32, vk::Bool32)>() is 8, so using that as T should Just Work without any additional measures in the interface--even without the change proposed in this PR.

Meaning that this PR together with the example proposed in #639 doesn't work as intended, since the use of u32 there results in a stride of 4? My question is whether query N+1 would overwrite the AVAILABILITY bit of query N in that case.
Local testing indicates that that is indeed what happens; the availability result is overwritten by query value N+1.

Of course the caller can/should use a Vec<(u32, vk::Bool32)> here and immediately receive the type-safe results in a usable manner. Replace u32 with u64 for 64-bit results. And that immediately addresses / works around the "missing" stride field.

The request to come up with a more specific API is probably moot given that its use may be expanded over time - see WITH_STATUS_KHR which is being introduced through the VK_KHR_video_queue beta extension.
We can't check for T=u32 + TYPE_64 either, but that's unnecessary and the job of the validation layer.

I lean towards dropping query_count in the spirit of greater type safety personally. Adding (or dynamically computing) stride would make it easier to select flags dynamically and decode results after the fact, but it's difficult to imagine a case where that is preferable.

IIRC we discussed and approved/agreed on removing query_count before, since the user passes in a slice here and can hence easily change the length.

@matszczygiel
Copy link
Author

OK. So what seems to be the solution is to just simply use a slice of (u32, vk::Bool32).
Should I close this PR ?

@MarijnS95
Copy link
Collaborator

MarijnS95 commented Jul 12, 2022

@matszczygiel this PR is correct after you reword the title/commit message as suggested above, and at the same time you must use a tuple for T so that the stride is correct.

Don't forget to add a changelog entry either.

EDIT: Meanwhile @Ralith may want to submit a separate PR to remove query_count.

matszczygiel and others added 2 commits July 12, 2022 17:17
… when called with `WITH_AVAILABILITY` flag
Co-authored-by: Benjamin Saunders <ben.e.saunders@gmail.com>
@matszczygiel
Copy link
Author

@MarijnS95 I have changed the commit message. Also added the changelog entry.

@MarijnS95 MarijnS95 changed the title fix get_query_pool_results() bug with vk::QueryResultFlags::WITH_AVAILABILITY Fix invalid data length calculated inside get_query_pool_results() when called with WITH_AVAILABILITY flag Jul 28, 2022
@MarijnS95 MarijnS95 changed the title Fix invalid data length calculated inside get_query_pool_results() when called with WITH_AVAILABILITY flag Fix invalid data length calculated in get_query_pool_results() when called with WITH_AVAILABILITY flag Jul 28, 2022
Copy link
Collaborator

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

@Ralith Recapping what we wrote above... What do we get when we do not merge this change?

I think not merging this change forces the user to use the proper (u32, vk::Bool32) type for T, and automatically get the right stride in what is currently mem::size_of::<T>() as _? As such there's not really anything to fix?

Then separately we can remove query_count and utilize slice length.

@@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Removed experimental AMD extensions (#607)

### Fixed

- Fix invalid data length calculated inside of `get_query_pool_results` when called with `WITH_AVAILABILITY` flag (#640)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- Fix invalid data length calculated inside of `get_query_pool_results` when called with `WITH_AVAILABILITY` flag (#640)
- Data size in `get_query_pool_results()` is now based on total slice size rather than type size times query count to support `WITH_AVAILABILITY` when `T` is "wrong" (#640)

But as I wrote, I don't think this is very sensible in the end.

@Ralith
Copy link
Collaborator

Ralith commented Jul 29, 2022

Fine by me.

@MarijnS95
Copy link
Collaborator

MarijnS95 commented Jul 29, 2022

Will close this then. I get the expected results on the current release using TYPE_64 | WITH_AVAILABILITY when passing a slice with T = (u64, vk::Bool32). Merging this would fix the wrong thing for the wrong reasons. #644 will only be a (breaking) API improvement.

@MarijnS95 MarijnS95 closed this Jul 29, 2022
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.

get_query_pool_results buggy when called with vk::QueryResultFlags::WITH_AVAILABILITY
3 participants