Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-10033

Force QVector4D to be 16-byte aligned where possible to allow for SIMD optimization

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • Some future release
    • GUI: OpenGL
    • None
    • Any MMX/SSE enabled processor

    Description

      Currently all vector operations in Qt3d are not SIMD accelerated, unless automatic vectorization is enabled in compilers supporting it (Intel, GNU).

      However, SSE instructions require the data to be 16-byte aligned in memory.
      QVector4D currently has a size of 16-byte (good, no vtable) on both GCC 4.3 and Visual C++ 2010, but is 4-byte aligned on both, which
      makes it generally SIMD incompatible (see http://www.agner.org/optimize/#manual_cpp).

      I used __alignof(Type) and sizeof(Type) to test this on both platforms.

      To make QVector4D suitable for SIMD acceleration (this also applies to the other vector types, but wastes more memory for arrays of QVector3D's if they are 16-byte aligned), it can be declared as follows on MSVC:

       
      class __declspec(align(16)) QVector4D { ... }
      

      and on GCC the following declaration forces it to 16 byte alignment:

       class __attribute__((aligned(16))) QVector4D { ... }

      This is the most basic requirement for SSE support, which would at least allow developers to implement SSE-based 3d math in terms of QVector4D.

      Using SIMD for QMatrix4x4 is more problematic since it uses qreal internally, which is by default defined as double. Personally I am using a Qt compiled with QT_COORD_TYPE=float, which solves this problem for me, but still leaves memory alignment issues, which cannot easily be solved by the alignment attributes since QMatrix4x4 stores an extra integer for flagBits. While it is feasible that using SIMD accelerated operations outweighs the benefit gained from flagBits, but this needs more testing.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            shartte Sebastian Hartte
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes