D3DUSAGE_AUTOGENMIPMAP

Started by
4 comments, last by Woodchuck 17 years, 5 months ago
When I create a texture with the D3DUSAGE_AUTOGENMIPMAP flag I can only create a full texture chain and I can't get a pointer to any other surface than the first one (IDirect3DTexture9::GetSurfaceLevel). However on the GPU the different surfaces is accessable through Tex2Dlod. Anyone know why this is so? Do I have to use IDirect3DBaseTexture9::GenerateMipSubLevels without the flag? [Edited by - 51mon on November 18, 2006 9:44:58 AM]
Advertisement
(1) Does your hardware support automatic generation of mipmaps? This is the D3DCAPS2_CANAUTOGENMIPMAP cap. Notice that even if your card doesn't, your CreateTexture() will still succeed, but just with code D3DOK_NOAUTOGEN.

(2) Does it work if you call GenerateMipSubLevels() separately?
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:Original post by 51mon
When I create a texture with the D3DUSAGE_AUTOGENMIPMAP flag I can only create a full texture chain and I can't get a pointer to any other surface than the first one (IDirect3DTexture9::GetSurfaceLevel).


This is because the autogenmipmap genre of texture only has an explicit handle to its first level. With other types of textures, each level is a high level entity of its own, with autogenmipmap, the whole mipchain is the only high level entity you're allowed to manipulate.

Also (to cover all our bases) you shouldn't confuse the autogenmipmap feature, which is used to generate mipmap levels at runtime after the texture has been rendered to (for example each frame), to regular mipmap textures whose level can be generated at loading time for example by a function such as D3DXCreateTextureFromFile, it will automatically create smaller miplevels if not present in the file by using an optimized but manual filtering technique (you can even select the quality which is not the case for autogenmipmap). And this is done typically only once.

Quote:Original post by 51mon However on the GPU the different surfaces is accessable through Tex2Dlod. Anyone know why this is so? Do I have to use IDirect3DBaseTexture9::GenerateMipSubLevels without the flag?


Tex2Dlod is a texture instruction in a pixel shader, this is just an extension of the regular Texture instruction that allows you to specify a specific LOD to texture from. The hardware is bound to know how to access a specific level of detail in a pixel shader because that's what it does on every texture access.

That doesn't mean the API needs to allow you to individually select a particular level for the purpose of locking, blitting, rendering to.

Also GenerateMipSubLevels is only accessible on textures you've created with the flag AUTOGENMIPMAP, so that the driver knows where to place it and what internal format to use to make the autogeneration of mipmap the most efficient (or even possible due to arch restrictions).

What do you want to achieve with those autogenerated miplevels ?

LeGreg
Quote:Original post by LeGreg
Quote:Original post by 51mon
When I create a texture with the D3DUSAGE_AUTOGENMIPMAP flag I can only create a full texture chain and I can't get a pointer to any other surface than the first one (IDirect3DTexture9::GetSurfaceLevel).


This is because the autogenmipmap genre of texture only has an explicit handle to its first level. With other types of textures, each level is a high level entity of its own, with autogenmipmap, the whole mipchain is the only high level entity you're allowed to manipulate.

Also (to cover all our bases) you shouldn't confuse the autogenmipmap feature, which is used to generate mipmap levels at runtime after the texture has been rendered to (for example each frame), to regular mipmap textures whose level can be generated at loading time for example by a function such as D3DXCreateTextureFromFile, it will automatically create smaller miplevels if not present in the file by using an optimized but manual filtering technique (you can even select the quality which is not the case for autogenmipmap). And this is done typically only once.

Quote:Original post by 51mon However on the GPU the different surfaces is accessable through Tex2Dlod. Anyone know why this is so? Do I have to use IDirect3DBaseTexture9::GenerateMipSubLevels without the flag?


Tex2Dlod is a texture instruction in a pixel shader, this is just an extension of the regular Texture instruction that allows you to specify a specific LOD to texture from. The hardware is bound to know how to access a specific level of detail in a pixel shader because that's what it does on every texture access.

That doesn't mean the API needs to allow you to individually select a particular level for the purpose of locking, blitting, rendering to.

Also GenerateMipSubLevels is only accessible on textures you've created with the flag AUTOGENMIPMAP, so that the driver knows where to place it and what internal format to use to make the autogeneration of mipmap the most efficient (or even possible due to arch restrictions).

What do you want to achieve with those autogenerated miplevels ?

LeGreg


Hi, thanks for the response.
I work with a deferred renderer but part of it is too complicated to be handled by the GPU (need pointers and persisting variables). To speed up the process I only want to send the second level of the mip chain to CPU, while the renderer is operating on the first level. I got the impression from the SDK that you could use IDirect3DBaseTexture9::GenerateMipSubLevels to generate mip chains even when AUTOGENMIPMAP wasn't specified? Otherwise how will I do it?
Quote:Original post by 51mon
Hi, thanks for the response.
I work with a deferred renderer but part of it is too complicated to be handled by the GPU (need pointers and persisting variables). To speed up the process I only want to send the second level of the mip chain to CPU, while the renderer is operating on the first level. I got the impression from the SDK that you could use IDirect3DBaseTexture9::GenerateMipSubLevels to generate mip chains even when AUTOGENMIPMAP wasn't specified? Otherwise how will I do it?


I see,

your point seems that you want the autogeneration to do some computation for you, but really autogenmipmap is only there to generate a whole chain of miplevels of a texture.

If what you want is to access a filtered down version of your rendertarget, you can use that surface in a render, or use stretchrect with the right filter type (do you need it to be bilinear filtered in the first place or you only care about the smaller version ?), and then use GetRenderTargetData to get the data delivered to a system memory surface.
If you're looking for real time perf, you should note that trying to read back data from video memory is generally not the preferred way of doing things..

LeGreg
Do the D3DUSAGE_AUTOGENMIPMAP have a performance issue ?

This topic is closed to new replies.

Advertisement