DirectX11 mip mapping

Started by
30 comments, last by Visje 11 years, 7 months ago
Hey everyone,

I'm working on a game with DirectX11 and I need to apply a mip mapping on my textures when they get far from the camera (I actually have a menu with a lot of textures far from the camera and the mip mapping doesn't seem to be applied because the framerate is quite low...)

I've searched for 3 days how I could do this and I found many solutions but none of them seems to work...

I have this piece of code that create a texture, and I can show you other pieces if required :


D3D11_TEXTURE2D_DESC textureDesc;
ZeroMemory( &textureDesc, sizeof(textureDesc) );
textureDesc.Width = width;
textureDesc.Height = height;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
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;

When I try to change the MipLevels value to 0 or another value, I get an error...

My question is : What should I do to get the mip mapping to work ? Do you have any clue, any idea.

Sorry for my average english I'm french mellow.png

Thanks a lot !
Advertisement
Are you using correct sampler states in the pixel shaders?

Cheers!
When I try to change the MipLevels value to another value, I get an error...
What is the error?
@Kauna :
In the Pixel Shader, I'm using this Sampler :

SamplerState simpleSampler : register(s0);


and later on... in the main of the PS

float4 texelColor = simpleTexture.Sample(simpleSampler, input.tex);
return texelColor;



@Hodgman :
The error is in french but you may recognize something, here it is :
Exception non gérée à 0x71F9E85C (nvwgf2um.dll) dans Direct3DApp1.exe : 0xC0000005 : Violation d'accès lors de la lecture de l'emplacement 0xCCCCCCCC.
It says, acces violation while writing at 0xCCCCCCCC
SamplerState simpleSampler : register(s0);[/quote]

Have you defined the sampler in the program side?

Cheers!
Yep, here it is :


D3D11_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(samplerDesc));
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.MaxAnisotropy = 0;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
samplerDesc.BorderColor[0] = 0.0f;
samplerDesc.BorderColor[1] = 0.0f;
samplerDesc.BorderColor[2] = 0.0f;
samplerDesc.BorderColor[3] = 0.0f;



Maybe the mipmaps are beeing generated but I can't notice any difference... that should increase the framerate normally :/
Do you check the HRESULT value when trying to create the texture?
It might return failure, and your crash could occur later when you try to use the uninitialized object.

What feature level are you running at?
http://msdn.microsoft.com/en-us/library/windows/desktop/cc627090%28v=vs.85%29.aspx lists B8G8R8A8 as optional for auto-generation of mipmaps, though it seems required on feature level 11.. Check the related pages linked at the menu on that page to check your feature level and supported formats.
I Get the same error with the HRESULT :/

I don't know the feature level i'm running at, actually, what is a "feature level" ?
If I change the format, the colors become very odd depending on the format.
If you change B8G8R8A8 to R8G8B8A8, does it work correctly?
If so, the format is the problem.
You can find your feature level by using ID3D11Device::GetFeatureLevel.
If I change B8G8R8A8 to R8G8B8A8, it works but the colors are all "browny"

My feature level is : D3D_FEATURE_LEVEL_11_0 (45056)

This topic is closed to new replies.

Advertisement