]> git.tdb.fi Git - libs/gl.git/commitdiff
Preparatory refactoring of the texelFetch implementation
authorMikko Rasa <tdb@tdb.fi>
Mon, 11 Apr 2022 11:35:16 +0000 (14:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 11 Apr 2022 11:37:30 +0000 (14:37 +0300)
source/glsl/spirv.cpp

index f8b36b26dbe03885f2f6bfb6b3259d4cc0511dc5..61e5937856b30d7abc38afc2d5143b03e1ca4b1e 100644 (file)
@@ -1371,17 +1371,25 @@ void SpirVGenerator::visit_builtin_texture(FunctionCall &call, const vector<Id>
 
 void SpirVGenerator::visit_builtin_texel_fetch(FunctionCall &call, const vector<Id> &argument_ids)
 {
-       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);
+       Opcode opcode = OP_IMAGE_FETCH;
+
+       bool need_sample = image.multisample;
+       bool need_lod = !need_sample;
+
+       if(argument_ids.size()!=2U+need_sample+need_lod)
+               throw internal_error("invalid texture fetch call");
+
+       r_expression_result_id = begin_expression(opcode, get_id(*call.type), 2+(need_lod|need_sample)+need_lod+need_sample);
        for(unsigned i=0; i<2; ++i)
                writer.write(argument_ids[i]);
-       writer.write(image.multisample ? 0x40 : 0x02);  // Sample or Lod
-       writer.write(argument_ids.back());
-       end_expression(OP_IMAGE_FETCH);
+       if(need_lod || need_sample)
+       {
+               writer.write(need_lod*0x02 | need_sample*0x40);
+               writer.write(argument_ids.back());
+       }
+       end_expression(opcode);
 }
 
 void SpirVGenerator::visit_builtin_interpolate(FunctionCall &call, const vector<Id> &argument_ids)