Set a Minimum Mip Level ?

Started by
4 comments, last by Mona2000 8 years, 10 months ago

Hi guys,

I create my mips automatically with ID3D11DeviceContext::GenerateMips() and they seem to be working.

I'd like to be able to set a minimum level to use. For example, if my base texture is 512 x 512 the first mip will be 256 x 256, I want it so that it will always start at that 256 x 256 mip and go lower (to 128 x 128, 64 x 64, and so on).

I tried SetResourceMinLOD() but it doesn't look like it's doing anything.

I was able to do this in D3D9 but can't figure it out in D3D11.

Thanks a lot.

Advertisement

If I understand what you're asking, the MostDetailedMip parameter in the SRV description specifies the largest mip to use. If you have a 512x512 texture, and want to use only 256x256 and smaller, set MostDetailedMip to 1, and MipLevels to -1.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Thanks Buckeye, I didn't know about the D3D11_SHADER_RESOURCE_VIEW_DESC struct since I was passing NULL for pDesc in CreateShaderResourceView(). I'll see if I can get it to work tomorrow.

SetResourceMinLOD is a better solution, because it makes sure the unwanted mips don't get loaded in video memory. In order for it to work, you need to set the flag D3D11_RESOURCE_MISC_RESOURCE_CLAMP when you create the resource. Did you do that?

Hi, I'm not able to get it to work. I'm not even sure if it's generating the mips.

 
ID3D11Texture2D* texture;
ID3D11ShaderResourceView* resourceview;
 
// create texture
 
D3D11_TEXTURE2D_DESC textureDesc;
ZeroMemory(&textureDesc, sizeof(textureDesc));

textureDesc.Width = 512;
textureDesc.Height = 512;
textureDesc.MipLevels = 0;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
 
if(FAILED(d3d_device->CreateTexture2D(&textureDesc, nullptr, &texture)))
 return E_FAIL;
 
// create shader resource
 
if(FAILED(d3d_device->CreateShaderResourceView(texture, nullptr, &resourceview)))
 return E_FAIL;
 
// generate mips
 
d3d_context->GenerateMips(resourceview);
 

Nothing fails but I can't tell if the mips were created or are being used (I thought I could but now I'm not so sure).

If I add D3D11_RESOURCE_MISC_RESOURCE_CLAMP to textureDesc.MiscFlags then CreateTexture2D() fails with E_INVAIDARG.

I am using NULL for the second argument to CreateShaderResourceView() to keep things less complicated while getting the mips set up, then I'll try what Buckeye suggested above.

Thanks guys.

I think you need to set the MipLevels value for it to work? Looks like it doesn't work together with D3D11_RESOURCE_MISC_GENERATE_MIPS.

But yeah, go for Buckeye's method, that one cannot possibly fail.

This topic is closed to new replies.

Advertisement