summaryrefslogtreecommitdiff
path: root/_gen.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-02-11 00:23:20 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-02-11 00:23:20 +0100
commit6cb08bbe4937f9122b0b6712d8674c3085b57349 (patch)
treec3f35955404784f72cdcb86e5857c2ac94c0b204 /_gen.c
downloadvulkan_compute_minimal_example-6cb08bbe4937f9122b0b6712d8674c3085b57349.zip
Add code
Diffstat (limited to '_gen.c')
-rw-r--r--_gen.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/_gen.c b/_gen.c
new file mode 100644
index 0000000..b1e9d30
--- /dev/null
+++ b/_gen.c
@@ -0,0 +1,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;
+}