Merge pull request #1501 from degasus/texture_creation

D3D: remove load texture on creation optimization
This commit is contained in:
Markus Wick 2015-01-11 01:01:18 +01:00
commit 6c46f27709
6 changed files with 12 additions and 30 deletions

View File

@ -81,30 +81,23 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
D3D::ReplaceRGBATexture2D(texture->GetTex(), TextureCache::temp, width, height, expanded_width, level, usage);
}
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
unsigned int height, unsigned int expanded_width,
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, unsigned int height,
unsigned int tex_levels, PC_TexFormat pcfmt)
{
D3D11_USAGE usage = D3D11_USAGE_DEFAULT;
D3D11_CPU_ACCESS_FLAG cpu_access = (D3D11_CPU_ACCESS_FLAG)0;
D3D11_SUBRESOURCE_DATA srdata, *data = nullptr;
if (tex_levels == 1)
{
usage = D3D11_USAGE_DYNAMIC;
cpu_access = D3D11_CPU_ACCESS_WRITE;
srdata.pSysMem = TextureCache::temp;
srdata.SysMemPitch = 4 * expanded_width;
data = &srdata;
}
const D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM,
width, height, 1, tex_levels, D3D11_BIND_SHADER_RESOURCE, usage, cpu_access);
ID3D11Texture2D *pTexture;
const HRESULT hr = D3D::device->CreateTexture2D(&texdesc, data, &pTexture);
const HRESULT hr = D3D::device->CreateTexture2D(&texdesc, nullptr, &pTexture);
CHECK(SUCCEEDED(hr), "Create texture of the TextureCache");
TCacheEntry* const entry = new TCacheEntry(new D3DTexture2D(pTexture, D3D11_BIND_SHADER_RESOURCE));
@ -116,9 +109,6 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
SAFE_RELEASE(pTexture);
if (tex_levels != 1)
entry->Load(width, height, expanded_width, 0);
return entry;
}

View File

@ -39,7 +39,7 @@ private:
};
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int tex_levels, PC_TexFormat pcfmt) override;
unsigned int tex_levels, PC_TexFormat pcfmt) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;
u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source) {return 0;};

View File

@ -108,8 +108,7 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l
return SaveTexture(filename, GL_TEXTURE_2D_ARRAY, texture, virtual_width, virtual_height, level);
}
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
unsigned int height, unsigned int expanded_width,
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, unsigned int height,
unsigned int tex_levels, PC_TexFormat pcfmt)
{
int gl_format = 0,
@ -175,10 +174,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
glBindTexture(GL_TEXTURE_2D_ARRAY, entry.texture);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, tex_levels - 1);
entry.Load(width, height, expanded_width, 0);
// This isn't needed as Load() also reset the stage in the end
//TextureCache::SetStage();
TextureCache::SetStage();
return &entry;
}

View File

@ -54,7 +54,7 @@ private:
~TextureCache();
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int tex_levels, PC_TexFormat pcfmt) override;
unsigned int tex_levels, PC_TexFormat pcfmt) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;

View File

@ -466,7 +466,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
// create the entry/texture
if (nullptr == entry)
{
textures[texID] = entry = g_texture_cache->CreateTexture(width, height, expandedWidth, texLevels, pcfmt);
textures[texID] = entry = g_texture_cache->CreateTexture(width, height, texLevels, pcfmt);
// Sometimes, we can get around recreating a texture if only the number of mip levels changes
// e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states
@ -481,16 +481,14 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
}
else
{
// load texture (CreateTexture also loads level 0)
entry->Load(width, height, expandedWidth, 0);
}
entry->SetGeneralParameters(address, texture_size, full_format, entry->num_mipmaps, entry->num_layers);
entry->SetDimensions(nativeW, nativeH, width, height);
entry->hash = tex_hash;
// load texture
entry->Load(width, height, expandedWidth, 0);
if (entry->IsEfbCopy() && !g_ActiveConfig.bCopyEFBToTexture)
entry->type = TCET_EC_DYNAMIC;
else

View File

@ -33,7 +33,6 @@ public:
u32 addr;
u32 size_in_bytes;
u64 hash;
//u32 pal_hash;
u32 format;
enum TexCacheEntryType type;
@ -64,10 +63,9 @@ public:
virtual_height = _virtual_height;
}
void SetHashes(u64 _hash/*, u32 _pal_hash*/)
void SetHashes(u64 _hash)
{
hash = _hash;
//pal_hash = _pal_hash;
}
@ -100,7 +98,7 @@ public:
static bool Find(u32 start_address, u64 hash);
virtual TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int tex_levels, PC_TexFormat pcfmt) = 0;
unsigned int tex_levels, PC_TexFormat pcfmt) = 0;
virtual TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) = 0;
virtual void CompileShaders() = 0; // currently only implemented by OGL