Mipmap HW Generation Non-Power-Two Topic is solved

What it says on the tin: a place to discuss proposed new features.
Post Reply
cyberjunk
Halfling
Posts: 51
Joined: Tue Jun 05, 2012 4:33 pm
x 1

Mipmap HW Generation Non-Power-Two

Post by cyberjunk »

Hey,

the following line disables mipmap hardware generation for non power-of-two texture sizes in the 1.10 branch (d3d9):

Code: Select all

// Hacky override - many (all?) cards seem to not be able to autogen on 
// textures which are not a power of two
// Can we even mipmap on 3D textures? Well
if ((mWidth & mWidth-1) || (mHeight & mHeight-1) || (mDepth & mDepth-1))
  return false;
From: https://bitbucket.org/sinbad/ogre/src/f ... e.cpp-1677

However, the manual creation of mipmaps (which is caused by this line) seems to be the most expansive task for me when loading larger textures (e.g. 1364x638 and beyond). Note: I didn't chose non-power-of-two textures... I just have to deal with it... :D

I removed this check so mipmaps get hw created for non-power-of-two sizes and it seems to work perfectly for me.
System is: Win10 + Ogre 1.10 + Nvidia GTX 660

Is it possible this exclusion for non-power-of-two textures is rather obsolete by now?
Due to its great influence on loading time, I would like to suggest:

1) Consider enabling hw generation (=remove the exclusion). In case any target GPU past e.g. 2010 can do it just fine?
2) May be provide a config option to enable or disable hw mipmaps for non-power-of-two textures..

Thanks!
Last edited by cyberjunk on Wed Jul 13, 2016 5:05 am, edited 1 time in total.
cyberjunk
Halfling
Posts: 51
Joined: Tue Jun 05, 2012 4:33 pm
x 1

Re: Mipmap HW Generation Non-Power-Two

Post by cyberjunk »

This snippet from the OgreD3D9Texture.cpp:

Code: Select all

// use auto.gen. if available, and if desired
mMipmapsHardwareGenerated = _canAutoGenMipmaps(d3d9Device, usage, D3DRTYPE_TEXTURE, d3dPF);
if (mMipmapsHardwareGenerated)
{
  usage |= D3DUSAGE_AUTOGENMIPMAP;
  numMips = 0;
}
From: https://bitbucket.org/sinbad/ogre/src/f ... e.cpp-1078

The 'numMips' will actually be used in the call to 'D3DXCreateTexture()' later.
It seems that if hardware generation is enabled, it will always create mipmaps up to 1x1 and ignore any setting for it. Is that right?
If this value is zero or D3DX_DEFAULT, a complete mipmap chain is created.
From: https://msdn.microsoft.com/en-us/librar ... s.85).aspx

I've tried uncommenting the following statement from above and it seems mitmaps are still generated fine (and possibly faster due to less levels if set so)

Code: Select all

//numMips = 0;
Furthermore I'd like to add, that this snippet (which is executed at the end of texture creation) will always set 'mNumMipmaps' to 0 for hw-generated:

Code: Select all

// Make sure number of mips is right
mNumMipmaps = static_cast<uint8>(textureResources->pBaseTex->GetLevelCount() - 1);
From: https://bitbucket.org/sinbad/ogre/src/f ... e.cpp-1730
Warning If you create a texture with D3DUSAGE_AUTOGENMIPMAP to make that texture automatically generate sublevels, GetLevelCount always returns 1 for the number of levels.
From: https://msdn.microsoft.com/en-us/librar ... s.85).aspx

This will actually cause incorrect logs created (not mentioning the mipmaps at all), because this is checking for 'nNumMipmaps'

Code: Select all

if (!(mMipmapsHardwareGenerated && mNumMipmaps == 0))
{
  str << " with " << static_cast<int>(mNumMipmaps);
  if(mUsage & TU_AUTOMIPMAP)
  {
    if (mMipmapsHardwareGenerated)
      str << " hardware";
  
   str << " generated mipmaps";
...
From: https://bitbucket.org/sinbad/ogre/src/f ... re.cpp-254
cyberjunk
Halfling
Posts: 51
Joined: Tue Jun 05, 2012 4:33 pm
x 1

Re: Mipmap HW Generation Non-Power-Two

Post by cyberjunk »

Anyone reviewed this?

I've tested on a couple of other GPU hardware, back to "Nvidia 9650M GT" from ~2008, and they all seem to do hw mipmaps also for non-power-of-two just fine.
I've also rolled out this change with the latest patch for my game client and got no negative user feedback so far...

I guess a RenderSystem option might be the best solution?
To maintain backward compatibility, but enable hw mipmaps for non-power-of-two by default or optionally?
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: Mipmap HW Generation Non-Power-Two

Post by Zonder »

For compatibility it probably should be an option I think that can be enabled. I don't get why it doesn't attempt hardware then drop to software if that fails? maybe some drivers hard carsh? might be worth seeing if there was an issue logged with the commit for that change.
There are 10 types of people in the world: Those who understand binary, and those who don't...
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: Mipmap HW Generation Non-Power-Two

Post by paroj »

fixed in 1.10. next time open an issue: https://ogre3d.atlassian.net/projects/OGRE/issues
cyberjunk
Halfling
Posts: 51
Joined: Tue Jun 05, 2012 4:33 pm
x 1

Re: Mipmap HW Generation Non-Power-Two

Post by cyberjunk »

@paroj

Thanks for having a look at this.
Yes, I should have opened a ticket in first place.

I did now:
https://ogre3d.atlassian.net/browse/OGRE-551

Because it seems to me that mentioned problems here about the user-defined mipmap count being ignored and the omitted log-info were not covered in your commit.
Post Reply