Skip to content

Commit

Permalink
Add interfaces to send ReturnData from decoder to client
Browse files Browse the repository at this point in the history
This adds HandleReturnData to DecoderClient to allow the
WebGPUDecoder to send binary blobs of return commands back
to the WebGPUImplementation. Its implementation in the
InProcessCommandBuffer and the ProxyCommandBufferImpl
forward the data to the GpuControlClient interface. The
WebGPUImplementation will receive the return command stream
via GpuControlClient::GpuControlOnReturnData.

Bug: 877147
Change-Id: Ic7983b9d7b6dd15680427162762bc3bc39bd52fd
Reviewed-on: https://chromium-review.googlesource.com/c/1481615
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636500}
  • Loading branch information
austinEng authored and Commit Bot committed Feb 28, 2019
1 parent 50bd86d commit 6ef198c
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 0 deletions.
5 changes: 5 additions & 0 deletions content/renderer/pepper/pepper_video_encoder_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ void PepperVideoEncoderHost::OnGpuControlLostContextMaybeReentrant() {
// No internal state to update on lost context.
}

void PepperVideoEncoderHost::OnGpuControlReturnData(
base::span<const uint8_t> data) {
NOTIMPLEMENTED();
}

int32_t PepperVideoEncoderHost::OnHostMsgGetSupportedProfiles(
ppapi::host::HostMessageContext* context) {
std::vector<PP_VideoProfileDescription> pp_profiles;
Expand Down
1 change: 1 addition & 0 deletions content/renderer/pepper/pepper_video_encoder_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class CONTENT_EXPORT PepperVideoEncoderHost
const gpu::SwapBuffersCompleteParams& params) final {}
void OnSwapBufferPresented(uint64_t swap_id,
const gfx::PresentationFeedback& feedback) final {}
void OnGpuControlReturnData(base::span<const uint8_t> data) final;

int32_t OnHostMsgGetSupportedProfiles(
ppapi::host::HostMessageContext* context);
Expand Down
5 changes: 5 additions & 0 deletions content/renderer/pepper/ppb_graphics_3d_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ void PPB_Graphics3D_Impl::OnGpuControlLostContextMaybeReentrant() {
void PPB_Graphics3D_Impl::OnGpuControlSwapBuffersCompleted(
const gpu::SwapBuffersCompleteParams& params) {}

void PPB_Graphics3D_Impl::OnGpuControlReturnData(
base::span<const uint8_t> data) {
NOTIMPLEMENTED();
}

void PPB_Graphics3D_Impl::OnSwapBuffers() {
if (HasPendingSwap()) {
// If we're off-screen, no need to trigger and wait for compositing.
Expand Down
1 change: 1 addition & 0 deletions content/renderer/pepper/ppb_graphics_3d_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared,
const gpu::SwapBuffersCompleteParams& params) final;
void OnSwapBufferPresented(uint64_t swap_id,
const gfx::PresentationFeedback& feedback) final {}
void OnGpuControlReturnData(base::span<const uint8_t> data) final;

// Other notifications from the GPU process.
void OnSwapBuffers();
Expand Down
5 changes: 5 additions & 0 deletions gpu/command_buffer/client/gles2_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ void GLES2Implementation::OnSwapBufferPresented(
pending_presentation_callbacks_.erase(found);
}

void GLES2Implementation::OnGpuControlReturnData(
base::span<const uint8_t> data) {
NOTIMPLEMENTED();
}

void GLES2Implementation::FreeSharedMemory(void* mem) {
mapped_memory_->FreePendingToken(mem, helper_->InsertToken());
}
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/client/gles2_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class GLES2_IMPL_EXPORT GLES2Implementation : public GLES2Interface,
const SwapBuffersCompleteParams& params) final;
void OnSwapBufferPresented(uint64_t swap_id,
const gfx::PresentationFeedback& feedback) final;
void OnGpuControlReturnData(base::span<const uint8_t> data) final;

void SendErrorMessage(std::string message, int32_t id);
void CallDeferredErrorCallbacks();
Expand Down
3 changes: 3 additions & 0 deletions gpu/command_buffer/client/gpu_control_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cstdint>

#include "base/containers/span.h"
#include "ui/gfx/presentation_feedback.h"

namespace gpu {
Expand All @@ -30,6 +31,8 @@ class GpuControlClient {
virtual void OnSwapBufferPresented(
uint64_t swap_id,
const gfx::PresentationFeedback& feedback) = 0;
// Sent by the WebGPUDecoder
virtual void OnGpuControlReturnData(base::span<const uint8_t> data) = 0;
};

} // namespace gpu
Expand Down
5 changes: 5 additions & 0 deletions gpu/command_buffer/client/raster_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ void RasterImplementation::OnSwapBufferPresented(
NOTREACHED();
}

void RasterImplementation::OnGpuControlReturnData(
base::span<const uint8_t> data) {
NOTIMPLEMENTED();
}

void RasterImplementation::SetAggressivelyFreeResources(
bool aggressively_free_resources) {
TRACE_EVENT1("gpu", "RasterImplementation::SetAggressivelyFreeResources",
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/client/raster_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
const SwapBuffersCompleteParams& params) final;
void OnSwapBufferPresented(uint64_t swap_id,
const gfx::PresentationFeedback& feedback) final;
void OnGpuControlReturnData(base::span<const uint8_t> data) final;

// Gets the GLError through our wrapper.
GLenum GetGLError();
Expand Down
5 changes: 5 additions & 0 deletions gpu/command_buffer/client/webgpu_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ void WebGPUImplementation::OnSwapBufferPresented(
const gfx::PresentationFeedback& feedback) {
NOTIMPLEMENTED();
}
void WebGPUImplementation::OnGpuControlReturnData(
base::span<const uint8_t> data) {
// TODO: Handle return commands
NOTIMPLEMENTED();
}

void WebGPUImplementation::Dummy() {
GPU_CLIENT_SINGLE_THREAD_CHECK();
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/client/webgpu_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class WEBGPU_EXPORT WebGPUImplementation final : public WebGPUInterface,
const SwapBuffersCompleteParams& params) final;
void OnSwapBufferPresented(uint64_t swap_id,
const gfx::PresentationFeedback& feedback) final;
void OnGpuControlReturnData(base::span<const uint8_t> data) final;

private:
const char* GetLogPrefix() const { return "webgpu"; }
Expand Down
4 changes: 4 additions & 0 deletions gpu/command_buffer/service/command_buffer_direct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ scoped_refptr<Buffer> CommandBufferDirect::CreateTransferBufferWithId(
return service_.CreateTransferBufferWithId(size, id);
}

void CommandBufferDirect::HandleReturnData(base::span<const uint8_t> data) {
NOTIMPLEMENTED();
}

} // namespace gpu
1 change: 1 addition & 0 deletions gpu/command_buffer/service/command_buffer_direct.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class GPU_EXPORT CommandBufferDirect : public CommandBuffer,
void OnRescheduleAfterFinished() override;
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override;

scoped_refptr<Buffer> CreateTransferBufferWithId(uint32_t size, int32_t id);

Expand Down
4 changes: 4 additions & 0 deletions gpu/command_buffer/service/decoder_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <string>

#include "base/containers/span.h"
#include "gpu/gpu_export.h"
#include "url/gurl.h"

Expand Down Expand Up @@ -48,6 +49,9 @@ class GPU_EXPORT DecoderClient {
virtual void ScheduleGrContextCleanup() = 0;

virtual void SetActiveURL(GURL url) {}

// Called by the decoder to pass a variable-size block of data to the client.
virtual void HandleReturnData(base::span<const uint8_t> data) = 0;
};

} // namespace gpu
Expand Down
2 changes: 2 additions & 0 deletions gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class GLES2DecoderTestBase : public ::testing::TestWithParam<bool>,
void OnRescheduleAfterFinished() override;
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

// Template to call glGenXXX functions.
template <typename T>
Expand Down Expand Up @@ -854,6 +855,7 @@ class GLES2DecoderPassthroughTestBase : public testing::Test,
void OnRescheduleAfterFinished() override;
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

void SetUp() override;
void TearDown() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class MemoryProgramCacheTest : public GpuServiceTest, public DecoderClient {
void OnRescheduleAfterFinished() override {}
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override {}
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

int32_t shader_cache_count() { return shader_cache_count_; }
const std::string& shader_cache_shader() { return shader_cache_shader_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PassthroughProgramCacheTest : public GpuServiceTest,
void OnRescheduleAfterFinished() override {}
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override {}
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

int32_t blob_count() { return blob_count_; }

Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/service/program_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ProgramManagerTestBase : public GpuServiceTest, public DecoderClient {
void OnRescheduleAfterFinished() override {}
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override {}
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

std::unique_ptr<ProgramManager> manager_;
GpuPreferences gpu_preferences_;
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/service/raster_decoder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class RasterDecoderOOPTest : public testing::Test, DecoderClient {
void OnRescheduleAfterFinished() override {}
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override {}
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

std::unique_ptr<RasterDecoder> CreateDecoder() {
auto decoder = base::WrapUnique(RasterDecoder::Create(
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/service/raster_decoder_unittest_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RasterDecoderTestBase : public ::testing::TestWithParam<bool>,
void OnRescheduleAfterFinished() override;
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
void ScheduleGrContextCleanup() override {}
void HandleReturnData(base::span<const uint8_t> data) override {}

// Template to call glGenXXX functions.
template <typename T>
Expand Down
7 changes: 7 additions & 0 deletions gpu/ipc/client/command_buffer_proxy_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_BufferPresented, OnBufferPresented);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetGpuFenceHandleComplete,
OnGetGpuFenceHandleComplete);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ReturnData, OnReturnData);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()

Expand Down Expand Up @@ -632,6 +633,12 @@ void CommandBufferProxyImpl::OnGetGpuFenceHandleComplete(
std::move(callback).Run(std::move(gpu_fence));
}

void CommandBufferProxyImpl::OnReturnData(const std::vector<uint8_t>& data) {
if (gpu_control_client_) {
gpu_control_client_->OnGpuControlReturnData(data);
}
}

void CommandBufferProxyImpl::TakeFrontBuffer(const gpu::Mailbox& mailbox) {
CheckLock();
base::AutoLock lock(last_state_lock_);
Expand Down
1 change: 1 addition & 0 deletions gpu/ipc/client/command_buffer_proxy_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class GPU_EXPORT CommandBufferProxyImpl : public gpu::CommandBuffer,
const gfx::PresentationFeedback& feedback);
void OnGetGpuFenceHandleComplete(uint32_t gpu_fence_id,
const gfx::GpuFenceHandle&);
void OnReturnData(const std::vector<uint8_t>& data);

// Try to read an updated copy of the state from shared memory, and calls
// OnGpuStateError() if the new state has an error.
Expand Down
6 changes: 6 additions & 0 deletions gpu/ipc/common/gpu_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,10 @@ IPC_MESSAGE_ROUTED2(GpuCommandBufferMsg_GetGpuFenceHandleComplete,
uint32_t /* gpu_fence_id */,
gfx::GpuFenceHandle)

// Returns a block of data from the GPU process to the renderer.
// This contains server->client messages produced by dawn_wire and is used to
// remote WebGPU.
IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_ReturnData,
std::vector<uint8_t> /* data */)

#endif // GPU_IPC_COMMON_GPU_MESSAGES_H_
16 changes: 16 additions & 0 deletions gpu/ipc/in_process_command_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,14 @@ void InProcessCommandBuffer::ScheduleGrContextCleanup() {
gr_cache_controller_->ScheduleGrContextCleanup();
}

void InProcessCommandBuffer::HandleReturnData(base::span<const uint8_t> data) {
DCHECK_CALLED_ON_VALID_SEQUENCE(gpu_sequence_checker_);
std::vector<uint8_t> vec(data.data(), data.data() + data.size());
PostOrRunClientCallback(base::BindOnce(
&InProcessCommandBuffer::HandleReturnDataOnOriginThread,
client_thread_weak_ptr_factory_.GetWeakPtr(), std::move(vec)));
}

void InProcessCommandBuffer::PostOrRunClientCallback(
base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(gpu_sequence_checker_);
Expand Down Expand Up @@ -1553,6 +1561,14 @@ void InProcessCommandBuffer::BufferPresentedOnOriginThread(
}
}

void InProcessCommandBuffer::HandleReturnDataOnOriginThread(
std::vector<uint8_t> data) {
DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
if (gpu_control_client_) {
gpu_control_client_->OnGpuControlReturnData(data);
}
}

void InProcessCommandBuffer::SetUpdateVSyncParametersCallback(
const UpdateVSyncParametersCallback& callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
Expand Down
3 changes: 3 additions & 0 deletions gpu/ipc/in_process_command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
void OnRescheduleAfterFinished() override;
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
void ScheduleGrContextCleanup() override;
void HandleReturnData(base::span<const uint8_t> data) override;

// ImageTransportSurfaceDelegate implementation:
#if defined(OS_WIN)
Expand Down Expand Up @@ -308,6 +309,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
uint32_t flags,
const gfx::PresentationFeedback& feedback);

void HandleReturnDataOnOriginThread(std::vector<uint8_t> data);

const CommandBufferId command_buffer_id_;

// Members accessed on the gpu thread (possibly with the exception of
Expand Down
7 changes: 7 additions & 0 deletions gpu/ipc/service/command_buffer_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,13 @@ void CommandBufferStub::ScheduleGrContextCleanup() {
channel_->gpu_channel_manager()->ScheduleGrContextCleanup();
}

void CommandBufferStub::HandleReturnData(base::span<const uint8_t> data) {
std::vector<uint8_t> vec(data.begin(), data.end());
IPC::Message* msg =
new GpuCommandBufferMsg_ReturnData(route_id_, std::move(vec));
Send(msg);
}

void CommandBufferStub::OnConsoleMessage(int32_t id,
const std::string& message) {
GPUCommandBufferConsoleMessage console_message;
Expand Down
1 change: 1 addition & 0 deletions gpu/ipc/service/command_buffer_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub
void OnDescheduleUntilFinished() override;
void OnRescheduleAfterFinished() override;
void ScheduleGrContextCleanup() override;
void HandleReturnData(base::span<const uint8_t> data) override;

using MemoryTrackerFactory =
base::RepeatingCallback<std::unique_ptr<MemoryTracker>(
Expand Down

0 comments on commit 6ef198c

Please sign in to comment.