diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index ae945cede4..baafb9b23b 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -74,7 +74,7 @@ static const char * pscode = " return c;\n" "}\n"; -void DXSetViewport(float x, float y, float w, float h, float minZ, float maxZ) { +static void DXSetViewport(float x, float y, float w, float h, float minZ, float maxZ) { D3DVIEWPORT9 vp; vp.X = (DWORD)x; vp.Y = (DWORD)y; @@ -252,11 +252,13 @@ void DXSetViewport(float x, float y, float w, float h, float minZ, float maxZ) { void FramebufferManagerDX9::DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) { if (useBufferedRendering_ && vfb && vfb->fbo_dx9) { fbo_bind_as_render_target(vfb->fbo_dx9); - DXSetViewport(0, 0, vfb->renderWidth, vfb->renderHeight); + D3DVIEWPORT9 vp{ 0, 0, vfb->renderWidth, vfb->renderHeight, 0.0f, 1.0f }; + pD3Ddevice->SetViewport(&vp); } else { float x, y, w, h; CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, ROTATION_LOCKED_HORIZONTAL); - DXSetViewport(x, y, w, h); + D3DVIEWPORT9 vp{ (DWORD)x, (DWORD)y, (DWORD)w, (DWORD)h, 0.0f, 1.0f }; + pD3Ddevice->SetViewport(&vp); } MakePixelTexture(srcPixels, srcPixelFormat, srcStride, width, height); DisableState(); @@ -569,7 +571,7 @@ void DXSetViewport(float x, float y, float w, float h, float minZ, float maxZ) { shaderManager_->DirtyLastShader(); pD3Ddevice->SetTexture(0, nullptr); - DXSetViewport(0, 0, vfb->renderWidth, vfb->renderHeight); + DXSetViewport(0, 0, vfb->renderWidth, vfb->renderHeight, 0.0f, 1.0f); // This should clear stencil and alpha without changing the other colors. HRESULT hr = pD3Ddevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float)); @@ -784,7 +786,7 @@ void DXSetViewport(float x, float y, float w, float h, float minZ, float maxZ) { if (useBufferedRendering_) { // In buffered, we no longer clear the backbuffer before we start rendering. ClearBuffer(); - DXSetViewport(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); + DXSetViewport(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0.0f, 1.0f); } u32 offsetX = 0; @@ -894,7 +896,7 @@ void DXSetViewport(float x, float y, float w, float h, float minZ, float maxZ) { g_Config.iBufFilter == SCALE_LINEAR ? FB_BLIT_LINEAR : FB_BLIT_NEAREST); if (!result) { ERROR_LOG_REPORT_ONCE(blit_fail, G3D, "fbo_blit_color failed on display"); - DXSetViewport(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); + DXSetViewport(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0.0f, 1.0f); // These are in the output display coordinates if (g_Config.iBufFilter == SCALE_LINEAR) { dxstate.texMagFilter.set(D3DTEXF_LINEAR); diff --git a/GPU/Directx9/StencilBufferDX9.cpp b/GPU/Directx9/StencilBufferDX9.cpp index 4fe3767589..8c0457575f 100644 --- a/GPU/Directx9/StencilBufferDX9.cpp +++ b/GPU/Directx9/StencilBufferDX9.cpp @@ -221,7 +221,8 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, bool skipZer if (dstBuffer->fbo_dx9) { fbo_bind_as_render_target(dstBuffer->fbo_dx9); } - DXSetViewport(0, 0, w, h); + D3DVIEWPORT9 vp{ 0, 0, w, h, 0.0f, 1.0f }; + pD3Ddevice->SetViewport(&vp); MakePixelTexture(src, dstBuffer->format, dstBuffer->fb_stride, dstBuffer->bufferWidth, dstBuffer->bufferHeight); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 00fd208cc5..4f67bcb66f 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -741,7 +741,8 @@ public: pD3Ddevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); pD3Ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - DXSetViewport(0, 0, renderW_, renderH_); + D3DVIEWPORT9 vp{ 0, 0, (DWORD)renderW_, (DWORD)renderH_, 0.0f, 1.0f }; + pD3Ddevice->SetViewport(&vp); HRESULT hr = pD3Ddevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts_, (3 + 2) * sizeof(float)); if (FAILED(hr)) { ERROR_LOG_REPORT(G3D, "Depal render failed: %08x", hr); diff --git a/GPU/Directx9/helper/global.cpp b/GPU/Directx9/helper/global.cpp index 5f4cb3e31d..67b49c77e7 100644 --- a/GPU/Directx9/helper/global.cpp +++ b/GPU/Directx9/helper/global.cpp @@ -9,7 +9,6 @@ namespace DX9 { LPDIRECT3DDEVICE9 pD3Ddevice = nullptr; LPDIRECT3DDEVICE9EX pD3DdeviceEx = nullptr; -LPDIRECT3D9 pD3D = nullptr; IDirect3DVertexDeclaration9* pFramebufferVertexDecl = nullptr; @@ -19,9 +18,6 @@ static const D3DVERTEXELEMENT9 VertexElements[] = { D3DDECL_END() }; -LPDIRECT3DVERTEXSHADER9 pFramebufferVertexShader = nullptr; // Vertex Shader -LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader = nullptr; // Pixel Shader - bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, LPD3DXCONSTANTTABLE *pShaderTable, std::string &errorMessage) { ID3DXBuffer *pShaderCode = nullptr; ID3DXBuffer *pErrorMsg = nullptr; diff --git a/GPU/Directx9/helper/global.h b/GPU/Directx9/helper/global.h index 4b6bb79127..7929efb847 100644 --- a/GPU/Directx9/helper/global.h +++ b/GPU/Directx9/helper/global.h @@ -18,10 +18,5 @@ bool CompileShaders(std::string &errorMessage); bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage); bool CompileVertexShader(const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage); void DestroyShaders(); -void DirectxInit(HWND window); -void DXSetViewport(float x, float y, float w, float h, float minZ = 0.0f, float maxZ = 1.0f); - -#define D3DBLEND_UNK D3DBLEND_FORCE_DWORD - -}; +} // namespace diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index 7885833feb..1ee13d52cf 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -304,6 +304,12 @@ enum InfoField { RENDERER, }; +enum class NativeObject { + CONTEXT, + DEVICE, + DEVICE_EX, +}; + // Binary compatible with D3D11 viewport. struct Viewport { float TopLeftX; @@ -554,6 +560,8 @@ public: virtual std::string GetInfoString(InfoField info) const = 0; + virtual uintptr_t GetNativeObject(NativeObject obj) const = 0; + protected: void CreatePresets(); diff --git a/ext/native/thin3d/thin3d_d3d11.cpp b/ext/native/thin3d/thin3d_d3d11.cpp index b636a9aeed..294611367d 100644 --- a/ext/native/thin3d/thin3d_d3d11.cpp +++ b/ext/native/thin3d/thin3d_d3d11.cpp @@ -70,6 +70,17 @@ public: } } + uintptr_t GetNativeObject(NativeObject obj) const override { + switch (obj) { + case NativeObject::DEVICE: + return (uintptr_t)device_; + case NativeObject::CONTEXT: + return (uintptr_t)context_; + default: + return 0; + } + } + private: void ApplyCurrentState(); diff --git a/ext/native/thin3d/thin3d_d3d9.cpp b/ext/native/thin3d/thin3d_d3d9.cpp index 303c7ed4ba..83e437f327 100644 --- a/ext/native/thin3d/thin3d_d3d9.cpp +++ b/ext/native/thin3d/thin3d_d3d9.cpp @@ -580,6 +580,19 @@ public: void DrawUP(const void *vdata, int vertexCount) override; void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal); + uintptr_t GetNativeObject(NativeObject obj) const override { + switch (obj) { + case NativeObject::CONTEXT: + return (uintptr_t)d3d_; + case NativeObject::DEVICE: + return (uintptr_t)device_; + case NativeObject::DEVICE_EX: + return (uintptr_t)deviceEx_; + default: + return 0; + } + } + std::string GetInfoString(InfoField info) const override { switch (info) { case APIVERSION: return "DirectX 9.0"; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 4ce82deb7a..b701a6fb58 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -606,6 +606,11 @@ public: } } + uintptr_t GetNativeObject(NativeObject obj) const override { + return 0; + } + +private: std::vector samplerStates_; DeviceCaps caps_; diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 8c398f36b7..ffb5c77443 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -421,6 +421,10 @@ public: std::vector GetFeatureList() const override; + uintptr_t GetNativeObject(NativeObject obj) const override { + return 0; + } + private: void ApplyDynamicState(); void DirtyDynamicState();