Page MenuHome

Fix: bad bitmasks for ENUM_OPERATORS ~ operator
AcceptedPublic

Authored by Ethan Hall (Ethan1080) on Apr 2 2022, 2:39 AM.

Details

Summary

This patch fixes the 'not' bitmasks for some enumerators.
This patch improves the comments for ENUM_OPERATORS and implements
a static assertion to reduce the chance of programming bad bitmasks
in future code.

Diff Detail

Repository
rB Blender
Branch
enum_ops_fix (branched from master)
Build Status
Buildable 21423
Build 21423: arc lint + arc unit

Event Timeline

Ethan Hall (Ethan1080) requested review of this revision.Apr 2 2022, 2:39 AM
Ethan Hall (Ethan1080) created this revision.

Oh, I also changed the 2 * x to x << 1.
Since we are preforming bit manipulation to create the mask, left shift by one is more clear than multiply by two.

Good find here. I'll defer to Jacques for final approval. Just a few minor comments right now.

source/blender/blenlib/BLI_utildefines.h
799

I'd add this assert block either at the very top or very bottom of the macro instead of in the middle of the operators.

801

There's no need to have a trailing \n character in your message. Clang literally writes out \n in the output and MSVC quotes the string, so you get a line with just an ending quote for it.

801

I think we'd actually want to disallow 0 right? Would a 0 ever be useable?

source/blender/gpu/GPU_platform.h
28

Oof... is there a separate patch for this duplicate value?? Seems wrong / would at least deserve a comment if nothing else.

34

This 7 probably depends on the answer to the above.

Ethan Hall (Ethan1080) added inline comments.
source/blender/blenlib/BLI_utildefines.h
801

0 results in a bitmask that is 1 for all bits. It might not be useful, but at least it does not leave holes in the bitmask, so it is not as bad as other non-power-of-twos.

The assert cannot prevent the programmer from putting the wrong power of two. It only prevents values that result in bitmasks holes or more than one switch over point from zeros to ones.

That said, an explicit check for _max_enum_value not equals 0 could be added.

source/blender/gpu/GPU_platform.h
28

Would have to ask @Brecht Van Lommel (brecht). The change was made to prevent a warning message for unknown GPU: rB62419975b78b
Maybe it is just a temporary fix until the Metal work is further along. It could use a comment though.

34

I set the value to (1 << 7) is to ensure that GPU_DEVICE_ANY (AKA 0xff) is fully included in the bitmask. Since there is no (1 << 6) or (1 << 7), I think 7 is independent of the answer to the above comment.

  • Moved assert to top and fixed assert message.
Ethan Hall (Ethan1080) marked 2 inline comments as done.Apr 2 2022, 10:30 AM
This revision is now accepted and ready to land.Apr 3 2022, 9:57 AM
source/blender/gpu/GPU_platform.h
28

Thanks, I committed a fix for that in rBaa1ae1d3c8ef: Fix overlapping GPU device bitmasks.

Ethan Hall (Ethan1080) marked 3 inline comments as done.Apr 5 2022, 5:50 AM