2 * Copyright (c) 2021 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 /* Simple test to reproduce this buffer reference counting issue:
25 * https://gitlab.freedesktop.org/mesa/mesa/-/issues/4259
30 #include "piglit-util-gl.h"
31 #include "piglit-glx-util.h"
33 int piglit_width
= 50, piglit_height
= 50;
36 main(int argc
, char **argv
)
41 Display
*dpy
= XOpenDisplay(NULL
);
43 fprintf(stderr
, "couldn't open display\n");
44 piglit_report_result(PIGLIT_FAIL
);
46 XVisualInfo
*visinfo
= piglit_get_glx_visual(dpy
);
47 Window win
= piglit_get_glx_window(dpy
, visinfo
);
49 GLXContext ctx1
= piglit_get_glx_context_share(dpy
, visinfo
, NULL
);
50 GLXContext ctx2
= piglit_get_glx_context_share(dpy
, visinfo
, ctx1
);
52 glXMakeCurrent(dpy
, win
, ctx1
);
53 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
55 piglit_require_extension("GL_ARB_uniform_buffer_object");
58 glCreateBuffers(2, buf
);
59 glBindBufferBase(GL_UNIFORM_BUFFER
, 0, buf
[0]);
60 glBindBufferBase(GL_UNIFORM_BUFFER
, 1, buf
[1]);
62 glXMakeCurrent(dpy
, win
, ctx2
);
63 glDeleteBuffers(1, &buf
[1]);
65 glXMakeCurrent(dpy
, win
, ctx1
);
66 glDeleteBuffers(1, &buf
[0]); /* This shouldn't crash. */
68 glXDestroyContext(dpy
, ctx1
);
69 glXDestroyContext(dpy
, ctx2
);
71 piglit_report_result(PIGLIT_PASS
);