-
Notifications
You must be signed in to change notification settings - Fork 436
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 Metal vertex format lookup logic and reduce memory used by MVKPixelFormats lookups. #2105
Fix Metal vertex format lookup logic and reduce memory used by MVKPixelFormats lookups. #2105
Conversation
- Remove MVKPixelFormats::_mtlFormatDescIndicesByMTLVertexFormats and index into _mtlVertexFormatDescriptions using MTLVertexFormat directly. - Fix assertion to test MTLVertexFormat < _mtlVertexFormatCount.
b6607c3
to
fc9f9ca
Compare
Is there any particular reason we don't use something like std::vector here instead of these statically sized C-arrays? This would get rid of all of this size nonsense, which was the only reason #1940 seemed correct but wasn't. And it would allow seamless addition of new formats in the future, while also avoiding any magic values like for example |
You're not wrong. However, BTW...the constants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor nitpicks...
Yes I know. Counting the formats is inherently finicky, and having to additionally rely on magic values for newer formats makes it even worse. I was also critiquing the weird use of one statically sized array and an unordered_map for core and extension format description lookups. Very similar issue to the vector replacement at eliminating accidental errors, though not as important. |
I agree, it's a different design. 😉 Access to the format descriptions is the core operation of
The first 184 elements are consecutive from zero, lending themselves to be put into an array or vector. The remaining elements cannot be handled that way. Also, the linear elements are in general, more commonly used than the later elements, so it would be a shame to put them all in a umap (where access would be something like an order of magnitude slower). |
- Add MVKInflectionMap collection to manage lookups based on enums that have a large set of consecutive elements, plus additional enum values that are more sparsely assigned. - Recognize every MTLPixelFormat value can be held in uint16_t. - Reduce inflection-map sizes by calling shrink_to_fit(). - runcts script log completion time (unrelated).
fc9f9ca
to
88799cf
Compare
Okay. I decided to have a little design fun to incorporate @spnda's recommendations. I've added a new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MVKInflectionMap
should probably get a reserve
function to avoid a lot of reallocations, which we can then use in initMTLPixelFormatCapabilities
and initVkFormatCapabilities
in addition to the shrink_to_fit
.
- Add MVKInflectionMap collection to manage lookups based on enums that have a large set of consecutive elements, plus additional enum values that are more sparsely assigned. - Recognize every MTLPixelFormat value can be held in uint16_t. - Reduce inflection-map sizes by calling shrink_to_fit(). - runcts script log completion time (unrelated).
23bd121
to
0654928
Compare
@billhollings I also mentioned this in my review, but didn't know where to put it into the diff as a review so just put it into the main review message:
That hasn't been addressed and I still think it's important. When looping through those two functions the |
- Add MVKInflectionMap collection to manage lookups based on enums that have a large set of consecutive elements, plus additional enum values that are more sparsely assigned. - Recognize every MTLPixelFormat value can be held in uint16_t. - Reduce inflection-map sizes by calling shrink_to_fit(). - runcts script log completion time (unrelated).
dc7f166
to
a836e18
Compare
Uggh. Sorry. I missed your initial recommendation for some reason. Good catch. I've added |
MVKPixelFormats::_mtlFormatDescIndicesByMTLVertexFormats
andindex into
_mtlVertexFormatDescriptions
usingMTLVertexFormat
directly.MTLVertexFormat < _mtlVertexFormatCount
.MTLPixelFormat
value can be held inuint16_t
.MTLPixelFormat
values, and rely on assertions to validate if additional formats are added in future.This fixes the assertion issues first identified in PR #1940.