Sign in to follow this  
GoodFun

[SlimDX] Problem creating many large textures in DirectX 10

Recommended Posts

GoodFun    218
Hi there, I come to you guys again with a fairly crazy issue... my project is always teetering on the insane and this one isn't any different... first of all, it's not a game and it's not for public consumption (at least not directly). First, this is the hardware it's going to run on: Dual Quad Core Nehalem 5550 2.66GHz 48GB Ram eVGA GTS 250 1GB Supercharged So, here is my dilemma... I need to create daily textures for two years, i.e. 732 textures. They are all 4096 x 4096 in size and use R16_Float format. Texturesize per texture is 32 megs, total size needed about 23 gigs... now if I start creating those textures, I get an out of memory error after 56 textures. That is only 1792Megs and way below the available texture memory. I started playing around with the code a bit and checked different texture sizes. Doing that I found that if the textures are 16 megs each, I can easily create 732 textures, I can even create double as many, i.e. 1464 without the software running out of memory... This leads me to believe that there might be an issue in the nVidia driver with textures that are larger than 16 megs. If I absolutely have to, I can use two textures of 4096 x 2048 but I'm worried that I might see some artifacts at the seam between the two, i.e. uneven smoothing. I was wondering if any of you have had issues creating large numbers of large size textures in DirectX 10... or if you guys are aware of any such limitation... btw, I'm using C# 2008, SlimDX March 2009, DirectX SDK March 2009 and DirectX 10. Here is a small code sample that shows the problem:
using SlimDX;
using D3D10 = SlimDX.Direct3D10;
using DXGI = SlimDX.DXGI;
 
struct TextureContainer
{
    public D3D10.Texture2D texture;
    public D3D10.ShaderResourceView textureView;
}
 
private void button1_Click(object sender, EventArgs e)
{
    List<TextureContainer> textureContainerList = new List<TextureContainer>();
 
    int textureWidth = 4096; // example, this would come from an input parameter
    int textureHeight = 4096;
 
    Half[] data = new Half[textureWidth * textureHeight];
 
    DXGI.SampleDescription sampleDescription = new DXGI.SampleDescription();
    sampleDescription.Count = 1;
    sampleDescription.Quality = 0;
 
    D3D10.Texture2DDescription dataTextureDescription = new D3D10.Texture2DDescription();
    dataTextureDescription.Width = textureWidth;
    dataTextureDescription.Height = textureHeight;
    dataTextureDescription.ArraySize = 1;
    dataTextureDescription.MipLevels = 1;
    dataTextureDescription.SampleDescription = sampleDescription;
    dataTextureDescription.Format = DXGI.Format.R16_Float;
    dataTextureDescription.CpuAccessFlags = D3D10.CpuAccessFlags.Write;
    dataTextureDescription.BindFlags = D3D10.BindFlags.ShaderResource;
    dataTextureDescription.Usage = D3D10.ResourceUsage.Dynamic;
 
    int count = 0;
    try
    {
        for (int i = 0; i < 732; i++)
        {
            TextureContainer textureContainer = new TextureContainer();
 
            textureContainer.texture = new D3D10.Texture2D(RenderingDevice.Device, dataTextureDescription);
 
            DataRectangle textureData = textureContainer.texture.Map(0, D3D10.MapMode.WriteDiscard, D3D10.MapFlags.None);
 
            try
            {
                textureData.Data.WriteRange<Half>(data, 0, textureWidth * textureHeight);
            }
            catch (Exception ex)
            {
                throw new Exception("CreateTexture: Error in texture creation logic.", ex);
            }
            finally
            {
                textureContainer.texture.Unmap(0);
            }
                    
            textureContainer.textureView = new D3D10.ShaderResourceView(RenderingDevice.Device, textureContainer.texture);
            textureContainerList.Add(textureContainer);
            count++;
        }
    }
    catch
    {
        MessageBox.Show("Error creating texture " + count.ToString());
    }
}

Share this post


Link to post
Share on other sites
Adam_42    3629
If you're not using a 64-bit operating system you'll hit the 2GB address space limit very quickly. Also make sure your program is set up as x64.

If that doesn't work (the driver or runtime may not let you use that much memory) then you'll need to use a caching scheme to leave some of the textures in memory instead of created as D3D textures.

Share this post


Link to post
Share on other sites
GoodFun    218
I am using Vista and Windows 7 64bit... and as I've said, I can create enough 16 meg textures, only the 32meg and above show this issue... In my tests today, I created 3000 16meg textures without a problem.

Here is what I'm seeing, pay attention to the last line, that one makes no sense what so ever:
on a Windows 7 64bit computer with 48 Gigs of RAM, I can create:

3000 x 16 meg textures, no error, total memory used: 48 gigs
56 x 32 meg textures, out of memory error, total memory used: 1,792 meg
56 x 64 meg textures, out of memory error, total memory used: 3,584 meg
56 x 128 meg textures, out of memory error, total memory used: 7,168 meg
112 x 256 meg textures, out of memory error, total memory used: 28,672 meg

so I can create double as many 256 meg textures than 128 meg textures, that makes no sense, and none of the textures above 16 megs actually fill up my physical memory completely while the 16 meg textures actually continue after 3000 with the computer starting to swap...

Anyways, I do believe this is a bug in the memory management of the nVidia driver and I probably have to file it with them unless someone has an idea on what I might be missing.

I was able to rewrite the project to use multiple 16 meg textures instead of a single 64 meg texture, but it's not very elegant to do this...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this