]> git.tdb.fi Git - libs/gl.git/commitdiff
Pass a non-sampled image to OP_IMAGE_FETCH
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2022 11:52:56 +0000 (14:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2022 11:52:56 +0000 (14:52 +0300)
source/glsl/spirv.cpp

index b86734f623365e1724a8ec430d33d0cc5e67fbdf..1fc9799ff6418ee7b153610f47c71465fb53c876 100644 (file)
@@ -1443,7 +1443,7 @@ void SpirVGenerator::visit_builtin_texture(FunctionCall &call, const vector<Id>
 
 void SpirVGenerator::visit_builtin_texture_fetch(FunctionCall &call, const vector<Id> &argument_ids)
 {
-       const ImageTypeDeclaration &image = dynamic_cast<const ImageTypeDeclaration &>(*call.arguments[0]->type);
+       ImageTypeDeclaration &image = dynamic_cast<ImageTypeDeclaration &>(*call.arguments[0]->type);
 
        Opcode opcode;
        if(call.name=="texelFetch")
@@ -1459,9 +1459,18 @@ void SpirVGenerator::visit_builtin_texture_fetch(FunctionCall &call, const vecto
        if(argument_ids.size()!=2U+need_sample+need_lod)
                throw internal_error("invalid texture fetch call");
 
+       Id image_id;
+       if(image.sampled)
+       {
+               Id image_type_id = get_item(image_type_ids, get_id(image));
+               image_id = write_expression(OP_IMAGE, image_type_id, argument_ids[0]);
+       }
+       else
+               image_id = argument_ids[0];
+
        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_id);
+       writer.write(argument_ids[1]);
        if(need_lod || need_sample)
        {
                writer.write(need_lod*0x02 | need_sample*0x40);