# 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/DDMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDMeshDescriptor {
    int32_t indexCapacity;
    int32_t indexType;
    int32_t vertexBufferCount;
    int32_t vertexCapacity;
    Vector<WebCore::DDModel::DDVertexAttributeFormat> vertexAttributes;
    Vector<WebCore::DDModel::DDVertexLayout> vertexLayouts;
    String identifier;
};

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

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

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

header: <WebCore/DDReplaceVertices.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDReplaceVertices {
    int32_t bufferIndex;
    Vector<uint8_t> buffer;
};

header: <WebCore/DDUpdateMeshDescriptor.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDUpdateMeshDescriptor {
    int32_t partCount;
    Vector<KeyValuePair<int32_t, WebCore::DDModel::DDMeshPart>> parts;
    Vector<KeyValuePair<int32_t, uint64_t>> renderFlags;
    Vector<WebCore::DDModel::DDReplaceVertices> vertices;
    Vector<uint8_t> indices;
    WebCore::DDModel::DDFloat4x4 transform;
    Vector<WebCore::DDModel::DDFloat4x4> instanceTransforms4x4;
    Vector<String> materialIds;
    String identifier;
};

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

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

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

header: <WebCore/DDImageAsset.h>
[CustomHeader] enum class WebCore::DDModel::DDSemantic : uint8_t {
    Color,
    Vector,
    Scalar,
    Unknown
};

header: <WebCore/DDImageAsset.h>
[AdditionalEncoder=StreamConnectionEncoder, CustomHeader] struct WebCore::DDModel::DDImageAsset {
    Vector<uint8_t> data;
    uint32_t width;
    uint32_t height;
    uint32_t bytesPerPixel;
    WebCore::DDModel::DDSemantic semantic;
    String path;
    String identifier;
};

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

