In an attempt to pass on more devices without lowering the tolerances
so low they are meaningless, we ask the hardware to tell us, for a given
gradient, level, what mix weights are being used.
This is done by drawing instanced quads and using instance_index to
write out results into an array. We sample a 2x2 pixel texture with
2 mip levels and set the 2nd mip level to white. This means the value
we get back represents the weight used to mix the 2 mip levels.
Just as a record of some differences across GPUs
level weights: mapping from the mip level
parameter of textureSampleLevel to
the mix weight used by the GPU
In an attempt to pass on more devices without lowering the tolerances so low they are meaningless, we ask the hardware to tell us, for a given gradient, level, what mix weights are being used.
This is done by drawing instanced quads and using instance_index to write out results into an array. We sample a 2x2 pixel texture with 2 mip levels and set the 2nd mip level to white. This means the value we get back represents the weight used to mix the 2 mip levels.
Just as a record of some differences across GPUs
level weights: mapping from the mip level parameter of
textureSampleLevel
to the mix weight used by the GPU+--------+--------+--------+--------+ | | | intel | amd | | | m1 | gen-9 | rna-1 | | level | mac | mac | mac | +--------+--------+--------+--------+ | 0.0000 | 0.0000 | 0.0000 | 0.0000 | | 0.0313 | 0.0314 | 0.0313 | 0.0000 | | 0.0625 | 0.0625 | 0.0625 | 0.0000 | | 0.0938 | 0.0939 | 0.0938 | 0.0000 | | 0.1250 | 0.1250 | 0.1250 | 0.0313 | | 0.1563 | 0.1564 | 0.1563 | 0.0703 | | 0.1875 | 0.1875 | 0.1875 | 0.1094 | | 0.2188 | 0.2189 | 0.2188 | 0.1484 | | 0.2500 | 0.2500 | 0.2500 | 0.1875 | | 0.2813 | 0.2814 | 0.2813 | 0.2266 | | 0.3125 | 0.3125 | 0.3125 | 0.2656 | | 0.3438 | 0.3439 | 0.3438 | 0.3047 | | 0.3750 | 0.3750 | 0.3750 | 0.3438 | | 0.4063 | 0.4064 | 0.4063 | 0.3828 | | 0.4375 | 0.4375 | 0.4375 | 0.4219 | | 0.4688 | 0.4689 | 0.4688 | 0.4609 | | 0.5000 | 0.5000 | 0.5000 | 0.5000 | | 0.5313 | 0.5314 | 0.5313 | 0.5391 | | 0.5625 | 0.5625 | 0.5625 | 0.5781 | | 0.5938 | 0.5939 | 0.5938 | 0.6172 | | 0.6250 | 0.6250 | 0.6250 | 0.6563 | | 0.6563 | 0.6564 | 0.6563 | 0.6953 | | 0.6875 | 0.6875 | 0.6875 | 0.7344 | | 0.7188 | 0.7189 | 0.7188 | 0.7734 | | 0.7500 | 0.7500 | 0.7500 | 0.8125 | | 0.7813 | 0.7814 | 0.7813 | 0.8516 | | 0.8125 | 0.8125 | 0.8125 | 0.8906 | | 0.8438 | 0.8439 | 0.8438 | 0.9297 | | 0.8750 | 0.8750 | 0.8750 | 0.9688 | | 0.9063 | 0.9064 | 0.9063 | 1.0000 | | 0.9375 | 0.9375 | 0.9375 | 1.0000 | | 0.9688 | 0.9689 | 0.9688 | 1.0000 | | 1.0000 | 1.0000 | 1.0000 | 1.0000 | +--------+--------+--------+--------+
grad weights: mapping from ddx value passed into
textureSampleGrad
to the mix weight used by the GPU+--------+--------+--------+--------+ | | | intel | amd | | | m1 | gen-9 | rna-1 | | ddx | mac | mac | mac | +--------+--------+--------+--------+ | 0.5000 | 0.0000 | 0.0000 | 0.0000 | | 0.5109 | 0.0390 | 0.0430 | 0.0000 | | 0.5221 | 0.0821 | 0.0859 | 0.0000 | | 0.5336 | 0.1211 | 0.1289 | 0.0352 | | 0.5453 | 0.1600 | 0.1719 | 0.0898 | | 0.5572 | 0.2032 | 0.2109 | 0.1328 | | 0.5694 | 0.2422 | 0.2461 | 0.1797 | | 0.5819 | 0.2814 | 0.2852 | 0.2305 | | 0.5946 | 0.3203 | 0.3203 | 0.2773 | | 0.6076 | 0.3554 | 0.3594 | 0.3164 | | 0.6209 | 0.3868 | 0.3906 | 0.3633 | | 0.6345 | 0.4218 | 0.4258 | 0.4063 | | 0.6484 | 0.4532 | 0.4609 | 0.4492 | | 0.6626 | 0.4882 | 0.4922 | 0.4883 | | 0.6771 | 0.5196 | 0.5234 | 0.5273 | | 0.6920 | 0.5507 | 0.5547 | 0.5664 | | 0.7071 | 0.5860 | 0.5859 | 0.6055 | | 0.7226 | 0.6132 | 0.6133 | 0.6406 | | 0.7384 | 0.6407 | 0.6445 | 0.6797 | | 0.7546 | 0.6679 | 0.6719 | 0.7148 | | 0.7711 | 0.6953 | 0.6992 | 0.7461 | | 0.7880 | 0.7225 | 0.7266 | 0.7813 | | 0.8052 | 0.7500 | 0.7539 | 0.8164 | | 0.8229 | 0.7814 | 0.7813 | 0.8516 | | 0.8409 | 0.8086 | 0.8086 | 0.8828 | | 0.8593 | 0.8321 | 0.8320 | 0.9141 | | 0.8781 | 0.8554 | 0.8594 | 0.9492 | | 0.8974 | 0.8789 | 0.8828 | 0.9766 | | 0.9170 | 0.9025 | 0.9063 | 1.0000 | | 0.9371 | 0.9297 | 0.9297 | 1.0000 | | 0.9576 | 0.9532 | 0.9531 | 1.0000 | | 0.9786 | 0.9765 | 0.9766 | 1.0000 | | 1.0000 | 1.0000 | 1.0000 | 1.0000 | +--------+--------+--------+--------+