{ "findLSB", "u", "GLSL.std.450", GLSL450_FIND_I_LSB, { 1 }, 0, 0 },
{ "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", "", "", OP_IMAGE_QUERY_SIZE_LOD, { 1, 2 }, CAP_IMAGE_QUERY, 0 },
+ { "textureSize", "", "", 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 },
r_expression_result_id = write_construct(get_id(*call.type), column_ids, n_columns);
}
+void SpirVGenerator::visit_builtin_texture_query(FunctionCall &call, const vector<Id> &argument_ids)
+{
+ if(argument_ids.size()<1)
+ throw internal_error("invalid texture query call");
+
+ Opcode opcode;
+ if(call.name=="textureSize")
+ opcode = OP_IMAGE_QUERY_SIZE_LOD;
+ else
+ throw internal_error("invalid texture query call");
+
+ ImageTypeDeclaration &image_arg0 = dynamic_cast<ImageTypeDeclaration &>(*call.arguments[0]->type);
+
+ Id image_id;
+ if(image_arg0.sampled)
+ {
+ Id image_type_id = get_item(image_type_ids, get_id(image_arg0));
+ image_id = write_expression(OP_IMAGE, image_type_id, argument_ids[0]);
+ }
+ else
+ image_id = argument_ids[0];
+
+ Id result_type_id = get_id(*call.type);
+ r_expression_result_id = begin_expression(opcode, result_type_id, argument_ids.size());
+ writer.write(image_id);
+ for(unsigned i=1; i<argument_ids.size(); ++i)
+ writer.write(argument_ids[i]);
+ end_expression(opcode);
+}
+
void SpirVGenerator::visit_builtin_texture(FunctionCall &call, const vector<Id> &argument_ids)
{
if(argument_ids.size()<2)
{
writer.write_op_name(type_id, image.name);
writer.write_op(content.globals, OP_TYPE_SAMPLED_IMAGE, type_id, image_id);
+ insert_unique(image_type_ids, type_id, image_id);
}
if(image.dimensions==ImageTypeDeclaration::ONE)
std::map<Node *, Declaration> declared_ids;
std::map<std::string, Id> declared_uniform_ids;
std::map<TypeKey, Id> standard_type_ids;
+ std::map<Id, Id> image_type_ids;
std::map<TypeKey, Id> array_type_ids;
std::map<TypeKey, Id> pointer_type_ids;
std::map<std::string, Id> function_type_ids;
virtual void visit(FunctionCall &);
void visit_constructor(FunctionCall &, const std::vector<Id> &, bool);
void visit_builtin_matrix_comp_mult(FunctionCall &, const std::vector<Id> &);
+ void visit_builtin_texture_query(FunctionCall &, const std::vector<Id> &);
void visit_builtin_texture(FunctionCall &, const std::vector<Id> &);
void visit_builtin_texel_fetch(FunctionCall &, const std::vector<Id> &);
void visit_builtin_interpolate(FunctionCall &, const std::vector<Id> &);