Shader_Minifier icon indicating copy to clipboard operation
Shader_Minifier copied to clipboard

Add #define logic

Open Lutymane opened this issue 2 years ago • 3 comments

Hello,

The minifier doesn't consider #define/#undef and doesn't optimize #if blocks

Example input:

#define MUT_0
#undef MUT_1

float f(){
  float r = 1.;

  #ifdef MUT_0
    r = mut0(r);
  #endif

  #ifdef MUT_1
    r = mut1(r);
  #endif

  return r;
}

1.3.1 gives:

#define MUT_0
#undef MUT_1
float M(){float M=1.;
#ifdef MUT_0
M=mut0(M);
#endif

#ifdef MUT_1
M=mut1(M);
#endif
return M;}

So it would make sense to preserve #if blocks only if there are no corresponding #define/#undef statements and process them if they are present

Lutymane avatar Dec 28 '22 16:12 Lutymane

Thanks for the idea, that would be nice to have, indeed.

laurentlb avatar Jan 01 '23 13:01 laurentlb

@laurentlb Thank you! Also would it be possible to specify defines as arguments (to skip having #defines in code)? Like so -d SOME_DEF -d DEF_WITH_VALUE=1

Lutymane avatar Apr 02 '23 07:04 Lutymane

Yeah, that would make sense.

laurentlb avatar Apr 02 '23 18:04 laurentlb