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

EnumUtils: Add Common::ToUnderlying #11962

Merged
merged 2 commits into from Jun 17, 2023

Conversation

Minty-Meeo
Copy link
Contributor

Mirrors the C++23 <utility> function, std::to_underlying.
This is an extract of changes from #11932.

@Minty-Meeo Minty-Meeo marked this pull request as ready for review June 17, 2023 06:42
Mirrors the C++23 <utility> function, std::to_underlying
@AdmiralCurtiss
Copy link
Contributor

Okay like half of your changes are actually changing the casted-to type here. If you want to argue that the casts were previously incorrect, be my guest (probably true for some of these, and some of the enums may have been intended as unsigned in the first place), but this is too many changes for me to casually merge in a single commit, even if it mainly affects logging.

@Minty-Meeo
Copy link
Contributor Author

Minty-Meeo commented Jun 17, 2023

I previously traced these type static_casts back to a commit by @Pokechu22. Seen here: cc56402. These were previously printed in the underlying type. In a way, this is actually a restoration. It's a good demonstration of what makes std::to_underlying / Common::ToUnderlying useful.

@AdmiralCurtiss
Copy link
Contributor

Mhm, fair enough, that's a pain in the ass to cross-check but I see your point. Let's see...

@Minty-Meeo
Copy link
Contributor Author

Perhaps Pokechu22 can chime in about whether these enums are better represented as a different type.

@@ -119,11 +120,11 @@ void WriteVertexLighting(ShaderCode& out, APIType api_type, std::string_view wor
out.Write(" if ({} != 0u) {{\n", BitfieldExtract<&LitChannel::enablelighting>("alphareg"));
out.Write(" if ({} != 0u) {{\n", BitfieldExtract<&LitChannel::ambsource>("alphareg"));
out.Write(" if ((components & ({}u << chan)) != 0u) // VB_HAS_COL0\n",
static_cast<u32>(VB_HAS_COL0));
Common::ToUnderlying(VB_HAS_COL0));
Copy link
Contributor

Choose a reason for hiding this comment

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

These (as well as the ones in UberShaderVertex.cpp) look really sketchy though, this code would clearly break if it actually printed as signed. None of the values are actually big enough for that to happen, but this is clearly intended as unsigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Multiple other places use it to modify u32s. Perhaps the underlying type for this one should be changed to that.

@AdmiralCurtiss
Copy link
Contributor

Okay, the Ubershader changes look wrong to me, but for everything else this is fine. From a quick glance the enum in NativeVertexFormat.h is always used in an unsigned context so it should be unsigned in the first place, at which point the changes here become okay.

@AdmiralCurtiss
Copy link
Contributor

Okay, yes, this looks correct to me now. I'll leave it open for a bit in case Pokechu wants to chime in.

@Pokechu22
Copy link
Contributor

I believe I just defaulted to using u32 because it felt better to me, with no deeper meaning.

@AdmiralCurtiss
Copy link
Contributor

Alright then.

@AdmiralCurtiss AdmiralCurtiss merged commit 93d9e90 into dolphin-emu:master Jun 17, 2023
14 checks passed
AdmiralCurtiss added a commit to AdmiralCurtiss/dolphin that referenced this pull request Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants