Skip to content

Commit

Permalink
Merge pull request #15852 from hrydgard/more-code-cleanup
Browse files Browse the repository at this point in the history
Remove DX9 namespace, other code cleanup
  • Loading branch information
unknownbrackets authored Aug 17, 2022
2 parents ce395ed + d0cdb36 commit f7e4efd
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 271 deletions.
8 changes: 2 additions & 6 deletions Common/GPU/D3D9/D3D9StateCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

#include "Common/GPU/D3D9/D3D9StateCache.h"

namespace DX9 {

DirectXState dxstate;

LPDIRECT3DDEVICE9 pD3Ddevice = nullptr;
LPDIRECT3DDEVICE9EX pD3DdeviceEx = nullptr;
LPDIRECT3DDEVICE9 pD3Ddevice9 = nullptr;
LPDIRECT3DDEVICE9EX pD3DdeviceEx9 = nullptr;

int DirectXState::state_count = 0;

Expand Down Expand Up @@ -62,6 +60,4 @@ void DirectXState::Restore() {
texAddressW.restore(); count++;
}

} // namespace DX9

#endif // _MSC_VER
58 changes: 27 additions & 31 deletions Common/GPU/D3D9/D3D9StateCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"

namespace DX9 {

// TODO: Get rid of these somehow.
extern LPDIRECT3DDEVICE9 pD3Ddevice;
extern LPDIRECT3DDEVICE9EX pD3DdeviceEx;
extern LPDIRECT3DDEVICE9 pD3Ddevice9;
extern LPDIRECT3DDEVICE9EX pD3DdeviceEx9;

class DirectXState {
private:
Expand Down Expand Up @@ -44,7 +42,7 @@ class DirectXState {
return _value;
}
void restore() {
pD3Ddevice->SetRenderState(cap, _value);
pD3Ddevice9->SetRenderState(cap, _value);
}
};

Expand All @@ -69,7 +67,7 @@ class DirectXState {
p1 = old;
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state1, p1);
}
};

Expand All @@ -94,7 +92,7 @@ class DirectXState {
p1 = old;
}
void restore() {
pD3Ddevice->SetSamplerState(0, _state1, p1);
pD3Ddevice9->SetSamplerState(0, _state1, p1);
}
};

Expand Down Expand Up @@ -123,7 +121,7 @@ class DirectXState {
p1 = old;
}
void restore() {
pD3Ddevice->SetSamplerState(0, _state1, p1d);
pD3Ddevice9->SetSamplerState(0, _state1, p1d);
}
};

Expand All @@ -141,11 +139,11 @@ class DirectXState {
inline void set(DWORD newp1, DWORD newp2) {
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state1, p1);
}
if (p2 != newp2) {
p2 = newp2;
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice9->SetRenderState(_state2, p2);
}
}
void force(DWORD newp1, DWORD newp2) {
Expand All @@ -156,8 +154,8 @@ class DirectXState {
p2 = old2;
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice9->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state2, p2);
}
};

Expand All @@ -177,15 +175,15 @@ class DirectXState {
inline void set(DWORD newp1, DWORD newp2, DWORD newp3) {
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state1, p1);
}
if (p2 != newp2) {
p2 = newp2;
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice9->SetRenderState(_state2, p2);
}
if (p3 != newp3) {
p3 = newp3;
pD3Ddevice->SetRenderState(_state3, p3);
pD3Ddevice9->SetRenderState(_state3, p3);
}
}
void force(DWORD newp1, DWORD newp2, DWORD newp3) {
Expand All @@ -198,9 +196,9 @@ class DirectXState {
p3 = old3;
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice->SetRenderState(_state3, p3);
pD3Ddevice9->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state2, p2);
pD3Ddevice9->SetRenderState(_state3, p3);
}
};

Expand All @@ -222,19 +220,19 @@ class DirectXState {
inline void set(DWORD newp1, DWORD newp2, DWORD newp3, DWORD newp4) {
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state1, p1);
}
if (p2 != newp2) {
p2 = newp2;
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice9->SetRenderState(_state2, p2);
}
if (p3 != newp3) {
p3 = newp3;
pD3Ddevice->SetRenderState(_state3, p3);
pD3Ddevice9->SetRenderState(_state3, p3);
}
if (p4 != newp4) {
p4 = newp4;
pD3Ddevice->SetRenderState(_state4, p4);
pD3Ddevice9->SetRenderState(_state4, p4);
}
}
void force(DWORD newp1, DWORD newp2, DWORD newp3, DWORD newp4) {
Expand All @@ -249,10 +247,10 @@ class DirectXState {
p4 = old4;
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice->SetRenderState(_state3, p3);
pD3Ddevice->SetRenderState(_state3, p4);
pD3Ddevice9->SetRenderState(_state1, p1);
pD3Ddevice9->SetRenderState(_state2, p2);
pD3Ddevice9->SetRenderState(_state3, p3);
pD3Ddevice9->SetRenderState(_state3, p4);
}
};

Expand Down Expand Up @@ -284,7 +282,7 @@ class DirectXState {
c = old;
}
inline void restore() {
pD3Ddevice->SetRenderState(D3DRS_BLENDFACTOR, c);
pD3Ddevice9->SetRenderState(D3DRS_BLENDFACTOR, c);
}
};

Expand Down Expand Up @@ -318,7 +316,7 @@ class DirectXState {
}

inline void restore() {
pD3Ddevice->SetViewport(&viewport);
pD3Ddevice9->SetViewport(&viewport);
}
};

Expand All @@ -340,7 +338,7 @@ class DirectXState {
}

inline void restore() {
pD3Ddevice->SetScissorRect(&rect);
pD3Ddevice9->SetScissorRect(&rect);
}
};

Expand Down Expand Up @@ -412,5 +410,3 @@ struct GLExtensions {
extern GLExtensions gl_extensions;

void CheckGLExtensions();

};
12 changes: 1 addition & 11 deletions Common/GPU/D3D9/thin3d_d3d9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class D3D9DepthStencilState : public DepthStencilState {
D3DCMPFUNC stencilCompareOp;

void Apply(LPDIRECT3DDEVICE9 device, uint8_t stencilRef, uint8_t stencilWriteMask, uint8_t stencilCompareMask) {
using namespace DX9;
dxstate.depthTest.set(depthTestEnabled);
if (depthTestEnabled) {
dxstate.depthWrite.set(depthWriteEnabled);
Expand All @@ -174,7 +173,6 @@ class D3D9RasterState : public RasterState {
DWORD cullMode; // D3DCULL_*

void Apply(LPDIRECT3DDEVICE9 device) {
using namespace DX9;
dxstate.cullMode.set(cullMode);
dxstate.scissorTest.enable();
}
Expand All @@ -188,7 +186,6 @@ class D3D9BlendState : public BlendState {
uint32_t colorMask;

void Apply(LPDIRECT3DDEVICE9 device) {
using namespace DX9;
dxstate.blend.set(enabled);
dxstate.blendFunc.set(srcCol, dstCol, srcAlpha, dstAlpha);
dxstate.blendEquation.set(eqCol, eqAlpha);
Expand All @@ -202,7 +199,6 @@ class D3D9SamplerState : public SamplerState {
D3DTEXTUREFILTERTYPE magFilt, minFilt, mipFilt;

void Apply(LPDIRECT3DDEVICE9 device, int index) {
using namespace DX9;
dxstate.texAddressU.set(wrapS);
dxstate.texAddressV.set(wrapT);
dxstate.texMagFilter.set(magFilt);
Expand Down Expand Up @@ -689,7 +685,7 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID

shaderLanguageDesc_.Init(HLSL_D3D9);

DX9::dxstate.Restore();
dxstate.Restore();
}

D3D9Context::~D3D9Context() {
Expand Down Expand Up @@ -1037,15 +1033,11 @@ void D3D9Context::Clear(int mask, uint32_t colorval, float depthVal, int stencil
}

void D3D9Context::SetScissorRect(int left, int top, int width, int height) {
using namespace DX9;

dxstate.scissorRect.set(left, top, left + width, top + height);
dxstate.scissorTest.set(true);
}

void D3D9Context::SetViewports(int count, Viewport *viewports) {
using namespace DX9;

int x = (int)viewports[0].TopLeftX;
int y = (int)viewports[0].TopLeftY;
int w = (int)viewports[0].Width;
Expand All @@ -1058,7 +1050,6 @@ void D3D9Context::SetBlendFactor(float color[4]) {
uint32_t g = (uint32_t)(color[1] * 255.0f);
uint32_t b = (uint32_t)(color[2] * 255.0f);
uint32_t a = (uint32_t)(color[3] * 255.0f);
using namespace DX9;
dxstate.blendColor.set(color);
}

Expand Down Expand Up @@ -1179,7 +1170,6 @@ D3D9Framebuffer::~D3D9Framebuffer() {
}

void D3D9Context::BindFramebufferAsRenderTarget(Framebuffer *fbo, const RenderPassInfo &rp, const char *tag) {
using namespace DX9;
if (fbo) {
D3D9Framebuffer *fb = (D3D9Framebuffer *)fbo;
device_->SetRenderTarget(0, fb->surf);
Expand Down
Loading

0 comments on commit f7e4efd

Please sign in to comment.