From f55b6a0dbc59e8836ebfec47a959791968612092 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 15 Sep 2013 08:53:21 -0700 Subject: [PATCH] Put the DirectX9 stuff into a namespace. This makes it almost build on Windows, but not quite. Some required files excluded from build, still. --- GPU/Directx9/FramebufferDX9.cpp | 43 ++++++++++++----------- GPU/Directx9/FramebufferDX9.h | 32 ++++++++++------- GPU/Directx9/GPU_DX9.cpp | 8 +++-- GPU/Directx9/GPU_DX9.h | 6 ++++ GPU/Directx9/PixelShaderGeneratorDX9.cpp | 4 +++ GPU/Directx9/PixelShaderGeneratorDX9.h | 4 +++ GPU/Directx9/ShaderManagerDX9.cpp | 4 +++ GPU/Directx9/ShaderManagerDX9.h | 4 +++ GPU/Directx9/SplineDX9.cpp | 7 +++- GPU/Directx9/StateMappingDX9.cpp | 4 +++ GPU/Directx9/TextureCacheDX9.cpp | 14 +++++--- GPU/Directx9/TextureCacheDX9.h | 15 ++++---- GPU/Directx9/TextureScalerDX9.cpp | 8 +++++ GPU/Directx9/TextureScalerDX9.h | 4 +++ GPU/Directx9/TransformPipelineDX9.cpp | 5 +++ GPU/Directx9/TransformPipelineDX9.h | 8 +++-- GPU/Directx9/VertexDecoderDX9.cpp | 6 +++- GPU/Directx9/VertexDecoderDX9.h | 3 ++ GPU/Directx9/VertexShaderGeneratorDX9.cpp | 4 +++ GPU/Directx9/VertexShaderGeneratorDX9.h | 4 +++ GPU/Directx9/helper/dx_state.cpp | 6 +++- GPU/Directx9/helper/dx_state.h | 4 +++ GPU/Directx9/helper/fbo.cpp | 6 +++- GPU/Directx9/helper/fbo.h | 6 +++- GPU/Directx9/helper/global.cpp | 6 +++- GPU/Directx9/helper/global.h | 8 +++-- GPU/GPU.vcxproj | 18 +++++++++- GPU/GPU.vcxproj.filters | 21 +++++++++++ GPU/GPUState.cpp | 13 ++++--- 29 files changed, 211 insertions(+), 64 deletions(-) diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index edde56fad9..4ec707512d 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -30,6 +30,7 @@ #include "GPU/Directx9/TextureCacheDX9.h" #include "GPU/Directx9/ShaderManagerDX9.h" +namespace DX9 { // Aggressively delete unused FBO:s to save gpu memory. enum { @@ -284,10 +285,10 @@ void FramebufferManagerDX9::DrawActiveTexture(float x, float y, float w, float h pD3Ddevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float)); } -VirtualFramebuffer *FramebufferManagerDX9::GetDisplayFBO() { - VirtualFramebuffer *match = NULL; +VirtualFramebufferDX9 *FramebufferManagerDX9::GetDisplayFBO() { + VirtualFramebufferDX9 *match = NULL; for (size_t i = 0; i < vfbs_.size(); ++i) { - VirtualFramebuffer *v = vfbs_[i]; + VirtualFramebufferDX9 *v = vfbs_[i]; if (MaskedEqual(v->fb_address, displayFramebufPtr_) && v->format == displayFormat_ && v->width >= 480) { // Could check w too but whatever if (match == NULL || match->last_frame_render < v->last_frame_render) { @@ -353,7 +354,7 @@ static void DrawingSize(int &drawing_width, int &drawing_height) { } } -void FramebufferManagerDX9::DestroyFramebuf(VirtualFramebuffer *v) { +void FramebufferManagerDX9::DestroyFramebuf(VirtualFramebufferDX9 *v) { textureCache_->NotifyFramebuffer(v->fb_address, v, NOTIFY_FB_DESTROYED); if (v->fbo) { fbo_destroy(v->fbo); @@ -406,9 +407,9 @@ void FramebufferManagerDX9::SetRenderFrameBuffer() { int buffer_height = drawing_height; // Find a matching framebuffer - VirtualFramebuffer *vfb = 0; + VirtualFramebufferDX9 *vfb = 0; for (size_t i = 0; i < vfbs_.size(); ++i) { - VirtualFramebuffer *v = vfbs_[i]; + VirtualFramebufferDX9 *v = vfbs_[i]; if (MaskedEqual(v->fb_address, fb_address) && v->format == fmt) { // Let's not be so picky for now. Let's say this is the one. vfb = v; @@ -429,7 +430,7 @@ void FramebufferManagerDX9::SetRenderFrameBuffer() { // None found? Create one. if (!vfb) { gstate_c.textureChanged = true; - vfb = new VirtualFramebuffer(); + vfb = new VirtualFramebufferDX9(); vfb->fbo = 0; vfb->fb_address = fb_address; vfb->fb_stride = fb_stride; @@ -598,7 +599,7 @@ void FramebufferManagerDX9::CopyDisplayToOutput() { currentRenderVfb_ = 0; - VirtualFramebuffer *vfb = GetDisplayFBO(); + VirtualFramebufferDX9 *vfb = GetDisplayFBO(); if (!vfb) { if (Memory::IsValidAddress(ramDisplayFramebufPtr_)) { // The game is displaying something directly from RAM. In GTA, it's decoded video. @@ -644,7 +645,7 @@ void FramebufferManagerDX9::CopyDisplayToOutput() { } } -void FramebufferManagerDX9::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync) { +void FramebufferManagerDX9::ReadFramebufferToMemory(VirtualFramebufferDX9 *vfb, bool sync) { // This only works with buffered rendering if (!useBufferedRendering_) { return; @@ -660,11 +661,11 @@ void FramebufferManagerDX9::ReadFramebufferToMemory(VirtualFramebuffer *vfb, boo // We'll pseudo-blit framebuffers here to get a resized and flipped version of vfb. // For now we'll keep these on the same struct as the ones that can get displayed // (and blatantly copy work already done above while at it). - VirtualFramebuffer *nvfb = 0; + VirtualFramebufferDX9 *nvfb = 0; // We maintain a separate vector of framebuffer objects for blitting. for (size_t i = 0; i < bvfbs_.size(); ++i) { - VirtualFramebuffer *v = bvfbs_[i]; + VirtualFramebufferDX9 *v = bvfbs_[i]; if (MaskedEqual(v->fb_address, vfb->fb_address) && v->format == vfb->format) { if (v->bufferWidth == vfb->bufferWidth && v->bufferHeight == vfb->bufferHeight) { nvfb = v; @@ -678,7 +679,7 @@ void FramebufferManagerDX9::ReadFramebufferToMemory(VirtualFramebuffer *vfb, boo // Create a new fbo if none was found for the size if(!nvfb) { - nvfb = new VirtualFramebuffer(); + nvfb = new VirtualFramebufferDX9(); nvfb->fbo = 0; nvfb->fb_address = vfb->fb_address; nvfb->fb_stride = vfb->fb_stride; @@ -749,7 +750,7 @@ void FramebufferManagerDX9::ReadFramebufferToMemory(VirtualFramebuffer *vfb, boo } } -void FramebufferManagerDX9::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFramebuffer *dst, bool flip, float upscale, float vscale) { +void FramebufferManagerDX9::BlitFramebuffer_(VirtualFramebufferDX9 *src, VirtualFramebufferDX9 *dst, bool flip, float upscale, float vscale) { // This only works with buffered rendering if (!useBufferedRendering_ || !src->fbo) { return; @@ -825,7 +826,7 @@ static void ConvertFromRGBA8888(u8 *dst, u8 *src, u32 stride, u32 height, GEBuff #include #endif -static void Resolve(u8* data, VirtualFramebuffer *vfb) { +static void Resolve(u8* data, VirtualFramebufferDX9 *vfb) { #ifdef _XBOX D3DTexture * rtt = (D3DTexture*)fbo_get_rtt(vfb->fbo); pD3Ddevice->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, rtt, NULL, 0, 0, NULL, 0.f, 0, NULL); @@ -839,7 +840,7 @@ static void Resolve(u8* data, VirtualFramebuffer *vfb) { #endif } -void FramebufferManagerDX9::PackFramebufferDirectx9_(VirtualFramebuffer *vfb) { +void FramebufferManagerDX9::PackFramebufferDirectx9_(VirtualFramebufferDX9 *vfb) { if (useBufferedRendering_ && vfb->fbo) { fbo_bind_for_read(vfb->fbo); } else { @@ -910,7 +911,7 @@ std::vector FramebufferManagerDX9::GetFramebufferList() { std::vector list; for (size_t i = 0; i < vfbs_.size(); ++i) { - VirtualFramebuffer *vfb = vfbs_[i]; + VirtualFramebufferDX9 *vfb = vfbs_[i]; FramebufferInfo info; info.fb_address = vfb->fb_address; @@ -934,7 +935,7 @@ void FramebufferManagerDX9::DecimateFBOs() { bool useMem = g_Config.iRenderingMode == FB_READFBOMEMORY_GPU; #endif for (size_t i = 0; i < vfbs_.size(); ++i) { - VirtualFramebuffer *vfb = vfbs_[i]; + VirtualFramebufferDX9 *vfb = vfbs_[i]; int age = frameLastFramebufUsed - std::max(vfb->last_frame_render, vfb->last_frame_used); if(useMem && age == 0 && !vfb->memoryUpdated) { @@ -954,7 +955,7 @@ void FramebufferManagerDX9::DecimateFBOs() { // Do the same for ReadFramebuffersToMemory's VFBs for (size_t i = 0; i < bvfbs_.size(); ++i) { - VirtualFramebuffer *vfb = bvfbs_[i]; + VirtualFramebufferDX9 *vfb = bvfbs_[i]; int age = frameLastFramebufUsed - vfb->last_frame_render; if (age > FBO_OLD_AGE) { INFO_LOG(SCEGE, "Decimating FBO for %08x (%i x %i x %i), age %i", vfb->fb_address, vfb->width, vfb->height, vfb->format, age) @@ -972,7 +973,7 @@ void FramebufferManagerDX9::DestroyAllFBOs() { prevPrevDisplayFramebuf_ = 0; for (size_t i = 0; i < vfbs_.size(); ++i) { - VirtualFramebuffer *vfb = vfbs_[i]; + VirtualFramebufferDX9 *vfb = vfbs_[i]; INFO_LOG(SCEGE, "Destroying FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format); DestroyFramebuf(vfb); } @@ -993,7 +994,7 @@ void FramebufferManagerDX9::UpdateFromMemory(u32 addr, int size) { bool needUnbind = false; for (size_t i = 0; i < vfbs_.size(); ++i) { - VirtualFramebuffer *vfb = vfbs_[i]; + VirtualFramebufferDX9 *vfb = vfbs_[i]; if (MaskedEqual(vfb->fb_address, addr)) { vfb->dirtyAfterDisplay = true; vfb->reallyDirtyAfterDisplay = true; @@ -1019,3 +1020,5 @@ void FramebufferManagerDX9::UpdateFromMemory(u32 addr, int size) { void FramebufferManagerDX9::Resized() { resized_ = true; } + +}; diff --git a/GPU/Directx9/FramebufferDX9.h b/GPU/Directx9/FramebufferDX9.h index 1a4e1d7bc0..5488dc9ee5 100644 --- a/GPU/Directx9/FramebufferDX9.h +++ b/GPU/Directx9/FramebufferDX9.h @@ -18,6 +18,7 @@ #pragma once #include +#include "d3d9.h" #include "GPU/Directx9/helper/fbo.h" // Keeps track of allocated FBOs. @@ -28,6 +29,8 @@ #include "Globals.h" #include "GPU/GPUCommon.h" +namespace DX9 { + struct GLSLProgram; class TextureCacheDX9; @@ -44,7 +47,7 @@ enum { FB_READFBOMEMORY_GPU = 3, }; -struct VirtualFramebuffer { +struct VirtualFramebufferDX9 { int last_frame_used; int last_frame_render; bool memoryUpdated; @@ -79,6 +82,7 @@ struct VirtualFramebuffer { void CenterRect(float *x, float *y, float *w, float *h, float origW, float origH, float frameW, float frameH); + class ShaderManagerDX9; class FramebufferManagerDX9 { @@ -107,10 +111,10 @@ public: void SetRenderFrameBuffer(); // Uses parameters computed from gstate void UpdateFromMemory(u32 addr, int size); - void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync = true); + void ReadFramebufferToMemory(VirtualFramebufferDX9 *vfb, bool sync = true); // TODO: Break out into some form of FBO manager - VirtualFramebuffer *GetDisplayFBO(); + VirtualFramebufferDX9 *GetDisplayFBO(); void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format); size_t NumVFBs() const { return vfbs_.size(); } @@ -128,7 +132,7 @@ public: return displayFramebuf_ ? (0x04000000 | displayFramebuf_->fb_address) : 0; } - void DestroyFramebuf(VirtualFramebuffer *vfb); + void DestroyFramebuf(VirtualFramebufferDX9 *vfb); private: u32 ramDisplayFramebufPtr_; // workaround for MotoGP insanity @@ -136,20 +140,20 @@ private: u32 displayStride_; GEBufferFormat displayFormat_; - VirtualFramebuffer *displayFramebuf_; - VirtualFramebuffer *prevDisplayFramebuf_; - VirtualFramebuffer *prevPrevDisplayFramebuf_; + VirtualFramebufferDX9 *displayFramebuf_; + VirtualFramebufferDX9 *prevDisplayFramebuf_; + VirtualFramebufferDX9 *prevPrevDisplayFramebuf_; int frameLastFramebufUsed; - std::vector vfbs_; + std::vector vfbs_; - VirtualFramebuffer *currentRenderVfb_; + VirtualFramebufferDX9 *currentRenderVfb_; // Used by ReadFramebufferToMemory - void BlitFramebuffer_(VirtualFramebuffer *src, VirtualFramebuffer *dst, bool flip = false, float upscale = 1.0f, float vscale = 1.0f); - void PackFramebufferDirectx9_(VirtualFramebuffer *vfb); + void BlitFramebuffer_(VirtualFramebufferDX9 *src, VirtualFramebufferDX9 *dst, bool flip = false, float upscale = 1.0f, float vscale = 1.0f); + void PackFramebufferDirectx9_(VirtualFramebufferDX9 *vfb); int gpuVendor; - std::vector bvfbs_; // blitting FBOs + std::vector bvfbs_; // blitting FBOs // Used by DrawPixels LPDIRECT3DTEXTURE9 drawPixelsTex_; @@ -164,4 +168,6 @@ private: bool resized_; bool useBufferedRendering_; -}; \ No newline at end of file +}; + +}; diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index fa7729c5fa..07d99a30e4 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -37,6 +37,8 @@ #include "Core/HLE/sceKernelInterrupt.h" #include "Core/HLE/sceGe.h" +namespace DX9 { + enum { FLAG_FLUSHBEFORE = 1, FLAG_FLUSHBEFOREONCHANGE = 2, @@ -478,7 +480,7 @@ bool DIRECTX9_GPU::FramebufferDirty() { // Allow it to process fully before deciding if it's dirty. SyncThread(); } - VirtualFramebuffer *vfb = framebufferManager_.GetDisplayFBO(); + VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayFBO(); if (vfb) { bool dirty = vfb->dirtyAfterDisplay; vfb->dirtyAfterDisplay = false; @@ -495,7 +497,7 @@ bool DIRECTX9_GPU::FramebufferReallyDirty() { SyncThread(); } - VirtualFramebuffer *vfb = framebufferManager_.GetDisplayFBO(); + VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayFBO(); if (vfb) { bool dirty = vfb->reallyDirtyAfterDisplay; vfb->reallyDirtyAfterDisplay = false; @@ -1379,3 +1381,5 @@ void DIRECTX9_GPU::DoState(PointerWrap &p) { framebufferManager_.DestroyAllFBOs(); shaderManager_->ClearCache(true); } + +}; diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 9ea772b177..e0de3b4318 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -27,6 +27,8 @@ #include "GPU/Directx9/TextureCacheDX9.h" #include "GPU/Directx9/helper/fbo.h" +namespace DX9 { + class ShaderManagerDX9; class LinkedShaderDX9; @@ -95,3 +97,7 @@ private: std::string reportingPrimaryInfo_; std::string reportingFullInfo_; }; + +}; + +typedef DX9::DIRECTX9_GPU DIRECTX9_GPU; diff --git a/GPU/Directx9/PixelShaderGeneratorDX9.cpp b/GPU/Directx9/PixelShaderGeneratorDX9.cpp index 9dc1df86f7..0ad6528ca6 100644 --- a/GPU/Directx9/PixelShaderGeneratorDX9.cpp +++ b/GPU/Directx9/PixelShaderGeneratorDX9.cpp @@ -27,6 +27,8 @@ // GL_NV_shader_framebuffer_fetch looks interesting.... +namespace DX9 { + static bool IsAlphaTestTriviallyTrue() { GEComparison alphaTestFunc = gstate.getAlphaTestFunction(); int alphaTestRef = gstate.getAlphaTestRef(); @@ -300,3 +302,5 @@ void GenerateFragmentShaderDX9(char *buffer) { } WRITE(p, "}\n"); } + +}; diff --git a/GPU/Directx9/PixelShaderGeneratorDX9.h b/GPU/Directx9/PixelShaderGeneratorDX9.h index 7a5e0a510a..83bd15f6dd 100644 --- a/GPU/Directx9/PixelShaderGeneratorDX9.h +++ b/GPU/Directx9/PixelShaderGeneratorDX9.h @@ -19,6 +19,8 @@ #include "Globals.h" +namespace DX9 { + struct FragmentShaderIDDX9 { FragmentShaderIDDX9() {d[0] = 0xFFFFFFFF;} @@ -50,3 +52,5 @@ struct FragmentShaderIDDX9 void ComputeFragmentShaderIDDX9(FragmentShaderIDDX9 *id); void GenerateFragmentShaderDX9(char *buffer); + +}; diff --git a/GPU/Directx9/ShaderManagerDX9.cpp b/GPU/Directx9/ShaderManagerDX9.cpp index 253e6ac2f4..500ddbb862 100644 --- a/GPU/Directx9/ShaderManagerDX9.cpp +++ b/GPU/Directx9/ShaderManagerDX9.cpp @@ -36,6 +36,8 @@ // For matrices convertions #include +namespace DX9 { + PSShader::PSShader(const char *code, bool useHWTransform) : failed_(false), useHWTransform_(useHWTransform) { source_ = code; #ifdef SHADERLOG @@ -653,3 +655,5 @@ LinkedShaderDX9 *ShaderManagerDX9::ApplyShader(int prim) { lastShader_ = ls; return ls; } + +}; diff --git a/GPU/Directx9/ShaderManagerDX9.h b/GPU/Directx9/ShaderManagerDX9.h index 200bbf5808..78510a758e 100644 --- a/GPU/Directx9/ShaderManagerDX9.h +++ b/GPU/Directx9/ShaderManagerDX9.h @@ -23,6 +23,8 @@ #include "GPU/Directx9/VertexShaderGeneratorDX9.h" #include "GPU/Directx9/PixelShaderGeneratorDX9.h" +namespace DX9 { + class PSShader; class VSShader; @@ -228,3 +230,5 @@ private: VSCache vsCache_; }; + +}; diff --git a/GPU/Directx9/SplineDX9.cpp b/GPU/Directx9/SplineDX9.cpp index a19fa28fdc..0bc4315df4 100644 --- a/GPU/Directx9/SplineDX9.cpp +++ b/GPU/Directx9/SplineDX9.cpp @@ -17,6 +17,9 @@ #include "Core/MemMap.h" #include "GPU/Directx9/TransformPipelineDX9.h" +#include "Gpu/Common/VertexDecoderCommon.h" + +namespace DX9 { // Just to get something on the screen, we'll just not subdivide correctly. void TransformDrawEngineDX9::DrawBezier(int ucount, int vcount) { @@ -191,4 +194,6 @@ void TransformDrawEngineDX9::SubmitBezier(void* control_points, void* indices, i vdecoder.SetVertexType(vertex_type); Flush(); -} \ No newline at end of file +} + +}; diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index c2661cfa6c..20d5463b34 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -28,6 +28,8 @@ #include "GPU/Directx9/TextureCacheDX9.h" #include "GPU/Directx9/FramebufferDX9.h" +namespace DX9 { + static const D3DBLEND aLookup[11] = { D3DBLEND_DESTCOLOR, D3DBLEND_INVDESTCOLOR, @@ -367,3 +369,5 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) { dxstate.viewport.set(vpX0 + renderX, vpY0 + renderY, vpWidth, vpHeight, depthRangeMin, depthRangeMax); } } + +}; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 49ea9e72bc..f2c0a31fcc 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -30,6 +30,8 @@ #include "math/math_util.h" #include "native/ext/cityhash/city.h" +namespace DX9 { + #define INVALID_TEX (LPDIRECT3DTEXTURE9)(-1) // If a texture hasn't been seen for this many frames, get rid of it. @@ -164,7 +166,7 @@ void TextureCacheDX9::ClearNextFrame() { template -inline void AttachFramebufferValid(T &entry, VirtualFramebuffer *framebuffer) { +inline void AttachFramebufferValid(T &entry, VirtualFramebufferDX9 *framebuffer) { const bool hasInvalidFramebuffer = entry->framebuffer == 0 || entry->invalidHint == -1; const bool hasOlderFramebuffer = entry->framebuffer != 0 && entry->framebuffer->last_frame_render < framebuffer->last_frame_render; if (hasInvalidFramebuffer || hasOlderFramebuffer) { @@ -174,14 +176,14 @@ inline void AttachFramebufferValid(T &entry, VirtualFramebuffer *framebuffer) { } template -inline void AttachFramebufferInvalid(T &entry, VirtualFramebuffer *framebuffer) { +inline void AttachFramebufferInvalid(T &entry, VirtualFramebufferDX9 *framebuffer) { if (entry->framebuffer == 0 || entry->framebuffer == framebuffer) { entry->framebuffer = framebuffer; entry->invalidHint = -1; } } -inline void TextureCacheDX9::AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, bool exactMatch) { +inline void TextureCacheDX9::AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebufferDX9 *framebuffer, bool exactMatch) { // If they match exactly, it's non-CLUT and from the top left. if (exactMatch) { DEBUG_LOG(G3D, "Render to texture detected at %08x!", address); @@ -220,13 +222,13 @@ inline void TextureCacheDX9::AttachFramebuffer(TexCacheEntry *entry, u32 address } } -inline void TextureCacheDX9::DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer) { +inline void TextureCacheDX9::DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebufferDX9 *framebuffer) { if (entry->framebuffer == framebuffer) { entry->framebuffer = 0; } } -void TextureCacheDX9::NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg) { +void TextureCacheDX9::NotifyFramebuffer(u32 address, VirtualFramebufferDX9 *framebuffer, FramebufferNotification msg) { // This is a rough heuristic, because sometimes our framebuffers are too tall. static const u32 MAX_SUBAREA_Y_OFFSET = 32; @@ -1759,3 +1761,5 @@ bool TextureCacheDX9::DecodeTexture(u8* output, GPUgstate state) OutputDebugStringA("TextureCache::DecodeTexture : FixMe\r\n"); return true; } + +}; diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index cf9f609882..1accc7cbba 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -24,7 +24,9 @@ #include "GPU/GPUState.h" #include "GPU/Directx9/TextureScalerDX9.h" -struct VirtualFramebuffer; +namespace DX9 { + +struct VirtualFramebufferDX9; enum TextureFiltering { AUTO = 1, @@ -56,7 +58,7 @@ public: // FramebufferManager keeps TextureCache updated about what regions of memory // are being rendered to. This is barebones so far. - void NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg); + void NotifyFramebuffer(u32 address, VirtualFramebufferDX9 *framebuffer, FramebufferNotification msg); size_t NumLoadedTextures() const { return cache.size(); @@ -88,7 +90,7 @@ private: int status; u32 addr; u32 hash; - VirtualFramebuffer *framebuffer; // if null, not sourced from an FBO. + VirtualFramebufferDX9 *framebuffer; // if null, not sourced from an FBO. u32 sizeInRAM; int lastFrame; int numFrames; @@ -125,8 +127,8 @@ private: const T *GetCurrentClut(); u32 GetCurrentClutHash(); void UpdateCurrentClut(); - void AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, bool exactMatch); - void DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer); + void AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebufferDX9 *framebuffer, bool exactMatch); + void DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebufferDX9 *framebuffer); void SetTextureFramebuffer(TexCacheEntry *entry); TexCacheEntry *GetEntryAt(u32 texaddr); @@ -134,7 +136,7 @@ private: typedef std::map TexCache; TexCache cache; TexCache secondCache; - std::vector fbCache_; + std::vector fbCache_; bool clearCacheNextFrame_; bool lowMemoryMode_; @@ -161,3 +163,4 @@ private: int decimationCounter_; }; +}; diff --git a/GPU/Directx9/TextureScalerDX9.cpp b/GPU/Directx9/TextureScalerDX9.cpp index 3779d2c06f..f06fee7416 100644 --- a/GPU/Directx9/TextureScalerDX9.cpp +++ b/GPU/Directx9/TextureScalerDX9.cpp @@ -28,6 +28,10 @@ #include #include +#ifndef _XBOX +#include +#endif + #undef min #undef max @@ -523,6 +527,8 @@ namespace { /////////////////////////////////////// Texture Scaler +namespace DX9 { + TextureScalerDX9::TextureScalerDX9() { initBicubicWeights(); } @@ -677,3 +683,5 @@ void TextureScalerDX9::ConvertTo8888(u32 format, u32* source, u32* &dest, int wi ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format"); } } + +}; diff --git a/GPU/Directx9/TextureScalerDX9.h b/GPU/Directx9/TextureScalerDX9.h index dc87b1ce19..2da5484645 100644 --- a/GPU/Directx9/TextureScalerDX9.h +++ b/GPU/Directx9/TextureScalerDX9.h @@ -24,6 +24,8 @@ #include +namespace DX9 { + class TextureScalerDX9 { public: @@ -50,3 +52,5 @@ private: // of course, scaling factor 5 is totally silly anyway SimpleBuf bufInput, bufDeposter, bufOutput, bufTmp1, bufTmp2, bufTmp3; }; + +}; diff --git a/GPU/Directx9/TransformPipelineDX9.cpp b/GPU/Directx9/TransformPipelineDX9.cpp index e14761bcd5..37f232ef96 100644 --- a/GPU/Directx9/TransformPipelineDX9.cpp +++ b/GPU/Directx9/TransformPipelineDX9.cpp @@ -40,6 +40,8 @@ #include "GPU/Directx9/ShaderManagerDX9.h" #include "GPU/Directx9/GPU_DX9.h" +namespace DX9 { + const D3DPRIMITIVETYPE glprim[8] = { D3DPT_POINTLIST, D3DPT_LINELIST, @@ -128,6 +130,7 @@ void TransformDrawEngineDX9::DestroyDeviceObjects() { } namespace { +using namespace DX9; // Convenient way to do precomputation to save the parts of the lighting calculation // that's common between the many vertices of a draw call. @@ -1330,3 +1333,5 @@ rotateVBO: numDrawCalls = 0; prevPrim_ = GE_PRIM_INVALID; } + +}; diff --git a/GPU/Directx9/TransformPipelineDX9.h b/GPU/Directx9/TransformPipelineDX9.h index a15915fc7a..352cb237d1 100644 --- a/GPU/Directx9/TransformPipelineDX9.h +++ b/GPU/Directx9/TransformPipelineDX9.h @@ -23,13 +23,15 @@ #include "GPU/Common/IndexGenerator.h" #include "GPU/Directx9/VertexDecoderDX9.h" +struct DecVtxFormat; + +namespace DX9 { + class LinkedShaderDX9; class ShaderManagerDX9; class TextureCacheDX9; class FramebufferManagerDX9; -struct DecVtxFormat; - // States transitions: // On creation: DRAWN_NEW // DRAWN_NEW -> DRAWN_HASHING @@ -227,3 +229,5 @@ struct Color4 { a = (col&0xff)/255.0f; } }; + +}; diff --git a/GPU/Directx9/VertexDecoderDX9.cpp b/GPU/Directx9/VertexDecoderDX9.cpp index b0e769e20f..929ada40de 100644 --- a/GPU/Directx9/VertexDecoderDX9.cpp +++ b/GPU/Directx9/VertexDecoderDX9.cpp @@ -24,6 +24,8 @@ #include "GPU/Directx9/VertexDecoderDX9.h" #include "GPU/Directx9/VertexShaderGeneratorDX9.h" +namespace DX9 { + // Always use float for decoding data #define USE_WEIGHT_HACK @@ -1001,4 +1003,6 @@ int VertexDecoderDX9::ToString(char *output) const { output += sprintf(output, " (size: %i)", VertexSize()); return output - start; -} \ No newline at end of file +} + +}; diff --git a/GPU/Directx9/VertexDecoderDX9.h b/GPU/Directx9/VertexDecoderDX9.h index a9b4682eac..38f0cd56d4 100644 --- a/GPU/Directx9/VertexDecoderDX9.h +++ b/GPU/Directx9/VertexDecoderDX9.h @@ -24,6 +24,8 @@ #include "GPU/Common/VertexDecoderCommon.h" +namespace DX9 { + class VertexDecoderDX9; typedef void (VertexDecoderDX9::*StepFunction)() const; @@ -150,3 +152,4 @@ public: int stats_[NUM_VERTEX_DECODER_STATS]; }; +}; diff --git a/GPU/Directx9/VertexShaderGeneratorDX9.cpp b/GPU/Directx9/VertexShaderGeneratorDX9.cpp index 5eede67bf4..c4e44c63e1 100644 --- a/GPU/Directx9/VertexShaderGeneratorDX9.cpp +++ b/GPU/Directx9/VertexShaderGeneratorDX9.cpp @@ -33,6 +33,8 @@ #define WRITE p+=sprintf +namespace DX9 { + bool CanUseHardwareTransformDX9(int prim) { if (!g_Config.bHardwareTransform) return false; @@ -575,3 +577,5 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) { } WRITE(p, "}\n"); } + +}; diff --git a/GPU/Directx9/VertexShaderGeneratorDX9.h b/GPU/Directx9/VertexShaderGeneratorDX9.h index e6645e43de..5c324d86a0 100644 --- a/GPU/Directx9/VertexShaderGeneratorDX9.h +++ b/GPU/Directx9/VertexShaderGeneratorDX9.h @@ -19,6 +19,8 @@ #include "Globals.h" +namespace DX9 { + // #define USE_BONE_ARRAY struct VertexShaderIDDX9 @@ -55,3 +57,5 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform); // Collapse to less skinning shaders to reduce shader switching, which is expensive. int TranslateNumBonesDX9(int bones); + +}; diff --git a/GPU/Directx9/helper/dx_state.cpp b/GPU/Directx9/helper/dx_state.cpp index 99630f480a..115eaa27fa 100644 --- a/GPU/Directx9/helper/dx_state.cpp +++ b/GPU/Directx9/helper/dx_state.cpp @@ -1,6 +1,8 @@ #include "dx_state.h" #include +namespace DX9 { + DirectxState dxstate; GLExtensions gl_extensions; @@ -76,4 +78,6 @@ void DirectxState::SetVSyncInterval(int interval) { wglSwapIntervalEXT(interval); #endif */ -} \ No newline at end of file +} + +}; \ No newline at end of file diff --git a/GPU/Directx9/helper/dx_state.h b/GPU/Directx9/helper/dx_state.h index b97022aeb0..89d3244921 100644 --- a/GPU/Directx9/helper/dx_state.h +++ b/GPU/Directx9/helper/dx_state.h @@ -4,6 +4,8 @@ #include #include "global.h" +namespace DX9 { + // OpenGL state cache. Should convert all code to use this instead of directly calling glEnable etc, // as GL state changes can be expensive on some hardware. class DirectxState @@ -297,3 +299,5 @@ struct GLExtensions { extern GLExtensions gl_extensions; void CheckGLExtensions(); + +}; diff --git a/GPU/Directx9/helper/fbo.cpp b/GPU/Directx9/helper/fbo.cpp index 33d8e5c099..192a608bf8 100644 --- a/GPU/Directx9/helper/fbo.cpp +++ b/GPU/Directx9/helper/fbo.cpp @@ -4,6 +4,8 @@ #include #include "fbo.h" +namespace DX9 { + static LPDIRECT3DSURFACE9 currentRtt; static LPDIRECT3DSURFACE9 workingRtt; static LPDIRECT3DSURFACE9 deviceRTsurf; @@ -157,4 +159,6 @@ void SwapBuffer() { // :s //pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0 ,0), 0, 0); -} \ No newline at end of file +} + +}; \ No newline at end of file diff --git a/GPU/Directx9/helper/fbo.h b/GPU/Directx9/helper/fbo.h index 77b65361fe..a7fa4ff1a7 100644 --- a/GPU/Directx9/helper/fbo.h +++ b/GPU/Directx9/helper/fbo.h @@ -4,6 +4,8 @@ // Very C-ish API because that's what I felt like, and it's cool to completely // hide the data from callers... +namespace DX9 { + struct FBO; enum FBOColorDepth { @@ -36,4 +38,6 @@ void fbo_resolve(FBO *fbo); void * fbo_get_rtt(FBO *fbo); // To get default depth and rt surface -void fbo_init(); \ No newline at end of file +void fbo_init(); + +}; \ No newline at end of file diff --git a/GPU/Directx9/helper/global.cpp b/GPU/Directx9/helper/global.cpp index 946a61a0fa..6999a0cce5 100644 --- a/GPU/Directx9/helper/global.cpp +++ b/GPU/Directx9/helper/global.cpp @@ -1,6 +1,8 @@ #include "global.h" #include "fbo.h" +namespace DX9 { + LPDIRECT3DDEVICE9 pD3Ddevice = NULL; LPDIRECT3D9 pD3D = NULL; @@ -246,4 +248,6 @@ void DirectxInit() { CompileShaders(); fbo_init(); -} \ No newline at end of file +} + +}; \ No newline at end of file diff --git a/GPU/Directx9/helper/global.h b/GPU/Directx9/helper/global.h index f565abc51f..ee94752e56 100644 --- a/GPU/Directx9/helper/global.h +++ b/GPU/Directx9/helper/global.h @@ -1,7 +1,7 @@ #pragma once +#include "Common/CommonWindows.h" #ifdef _XBOX -#include // Used on XBox to create a linear format // TODO: Might actually want to use nonlinear on xbox? #define D3DFMT(x) (D3DFORMAT)MAKELINFMT(x) @@ -9,6 +9,8 @@ #define D3DFMT(x) x #endif +namespace DX9 { + #include #include @@ -23,4 +25,6 @@ extern IDirect3DVertexDeclaration9* pSoftVertexDecl; bool CompilePixelShader(const char * code, LPDIRECT3DPIXELSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable); bool CompileVertexShader(const char * code, LPDIRECT3DVERTEXSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable); -#define D3DBLEND_UNK D3DSTENCILOP_FORCE_DWORD \ No newline at end of file +#define D3DBLEND_UNK D3DSTENCILOP_FORCE_DWORD + +}; diff --git a/GPU/GPU.vcxproj b/GPU/GPU.vcxproj index 9fba10d7c5..5b0cdeffdb 100644 --- a/GPU/GPU.vcxproj +++ b/GPU/GPU.vcxproj @@ -158,6 +158,9 @@ + + + @@ -196,6 +199,19 @@ + + + true + true + true + true + + + true + true + true + true + @@ -239,4 +255,4 @@ - + \ No newline at end of file diff --git a/GPU/GPU.vcxproj.filters b/GPU/GPU.vcxproj.filters index a2b2441f3d..fca0d1d5fe 100644 --- a/GPU/GPU.vcxproj.filters +++ b/GPU/GPU.vcxproj.filters @@ -16,6 +16,9 @@ {88629970-4774-4122-b031-2128244b795c} + + {ba434472-5d5e-4b08-ab16-bfb7ec8e7068} + @@ -126,6 +129,15 @@ Common + + DirectX9\helper + + + DirectX9\helper + + + DirectX9\helper + @@ -233,6 +245,15 @@ Common + + DirectX9\helper + + + DirectX9\helper + + + DirectX9\helper + diff --git a/GPU/GPUState.cpp b/GPU/GPUState.cpp index 2c2f3db210..186c1a0d5f 100644 --- a/GPU/GPUState.cpp +++ b/GPU/GPUState.cpp @@ -23,8 +23,8 @@ #endif #include "GPU/Null/NullGpu.h" #include "GPU/Software/SoftGpu.h" -#ifdef USE_DIRECTX -#include "Directx9/DisplayListInterpreter.h" +#if defined(_XBOX) +#include "GPU/Directx9/GPU_DX9.h" #endif #include "Core/CoreParameter.h" #include "Core/System.h" @@ -39,22 +39,21 @@ bool GPU_Init() { case GPU_NULL: gpu = new NullGPU(); break; -#ifndef _XBOX case GPU_GLES: +#ifndef _XBOX gpu = new GLES_GPU(); +#endif break; -#endif case GPU_SOFTWARE: #if !(defined(__SYMBIAN32__) || defined(_XBOX)) gpu = new SoftGPU(); #endif break; - -#ifdef USE_DIRECTX case GPU_DIRECTX9: +#if defined(_XBOX) gpu = new DIRECTX9_GPU(); - break; #endif + break; } return gpu != NULL;