# Copyright (C) 2025 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1.  Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
# 2.  Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#if ENABLE(GPU_PROCESS_MODEL)
header: <WebCore/DDFloat4x4.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDFloat4x4 {
    float m00;
    float m01;
    float m02;
    float m03;

    float m10;
    float m11;
    float m12;
    float m13;

    float m20;
    float m21;
    float m22;
    float m23;

    float m30;
    float m31;
    float m32;
    float m33;
};

header: <WebCore/DDFloat3.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDFloat3 {
    float x;
    float y;
    float z;
    float w;
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDEdge {
    long upstreamNodeIndex;
    long downstreamNodeIndex;
    String upstreamOutputName;
    String downstreamInputName;
};

header: <WebCore/DDMaterialDescriptor.h>
[CustomHeader] enum class WebCore::DDModel::DDDataType : uint8_t {
    kBool,
    kInt,
    kInt2,
    kInt3,
    kInt4,
    kFloat,
    kColor3f,
    kColor3h,
    kColor4f,
    kColor4h,
    kFloat2,
    kFloat3,
    kFloat4,
    kHalf,
    kHalf2,
    kHalf3,
    kHalf4,
    kMatrix2f,
    kMatrix3f,
    kMatrix4f,
    kSurfaceShader,
    kGeometryModifier,
    kString,
    kToken,
    kAsset
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDPrimvar {
    String name;
    String referencedGeomPropName;
    uint64_t attributeFormat;
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDInputOutput {
    WebCore::DDModel::DDDataType type;
    String name;
};

header: <WebCore/DDMaterialDescriptor.h>
[CustomHeader] enum class WebCore::DDModel::DDConstant : uint8_t {
    kBool,
    kUchar,
    kInt,
    kUint,
    kHalf,
    kFloat,
    kTimecode,
    kString,
    kToken,
    kAsset,
    kMatrix2f,
    kMatrix3f,
    kMatrix4f,
    kQuatf,
    kQuath,
    kFloat2,
    kHalf2,
    kInt2,
    kFloat3,
    kHalf3,
    kInt3,
    kFloat4,
    kHalf4,
    kInt4,
    kPoint3f,
    kPoint3h,
    kNormal3f,
    kNormal3h,
    kVector3f,
    kVector3h,
    kColor3f,
    kColor3h,
    kColor4f,
    kColor4h,
    kTexCoord2h,
    kTexCoord2f,
    kTexCoord3h,
    kTexCoord3f
};

header: <WebCore/DDMaterialDescriptor.h>
[CustomHeader] enum class WebCore::DDModel::DDNodeType : uint8_t {
    Builtin,
    Constant,
    Arguments,
    Results
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDConstantContainer {
    WebCore::DDModel::DDConstant constant;
    Vector<Variant<String, double>> constantValues;
    String name;
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDBuiltin {
    String definition;
    String name;
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDNode {
    WebCore::DDModel::DDNodeType bridgeNodeType;
    WebCore::DDModel::DDBuiltin builtin;
    WebCore::DDModel::DDConstantContainer constant;
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDMaterialGraph {
    Vector<WebCore::DDModel::DDNode> nodes;
    Vector<WebCore::DDModel::DDEdge> edges;
    Vector<WebCore::DDModel::DDInputOutput> inputs;
    Vector<WebCore::DDModel::DDInputOutput> outputs;
    Vector<WebCore::DDModel::DDPrimvar> primvars;
    String identifier;
};

header: <WebCore/DDUpdateTextureDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDUpdateTextureDescriptor {
    WebCore::DDModel::DDImageAsset imageAsset;
    String identifier;
    String hashString;
};

header: <WebCore/DDUpdateMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDUpdateMaterialDescriptor {
    Vector<uint8_t> materialGraph;
    String identifier;
};

header: <WebCore/DDMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDMeshDescriptor {
    long vertexBufferCount;
    long vertexCapacity;
    Vector<WebCore::DDModel::DDVertexAttributeFormat> vertexAttributes;
    Vector<WebCore::DDModel::DDVertexLayout> vertexLayouts;
    long indexCapacity;
    long indexType;
};

header: <WebCore/DDUpdateMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDSkinningData {
    uint8_t influencePerVertexCount;
    Vector<WebCore::DDModel::DDFloat4x4> jointTransforms;
    Vector<WebCore::DDModel::DDFloat4x4> inverseBindPoses;
    Vector<uint32_t> influenceJointIndices;
    Vector<float> influenceWeights;
    WebCore::DDModel::DDFloat4x4 geometryBindTransform;
};

header: <WebCore/DDUpdateMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDBlendShapeData {
    Vector<float> weights;
    Vector<Vector<WebCore::DDModel::DDFloat3>> positionOffsets;
    Vector<Vector<WebCore::DDModel::DDFloat3>> normalOffsets;
};

header: <WebCore/DDUpdateMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDRenormalizationData {
    Vector<uint32_t> vertexIndicesPerTriangle;
    Vector<uint32_t> vertexAdjacencies;
    Vector<uint32_t> vertexAdjacencyEndIndices;
};

header: <WebCore/DDUpdateMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDDeformationData {
    std::optional<WebCore::DDModel::DDSkinningData> skinningData;
    std::optional<WebCore::DDModel::DDBlendShapeData> blendShapeData;
    std::optional<WebCore::DDModel::DDRenormalizationData> renormalizationData;
};

header: <WebCore/DDUpdateMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDUpdateMeshDescriptor {
    String identifier;
    uint8_t updateType;
    WebCore::DDModel::DDMeshDescriptor descriptor;
    Vector<WebCore::DDModel::DDMeshPart> parts;
    Vector<uint8_t> indexData;
    Vector<Vector<uint8_t>> vertexData;
    WebCore::DDModel::DDFloat4x4 transform;
    Vector<WebCore::DDModel::DDFloat4x4> instanceTransforms;
    Vector<String> materialPrims;
    std::optional<WebCore::DDModel::DDDeformationData> deformationData;
};

header: <WebCore/DDVertexAttributeFormat.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDVertexAttributeFormat {
    long semantic;
    unsigned long format;
    long layoutIndex;
    long offset;
};

header: <WebCore/DDVertexLayout.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDVertexLayout {
    long bufferIndex;
    long bufferOffset;
    long bufferStride;
};

header: <WebCore/DDMaterialDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDMaterialDescriptor {
    Vector<uint8_t> materialGraph;
    String identifier;
};

header: <WebCore/DDImageAsset.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDImageAssetSwizzle {
    uint8_t red;
    uint8_t green;
    uint8_t blue;
    uint8_t alpha;
};

header: <WebCore/DDImageAsset.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDImageAsset {
    Vector<uint8_t> data;
    long width;
    long height;
    long depth;
    long bytesPerPixel;
    uint64_t textureType;
    uint64_t pixelFormat;
    long mipmapLevelCount;
    long arrayLength;
    uint64_t textureUsage;
    WebCore::DDModel::DDImageAssetSwizzle swizzle;
};

header: <WebCore/DDMeshPart.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDMeshPart {
    uint32_t indexOffset;
    uint32_t indexCount;
    uint32_t topology;
    uint32_t materialIndex;
    WebCore::DDModel::DDFloat3 boundsMin;
    WebCore::DDModel::DDFloat3 boundsMax;
};

#endif

