Skip to content

Commit 9d17818

Browse files
committed
add glsl opmizier
1 parent 417fb5c commit 9d17818

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#pragma once
2+
#ifndef GLSL_OPTIMIZER_H
3+
#define GLSL_OPTIMIZER_H
4+
5+
/*
6+
Main GLSL optimizer interface.
7+
See ../../README.md for more instructions.
8+
9+
General usage:
10+
11+
ctx = glslopt_initialize();
12+
for (lots of shaders) {
13+
shader = glslopt_optimize (ctx, shaderType, shaderSource, options);
14+
if (glslopt_get_status (shader)) {
15+
newSource = glslopt_get_output (shader);
16+
} else {
17+
errorLog = glslopt_get_log (shader);
18+
}
19+
glslopt_shader_delete (shader);
20+
}
21+
glslopt_cleanup (ctx);
22+
*/
23+
24+
struct glslopt_shader;
25+
struct glslopt_ctx;
26+
27+
enum glslopt_shader_type {
28+
kGlslOptShaderVertex = 0,
29+
kGlslOptShaderFragment,
30+
};
31+
32+
// Options flags for glsl_optimize
33+
enum glslopt_options {
34+
kGlslOptionSkipPreprocessor = (1<<0), // Skip preprocessing shader source. Saves some time if you know you don't need it.
35+
kGlslOptionNotFullShader = (1<<1), // Passed shader is not the full shader source. This makes some optimizations weaker.
36+
};
37+
38+
// Optimizer target language
39+
enum glslopt_target {
40+
kGlslTargetOpenGL = 0,
41+
kGlslTargetOpenGLES20 = 1,
42+
kGlslTargetOpenGLES30 = 2,
43+
kGlslTargetMetal = 3,
44+
};
45+
46+
// Type info
47+
enum glslopt_basic_type {
48+
kGlslTypeFloat = 0,
49+
kGlslTypeInt,
50+
kGlslTypeBool,
51+
kGlslTypeTex2D,
52+
kGlslTypeTex3D,
53+
kGlslTypeTexCube,
54+
kGlslTypeTex2DShadow,
55+
kGlslTypeTex2DArray,
56+
kGlslTypeOther,
57+
kGlslTypeCount
58+
};
59+
enum glslopt_precision {
60+
kGlslPrecHigh = 0,
61+
kGlslPrecMedium,
62+
kGlslPrecLow,
63+
kGlslPrecCount
64+
};
65+
66+
glslopt_ctx* glslopt_initialize (glslopt_target target);
67+
void glslopt_cleanup (glslopt_ctx* ctx);
68+
69+
void glslopt_set_max_unroll_iterations (glslopt_ctx* ctx, unsigned iterations);
70+
71+
glslopt_shader* glslopt_optimize (glslopt_ctx* ctx, glslopt_shader_type type, const char* shaderSource, unsigned options);
72+
bool glslopt_get_status (glslopt_shader* shader);
73+
const char* glslopt_get_output (glslopt_shader* shader);
74+
const char* glslopt_get_raw_output (glslopt_shader* shader);
75+
const char* glslopt_get_log (glslopt_shader* shader);
76+
void glslopt_shader_delete (glslopt_shader* shader);
77+
78+
int glslopt_shader_get_input_count (glslopt_shader* shader);
79+
void glslopt_shader_get_input_desc (glslopt_shader* shader, int index, const char** outName, glslopt_basic_type* outType, glslopt_precision* outPrec, int* outVecSize, int* outMatSize, int* outArraySize, int* outLocation);
80+
int glslopt_shader_get_uniform_count (glslopt_shader* shader);
81+
int glslopt_shader_get_uniform_total_size (glslopt_shader* shader);
82+
void glslopt_shader_get_uniform_desc (glslopt_shader* shader, int index, const char** outName, glslopt_basic_type* outType, glslopt_precision* outPrec, int* outVecSize, int* outMatSize, int* outArraySize, int* outLocation);
83+
int glslopt_shader_get_texture_count (glslopt_shader* shader);
84+
void glslopt_shader_get_texture_desc (glslopt_shader* shader, int index, const char** outName, glslopt_basic_type* outType, glslopt_precision* outPrec, int* outVecSize, int* outMatSize, int* outArraySize, int* outLocation);
85+
86+
// Get *very* approximate shader stats:
87+
// Number of math, texture and flow control instructions.
88+
void glslopt_shader_get_stats (glslopt_shader* shader, int* approxMath, int* approxTex, int* approxFlow);
89+
90+
91+
#endif /* GLSL_OPTIMIZER_H */
76.3 KB
Binary file not shown.
1.51 MB
Binary file not shown.

glsl-optimizer/prebuilt/mac/libmesa.a

12 KB
Binary file not shown.

0 commit comments

Comments
 (0)