D3D: Handle device resets (resizes) a little bit better .. not quite there yet. some random cleanup.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4279 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e0baa817e4
commit
ef6e574ea1
|
@ -102,12 +102,10 @@ void FlushPipeline()
|
||||||
|
|
||||||
void SetGenerationMode(const BPCmd &bp)
|
void SetGenerationMode(const BPCmd &bp)
|
||||||
{
|
{
|
||||||
// dev->SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
|
||||||
D3D::SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
D3D::SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
||||||
|
|
||||||
if (bpmem.genMode.cullmode == 3)
|
if (bpmem.genMode.cullmode == 3)
|
||||||
{
|
{
|
||||||
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
|
|
||||||
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, 0);
|
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -118,7 +116,6 @@ void SetGenerationMode(const BPCmd &bp)
|
||||||
if (bpmem.blendmode.colorupdate)
|
if (bpmem.blendmode.colorupdate)
|
||||||
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
||||||
|
|
||||||
// dev->SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
|
||||||
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,19 +292,17 @@ void SetSamplerState(const BPCmd &bp)
|
||||||
if ((bp.address & 0xE0) == 0xA0)
|
if ((bp.address & 0xE0) == 0xA0)
|
||||||
stage += 4;
|
stage += 4;
|
||||||
|
|
||||||
if (g_ActiveConfig.iMaxAnisotropy > 1)
|
if (mag == D3DTEXF_LINEAR && min == D3DTEXF_LINEAR &&
|
||||||
|
g_ActiveConfig.iMaxAnisotropy > 1)
|
||||||
{
|
{
|
||||||
mag = D3DTEXF_LINEAR;
|
|
||||||
min = D3DTEXF_ANISOTROPIC;
|
min = D3DTEXF_ANISOTROPIC;
|
||||||
mip = D3DTEXF_LINEAR;
|
|
||||||
}
|
}
|
||||||
dev->SetSamplerState(stage, D3DSAMP_MINFILTER, min);
|
D3D::SetSamplerState(stage, D3DSAMP_MINFILTER, min);
|
||||||
dev->SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
|
D3D::SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
|
||||||
dev->SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
|
D3D::SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
|
||||||
|
|
||||||
dev->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);
|
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
|
||||||
dev->SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
|
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
|
||||||
dev->SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
|
|
||||||
//wip
|
//wip
|
||||||
//dev->SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,tm0.lod_bias/4.0f);
|
//dev->SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,tm0.lod_bias/4.0f);
|
||||||
//char temp[256];
|
//char temp[256];
|
||||||
|
|
|
@ -37,6 +37,13 @@ LPDIRECT3DTEXTURE9 GetEFBColorTexture(const EFBRectangle& sourceRc)
|
||||||
return s_efb_color_texture;
|
return s_efb_color_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LPDIRECT3DTEXTURE9 GetEFBDepthTexture(const EFBRectangle &sourceRc)
|
||||||
|
{
|
||||||
|
// Depth textures not supported under DX9. We're gonna fake this
|
||||||
|
// with a secondary render target later.
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void Create()
|
void Create()
|
||||||
{
|
{
|
||||||
// Simplest possible setup to start with.
|
// Simplest possible setup to start with.
|
||||||
|
@ -62,10 +69,9 @@ void Destroy()
|
||||||
|
|
||||||
s_efb_color_surface->Release();
|
s_efb_color_surface->Release();
|
||||||
s_efb_color_surface = NULL;
|
s_efb_color_surface = NULL;
|
||||||
#ifdef TEXSURF
|
|
||||||
s_efb_color_texture->Release();
|
s_efb_color_texture->Release();
|
||||||
s_efb_color_texture = NULL;
|
s_efb_color_texture = NULL;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
|
@ -68,12 +68,19 @@ void SetupDeviceObjects()
|
||||||
D3D::font.Init();
|
D3D::font.Init();
|
||||||
VertexLoaderManager::Init();
|
VertexLoaderManager::Init();
|
||||||
FBManager::Create();
|
FBManager::Create();
|
||||||
|
|
||||||
|
VertexShaderManager::Init();
|
||||||
|
PixelShaderManager::Init();
|
||||||
|
|
||||||
// Tex and shader caches will recreate themselves over time.
|
// Tex and shader caches will recreate themselves over time.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill off all POOL_DEFAULT device objects.
|
// Kill off all POOL_DEFAULT device objects.
|
||||||
void TeardownDeviceObjects()
|
void TeardownDeviceObjects()
|
||||||
{
|
{
|
||||||
|
VertexShaderManager::Shutdown();
|
||||||
|
PixelShaderManager::Shutdown();
|
||||||
|
|
||||||
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
|
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
|
||||||
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
|
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
|
||||||
FBManager::Destroy();
|
FBManager::Destroy();
|
||||||
|
@ -83,8 +90,6 @@ void TeardownDeviceObjects()
|
||||||
VertexLoaderManager::Shutdown();
|
VertexLoaderManager::Shutdown();
|
||||||
VertexShaderCache::Clear();
|
VertexShaderCache::Clear();
|
||||||
PixelShaderCache::Clear();
|
PixelShaderCache::Clear();
|
||||||
|
|
||||||
// This really should be all but Zelda for example still fails...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::Init()
|
bool Renderer::Init()
|
||||||
|
@ -134,8 +139,8 @@ bool Renderer::Init()
|
||||||
|
|
||||||
SetupDeviceObjects();
|
SetupDeviceObjects();
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++)
|
for (int stage = 0; stage < 8; stage++)
|
||||||
D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16);
|
D3D::SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);
|
||||||
|
|
||||||
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0, 0);
|
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0, 0);
|
||||||
|
|
||||||
|
@ -358,7 +363,6 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
|
||||||
|
|
||||||
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
||||||
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
||||||
D3D::dev->SetRenderState(D3DRS_ZENABLE, TRUE);
|
|
||||||
|
|
||||||
RECT rc;
|
RECT rc;
|
||||||
rc.left = 0;
|
rc.left = 0;
|
||||||
|
@ -366,7 +370,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
|
||||||
rc.right = (LONG)s_target_width;
|
rc.right = (LONG)s_target_width;
|
||||||
rc.bottom = (LONG)s_target_height;
|
rc.bottom = (LONG)s_target_height;
|
||||||
D3D::dev->SetScissorRect(&rc);
|
D3D::dev->SetScissorRect(&rc);
|
||||||
D3D::dev->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
||||||
|
|
||||||
UpdateViewport();
|
UpdateViewport();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ void TextureCache::TCacheEntry::Destroy(bool shutdown)
|
||||||
texture = 0;
|
texture = 0;
|
||||||
if (!isRenderTarget && !shutdown)
|
if (!isRenderTarget && !shutdown)
|
||||||
{
|
{
|
||||||
u32 *ptr = (u32*)g_VideoInitialize.pGetMemoryPointer(addr + hashoffset*4);
|
u32 *ptr = (u32*)g_VideoInitialize.pGetMemoryPointer(addr);
|
||||||
if (ptr && *ptr == hash)
|
if (ptr && *ptr == hash)
|
||||||
*ptr = oldpixel;
|
*ptr = oldpixel;
|
||||||
}
|
}
|
||||||
|
@ -211,11 +211,10 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
|
||||||
//Make an entry in the table
|
//Make an entry in the table
|
||||||
TCacheEntry& entry = textures[texID];
|
TCacheEntry& entry = textures[texID];
|
||||||
|
|
||||||
entry.hashoffset = 0;
|
|
||||||
entry.hash = hash_value;
|
entry.hash = hash_value;
|
||||||
//entry.hash = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF);
|
//entry.hash = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF);
|
||||||
entry.paletteHash = palhash;
|
entry.paletteHash = palhash;
|
||||||
entry.oldpixel = ((u32 *)ptr)[entry.hashoffset];
|
entry.oldpixel = ((u32 *)ptr)[0];
|
||||||
//((u32 *)ptr)[entry.hashoffset] = entry.hash;
|
//((u32 *)ptr)[entry.hashoffset] = entry.hash;
|
||||||
|
|
||||||
entry.addr = address;
|
entry.addr = address;
|
||||||
|
@ -226,18 +225,14 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
|
||||||
entry.w = width;
|
entry.w = width;
|
||||||
entry.h = height;
|
entry.h = height;
|
||||||
entry.fmt = format;
|
entry.fmt = format;
|
||||||
entry.mode = bpmem.tex[stage > 3].texMode0[stage & 3];
|
|
||||||
|
|
||||||
if (g_ActiveConfig.bDumpTextures)
|
if (g_ActiveConfig.bDumpTextures)
|
||||||
{ // dump texture to file
|
{ // dump texture to file
|
||||||
|
|
||||||
char szTemp[MAX_PATH];
|
char szTemp[MAX_PATH];
|
||||||
char szDir[MAX_PATH];
|
char szDir[MAX_PATH];
|
||||||
const char* uniqueId = globals->unique_id;
|
const char* uniqueId = globals->unique_id;
|
||||||
bool bCheckedDumpDir = false;
|
bool bCheckedDumpDir = false;
|
||||||
|
|
||||||
sprintf(szDir, "%s/%s", FULL_DUMP_TEXTURES_DIR, uniqueId);
|
sprintf(szDir, "%s/%s", FULL_DUMP_TEXTURES_DIR, uniqueId);
|
||||||
|
|
||||||
if (!bCheckedDumpDir)
|
if (!bCheckedDumpDir)
|
||||||
{
|
{
|
||||||
if (!File::Exists(szDir) || !File::IsDirectory(szDir))
|
if (!File::Exists(szDir) || !File::IsDirectory(szDir))
|
||||||
|
@ -245,13 +240,10 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
|
||||||
|
|
||||||
bCheckedDumpDir = true;
|
bCheckedDumpDir = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir, uniqueId, tex_hash, format);
|
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir, uniqueId, tex_hash, format);
|
||||||
//sprintf(szTemp, "%s\\txt_%04i_%i.png", g_Config.texDumpPath.c_str(), counter++, format); <-- Old method
|
//sprintf(szTemp, "%s\\txt_%04i_%i.png", g_Config.texDumpPath.c_str(), counter++, format); <-- Old method
|
||||||
if (!File::Exists(szTemp))
|
if (!File::Exists(szTemp))
|
||||||
D3DXSaveTextureToFileA(szTemp,D3DXIFF_BMP,entry.texture,0);
|
D3DXSaveTextureToFileA(szTemp,D3DXIFF_BMP,entry.texture,0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INCSTAT(stats.numTexturesCreated);
|
INCSTAT(stats.numTexturesCreated);
|
||||||
|
@ -298,7 +290,6 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
|
||||||
TCacheEntry entry;
|
TCacheEntry entry;
|
||||||
entry.isRenderTarget = true;
|
entry.isRenderTarget = true;
|
||||||
entry.hash = 0;
|
entry.hash = 0;
|
||||||
entry.hashoffset = 0;
|
|
||||||
entry.frameCount = frameCount;
|
entry.frameCount = frameCount;
|
||||||
entry.w = tex_w;
|
entry.w = tex_w;
|
||||||
entry.h = tex_h;
|
entry.h = tex_h;
|
||||||
|
|
|
@ -31,21 +31,26 @@ public:
|
||||||
struct TCacheEntry
|
struct TCacheEntry
|
||||||
{
|
{
|
||||||
LPDIRECT3DTEXTURE9 texture;
|
LPDIRECT3DTEXTURE9 texture;
|
||||||
|
|
||||||
u32 addr;
|
u32 addr;
|
||||||
|
u32 size_in_bytes;
|
||||||
u32 hash;
|
u32 hash;
|
||||||
u32 paletteHash;
|
u32 paletteHash;
|
||||||
u32 hashoffset;
|
|
||||||
u32 oldpixel;
|
u32 oldpixel;
|
||||||
bool isRenderTarget;
|
|
||||||
bool isNonPow2;
|
|
||||||
int frameCount;
|
int frameCount;
|
||||||
int w, h, fmt;
|
int w, h, fmt;
|
||||||
TexMode0 mode; // current filter and clamp modes that texture is set to
|
|
||||||
|
bool isRenderTarget;
|
||||||
|
bool isNonPow2;
|
||||||
|
|
||||||
TCacheEntry()
|
TCacheEntry()
|
||||||
{
|
{
|
||||||
texture = 0;
|
texture = 0;
|
||||||
isRenderTarget = 0;
|
isRenderTarget = 0;
|
||||||
hash = 0;
|
hash = 0;
|
||||||
|
paletteHash = 0;
|
||||||
|
oldpixel = 0;
|
||||||
}
|
}
|
||||||
void Destroy(bool shutdown);
|
void Destroy(bool shutdown);
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@ class TextureMngr
|
||||||
public:
|
public:
|
||||||
struct TCacheEntry
|
struct TCacheEntry
|
||||||
{
|
{
|
||||||
TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0), w(0), h(0), scaleX(1.0f), scaleY(1.0f), isRenderTarget(false), isUpsideDown(false), isRectangle(true), bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; }
|
TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0), w(0), h(0), scaleX(1.0f), scaleY(1.0f), isRenderTarget(false), isRectangle(true), bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; }
|
||||||
|
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
u32 addr;
|
u32 addr;
|
||||||
|
@ -47,7 +47,6 @@ public:
|
||||||
|
|
||||||
bool isRenderTarget; // if render texture, then rendertex is filled with the direct copy of the render target
|
bool isRenderTarget; // if render texture, then rendertex is filled with the direct copy of the render target
|
||||||
// later conversions would have to convert properly from rendertexfmt to texfmt
|
// later conversions would have to convert properly from rendertexfmt to texfmt
|
||||||
bool isUpsideDown;
|
|
||||||
bool isRectangle; // if nonpow2, use GL_TEXTURE_2D, else GL_TEXTURE_RECTANGLE_NV
|
bool isRectangle; // if nonpow2, use GL_TEXTURE_2D, else GL_TEXTURE_RECTANGLE_NV
|
||||||
bool bHaveMipMaps;
|
bool bHaveMipMaps;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue