Skip to content

Commit

Permalink
Merge branch 'origin/lvengesanam/implement_query_apis' into 'main'
Browse files Browse the repository at this point in the history
Implement missing Query functions in Bridge

See merge request lightspeedrtx/bridge-remix-nv!26
  • Loading branch information
lvengesanam committed Jul 25, 2023
2 parents 3d81628 + 0513fe2 commit 44ed02b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 13 deletions.
54 changes: 45 additions & 9 deletions src/client/d3d9_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#include "pch.h"
#include "d3d9_query.h"
#include "util_devicecommand.h"

HRESULT Direct3DQuery9_LSS::QueryInterface(REFIID riid, LPVOID* ppvObj) {
LogFunctionCall();
Expand Down Expand Up @@ -51,7 +52,11 @@ ULONG Direct3DQuery9_LSS::Release() {
}

void Direct3DQuery9_LSS::onDestroy() {
// TODO: implement me.
LogFunctionCall();
BRIDGE_PARENT_DEVICE_LOCKGUARD();
{
ClientMessage { Commands::IDirect3DQuery9_Destroy, getId() };
}
}

HRESULT Direct3DQuery9_LSS::GetDevice(IDirect3DDevice9** ppDevice) {
Expand Down Expand Up @@ -88,15 +93,46 @@ DWORD Direct3DQuery9_LSS::GetDataSize() {
}

HRESULT Direct3DQuery9_LSS::Issue(DWORD dwIssueFlags) {
LogMissingFunctionCall();
// TODO: Implement queries across the bridge.
// For now return success. Some apps will spin wait on these
return S_OK;
LogFunctionCall();

UID currentUID = 0;
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
{
ClientMessage c(Commands::IDirect3DQuery9_Issue, getId());
currentUID = c.get_uid();
c.send_data(dwIssueFlags);
}
}

WAIT_FOR_OPTIONAL_SERVER_RESPONSE("Direct3DQuery9_LSS::Issue()", D3DERR_INVALIDCALL, currentUID);

return S_OK;
}

HRESULT Direct3DQuery9_LSS::GetData(void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
LogMissingFunctionCall();
// TODO: Implement queries across the bridge.
// For now return success. Some apps will spin wait on these
return S_OK;
LogFunctionCall();

UID currentUID = 0;
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
{
ClientMessage c(Commands::IDirect3DQuery9_GetData, getId());
currentUID = c.get_uid();
c.send_data(dwSize);
c.send_data(dwGetDataFlags);
}
}

WAIT_FOR_SERVER_RESPONSE("Direct3DQuery9_LSS::GetData()", D3DERR_INVALIDCALL, currentUID);
HRESULT hresult = DeviceBridge::get_data();
if (SUCCEEDED(hresult) && dwSize > 0 && pData != NULL) {
void* pDataReturned = NULL;
DeviceBridge::get_data(&pDataReturned);
memcpy(pData, pDataReturned, dwSize);
}

DeviceBridge::pop_front();

return hresult;
}
46 changes: 43 additions & 3 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ std::unordered_map<uint32_t, IDirect3DStateBlock9*> gpD3DStateBlocks;
std::unordered_map<uint32_t, IDirect3DVertexShader9*> gpD3DVertexShaders;
std::unordered_map<uint32_t, IDirect3DPixelShader9*> gpD3DPixelShaders;
std::unordered_map<uint32_t, IDirect3DSwapChain9*> gpD3DSwapChains;
std::unordered_map<uint32_t, IDirect3DQuery9*> gpD3DQuery;

// Global state
bool gbBridgeRunning = true;
Expand Down Expand Up @@ -1545,9 +1546,11 @@ void ProcessDeviceCommandQueue() {
GET_RES(pD3DDevice, gpD3DDevices);
PULL(D3DQUERYTYPE, Type);
PULL_HND(pHandle);
// Do nothing

// TODO: Implement query 'getters', until then, Queries are useless here.
IDirect3DQuery9* ppQuery;
const auto hresult = pD3DDevice->CreateQuery(IN Type, OUT & ppQuery);
if (SUCCEEDED(hresult)) {
gpD3DQuery[pHandle] = ppQuery;
}
break;
}
/*
Expand Down Expand Up @@ -2545,17 +2548,54 @@ void ProcessDeviceCommandQueue() {
case IDirect3DQuery9_AddRef:
break;
case IDirect3DQuery9_Destroy:
{
GET_HND(pHandle);
const auto& pQuery = (IDirect3DQuery9*) gpD3DQuery[pHandle];
safeDestroy(pQuery, pHandle);
gpD3DQuery.erase(pHandle);
break;
}
case IDirect3DQuery9_GetDevice:
break;
case IDirect3DQuery9_GetType:
break;
case IDirect3DQuery9_GetDataSize:
break;
case IDirect3DQuery9_Issue:
{
GET_HND(pHandle);
PULL(DWORD, dwIssueFlags);
const auto &pQuery = gpD3DQuery[pHandle];
const auto hresult = pQuery->Issue(dwIssueFlags);
SEND_OPTIONAL_SERVER_RESPONSE(hresult, currentUID);
break;
}
case IDirect3DQuery9_GetData:
{
GET_HND(pHandle);
PULL(DWORD, dwSize);
PULL(DWORD, dwGetDataFlags);
const auto& pQuery = gpD3DQuery[pHandle];
void* pData = NULL;
if (dwSize > 0) {
pData = new char[dwSize];
}
const auto hresult = pQuery->GetData(pData, dwSize, dwGetDataFlags);

ServerMessage c(Commands::Bridge_Response, currentUID);
c.send_data(hresult);
if (SUCCEEDED(hresult) && dwSize > 0) {
if (auto* blobPacketPtr = c.begin_data_blob(dwSize)) {
memcpy(blobPacketPtr, pData, dwSize);
c.end_data_blob();
}
}

if (dwSize > 0) {
delete[]pData;
}
break;
}

/*
* Other commands
Expand Down
2 changes: 1 addition & 1 deletion src/util/util_bridgecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ DECL_BRIDGE_FUNC(bridge_util::Result, waitForCommand, const Commands::D3D9Comman
#endif
return Result::Success;
} else {
Logger::debug(format_string("Different instance of a command detected: %s. Expected: %s with UID: %s. ", Commands::toString(header.command).c_str(),
Logger::debug(format_string("Different instance of a command detected: %s with UID: %s , Expected: %s with UID: %s. ", Commands::toString(header.command).c_str(), std::to_string(header.pHandle).c_str(),
Commands::toString(command).c_str(), std::to_string(uidToVerify).c_str()));
// If we see the incorrect command, we want to give the other side of
// the bridge ample time to make an attempt to process it first
Expand Down

0 comments on commit 44ed02b

Please sign in to comment.