diff options
Diffstat (limited to 'src/glsl/builtins/tools')
-rwxr-xr-x | src/glsl/builtins/tools/generate_builtins.py | 10 | ||||
-rwxr-xr-x | src/glsl/builtins/tools/texture_builtins.py | 210 |
2 files changed, 153 insertions, 67 deletions
diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py index 3a938a022da..edd3c70e00b 100755 --- a/src/glsl/builtins/tools/generate_builtins.py +++ b/src/glsl/builtins/tools/generate_builtins.py @@ -152,6 +152,8 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne { struct gl_context fakeCtx; fakeCtx.API = API_OPENGL; + fakeCtx.Const.GLSLVersion = 130; + fakeCtx.Extensions.ARB_ES2_compatibility = true; gl_shader *sh = _mesa_new_shader(NULL, 0, target); struct _mesa_glsl_parse_state *st = new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh); @@ -178,7 +180,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne if (st->error) { printf("error reading builtin: %.35s ...\\n", functions[i]); printf("Info log:\\n%s\\n", st->info_log); - talloc_free(sh); + ralloc_free(sh); return NULL; } } @@ -203,7 +205,7 @@ void *builtin_mem_ctx = NULL; void _mesa_glsl_release_functions(void) { - talloc_free(builtin_mem_ctx); + ralloc_free(builtin_mem_ctx); builtin_mem_ctx = NULL; memset(builtin_profiles, 0, sizeof(builtin_profiles)); } @@ -219,7 +221,7 @@ _mesa_read_profile(struct _mesa_glsl_parse_state *state, if (sh == NULL) { sh = read_builtins(GL_VERTEX_SHADER, prototypes, functions, count); - talloc_steal(builtin_mem_ctx, sh); + ralloc_steal(builtin_mem_ctx, sh); builtin_profiles[profile_index] = sh; } @@ -231,7 +233,7 @@ void _mesa_glsl_initialize_functions(struct _mesa_glsl_parse_state *state) { if (builtin_mem_ctx == NULL) { - builtin_mem_ctx = talloc_init("GLSL built-in functions"); + builtin_mem_ctx = ralloc_context(NULL); // "GLSL built-in functions" memset(&builtin_profiles, 0, sizeof(builtin_profiles)); } diff --git a/src/glsl/builtins/tools/texture_builtins.py b/src/glsl/builtins/tools/texture_builtins.py index 8bf708b5aac..8017e943b1b 100755 --- a/src/glsl/builtins/tools/texture_builtins.py +++ b/src/glsl/builtins/tools/texture_builtins.py @@ -3,6 +3,10 @@ import sys import StringIO +# Bitfield constants for the 'variant' argument to generate_sigs +Proj = 1 +Offset = 2 + def vec_type(g, size): if size == 1: if g == "i": @@ -12,16 +16,20 @@ def vec_type(g, size): return "float" return g + "vec" + str(size) -# Get the base dimension - i.e. sampler3D gives 3 -# Array samplers also get +1 here since the layer is really an extra coordinate -def get_coord_dim(sampler_type): +# Get the sampler dimension - i.e. sampler3D gives 3 +def get_sampler_dim(sampler_type): if sampler_type[0].isdigit(): - coord_dim = int(sampler_type[0]) + sampler_dim = int(sampler_type[0]) elif sampler_type.startswith("Cube"): - coord_dim = 3 + sampler_dim = 3 else: assert False ("coord_dim: invalid sampler_type: " + sampler_type) + return sampler_dim +# Get the coordinate dimension for a given sampler type. +# Array samplers also get +1 here since the layer is really an extra coordinate +def get_coord_dim(sampler_type): + coord_dim = get_sampler_dim(sampler_type) if sampler_type.find("Array") != -1: coord_dim += 1 return coord_dim @@ -35,18 +43,17 @@ def get_extra_dim(sampler_type, use_proj, unused_fields): extra_dim += 1 return extra_dim -def generate_sigs(g, tex_inst, sampler_type, use_proj = False, unused_fields = 0): +def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0): coord_dim = get_coord_dim(sampler_type) - extra_dim = get_extra_dim(sampler_type, use_proj, unused_fields) + extra_dim = get_extra_dim(sampler_type, variant & Proj, unused_fields) + offset_dim = get_sampler_dim(sampler_type) # Print parameters print " (signature " + g + "vec4" print " (parameters" print " (declare (in) " + g + "sampler" + sampler_type + " sampler)" print " (declare (in) " + vec_type("i" if tex_inst == "txf" else "", coord_dim + extra_dim) + " P)", - if tex_inst == "txb": - print "\n (declare (in) float bias)", - elif tex_inst == "txl": + if tex_inst == "txl": print "\n (declare (in) float lod)", elif tex_inst == "txf": print "\n (declare (in) int lod)", @@ -55,6 +62,11 @@ def generate_sigs(g, tex_inst, sampler_type, use_proj = False, unused_fields = 0 print "\n (declare (in) " + grad_type + " dPdx)", print "\n (declare (in) " + grad_type + " dPdy)", + if variant & Offset: + print "\n (declare (const_in) " + vec_type("i", offset_dim) + " offset)", + if tex_inst == "txb": + print "\n (declare (in) float bias)", + print ")\n ((return (" + tex_inst + " (var_ref sampler)", # Coordinate @@ -63,12 +75,14 @@ def generate_sigs(g, tex_inst, sampler_type, use_proj = False, unused_fields = 0 else: print "(var_ref P)", - # Offset - print "(0 0 0)", + if variant & Offset: + print "(var_ref offset)", + else: + print "0", if tex_inst != "txf": # Projective divisor - if use_proj: + if variant & Proj: print "(swiz " + "xyzw"[coord_dim + extra_dim-1] + " (var_ref P))", else: print "1", @@ -90,10 +104,10 @@ def generate_sigs(g, tex_inst, sampler_type, use_proj = False, unused_fields = 0 print "((var_ref dPdx) (var_ref dPdy))", print "))))\n" -def generate_fiu_sigs(tex_inst, sampler_type, use_proj = False, unused_fields = 0): - generate_sigs("", tex_inst, sampler_type, use_proj, unused_fields) - generate_sigs("i", tex_inst, sampler_type, use_proj, unused_fields) - generate_sigs("u", tex_inst, sampler_type, use_proj, unused_fields) +def generate_fiu_sigs(tex_inst, sampler_type, variant = 0, unused_fields = 0): + generate_sigs("", tex_inst, sampler_type, variant, unused_fields) + generate_sigs("i", tex_inst, sampler_type, variant, unused_fields) + generate_sigs("u", tex_inst, sampler_type, variant, unused_fields) def start_function(name): sys.stdout = StringIO.StringIO() @@ -127,17 +141,17 @@ def generate_texture_functions(fs): end_function(fs, "texture") start_function("textureProj") - generate_fiu_sigs("tex", "1D", True) - generate_fiu_sigs("tex", "1D", True, 2) - generate_fiu_sigs("tex", "2D", True) - generate_fiu_sigs("tex", "2D", True, 1) - generate_fiu_sigs("tex", "3D", True) - - generate_fiu_sigs("txb", "1D", True) - generate_fiu_sigs("txb", "1D", True, 2) - generate_fiu_sigs("txb", "2D", True) - generate_fiu_sigs("txb", "2D", True, 1) - generate_fiu_sigs("txb", "3D", True) + generate_fiu_sigs("tex", "1D", Proj) + generate_fiu_sigs("tex", "1D", Proj, 2) + generate_fiu_sigs("tex", "2D", Proj) + generate_fiu_sigs("tex", "2D", Proj, 1) + generate_fiu_sigs("tex", "3D", Proj) + + generate_fiu_sigs("txb", "1D", Proj) + generate_fiu_sigs("txb", "1D", Proj, 2) + generate_fiu_sigs("txb", "2D", Proj) + generate_fiu_sigs("txb", "2D", Proj, 1) + generate_fiu_sigs("txb", "3D", Proj) end_function(fs, "textureProj") start_function("textureLod") @@ -149,6 +163,28 @@ def generate_texture_functions(fs): generate_fiu_sigs("txl", "2DArray") end_function(fs, "textureLod") + start_function("textureLodOffset") + generate_fiu_sigs("txl", "1D", Offset) + generate_fiu_sigs("txl", "2D", Offset) + generate_fiu_sigs("txl", "3D", Offset) + generate_fiu_sigs("txl", "1DArray", Offset) + generate_fiu_sigs("txl", "2DArray", Offset) + end_function(fs, "textureLodOffset") + + start_function("textureOffset") + generate_fiu_sigs("tex", "1D", Offset) + generate_fiu_sigs("tex", "2D", Offset) + generate_fiu_sigs("tex", "3D", Offset) + generate_fiu_sigs("tex", "1DArray", Offset) + generate_fiu_sigs("tex", "2DArray", Offset) + + generate_fiu_sigs("txb", "1D", Offset) + generate_fiu_sigs("txb", "2D", Offset) + generate_fiu_sigs("txb", "3D", Offset) + generate_fiu_sigs("txb", "1DArray", Offset) + generate_fiu_sigs("txb", "2DArray", Offset) + end_function(fs, "textureOffset") + start_function("texelFetch") generate_fiu_sigs("txf", "1D") generate_fiu_sigs("txf", "2D") @@ -157,14 +193,44 @@ def generate_texture_functions(fs): generate_fiu_sigs("txf", "2DArray") end_function(fs, "texelFetch") + start_function("texelFetchOffset") + generate_fiu_sigs("txf", "1D", Offset) + generate_fiu_sigs("txf", "2D", Offset) + generate_fiu_sigs("txf", "3D", Offset) + generate_fiu_sigs("txf", "1DArray", Offset) + generate_fiu_sigs("txf", "2DArray", Offset) + end_function(fs, "texelFetchOffset") + + start_function("textureProjOffset") + generate_fiu_sigs("tex", "1D", Proj | Offset) + generate_fiu_sigs("tex", "1D", Proj | Offset, 2) + generate_fiu_sigs("tex", "2D", Proj | Offset) + generate_fiu_sigs("tex", "2D", Proj | Offset, 1) + generate_fiu_sigs("tex", "3D", Proj | Offset) + + generate_fiu_sigs("txb", "1D", Proj | Offset) + generate_fiu_sigs("txb", "1D", Proj | Offset, 2) + generate_fiu_sigs("txb", "2D", Proj | Offset) + generate_fiu_sigs("txb", "2D", Proj | Offset, 1) + generate_fiu_sigs("txb", "3D", Proj | Offset) + end_function(fs, "textureProjOffset") + start_function("textureProjLod") - generate_fiu_sigs("txl", "1D", True) - generate_fiu_sigs("txl", "1D", True, 2) - generate_fiu_sigs("txl", "2D", True) - generate_fiu_sigs("txl", "2D", True, 1) - generate_fiu_sigs("txl", "3D", True) + generate_fiu_sigs("txl", "1D", Proj) + generate_fiu_sigs("txl", "1D", Proj, 2) + generate_fiu_sigs("txl", "2D", Proj) + generate_fiu_sigs("txl", "2D", Proj, 1) + generate_fiu_sigs("txl", "3D", Proj) end_function(fs, "textureProjLod") + start_function("textureProjLodOffset") + generate_fiu_sigs("txl", "1D", Proj | Offset) + generate_fiu_sigs("txl", "1D", Proj | Offset, 2) + generate_fiu_sigs("txl", "2D", Proj | Offset) + generate_fiu_sigs("txl", "2D", Proj | Offset, 1) + generate_fiu_sigs("txl", "3D", Proj | Offset) + end_function(fs, "textureProjLodOffset") + start_function("textureGrad") generate_fiu_sigs("txd", "1D") generate_fiu_sigs("txd", "2D") @@ -174,22 +240,40 @@ def generate_texture_functions(fs): generate_fiu_sigs("txd", "2DArray") end_function(fs, "textureGrad") + start_function("textureGradOffset") + generate_fiu_sigs("txd", "1D", Offset) + generate_fiu_sigs("txd", "2D", Offset) + generate_fiu_sigs("txd", "3D", Offset) + generate_fiu_sigs("txd", "Cube", Offset) + generate_fiu_sigs("txd", "1DArray", Offset) + generate_fiu_sigs("txd", "2DArray", Offset) + end_function(fs, "textureGradOffset") + start_function("textureProjGrad") - generate_fiu_sigs("txd", "1D", True) - generate_fiu_sigs("txd", "1D", True, 2) - generate_fiu_sigs("txd", "2D", True) - generate_fiu_sigs("txd", "2D", True, 1) - generate_fiu_sigs("txd", "3D", True) + generate_fiu_sigs("txd", "1D", Proj) + generate_fiu_sigs("txd", "1D", Proj, 2) + generate_fiu_sigs("txd", "2D", Proj) + generate_fiu_sigs("txd", "2D", Proj, 1) + generate_fiu_sigs("txd", "3D", Proj) end_function(fs, "textureProjGrad") + start_function("textureProjGradOffset") + generate_fiu_sigs("txd", "1D", Proj | Offset) + generate_fiu_sigs("txd", "1D", Proj | Offset, 2) + generate_fiu_sigs("txd", "2D", Proj | Offset) + generate_fiu_sigs("txd", "2D", Proj | Offset, 1) + generate_fiu_sigs("txd", "3D", Proj | Offset) + end_function(fs, "textureProjGradOffset") + + # ARB_texture_rectangle extension start_function("texture2DRect") generate_sigs("", "tex", "2DRect") end_function(fs, "texture2DRect") start_function("texture2DRectProj") - generate_sigs("", "tex", "2DRect", True) - generate_sigs("", "tex", "2DRect", True, 1) + generate_sigs("", "tex", "2DRect", Proj) + generate_sigs("", "tex", "2DRect", Proj, 1) end_function(fs, "texture2DRectProj") start_function("shadow2DRect") @@ -197,7 +281,7 @@ def generate_texture_functions(fs): end_function(fs, "shadow2DRect") start_function("shadow2DRectProj") - generate_sigs("", "tex", "2DRectShadow", True) + generate_sigs("", "tex", "2DRectShadow", Proj) end_function(fs, "shadow2DRectProj") # EXT_texture_array extension @@ -243,15 +327,15 @@ def generate_texture_functions(fs): end_function(fs, "texture1DLod") start_function("texture1DProj") - generate_sigs("", "tex", "1D", True) - generate_sigs("", "tex", "1D", True, 2) - generate_sigs("", "txb", "1D", True) - generate_sigs("", "txb", "1D", True, 2) + generate_sigs("", "tex", "1D", Proj) + generate_sigs("", "tex", "1D", Proj, 2) + generate_sigs("", "txb", "1D", Proj) + generate_sigs("", "txb", "1D", Proj, 2) end_function(fs, "texture1DProj") start_function("texture1DProjLod") - generate_sigs("", "txl", "1D", True) - generate_sigs("", "txl", "1D", True, 2) + generate_sigs("", "txl", "1D", Proj) + generate_sigs("", "txl", "1D", Proj, 2) end_function(fs, "texture1DProjLod") start_function("texture2D") @@ -264,15 +348,15 @@ def generate_texture_functions(fs): end_function(fs, "texture2DLod") start_function("texture2DProj") - generate_sigs("", "tex", "2D", True) - generate_sigs("", "tex", "2D", True, 1) - generate_sigs("", "txb", "2D", True) - generate_sigs("", "txb", "2D", True, 1) + generate_sigs("", "tex", "2D", Proj) + generate_sigs("", "tex", "2D", Proj, 1) + generate_sigs("", "txb", "2D", Proj) + generate_sigs("", "txb", "2D", Proj, 1) end_function(fs, "texture2DProj") start_function("texture2DProjLod") - generate_sigs("", "txl", "2D", True) - generate_sigs("", "txl", "2D", True, 1) + generate_sigs("", "txl", "2D", Proj) + generate_sigs("", "txl", "2D", Proj, 1) end_function(fs, "texture2DProjLod") start_function("texture3D") @@ -285,12 +369,12 @@ def generate_texture_functions(fs): end_function(fs, "texture3DLod") start_function("texture3DProj") - generate_sigs("", "tex", "3D", True) - generate_sigs("", "txb", "3D", True) + generate_sigs("", "tex", "3D", Proj) + generate_sigs("", "txb", "3D", Proj) end_function(fs, "texture3DProj") start_function("texture3DProjLod") - generate_sigs("", "txl", "3D", True) + generate_sigs("", "txl", "3D", Proj) end_function(fs, "texture3DProjLod") start_function("textureCube") @@ -312,12 +396,12 @@ def generate_texture_functions(fs): end_function(fs, "shadow1DLod") start_function("shadow1DProj") - generate_sigs("", "tex", "1DShadow", True, 1) - generate_sigs("", "txb", "1DShadow", True, 1) + generate_sigs("", "tex", "1DShadow", Proj, 1) + generate_sigs("", "txb", "1DShadow", Proj, 1) end_function(fs, "shadow1DProj") start_function("shadow1DProjLod") - generate_sigs("", "txl", "1DShadow", True, 1) + generate_sigs("", "txl", "1DShadow", Proj, 1) end_function(fs, "shadow1DProjLod") start_function("shadow2D") @@ -330,12 +414,12 @@ def generate_texture_functions(fs): end_function(fs, "shadow2DLod") start_function("shadow2DProj") - generate_sigs("", "tex", "2DShadow", True) - generate_sigs("", "txb", "2DShadow", True) + generate_sigs("", "tex", "2DShadow", Proj) + generate_sigs("", "txb", "2DShadow", Proj) end_function(fs, "shadow2DProj") start_function("shadow2DProjLod") - generate_sigs("", "txl", "2DShadow", True) + generate_sigs("", "txl", "2DShadow", Proj) end_function(fs, "shadow2DProjLod") sys.stdout = sys.__stdout__ @@ -346,4 +430,4 @@ if __name__ == "__main__": fs = {} generate_texture_functions(fs); for k, v in fs.iteritems(): - print v + print v |