XNA Creators Club Online
Page 1 of 1 (14 items)
Sort Posts: Previous Next

RenderTarget2D Mipmapping Behavior

Last post 04-30-2008 9:32 PM by warmi1084. 13 replies.
  • 12-26-2007 3:50 PM

    RenderTarget2D Mipmapping Behavior

    I am stuck on a problem -- I am wondering if anyone has run into this before. I am getting an unexpected mipmapping result when baking sprites into a single texture using RenderTarget2D. At a high level here is what I do:

    1) Create a render target and select it.
    2) Render N texture rectangles to the backbuffer.
    3) Restore the previous render target.
    4) Call render target GetTexture() to save texture. When I complete step four I open up the texture and I can see that mip maps are not generated. What am I doing wrong here?


    Here is what the code looks like:

    RenderTarget2D renderTarget = new RenderTarget2D(device, width, height, 0, SurfaceFormat.Color, RenderTargetUsage.DiscardContents);
    RenderTarget2D defaultTarget = device.GetRenderTarget(0);

    device.SetRenderTarget(0, renderTarget);
    device.Clear(ClearOptions.Target, Color.Transparent, 0, 0);

    // perform rendering to back buffer
    ...

    device.SetRenderTarget(0, (RenderTarget2D)defaultTarget);
    renderTarget.GetTexture().GenerateMipMaps(); // doesn't do anything.
    renderTarget.GetTexture().Save@("C:\foo.dds", ImageFileFormat.Dds); // this produces the attached image
    renderTarget.Dispose();


  • 12-26-2007 4:53 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Wow, that's pretty funky!

    Mipmap creation should happen automatically when you finish drawing to the rendertarget.

    What graphics card is this? What is the size and format of your target?
    XNA Framework Developer - blog - homepage
  • 12-26-2007 5:57 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Width 512, Height 256, Mipmap chain 0, SurfaceFormat.Color, RenderTarget.DiscardContents. We're seeing it on GeForce 7800 GO only. We notice that the 8600 GO does not do this. Shawn, if you have any questions please let me know. Also, I am not getting any warnings/errors from DirectX debug spew.
  • 12-26-2007 6:18 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    This looks like a bug we ran into internally as well, on that era of GeForce cards. It's an NVidia driver problem: apparently they don't implement StretchRect properly, even though the caps claim it is supported, and the call doesn't return any errors to us. Unfortunately we couldn't find any way to work around it.
    XNA Framework Developer - blog - homepage
  • 12-27-2007 6:39 AM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Shawn, as a heads up here, upgrading to the latest NVidia drivers does not resolve the problem. What do we typically do when we find a bug in the device driver implementation? Do I contact NVidia so that they can be aware of it? On our side of things we'll implement a check for these cards (NVidia 7* series).
  • 12-27-2007 1:04 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Good question... it's probably a good idea to contact NVidia but I don't know how you would do that.
    XNA Framework Developer - blog - homepage
  • 01-09-2008 1:07 AM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Sorry to repoen such an old thread..

    But I've run into the exact same problem.

     

    HOWEVER,

    the direct3D debugger possibly reveals the problem:

     

    [285268] Direct3D9: (ERROR) :GenerateMipSublevels called on non-autogenerated mipmap

    So I'm guessing D3DUSAGE_AUTOGENMIPMAP isn't being set? I had a look with reflector and as far as I can tell, the render target surface is being created with CreateRenderTarget(), but (as far as I remember - it's been a while since I've used native DX :) the only way to create a mipmapped render target is using CreateTexture() with D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP as the usage. (at least, this is as far as I could tell :-)

  • 01-12-2008 7:15 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Is there a way I can tell what kind of card is being used so that I can change the mip map behavior accordingly to work around this behavior? StatusUnknown, if I understand what you are saying, this is an error in the XNA implementation?
  • 01-14-2008 1:46 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    GraphicsAdapter.VendorId and DeviceId are the best way to detect specific hardware.

    People sometimes think they can parse the GraphicsAdapter name strings to identify the manufacturer, but that isn't robust because different drivers or languages may modify the string to anything they like. The strings are only intended for display to the user, while the *Id properties are mapped through directly from the underlying hardware identifiers, so can reliably identify specific chipsets.

    The hard part is getting a comprehensive list of all the PCI device IDs used by a particular manufacturer. There are often hundreds of these, for instance in MotoGP I had a list of 61 different IDs used by ATI for variants of their Rage series cards. pcidatabase.com is a good place to start looking.
    XNA Framework Developer - blog - homepage
  • 01-14-2008 1:48 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    I'm not sure whether the error StatusUnknown is seeing is causing the problem, or just a symptom of it (if this is the same issue we ran into before, I have a vague memory that we got sent down the wrong code path because the driver reported some incorrect caps, or returned a success code from a method that actually failed, or something confusing like that). We'll take a look in more detail sometime before our next release.
    XNA Framework Developer - blog - homepage
  • 01-16-2008 8:30 AM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    Thank-you for the help Shawn! We'll use the *Id property to side-step this behavior on NVidia cards.
  • 02-04-2008 7:28 AM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    With mipmapping enabled the distant grass here would look SO much better. ;) (anxiously awaits fix)...
  • 02-04-2008 5:01 PM In reply to

    Re: RenderTarget2D Mipmapping Behavior

    <<< anxiously awaits demo of above post ^^^
    XNA QuickStart Engine | My site
    "I'll be whatever I want to do!", Philip J. Fry
  • 04-3