Skip to content

Hxsl uniform Ints in fragment stage are always 0 on some devices #1353

Description

@Nestorboy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions