mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
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>
This commit is contained in:
committed by
Commit Bot service account
parent
ccaef85257
commit
cac0442277
@@ -29,48 +29,18 @@ namespace utils {
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
size_t TerribleCommandBuffer::GetMaximumAllocationSize() const {
|
||||
return sizeof(mBuffer);
|
||||
}
|
||||
|
||||
void* TerribleCommandBuffer::GetCmdSpace(size_t size) {
|
||||
// TODO(kainino@chromium.org): Should we early-out if size is 0?
|
||||
// (Here and/or in the caller?) It might be good to make the wire receiver get a nullptr
|
||||
// instead of pointer to zero-sized allocation in mBuffer.
|
||||
|
||||
// Cannot have commands in mBuffer and mLargeBuffer at same time.
|
||||
ASSERT(mOffset == 0 || mLargeBufferCmdSize == 0);
|
||||
|
||||
if (size > sizeof(mBuffer)) {
|
||||
// Flush current cmds in mBuffer to keep order.
|
||||
if (mOffset > 0) {
|
||||
if (!Flush()) {
|
||||
return nullptr;
|
||||
}
|
||||
return GetCmdSpace(size);
|
||||
}
|
||||
|
||||
// Resize large buffer to the size that can
|
||||
// contain incoming command if needed.
|
||||
if (mLargeBuffer.size() < size) {
|
||||
mLargeBuffer.resize(size);
|
||||
}
|
||||
|
||||
// Record whole cmd space.
|
||||
mLargeBufferCmdSize = size;
|
||||
|
||||
return mLargeBuffer.data();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Trigger flush if large buffer contain cmds.
|
||||
if (mLargeBufferCmdSize > 0) {
|
||||
if (!Flush()) {
|
||||
return nullptr;
|
||||
}
|
||||
return GetCmdSpace(size);
|
||||
}
|
||||
|
||||
// Need to flush large buffer first.
|
||||
ASSERT(mLargeBufferCmdSize == 0);
|
||||
|
||||
char* result = &mBuffer[mOffset];
|
||||
|
||||
if (sizeof(mBuffer) - size < mOffset) {
|
||||
if (!Flush()) {
|
||||
return nullptr;
|
||||
@@ -79,26 +49,12 @@ namespace utils {
|
||||
}
|
||||
|
||||
mOffset += size;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TerribleCommandBuffer::Flush() {
|
||||
// Cannot have commands in mBuffer and mLargeBuffer at same time.
|
||||
ASSERT(mOffset == 0 || mLargeBufferCmdSize == 0);
|
||||
|
||||
bool success = false;
|
||||
// Big buffer not empty, flush it!
|
||||
if (mLargeBufferCmdSize > 0) {
|
||||
success = mHandler->HandleCommands(mLargeBuffer.data(), mLargeBufferCmdSize) != nullptr;
|
||||
// Clear big command buffers.
|
||||
mLargeBufferCmdSize = 0;
|
||||
return success;
|
||||
}
|
||||
|
||||
success = mHandler->HandleCommands(mBuffer, mOffset) != nullptr;
|
||||
bool success = mHandler->HandleCommands(mBuffer, mOffset) != nullptr;
|
||||
mOffset = 0;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#ifndef UTILS_TERRIBLE_COMMAND_BUFFER_H_
|
||||
#define UTILS_TERRIBLE_COMMAND_BUFFER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "dawn_wire/Wire.h"
|
||||
|
||||
namespace utils {
|
||||
@@ -28,17 +26,15 @@ namespace utils {
|
||||
|
||||
void SetHandler(dawn_wire::CommandHandler* handler);
|
||||
|
||||
size_t GetMaximumAllocationSize() const override;
|
||||
|
||||
void* GetCmdSpace(size_t size) override;
|
||||
bool Flush() override;
|
||||
|
||||
private:
|
||||
dawn_wire::CommandHandler* mHandler = nullptr;
|
||||
size_t mOffset = 0;
|
||||
// Cannot have commands in mBuffer and mLargeBuffer
|
||||
// at the same time to ensure commands order.
|
||||
char mBuffer[1000000];
|
||||
std::vector<char> mLargeBuffer;
|
||||
size_t mLargeBufferCmdSize = 0;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user