Supports writing a matrix to a matrix, regardless of size of src and dst.
| 191 | |
| 192 | // Supports writing a matrix to a matrix, regardless of size of src and dst. |
| 193 | static void WriteMatrixToMatrix(uint8_t* write_ptr, const UnpackAttributeData& src_data, const UnpackAttributeData& dst_data) |
| 194 | { |
| 195 | const uint32_t dst_element_byte_width = DataTypeToByteWidth(dst_data.m_DataType); |
| 196 | const uint32_t src_element_byte_width = DataTypeToByteWidth(src_data.m_DataType); |
| 197 | const uint32_t dst_row_col_count = VectorTypeToMatrixRowColCount(dst_data.m_VectorType); |
| 198 | const uint32_t src_row_col_count = VectorTypeToMatrixRowColCount(src_data.m_VectorType); |
| 199 | |
| 200 | // Case 1: No matrix size conversion needed, source and destination element counts are the same |
| 201 | if (src_data.m_ElementCount == dst_data.m_ElementCount) |
| 202 | { |
| 203 | if (src_data.m_DataType == dst_data.m_DataType) |
| 204 | { |
| 205 | memcpy(write_ptr, src_data.m_ValuePtr, dst_data.m_ElementCount * dst_element_byte_width); |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | for (uint32_t i = 0; i < dst_data.m_ElementCount; ++i) |
| 210 | { |
| 211 | float float_value = VertexAttributeDataTypeToFloat(src_data.m_DataType, src_data.m_ValuePtr + i * src_element_byte_width); |
| 212 | |
| 213 | write_ptr = WriteVertexAttributeFromFloat(write_ptr, float_value, dst_data.m_DataType); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | // Case 2: Converting from larger to smaller matrix (use top-left portion) |
| 218 | else if (src_data.m_ElementCount > dst_data.m_ElementCount) |
| 219 | { |
| 220 | for (uint32_t row = 0; row < dst_row_col_count; ++row) |
| 221 | { |
| 222 | for (uint32_t col = 0; col < dst_row_col_count; ++col) |
| 223 | { |
| 224 | const uint32_t src_index = row * src_row_col_count + col; |
| 225 | |
| 226 | if (src_data.m_DataType == dst_data.m_DataType) |
| 227 | { |
| 228 | memcpy(write_ptr, src_data.m_ValuePtr + src_index * src_element_byte_width, dst_element_byte_width); |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | float float_value = VertexAttributeDataTypeToFloat(src_data.m_DataType, src_data.m_ValuePtr + src_index * src_element_byte_width); |
| 233 | |
| 234 | write_ptr = WriteVertexAttributeFromFloat(write_ptr, float_value, dst_data.m_DataType); |
| 235 | } |
| 236 | |
| 237 | write_ptr += dst_element_byte_width; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | // Case 3: Converting from a matrix to a larger matrix will write into the top-left portion of the destination matrix, and fill the remaining space with the identity matrix. |
| 242 | else |
| 243 | { |
| 244 | uint8_t* read_ptr = (uint8_t*) src_data.m_ValuePtr; |
| 245 | for (int row = 0; row < dst_row_col_count; ++row) |
| 246 | { |
| 247 | for (int col = 0; col < dst_row_col_count; ++col) |
| 248 | { |
| 249 | // Use source matrix values in the top-left portion |
| 250 | if (row < src_row_col_count && col < src_row_col_count) |
no test coverage detected