[Mesa-users] Problem with ARB_copy_buffer on Mesa 9.2.4
Jonas Kulla
nyocurio at gmail.com
Tue May 6 04:40:06 PDT 2014
Hello list,
after about 3 days of debugging, I was able to isolate a rather weird
behavior in Mesa GL.
The gist of it is the following: When I create a buffer object and allocate
uninitilaized
memory for it (glBufferData() with nullptr as 'data'),
then glCopyBufferSubData() data into
it from another buffer object, then subsequently fill a part of it with
glBufferSubData(),
this new data isn't visible to the buffer object. In fact, it seems that
the SubData'ed bytes
are completely lost. Any further data uploads however work as expected. I
will attach
a small C test case below that demonstrates this behavior.
I realize that I am working with an old Mesa release (on Fedora 19), but
I'm afraid of
upgrading my system to the newest distro release as I might break my
working environment.
That's why I would like to kindly ask if someone could verify that this
problem still persists
on the newest Mesa code, in which case I would go ahead and file a bug
report. At the
same time, maybe someone could spot a critical mistake in my code that
would explain
this strange behavior I'm seeing. I think the code paths I'm hitting here
in the driver are
sufficiently obscure though.
I should probably mention that my card is a Mobility Radeon HD 3650 (ie.
r600).
Here's the code sample (you can replace the GL setup code with your own):
#include <stdlib.h>
#include <string.h>
#include <GL/glew.h>
#include <SDL2/SDL.h>
static SDL_Window *win;
static SDL_GLContext *ctx;
void setupGL()
{
SDL_Init(SDL_INIT_VIDEO);
win = SDL_CreateWindow("CopyBufferBug", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 64, 64, SDL_WINDOW_OPENGL);
ctx = SDL_GL_CreateContext(win);
glewInit();
}
static void teardownGL()
{
SDL_GL_DeleteContext(ctx);
SDL_DestroyWindow(win);
SDL_Quit();
}
int main(int argc, char *argv[])
{
setupGL();
/* These don't matter I think */
#define BLOCK_SIZE 128
#define BUFFER1_SIZE BLOCK_SIZE
#define BUFFER2_SIZE BLOCK_SIZE
#define BUFFER1_TARGET GL_COPY_READ_BUFFER
#define BUFFER2_TARGET GL_COPY_WRITE_BUFFER
#define BUFFER1_USAGE GL_DYNAMIC_DRAW
#define BUFFER2_USAGE GL_DYNAMIC_DRAW
GLuint buffers[2];
glGenBuffers(2, buffers);
/* We allocate both buffers with undefined memory */
glBindBuffer(BUFFER1_TARGET, buffers[0]);
glBufferData(BUFFER1_TARGET, BUFFER1_SIZE, 0, BUFFER1_USAGE);
glBindBuffer(BUFFER2_TARGET, buffers[1]);
glBufferData(BUFFER2_TARGET, BUFFER2_SIZE, 0, BUFFER2_USAGE);
/* Then copy (undefined) bytes from the first into the second
buffer */
/* Note: If I comment this line out, everything works */
glCopyBufferSubData(BUFFER1_TARGET, BUFFER2_TARGET, 0, 0,
BUFFER1_SIZE);
/* Generate random string */
FILE *rand = fopen("/dev/urandom", "r");
char data[BLOCK_SIZE];
fread(data, 1, sizeof(data), rand);
fclose(rand);
/* We fill the second buffer with defined data */
/* Note: If I execute this call twice (just copy paste the line),
everything works */
glBufferSubData(BUFFER2_TARGET, 0, sizeof(data), data);
/* Then download it again to compare its contents against our test
string */
char data2[BLOCK_SIZE];
glGetBufferSubData(BUFFER2_TARGET, 0, sizeof(data2), data2);
if (memcmp(data, data2, sizeof(data)))
printf("Data does NOT match up!\n");
else
printf("Data matches.\n");
glDeleteBuffers(2, buffers);
teardownGL();
return 0;
}
Thank you very much for your time.
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-users/attachments/20140506/e8e1dd8b/attachment.html>
More information about the mesa-users
mailing list