Add inline DX device getters

This commit is contained in:
Kawe Mazidjatari 2023-09-11 01:28:17 +02:00
parent ee1a2c5207
commit 0fe7b40506
3 changed files with 16 additions and 9 deletions

View File

@ -183,10 +183,13 @@ bool CEngineAPI::MainLoop()
params.minimumIntervalUs = fpsMax > 0 ? (NvU32)((1000.0f / fpsMax) * 1000.0f) : 0;
params.bUseMarkersToOptimize = false;
NvAPI_Status status = NvAPI_D3D_SetSleepMode(*g_ppGameDevice, &params);
ID3D11Device* pGameDevice = D3D11Device();
Assert(pGameDevice);
NvAPI_Status status = NvAPI_D3D_SetSleepMode(pGameDevice, &params);
if (status == NVAPI_OK)
NvAPI_D3D_Sleep(*g_ppGameDevice);
NvAPI_D3D_Sleep(pGameDevice);
CEngineAPI_PumpMessages();
#endif // !DEDICATED

View File

@ -90,7 +90,7 @@ void ImGui_Init()
io.ConfigFlags |= ImGuiConfigFlags_IsSRGB;
ImGui_ImplWin32_Init(*g_pGameWindow);
ImGui_ImplDX11_Init(*g_ppGameDevice, *g_ppImmediateContext);
ImGui_ImplDX11_Init(D3D11Device(), D3D11DeviceContext());
}
void ImGui_Shutdown()
@ -231,7 +231,7 @@ void CreateTextureResource(TextureHeader_t* textureHeader, INT_PTR imageData)
const uint32_t offsetStartResourceData = mipLevel << 4u;
const D3D11_SUBRESOURCE_DATA* subResData = (D3D11_SUBRESOURCE_DATA*)((uint8_t*)initialData + offsetStartResourceData);
const HRESULT createTextureRes = (*g_ppGameDevice)->CreateTexture2D(&textureDesc, subResData, &textureHeader->m_ppTexture);
const HRESULT createTextureRes = D3D11Device()->CreateTexture2D(&textureDesc, subResData, &textureHeader->m_ppTexture);
if (createTextureRes < S_OK)
Error(eDLL_T::RTECH, EXIT_FAILURE, "Couldn't create texture \"%s\": error code = %08x\n", textureHeader->m_pDebugName, createTextureRes);
@ -249,7 +249,7 @@ void CreateTextureResource(TextureHeader_t* textureHeader, INT_PTR imageData)
shaderResource.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
}
const HRESULT createShaderResourceRes = (*g_ppGameDevice)->CreateShaderResourceView(textureHeader->m_ppTexture, &shaderResource, &textureHeader->m_ppShaderResourceView);
const HRESULT createShaderResourceRes = D3D11Device()->CreateShaderResourceView(textureHeader->m_ppTexture, &shaderResource, &textureHeader->m_ppShaderResourceView);
if (createShaderResourceRes < S_OK)
Error(eDLL_T::RTECH, EXIT_FAILURE, "Couldn't create shader resource view for texture \"%s\": error code = %08x\n", textureHeader->m_pDebugName, createShaderResourceRes);
}
@ -290,7 +290,7 @@ bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView*
subResource.pSysMem = pImageData;
subResource.SysMemPitch = desc.Width * 4;
subResource.SysMemSlicePitch = 0;
(*g_ppGameDevice)->CreateTexture2D(&desc, &subResource, &pTexture);
D3D11Device()->CreateTexture2D(&desc, &subResource, &pTexture);
// Create texture view
ZeroMemory(&srvDesc, sizeof(srvDesc));
@ -301,7 +301,7 @@ bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView*
if (pTexture)
{
(*g_ppGameDevice)->CreateShaderResourceView(pTexture, &srvDesc, out_srv);
D3D11Device()->CreateShaderResourceView(pTexture, &srvDesc, out_srv);
pTexture->Release();
}

View File

@ -107,9 +107,13 @@ enum class DXGISwapChainVTbl : short
};
#ifndef BUILDING_LIBIMGUI
inline ID3D11Device** g_ppGameDevice = nullptr;
inline ID3D11Device** g_ppGameDevice = nullptr;
inline ID3D11DeviceContext** g_ppImmediateContext = nullptr;
inline IDXGISwapChain** g_ppSwapChain = nullptr;
inline IDXGISwapChain** g_ppSwapChain = nullptr;
FORCEINLINE ID3D11Device* D3D11Device() { Assert(g_ppGameDevice); return (*g_ppGameDevice); }
FORCEINLINE ID3D11DeviceContext* D3D11DeviceContext() { Assert(g_ppImmediateContext); return (*g_ppImmediateContext); }
FORCEINLINE IDXGISwapChain* D3D11SwapChain() { Assert(g_ppSwapChain); return (*g_ppSwapChain); }
class VDXGI : public IDetour
{