dawn-cmake/src/dawn_wire/ChunkedCommandHandler.h
Austin Eng cac0442277 dawn_wire: Support chunked commands
This CL adds support for chunking large commands by first serializing
large commands first into a separate buffer, and then sending the
buffer data chunk by chunk.

This code path is used for large writeBuffer and writeTexture, as well
as the inline memory transfer service for buffer mapping. The transfer
for writeBuffer and writeTexture will be optimized further in Chrome,
and the inline memory transfer service is currently used only in tests.

Bug: chromium:1123861, chromium:951558
Change-Id: I02491a44e653e2383174958d9c3d4a4db6fd7bde
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28882
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
2020-10-13 22:35:34 +00:00

72 lines
2.6 KiB
C++

// Copyright 2020 The Dawn Authors
//
// 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 DAWNWIRE_CHUNKEDCOMMANDHANDLER_H_
#define DAWNWIRE_CHUNKEDCOMMANDHANDLER_H_
#include "common/Assert.h"
#include "dawn_wire/Wire.h"
#include "dawn_wire/WireCmd_autogen.h"
#include <cstdint>
#include <vector>
namespace dawn_wire {
class ChunkedCommandHandler : public CommandHandler {
public:
const volatile char* HandleCommands(const volatile char* commands, size_t size) override;
~ChunkedCommandHandler() override;
protected:
enum class ChunkedCommandsResult {
Passthrough,
Consumed,
Error,
};
// Returns |true| if the commands were entirely consumed into the chunked command vector
// and should be handled later once we receive all the command data.
// Returns |false| if commands should be handled now immediately.
ChunkedCommandsResult HandleChunkedCommands(const volatile char* commands, size_t size) {
uint64_t commandSize64 =
reinterpret_cast<const volatile CmdHeader*>(commands)->commandSize;
if (commandSize64 > std::numeric_limits<size_t>::max()) {
return ChunkedCommandsResult::Error;
}
size_t commandSize = static_cast<size_t>(commandSize64);
if (size < commandSize) {
BeginChunkedCommandData(commands, commandSize, size);
return ChunkedCommandsResult::Consumed;
}
return ChunkedCommandsResult::Passthrough;
}
private:
virtual const volatile char* HandleCommandsImpl(const volatile char* commands,
size_t size) = 0;
void BeginChunkedCommandData(const volatile char* commands,
size_t commandSize,
size_t initialSize);
size_t mChunkedCommandRemainingSize = 0;
std::vector<char> mChunkedCommandData;
};
} // namespace dawn_wire
#endif // DAWNWIRE_CHUNKEDCOMMANDHANDLER_H_