Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3D: remove load texture on creation optimization #1501

Merged
merged 3 commits into from
Jan 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions Source/Core/VideoBackends/D3D/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D/TextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TextureCache : public ::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;
u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source) {return 0;};
Expand Down
8 changes: 2 additions & 6 deletions Source/Core/VideoBackends/OGL/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/TextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TextureCache : public ::TextureCache
~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;

Expand Down
10 changes: 4 additions & 6 deletions Source/Core/VideoCommon/TextureCacheBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/VideoCommon/TextureCacheBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class TextureCache
u32 addr;
u32 size_in_bytes;
u64 hash;
//u32 pal_hash;
u32 format;

enum TexCacheEntryType type;
Expand Down Expand Up @@ -64,10 +63,9 @@ class TextureCache
virtual_height = _virtual_height;
}

void SetHashes(u64 _hash/*, u32 _pal_hash*/)
void SetHashes(u64 _hash)
{
hash = _hash;
//pal_hash = _pal_hash;
}


Expand Down Expand Up @@ -100,7 +98,7 @@ class TextureCache
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
Expand Down