blob: b72a7181035c7c4268844d40b92fcec62b3b1fc0 [file] [edit]
// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_WEBGPU_DAWN_TESTING_COMMAND_SERIALIZER_H_
#define GPU_WEBGPU_DAWN_TESTING_COMMAND_SERIALIZER_H_
#include <array>
#include <cstddef>
#include <utility>
#include "base/memory/raw_ptr.h"
#include "third_party/dawn/include/dawn/wire/Wire.h"
namespace gpu::webgpu {
// In-memory `dawn::wire::CommandSerializer` for unit tests that run a
// `dawn::wire::WireClient` and `dawn::wire::WireServer` in the same process.
class DawnTestingCommandSerializer : public dawn::wire::CommandSerializer {
public:
using CommandSpace =
decltype(std::declval<dawn::wire::CommandSerializer>().GetCommandSpace(
0));
DawnTestingCommandSerializer();
~DawnTestingCommandSerializer() override;
DawnTestingCommandSerializer(const DawnTestingCommandSerializer&) = delete;
DawnTestingCommandSerializer& operator=(const DawnTestingCommandSerializer&) =
delete;
void SetHandler(dawn::wire::CommandHandler* handler);
size_t GetMaximumAllocationSize() const override;
CommandSpace GetCommandSpace(size_t size) override;
bool Flush() override;
bool Empty() const { return offset_ == 0; }
private:
raw_ptr<dawn::wire::CommandHandler> handler_ = nullptr;
size_t offset_ = 0;
size_t last_flushed_offset_ = 0;
alignas(8) std::array<std::byte, 1024 * 1024> buffer_;
};
} // namespace gpu::webgpu
#endif // GPU_WEBGPU_DAWN_TESTING_COMMAND_SERIALIZER_H_