   cg and dependent texture reads
  The following program gives me an error that it uses 4th - 11th order dependent texture reads.I don't get it.I have a loop which performs a single 2nd order dependent texture read each time, and adds to an accumulator.How can I fix this?-------------------FPO motionBlurDisplay_fp(VPO2 IN,    uniform sampler2D sceneTex : TEXUNIT0,   uniform sampler2D velocityMap : TEXUNIT1){FPO OUT;half2 vel = h2tex2D(velocityMap,IN.uv1).xy;const float samples = NUM_SAMPLES;const float step = 1.0 / samples;fixed4 acc = 0;float4 tmp;float i;for(i = 0; i < NUM_SAMPLES; i+=1){float t = i / (samples-1);tmp = acc + x4tex2D(sceneTex, IN.uv0 + vel*t) * step;acc = tmp;}OUT.col = acc; //pColor;return OUT;}   
  Hi,it seems that the number of dependent texture reads are limited to 4 or 5, I don't remember. From what I know there is no way of pushing out this limit.I had the same problem when wanted to implement some filtering on my shadow map implementation, and wasn't able to solve it ;(   ;  ATI cards has a limit of 4 dependent reads. NVIDIA has no limit iirc.   ;  I guess one thing you could do would be to compile your shader using HLSL, and then translate the assembly output to GL by hand.  Since HLSL will unroll and reorder the shader to minimize dependent reads.Here is your shader compiled with NUM_SAMPLES = 16Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000Copyright (C) Microsoft Corporation 2002-2003. All rights reserved.//// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000////   fxc test.fx -T ps_2_0////// Parameters:////   sampler2D $sceneTex;//   sampler2D $velocityMap;////// Registers:////   Name    Reg   Size//   ------------ ----- ----//   $sceneTex    s0  1//   $velocityMap s1  1//    ps_2_0    def c0, 0.0666666701, 0.0625, 0.13333334, 0.200000003    def c1, 0.266666681, 0.333333343, 0.400000006, 0.466666669    def c2, 0.533333361, 0.600000024, 0.666666687, 0.733333349    def c3, 0.800000012, 0.866666675, 0.933333337, 0    dcl t0.xy    dcl t1.xy    dcl_2d s0    dcl_2d s1    texld_pp r0, t1, s1    mad r10.xy, r0, c0.x, t0    mad r8.xy, r0, c0.z, t0    mad r7.xy, r0, c0.w, t0    mad r6.xy, r0, c1.x, t0    mad r5.xy, r0, c1.y, t0    mad r4.xy, r0, c1.z, t0    mad r3.xy, r0, c1.w, t0    mad r2.xy, r0, c2.x, t0    mad r1.xy, r0, c2.y, t0    texld r9, t0, s0    texld r10, r10, s0    texld r8, r8, s0    texld r7, r7, s0    texld r6, r6, s0    texld r5, r5, s0    texld r4, r4, s0    texld r3, r3, s0    texld r2, r2, s0    texld r1, r1, s0    mul r10, r10, c0.y    mad r9, r9, c0.y, r10    mad r8, r8, c0.y, r9    mad r7, r7, c0.y, r8    mad r6, r6, c0.y, r7    mad r5, r5, c0.y, r6    mad r4, r4, c0.y, r5    mad r3, r3, c0.y, r4    mad r2, r2, c0.y, r3    mad r6, r1, c0.y, r2    mad r5.xy, r0, c2.z, t0    mad r4.xy, r0, c2.w, t0    mad r3.xy, r0, c3.x, t0    mad r2.xy, r0, c3.y, t0    mad r1.xy, r0, c3.z, t0    add r0.xy, r0, t0    texld r5, r5, s0    texld r4, r4, s0    texld r3, r3, s0    texld r2, r2, s0    texld r1, r1, s0    texld r0, r0, s0    mad r5, r5, c0.y, r6    mad r4, r4, c0.y, r5    mad r3, r3, c0.y, r4    mad r2, r2, c0.y, r3    mad r1, r1, c0.y, r2    mad r0, r0, c0.y, r1    mov oC0, r0// approximately 49 instruction slots used (17 texture, 32 arithmetic);  It turns out that it worked fine when I updated the cg.dll to the latest (1.4rc1).Although I could only get 11 samples.Maybe I should try to find a better card to continue experimenting with this...   ;Quote:Original post by SunrayATI cards has a limit of 4 dependent reads. NVIDIA has no limit iirc.You mean 4th order dependent texture reads, right?The number of reads must be much higher since it's possible to implement various 12-tap gaussian filters etc.Anyway, the problem was that it for some reasons structured the asm so that the reads inside the loop looked like they depended on each other when they really didn't.   ;  Hi,a little question, why do you exactly mean with 4th order dependent reads? Does 2nd order means, that the second texture read is dependant from the result of the first one ?For about 6 month, I've written a TSM (shadow map) shader which works. Then I wanted to add some filtering by mutlisampling the shadow maps, and it cames out that the shader wasn't able to be loaded on my ATI 9600 card when the shader requested more than 3 textures reads on the shadow map.The shader was (sorry for the long post):struct VertexInput{float4 Position : POSITIONfloat3 Normal : NORMALfloat2 TexCoord0 : TEXCOORD}struct VertexOutput{float4 Position : POSITIONfloat2 TexCoord0 : TEXCOORD0float4 projCoords : TEXCOORD1float3 Normal : TEXCOORD2float4 PositionZ : TEXCOORD3}struct FragmentOutput{float4 Color : COLOR}FragmentOutput mainfrag(VertexOutput IN,const uniform float3 lightworlddir0 : C3, // position of light0 in view coordinatesconst uniform float3 eyepositionmodel : C4, // camera position in view coordinatesconst uniform float3 AmbientColor : C5,const uniform float3 DiffuseColor : C6,const uniform float3 SpecularColor : C7,const uniform float specExp : C8,const uniform float4x4 matworld : C9,const uniform float4x4 mattsm : C10,uniform sampler2D basetexture0, // normal texuniform sampler2D basetexture1 // shadow map texture){FragmentOutput finalColorfloat fEpsilon = 0.0005ffloat texelSize = 1.0f / 1024ffloat fZToCompare = IN.PositionZ.z/IN.PositionZ.w - fEpsilonfloat2 ShadowTexC = IN.projCoords.xy / IN.projCoords.w// transform to texel spacefloat2 texelpos = 1024 * ShadowTexC// Determine the lerp amountsfloat2 lerps = frac( texelpos )//read in bilerp stamp, doing the shadow checksfloat sourcevals[4]sourcevals[0] = (fZToCompare > tex2D( basetexture1, ShadowTexC ).r) ? 0.0f : 1.0fsourcevals[1] = (fZToCompare > tex2D( basetexture1, ShadowTexC + float2(texelSize, 0) ).r) ? 0.0f : 1.0fsourcevals[2] = (fZToCompare > tex2D( basetexture1, ShadowTexC + float2(0, texelSize) ).r) ? 0.0f : 1.0fsourcevals[3] = (fZToCompare > tex2D( basetexture1, ShadowTexC + float2(texelSize, texelSize) ).r) ? 0.0f : 1.0f// lerp between the shadow values to calculate our light amountfloat shadow = lerp( lerp( sourcevals[0], sourcevals[1], lerps.x ),lerp( sourcevals[2], sourcevals[3], lerps.x ),lerps.y )float4 Kd = tex2D( basetexture0, IN.TexCoord0.xy ) // normal texturefloat3 N = normalize(IN.Normal)float3 L = -normalize(lightworlddir0)float diffuse = max( dot(N, L), 0 )float3 finalShadow = float3(shadow, shadow, shadow)finalColor.Color = float4( ( Kd.xyz * AmbientColor ) + ( Kd.xyz * diffuse * DiffuseColor) * finalShadow, 1 )return finalColor}The generated asm code, as well as the output of the cg log :// cgc version 1.3.0001, build date Jan 7 2005 14:01:35// command line args: -q -profile ps_2_0 -entry mainfrag//vendor NVIDIA Corporation//version 1.0.02//profile ps_2_0//program mainfrag//semantic mainfrag.lightworlddir0 : C3//semantic mainfrag.eyepositionmodel : C4//semantic mainfrag.AmbientColor : C5//semantic mainfrag.DiffuseColor : C6//semantic mainfrag.SpecularColor : C7//semantic mainfrag.specExp : C8//semantic mainfrag.matworld : C9//semantic mainfrag.mattsm : C10//semantic mainfrag.basetexture0//semantic mainfrag.basetexture1//var float2 IN.TexCoord0 : $vin.TEX0 : TEX0 : 0 : 1//var float4 IN.projCoords : $vin.TEX1 : TEX1 : 0 : 1//var float3 IN.Normal : $vin.TEX2 : TEX2 : 0 : 1//var float4 IN.PositionZ : $vin.TEX3 : TEX3 : 0 : 1//var float3 lightworlddir0 : C3 : c[3] : 1 : 1//var float3 eyepositionmodel : C4 : c[4] : 2 : 0//var float3 AmbientColor : C5 : c[5] : 3 : 1//var float3 DiffuseColor : C6 : c[6] : 4 : 1//var float3 SpecularColor : C7 : c[7] : 5 : 0//var float specExp : C8 : c[8] : 6 : 0//var float4x4 matworld : C9 : c[9], 4 : 7 : 0//var float4x4 mattsm : C10 : c[10], 4 : 8 : 0//var sampler2D basetexture0 : : texunit 0 : 9 : 1//var sampler2D basetexture1 : : texunit 1 : 10 : 1//var float4 mainfrag.Color : $vout.COL : COL : -1 : 1//const c[0] = 0 1024 0.0005 0.0009765625//const c[1] = 1dcl_2d s1dcl_2d s0def c0, 0.000000, 1024.000000, 0.000500, 0.000977def c1, 1.000000, 0.000000, 0.000000, 0.000000dcl t0.xydcl t1.xyzwdcl t2.xyzdcl t3.xyzwdp3 r1.x, c3, c3dp3 r0.x, t2, t2rsq r1.x, r1.xrsq r0.x, r0.xmul r1.xyz, r1.x, c3mul r0.xyz, r0.x, t2dp3 r0.x, r0, -r1rcp r1.x, t1.wmul r7.xy, t1, r1.xadd r4.xy, r7, c0.wmax r0.x, r0, c0mov r2.y, c0.xmov r2.x, c0.wadd r5.xy, r7, r2rcp r2.x, t3.wmad r3.x, t3.z, r2, -c0.ztexld r8, r4, s1mov r2.x, r8texld r8, r5, s1mov r5.x, r8mov r4.x, c0add r2.x, r3, -r2add r5.x, r3, -r5cmp r5.x, -r5, c1, r4cmp r2.x, -r2, c1, r4texld r8, r7, s1mov r6.x, r8mov r1.y, c0.wmov r1.x, c0add r1.xy, r7, r1texld r8, r1, s1mov r1.x, r8add r1.x, r3, -r1add r3.x, r3, -r6cmp r1.x, -r1, c1, r4cmp r3.x, -r3, c1, r4add r2.x, r2, -r1add r4.x, r5, -r3mul r6.xy, r7, c0.yfrc r5.xy, r6mad r1.x, r5, r2, r1mad r3.x, r5, r4, r3texld r8, t0, s0mov r2.xyz, r8add r1.x, r1, -r3mul r4.xyz, r2, r0.xmad r0.x, r5.y, r1, r3mul r1.xyz, r4, c6mul r0.xyz, r1, r0.xmov r0.w, c1.xmad r0.xyz, r2, c5, r0mov oC0, r0It turned out that the number of depedent texture reads was the problem, so I don't really understand how a 11-sample shader could work ?Does someone know how I could fix this shader ?? I would really appreciate, as as I said, I am looking for a solution for 6 months ;(   