-
Notifications
You must be signed in to change notification settings - Fork 16.2k
feat: GPU shared texture offscreen rendering #42001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# OffscreenSharedTexture Object | ||
|
||
* `textureInfo` Object - The shared texture info. | ||
* `widgetType` string - The widget type of the texture, could be `popup` or `frame`. | ||
* `pixelFormat` string - The pixel format of the texture, could be `rgba` or `bgra`. | ||
* `sharedTextureHandle` string - _Windows_ _macOS_ The handle to the shared texture. | ||
* `planes` Object[] - _Linux_ Each plane's info of the shared texture. | ||
* `stride` number - The strides and offsets in bytes to be used when accessing the buffers via a memory mapping. One per plane per entry. | ||
* `offset` number - The strides and offsets in bytes to be used when accessing the buffers via a memory mapping. One per plane per entry. | ||
* `size` number - Size in bytes of the plane. This is necessary to map the buffers. | ||
* `fd` number - File descriptor for the underlying memory object (usually dmabuf). | ||
* `modifier` string - _Linux_ The modifier is retrieved from GBM library and passed to EGL driver. | ||
nornagon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* `release` Function - Release the resources. The `texture` cannot be directly passed to another process, users need to maintain texture lifecycles in | ||
main process, but it is safe to pass the `textureInfo` to another process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
patches/chromium/osr_shared_texture_remove_keyed_mutex_on_win_dxgi.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Reito <[email protected]> | ||
Date: Fri, 19 Apr 2024 11:46:47 +0800 | ||
Subject: Remove DXGI GMB keyed-mutex | ||
|
||
This CL is only for reference for a vendor specific change. It is kept for rebasing. | ||
|
||
On CEF/electron, FrameSinkVideoCapturer is used in GPU accelerated OSR, and it can be faster | ||
if we remove the mutex on the shared resource for Windows. | ||
|
||
Maintain this patch in https://crrev.com/c/5465148 | ||
|
||
Change-Id: Id90acd587f17acd228ae7cb5ef93005eb8388b80 | ||
reitowo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
diff --git a/gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc b/gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc | ||
index 58df3e9ad67b2b7835fe64835f9e589a563ee073..d08d4611361fc1387e94f553ba88c20a8cd87741 100644 | ||
--- a/gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc | ||
+++ b/gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc | ||
@@ -180,7 +180,8 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer( | ||
// so make sure that the usage is one that we support. | ||
DCHECK(usage == gfx::BufferUsage::GPU_READ || | ||
usage == gfx::BufferUsage::SCANOUT || | ||
- usage == gfx::BufferUsage::SCANOUT_CPU_READ_WRITE) | ||
+ usage == gfx::BufferUsage::SCANOUT_CPU_READ_WRITE || | ||
+ usage == gfx::BufferUsage::SCANOUT_VEA_CPU_READ) | ||
<< "Incorrect usage, usage=" << gfx::BufferUsageToString(usage); | ||
|
||
D3D11_TEXTURE2D_DESC desc = { | ||
@@ -194,7 +195,9 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer( | ||
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET, | ||
0, | ||
D3D11_RESOURCE_MISC_SHARED_NTHANDLE | | ||
- D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX}; | ||
+ static_cast<UINT>(usage == gfx::BufferUsage::SCANOUT_VEA_CPU_READ | ||
+ ? D3D11_RESOURCE_MISC_SHARED | ||
+ : D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)}; | ||
|
||
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture; | ||
|
||
diff --git a/media/video/renderable_gpu_memory_buffer_video_frame_pool.cc b/media/video/renderable_gpu_memory_buffer_video_frame_pool.cc | ||
index c007238f1c7392042ae91a82f3d70751ba258422..0a65f20f65ed1d7cc140d0a54042fc4a41138774 100644 | ||
--- a/media/video/renderable_gpu_memory_buffer_video_frame_pool.cc | ||
+++ b/media/video/renderable_gpu_memory_buffer_video_frame_pool.cc | ||
@@ -198,7 +198,7 @@ gfx::Size GetBufferSizeInPixelsForVideoPixelFormat( | ||
bool FrameResources::Initialize() { | ||
auto* context = pool_->GetContext(); | ||
|
||
- constexpr gfx::BufferUsage kBufferUsage = | ||
+ gfx::BufferUsage buffer_usage = | ||
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) | ||
gfx::BufferUsage::SCANOUT_VEA_CPU_READ | ||
#else | ||
@@ -212,13 +212,30 @@ bool FrameResources::Initialize() { | ||
const gfx::Size buffer_size_in_pixels = | ||
GetBufferSizeInPixelsForVideoPixelFormat(format_, coded_size_); | ||
|
||
+#if BUILDFLAG(IS_WIN) | ||
+ // For CEF OSR feature, currently there's no other place in chromium use RGBA. | ||
+ // If the format is RGBA, currently CEF do not write to the texture anymore | ||
+ // once the GMB is returned from CopyRequest. So there will be no race | ||
+ // condition on that texture. We can request a GMB without a keyed mutex to | ||
+ // accelerate and probably prevent some driver deadlock. | ||
+ if (format_ == PIXEL_FORMAT_ARGB || format_ == PIXEL_FORMAT_ABGR) { | ||
+ // This value is 'borrowed', SCANOUT_VEA_CPU_READ is probably invalid | ||
+ // cause there's no real SCANOUT on Windows. We simply use this enum as a | ||
+ // flag to disable mutex in the GMBFactoryDXGI because this enum is also | ||
+ // used above in macOS and CrOS for similar usage (claim no other one will | ||
+ // concurrently use the resource). | ||
+ // https://chromium-review.googlesource.com/c/chromium/src/+/5302103 | ||
+ buffer_usage = gfx::BufferUsage::SCANOUT_VEA_CPU_READ; | ||
+ } | ||
+#endif | ||
+ | ||
// Create the GpuMemoryBuffer. | ||
gpu_memory_buffer_ = context->CreateGpuMemoryBuffer( | ||
- buffer_size_in_pixels, buffer_format, kBufferUsage); | ||
+ buffer_size_in_pixels, buffer_format, buffer_usage); | ||
if (!gpu_memory_buffer_) { | ||
DLOG(ERROR) << "Failed to allocate GpuMemoryBuffer for frame: coded_size=" | ||
<< coded_size_.ToString() | ||
- << ", usage=" << static_cast<int>(kBufferUsage); | ||
+ << ", usage=" << static_cast<int>(buffer_usage); | ||
return false; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.