]> git.tdb.fi Git - libs/gl.git/commitdiff
Add multisampled texture types to the shader compiler
authorMikko Rasa <tdb@tdb.fi>
Sun, 10 Apr 2022 10:03:20 +0000 (13:03 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 10 Apr 2022 10:03:20 +0000 (13:03 +0300)
builtin_data/_builtin.glsl
scripts/builtin_funcs.py
source/glsl/debug.cpp
source/glsl/parser.cpp
source/glsl/reflect.cpp
source/glsl/spirv.cpp
source/glsl/spirvconstants.h
source/glsl/syntax.h

index 1bdfde13306cb347c061dd29d85a7dbb0acb9f77..b671f944df83da4960a5809fc4b28ab4f07839ff 100644 (file)
@@ -39,6 +39,8 @@ typedef image(dimensions=1[], shadow, sampled) float sampler1DArrayShadow;
 typedef image(dimensions=2[], shadow, sampled) float sampler2DArrayShadow;
 typedef image(dimensions=cube, shadow, sampled) float samplerCubeShadow;
 typedef image(dimensions=cube[], shadow, sampled) float samplerCubeArrayShadow;
+typedef image(dimensions=2, sampled, multisample) float sampler2DMS;
+typedef image(dimensions=2[], sampled, multisample) float sampler2DMSArray;
 
 const float PI = 3.1415926535;
 
@@ -473,6 +475,8 @@ ivec2 textureSize(samplerCubeShadow sampler, int lod);
 ivec2 textureSize(sampler1DArrayShadow sampler, int lod);
 ivec3 textureSize(sampler2DArrayShadow sampler, int lod);
 ivec3 textureSize(samplerCubeArrayShadow sampler, int lod);
+ivec2 textureSize(sampler2DMS sampler, int lod);
+ivec3 textureSize(sampler2DMSArray sampler, int lod);
 vec2 textureQueryLod(sampler1D sampler, float P);
 vec2 textureQueryLod(sampler2D sampler, vec2 P);
 vec2 textureQueryLod(sampler3D sampler, vec3 P);
@@ -499,6 +503,8 @@ int textureQueryLevels(samplerCubeShadow sampler);
 int textureQueryLevels(sampler1DArrayShadow sampler);
 int textureQueryLevels(sampler2DArrayShadow sampler);
 int textureQueryLevels(samplerCubeArrayShadow sampler);
+int textureSamples(sampler2DMS sampler);
+int textureSamples(sampler2DMSArray sampler);
 vec4 texture(sampler1D sampler, float P);
 vec4 texture(sampler2D sampler, vec2 P);
 vec4 texture(sampler3D sampler, vec3 P);
@@ -524,6 +530,8 @@ vec4 texelFetch(sampler2D sampler, ivec2 P, int lod);
 vec4 texelFetch(sampler3D sampler, ivec3 P, int lod);
 vec4 texelFetch(sampler1DArray sampler, ivec2 P, int lod);
 vec4 texelFetch(sampler2DArray sampler, ivec3 P, int lod);
+vec4 texelFetch(sampler2DMS sampler, ivec2 P, int sample);
+vec4 texelFetch(sampler2DMSArray sampler, ivec3 P, int sample);
 // END BUILTIN FUNCTIONS
 
 #pragma MSP stage(vertex)
index bf5198f5831478730d1a8696c84a29d04b87e3ae..5ff3a57fc68150e58bbc6378f6063b93a449c634 100755 (executable)
@@ -16,6 +16,8 @@ traits = {
        "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 },
@@ -62,6 +64,7 @@ matrixtypes = squarematrixtypes+("mat2x3", "mat3x2", "mat2x4", "mat4x2", "mat3x4
 flatsamplertypes = ("sampler1D", "sampler2D", "sampler3D", "sampler1DArray", "sampler2DArray")
 colorsamplertypes = flatsamplertypes+("samplerCube", "samplerCubeArray")
 shadowsamplertypes = ("sampler1DShadow", "sampler2DShadow", "samplerCubeShadow", "sampler1DArrayShadow", "sampler2DArrayShadow", "samplerCubeArrayShadow")
+mssamplertypes = ("sampler2DMS", "sampler2DMSArray")
 samplertypes = colorsamplertypes+shadowsamplertypes
 shared_funcs = [
        # Trigonometric
@@ -155,14 +158,16 @@ shared_funcs = [
        ("int[T::Dim] findMSB(T value)", int32types),
 
        # Texture
-       ("int[T::IDim] textureSize(T sampler, int lod)", samplertypes),
+       ("int[T::IDim] textureSize(T sampler, int lod)", samplertypes+mssamplertypes),
        ("vec2 textureQueryLod(T sampler, float[T::LDim] P)", samplertypes),
        ("int textureQueryLevels(T sampler)", samplertypes),
+       ("int textureSamples(T sampler)", mssamplertypes),
        ("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)",
        ("vec4 textureLod(T sampler, float[T::CDim] P, float lod)", colorsamplertypes),
-       ("vec4 texelFetch(T sampler, int[T::CDim] P, int lod)", flatsamplertypes)
+       ("vec4 texelFetch(T sampler, int[T::CDim] P, int lod)", flatsamplertypes),
+       ("vec4 texelFetch(T sampler, int[T::CDim] P, int sample)", mssamplertypes)
 ]
 
 fragment_funcs = [
index 60b7c2477cf093664f4fc2ac8bcfdb52f56fb5b1..c741ed57665b2dfae993073c13b387fcec61b0aa 100644 (file)
@@ -357,6 +357,8 @@ void DumpTree::visit(ImageTypeDeclaration &type)
                branches.emplace_back(format("Element type: %s %s", get_label(*type.base_type), format_type(type.base_type->name)));
        if(type.shadow)
                branches.emplace_back("Shadow");
+       if(type.multisample)
+               branches.emplace_back("Multisample");
        append_subtree(branches);
 }
 
index ca1f3156d1179b1bd1e9091bdf645e9184e10b67..d210cee9fe7d97c97dc48e90ec2f3b43ec6a6209 100644 (file)
@@ -707,6 +707,8 @@ RefPtr<ImageTypeDeclaration> Parser::parse_image_type_declaration()
                        type->sampled = true;
                else if(token=="shadow")
                        type->shadow = true;
+               else if(token=="multisample")
+                       type->multisample = true;
                else
                        throw parse_error(tokenizer.get_location(), token, "image type attribute");
 
index 643c42e79be90f51f07009df7343ce67df80f09e..64dbbf6e0e140ddc47385b75f6a966a2658fea8b 100644 (file)
@@ -178,7 +178,7 @@ void TypeComparer::visit(ImageTypeDeclaration &image)
        {
                if(image1->dimensions!=image.dimensions || image1->array!=image.array)
                        r_result = false;
-               else if(image1->sampled!=image.sampled || image1->shadow!=image.shadow)
+               else if(image1->sampled!=image.sampled || image1->shadow!=image.shadow || image1->multisample!=image.multisample)
                        r_result = false;
                else if(image1->base_type && image.base_type)
                        compare(*image1->base_type, *image.base_type);
index c6f15614f5c8a56a36c7e7236a1c785f081e0a19..61e2d594e6c641105379dfd6c671a82b1991f5fa 100644 (file)
@@ -111,6 +111,7 @@ const SpirVGenerator::BuiltinFunctionInfo SpirVGenerator::builtin_functions[] =
        { "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 },
+       { "textureSamples", "", "", 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 },
@@ -1295,6 +1296,8 @@ void SpirVGenerator::visit_builtin_texture_query(FunctionCall &call, const vecto
                opcode = OP_IMAGE_QUERY_LOD;
        else if(call.name=="textureQueryLevels")
                opcode = OP_IMAGE_QUERY_LEVELS;
+       else if(call.name=="textureSamples")
+               opcode = OP_IMAGE_QUERY_SAMPLES;
        else
                throw internal_error("invalid texture query call");
 
@@ -1371,10 +1374,12 @@ void SpirVGenerator::visit_builtin_texel_fetch(FunctionCall &call, const vector<
        if(argument_ids.size()!=3)
                throw internal_error("invalid texelFetch call");
 
+       const ImageTypeDeclaration &image = dynamic_cast<const ImageTypeDeclaration &>(*call.arguments[0]->type);
+
        r_expression_result_id = begin_expression(OP_IMAGE_FETCH, get_id(*call.type), 4);
        for(unsigned i=0; i<2; ++i)
                writer.write(argument_ids[i]);
-       writer.write(2);  // Lod
+       writer.write(image.multisample ? 0x40 : 0x02);  // Sample or Lod
        writer.write(argument_ids.back());
        end_expression(OP_IMAGE_FETCH);
 }
@@ -1492,7 +1497,7 @@ void SpirVGenerator::visit(ImageTypeDeclaration &image)
        writer.write(image.dimensions-1);
        writer.write(image.shadow);
        writer.write(image.array);
-       writer.write(false);  // Multisample
+       writer.write(image.multisample);
        writer.write(image.sampled ? 1 : 2);
        writer.write(0);  // Format (unknown)
        writer.end_op(OP_TYPE_IMAGE);
index aa164b87c1d803ec27ad74a080fd7f39a391bcbb..64daa9ff01a58f60a92b2ca54669f1f9ac026b73 100644 (file)
@@ -68,6 +68,7 @@ enum SpirVOpcode
        OP_IMAGE_QUERY_SIZE_LOD = 103,
        OP_IMAGE_QUERY_LOD = 105,
        OP_IMAGE_QUERY_LEVELS = 106,
+       OP_IMAGE_QUERY_SAMPLES = 107,
        OP_CONVERT_F_TO_U = 109,
        OP_CONVERT_F_TO_S = 110,
        OP_CONVERT_S_TO_F = 111,
index bb00218314053443e3f062e8b251107f1cdad006..b6a118d695218c0652624170d5107546857c6e8c 100644 (file)
@@ -366,6 +366,7 @@ struct ImageTypeDeclaration: TypeDeclaration
        bool array = false;
        bool sampled = true;
        bool shadow = false;
+       bool multisample = false;
        std::string base;
 
        TypeDeclaration *base_type = 0;