we have a strange problem. The texture2D call works when used directly, but not when used in a function with a return value.
The device is a Samsung S3, SPH-L710, Android 4.0.4, Adreno 225.
The code we use works on Tegra, PowerVR, Mali, etc. But not on Adrenos.
Code example:
vec4 myTex2D(sampler2D s, vec2 uv) { return texture2D(s, uv); } void ShaderRun() { IShaderNode_SetOutputColor0(myTex2D(s, IShaderNode_GetInputTexcoord0().xy)); } void main(void) { glFragColor = IShaderNode_GetOutputColor0(); }
Nothing special here. The IShaderNode_* functions are accessories of our node-based shader system. This is also the reason why we call this call in a function.
The problem is that this code does not detect errors in the Adreno Profiler shader analyzer and glCompileShader does not return errors either.
But when using this shader, we have a glitch in glLinkProgram :
11-27 09:10:10.599: I/faktum(24249): Check: Clockspeed: 1512 11-27 09:10:10.599: I/faktum(24249): Check: Manufactor: 0 11-27 09:10:10.599: I/faktum(24249): Check: Sys Code To File: 1512 11-27 09:10:10.599: I/faktum(24249): SV: Save: Calculated CRC: 114273795 11-27 09:10:10.599: I/faktum(24249): SV: Save: Size: 7917 11-27 09:10:10.760: I/DEBUG(24198): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 11-27 09:10:10.760: I/DEBUG(24198): Build fingerprint: 'samsung/d2spr/d2spr:4.0.4/IMM76D/L710VPALI3:user/release-keys' 11-27 09:10:10.760: I/DEBUG(24198): pid: 24249, tid: 24279 >>> com.vivamedia.cmGGTHD <<< 11-27 09:10:10.760: I/DEBUG(24198): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000018 11-27 09:10:10.760: I/DEBUG(24198): r0 00000000 r1 00000001 r2 00000000 r3 015f39d8 11-27 09:10:10.760: I/DEBUG(24198): r4 015ed4c0 r5 014c6510 r6 60961e50 r7 015f3528 11-27 09:10:10.760: I/DEBUG(24198): r8 0000000a r9 00000000 10 015f3618 fp 60961e54 11-27 09:10:10.760: I/DEBUG(24198): ip 00000004 sp 60961d98 lr 5d148a2b pc 5d14b0a4 cpsr 08000030 11-27 09:10:10.760: I/DEBUG(24198): d0 0084001200000047 d1 0084000000000055 11-27 09:10:10.760: I/DEBUG(24198): d2 0000004700003210 d3 000000550084000e 11-27 09:10:10.760: I/DEBUG(24198): d4 0000321000840012 d5 0000003200000053 11-27 09:10:10.760: I/DEBUG(24198): d6 0000004700000003 d7 0000005500840013 11-27 09:10:10.760: I/DEBUG(24198): d8 0000000000000000 d9 0000000000000000 11-27 09:10:10.760: I/DEBUG(24198): d10 0000000000000000 d11 0000000000000000 11-27 09:10:10.760: I/DEBUG(24198): d12 0000000000000000 d13 0000000000000000 11-27 09:10:10.760: I/DEBUG(24198): d14 0000000000000000 d15 0000000000000000 11-27 09:10:10.760: I/DEBUG(24198): d16 3feffead00000000 d17 3dbebd9ffead0000 11-27 09:10:10.760: I/DEBUG(24198): d18 3fe0000000000000 d19 3fe000000003d7b4 11-27 09:10:10.760: I/DEBUG(24198): d20 3fa55553e1053a42 d21 3f6941845904b7dd 11-27 09:10:10.760: I/DEBUG(24198): d22 3ff0000000000000 d23 3ef99342e0ee5069 11-27 09:10:10.760: I/DEBUG(24198): d24 3ef99342e0ee5069 d25 3fdbeaaaa0000000 11-27 09:10:10.760: I/DEBUG(24198): d26 4068200000000000 d27 3ef99342e0ee5069 11-27 09:10:10.760: I/DEBUG(24198): d28 c00005c02b53cb8a d29 bf66fdec79316df6 11-27 09:10:10.760: I/DEBUG(24198): d30 bc0a42cc192d5632 d31 be23e4f5df600000 11-27 09:10:10.760: I/DEBUG(24198): scr 60000010 11-27 09:10:11.040: I/DEBUG(24198):
..... etc.
Now for the weird part.
When replacing myTex2D call this way ...
vec4 myTex2D(sampler2D s, vec2 uv) { return texture2D(s, uv); } void ShaderRun() { IShaderNode_SetOutputColor0(texture2D(s, IShaderNode_GetInputTexcoord0().xy)); } void main(void) { glFragColor = IShaderNode_GetOutputColor0(); }
... by directly calling texture2D . He works!
Can someone explain this? We tried various refinements, saved the parameters, etc. Nothing helped.
Is there any special question when using functions with a return value in a shader on an Adreno GPU?
We have no idea what to do here. This seems to be a driver issue.
EDIT November 30, 2012:
We got a workaround using definitions instead of subfunctions for texture-containing functions.