-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Use 3 bits of PipelineKey to store MSAA sample count #5826
Conversation
let msaa_bits = ((msaa_samples - 1) & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS; | ||
MeshPipelineKey::from_bits(msaa_bits).unwrap() | ||
let msaa_bits = | ||
(msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS; |
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.
Should this report an error in some way if the MSAA sample number is not a power of two?
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.
These checks are already inside the wgpu-rs.
Sample count must not only be the power of two, but also match the values chosen for the RenderTarget's attachments.
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.
Looks good to me. Always glad to have more space in the pipeline keys!
bors r+ |
Sample count always power of two. Thus, it is enough to store `log2(sample_count)`. This can be implemented using [u32::trailing_zeros](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.trailing_zeros). Then we can restore sample count with the `1 << stored`. You get 3 bits instead of 6 and up to 128x MSAA. This is more than is supported by any common hardware. Full table of possible variations: ``` original MSAA sample count stored loaded * 00000000000000000000000000000000 -> 000 -> 00000001 1 00000000000000000000000000000001 -> 000 -> 00000001 1 00000000000000000000000000000010 -> 001 -> 00000010 2 00000000000000000000000000000100 -> 010 -> 00000100 4 00000000000000000000000000001000 -> 011 -> 00001000 8 00000000000000000000000000010000 -> 100 -> 00010000 16 00000000000000000000000000100000 -> 101 -> 00100000 32 00000000000000000000000001000000 -> 110 -> 01000000 64 00000000000000000000000010000000 -> 111 -> 10000000 128 * 00000000000000000000000100000000 -> 000 -> 00000001 256 * 00000000000000000000001000000000 -> 001 -> 00000010 512 * 00000000000000000000010000000000 -> 010 -> 00000100 1024 * 00000000000000000000100000000000 -> 011 -> 00001000 2048 * 00000000000000000001000000000000 -> 100 -> 00010000 4096 * 00000000000000000010000000000000 -> 101 -> 00100000 8192 * 00000000000000000100000000000000 -> 110 -> 01000000 16384 * 00000000000000001000000000000000 -> 111 -> 10000000 32768 * 00000000000000010000000000000000 -> 000 -> 00000001 65536 * 00000000000000100000000000000000 -> 001 -> 00000010 131072 * 00000000000001000000000000000000 -> 010 -> 00000100 262144 * 00000000000010000000000000000000 -> 011 -> 00001000 524288 * 00000000000100000000000000000000 -> 100 -> 00010000 1048576 * 00000000001000000000000000000000 -> 101 -> 00100000 2097152 * 00000000010000000000000000000000 -> 110 -> 01000000 4194304 * 00000000100000000000000000000000 -> 111 -> 10000000 8388608 * 00000001000000000000000000000000 -> 000 -> 00000001 16777216 * 00000010000000000000000000000000 -> 001 -> 00000010 33554432 * 00000100000000000000000000000000 -> 010 -> 00000100 67108864 * 00001000000000000000000000000000 -> 011 -> 00001000 134217728 * 00010000000000000000000000000000 -> 100 -> 00010000 268435456 * 00100000000000000000000000000000 -> 101 -> 00100000 536870912 * 01000000000000000000000000000000 -> 110 -> 01000000 1073741824 * 10000000000000000000000000000000 -> 111 -> 10000000 2147483648 ```
Pull request successfully merged into main. Build succeeded: |
Sample count always power of two. Thus, it is enough to store `log2(sample_count)`. This can be implemented using [u32::trailing_zeros](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.trailing_zeros). Then we can restore sample count with the `1 << stored`. You get 3 bits instead of 6 and up to 128x MSAA. This is more than is supported by any common hardware. Full table of possible variations: ``` original MSAA sample count stored loaded * 00000000000000000000000000000000 -> 000 -> 00000001 1 00000000000000000000000000000001 -> 000 -> 00000001 1 00000000000000000000000000000010 -> 001 -> 00000010 2 00000000000000000000000000000100 -> 010 -> 00000100 4 00000000000000000000000000001000 -> 011 -> 00001000 8 00000000000000000000000000010000 -> 100 -> 00010000 16 00000000000000000000000000100000 -> 101 -> 00100000 32 00000000000000000000000001000000 -> 110 -> 01000000 64 00000000000000000000000010000000 -> 111 -> 10000000 128 * 00000000000000000000000100000000 -> 000 -> 00000001 256 * 00000000000000000000001000000000 -> 001 -> 00000010 512 * 00000000000000000000010000000000 -> 010 -> 00000100 1024 * 00000000000000000000100000000000 -> 011 -> 00001000 2048 * 00000000000000000001000000000000 -> 100 -> 00010000 4096 * 00000000000000000010000000000000 -> 101 -> 00100000 8192 * 00000000000000000100000000000000 -> 110 -> 01000000 16384 * 00000000000000001000000000000000 -> 111 -> 10000000 32768 * 00000000000000010000000000000000 -> 000 -> 00000001 65536 * 00000000000000100000000000000000 -> 001 -> 00000010 131072 * 00000000000001000000000000000000 -> 010 -> 00000100 262144 * 00000000000010000000000000000000 -> 011 -> 00001000 524288 * 00000000000100000000000000000000 -> 100 -> 00010000 1048576 * 00000000001000000000000000000000 -> 101 -> 00100000 2097152 * 00000000010000000000000000000000 -> 110 -> 01000000 4194304 * 00000000100000000000000000000000 -> 111 -> 10000000 8388608 * 00000001000000000000000000000000 -> 000 -> 00000001 16777216 * 00000010000000000000000000000000 -> 001 -> 00000010 33554432 * 00000100000000000000000000000000 -> 010 -> 00000100 67108864 * 00001000000000000000000000000000 -> 011 -> 00001000 134217728 * 00010000000000000000000000000000 -> 100 -> 00010000 268435456 * 00100000000000000000000000000000 -> 101 -> 00100000 536870912 * 01000000000000000000000000000000 -> 110 -> 01000000 1073741824 * 10000000000000000000000000000000 -> 111 -> 10000000 2147483648 ```
Sample count always power of two. Thus, it is enough to store `log2(sample_count)`. This can be implemented using [u32::trailing_zeros](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.trailing_zeros). Then we can restore sample count with the `1 << stored`. You get 3 bits instead of 6 and up to 128x MSAA. This is more than is supported by any common hardware. Full table of possible variations: ``` original MSAA sample count stored loaded * 00000000000000000000000000000000 -> 000 -> 00000001 1 00000000000000000000000000000001 -> 000 -> 00000001 1 00000000000000000000000000000010 -> 001 -> 00000010 2 00000000000000000000000000000100 -> 010 -> 00000100 4 00000000000000000000000000001000 -> 011 -> 00001000 8 00000000000000000000000000010000 -> 100 -> 00010000 16 00000000000000000000000000100000 -> 101 -> 00100000 32 00000000000000000000000001000000 -> 110 -> 01000000 64 00000000000000000000000010000000 -> 111 -> 10000000 128 * 00000000000000000000000100000000 -> 000 -> 00000001 256 * 00000000000000000000001000000000 -> 001 -> 00000010 512 * 00000000000000000000010000000000 -> 010 -> 00000100 1024 * 00000000000000000000100000000000 -> 011 -> 00001000 2048 * 00000000000000000001000000000000 -> 100 -> 00010000 4096 * 00000000000000000010000000000000 -> 101 -> 00100000 8192 * 00000000000000000100000000000000 -> 110 -> 01000000 16384 * 00000000000000001000000000000000 -> 111 -> 10000000 32768 * 00000000000000010000000000000000 -> 000 -> 00000001 65536 * 00000000000000100000000000000000 -> 001 -> 00000010 131072 * 00000000000001000000000000000000 -> 010 -> 00000100 262144 * 00000000000010000000000000000000 -> 011 -> 00001000 524288 * 00000000000100000000000000000000 -> 100 -> 00010000 1048576 * 00000000001000000000000000000000 -> 101 -> 00100000 2097152 * 00000000010000000000000000000000 -> 110 -> 01000000 4194304 * 00000000100000000000000000000000 -> 111 -> 10000000 8388608 * 00000001000000000000000000000000 -> 000 -> 00000001 16777216 * 00000010000000000000000000000000 -> 001 -> 00000010 33554432 * 00000100000000000000000000000000 -> 010 -> 00000100 67108864 * 00001000000000000000000000000000 -> 011 -> 00001000 134217728 * 00010000000000000000000000000000 -> 100 -> 00010000 268435456 * 00100000000000000000000000000000 -> 101 -> 00100000 536870912 * 01000000000000000000000000000000 -> 110 -> 01000000 1073741824 * 10000000000000000000000000000000 -> 111 -> 10000000 2147483648 ```
Sample count always power of two. Thus, it is enough to store
log2(sample_count)
.This can be implemented using u32::trailing_zeros. Then we can restore sample count with the
1 << stored
.You get 3 bits instead of 6 and up to 128x MSAA. This is more than is supported by any common hardware.
Full table of possible variations: