Comments (15)
Getting a scaled down buffer directly from the API is not available at the moment, but it's something we're investigating. In the mean-time, you'll need to scale down the buffer yourself using D3D/D2D. This won't give you any perf back on generating the frame, but if your pipeline is resolution dependent you may get something back there.
If you use D2D, there's a variety of interpolation modes.
from windows.ui.composition-win32-samples.
Thanks.
Do you know or can give an example of how to do it on ID3D11Texture2D ?
from windows.ui.composition-win32-samples.
I will try to ask you better what example I want:
In file SimpleCapture.cpp in function SimpleCapture::OnFrameArrived
The relevant code is:
auto frame = sender.TryGetNextFrame();
if (frameContentSize.Width != m_lastSize.Width ||
frameContentSize.Height != m_lastSize.Height)
{
.....
.....
}
auto frameSurface = GetDXGIInterfaceFromObject<ID3D11Texture2D>(frame.Surface());
.....
.....
m_d3dContext->CopyResource(backBuffer.get(), frameSurface.get());
What I want to do is this:
before line
m_d3dContext->CopyResource(backBuffer.get(), frameSurface.get());
I know that I get ID3D11Texture2D
What I want to do here is this:
- Reduce the texture size to 1920x1080 or any other resolution I want
- I will do here my own processing algorithm (does not matter what)
- Rescale it back to the original resolution
- Do
m_d3dContext->CopyResource(backBuffer.get(), frameSurface.get());
To be clear: This line (unlike in the original example) actually copies the resized texture (original resolution but not the original frame)
You don't need to be care about step 2.
Please let me know how to: downscale it to another resolution --> rescale it back to the original resolution. After that, all steps are like in the example. You copy the resized frame instead of the original frame.
Thanks!
from windows.ui.composition-win32-samples.
If you can send me a modified version of the code in
void SimpleCapture::OnFrameArrived(
Direct3D11CaptureFramePool const& sender,
winrt::Windows::Foundation::IInspectable const&)
Choose any resolution you want.. for example, you can write that the code will always resize it to 1024x768 and then resize it to the original frame resolution
I will be very thanks to you.
from windows.ui.composition-win32-samples.
One more important note: I want that the resize will be done natively and not using the CPU.
In Direct3D/DirectX. I don't want to "Map" the texture and modify the buffer via CPU.
I want to resize it natively.
I did not found any docs about resizing the ID3D11Texture2D
texture directly in the device.
from windows.ui.composition-win32-samples.
You need to setup a render target and texture a quad with the buffer (using shaders, a sampler, etc). Then you can use that render target (Or a copy of it with CopyResource) in the rest of your pipeline. I would look at D3D tutorials for that, that's outside the scope of these samples.
from windows.ui.composition-win32-samples.
I found that it will not help.
The GPU that scanning the frame is not so fast and this is the bottleneck.
At best, I get about 35 FPS on 4K, and then I have done my own processing using CUDA and it reduced to about 28FPS.. I don't have a very good start.
Please add support in the API to reduce the resolution of the scan so that at the very beginning I will not get the bottleneck.
If you add this support when it is expected to release?
from windows.ui.composition-win32-samples.
Unfortunately I can't provide a timeline at this time. I'll let you know when things change.
from windows.ui.composition-win32-samples.
OK, thanks.
I am watching this issue for updates about this.
from windows.ui.composition-win32-samples.
Hi @robmikh
Any update about this request?
The idea to scale it down myself did not solve any performance issues because I found that the bottleneck is on the OS level.
I need that the API will able to capture lower resolution.
I need it to solve this issue:
WindowTop/WindowTop-App#19
from windows.ui.composition-win32-samples.
There is no update at this time.
from windows.ui.composition-win32-samples.
OK thanks for the response.
Do you have some idea when will be update about the request?
from windows.ui.composition-win32-samples.
No
from windows.ui.composition-win32-samples.
@robmikh
Seems that I got it wrong all the time.
I see that what make it slow is not the capturing process.
It is the draw process.
I did some test with your ScreenCaptureforHWND example.
I captured 4k window in 2 ways:
- First time when I reduced a lot the size of ScreenCaptureforHWND window. To something small:
- When I increased the size of ScreenCaptureforHWND window
In the case that the ScreenCaptureforHWND window was very big, I noticed very big slowdown.
Is there a way to fix the example so it will work fast also when you draw the captured frame on much more pixels?
This seems to be the main issue or at least big part of it..
I was able to prove it also in another way
from windows.ui.composition-win32-samples.
@robmikh
Seems that I was right.
I tried to figure it out..
The first thing that I was thought about is this line:
I have 0 knowledge about all of this stuff but my common sense told me that the flag DXGI_SCALING_STRETCH
may be the issue that causing the slowdown in the rendering process.
So I tried to change it to DXGI_SCALING_NONE
but without success.
I used to get the error DXGI_ERROR_INVALID_CALL
But I did not give up.
My strategy was to look for any code on the internet that creating swap chain with flag DXGI_SCALING_NONE
Then I found this code via google search
https://github.com/HadrianFinch/ScreenSnipper/blob/c77ec1ea499febf313f55cf892f2d52be303780e/packages/robmikh.common.0.0.7-beta/include/robmikh.common/d3dHelpers.desktop.h#L31
Looks like it is your code from another example so I thought to use it somehow.
So I ended up using your CreateDXGISwapChainForWindow
function because it using DXGI_SCALING_NONE
.
This time the function succeeds but I still ended up with an error here:
Then my common sense told me that maybe I should just remove these lines:
auto surface = m_capture->CreateSurface(m_compositor);
m_brush.Surface(surface);
And it just worked!
And now I see that this API is working 100% fast.
All the time the issue was in the draw and not in the capturing
from windows.ui.composition-win32-samples.
Related Issues (20)
- Some samples use `WindowsRuntimeMarshal` class, that is no longer available in .NET 5+ HOT 4
- Cannot use IGraphicsCaptureItemInterop::CreateForWindow with electron apps HOT 6
- This repo is missing important files HOT 4
- How to capture Windows10/11 Virtual Desktop via Windows.Graphics.Capture ? HOT 2
- Accessing screen capture image bytes with MapFlags.DoNotWait for better CPU usage HOT 3
- Can I do successive captures on two different windows HOT 8
- ScreenCapture Sample - write capture stream to disk mp4? HOT 5
- Capture area of a monitor HOT 4
- Memory Leak? HOT 5
- BSODs on 4 separate Hard Drives HOT 3
- Multiple screen captures in a loop cause explorer.exe and native Windows app to lag? HOT 11
- Capture OnFrame Callback very slow on Win11 23H2 HOT 7
- access_denied in CreateForMonitor in some cases HOT 5
- Cannot catch errors in CreateCaptureItemForWindow HOT 3
- WGC CaptureFrame returns wrong SystemRelativeTime in window capture mode HOT 2
- Cursor may become invisible when recording some fullscreen games using WGC HOT 6
- Frame has issue after change window state (maximize from normal/ normal from maximize/ ...) HOT 1
- ScreenCaptureforHWND sample leaks handles leading to "Out of memory" crash HOT 1
- ScreenCaptureforHWND sample main thread hang HOT 2
- ScreenCaptureforHWND: How to get the byte data of the captured frame? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windows.ui.composition-win32-samples.