Advertisement

MipMap Offset

Started by November 11, 2019 04:41 PM
2 comments, last by Jman2 4 years, 9 months ago

Hello,

So a long while ago i asked a question about effecinet mip offset in a linear memory data array, essentially i wanted to load all the data in one go but still allow access to individual faces or mip levels. The method i used was basically to create a look up table when ever the user created an image that stored pointers into the byte data, that is probably the correct solution, however i did come up with a pieace of useless math today after thinking about it:


	inline Uint32 TextureOffset(const TextureDesc& info,  Uint32 mipLevel, Uint32 arraySlice, Uint32 byteCount)
	{
		Uint32 pow = Mathf::Pow(4, mipLevel);
		Uint32 A = byteCount / info.m_ArraySize; // Total bytes to a surface + mips
		Uint32 B = CalculateSurfaceSize(info.m_Width, info.m_Height, info.m_Format); // Total bytes to top level surface
		return  (arraySlice * A) + B + (B * (Mathf::Floor(pow / 3) / pow)); // offset bytes
	}

The above will find the exact offset to the mip and array level, but its waaay to expensive to be useable i think.

Woder what method anyone else would use, i know alot will just create a List or vector of each surface pretty sure thats what nvidia does but it would be nice to be able to load everything into a big bulk container and just dip into the data at the specific offset you need too. The annoying think about the look up is having to loop through and create the offsets to access the data.

I thought an elegant pieace of math would exist but i guess i was wrong xD

I'm not sure what you mean by expensive. Are you referring to that power function? How often are you calling this piece of code?

The power is INTEGRAL, why are you using floating point? :) Are you aware that you can do powers simply by integral shifting?

Advertisement
On 11/12/2019 at 9:14 AM, pcmaster said:

I'm not sure what you mean by expensive. Are you referring to that power function? How often are you calling this piece of code?

The power is INTEGRAL, why are you using floating point? :) Are you aware that you can do powers simply by integral shifting?

Ha yeah your totally right, i missed that as i tackled it from the math perspective instead of code then shuved it into a function as it was...

This topic is closed to new replies.

Advertisement