Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMetalCodeGenerator.cpp (249815 => 249816)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMetalCodeGenerator.cpp 2019-09-12 20:18:07 UTC (rev 249815)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMetalCodeGenerator.cpp 2019-09-12 21:47:25 UTC (rev 249816)
@@ -58,132 +58,17 @@
"{\n"
" vec<T, Rows> columns[Cols];\n"
" private:\n"
- " template <typename U, int... R>\n"
- " static vec<T, Rows> build_col(initializer_list<U> col, _integer_sequence<int, R...>)\n"
- " {\n"
- " return {(R < col.size() ? *(col.begin() + R) : U())...};\n"
- " }\n"
- " template <int... R>\n"
- " static vec<T, Rows> build_full_col(int c, initializer_list<T> elems, _integer_sequence<int, R...>)\n"
- " {\n"
- " return {*(elems.begin() + c * Rows + R)...};\n"
- " }\n"
- " struct cols_init_tag { };\n"
- " struct cols_all_tag { };\n"
- " struct elems_all_tag { };\n"
- " template <int... C>\n"
- " inline explicit WSLMatrix(cols_init_tag, initializer_list<vec<T, Rows>> cols, _integer_sequence<int, C...>) thread\n"
- " : columns{(C < cols.size() ? *(cols.begin() + C) : vec<T, Rows>())...}\n"
- " {\n"
- " }\n"
- " template <typename... U>\n"
- " inline explicit WSLMatrix(cols_all_tag, U... cols) thread\n"
- " : columns{ cols... }\n"
- " {\n"
- " }\n"
- " template <typename... U>\n"
- " inline explicit WSLMatrix(elems_all_tag, U... elems) thread\n"
- " : WSLMatrix({T(elems)...}, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
- " template <int... C>\n"
- " inline explicit WSLMatrix(initializer_list<T> elems, _integer_sequence<int, C...>) thread\n"
- " : columns{build_full_col(C, elems, _make_integer_sequence<int, Rows>())...}\n"
- " {\n"
- " }\n"
- " template <int... C>\n"
- " inline explicit WSLMatrix(cols_init_tag, initializer_list<vec<T, Rows>> cols, _integer_sequence<int, C...>) constant\n"
- " : columns{(C < cols.size() ? *(cols.begin() + C) : vec<T, Rows>())...}\n"
- " {\n"
- " }\n"
- " template <typename... U>\n"
- " inline explicit WSLMatrix(cols_all_tag, U... cols) constant\n"
- " : columns{ cols... }\n"
- " {\n"
- " }\n"
- " template <typename... U>\n"
- " inline explicit WSLMatrix(elems_all_tag, U... elems) constant\n"
- " : WSLMatrix({T(elems)...}, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
- " template <int... C>\n"
- " inline explicit WSLMatrix(initializer_list<T> elems, _integer_sequence<int, C...>) constant\n"
- " : columns{build_full_col(C, elems, _make_integer_sequence<int, Rows>())...}\n"
- " {\n"
- " }\n"
" public:\n"
" inline WSLMatrix() thread = default;\n"
- " inline WSLMatrix(initializer_list<vec<T, Rows>> cols) thread\n"
- " : WSLMatrix(cols_init_tag(), cols, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
- " template <typename... U>\n"
- " inline explicit WSLMatrix(U... vals) thread\n"
- " : WSLMatrix(conditional_t<sizeof...(U) == Cols, cols_all_tag, elems_all_tag>(), vals...)\n"
- " {\n"
- " }\n"
" inline WSLMatrix() constant = default;\n"
- " inline WSLMatrix(initializer_list<vec<T, Rows>> cols) constant\n"
- " : WSLMatrix(cols_init_tag(), cols, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
- " inline explicit WSLMatrix(T val) constant\n"
- " : WSLMatrix(val, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
- " template <typename... U>\n"
- " inline explicit WSLMatrix(U... vals) constant\n"
- " : WSLMatrix(conditional_t<sizeof...(U) == Cols, cols_all_tag, elems_all_tag>(), vals...)\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const thread WSLMatrix<T, Cols, Rows> &that) thread = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const thread WSLMatrix<U, Cols, Rows> &that) thread\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const device WSLMatrix<T, Cols, Rows> &that) thread = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const device WSLMatrix<U, Cols, Rows> &that) thread\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const constant WSLMatrix<T, Cols, Rows> &that) thread = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const constant WSLMatrix<U, Cols, Rows> &that) thread\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const threadgroup WSLMatrix<T, Cols, Rows> &that) thread = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const threadgroup WSLMatrix<U, Cols, Rows> &that) thread\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const thread WSLMatrix<T, Cols, Rows> &that) constant = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const thread WSLMatrix<U, Cols, Rows> &that) constant\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const device WSLMatrix<T, Cols, Rows> &that) constant = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const device WSLMatrix<U, Cols, Rows> &that) constant\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const constant WSLMatrix<T, Cols, Rows> &that) constant = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const constant WSLMatrix<U, Cols, Rows> &that) constant\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" inline WSLMatrix(const threadgroup WSLMatrix<T, Cols, Rows> &that) constant = default;\n"
- " template <typename U>\n"
- " inline explicit WSLMatrix(const threadgroup WSLMatrix<U, Cols, Rows> &that) constant\n"
- " : WSLMatrix(that, _make_integer_sequence<int, Cols>())\n"
- " {\n"
- " }\n"
" public:\n"
" inline thread vec<T, Rows> &operator[](int r) thread\n"
" {\n"
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp (249815 => 249816)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp 2019-09-12 20:18:07 UTC (rev 249815)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp 2019-09-12 21:47:25 UTC (rev 249816)
@@ -182,13 +182,33 @@
}
if (auto* matrixType = asMatrixType(returnType)) {
- stringBuilder.append(metalReturnTypeName, '(');
- for (size_t i = 0; i < args.size(); ++i) {
- if (i)
- stringBuilder.append(", ");
- stringBuilder.append(args[i]);
+ // We're either constructing with all individual elements, or with
+ // vectors for each column.
+
+ stringBuilder.append('(');
+ if (args.size() == matrixType->numberOfMatrixColumns()) {
+ // Constructing with vectors for each column.
+ for (size_t i = 0; i < args.size(); ++i) {
+ if (i)
+ stringBuilder.append(", ");
+ stringBuilder.append(resultName, ".columns[", i, "] = ", args[i]);
+ }
+ } else {
+ // Constructing with all elements.
+ RELEASE_ASSERT(args.size() == matrixType->numberOfMatrixColumns() * matrixType->numberOfMatrixRows());
+
+ size_t argNumber = 0;
+ for (size_t i = 0; i < matrixType->numberOfMatrixColumns(); ++i) {
+ for (size_t j = 0; j < matrixType->numberOfMatrixRows(); ++j) {
+ if (argNumber)
+ stringBuilder.append(", ");
+ stringBuilder.append(resultName, ".columns[", i, "][", j, "] = ", args[argNumber]);
+ ++argNumber;
+ }
+ }
}
- stringBuilder.append(')');
+
+ stringBuilder.append(", ", resultName, ')');
return;
}