WebGPU ShaderStage missing Flags attribute
Summary
ShaderStage is used to indicate visibility of bind groups. It is allowed to have more than 1 of these items, and their values are 2^n.
Steps to reproduce
Write:
ShaderStage.Vertex | ShaderStage.Fragment
gives warning:
Bitwise operation on enum is not marked by [Flags] attribute
Comments
I know [Flags] needs to be added, I just do not know how in the process to automate that.
Hmmm. Looking at that enum it won't be automatically marked because of Force32, so I guess in automating this we'd have to add recognition for such patterns.
Maybe:
- Do the current checks.
- If unsuccessful, remove
MaxValuevalues from the list of enums to check. - If still unsuccessful, check whether:
- each enum has only one bit set, or
- each enum only has bits set that were declared before it when ordered, as long as
- the enum is not sequential (a false positive check for the previous check)
Or alternatively mark everything as Flags, but that seems like a bad idea.
cc @tannergooding do you have opinions on marking things with Flags?
The problem is IsSequential returning true for the [0,1,2,4,int.MaxValue] set. So keeping an IsSequential check won't work.
Idea:
- Current algorithm succeeds,
- or:
- All items that are not int.MaxValue have PopCount==1
- There are more than 2 items that have value > 0 (to prevent [1,2] [0,1], [0,1,2] from becoming flags)