]> git.tdb.fi Git - libs/gl.git/commitdiff
Implement other texture query functions for GLSL
authorMikko Rasa <tdb@tdb.fi>
Wed, 28 Apr 2021 11:43:33 +0000 (14:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 28 Apr 2021 12:28:25 +0000 (15:28 +0300)
builtin_data/_builtin.glsl
scripts/builtin_funcs.py
source/glsl/spirv.cpp
source/glsl/spirvconstants.h

index 94a7ca696c4f9d5187f15a5cd8abbc9656b5c737..c8336d9a18e12f05dc3a468023fecd7747e0d7fb 100644 (file)
@@ -471,6 +471,32 @@ ivec2 textureSize(samplerCubeShadow sampler, int lod);
 ivec2 textureSize(sampler1DArrayShadow sampler, int lod);
 ivec3 textureSize(sampler2DArrayShadow sampler, int lod);
 ivec3 textureSize(samplerCubeArrayShadow sampler, int lod);
+vec2 textureQueryLod(sampler1D sampler, float P);
+vec2 textureQueryLod(sampler2D sampler, vec2 P);
+vec2 textureQueryLod(sampler3D sampler, vec3 P);
+vec2 textureQueryLod(sampler1DArray sampler, float P);
+vec2 textureQueryLod(sampler2DArray sampler, vec2 P);
+vec2 textureQueryLod(samplerCube sampler, vec3 P);
+vec2 textureQueryLod(samplerCubeArray sampler, vec3 P);
+vec2 textureQueryLod(sampler1DShadow sampler, float P);
+vec2 textureQueryLod(sampler2DShadow sampler, vec2 P);
+vec2 textureQueryLod(samplerCubeShadow sampler, vec3 P);
+vec2 textureQueryLod(sampler1DArrayShadow sampler, float P);
+vec2 textureQueryLod(sampler2DArrayShadow sampler, vec2 P);
+vec2 textureQueryLod(samplerCubeArrayShadow sampler, vec3 P);
+int textureQueryLevels(sampler1D sampler);
+int textureQueryLevels(sampler2D sampler);
+int textureQueryLevels(sampler3D sampler);
+int textureQueryLevels(sampler1DArray sampler);
+int textureQueryLevels(sampler2DArray sampler);
+int textureQueryLevels(samplerCube sampler);
+int textureQueryLevels(samplerCubeArray sampler);
+int textureQueryLevels(sampler1DShadow sampler);
+int textureQueryLevels(sampler2DShadow sampler);
+int textureQueryLevels(samplerCubeShadow sampler);
+int textureQueryLevels(sampler1DArrayShadow sampler);
+int textureQueryLevels(sampler2DArrayShadow sampler);
+int textureQueryLevels(samplerCubeArrayShadow sampler);
 vec4 texture(sampler1D sampler, float P);
 vec4 texture(sampler2D sampler, vec2 P);
 vec4 texture(sampler3D sampler, vec3 P);
index ef19d54fd9162d9e4bf92cfa94d22dfcac648c83..bf5198f5831478730d1a8696c84a29d04b87e3ae 100755 (executable)
@@ -3,19 +3,19 @@
 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 },
        "float": { "Base": "float", "Dim": 1, "Vec": "vec", "Mat": "mat" },
        "vec2": { "Base": "float", "Dim": 2 },
        "vec3": { "Base": "float", "Dim": 3 },
@@ -156,6 +156,8 @@ shared_funcs = [
 
        # Texture
        ("int[T::IDim] textureSize(T sampler, int lod)", samplertypes),
+       ("vec2 textureQueryLod(T sampler, float[T::LDim] P)", samplertypes),
+       ("int textureQueryLevels(T sampler)", 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)),
        "float texture(samplerCubeArrayShadow sampler, vec4 P, float compare)",
index 186521c5efe109b1bfcb1f6d331cfb666f2617fa..63c76f9a2233050851e9491af42855ee9f0e8a8c 100644 (file)
@@ -108,6 +108,8 @@ const SpirVGenerator::BuiltinFunctionInfo SpirVGenerator::builtin_functions[] =
        { "findMSB", "i", "GLSL.std.450", GLSL450_FIND_S_MSB, { 1 }, 0, 0 },
        { "findMSB", "u", "GLSL.std.450", GLSL450_FIND_U_MSB, { 1 }, 0, 0 },
        { "textureSize", "", "", 0, { }, CAP_IMAGE_QUERY, &SpirVGenerator::visit_builtin_texture_query },
+       { "textureQueryLod", "", "", 0, { }, CAP_IMAGE_QUERY, &SpirVGenerator::visit_builtin_texture_query },
+       { "textureQueryLevels", "", "", 0, { }, CAP_IMAGE_QUERY, &SpirVGenerator::visit_builtin_texture_query },
        { "texture", "", "", 0, { }, 0, &SpirVGenerator::visit_builtin_texture },
        { "textureLod", "", "", 0, { }, 0, &SpirVGenerator::visit_builtin_texture },
        { "texelFetch", "", "", 0, { }, 0, &SpirVGenerator::visit_builtin_texel_fetch },
@@ -1292,6 +1294,10 @@ void SpirVGenerator::visit_builtin_texture_query(FunctionCall &call, const vecto
        Opcode opcode;
        if(call.name=="textureSize")
                opcode = OP_IMAGE_QUERY_SIZE_LOD;
+       else if(call.name=="textureQueryLod")
+               opcode = OP_IMAGE_QUERY_LOD;
+       else if(call.name=="textureQueryLevels")
+               opcode = OP_IMAGE_QUERY_LEVELS;
        else
                throw internal_error("invalid texture query call");
 
index 3d424844e6d6975bf59e9013e08dc536a4a00a44..661839053544d7e762d640fac159073cc57392da 100644 (file)
@@ -66,6 +66,8 @@ enum SpirVOpcode
        OP_IMAGE_FETCH = 95,
        OP_IMAGE = 100,
        OP_IMAGE_QUERY_SIZE_LOD = 103,
+       OP_IMAGE_QUERY_LOD = 105,
+       OP_IMAGE_QUERY_LEVELS = 106,
        OP_CONVERT_F_TO_U = 109,
        OP_CONVERT_F_TO_S = 110,
        OP_CONVERT_S_TO_F = 111,