remove useThread flag #10
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,7 @@
|
|||||||
#include "IUnityInterface.h"
|
#include "IUnityInterface.h"
|
||||||
#include "IUnityGraphicsD3D11.h"
|
#include "IUnityGraphicsD3D11.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
using namespace Microsoft::WRL;
|
using namespace Microsoft::WRL;
|
||||||
|
|
||||||
@@ -33,6 +34,29 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LUID GetUnityAdapterLuid()
|
||||||
|
{
|
||||||
|
const auto device = GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||||
|
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
||||||
|
if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgiDevice)))){
|
||||||
|
Debug::Error("QueryInterface from IUnityGraphicsD3D11 to IDXGIDevice1 failed.");
|
||||||
|
return LUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||||
|
if (FAILED(dxgiDevice->GetAdapter(&dxgiAdapter))) {
|
||||||
|
Debug::Error("QueryInterface from IDXGIDevice1 to IDXGIAdapter failed.");
|
||||||
|
return LUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
DXGI_ADAPTER_DESC adapterDesc;
|
||||||
|
dxgiAdapter->GetDesc(&adapterDesc);
|
||||||
|
|
||||||
|
return adapterDesc.AdapterLuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SendMessageToUnity(Message message)
|
void SendMessageToUnity(Message message)
|
||||||
{
|
{
|
||||||
g_messages.push(message);
|
g_messages.push(message);
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
|
||||||
// Unity interface and ID3D11Device getters
|
// Unity interface getter
|
||||||
struct IUnityInterfaces;
|
struct IUnityInterfaces;
|
||||||
IUnityInterfaces* GetUnity();
|
IUnityInterfaces* GetUnity();
|
||||||
|
|
||||||
|
// ID3D11Device (in Unity) getter
|
||||||
struct ID3D11Device;
|
struct ID3D11Device;
|
||||||
Microsoft::WRL::ComPtr<ID3D11Device> GetDevice();
|
Microsoft::WRL::ComPtr<ID3D11Device> GetDevice();
|
||||||
|
|
||||||
|
|
||||||
// Manager getter
|
// Manager getter
|
||||||
class MonitorManager;
|
class MonitorManager;
|
||||||
const std::unique_ptr<MonitorManager>& GetMonitorManager();
|
const std::unique_ptr<MonitorManager>& GetMonitorManager();
|
||||||
|
|
||||||
|
// Get adapter LUID to check the adapter of the monitor is same as Unity one.
|
||||||
|
LUID GetUnityAdapterLuid();
|
||||||
|
|
||||||
|
|
||||||
// Message is pooled and fetch from Unity.
|
// Message is pooled and fetch from Unity.
|
||||||
enum class Message
|
enum class Message
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ MonitorManager::~MonitorManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MonitorManager::Initialize(LUID unityAdapterLuid, bool useThread)
|
void MonitorManager::Initialize()
|
||||||
{
|
{
|
||||||
Finalize();
|
Finalize();
|
||||||
|
|
||||||
@@ -54,15 +54,11 @@ void MonitorManager::Initialize(LUID unityAdapterLuid, bool useThread)
|
|||||||
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
|
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
|
||||||
{
|
{
|
||||||
auto monitor = std::make_shared<Monitor>(id++);
|
auto monitor = std::make_shared<Monitor>(id++);
|
||||||
if (useThread) {
|
const auto unityAdapterLuid = GetUnityAdapterLuid();
|
||||||
monitor->InitializeThreaded(adapter
|
monitor->InitializeThreaded(adapter
|
||||||
, desc.AdapterLuid.HighPart == unityAdapterLuid.HighPart
|
, desc.AdapterLuid.HighPart == unityAdapterLuid.HighPart
|
||||||
&& desc.AdapterLuid.LowPart == unityAdapterLuid.LowPart
|
&& desc.AdapterLuid.LowPart == unityAdapterLuid.LowPart
|
||||||
, output);
|
, output);
|
||||||
}
|
|
||||||
else {
|
|
||||||
monitor->Initialize(output.Get());
|
|
||||||
}
|
|
||||||
monitors_.push_back(monitor);
|
monitors_.push_back(monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,9 +77,8 @@ void MonitorManager::RequireReinitilization()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MonitorManager::Reinitialize(bool useThread)
|
void MonitorManager::Reinitialize()
|
||||||
{
|
{
|
||||||
useThread_ = useThread;
|
|
||||||
Debug::Log("MonitorManager::Reinitialize()");
|
Debug::Log("MonitorManager::Reinitialize()");
|
||||||
Initialize();
|
Initialize();
|
||||||
SendMessageToUnity(Message::Reinitialized);
|
SendMessageToUnity(Message::Reinitialized);
|
||||||
@@ -137,7 +132,7 @@ void MonitorManager::Update()
|
|||||||
{
|
{
|
||||||
if (isReinitializationRequired_)
|
if (isReinitializationRequired_)
|
||||||
{
|
{
|
||||||
Reinitialize(useThread_);
|
Reinitialize();
|
||||||
isReinitializationRequired_ = false;
|
isReinitializationRequired_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class MonitorManager
|
|||||||
public:
|
public:
|
||||||
explicit MonitorManager(LUID unityAdapterLuid_);
|
explicit MonitorManager(LUID unityAdapterLuid_);
|
||||||
~MonitorManager();
|
~MonitorManager();
|
||||||
void Reinitialize(bool useThread);
|
void Reinitialize();
|
||||||
bool HasMonitorCountChanged() const;
|
bool HasMonitorCountChanged() const;
|
||||||
void RequireReinitilization();
|
void RequireReinitilization();
|
||||||
void SetCursorMonitorId(int id) { cursorMonitorId_ = id; }
|
void SetCursorMonitorId(int id) { cursorMonitorId_ = id; }
|
||||||
@@ -24,8 +24,7 @@ public:
|
|||||||
std::shared_ptr<Cursor> GetCursor() const;
|
std::shared_ptr<Cursor> GetCursor() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Initialize(){ Initialize(unityAdapterLuid_, useThread_); }
|
void Initialize();
|
||||||
void Initialize(LUID unityAdapterLuid, bool useThread);
|
|
||||||
void Finalize();
|
void Finalize();
|
||||||
|
|
||||||
// Setters from Unity
|
// Setters from Unity
|
||||||
@@ -39,11 +38,9 @@ public:
|
|||||||
int GetMonitorCount() const;
|
int GetMonitorCount() const;
|
||||||
int GetTotalWidth() const;
|
int GetTotalWidth() const;
|
||||||
int GetTotalHeight() const;
|
int GetTotalHeight() const;
|
||||||
bool UseThread()const { return useThread_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LUID unityAdapterLuid_;
|
LUID unityAdapterLuid_;
|
||||||
bool useThread_ = false;
|
|
||||||
|
|
||||||
int timeout_ = 10;
|
int timeout_ = 10;
|
||||||
bool enableTextureCopyFromGpuToCpu_ = false;
|
bool enableTextureCopyFromGpuToCpu_ = false;
|
||||||
|
|||||||
@@ -106,12 +106,7 @@ extern "C"
|
|||||||
if (!g_manager) return;
|
if (!g_manager) return;
|
||||||
if (auto monitor = g_manager->GetMonitor(id))
|
if (auto monitor = g_manager->GetMonitor(id))
|
||||||
{
|
{
|
||||||
if (g_manager->UseThread()) {
|
monitor->CopyTextureFromThread();
|
||||||
monitor->CopyTextureFromThread();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
monitor->Render(g_manager->GetTimeout());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,10 +115,10 @@ extern "C"
|
|||||||
return OnRenderEvent;
|
return OnRenderEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Reinitialize(int useThread)
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Reinitialize()
|
||||||
{
|
{
|
||||||
if (!g_manager) return;
|
if (!g_manager) return;
|
||||||
return g_manager->Reinitialize(useThread);
|
return g_manager->Reinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Update()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Update()
|
||||||
|
|||||||
Binary file not shown.
@@ -1,2 +1 @@
|
|||||||
m_EditorVersion: 5.4.2f2
|
m_EditorVersion: 5.5.0f3
|
||||||
m_StandardAssetsVersion: 0
|
|
||||||
|
|||||||
Reference in New Issue
Block a user