Description
When using a uniform Int in a shader, the uniform gets packed into the vec4 array which doesn't have any specified precision, thus depending on the precision for the current program. By default however, the fragment stage is set to mediump, and on some devices this can lead to lower precision floats, and when floatBitsToInt is subsequently used to extract the ints, it will seemingly fail to do so, presumable due to the encoding differences.
The issue can be worked around by replacing all instances of Int with Float, however, this still leaves Int being unpredictable in the fragment stage, so a more proper solution should probably be applied.
Example
class IntCheckShader extends hxsl.Shader {
static var SRC = {
@param var myInt:Int;
var vertCheck:Float;
var pixelColor:Vec4;
// highp
function vertex() {
vertCheck = myInt == 45 ? 1.0 : 0.0;
}
// mediump
function fragment() {
var fragCheck = myInt == 45 ? 1.0 : 0.0;
pixelColor = vec4(vertCheck, fragCheck, 0.0, 1.0);
}
}
public function new() {
super();
myInt = 45;
}
}
Expected
The shader should output yellow, both int checks being true.
Observed
Output is red when using specific devices, like the Google Pixel 7 Pro, Google Pixel 8 or Google Pixeel 9 Pro, for example.
Description
When using a uniform Int in a shader, the uniform gets packed into the vec4 array which doesn't have any specified precision, thus depending on the precision for the current program. By default however, the fragment stage is set to
mediump, and on some devices this can lead to lower precision floats, and whenfloatBitsToIntis subsequently used to extract the ints, it will seemingly fail to do so, presumable due to the encoding differences.The issue can be worked around by replacing all instances of
IntwithFloat, however, this still leavesIntbeing unpredictable in thefragmentstage, so a more proper solution should probably be applied.Example
Expected
The shader should output yellow, both int checks being true.
Observed
Output is red when using specific devices, like the Google Pixel 7 Pro, Google Pixel 8 or Google Pixeel 9 Pro, for example.