DX11: Fix mipmaps. Someone forgot creating them at the proper time ;P

DX11: Fix a DX11 debug runtime error caused by the vertex shader output signature and the pixel shader input signature not matching if per-pixel lighting is disabled. Someone forgot disabling those pixel shader parameters ;P
DX11: Enable use of dynamic textures wherever possible.
DX9: Remove two unnecessary TODOs. Someone forgot removing those since they've been obsolete for a long time ;P

Anyway, at least working mipmaps and dynamic textures should increase DX11 performance a bit. And "a bit" is more than my usual "marginally" ;)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6473 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2010-11-24 19:13:19 +00:00
parent 84a72e90b0
commit 76b9e975d5
11 changed files with 29 additions and 27 deletions

View File

@ -26,7 +26,7 @@
// shader cache for every revision, graphics-related or not, which is simply annoying. // shader cache for every revision, graphics-related or not, which is simply annoying.
enum enum
{ {
LINEAR_DISKCACHE_VER = 6463 LINEAR_DISKCACHE_VER = 6473
}; };
// On disk format: // On disk format:

View File

@ -540,13 +540,22 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numTexgen; ++i) for (int i = 0; i < numTexgen; ++i)
WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i); WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i);
WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen); WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen);
WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1); if(g_ActiveConfig.bEnablePixelLigting)
WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1);
} }
else else
{ {
// wpos is in w of first 4 texcoords // wpos is in w of first 4 texcoords
for (int i = 0; i < 8; ++i) if(g_ActiveConfig.bEnablePixelLigting)
WRITE(p, ",\n in float4 uv%d : TEXCOORD%d", i, i); {
for (int i = 0; i < 8; ++i)
WRITE(p, ",\n in float4 uv%d : TEXCOORD%d", i, i);
}
else
{
for (int i = 0; i < xfregs.numTexGens; ++i)
WRITE(p, ",\n in float%d uv%d : TEXCOORD%d", i < 4 ? 4 : 3 , i, i);
}
} }
WRITE(p, " ) {\n"); WRITE(p, " ) {\n");

View File

@ -356,7 +356,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage,
entry->hash = *(u32*)ptr = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF); entry->hash = *(u32*)ptr = (u32)(((double)rand() / RAND_MAX) * 0xFFFFFFFF);
// load texture // load texture
entry->Load(width, height, expandedWidth, 0); entry->Load(width, height, expandedWidth, 0, (texLevels == 0));
// load mips // load mips
if (texLevels > 1 && pcfmt != PC_TEX_FMT_NONE) if (texLevels > 1 && pcfmt != PC_TEX_FMT_NONE)

View File

@ -61,7 +61,7 @@ public:
virtual bool Save(const char filename[]) = 0; virtual bool Save(const char filename[]) = 0;
virtual void Load(unsigned int width, unsigned int height, virtual void Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level) = 0; unsigned int expanded_width, unsigned int level, bool autogen_mips = false) = 0;
virtual void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf, virtual void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf,
unsigned int cbufid, const float *colmat, const EFBRectangle &source_rect, unsigned int cbufid, const float *colmat, const EFBRectangle &source_rect,
bool bIsIntensityFmt, u32 copyfmt) = 0; bool bIsIntensityFmt, u32 copyfmt) = 0;

View File

@ -61,12 +61,12 @@ bool TextureCache::TCacheEntry::Save(const char filename[])
} }
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level) unsigned int expanded_width, unsigned int level, bool autogen_mips)
{ {
// TODO: remove hax
if (level != 0) return;
D3D::ReplaceRGBATexture2D(texture->GetTex(), TextureCache::temp, width, height, expanded_width, level, usage); D3D::ReplaceRGBATexture2D(texture->GetTex(), TextureCache::temp, width, height, expanded_width, level, usage);
if (autogen_mips)
PD3DX11FilterTexture(D3D::context, texture->GetTex(), 0, D3DX11_DEFAULT);
} }
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
@ -77,18 +77,15 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
D3D11_CPU_ACCESS_FLAG cpu_access = (D3D11_CPU_ACCESS_FLAG)0; D3D11_CPU_ACCESS_FLAG cpu_access = (D3D11_CPU_ACCESS_FLAG)0;
D3D11_SUBRESOURCE_DATA srdata, *data = NULL; D3D11_SUBRESOURCE_DATA srdata, *data = NULL;
// TODO: remove hax if (tex_levels == 1)
tex_levels = 1;
if (1 == tex_levels)
{ {
usage = D3D11_USAGE_DYNAMIC; usage = D3D11_USAGE_DYNAMIC;
cpu_access = D3D11_CPU_ACCESS_WRITE; cpu_access = D3D11_CPU_ACCESS_WRITE;
srdata.pSysMem = TextureCache::temp; srdata.pSysMem = TextureCache::temp;
srdata.SysMemPitch = 4 * expanded_width; srdata.SysMemPitch = 4 * expanded_width;
// testing
//data = &srdata; data = &srdata;
} }
const D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, const D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM,
@ -107,9 +104,6 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
SAFE_RELEASE(pTexture); SAFE_RELEASE(pTexture);
if (0 == tex_levels)
PD3DX11FilterTexture(D3D::context, entry->texture->GetTex(), 0, D3DX11_DEFAULT);
return entry; return entry;
} }

View File

@ -46,7 +46,7 @@ private:
~TCacheEntry(); ~TCacheEntry();
void Load(unsigned int width, unsigned int height, void Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int levels); unsigned int expanded_width, unsigned int levels, bool autogen_mips = false);
void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf, void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf,
unsigned int cbufid, const float* colmat, const EFBRectangle &source_rect, unsigned int cbufid, const float* colmat, const EFBRectangle &source_rect,

View File

@ -36,8 +36,6 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
} }
HRESULT hr; HRESULT hr;
// TODO(ector): Allow mipmaps for non-pow textures on newer cards?
// TODO(ector): Use the game-specified mipmaps?
if (levels > 0) if (levels > 0)
hr = dev->CreateTexture(width, height, levels, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL); hr = dev->CreateTexture(width, height, levels, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
else else

View File

@ -64,9 +64,10 @@ bool TextureCache::TCacheEntry::Save(const char filename[])
} }
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level) unsigned int expanded_width, unsigned int level, bool autogen_mips)
{ {
D3D::ReplaceTexture2D(texture, temp, width, height, expanded_width, d3d_fmt, swap_r_b, level); D3D::ReplaceTexture2D(texture, temp, width, height, expanded_width, d3d_fmt, swap_r_b, level);
// D3D9 will automatically generate mip maps if necessary
} }
void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf, void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf,

View File

@ -44,7 +44,7 @@ private:
~TCacheEntry(); ~TCacheEntry();
void Load(unsigned int width, unsigned int height, void Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int levels); unsigned int expanded_width, unsigned int levels, bool autogen_mips = false);
void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf, void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf,
unsigned int cbufid, const float* colmat, const EFBRectangle &source_rect, unsigned int cbufid, const float* colmat, const EFBRectangle &source_rect,

View File

@ -199,7 +199,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
} }
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level) unsigned int expanded_width, unsigned int level, bool autogen_mips)
{ {
//glEnable(GL_TEXTURE_2D); //glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
@ -210,7 +210,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
if (expanded_width != width) if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width); glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
if (bHaveMipMaps && 0 == level) if (bHaveMipMaps && autogen_mips)
{ {
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp); glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);

View File

@ -54,7 +54,7 @@ private:
~TCacheEntry(); ~TCacheEntry();
void Load(unsigned int width, unsigned int height, void Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level); unsigned int expanded_width, unsigned int level, bool autogen_mips = false);
void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf, void FromRenderTarget(bool bFromZBuffer, bool bScaleByHalf,
unsigned int cbufid, const float colmat[], const EFBRectangle &source_rect, unsigned int cbufid, const float colmat[], const EFBRectangle &source_rect,