summaryrefslogtreecommitdiffstats
path: root/src/glsl/builtins/tools
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2012-04-18 10:51:23 -0700
committerEric Anholt <[email protected]>2012-04-24 10:01:10 -0700
commit7de1331662816d31fb9bed423b1e5372284a260e (patch)
tree0992bf4c8a253d4f1bff450941500199f1bb4891 /src/glsl/builtins/tools
parent41b47441d720957d7b8a63afa26d94c752c8740b (diff)
glsl: Add support for generating builtin code from GLSL instead of IR.
This takes advantage of the builtin compiler to generate IR into a string, the same way we read GLSL for function prototypes for our profiles. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/glsl/builtins/tools')
-rwxr-xr-xsrc/glsl/builtins/tools/generate_builtins.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index fb9052bbd3f..eada4a65681 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -29,11 +29,23 @@ def read_ir_files(fs):
with open(filename) as f:
fs[function_name] = f.read()
+def read_glsl_files(fs):
+ for filename in glob(path.join(path.join(builtins_dir, 'glsl'), '*.glsl')):
+ function_name = path.basename(filename).split('.')[0]
+ (output, returncode) = run_compiler([filename])
+ if (returncode):
+ sys.stderr.write("Failed to compile builtin: " + filename + "\n")
+ sys.stderr.write("Result:\n")
+ sys.stderr.write(output)
+ else:
+ fs[function_name] = output;
+
# Return a dictionary containing all builtin definitions (even generated)
def get_builtin_definitions():
fs = {}
generate_texture_functions(fs)
read_ir_files(fs)
+ read_glsl_files(fs)
return fs
def stringify(s):
@@ -78,6 +90,10 @@ def run_compiler(args):
# Also toss any duplicate newlines
output = output.replace('\n\n', '\n')
+ # Kill any global variable declarations. We don't want them.
+ kill_globals = re.compile(r'^\(declare.*\n', re.MULTILINE)
+ output = kill_globals.sub('', output)
+
return (output, p.returncode)
def write_profile(filename, profile):
@@ -87,10 +103,6 @@ def write_profile(filename, profile):
print '#error builtins profile', profile, 'failed to compile'
return
- # Kill any global variable declarations. We don't want them.
- kill_globals = re.compile(r'^\(declare.*\n', re.MULTILINE)
- proto_ir = kill_globals.sub('', proto_ir)
-
print 'static const char prototypes_for_' + profile + '[] ='
print stringify(proto_ir), ';'