Page 1 of 1

Mipmap HW Generation Non-Power-Two

Posted: Tue Jul 12, 2016 4:50 am
by cyberjunk

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: ... 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..


Re: Mipmap HW Generation Non-Power-Two

Posted: Wed Jul 13, 2016 2:52 am
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)
  numMips = 0;
From: ... 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: ... 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: ... 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: ... 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: ... re.cpp-254

Re: Mipmap HW Generation Non-Power-Two

Posted: Tue Jul 19, 2016 5:38 am
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?

Re: Mipmap HW Generation Non-Power-Two

Posted: Tue Jul 19, 2016 8:02 am
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.

Re: Mipmap HW Generation Non-Power-Two

Posted: Fri Mar 03, 2017 7:35 pm
by paroj
fixed in 1.10. next time open an issue:

Re: Mipmap HW Generation Non-Power-Two

Posted: Sun May 07, 2017 2:29 am
by cyberjunk

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

I did now:

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.