Allocating contiguous memory from userland


ptitSeb

Serial Porter
Joined
Aug 15, 2012
Messages
9,330
Age
51
Location
France, near Lyon
I'm trying to use the eglCreatePixmapSurface function. For that, I need to allocate a NATIVE_PIXMAP_BUFFER that is Contiguous, and I need the Physical adress of that Memory.

On TI samples, they use the CMEM driver, but I don't think it's installed by default on Pandora now.

I wanted to use CMA, with some dma_alloc_*, but it seems it's Kernel only.

Is there some way, for a usermode program, to allocate contiguous memory, by using some CMA function, or using bsp's dsp module maybe?
 
Isn't NativePixmapType just an X11 Pixmap? What exactly are you doing and why do you think you need a block of memory with contiguous physical addresses and where do you think you need to supply that physical address?
 
Isn't NativePixmapType just an X11 Pixmap? What exactly are you doing and why do you think you need a block of memory with contiguous physical addresses and where do you think you need to supply that physical address?
I looked at the samples from TI, the sgxperf_gles20_vg.cpp (or sgxperf_gles11_vg.cpp, they look the same).

I'm trying to find ways to upload texture in memory faster, and a way to read back things to (other the glReadPixel).

The NATIVE_PIXMAP seems the best way.

But if read the sources file correctly:

Code:
EGLint pi32ConfigAttribs[5];
pi32ConfigAttribs[0] = EGL_SURFACE_TYPE;
pi32ConfigAttribs[1] = EGL_WINDOW_BIT | EGL_PIXMAP_BIT;
pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE;
if(testID == 9)
pi32ConfigAttribs[3] = EGL_OPENVG_BIT;
else
pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT;
pi32ConfigAttribs[4] = EGL_NONE;
 
int iConfigs;
if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))
{
SGX_PERF_ERR_printf("Error: eglChooseConfig() failed.\n");
return 1;
}
if(surfaceType == SGXPERF_SURFACE_TYPE_WINDOW)
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (void*) NULL, NULL);
else if(surfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16)
{
common_create_native_pixmap(SGXPERF_RGB565, 
inTextureWidth, inTextureHeight, pNativePixmapPtr);
eglSurface = eglCreatePixmapSurface(eglDisplay, eglConfig, *pNativePixmapPtr, NULL);
}
else if(surfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32)
{
common_create_native_pixmap(SGXPERF_ARGB8888, 
inTextureWidth, inTextureHeight, pNativePixmapPtr);
eglSurface = eglCreatePixmapSurface(eglDisplay, eglConfig, *pNativePixmapPtr, NULL);
}
 

Is the part that create the eglSurface...

It calls the function common_create_native_pixmap that is:


Code:
void common_create_native_pixmap(
unsigned long pixmapFormat,
unsigned long pixmapwidth,
unsigned long pixmapHeight,
NATIVE_PIXMAP_STRUCT **pNativePixmapPtr
)
{
#ifdef _ENABLE_CMEM
//The cmem module should be inserted before running this application
//Create a contiguous buffer of required size for texture, and get userspace address
*pNativePixmapPtr = (NATIVE_PIXMAP_STRUCT*)malloc(sizeof(NATIVE_PIXMAP_STRUCT));
 
  if(pixmapFormat == SGXPERF_RGB565)
    (*pNativePixmapPtr)->ePixelFormat = 0;
  else if(pixmapFormat == SGXPERF_ARGB8888)
    (*pNativePixmapPtr)->ePixelFormat = 2;
  else           
  {  
SGX_PERF_ERR_printf("Invalid pixmap format type %ld\n", pixmapFormat);
exit(-1);
  }
    (*pNativePixmapPtr)->eRotation = 0;
    (*pNativePixmapPtr)->lWidth = pixmapwidth;//480;
    (*pNativePixmapPtr)->lHeight = pixmapHeight;//640; 
if(pixmapFormat == SGXPERF_RGB565)    
(*pNativePixmapPtr)->lStride = (*pNativePixmapPtr)->lWidth* 16/8; //bitwidth/8
else if(pixmapFormat == SGXPERF_ARGB8888)
(*pNativePixmapPtr)->lStride = (*pNativePixmapPtr)->lWidth* 32/8; //bitwidth/8
    (*pNativePixmapPtr)->lSizeInBytes = (*pNativePixmapPtr)->lHeight * (*pNativePixmapPtr)->lStride;
    (*pNativePixmapPtr)->lAddress = (long) CMEM_alloc((*pNativePixmapPtr)->lSizeInBytes, NULL);
if(!(*pNativePixmapPtr)->lAddress)
{
SGX_PERF_ERR_printf("CMEM_alloc returned NULL\n");
exit(-1);
}
    //Get the physical page corresponding to the above cmem buffer
    (*pNativePixmapPtr)->pvAddress = CMEM_getPhys((void*)(*pNativePixmapPtr)->lAddress);
SGX_PERF_printf("Physical address = %x\n", (*pNativePixmapPtr)->pvAddress);
if((*pNativePixmapPtr)->pvAddress & 0xFFF)
SGX_PERF_printf("PVR2DMemWrap may have issues with this non-aligned address!\n");
#endif
}
 

So, that's why...
 
Hmm I really doubt eglCreatePixmapSurface() will work with our SGX driver. You can try to feed it fake physical address first, give it something like 0x81000000 and see if it returns an error. This may crash the system though.

Currently easiest way to get physical contiguous memory on pandora is through c64_tools.

There is also this TI texture streaming thing, maybe it can do what you want?

http://processors.wiki.ti.com/index.php/OpenGLES_Texture_Streaming_-_bc-cat_User_Guide
 
If you allocated memory from fbdev that should be contiguous in physical memory too, right? But I don't know how you'd get the physical address...
 
Hmm I really doubt eglCreatePixmapSurface() will work with our SGX driver. You can try to feed it fake physical address first, give it something like 0x81000000 and see if it returns an error. This may crash the system though.

Currently easiest way to get physical contiguous memory on pandora is through c64_tools.
Yes, I started looking at that. I'll probably try some experiment with that to see if it's viable to create a Pixmap surface befaore starting some new kernel module...
There is also this TI texture streaming thing, maybe it can do what you want?

http://processors.wiki.ti.com/index.php/OpenGLES_Texture_Streaming_-_bc-cat_User_Guide
Sounds interesting. Now sure on how to use it yet, so I'll probably have to do some simple experiments too.
 
I tried the bc-cat driver.

Got the test sample (from v0.1) compiled but I just get a "ERROR: BCIOREQ_BUFFERS failed".

Not sure how bc-cat get it's memory, but it seems it doesn't have any in the version on the last firmware? I have to dig a bit more (and try maybe v0.2 version).

*EDIT* It works with v0.2 :) So I guess I have a simple way, with bc-cat, to get texture memory that is contiguous and with a physical address 
 
Last edited by a moderator:
Nice, if you're going to release something with it, we need to include bc_cat into official firmware, otherwise your pnd will break on next kernel update.

We also need to add module loader script so that your pnd doesn't have to run as root needlessly.
 
I tried the bc-cat driver.

Got the test sample (from v0.1) compiled but I just get a "ERROR: BCIOREQ_BUFFERS failed".

Not sure how bc-cat get it's memory, but it seems it doesn't have any in the version on the last firmware? I have to dig a bit more (and try maybe v0.2 version).

*EDIT* It works with v0.2 :) So I guess I have a simple way, with bc-cat, to get texture memory that is contiguous and with a physical address 
Soo does this mean Mupen will be faster again? ;)
 
I tried the bc-cat driver.

Got the test sample (from v0.1) compiled but I just get a "ERROR: BCIOREQ_BUFFERS failed".

Not sure how bc-cat get it's memory, but it seems it doesn't have any in the version on the last firmware? I have to dig a bit more (and try maybe v0.2 version).

*EDIT* It works with v0.2 :) So I guess I have a simple way, with bc-cat, to get texture memory that is contiguous and with a physical address 
Soo does this mean Mupen will be faster again? ;)
Ah muppen, I'm not sure if I can use it there (maybe but not sure at all), but XBMC, yeah, I have to work on that.
 
bc-cat driver is include in current firmware.

And the demo app is working (at least on my Gigahertz model).
It's not included with the default driver though, it will only appear after some non-default driver is selected with driver changer pnd. I guess I'll need to fix that..
 
Back
Top