GLSL compile error "memory exhausted" -


i trying implement glsl fragment shader complex if-else decision tree. unfortunately shader compiler fails quite "syntax error - memory exhausted" error. there constraints code size or decision tree depth in glsl? suggestion how overcome issue?

bool block1(float p[16], float cb, float c_b) {    if(p[6] > cb)    if(p[7] > cb)     if(p[8] > cb)      return true;     else      if(p[15] > cb)       return true;      else       return false;    else if(p[7] < c_b)     if(p[14] > cb)      if(p[15] > cb)       return true;      else       return false;     else if(p[14] < c_b)      if(p[8] < c_b)       if(p[9] < c_b)        if(p[10] < c_b)         if(p[11] < c_b)          if(p[12] < c_b)           if(p[13] < c_b)            if(p[15] < c_b)             return true;            else             return false;   // ';' : syntax error memory exhausted           else            return false;          else           return false;         else          return false;        else         return false;       else        return false;      else       return false;     else      return false;    else     if(p[14] > cb)      if(p[15] > cb)       return true;      else       return false;     else      return false;   else if(p[6] < c_b)    if(p[15] > cb)     if(p[13] > cb)      if(p[14] > cb)       return true;      else       return false;     else if(p[13] < c_b)      if(p[7] < c_b)       if(p[8] < c_b)        if(p[9] < c_b)         if(p[10] < c_b)          if(p[11] < c_b)           if(p[12] < c_b)            if(p[14] < c_b)             return true;            else             return false;           else            return false;          else           return false;         else          return false;        else         return false;       else        return false;      else       return false;     else      return false;    else     if(p[7] < c_b)      if(p[8] < c_b)       if(p[9] < c_b)        if(p[10] < c_b)         if(p[11] < c_b)          if(p[12] < c_b)           if(p[13] < c_b)            if(p[14] < c_b)             return true;            else             return false;           else            return false;          else           return false;         else          return false;        else         return false;       else        return false;      else       return false;     else      return false;   else    if(p[13] > cb)     if(p[14] > cb)      if(p[15] > cb)       return true;      else       return false;     else      return false;    else if(p[13] < c_b)     if(p[7] < c_b)      if(p[8] < c_b)       if(p[9] < c_b)        if(p[10] < c_b)         if(p[11] < c_b)          if(p[12] < c_b)           if(p[14] < c_b)            if(p[15] < c_b)             return true;            else             return false;           else            return false;          else           return false;         else          return false;        else         return false;       else        return false;      else       return false;     else      return false;    else     return false; } 

i'm going go out on limb here, know nothing shader languages.

1. use logic combinations (and, or)

however know general logic , lots of programming languages. chances big construct like:

if(p[8] < c_b)  if(p[9] < c_b)   if(p[10] < c_b)    if(p[11] < c_b)     if(p[12] < c_b)      if(p[13] < c_b)       if(p[15] < c_b)        return true;       else        return false;   // ';' : syntax error memory exhausted      else       return false;     else      return false;    else     return false;   else    return false;  else   return false; else  return false; 

could trivially stated equivalently following (single) boolean expression:

return (p[8] < c_b)     && (p[9] < c_b)     && (p[10] < c_b)     && (p[11] < c_b)     && (p[12] < c_b)     && (p[13] < c_b)     && (p[15] < c_b); 

you might have use and instead of && depending on exact grammar of particular language.

2. eliminate redundancy

i noticed @ least 2 of 'subtrees' identical. more specifically, e.g. line #57 (formatting condensed convenience, here):

    if(p[13] < c_b) if(p[7] < c_b) if(p[8] < c_b) if(p[9] < c_b) if(p[10] < c_b) if(p[11] < c_b) if(p[12] < c_b) if(p[14] < c_b)         return true;     else return false; else return false; else return false; else return false; else return false; else return false; else return false; else return false; 

is identical line #83

   if(p[7] < c_b) if(p[8] < c_b) if(p[9] < c_b) if(p[10] < c_b) if(p[11] < c_b) if(p[12] < c_b) if(p[13] < c_b) if(p[14] < c_b)        return true;    else return false; else return false; else return false; else return false; else return false; else return false; else return false; else 

just (p[13] < c_b) condition moved nearer end. highly combine branches in occurs.

instead of manually doing (painstaking) process, suggest making truth table (just map out possible inputs) , deducing single boolean expression generate result value that.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -