From: Mikko Rasa Date: Wed, 28 Apr 2021 11:43:33 +0000 (+0300) Subject: Implement other texture query functions for GLSL X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=e0caeb9be47bc140978552bb7149f1c9c8c973db Implement other texture query functions for GLSL --- diff --git a/builtin_data/_builtin.glsl b/builtin_data/_builtin.glsl index 94a7ca69..c8336d9a 100644 --- a/builtin_data/_builtin.glsl +++ b/builtin_data/_builtin.glsl @@ -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); diff --git a/scripts/builtin_funcs.py b/scripts/builtin_funcs.py index ef19d54f..bf5198f5 100755 --- a/scripts/builtin_funcs.py +++ b/scripts/builtin_funcs.py @@ -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)", diff --git a/source/glsl/spirv.cpp b/source/glsl/spirv.cpp index 186521c5..63c76f9a 100644 --- a/source/glsl/spirv.cpp +++ b/source/glsl/spirv.cpp @@ -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"); diff --git a/source/glsl/spirvconstants.h b/source/glsl/spirvconstants.h index 3d424844..66183905 100644 --- a/source/glsl/spirvconstants.h +++ b/source/glsl/spirvconstants.h @@ -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,