X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=scripts%2Fbuiltin_funcs.py;h=e7618877f34b00ebddf5032c69fbecbd2bf6b1b0;hb=HEAD;hp=0022f40c7e5125c9db01d9826f05f084e085ab59;hpb=9e44b553e200a9377901bd8e4c9de2b1465ec86a;p=libs%2Fgl.git diff --git a/scripts/builtin_funcs.py b/scripts/builtin_funcs.py index 0022f40c..16c5721b 100755 --- a/scripts/builtin_funcs.py +++ b/scripts/builtin_funcs.py @@ -3,19 +3,21 @@ import sys traits = { - "sampler1D": { "CDim": 1, "IDim": 1 }, - "sampler2D": { "CDim": 2, "IDim": 2 }, - "sampler3D": { "CDim": 3, "IDim": 3 }, - "sampler1DArray": { "CDim": 2, "IDim": 2 }, - "sampler2DArray": { "CDim": 3, "IDim": 3 }, - "samplerCube": { "CDim": 3, "IDim": 2 }, - "samplerCubeArray": { "CDim": 4, "IDim": 3 }, - "sampler1DShadow": { "CDim": 3, "IDim": 1 }, - "sampler2DShadow": { "CDim": 3, "IDim": 2 }, - "samplerCubeShadow": { "CDim": 4, "IDim": 2 }, - "sampler1DArrayShadow": { "CDim": 3, "IDim": 2 }, - "sampler2DArrayShadow": { "CDim": 4, "IDim": 3 }, - "samplerCubeArrayShadow": { "IDim": 3 }, + "sampler1D": { "CDim": 1, "IDim": 1, "LDim": 1 }, + "sampler2D": { "CDim": 2, "IDim": 2, "LDim": 2 }, + "sampler3D": { "CDim": 3, "IDim": 3, "LDim": 3 }, + "sampler1DArray": { "CDim": 2, "IDim": 2, "LDim": 1 }, + "sampler2DArray": { "CDim": 3, "IDim": 3, "LDim": 2 }, + "samplerCube": { "CDim": 3, "IDim": 2, "LDim": 3 }, + "samplerCubeArray": { "CDim": 4, "IDim": 3, "LDim": 3 }, + "sampler1DShadow": { "CDim": 3, "IDim": 1, "LDim": 1 }, + "sampler2DShadow": { "CDim": 3, "IDim": 2, "LDim": 2 }, + "samplerCubeShadow": { "CDim": 4, "IDim": 2, "LDim": 3 }, + "sampler1DArrayShadow": { "CDim": 3, "IDim": 2, "LDim": 1 }, + "sampler2DArrayShadow": { "CDim": 4, "IDim": 3, "LDim": 2 }, + "samplerCubeArrayShadow": { "IDim": 3, "LDim": 3 }, + "sampler2DMS": { "CDim": 2, "IDim": 2, "LDim": 2 }, + "sampler2DMSArray": { "CDim": 3, "IDim": 3, "LDim": 2 }, "float": { "Base": "float", "Dim": 1, "Vec": "vec", "Mat": "mat" }, "vec2": { "Base": "float", "Dim": 2 }, "vec3": { "Base": "float", "Dim": 3 }, @@ -24,6 +26,10 @@ traits = { "ivec2": { "Base": "int", "Dim": 2 }, "ivec3": { "Base": "int", "Dim": 3 }, "ivec4": { "Base": "int", "Dim": 4 }, + "uint": { "Base": "uint", "Dim": 1, "Vec": "uvec" }, + "uvec2": { "Base": "uint", "Dim": 2 }, + "uvec3": { "Base": "uint", "Dim": 3 }, + "uvec4": { "Base": "uint", "Dim": 4 }, "bool": { "Base": "bool", "Dim": 1, "Vec": "bvec" }, "bvec2": { "Base": "bool", "Dim": 2 }, "bvec3": { "Base": "bool", "Dim": 3 }, @@ -41,19 +47,29 @@ traits = { float32vectypes = ("vec2", "vec3", "vec4") float32types = ("float",)+float32vectypes +floatvectypes = float32vectypes floattypes = float32types -int32vectypes = ("ivec2", "ivec3", "ivec4") -int32types = ("int",)+int32vectypes -signedtypes = floattypes+int32types -arithmetictypes = signedtypes -arithmeticvectypes = float32vectypes+int32vectypes +sint32vectypes = ("ivec2", "ivec3", "ivec4") +sint32types = ("int",)+sint32vectypes +signedtypes = floattypes+sint32types +uint32vectypes = ("uvec2", "uvec3", "uvec4") +uint32types = ("uint",)+uint32vectypes +int32types = sint32types+uint32types +unsignedtypes = uint32types +arithmetictypes = signedtypes+unsignedtypes +arithmeticvectypes = float32vectypes+sint32vectypes+uint32vectypes boolvectypes = ("bvec2", "bvec3", "bvec4") squarematrixtypes = ("mat2", "mat3", "mat4") matrixtypes = squarematrixtypes+("mat2x3", "mat3x2", "mat2x4", "mat4x2", "mat3x4", "mat4x3") -flatsamplertypes = ("sampler1D", "sampler2D", "sampler3D", "sampler1DArray", "sampler2DArray") -colorsamplertypes = flatsamplertypes+("samplerCube", "samplerCubeArray") -shadowsamplertypes = ("sampler1DShadow", "sampler2DShadow", "samplerCubeShadow", "sampler1DArrayShadow", "sampler2DArrayShadow", "samplerCubeArrayShadow") -samplertypes = colorsamplertypes+shadowsamplertypes +flatdimensions = ("1D", "2D", "3D", "1DArray", "2DArray") +colordimensions = flatdimensions+("Cube", "CubeArray") +shadowdimensions = ("1DShadow", "2DShadow", "CubeShadow", "1DArrayShadow", "2DArrayShadow", "CubeArrayShadow") +msdimensions = ("2DMS", "2DMSArray") +dimensions = colordimensions+shadowdimensions +samplertypes = lambda d: tuple("sampler"+i for i in d) +imagetypes = lambda d: tuple("image"+i for i in d) +for i in colordimensions+msdimensions: + traits["image"+i] = traits["sampler"+i] shared_funcs = [ # Trigonometric ("T radians(T degrees)", float32types), @@ -91,38 +107,33 @@ shared_funcs = [ ("T ceil(T x)", floattypes), ("T fract(T x)", floattypes), ("T mod(T x, T y)", floattypes), - ("T mod(T x, T::Base y)", floattypes), - ("T modf(T x, out T y)", floattypes), + ("T mod(T x, T::Base y)", "mod(x, T(y))", floatvectypes), ("T min(T x, T y)", arithmetictypes), - ("T min(T x, T::Base y)", arithmetictypes), + ("T min(T x, T::Base y)", "min(x, T(y))", arithmeticvectypes), ("T max(T x, T y)", arithmetictypes), - ("T max(T x, T::Base y)", arithmetictypes), + ("T max(T x, T::Base y)", "max(x, T(y))", arithmeticvectypes), ("T clamp(T x, T minVal, T maxVal)", arithmetictypes), - ("T clamp(T x, T::Base minVal, T::Base maxVal)", arithmetictypes), + ("T clamp(T x, T::Base minVal, T::Base maxVal)", "clamp(x, T(minVal), T(maxVal))", arithmeticvectypes), ("T mix(T x, T y, T a)", floattypes), - ("T mix(T x, T y, T::Base a)", floattypes), + ("T mix(T x, T y, T::Base a)", "mix(x, y, T(a))", floattypes), ("T mix(T x, T y, bool[T::Dim] a)", arithmetictypes), ("T step(T edge, T x)", floattypes), - ("T step(T::Base edge, T x)", floattypes), + ("T step(T::Base edge, T x)", "step(T(edge), x)", floatvectypes), ("T smoothstep(T edge0, T edge1, T x)", floattypes), - ("T smoothstep(T::Base edge0, T::Base edge1, T x)", floattypes), + ("T smoothstep(T::Base edge0, T::Base edge1, T x)", "smoothstep(T(edge0), T(edge1), x)", floatvectypes), ("bool[T::Dim] isnan(T x)", floattypes), ("bool[T::Dim] isinf(T x)", floattypes), - ("int[T::Dim] floatBitsToInt(T value)", float32types), - ("T intBitsToFloat(int[T::Dim] value)", float32types), ("T fma(T a, T b, T c)", floattypes), - ("T frexp(T x, out int[T::Dim] exp)", floattypes), - ("T ldexp(T x, int[T::Dim] exp)", floattypes), # Geometric ("T::Base length(T x)", floattypes), ("T::Base distance(T p0, T p1)", floattypes), ("T::Base dot(T x, T y)", floattypes), - "vec3 cross(vec3 x)", + "vec3 cross(vec3 x, vec3 y)", ("T normalize(T x)", floattypes), ("T faceforward(T N, T I, T Nref)", floattypes), - ("T reflect(T N, T I)", floattypes), - ("T refract(T N, T I, float eta)", floattypes), + ("T reflect(T I, T N)", floattypes), + ("T refract(T I, T N, float eta)", floattypes), # Matrix ("T matrixCompMult(T x, T y)", matrixtypes), @@ -143,7 +154,6 @@ shared_funcs = [ ("bool not(T x)", boolvectypes), # Integer - ("void imulExtended(T x, T y, out T msb, out T lsb)", int32types), ("T bitfieldExtract(T value, int offset, int bits)", int32types), ("T bitfieldInsert(T value, T insert, int offset, int bits)", int32types), ("T bitfieldReverse(T value)", int32types), @@ -152,12 +162,24 @@ shared_funcs = [ ("int[T::Dim] findMSB(T value)", int32types), # Texture - ("int[T::IDim] textureSize(T sampler, int lod)", samplertypes), - ("vec4 texture(T sampler, float[T::CDim] P)", colorsamplertypes), - ("float texture(T sampler, float[T::CDim] P)", tuple(s for s in shadowsamplertypes if "CubeArray" not in s)), + ("int[T::IDim] textureSize(T sampler, int lod)", samplertypes(dimensions+msdimensions)), + ("vec2 textureQueryLod(T sampler, float[T::LDim] P)", samplertypes(dimensions)), + ("int textureQueryLevels(T sampler)", samplertypes(dimensions)), + ("int textureSamples(T sampler)", samplertypes(msdimensions)), + ("vec4 texture(T sampler, float[T::CDim] P)", samplertypes(colordimensions)), + ("float texture(T sampler, float[T::CDim] P)", tuple(s for s in samplertypes(shadowdimensions) if "CubeArray" not in s)), "float texture(samplerCubeArrayShadow sampler, vec4 P, float compare)", - ("vec4 textureLod(T sampler, float[T::CDim] P)", colorsamplertypes), - ("vec4 texelFetch(T sampler, int[T::CDim] P, int lod)", flatsamplertypes) + ("vec4 textureLod(T sampler, float[T::CDim] P, float lod)", samplertypes(colordimensions)), + ("vec4 texelFetch(T sampler, int[T::CDim] P, int lod)", samplertypes(flatdimensions)), + ("vec4 texelFetch(T sampler, int[T::CDim] P, int sample)", samplertypes(msdimensions)), + + # Image + ("int[T::IDim] imageSize(T image)", imagetypes(colordimensions+msdimensions)), + ("int imageSamples(T image)", imagetypes(msdimensions)), + ("vec4 imageLoad(T image, int[T::CDim] P)", imagetypes(colordimensions)), + ("vec4 imageLoad(T image, int[T::CDim] P, int sample)", imagetypes(msdimensions)), + ("void imageStore(T image, int[T::CDim] P, vec4 data)", imagetypes(colordimensions)), + ("void imageStore(T image, int[T::CDim] P, int sample, vec4 data)", imagetypes(msdimensions)) ] fragment_funcs = [ @@ -235,10 +257,9 @@ def expand_template(template, gentype): result += " " special = not t[0].isalpha() - if t==",": - result += ", " - else: - result += t + result += t + if t[-1]==",": + result += " " i += advance @@ -249,10 +270,14 @@ def generate_functions(funcs): generated = set() for f in funcs: if type(f)==tuple: - for t in f[1]: + for t in f[-1]: decl = expand_template(f[0], t) + if len(f)>=3: + decl += " {{ return {}; }}".format(expand_template(f[1], t)) + else: + decl += ";" if not decl in generated: - out_lines.append(decl+";\n") + out_lines.append(decl+"\n") generated.add(decl) else: out_lines.append(f+";\n")