aminejelliti's picture

GL.TexImage3D + Out Of Memory

I noticed that when I load my 3D texture with an array or Intptr ( shor or ushort source) I've seen that Memory is duplicated at the moment when
i call GL.TexImage3D and descends after to its level , and this causes an outofmemory when my graphic card supports 1Go of memory and i have this problem
when trying to load about 400 Mo : an ushort array 841 *841 *290 .
did openTk create a copy of the memoryzone to pass it to GPU or is there any other logic explication
Morevoer i have later amemory access viloation exception when trying to reload a 3d texture with the same type of data ( ushort array) even with array of 841*841*1

Thanks


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
FingersLingers's picture

There could be many reasons to get mem out errors, Open TK does not duplicate the passed array if you use references, interop might, but thats another story, Another factor is what Storage you are telling OpenGL to store the image as well, I can load a 100K array as bytes and GL can store it at over ten times that if it's told to.

Can you be a bit more specific on the formats you are loading in at and what formats you are instructing gl to store it as....

:D

aminejelliti's picture

GL.GenTextures(1, out _texture);
GL.BindTexture(TextureTarget.Texture3D, _texture);

GL.TexImage3D
(
TextureTarget.Texture3D,
0,
PixelInternalFormat.Luminance16,
XSize, //size X
YSize, //size Y
ZSize, //size Z
0, //niveau de MIPMA
OpenTK.Graphics.OpenGL.PixelFormat.Luminance,
PixelType.UnsignedShort,
Bufferushort //Bufferushort is ushort[841*841*290]

);

GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

ErrorCode Er = GL.GetError();

if (Er == ErrorCode.OutOfMemory)
{

}

I've done a test with a texture of 184Mo (512*512*358) *2 (it's an short array)

Before creating my buffer , my procces toke 128 Mo
after creation of my buffer 312 Mo

just after GL.TexImage3D 496 Mo
and then 312 Mo (without any action)
and then when dispose my array of short 131 Mo

Note that with this size of memory it works , problems begans when i reach 350Mo

Hope this will help

thanks

FingersLingers's picture

Ouch, Too big for my card ..... but this may help you.

on mine, believe it or mot, 840*840*290 loads, just fits in.

I get no memory sluctuation while loading the GLTexture3D, memory remain a constant 400+Mb.

Try this out.

int mSize; // Maximum Texture Buffer Size
GL.GetInteger(GetPName.MaxTextureBufferSize, out mSize); // For me this is 134217728 or 512^3

if i set my buffer size to exactly that, it loads, a little leeway over will still load, and then thats it.

Sry I couldn't help more :D

aminejelliti's picture

In wich verssion do you get GetPName.MaxTextureBufferSize ?
I've no acces to this extention in my opentk version

FingersLingers's picture

The latest Binary should have it, however I'm using the source snap of 15 March 2012, with a few modifications to math library (I use a Matrix3 and vec2i, and a few other things I need to interface to the Physics library i use). After a bit more testing it looks like the value on my machine is at 24 bit depth, so I can load my buffer to 150% that max value.

Hope it helps :D

Inertia's picture

Just a quick note to avoid confusion: the token MaxTextureBufferSize belongs to the Texture Buffer Objects Extension, according to the Texture 3D Spec the token you're looking for is MAX_3D_TEXTURE_SIZE_EXT.

You are on the right track though, OpenTK does not make any copy when pinning Memory. (The OpenGL Driver may do a copy, but OpenTK does not.)