AMD: textureOffset flickering and texelFetch crash

Hi

Will using textureOffset, I notice some obvious artefacts on AMD 11.1.

On AMD: http://img820.imageshack.us/i/amds.png
On nVidia: http://img138.imageshack.us/i/nvidiak.png

The shader is pretty simple:

void main()
{
	vec4 Texel00 = textureOffset(Diffuse, Vert.Texcoord, ivec2(-1,-1));
	vec4 Texel10 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 0,-1));
	vec4 Texel20 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 1,-1));
	vec4 Texel30 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 2,-1));

	vec4 Texel01 = textureOffset(Diffuse, Vert.Texcoord, ivec2(-1, 0));
	vec4 Texel11 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 0, 0));
	vec4 Texel21 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 1, 0));
	vec4 Texel31 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 2, 0));

	vec4 Texel02 = textureOffset(Diffuse, Vert.Texcoord, ivec2(-1, 1));
	vec4 Texel12 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 0, 1));
	vec4 Texel22 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 1, 1));
	vec4 Texel32 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 2, 1));

	vec4 Texel03 = textureOffset(Diffuse, Vert.Texcoord, ivec2(-1, 2));
	vec4 Texel13 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 0, 2));
	vec4 Texel23 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 1, 2));
	vec4 Texel33 = textureOffset(Diffuse, Vert.Texcoord, ivec2( 2, 2));

	vec2 TexelCoord = Vert.Texcoord * textureSize(Diffuse, 0);
	vec2 SplineCoord = fract(TexelCoord);

	vec4 Row0 = hermite(Texel00, Texel10, Texel20, Texel30, SplineCoord.x);
	vec4 Row1 = hermite(Texel01, Texel11, Texel21, Texel31, SplineCoord.x);
	vec4 Row2 = hermite(Texel02, Texel12, Texel22, Texel32, SplineCoord.x);
	vec4 Row3 = hermite(Texel03, Texel13, Texel23, Texel33, SplineCoord.x);

	FragColor = hermite(Row0, Row1, Row2, Row3, SplineCoord.y);
}

I replaced textureOffset by an alternative based on texelFetch but glCompileShader just crash… The code:


void main()
{
	ivec2 TextureSize = textureSize(Diffuse, 0);
	ivec2 TexelCoord = TextureSize * Vert.Texcoord;

	vec4 Texel00 = texelOffset(Diffuse, TexelCoord, ivec2(-1,-1));
	vec4 Texel10 = texelOffset(Diffuse, TexelCoord, ivec2( 0,-1));
	vec4 Texel20 = texelOffset(Diffuse, TexelCoord, ivec2( 1,-1));
	vec4 Texel30 = texelOffset(Diffuse, TexelCoord, ivec2( 2,-1));

	vec4 Texel01 = texelOffset(Diffuse, TexelCoord, ivec2(-1, 0));
	vec4 Texel11 = texelOffset(Diffuse, TexelCoord, ivec2( 0, 0));
	vec4 Texel21 = texelOffset(Diffuse, TexelCoord, ivec2( 1, 0));
	vec4 Texel31 = texelOffset(Diffuse, TexelCoord, ivec2( 2, 0));

	vec4 Texel02 = texelOffset(Diffuse, TexelCoord, ivec2(-1, 1));
	vec4 Texel12 = texelOffset(Diffuse, TexelCoord, ivec2( 0, 1));
	vec4 Texel22 = texelOffset(Diffuse, TexelCoord, ivec2( 1, 1));
	vec4 Texel32 = texelOffset(Diffuse, TexelCoord, ivec2( 2, 1));

	vec4 Texel03 = texelOffset(Diffuse, TexelCoord, ivec2(-1, 2));
	vec4 Texel13 = texelOffset(Diffuse, TexelCoord, ivec2( 0, 2));
	vec4 Texel23 = texelOffset(Diffuse, TexelCoord, ivec2( 1, 2));
	vec4 Texel33 = texelOffset(Diffuse, TexelCoord, ivec2( 2, 2));

	vec2 SplineCoord = fract(TextureSize * Vert.Texcoord);

	vec4 Row0 = hermite(Texel00, Texel10, Texel20, Texel30, SplineCoord.x);
	vec4 Row1 = hermite(Texel01, Texel11, Texel21, Texel31, SplineCoord.x);
	vec4 Row2 = hermite(Texel02, Texel12, Texel22, Texel32, SplineCoord.x);
	vec4 Row3 = hermite(Texel03, Texel13, Texel23, Texel33, SplineCoord.x);

	FragColor = hermite(Row0, Row1, Row2, Row3, SplineCoord.y);
}

PS: Yes this code is not correct but the build should not crash the software anyway and just report the errors.

:frowning:

Could you please help to paste out the whole shader for me to reproduce the crash? I can’t get it by replacing the textureOffset as you said.

I guess the type of Vert.Texcoord is declared as “ivec2”. Could you please change it to “vec2” according to the spec to double check the result? Thanks.

#version 410 core

precision highp int;

// Declare all the semantics
#define ATTR_POSITION	0
#define ATTR_COLOR		3
#define ATTR_TEXCOORD	4
#define FRAG_COLOR		0

uniform sampler2D Diffuse;

in vert
{
	vec2 Texcoord;
} Vert;

layout(location = FRAG_COLOR, index = 0) out vec4 FragColor;

vec4 catmullRom(in vec4 A, in vec4 B, in vec4 C, in vec4 D, in float s)
{
	mat4 CatmullRom = mat4(
		vec4(-1, 2,-1, 0), 
		vec4( 3,-5, 0, 2),
		vec4(-3, 4, 1, 0),
		vec4( 1,-1, 0, 0));

	vec4 Expo = vec4(s * s * s, s * s, s, 1);

	return 0.5 * Expo * CatmullRom * mat4(
		A[0], B[0], C[0], D[0],
		A[1], B[1], C[1], D[1],
		A[2], B[2], C[2], D[2],
		A[3], B[3], C[3], D[3]);
}

vec4 textureCatmullrom(in sampler2D Sampler, in vec2 Texcoord)
{
	ivec2 TextureSize = textureSize(Sampler, 0) - ivec2(1);
	ivec2 TexelCoord = ivec2(TextureSize * Texcoord);

// Remove the 0 and it won't crash
	vec4 Texel00 = textureOffset(Sampler, Texcoord, 0, ivec2(-1,-1));
	vec4 Texel10 = textureOffset(Sampler, Texcoord, ivec2( 0,-1));
	vec4 Texel20 = textureOffset(Sampler, Texcoord, ivec2( 1,-1));
	vec4 Texel30 = textureOffset(Sampler, Texcoord, ivec2( 2,-1));

	vec4 Texel01 = textureOffset(Sampler, Texcoord, ivec2(-1, 0));
	vec4 Texel11 = textureOffset(Sampler, Texcoord, ivec2( 0, 0));
	vec4 Texel21 = textureOffset(Sampler, Texcoord, ivec2( 1, 0));
	vec4 Texel31 = textureOffset(Sampler, Texcoord, ivec2( 2, 0));

	vec4 Texel02 = textureOffset(Sampler, Texcoord, ivec2(-1, 1));
	vec4 Texel12 = textureOffset(Sampler, Texcoord, ivec2( 0, 1));
	vec4 Texel22 = textureOffset(Sampler, Texcoord, ivec2( 1, 1));
	vec4 Texel32 = textureOffset(Sampler, Texcoord, ivec2( 2, 1));

	vec4 Texel03 = textureOffset(Sampler, Texcoord, ivec2(-1, 2));
	vec4 Texel13 = textureOffset(Sampler, Texcoord, ivec2( 0, 2));
	vec4 Texel23 = textureOffset(Sampler, Texcoord, ivec2( 1, 2));
	vec4 Texel33 = textureOffset(Sampler, Texcoord, ivec2( 2, 2));

	vec2 SplineCoord = fract(TextureSize * Texcoord);

	vec4 Row0 = catmullRom(Texel00, Texel10, Texel20, Texel30, SplineCoord.x);
	vec4 Row1 = catmullRom(Texel01, Texel11, Texel21, Texel31, SplineCoord.x);
	vec4 Row2 = catmullRom(Texel02, Texel12, Texel22, Texel32, SplineCoord.x);
	vec4 Row3 = catmullRom(Texel03, Texel13, Texel23, Texel33, SplineCoord.x);

	return catmullRom(Row0, Row1, Row2, Row3, SplineCoord.y);
}

void main()
{
	FragColor = textureCatmullrom(Diffuse, Vert.Texcoord);
}

Vert.Texcoord was a vec2.
Again, I am not saying that this code is valid, just that the compiler should not crash and simply return a build error.

Thanks

I get the error message without any crash.
ERROR: 0:43: [parser] error(#202) No matching overloaded function found textureOffset
ERROR: 0:43: [parser] error(#160) Cannot convert from ‘const float’ to ‘highp 4-component vector of float’

There may be two reasons for your crash.

  1. You use an old driver that may have bugs in compiling the shaders.
  2. The crash may come from the interface block matching.

I am not sure if the bug it 100% reproducible but if you increase the number of errors, the crash happen all the time:

#version 330 core

precision highp int;

// Declare all the semantics
#define ATTR_POSITION	0
#define ATTR_COLOR		3
#define ATTR_TEXCOORD	4
#define FRAG_COLOR		0

uniform sampler2D Diffuse;
uniform ivec2 Offset;

in vert
{
	vec2 Texcoord;
} Vert;

layout(location = FRAG_COLOR, index = 0) out vec4 FragColor;

vec4 catmullRom(in vec4 A, in vec4 B, in vec4 C, in vec4 D, in float s)
{
	mat4 CatmullRom = mat4(
		vec4(-1, 2,-1, 0), 
		vec4( 3,-5, 0, 2),
		vec4(-3, 4, 1, 0),
		vec4( 1,-1, 0, 0));

	vec4 Expo = vec4(s * s * s, s * s, s, 1);

	return 0.5 * Expo * CatmullRom * mat4(
		A[0], B[0], C[0], D[0],
		A[1], B[1], C[1], D[1],
		A[2], B[2], C[2], D[2],
		A[3], B[3], C[3], D[3]);
}

vec4 textureCatmullrom(in sampler2D Sampler, in vec2 Texcoord, in vec2 Offset)
{
	vec4 Texel00 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2(-1,-1));
	vec4 Texel10 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2( 0,-1));
	vec4 Texel20 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2( 1,-1));
	vec4 Texel30 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2( 2,-1));

	vec4 Texel01 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2(-1, 0));
	vec4 Texel11 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2( 0, 0));
	vec4 Texel21 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2( 1, 0));
	vec4 Texel31 = textureOffset(Sampler, Texcoord + Offset, 0, ivec2( 2, 0));

	vec4 Texel02 = textureOffset(Sampler, Texcoord + Offset, ivec2(-1, 1));
	vec4 Texel12 = textureOffset(Sampler, Texcoord + Offset, ivec2( 0, 1));
	vec4 Texel22 = textureOffset(Sampler, Texcoord + Offset, ivec2( 1, 1));
	vec4 Texel32 = textureOffset(Sampler, Texcoord + Offset, ivec2( 2, 1));

	vec4 Texel03 = textureOffset(Sampler, Texcoord + Offset, ivec2(-1, 2));
	vec4 Texel13 = textureOffset(Sampler, Texcoord + Offset, ivec2( 0, 2));
	vec4 Texel23 = textureOffset(Sampler, Texcoord + Offset, ivec2( 1, 2));
	vec4 Texel33 = textureOffset(Sampler, Texcoord + Offset, ivec2( 2, 2));

	vec2 SplineCoord = fract(textureSize(Sampler, 0) * Texcoord);

	vec4 Row0 = catmullRom(Texel00, Texel10, Texel20, Texel30, SplineCoord.x);
	vec4 Row1 = catmullRom(Texel01, Texel11, Texel21, Texel31, SplineCoord.x);
	vec4 Row2 = catmullRom(Texel02, Texel12, Texel22, Texel32, SplineCoord.x);
	vec4 Row3 = catmullRom(Texel03, Texel13, Texel23, Texel33, SplineCoord.x);

	return catmullRom(Row0, Row1, Row2, Row3, SplineCoord.y);
}

void main()
{
	ivec2 TextureSize = textureSize(Diffuse, 0);

	FragColor = textureCatmullrom(Diffuse, Vert.Texcoord, vec2(Offset) / vec2(TextureSize));
}


Indeed, I am running Catalyst 11.2.
I just reproduced the crash on Seven 32 + 5450 platform.

EDIT: There is also the flickering issue in this report.
You can see this issue in the sample ogl-330-texture-offset in the OpenGL Samples Pack 4.1.5.0 (http://www.g-truc.net/post-0382.html#menu)

I can’t get the crash by using Cat11.2. That’s rather strange.
Below are the errors by running the texture-offset case in the new g-truc package,
[b]Fragment shader failed to compile with the following errors:
ERROR: 0:44: error(#202) No matching overloaded function found textureOffset
ERROR: 0:44: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:45: error(#202) No matching overloaded function found textureOffset
ERROR: 0:45: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:46: error(#202) No matching overloaded function found textureOffset
ERROR: 0:46: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:47: error(#202) No matching overloaded function found textureOffset
ERROR: 0:47: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:49: error(#202) No matching overloaded function found textureOffset
ERROR: 0:49: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:50: error(#202) No matching overloaded function found textureOffset
ERROR: 0:50: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:51: error(#202) No matching overloaded function found textureOffset
ERROR: 0:51: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: 0:52: error(#202) No matching overloaded function found textureOffset
ERROR: 0:52: error(#160) Cannot convert from ‘const float’ to ‘highp 4-component
vector of float’
ERROR: error(#273) 16 compilation errors. No code generated

Linking program
Fragment shader(s) were not successfully compiled before glLinkProgram() was cal
led. Link failed.[/b]

How can I get the flickering issue? Just run the project without any other operations? I could see two pictures are generated without any problem.

Surprising, I reproduced the bug on 2 differents platform, 32 and 64 bits.

For the “flicking” issue you need to rotate the view with the right click.

Thanks!

I have a similar quite of error that make me think that the GLSL compiler crash when trying to cast or to find the appropriate overloaded function:

Incorrect code that crash the GLSL compiler:

vec4 Texel00 = texelFetch(Sampler, clamp(Texelcoord + ivec2(0, 0), 0, Size), Lod);
vec4 Texel10 = texelFetch(Sampler, clamp(Texelcoord + ivec2(1, 0), 0, Size), Lod);
vec4 Texel11 = texelFetch(Sampler, clamp(Texelcoord + ivec2(1, 1), 0, Size), Lod);
vec4 Texel01 = texelFetch(Sampler, clamp(Texelcoord + ivec2(0, 1), 0, Size), Lod);

Correct code:


vec4 Texel00 = texelFetch(Sampler, clamp(Texelcoord + ivec2(0, 0), ivec2(0), Size), Lod);
vec4 Texel10 = texelFetch(Sampler, clamp(Texelcoord + ivec2(1, 0), ivec2(0), Size), Lod);
vec4 Texel11 = texelFetch(Sampler, clamp(Texelcoord + ivec2(1, 1), ivec2(0), Size), Lod);
vec4 Texel01 = texelFetch(Sampler, clamp(Texelcoord + ivec2(0, 1), ivec2(0), Size), Lod);

There must be some special settings in your sample since I can’t reproduce the crash. If possible, could you please narrow down your project and send it to me for investigation? My email address is frank.li@amd.com. Thanks.

I appreciate that you also send me the captured picture for the flicker issue. Thanks again.

Frank

One more crash:

	ivec2 TextureSize = textureSize(Sampler, Lod) - ivec2(1);
	ivec2 TexelCoord = ivec2(TextureSize * Texcoord);

	vec4 Texel00 = texelFetch(Sampler, (TexelCoord + ivec2(-1,-1)) % Size, Lod);
	vec4 Texel10 = texelFetch(Sampler, (TexelCoord + ivec2( 0,-1)) % Size, Lod);

Size is not declared because TextureSize is the wrong name.
I don’t have much time for narrowing down to a code sample right now but maybe later. 2 crash bugs per day is my rate since I started to play with texelFetch. it might be the same but showing up in different ways… :stuck_out_tongue:

Other crash example:

vec4 textureTrilinearLod(
	in sampler2D Sampler, in vec2 Texcoord, in float Lod)
{
	int lodMin = int(floor(Lod));
	int lodMax = int(ceil(Lod));

	vec4 TexelMin = textureBilinearLod(Diffuse, Texcoord, lodMin);
	vec4 TexelMax = textureBilinearLod(Diffuse, Texcoord, lodMax);

	return mix(TexelMin, TexelMax, fract(Lod));
}

Where Diffuse is a undeclared but suppose to be a sampler2D.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.