Commit f7a936dc authored by Corentin Wallez's avatar Corentin Wallez Committed by Commit Bot

WebGPU: Automatically synchronize mailbox commands with other commands

This CL makes the Associate/DissociateMailbox commands automatically
flush pending Dawn commands so that users of the WebGPUImplementation
don't need to remember to do it everytime.

Bug: chromium:1059777
Change-Id: I15f6ec1528657b063d83710f119329c8865b3f65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095102
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarAustin Eng <enga@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748986}
parent 4e55899c
...@@ -54,12 +54,14 @@ _FUNCTION_INFO = { ...@@ -54,12 +54,14 @@ _FUNCTION_INFO = {
}, },
}, },
'AssociateMailbox': { 'AssociateMailbox': {
'impl_func': False,
'client_test': False,
'type': 'PUT', 'type': 'PUT',
'count': 16, # GL_MAILBOX_SIZE_CHROMIUM 'count': 16, # GL_MAILBOX_SIZE_CHROMIUM
'trace_level': 1,
}, },
'DissociateMailbox': { 'DissociateMailbox': {
'trace_level': 1, 'impl_func': False,
'client_test': False,
}, },
'RequestAdapter': { 'RequestAdapter': {
'impl_func': False, 'impl_func': False,
......
...@@ -603,6 +603,42 @@ bool WebGPUImplementation::RequestDeviceAsync( ...@@ -603,6 +603,42 @@ bool WebGPUImplementation::RequestDeviceAsync(
#endif #endif
} }
void WebGPUImplementation::AssociateMailbox(GLuint64 device_client_id,
GLuint device_generation,
GLuint id,
GLuint generation,
GLuint usage,
const GLbyte* mailbox) {
#if BUILDFLAG(USE_DAWN)
// Flush previous Dawn commands as they may manipulate texture object IDs
// and need to be resolved prior to the AssociateMailbox command. Otherwise
// the service side might not know, for example that the previous texture
// using that ID has been released.
WebGPUCommandSerializer* command_serializer =
GetCommandSerializerWithDeviceClientID(device_client_id);
DCHECK(command_serializer);
command_serializer->Flush();
helper_->AssociateMailboxImmediate(device_client_id, device_generation, id,
generation, usage, mailbox);
#endif
}
void WebGPUImplementation::DissociateMailbox(GLuint64 device_client_id,
GLuint texture_id,
GLuint texture_generation) {
#if BUILDFLAG(USE_DAWN)
// Flush previous Dawn commands that might be rendering to the texture, prior
// to Dissociating the shared image from that texture.
WebGPUCommandSerializer* command_serializer =
GetCommandSerializerWithDeviceClientID(device_client_id);
DCHECK(command_serializer);
command_serializer->Flush();
helper_->DissociateMailbox(device_client_id, texture_id, texture_generation);
#endif
}
void WebGPUImplementation::RemoveDevice(DawnDeviceClientID device_client_id) { void WebGPUImplementation::RemoveDevice(DawnDeviceClientID device_client_id) {
#if BUILDFLAG(USE_DAWN) #if BUILDFLAG(USE_DAWN)
auto it = command_serializers_.find(device_client_id); auto it = command_serializers_.find(device_client_id);
......
...@@ -13,33 +13,4 @@ ...@@ -13,33 +13,4 @@
#ifndef GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_IMPL_AUTOGEN_H_ #ifndef GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_IMPL_AUTOGEN_H_
#define GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_IMPL_AUTOGEN_H_ #define GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_IMPL_AUTOGEN_H_
void WebGPUImplementation::AssociateMailbox(GLuint64 device_client_id,
GLuint device_generation,
GLuint id,
GLuint generation,
GLuint usage,
const GLbyte* mailbox) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] wgAssociateMailbox("
<< device_client_id << ", " << device_generation << ", "
<< id << ", " << generation << ", " << usage << ", "
<< static_cast<const void*>(mailbox) << ")");
uint32_t count = 16;
for (uint32_t ii = 0; ii < count; ++ii)
GPU_CLIENT_LOG("value[" << ii << "]: " << mailbox[ii]);
helper_->AssociateMailboxImmediate(device_client_id, device_generation, id,
generation, usage, mailbox);
CheckGLError();
}
void WebGPUImplementation::DissociateMailbox(GLuint64 device_client_id,
GLuint texture_id,
GLuint texture_generation) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] wgDissociateMailbox("
<< device_client_id << ", " << texture_id << ", "
<< texture_generation << ")");
helper_->DissociateMailbox(device_client_id, texture_id, texture_generation);
}
#endif // GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_IMPL_AUTOGEN_H_ #endif // GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_IMPL_AUTOGEN_H_
...@@ -13,30 +13,4 @@ ...@@ -13,30 +13,4 @@
#ifndef GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_UNITTEST_AUTOGEN_H_ #ifndef GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_UNITTEST_AUTOGEN_H_
#define GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_UNITTEST_AUTOGEN_H_ #define GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_UNITTEST_AUTOGEN_H_
TEST_F(WebGPUImplementationTest, AssociateMailbox) {
GLbyte data[16] = {0};
struct Cmds {
cmds::AssociateMailboxImmediate cmd;
GLbyte data[16];
};
for (int jj = 0; jj < 16; ++jj) {
data[jj] = static_cast<GLbyte>(jj);
}
Cmds expected;
expected.cmd.Init(1, 2, 3, 4, 5, &data[0]);
gl_->AssociateMailbox(1, 2, 3, 4, 5, &data[0]);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
TEST_F(WebGPUImplementationTest, DissociateMailbox) {
struct Cmds {
cmds::DissociateMailbox cmd;
};
Cmds expected;
expected.cmd.Init(1, 2, 3);
gl_->DissociateMailbox(1, 2, 3);
EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
#endif // GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_UNITTEST_AUTOGEN_H_ #endif // GPU_COMMAND_BUFFER_CLIENT_WEBGPU_IMPLEMENTATION_UNITTEST_AUTOGEN_H_
...@@ -69,7 +69,7 @@ struct AssociateMailboxImmediate { ...@@ -69,7 +69,7 @@ struct AssociateMailboxImmediate {
typedef AssociateMailboxImmediate ValueType; typedef AssociateMailboxImmediate ValueType;
static const CommandId kCmdId = kAssociateMailboxImmediate; static const CommandId kCmdId = kAssociateMailboxImmediate;
static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN;
static const uint8_t cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(1); static const uint8_t cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
static uint32_t ComputeDataSize() { static uint32_t ComputeDataSize() {
return static_cast<uint32_t>(sizeof(GLbyte) * 16); return static_cast<uint32_t>(sizeof(GLbyte) * 16);
...@@ -149,7 +149,7 @@ struct DissociateMailbox { ...@@ -149,7 +149,7 @@ struct DissociateMailbox {
typedef DissociateMailbox ValueType; typedef DissociateMailbox ValueType;
static const CommandId kCmdId = kDissociateMailbox; static const CommandId kCmdId = kDissociateMailbox;
static const cmd::ArgFlags kArgFlags = cmd::kFixed; static const cmd::ArgFlags kArgFlags = cmd::kFixed;
static const uint8_t cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(1); static const uint8_t cmd_flags = CMD_FLAG_SET_TRACE_LEVEL(3);
static uint32_t ComputeSize() { static uint32_t ComputeSize() {
return static_cast<uint32_t>(sizeof(ValueType)); // NOLINT return static_cast<uint32_t>(sizeof(ValueType)); // NOLINT
......
...@@ -126,8 +126,6 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) { ...@@ -126,8 +126,6 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) {
wgpu::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Dissociate the mailbox, flushing previous commands first
webgpu()->FlushCommands();
webgpu()->DissociateMailbox(device_client_id, reservation.id, webgpu()->DissociateMailbox(device_client_id, reservation.id,
reservation.generation); reservation.generation);
} }
...@@ -138,10 +136,6 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) { ...@@ -138,10 +136,6 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) {
gpu::webgpu::ReservedTexture reservation = gpu::webgpu::ReservedTexture reservation =
webgpu()->ReserveTexture(device_client_id); webgpu()->ReserveTexture(device_client_id);
// Make sure previous Dawn wire commands are sent so that the texture IDs
// are validated correctly.
webgpu()->FlushCommands();
webgpu()->AssociateMailbox(device_client_id, 0, reservation.id, webgpu()->AssociateMailbox(device_client_id, 0, reservation.id,
reservation.generation, WGPUTextureUsage_CopySrc, reservation.generation, WGPUTextureUsage_CopySrc,
reinterpret_cast<GLbyte*>(&mailbox)); reinterpret_cast<GLbyte*>(&mailbox));
...@@ -174,8 +168,6 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) { ...@@ -174,8 +168,6 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) {
wgpu::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Dissociate the mailbox, flushing previous commands first
webgpu()->FlushCommands();
webgpu()->DissociateMailbox(device_client_id, reservation.id, webgpu()->DissociateMailbox(device_client_id, reservation.id,
reservation.generation); reservation.generation);
......
...@@ -101,10 +101,6 @@ WGPUTexture WebGPUSwapBufferProvider::GetNewTexture(const IntSize& size) { ...@@ -101,10 +101,6 @@ WGPUTexture WebGPUSwapBufferProvider::GetNewTexture(const IntSize& size) {
current_swap_buffer_ = base::AdoptRef(new SwapBuffer( current_swap_buffer_ = base::AdoptRef(new SwapBuffer(
this, mailbox, creation_token, static_cast<gfx::Size>(size))); this, mailbox, creation_token, static_cast<gfx::Size>(size)));
// Make sure previous Dawn wire commands are sent so that for example the ID
// is freed before we associate the SharedImage.
webgpu->FlushCommands();
// Ensure the shared image is allocated service-side before working with it // Ensure the shared image is allocated service-side before working with it
webgpu->WaitSyncTokenCHROMIUM( webgpu->WaitSyncTokenCHROMIUM(
current_swap_buffer_->access_finished_token.GetConstData()); current_swap_buffer_->access_finished_token.GetConstData());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment