From 24f03fe81bc8c6567ddd5974a7b7b71a05528c2e Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 17 Mar 2004 06:14:54 +0000 Subject: [PATCH] my mom always told me i was kool --- Cxbx.opt | Bin 67072 -> 62976 bytes CxbxKrnl.dsp | 14 +- Include/Cxbx.h | 9 +- Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h | 37 ---- Include/Win32/CxbxKrnl/EmuD3D8Types.h | 1 + Include/Win32/CxbxKrnl/ResourceTracker.h | 75 ++++++++ Include/Win32/Mutex.h | 17 +- Source/Win32/CxbxKrnl/DbgConsole.cpp | 181 ++++++++++++++---- Source/Win32/CxbxKrnl/EmuD3D8.cpp | 47 +++-- Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp | 14 ++ .../Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp | 99 ---------- .../Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp | 4 +- Source/Win32/CxbxKrnl/EmuKrnl.cpp | 6 + Source/Win32/CxbxKrnl/ResourceTracker.cpp | 153 +++++++++++++++ 14 files changed, 443 insertions(+), 214 deletions(-) create mode 100644 Include/Win32/CxbxKrnl/ResourceTracker.h create mode 100644 Source/Win32/CxbxKrnl/ResourceTracker.cpp diff --git a/Cxbx.opt b/Cxbx.opt index 4f7bdd37e8debce37e15dae205a96183bed56763..5d3b2ce41036e4a3197f24d3b13bcb9049ea5c65 100644 GIT binary patch literal 62976 zcmeHQS#TRidIm&MrbgCbTRzsC^>(P(7Gnv#taG)Dh(j_g;#filW5eMNW}3j5gBk41 zKm?u2M$enW-W>a$WK&5VQ`x+$l58q@NW~8+zql&9esgV7dETnj#`*pkG%)~y!O*6x zMCxY!=_1}Mg_^(g>^iTf!#ZM9gZYeR5_@B=XCk}Dx&c}N6+lH$2~-AAIid=}H$k^Rw?TJ6YoK2Ty#;z3M11eS{|(SO=-VI_R0C-s z9mGMzSBKvK8K8GTn;;X^1X&;(M10?Y?|@v82Wo@vg0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UU zs-o)G@Jo1{ny%}Lg}2#hy3s&Ig{CkRt?lwFxSa4@YBy?CAy>BK*My<_b^N;Hkkf>% zsFsX3x3%i+-n|cp({2qp?FKqubz=mZ`WyI6xIP6W>s_nsZ~FEB7N(=F2`P%zO*y?G z)J@;|J6Mmn)+G&Dbc1J}hV4LJm*+)8H@5sUooB?%%*PEg7)9Tek!L~VqF+=CX|;yz-7{R>Fv}9bpC>Y6LIx0J2vF%eGZoix5vF_ zKcB!Yk(ry5^SUKZ)1~!0mxAR%vg9PxUhkH)$BZr_n}vLnu}3@G`#o zklHdvR}@R#cm|U*or7ongG>IwbCPrx9lb)Gl^pGB=d{+m{y$Z`XVX3N{6C)mN56I6 zm;q*h8DIvO0cL<1xYG=<{>SwkM!|I0|aq$2-l1KCG4$wD5~-EAjsA^)gNA-w#f zyNed?z1#e&;kDd)>Af8PJ#_nvUO=G{}0{|od5UM|G~&-G6T#2Gr$Zm1Iz$3a2FY1{h#%J*8lge{{Mehw8pLg diff --git a/CxbxKrnl.dsp b/CxbxKrnl.dsp index c21c7fef0..3f3094d04 100644 --- a/CxbxKrnl.dsp +++ b/CxbxKrnl.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbx" /I "Include/Win32/CxbxKrnl" /I "Include/Win32/CxbxKrnl/HLEDataBase" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbx" /I "Include/Win32/CxbxKrnl" /I "Include/Win32/CxbxKrnl/HLEDataBase" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" @@ -53,8 +53,8 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 ws2_32.lib dsound.lib winmm.lib ddraw.lib d3dx8.lib d3d8.lib dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /map /machine:I386 /out:"Bin/Cxbx.dll" /libpath:"Lib" -# SUBTRACT LINK32 /profile /pdb:none /debug +# ADD LINK32 ws2_32.lib dsound.lib winmm.lib ddraw.lib d3dx8.lib d3d8.lib dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /pdb:none /machine:I386 /out:"Bin/Cxbx.dll" /libpath:"Lib" +# SUBTRACT LINK32 /profile /map /debug !ELSEIF "$(CFG)" == "CxbxKrnl - Win32 Debug" @@ -326,6 +326,10 @@ SOURCE=.\Include\Win32\CxbxKrnl\OOVPA.h # End Source File # Begin Source File +SOURCE=.\Include\Win32\CxbxKrnl\ResourceTracker.h +# End Source File +# Begin Source File + SOURCE=.\Include\Win32\XBController.h # End Source File # Begin Source File @@ -571,6 +575,10 @@ SOURCE=.\Source\Win32\Mutex.cpp # End Source File # Begin Source File +SOURCE=.\Source\Win32\CxbxKrnl\ResourceTracker.cpp +# End Source File +# Begin Source File + SOURCE=.\Source\Win32\XBController.cpp # End Source File # Begin Source File diff --git a/Include/Cxbx.h b/Include/Cxbx.h index 76640a74c..d977fe969 100644 --- a/Include/Cxbx.h +++ b/Include/Cxbx.h @@ -54,14 +54,15 @@ typedef signed char sint08; typedef signed short sint16; typedef signed long sint32; -// define this to track vertex buffers for debugging purposes -#define _DEBUG_TRACK_VB +// define this to track resources for debugging purposes +//#define _DEBUG_TRACK_VB // Vertex Buffers +//#define _DEBUG_TRACK_PB // Push Buffers // define this to trace intercepted function calls -#define _DEBUG_TRACE +//#define _DEBUG_TRACE // define this to trace warnings -#define _DEBUG_WARNINGS +//#define _DEBUG_WARNINGS // version information #ifndef _DEBUG_TRACE diff --git a/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h b/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h index d4b719f59..431baf892 100644 --- a/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h +++ b/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h @@ -36,43 +36,6 @@ #include "Cxbx.h" -#ifdef _DEBUG_TRACK_VB - -struct VBNode -{ - XTL::IDirect3DVertexBuffer8 *vb; - VBNode *next; -}; - -extern bool g_bVBSkipStream; - -extern class VBTracker -{ - public: - VBTracker() : m_head(0), m_tail(0) {} - ~VBTracker(); - - // insert a ptr - void insert(XTL::IDirect3DVertexBuffer8 *pVB); - - // remove a ptr - void remove(XTL::IDirect3DVertexBuffer8 *pVB); - - // check for existance of ptr - bool exists(XTL::IDirect3DVertexBuffer8 *pVB); - - // for traversal - VBNode *getHead() { return m_head; } - - private: - // list of "live" vertex buffers for debugging purposes - VBNode *m_head; - VBNode *m_tail; -} -g_VBTrackTotal, g_VBTrackDisable; - -#endif - // fixup xbox extensions to be compatible with PC direct3d extern UINT EmuFixupVerticesA ( diff --git a/Include/Win32/CxbxKrnl/EmuD3D8Types.h b/Include/Win32/CxbxKrnl/EmuD3D8Types.h index 0949f9e6b..d5e014734 100644 --- a/Include/Win32/CxbxKrnl/EmuD3D8Types.h +++ b/Include/Win32/CxbxKrnl/EmuD3D8Types.h @@ -186,6 +186,7 @@ struct X_D3DResource #define X_D3DRESOURCE_DATA_FLAG_SURFACE 0xEFFFFFFF #define X_D3DRESOURCE_DATA_FLAG_YUVSURF 0xDFFFFFFF #define X_D3DRESOURCE_DATA_FLAG_D3DREND 0xCFFFFFFF // D3D Render Target +#define X_D3DRESOURCE_DATA_FLAG_D3DSTEN 0xBFFFFFFF // D3D Stencil Surface // special resource lock flags #define X_D3DRESOURCE_LOCK_FLAG_NOSIZE 0xEFFFFFFF diff --git a/Include/Win32/CxbxKrnl/ResourceTracker.h b/Include/Win32/CxbxKrnl/ResourceTracker.h new file mode 100644 index 000000000..682c64f64 --- /dev/null +++ b/Include/Win32/CxbxKrnl/ResourceTracker.h @@ -0,0 +1,75 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Win32->CxbxKrnl->ResourceTracker.h +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * +// * All rights reserved +// * +// ****************************************************************** +#ifndef RESOURCETRACKER_H +#define RESOURCETRACKER_H + +#include "Cxbx.h" +#include "Mutex.h" + +extern bool g_bVBSkipStream; +extern bool g_bPBSkipPusher; + +extern class ResourceTracker : public Mutex +{ + public: + ResourceTracker() : m_head(0), m_tail(0) {}; + ~ResourceTracker(); + + // insert a ptr + void insert(void *pResource); + + // remove a ptr + void remove(void *pResource); + + // check for existance of ptr + bool exists(void *pResource); + + // for traversal + struct RTNode *getHead() { return m_head; } + + private: + // list of "live" vertex buffers for debugging purposes + struct RTNode *m_head; + struct RTNode *m_tail; +} +g_VBTrackTotal, g_VBTrackDisable, +g_PBTrackTotal, g_PBTrackDisable; + +struct RTNode +{ + void *pResource; + RTNode *pNext; +}; + +#endif diff --git a/Include/Win32/Mutex.h b/Include/Win32/Mutex.h index 819dccd45..dbd331641 100644 --- a/Include/Win32/Mutex.h +++ b/Include/Win32/Mutex.h @@ -36,31 +36,16 @@ #include -// ****************************************************************** -// * Mutex object (intended to be inherited from) -// ****************************************************************** +// mutex object (intended to be inherited from) class Mutex { public: - // ****************************************************************** - // * Constructor - // ****************************************************************** Mutex(); - // ****************************************************************** - // * Lock critical section - // ****************************************************************** void Lock(); - - // ****************************************************************** - // * Unlock critical section - // ****************************************************************** void Unlock(); private: - // ****************************************************************** - // * Critical section - // ****************************************************************** LONG m_MutexLock; // Mutex lock LONG m_OwnerProcess; // Current owner process (or zero) LONG m_OwnerThread; // Current owner thread diff --git a/Source/Win32/CxbxKrnl/DbgConsole.cpp b/Source/Win32/CxbxKrnl/DbgConsole.cpp index f89a46f4c..c44764052 100644 --- a/Source/Win32/CxbxKrnl/DbgConsole.cpp +++ b/Source/Win32/CxbxKrnl/DbgConsole.cpp @@ -37,6 +37,7 @@ #include "Emu.h" #include "DbgConsole.h" +#include "ResourceTracker.h" #include @@ -115,40 +116,50 @@ void DbgConsole::Reset() } #ifdef _DEBUG_TRACK_VB -static void EnableVB(int n, bool enable) +static void EnableTracker(ResourceTracker &trackTotal, ResourceTracker &trackDisable, int a, int b, bool enable) { - using namespace XTL; - int v=0; - VBNode *cur = g_VBTrackTotal.getHead(); + trackTotal.Lock(); - for(v=0;vnext == NULL)) + if(cur == NULL || (cur->pNext == NULL)) break; - cur = cur->next; + cur = cur->pNext; } - if(n == v && (cur != NULL) && (cur->next != NULL)) + if((a == v) && (cur != NULL) && (cur->pNext != NULL)) { - if(enable) + for(;a<=b;a++) { - g_VBTrackDisable.remove(cur->vb); - } - else - { - g_VBTrackDisable.insert(cur->vb); - } + if((cur == NULL) || (cur->pNext == NULL)) + break; - printf("CxbxDbg: %.02d (0x%.08X) %s\n", n, cur->vb, enable ? "enabled" : "disabled"); + if(enable) + { + trackDisable.remove(cur->pResource); + } + else + { + trackDisable.insert(cur->pResource); + } + + printf("CxbxDbg: %.02d (0x%.08X) %s\n", a, cur->pResource, enable ? "enabled" : "disabled"); + + cur = cur->pNext; + } } else { printf("CxbxDbg: # out of range\n"); } + trackTotal.Unlock(); + return; } #endif @@ -159,6 +170,8 @@ void DbgConsole::ParseCommand() char szCmd[32]; + szCmd[0] = '\0'; + sscanf(m_szInput, "%s", szCmd); // TODO: as command list grows, turn into static string/ptr lookup @@ -168,14 +181,19 @@ void DbgConsole::ParseCommand() printf("CxbxDbg: \n"); printf("CxbxDbg: Cxbx Debug Command List:\n"); printf("CxbxDbg: \n"); - printf("CxbxDbg: HELP (H)\n"); - printf("CxbxDbg: QUIT (Q or EXIT)\n"); - printf("CxbxDbg: TRACE (T)\n"); - printf("CxbxDbg: ListVB (LVB)\n"); - printf("CxbxDbg: DisableVB # (DVB #)\n"); - printf("CxbxDbg: EnableVB # (EVB #)\n"); + printf("CxbxDbg: Help [H] : Show Command List\n"); + printf("CxbxDbg: Quit/Exit [Q] : Stop Emulation\n"); + printf("CxbxDbg: Trace [T] : Toggle Debug Trace\n"); + printf("CxbxDbg: ListVB [LVB] : List Active Vertex Buffers\n"); + printf("CxbxDbg: DisableVB [DVB #] : Disable Active Vertex Buffer(s)\n"); + printf("CxbxDbg: EnableVB [EVB #] : Enable Active Vertex Buffer(s)\n"); + printf("CxbxDbg: ListPB [LPB] : List Active Push Buffers\n"); + printf("CxbxDbg: DisablePB [DPB #] : Disable Active Push Buffer(s)\n"); + printf("CxbxDbg: EnablePB [EPB #] : Enable Active Push Buffer(s)\n"); printf("CxbxDbg: CLS\n"); printf("CxbxDbg: \n"); + printf("CxbxDbg: # denotes parameter of form [#] or [#-#]\n"); + printf("CxbxDbg: \n"); } else if(stricmp(szCmd, "q") == 0 || stricmp(szCmd, "quit") == 0 || stricmp(szCmd, "exit") == 0) { @@ -191,20 +209,22 @@ void DbgConsole::ParseCommand() { #ifdef _DEBUG_TRACK_VB { - using namespace XTL; - int v=0; - VBNode *cur = g_VBTrackTotal.getHead(); + g_VBTrackTotal.Lock(); - while(cur != NULL && cur->next != NULL) + RTNode *cur = g_VBTrackTotal.getHead(); + + while(cur != NULL && cur->pNext != NULL) { - bool enabled = !g_VBTrackDisable.exists(cur->vb); + bool enabled = !g_VBTrackDisable.exists(cur->pResource); - printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->vb, enabled ? "enabled" : "disabled"); + printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); - cur = cur->next; + cur = cur->pNext; } + + g_VBTrackTotal.Unlock(); } #else printf("CxbxDbg: _DEBUG_TRACK_VB is not defined!\n"); @@ -214,13 +234,17 @@ void DbgConsole::ParseCommand() { #ifdef _DEBUG_TRACK_VB { - using namespace XTL; + int n=0, m=0; - int n=0; - - if(sscanf(m_szInput, "%*s %d", &n) == 1) + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) { - EnableVB(n, false); + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, false); + } + else if(c == 2) + { + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, false); } else { @@ -235,13 +259,17 @@ void DbgConsole::ParseCommand() { #ifdef _DEBUG_TRACK_VB { - using namespace XTL; + int n=0, m=0; - int n=0; - - if(sscanf(m_szInput, "%*s %d", &n) == 1) + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) { - EnableVB(n, true); + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, true); + } + else if(c == 2) + { + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, true); } else { @@ -252,6 +280,81 @@ void DbgConsole::ParseCommand() printf("CxbxDbg: _DEBUG_TRACK_VB is not defined!\n"); #endif } + else if(stricmp(szCmd, "lpb") == 0 || stricmp(szCmd, "ListPB") == 0) + { + #ifdef _DEBUG_TRACK_PB + { + int v=0; + + g_PBTrackTotal.Lock(); + + RTNode *cur = g_PBTrackTotal.getHead(); + + while(cur != NULL && cur->pNext != NULL) + { + bool enabled = !g_PBTrackDisable.exists(cur->pResource); + + printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); + + cur = cur->pNext; + } + + g_PBTrackTotal.Unlock(); + } + #else + printf("CxbxDbg: _DEBUG_TRACK_PB is not defined!\n"); + #endif + } + else if(stricmp(szCmd, "dpb") == 0 || stricmp(szCmd, "DisablePB") == 0) + { + #ifdef _DEBUG_TRACK_PB + { + int n=0, m=0; + + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, false); + } + else if(c == 2) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, false); + } + else + { + printf("CxbxDbg: Syntax Incorrect (dpb #)\n"); + } + } + #else + printf("CxbxDbg: _DEBUG_TRACK_PB is not defined!\n"); + #endif + } + else if(stricmp(szCmd, "epb") == 0 || stricmp(szCmd, "EnablePB") == 0) + { + #ifdef _DEBUG_TRACK_PB + { + int n=0, m=0; + + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, true); + } + else if(c == 2) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, true); + } + else + { + printf("CxbxDbg: Syntax Incorrect (dpb #)\n"); + } + } + #else + printf("CxbxDbg: _DEBUG_TRACK_PB is not defined!\n"); + #endif + } else if(stricmp(szCmd, "cls") == 0) { // clear screen using system call diff --git a/Source/Win32/CxbxKrnl/EmuD3D8.cpp b/Source/Win32/CxbxKrnl/EmuD3D8.cpp index 08bfefc2b..59b434a3a 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -44,6 +44,7 @@ namespace xboxkrnl #include "EmuFS.h" #include "EmuShared.h" #include "DbgConsole.h" +#include "ResourceTracker.h" // prevent name collisions namespace XTL @@ -873,6 +874,8 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // update z-stencil surface cache g_pCachedZStencilSurface = new XTL::X_D3DSurface(); + g_pCachedZStencilSurface->Common = 0; + g_pCachedZStencilSurface->Data = X_D3DRESOURCE_DATA_FLAG_D3DSTEN; g_pD3DDevice8->GetDepthStencilSurface(&g_pCachedZStencilSurface->EmuSurface8); // begin scene @@ -936,7 +939,7 @@ static void EmuVerifyResourceIsRegistered(XTL::X_D3DResource *pResource) return; // Already "Registered" implicitly - if(pResource->Data == X_D3DRESOURCE_DATA_FLAG_D3DREND) + if((pResource->Data == X_D3DRESOURCE_DATA_FLAG_D3DREND) || (pResource->Data == X_D3DRESOURCE_DATA_FLAG_D3DSTEN)) return; int v=0; @@ -1985,8 +1988,7 @@ XTL::X_D3DSurface * WINAPI XTL::EmuIDirect3DDevice8_GetDepthStencilSurface2() { EmuSwapFS(); // Win2k/XP FS - DbgPrintf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface2()\n", - GetCurrentThreadId()); + DbgPrintf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface2()\n", GetCurrentThreadId()); IDirect3DSurface8 *pSurface8 = g_pCachedZStencilSurface->EmuSurface8; @@ -3113,7 +3115,7 @@ static void EmuFlushD3DIVB() HRESULT hRet = S_OK; #ifdef _DEBUG_TRACK_VB - if(!XTL::g_bVBSkipStream) + if(!g_bVBSkipStream) { #endif @@ -4089,12 +4091,24 @@ ULONG WINAPI XTL::EmuIDirect3DResource8_Release } } + #ifdef _DEBUG_TRACE_VB + D3DRESOURCETYPE Type = pResource8->GetType(); + #endif + uRet = pResource8->Release(); if(uRet == 0) { DbgPrintf("EmuIDirect3DResource8_Release (0x%X): Cleaned up a Resource!\n", GetCurrentThreadId()); + #ifdef _DEBUG_TRACE_VB + if(Type == D3DRTYPE_VERTEXBUFFER) + { + g_VBTrackTotal.remove(pResource8); + g_VBTrackDisable.remove(pResource8); + } + #endif + delete pThis; } } @@ -6227,17 +6241,24 @@ VOID WINAPI XTL::EmuIDirect3DDevice8_DrawVertices uint32 nStride = EmuFixupVerticesA(PrimitiveType, PrimitiveCount, pOrigVertexBuffer8, pHackVertexBuffer8, StartVertex, 0, 0, 0); #ifdef _DEBUG_TRACK_VB - if(!g_bVBSkipStream) + if(g_bVBSkipStream) + { + g_pD3DDevice8->DrawPrimitive + ( + PCPrimitiveType, + StartVertex, + 0 + ); + } + else { #endif - - g_pD3DDevice8->DrawPrimitive - ( - PCPrimitiveType, - StartVertex, - PrimitiveCount - ); - + g_pD3DDevice8->DrawPrimitive + ( + PCPrimitiveType, + StartVertex, + PrimitiveCount + ); #ifdef _DEBUG_TRACK_VB } #endif diff --git a/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp b/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp index 11d82b3d8..c80e5f90d 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp @@ -35,6 +35,7 @@ #define _XBOXKRNL_DEFEXTRN_ #include "Emu.h" +#include "ResourceTracker.h" // prevent name collisions namespace XTL @@ -109,6 +110,10 @@ void XTL::EmuExecutePushBuffer pIndexData = pdwPushData; + #ifdef _DEBUG_TRACK_PB + g_PBTrackTotal.insert(pIndexData); + #endif + pdwPushData += dwCount - (bInc ? 0 : 1); // perform rendering @@ -135,10 +140,19 @@ void XTL::EmuExecutePushBuffer { g_pD3DDevice8->SetIndices(pIndexBuffer, 0); + #ifdef _DEBUG_TRACK_PB + if(!g_PBTrackDisable.exists(pIndexData)) + { + #endif + g_pD3DDevice8->DrawIndexedPrimitive ( PCPrimitiveType, 0, dwCount*2, 0, EmuD3DVertex2PrimitiveCount(XBPrimitiveType, dwCount*2) ); + + #ifdef _DEBUG_TRACK_PB + } + #endif } // cleanup diff --git a/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp b/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp index f98349ff5..58fde5c57 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp @@ -45,105 +45,6 @@ namespace XTL extern XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8; // Direct3D8 Device -#ifdef _DEBUG_TRACK_VB - -bool XTL::g_bVBSkipStream = false; - -XTL::VBTracker XTL::g_VBTrackTotal, XTL::g_VBTrackDisable; - -XTL::VBTracker::~VBTracker() -{ - VBNode *cur = m_head; - - while(cur != NULL) - { - VBNode *tmp = cur->next; - - delete cur; - - cur = tmp; - } -} - -void XTL::VBTracker::insert(IDirect3DVertexBuffer8 *pVB) -{ - if(exists(pVB)) - return; - - if(m_head == 0) - { - m_tail = m_head = new VBNode(); - m_tail->vb = 0; - m_tail->next = 0; - } - - m_tail->vb = pVB; - - m_tail->next = new VBNode(); - - m_tail = m_tail->next; - - m_tail->vb = 0; - m_tail->next = 0; - - return; -} - -void XTL::VBTracker::remove(IDirect3DVertexBuffer8 *pVB) -{ - VBNode *pre = 0; - VBNode *cur = m_head; - - while(cur != NULL) - { - if(cur->vb == pVB) - { - if(pre != 0) - { - pre->next = cur->next; - } - else - { - m_head = cur->next; - - if(m_head->next == 0) - { - delete m_head; - - m_head = 0; - m_tail = 0; - } - } - - delete cur; - - return; - } - - pre = cur; - cur = cur->next; - } - - return; -} - -bool XTL::VBTracker::exists(IDirect3DVertexBuffer8 *pVB) -{ - VBNode *cur = m_head; - - while(cur != NULL) - { - if(cur->vb == pVB) - return true; - - cur = cur->next; - } - - return false; -} - -#endif // _DEBUG_TRACK_VB - // fixup xbox extensions to be compatible with PC direct3d UINT XTL::EmuFixupVerticesA ( diff --git a/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp b/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp index 5764be0a8..d345d514a 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp @@ -45,8 +45,6 @@ namespace XTL extern XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8; // Direct3D8 Device -#include - // **************************************************************************** // * Vertex shader function recompiler // **************************************************************************** @@ -1463,7 +1461,7 @@ static DWORD VshConvertToken_CONSTMEM(DWORD *pToken) //pToken = D3DVSD_CONST(ConstantAddress, Count); - for (int i = 0; i < Count; i++) + for (uint i = 0; i < Count; i++) { DbgVshPrintf("\t0x%08X,\n", pToken); } diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index dbe810567..b13b2607b 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -850,7 +850,13 @@ XBSYSAPI EXPORTNUM(171) VOID NTAPI xboxkrnl::MmFreeContiguousMemory } if(BaseAddress != &xLaunchDataPage) + { free(BaseAddress); + } + else + { + DbgPrintf("Ignored MmFreeContiguousMemory(&xLaunchDataPage)\n"); + } EmuSwapFS(); // Xbox FS diff --git a/Source/Win32/CxbxKrnl/ResourceTracker.cpp b/Source/Win32/CxbxKrnl/ResourceTracker.cpp new file mode 100644 index 000000000..8b795e083 --- /dev/null +++ b/Source/Win32/CxbxKrnl/ResourceTracker.cpp @@ -0,0 +1,153 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Win32->CxbxKrnl->ResourceTracker.cpp +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * +// * All rights reserved +// * +// ****************************************************************** +#include "ResourceTracker.h" + +// exported globals +bool g_bVBSkipStream = false; +bool g_bVBSkipPusher = false; +ResourceTracker g_VBTrackTotal; +ResourceTracker g_VBTrackDisable; +ResourceTracker g_PBTrackTotal; +ResourceTracker g_PBTrackDisable; + +ResourceTracker::~ResourceTracker() +{ + RTNode *cur = m_head; + + while(cur != 0) + { + RTNode *tmp = cur->pNext; + + delete cur; + + cur = tmp; + } +} + +void ResourceTracker::insert(void *pResource) +{ + this->Lock(); + + if(exists(pResource)) + { + this->Unlock(); + return; + } + + if(m_head == 0) + { + m_tail = m_head = new RTNode(); + m_tail->pResource = 0; + m_tail->pNext = 0; + } + + m_tail->pResource = pResource; + + m_tail->pNext = new RTNode(); + + m_tail = m_tail->pNext; + + m_tail->pResource = 0; + m_tail->pNext = 0; + + this->Unlock(); + + return; +} + +void ResourceTracker::remove(void *pResource) +{ + this->Lock(); + + RTNode *pre = 0; + RTNode *cur = m_head; + + while(cur != 0) + { + if(cur->pResource == pResource) + { + if(pre != 0) + { + pre->pNext = cur->pNext; + } + else + { + m_head = cur->pNext; + + if(m_head->pNext == 0) + { + delete m_head; + + m_head = 0; + m_tail = 0; + } + } + + delete cur; + + this->Unlock(); + + return; + } + + pre = cur; + cur = cur->pNext; + } + + this->Unlock(); + + return; +} + +bool ResourceTracker::exists(void *pResource) +{ + this->Lock(); + + RTNode *cur = m_head; + + while(cur != 0) + { + if(cur->pResource == pResource) + { + this->Unlock(); + return true; + } + + cur = cur->pNext; + } + + this->Unlock(); + + return false; +}