-
Notifications
You must be signed in to change notification settings - Fork 329
Description
GLSL has integer builtin functions bitfieldExtract and bitfieldInsert
genIType bitfieldExtract (genIType value,
int offset, int bits)
genUType bitfieldExtract (genUType value,
int offset, int bits)Extracts bits [offset, offset + bits - 1] from value,
returning them in the least significant bits of the result.
For unsigned data types, the most significant bits of the
result will be set to zero. For signed data types, the
most significant bits will be set to the value of bit offset + bits – 1.If bits is zero, the result will be zero. The result will be
undefined if offset or bits is negative, or if the sum of
offset and bits is greater than the number of bits used
to store the operand.
genIType bitfieldInsert (genIType base, genIType insert, int offset, int bits)
genUType bitfieldInsert (genUType base, genUType insert, int offset, int bits)Returns the insertion of the bits least-significant bits of
insert into base.
The result will have bits [offset, offset + bits - 1] taken
from bits [0, bits – 1] of insert, and all other bits taken
directly from the corresponding bits of base. If bits is
zero, the result will simply be base. The result will be
undefined if offset or bits is negative, or if the sum of
offset and bits is greater than the number of bits used to
store the operand.
I propose we avoid the undefined cases by clamping both offset and offset+bits-1 to [0,31]
This is low cost.