-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.cpp
More file actions
114 lines (97 loc) · 3.01 KB
/
main.cpp
File metadata and controls
114 lines (97 loc) · 3.01 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "compiler_iface.h"
#include <getopt.h>
static int usage(const char* prog)
{
fprintf(stderr,
"Usage: %s [options] file\n"
"Options:\n"
" -o, --out=<file> Specifies the output deko3d shader module file (.dksh)\n"
" -r, --raw=<file> Specifies the file to which output raw Maxwell bytecode\n"
" -t, --tgsi=<file> Specifies the file to which output intermediary TGSI code\n"
" -s, --stage=<name> Specifies the pipeline stage of the shader\n"
" (vert, tess_ctrl, tess_eval, geom, frag, comp)\n"
" -v, --version Displays version information\n"
, prog);
return EXIT_FAILURE;
}
int main(int argc, char* argv[])
{
const char *inFile = nullptr, *outFile = nullptr, *rawFile = nullptr, *tgsiFile = nullptr, *stageName = nullptr;
static struct option long_options[] =
{
{ "out", required_argument, NULL, 'o' },
{ "raw", required_argument, NULL, 'r' },
{ "tgsi", required_argument, NULL, 't' },
{ "stage", required_argument, NULL, 's' },
{ "help", no_argument, NULL, '?' },
{ "version", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
int opt, optidx = 0;
while ((opt = getopt_long(argc, argv, "o:r:t:s:?v", long_options, &optidx)) != -1)
{
switch (opt)
{
case 'o': outFile = optarg; break;
case 'r': rawFile = optarg; break;
case 't': tgsiFile = optarg; break;
case 's': stageName = optarg; break;
case '?': usage(argv[0]); return EXIT_SUCCESS;
case 'v': printf("%s - Built on %s %s\n", PACKAGE_STRING, __DATE__, __TIME__); return EXIT_SUCCESS;
default: return usage(argv[0]);
}
}
if ((argc-optind) != 1)
return usage(argv[0]);
inFile = argv[optind];
if (!stageName)
{
fprintf(stderr, "Missing pipeline stage argument (--stage)\n");
return EXIT_FAILURE;
}
if (!outFile && !rawFile && !tgsiFile)
{
fprintf(stderr, "No output file specified\n");
return EXIT_FAILURE;
}
pipeline_stage stage;
if (0) ((void)0);
#define TEST_STAGE(_str,_val) else if (strcmp(stageName,(_str))==0) stage = (_val)
TEST_STAGE("vert", pipeline_stage_vertex);
TEST_STAGE("tess_ctrl", pipeline_stage_tess_ctrl);
TEST_STAGE("tess_eval", pipeline_stage_tess_eval);
TEST_STAGE("geom", pipeline_stage_geometry);
TEST_STAGE("frag", pipeline_stage_fragment);
TEST_STAGE("comp", pipeline_stage_compute);
#undef TEST_STAGE
else
{
fprintf(stderr, "Unrecognized pipeline stage: `%s'\n", stageName);
return EXIT_FAILURE;
}
FILE* fin = fopen(inFile, "rb");
if (!fin)
{
fprintf(stderr, "Could not open input file: %s\n", inFile);
return EXIT_FAILURE;
}
fseek(fin, 0, SEEK_END);
long fsize = ftell(fin);
rewind(fin);
char* glsl_source = new char[fsize+1];
fread(glsl_source, 1, fsize, fin);
fclose(fin);
glsl_source[fsize] = 0;
DekoCompiler compiler{stage};
bool rc = compiler.CompileGlsl(glsl_source);
delete[] glsl_source;
if (!rc)
return EXIT_FAILURE;
if (outFile)
compiler.OutputDksh(outFile);
if (rawFile)
compiler.OutputRawCode(rawFile);
if (tgsiFile)
compiler.OutputTgsi(tgsiFile);
return EXIT_SUCCESS;
}