Skip to content

Commit 8e5ae01

Browse files
committed
improve performance.
1 parent daef7e0 commit 8e5ae01

File tree

12 files changed

+25
-25
lines changed

12 files changed

+25
-25
lines changed
0 Bytes
Binary file not shown.
83 KB
Binary file not shown.
107 KB
Binary file not shown.

Assets/uWindowCapture/Scripts/UwcLib.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ public static class Lib
8686
public static extern IntPtr GetRenderEventFunc();
8787
[DllImport(name, EntryPoint = "UwcUpdate")]
8888
public static extern void Update(float dt);
89-
[DllImport(name, EntryPoint = "UwcTriggerGpuUpload")]
90-
public static extern void TriggerGpuUpload();
9189
[DllImport(name, EntryPoint = "UwcGetMessageCount")]
9290
private static extern int GetMessageCount();
9391
[DllImport(name, EntryPoint = "UwcGetMessages")]

Assets/uWindowCapture/Scripts/UwcManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ IEnumerator Render()
167167
for (;;) {
168168
yield return new WaitForEndOfFrame();
169169
GL.IssuePluginEvent(renderEventFunc_, 0);
170-
Lib.TriggerGpuUpload();
171170
}
172171
}
173172

Plugins/uWindowCapture/uWindowCapture/Main.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ extern "C"
126126
WindowManager::Get().Update(dt);
127127
}
128128

129-
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UwcTriggerGpuUpload()
130-
{
131-
if (WindowManager::IsNull()) return;
132-
WindowManager::Get().GetUploadManager()->TriggerGpuUpload();
133-
}
134-
135129
UNITY_INTERFACE_EXPORT UINT UNITY_INTERFACE_API UwcGetMessageCount()
136130
{
137131
if (MessageManager::IsNull()) return 0;

Plugins/uWindowCapture/uWindowCapture/UploadManager.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ using TexturePtr = Microsoft::WRL::ComPtr<ID3D11Texture2D>;
2020

2121

2222

23+
namespace
24+
{
25+
constexpr auto kLoopMinTime = std::chrono::microseconds(100);
26+
}
27+
28+
29+
// ---
30+
31+
2332
UploadManager::UploadManager()
2433
{
2534
initThread_ = std::thread([this]
@@ -120,10 +129,6 @@ void UploadManager::StartUploadThread()
120129
{
121130
threadLoop_.Start([this]
122131
{
123-
// Waiting for being triggered...
124-
if (!hasUploadTriggered_) return;
125-
hasUploadTriggered_ = false;
126-
127132
// Check window upload
128133
const int windowId = windowUploadQueue_.Dequeue();
129134
if (windowId >= 0 && WindowManager::Get().CheckExistence(windowId))
@@ -149,7 +154,7 @@ void UploadManager::StartUploadThread()
149154
{
150155
cursor->Upload();
151156
}
152-
}, std::chrono::microseconds(1000));
157+
}, kLoopMinTime);
153158
}
154159

155160

@@ -168,10 +173,4 @@ void UploadManager::RequestUploadWindow(int id)
168173
void UploadManager::RequestUploadIcon(int id)
169174
{
170175
iconUploadQueue_.Enqueue(id);
171-
}
172-
173-
174-
void UploadManager::TriggerGpuUpload()
175-
{
176-
hasUploadTriggered_ = true;
177176
}

Plugins/uWindowCapture/uWindowCapture/UploadManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class UploadManager
2727
void RequestUploadIcon(int id);
2828
void StartUploadThread();
2929
void StopUploadThread();
30-
void TriggerGpuUpload();
3130

3231
private:
3332
void CreateDevice();
@@ -38,5 +37,4 @@ class UploadManager
3837
ThreadLoop threadLoop_;
3938
WindowQueue windowUploadQueue_;
4039
WindowQueue iconUploadQueue_;
41-
std::atomic<bool> hasUploadTriggered_ = false;
4240
};

Plugins/uWindowCapture/uWindowCapture/Util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <chrono>
66
#include <Windows.h>
77

8-
// #define UWC_DEBUG_ON
8+
#define UWC_DEBUG_ON
99

1010

1111
// Window utilities

Plugins/uWindowCapture/uWindowCapture/WindowTexture.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ bool WindowTexture::Upload()
437437

438438
bool WindowTexture::RecreateSharedTextureIfNeeded()
439439
{
440-
UWC_SCOPE_TIMER(UploadByWin32API)
440+
UWC_SCOPE_TIMER(RecreateSharedTextureIfNeeded)
441441

442442
if (!unityTexture_.load())
443443
{
@@ -512,6 +512,8 @@ bool WindowTexture::RecreateSharedTextureIfNeeded()
512512

513513
bool WindowTexture::UploadByWin32API()
514514
{
515+
UWC_SCOPE_TIMER(UploadByWin32API)
516+
515517
std::lock_guard<std::mutex> lock(bufferMutex_);
516518

517519
const auto& uploader = WindowManager::GetUploadManager();
@@ -544,6 +546,7 @@ bool WindowTexture::UploadByWindowsGraphicsCapture()
544546

545547
ComPtr<ID3D11DeviceContext> context;
546548
uploader->GetDevice()->GetImmediateContext(&context);
549+
/*
547550
context->CopySubresourceRegion(
548551
sharedTexture_.Get(),
549552
D3D11CalcSubresource(0, 0, 1),
@@ -552,7 +555,8 @@ bool WindowTexture::UploadByWindowsGraphicsCapture()
552555
0,
553556
result.pTexture,
554557
0,
555-
NULL);
558+
NULL);*/
559+
context->CopyResource(sharedTexture_.Get(), result.pTexture);
556560
context->Flush();
557561

558562
if (result.hasSizeChanged)

0 commit comments

Comments
 (0)