J'ai trouvé d'autres sens pour retourner le problèmegabriel a écrit :
Bon après avoir retourner le problème dans tous les sens le meilleur compromis trouvé est à
59 instructions (6 texture, 53 arithmetic) sur 84 cyles pour un noise 2d
Fx Composer intègre un desassembleur, je me suis donc armé d'une nouvelle boite d'aspirine pour voir ce qu'on pouvait en faire.
Je passe les détails mais à la fin de la fonction, on calcule la contribution de bruit pour chaque vertice.
Basiquement, si la contribution de bruit est inférieur à 0, on ne va pas calculer la valeur. cela a du sens car consommer quelques cycles de calcul pour un résultat qui sera finalement jeté à la fin n'est pas payant. Cela revient moins cher de tester une condition ...
Code : Tout sélectionner
// Calculate the contribution from the three corners
float3 t = 0.5 - float3(dot(xy0, xy0), dot(xy12.xy, xy12.xy), dot(xy12.zw, xy12.zw));
// Noise contributions from the three corners
float3 n = 0;
if(t.x > 0){
// Just one lookup table on lnoise_random
n.x = pow(t.x, 4) * lnoise_FS_lookupGrad3FromRandomAndDot(i0.x + lnoise_FS_lookupRandom(i0.y) , xy0);
}//end if
if(t.y > 0){
n.y = pow(t.y, 4) * lnoise_FS_lookupGrad3FromRandomAndDot(i0.x + i1.x + lnoise_FS_lookupRandom(i0.y + i1.y) , xy12.xy);
}//end if
if(t.z > 0){
n.z = pow(t.z, 4) * lnoise_FS_lookupGrad3FromRandomAndDot(i2.x + lnoise_FS_lookupRandom(i2.y) , xy12.zw);
}//end if
J'ai donc optimisé cela en calculant t mais en utilisant la fonction max (0, %calcul%) ce qui fait que si %calcul% est inférieur à 0, t vaut 0, sinon %calcul%
si t vaut 0, tous les calculs liés à n (dépendant de t) seront alors égale à 0 ( pow(t, 4) * ).
Code : Tout sélectionner
// Calculate the contribution from the three corners
float3 t = max(0, (0.5).xxx - float3(dot(xy0, xy0), dot(xy12.xy, xy12.xy), dot(xy12.zw, xy12.zw)));
// Noise contributions from the three corners
// Just one lookup table on lnoise_random
float3 n = pow(t, 4) * float3(
lnoise_FS_lookupGrad3FromRandomAndDot(i0.x + lnoise_FS_lookupRandom(i0.y) , xy0).x,
lnoise_FS_lookupGrad3FromRandomAndDot(i1.x + lnoise_FS_lookupRandom(i1.y) , xy12.xy).x,
lnoise_FS_lookupGrad3FromRandomAndDot(i2.x + lnoise_FS_lookupRandom(i2.y) , xy12.zw).x
);
approximately 54 instruction slots used (6 texture, 48 arithmetic)
De plus, en farfouillant dans le sujet j'ai appris quand dans certaines conditions, faire un lookup sur une texture dans un une condition était interdit par le GPU ...
en résuméerror X6077: texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks, dynamic conditional subroutine calls, or loop/rep with break*.
There are cases where usage of IF can be a good idea, but branching around for 1 line definitely costs more than it helps as a single vector op is a single tick instruction