Silk.NET icon indicating copy to clipboard operation
Silk.NET copied to clipboard

WebGPU ShaderStage missing Flags attribute

Open joskuijpers opened this issue 1 year ago • 3 comments

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.

joskuijpers avatar Jul 01 '24 19:07 joskuijpers

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:

  1. Do the current checks.
  2. If unsuccessful, remove MaxValue values from the list of enums to check.
  3. 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.

Perksey avatar Jul 01 '24 21:07 Perksey

cc @tannergooding do you have opinions on marking things with Flags?

Perksey avatar Jul 01 '24 21:07 Perksey

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)

joskuijpers avatar Sep 14 '24 15:09 joskuijpers