+void SpirVGenerator::visit_builtin_texture_fetch(FunctionCall &call, const vector<Id> &argument_ids)
+{
+ ImageTypeDeclaration &image = dynamic_cast<ImageTypeDeclaration &>(*call.arguments[0]->type);
+
+ Opcode opcode;
+ if(call.name=="texelFetch")
+ opcode = OP_IMAGE_FETCH;
+ else if(call.name=="imageLoad")
+ opcode = OP_IMAGE_READ;
+ else
+ throw internal_error("invalid texture fetch call");
+
+ bool need_sample = image.multisample;
+ bool need_lod = (opcode==OP_IMAGE_FETCH && !need_sample);
+
+ 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);
+ writer.write(image_id);
+ writer.write(argument_ids[1]);
+ 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_texture_store(FunctionCall &call, const vector<Id> &argument_ids)