summaryrefslogtreecommitdiff
path: root/_gen.c
blob: b1e9d3034ce8bc2a75002507e1fec703ca9888b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#if 0
SRC=${0##*/}
BIN=${SRC%.*}
glslc compute_module.comp -o COMPUTE_MODULE.tmp
gcc $SRC -o $BIN -lm -lvulkan && ./$BIN && rm $BIN
rm COMPUTE_MODULE.tmp
exit 0
#endif

#include <stdio.h>

int main(int argc, char **argv) {
  FILE *in = fopen("COMPUTE_MODULE.tmp", "rb");

  if (in == NULL) {
    printf("Cannot open compiled module code.\n");
    return -1;
  }

  FILE *out = fopen("compute_module.inl.h", "wb");

  if (out == NULL) {
    printf("Cannot write compiled module inlined data.\n");
    return -1;
  }

  fprintf(out, "#ifndef SAMPLE_COMPUTE_COMPUTE_MODULE_INL_H\n");
  fprintf(out, "#define SAMPLE_COMPUTE_COMPUTE_MODULE_INL_H\n");

  fprintf(out, "\n");
  fprintf(out, "unsigned COMPUTE_MODULE_CODE[] = {\n ");

  while (!feof(in)) {
    int x = 0;

    int n = fread(&x, 1, 4, in);

    if (n <= 0)
      break;

    fprintf(out, " %d,", x);
  }

  fprintf(out, "\n};\n\n");

  fprintf(out, "#endif\n");

  fclose(in);
  fclose(out);

  return 0;
}