46
QString halideTypeName(Halide::Type type)
50
if (type.is_vector()) {
56
} else if (type.is_handle()) {
57
name += "handle (void *)";
59
if (type.is_float()) {
61
} else if (type.is_int()) {
63
} else if (type.is_uint()) {
64
name += "unsigned int";
66
name += QString(" (%1 bits)").arg(type.bits);
72
QString halideTypeToQmlType(Halide::Type type, bool& possibleOverflow)
75
possibleOverflow = false;
77
if (type.is_vector()) {
83
} else if (type.is_handle()) {
85
} else if (type.is_float()) {
87
possibleOverflow = type.bits < (int)sizeof(double);
88
} else if (type.is_int() || type.is_uint()) {
90
possibleOverflow = type.bits < (int)sizeof(int);
96
Halide::Type qMetaTypeToHalideType(int qMetaType)
100
return Halide::type_of<bool>();
103
return Halide::type_of<int>();
105
case QMetaType::SChar:
106
case QMetaType::Char:
107
return Halide::type_of<int8_t>();
109
case QMetaType::Short:
110
return Halide::type_of<short>();
112
case QMetaType::Long:
113
return Halide::type_of<long>();
115
case QMetaType::LongLong:
116
return Halide::type_of<int64_t>();
118
case QMetaType::UInt:
119
return Halide::type_of<unsigned int>();
121
case QMetaType::UChar:
122
return Halide::type_of<unsigned char>();
124
case QMetaType::UShort:
125
return Halide::type_of<unsigned short>();
127
case QMetaType::ULong:
128
return Halide::type_of<unsigned long>();
130
case QMetaType::ULongLong:
131
return Halide::type_of<uint64_t>();
133
case QMetaType::Float:
134
return Halide::type_of<float>();
136
case QMetaType::Double:
137
return Halide::type_of<double>();
148
QString halideArgumentToQmlType(const Halide::Argument& argument, bool& possibleOverflow)
150
if (argument.is_buffer) {
151
return "HalideImage";
153
return halideTypeToQmlType(argument.type, possibleOverflow);
157
bool isHalideArgumentCompatible(const Halide::Argument& argument, int qMetaType)
159
if (argument.is_buffer) {
160
return qMetaType == qMetaTypeId<HalideImage*>();
162
if (argument.type.code == Halide::Type::TypeCode::UInt && qMetaType == QMetaType::Int) {
163
// FIXME: this is a workaround to allow QML int to represent
164
// generators' unsigned int parameters; necessary due to the lack of
165
// unsigned int in QML
168
return qMetaTypeToHalideType(qMetaType).can_represent(argument.type);
173
QString halideArgumentTypeName(const Halide::Argument& argument)
175
if (argument.is_buffer) {
178
return halideTypeName(argument.type);
46
183
void HalideFunction::matchPropertiesToArguments(const std::vector<Halide::Argument>& arguments)
48
185
m_signalMappers.clear();
53
190
int propertyIndex = meta->indexOfProperty(argument.name.c_str());
54
191
QString propertyName = QString::fromStdString(argument.name);
55
192
m_propertiesValid[propertyName] = false;
56
// FIXME: should check that the type of the property is compatible with the type of the parameter
193
bool possibleOverflow;
194
QString expectedQmlType = halideArgumentToQmlType(argument, possibleOverflow);
195
QString argumentTypeName = halideArgumentTypeName(argument);
57
196
if (propertyIndex == -1) {
58
// FIXME: convert type.code to human readable format
59
qWarning() << "Missing property" << propertyName << "of type" << argument.type.code;
197
qWarning().noquote() << QString("HalideFunction '%1' is missing property '%2' of type %3.")
200
.arg(expectedQmlType);
61
m_propertiesValid[propertyName] = isPropertyValid(propertyName);
62
connectToPropertyChange(propertyName);
202
int propertyType = meta->property(propertyIndex).userType();
203
if (isHalideArgumentCompatible(argument, propertyType)) {
204
m_propertiesValid[propertyName] = isPropertyValid(propertyName);
205
connectToPropertyChange(propertyName);
207
QString propertyTypeName = QMetaType::typeName(propertyType);
208
qWarning().noquote() << QString("HalideFunction '%1': property '%2' is of type %3 incompatible "
209
"with generator parameter of Halide type %4. Type should be %5.")
212
.arg(propertyTypeName)
213
.arg(argumentTypeName)
214
.arg(expectedQmlType);
217
if (possibleOverflow) {
218
qWarning() << QString("Conversion from QML %1 to %2 could overflow").arg(expectedQmlType).arg(argumentTypeName);
65
221
updateAllPropertiesValid();