Repository: google/filament
File: filament/backend/src/webgpu/WebGPUHandles.h (C/C++)

Code before:
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H
#define TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H

#include "DriverBase.h"

#include <backend/DriverEnums.h>
#include <backend/Handle.h>
#include <utils/FixedCapacityVector.h>

#include <webgpu/webgpu_cpp.h>

namespace filament::backend {

struct WGPUBufferObject;
struct WGPUVertexBufferInfo : public HwVertexBufferInfo {
    WGPUVertexBufferInfo(uint8_t bufferCount, uint8_t attributeCount,
            AttributeArray const& attributes)
        : HwVertexBufferInfo(bufferCount, attributeCount),
          attributes(attributes) {}
    AttributeArray attributes;
};

struct WGPUVertexBuffer : public HwVertexBuffer {
    WGPUVertexBuffer(uint32_t vextexCount, uint32_t bufferCount, Handle<WGPUVertexBufferInfo> vbih);
    void setBuffer(WGPUBufferObject* bufferObject, uint32_t index);

    Handle<WGPUVertexBufferInfo> vbih;
    utils::FixedCapacityVector<wgpu::Buffer> mBuffers;
};

struct WGPUIndexBuffer : public HwIndexBuffer {
    WGPUIndexBuffer(BufferUsage usage, uint8_t elementSize, uint32_t indexCount);

    wgpu::Buffer buffer;
};

struct WGPUBufferObject : HwBufferObject {

Review comment (suggestion):
Based on the "include what you use" best practice, I suggest we include `<cstdint>` _(for `uint8_t` and such)_, and `<math/vec2.h>` _(if `math::uint2` is really necessary)_.

Code after:
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H
#define TNT_FILAMENT_BACKEND_WEBGPUHANDLES_H

#include "DriverBase.h"

#include <backend/DriverEnums.h>
#include <backend/Handle.h>

#include <utils/FixedCapacityVector.h>

#include <webgpu/webgpu_cpp.h>

#include <cstdint>

namespace filament::backend {

struct WGPUBufferObject;
// TODO: Currently WGPUVertexBufferInfo is not used by WebGPU for useful task.
// Update the struct when used by WebGPU driver.
struct WGPUVertexBufferInfo : public HwVertexBufferInfo {
    WGPUVertexBufferInfo(uint8_t bufferCount, uint8_t attributeCount,
            AttributeArray const& attributes)
        : HwVertexBufferInfo(bufferCount, attributeCount),
          attributes(attributes) {}
    AttributeArray attributes;
};

// TODO: Currently WGPUVertexBuffer is not used by WebGPU for useful task.
// Update the struct when used by WebGPU driver.
struct WGPUVertexBuffer : public HwVertexBuffer {
    WGPUVertexBuffer(uint32_t vextexCount, uint32_t bufferCount, Handle<WGPUVertexBufferInfo> vbih);
    void setBuffer(WGPUBufferObject* bufferObject, uint32_t index);

    Handle<WGPUVertexBufferInfo> vbih;
    utils::FixedCapacityVector<wgpu::Buffer> buffers;
};