Changeset 249214 in webkit


Ignore:
Timestamp:
Aug 28, 2019 12:46:36 PM (5 years ago)
Author:
mmaxfield@apple.com
Message:

[WHLSL] Matrices need to have correct alignment
https://bugs.webkit.org/show_bug.cgi?id=201212

Reviewed by Robin Morisset.

Source/WebCore:

Matrices have particular alignment requirements and size requirements.

Type | Alignment | Size


float2x2 | 8 | 16
float2x3 | 16 | 32
float2x4 | 16 | 32
float3x2 | 8 | 24
float3x3 | 16 | 48
float3x4 | 16 | 48
float4x2 | 8 | 32
float4x3 | 16 | 64
float4x4 | 16 | 64

These are important because they may be a member of a struct, and we don't want to misplace
every successive item in the struct.

Test: webgpu/whlsl/matrix-alignment.html

  • Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp:

(WebCore::WHLSL::Metal::writeNativeType):

LayoutTests:

Test the alignment and size of float matrices.

Intentionally don't test bool matrices, because they can't be placed in buffers,
meaning their size and alignment is unobservable.

  • webgpu/whlsl/matrix-alignment-expected.txt: Added.
  • webgpu/whlsl/matrix-alignment.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249212 r249214  
     12019-08-28  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [WHLSL] Matrices need to have correct alignment
     4        https://bugs.webkit.org/show_bug.cgi?id=201212
     5
     6        Reviewed by Robin Morisset.
     7
     8        Test the alignment and size of float matrices.
     9
     10        Intentionally don't test bool matrices, because they can't be placed in buffers,
     11        meaning their size and alignment is unobservable.
     12
     13        * webgpu/whlsl/matrix-alignment-expected.txt: Added.
     14        * webgpu/whlsl/matrix-alignment.html: Added.
     15
    1162019-08-28  Rob Buis  <rbuis@igalia.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r249212 r249214  
     12019-08-28  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [WHLSL] Matrices need to have correct alignment
     4        https://bugs.webkit.org/show_bug.cgi?id=201212
     5
     6        Reviewed by Robin Morisset.
     7
     8        Matrices have particular alignment requirements and size requirements.
     9
     10          Type   | Alignment | Size
     11        ---------------------------
     12        float2x2 |         8 |   16
     13        float2x3 |        16 |   32
     14        float2x4 |        16 |   32
     15        float3x2 |         8 |   24
     16        float3x3 |        16 |   48
     17        float3x4 |        16 |   48
     18        float4x2 |         8 |   32
     19        float4x3 |        16 |   64
     20        float4x4 |        16 |   64
     21
     22        These are important because they may be a member of a struct, and we don't want to misplace
     23        every successive item in the struct.
     24
     25        Test: webgpu/whlsl/matrix-alignment.html
     26
     27        * Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp:
     28        (WebCore::WHLSL::Metal::writeNativeType):
     29
    1302019-08-28  Rob Buis  <rbuis@igalia.com>
    231
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp

    r248795 r249214  
    3838
    3939namespace Metal {
     40
     41enum class MatrixType : uint8_t {
     42    Float,
     43    Bool
     44};
    4045
    4146String writeNativeType(AST::NativeTypeDeclaration& nativeTypeDeclaration)
     
    97102        auto& namedType = downcast<AST::NamedType>(unifyNode);
    98103        auto& parameterType = downcast<AST::NativeTypeDeclaration>(namedType);
    99         auto prefix = ([&]() -> String {
     104        auto matrixType = ([&]() -> MatrixType {
    100105            if (parameterType.name() == "bool")
    101                 return "bool";
     106                return MatrixType::Bool;
    102107            ASSERT(parameterType.name() == "float");
    103             return "float";
     108            return MatrixType::Float;
    104109        })();
    105110
     
    115120        unsigned columns = integerLiteral2.value();
    116121        ASSERT(columns == 2 || columns == 3 || columns == 4);
    117         return makeString("array<", prefix, ", ", columns * rows, ">");
     122
     123        switch (matrixType) {
     124        case MatrixType::Float: {
     125            unsigned alignment = columns == 2 ? 8 : 16;
     126            if (columns == 3)
     127                columns = 4;
     128            return makeString("array<float, ", columns * rows, "> __attribute__((aligned(", alignment, ")))");
     129        }
     130        case MatrixType::Bool:
     131            return makeString("array<bool, ", columns * rows, ">");
     132        }
    118133    }
    119134    ASSERT(nativeTypeDeclaration.typeArguments().size() == 1);
Note: See TracChangeset for help on using the changeset viewer.