Kode/krafix

[linux + vulkan] using textureSize will create empty shader files

Closed this issue · 7 comments

When i use https://registry.khronos.org/OpenGL-Refpages/gl4/html/textureSize.xhtml in a shader, krafix writes a 0 bytes file but it shows no error.

#version 450

in vec2 f_uv;

uniform sampler2D u_msdf;
uniform vec4 u_background_color;
uniform vec4 u_foreground_color;
uniform float u_px_range;

out vec4 FragColor;

float median( float r, float g, float b ) {
	return max(min(r, g), min(max(r, g), b));
}

float screen_px_range() {
	// vec2 unit_range = vec2(u_px_range) / vec2(textureSize(u_msdf, 0));
        vec2 unit_range = vec2(1.0, 1.0);
	vec2 screen_tex_size = vec2(1.0) / fwidth(f_uv);
	return max(0.5 * dot(unit_range, screen_tex_size), 1.0);
}

void main() {
	vec3 msd = texture(u_msdf, f_uv).rgb;
	float sd = median(msd.r, msd.g, msd.b);
	float screen_px_distance = screen_px_range() * (sd - 0.5);
	float opacity = clamp(screen_px_distance + 0.5, 0.0, 1.0);
	FragColor = mix(u_background_color, u_foreground_color, opacity);
}

I can't reproduce that.

Oooh, it's commented out in your shader, sneaky.

Now I can reproduce it. But I can't reproduce it with


in vec2 texcoord;

out vec4 FragColor;

uniform sampler2D texsampler;

void main() {
	vec4 color = texture(texsampler, texcoord);
	FragColor = vec4(color.r, color.g, color.b * textureSize(texsampler, 0).x, 1.0);
}

So it might not actually be about textureSize.

Indeed, found an easier way. This will fail, but works when you change a to a vec2.

#version 450

in vec2 texcoord;

out vec4 FragColor;

uniform sampler2D texsampler;
uniform vec2 a; // works when this is vec2
uniform float b;

void main() {
	float foo = b;
	vec4 color = texture(texsampler, texcoord);
	FragColor = vec4(color.r, color.g, color.b * textureSize(texsampler, 0).x, 1.0);
}

But but but a is already a vec2.

Sorry, copied the wrong shader, make it a vec3 and it fails.

It was indeed completely unrelated to textureSize. Even unrelated to textures overall. It was about uniform alignment and by removing that one line you allowed the compiler to remove a uniform and thereby the problem.