1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
// SPDX-License-Identifier: GPL-2.0 OR MIT
/**********************************************************
* Copyright 2021-2022 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************/
#include "igt_vmwgfx.h"
IGT_TEST_DESCRIPTION("Test surface copies.");
/**
* Compares two 2d surfaces to see if their size and contents are equal.
*/
static bool are_surfaces_identical(int fd, struct vmw_surface *s1,
struct vmw_surface *s2)
{
struct vmw_mob mob1 = { .size = s1->base.buffer_size,
.handle = s1->base.buffer_handle,
.map_handle = s1->base.buffer_map_handle };
struct vmw_mob mob2 = { .size = s2->base.buffer_size,
.handle = s2->base.buffer_handle,
.map_handle = s2->base.buffer_map_handle };
char *readback1;
char *readback2;
bool is_equal = true;
uint32 i, j;
uint32 stride1, stride2, height, width;
if ((s1->params.base.base_size.width !=
s2->params.base.base_size.width) ||
(s1->params.base.base_size.height !=
s2->params.base.base_size.height)) {
return false;
}
width = s1->params.base.base_size.width;
height = s1->params.base.base_size.height;
stride1 = s1->params.buffer_byte_stride == 0 ?
width :
s1->params.buffer_byte_stride;
stride2 = s2->params.buffer_byte_stride == 0 ?
width :
s2->params.buffer_byte_stride;
readback1 = vmw_ioctl_mob_map(fd, &mob1);
readback2 = vmw_ioctl_mob_map(fd, &mob2);
for (i = 0; i < width; i++) {
for (j = 0; j < height; j++) {
if (readback1[j * stride1 + i] !=
readback2[j * stride2 + i]) {
is_equal = false;
goto are_surfaces_identical_end;
}
}
}
are_surfaces_identical_end:
vmw_ioctl_mob_unmap(&mob1);
vmw_ioctl_mob_unmap(&mob2);
return is_equal;
}
static void set_surface_value(int fd, struct vmw_surface *surface, char value)
{
struct vmw_mob mob = { .size = surface->base.buffer_size,
.handle = surface->base.buffer_handle,
.map_handle = surface->base.buffer_map_handle };
char *readback;
readback = vmw_ioctl_mob_map(fd, &mob);
memset(readback, value, mob.size);
vmw_ioctl_mob_unmap(&mob);
}
static void exec_surface_copy(struct vmw_execbuf *cmd_buf,
struct drm_vmw_fence_rep *cmd_fence,
SVGA3dSurfaceImageId src,
SVGA3dSurfaceImageId dest, SVGA3dCopyBox *box)
{
vmw_cmd_surface_copy(cmd_buf, src, dest, box, 1);
vmw_execbuf_submit(cmd_buf, cmd_fence);
vmw_ioctl_fence_finish(cmd_buf->drm_fd, cmd_fence);
}
static void test_invalid_copies(int fd, int32 cid)
{
struct vmw_surface *s1;
struct vmw_surface *s2;
struct vmw_execbuf *cmd_buf;
struct drm_vmw_fence_rep cmd_fence;
SVGA3dSize surface_size;
SVGA3dCopyBox box;
SVGA3dSurfaceImageId src;
SVGA3dSurfaceImageId dest;
SVGA3dSurfaceImageId bad_surface;
surface_size.width = 128;
surface_size.height = 128;
surface_size.depth = 1;
igt_require(
vmw_is_format_supported(fd, SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8));
s1 = vmw_create_surface_simple(fd, 0, SVGA3D_A8R8G8B8, surface_size,
SVGA3D_INVALID_ID);
s2 = vmw_create_surface_simple(fd, 0, SVGA3D_A8R8G8B8, surface_size,
SVGA3D_INVALID_ID);
cmd_buf = vmw_execbuf_create(fd, cid);
box.x = 0;
box.y = 0;
box.z = 0;
box.w = 1;
box.h = 1;
box.d = 1;
box.srcx = 0;
box.srcy = 0;
box.srcz = 0;
src.sid = s1->base.handle;
src.face = 0;
src.mipmap = 0;
dest.sid = s2->base.handle;
dest.face = 0;
dest.mipmap = 0;
/* Testing a valid copy first */
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(are_surfaces_identical(fd, s1, s2));
/* Setting surfaces to different values */
set_surface_value(fd, s1, 0);
set_surface_value(fd, s2, 16);
/* Testing invalid copies */
/* x */
box.x = 129;
box.w = 1;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.x = 0;
box.w = 129;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.srcx = 129;
box.w = 1;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.srcx = 0;
box.w = 129;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
/* y */
box.y = 129;
box.h = 1;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.y = 0;
box.h = 129;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.srcy = 129;
box.h = 1;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.srcy = 0;
box.h = 129;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
/* z */
box.z = 2;
box.d = 1;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.z = 0;
box.d = 2;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.srcz = 2;
box.d = 1;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
box.srcz = 0;
box.d = 2;
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
/* Invalid surface id */
bad_surface.sid = src.sid + dest.sid + 1;
bad_surface.face = 0;
bad_surface.mipmap = 0;
box.x = 0;
box.y = 0;
box.z = 0;
box.w = 1;
box.h = 1;
box.d = 1;
box.srcx = 0;
box.srcy = 0;
box.srcz = 0;
vmw_cmd_surface_copy(cmd_buf, bad_surface, dest, &box, 1);
igt_assert(vmw_execbuf_submit(cmd_buf, &cmd_fence) != 0);
vmw_cmd_surface_copy(cmd_buf, src, bad_surface, &box, 1);
igt_assert(vmw_execbuf_submit(cmd_buf, &cmd_fence) != 0);
vmw_ioctl_fence_finish(fd, &cmd_fence);
bad_surface.sid = src.sid;
bad_surface.face = 2;
exec_surface_copy(cmd_buf, &cmd_fence, bad_surface, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
exec_surface_copy(cmd_buf, &cmd_fence, src, bad_surface, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
vmw_execbuf_destroy(cmd_buf);
vmw_ioctl_surface_unref(fd, s1);
vmw_ioctl_surface_unref(fd, s2);
}
static void test_invalid_copies_3d(int fd, int32 cid)
{
struct vmw_surface *s1;
struct vmw_surface *s2;
struct vmw_execbuf *cmd_buf;
struct drm_vmw_fence_rep cmd_fence;
SVGA3dSize surface_size;
SVGA3dCopyBox box;
SVGA3dSurfaceImageId src;
SVGA3dSurfaceImageId dest;
surface_size.width = 128;
surface_size.height = 128;
surface_size.depth = 1;
igt_require(
vmw_is_format_supported(fd, SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8));
igt_require(vmw_is_format_supported(fd, SVGA3D_DEVCAP_DXFMT_Z_D32));
s1 = vmw_create_surface_simple(fd, 0, SVGA3D_A8R8G8B8, surface_size,
SVGA3D_INVALID_ID);
s2 = vmw_create_surface_simple(fd, 0, SVGA3D_Z_D32, surface_size, SVGA3D_INVALID_ID);
cmd_buf = vmw_execbuf_create(fd, cid);
box.x = 0;
box.y = 0;
box.z = 0;
box.w = 10;
box.h = 10;
box.d = 10;
box.srcx = 0;
box.srcy = 0;
box.srcz = 0;
src.sid = s1->base.handle;
src.face = 0;
src.mipmap = 0;
dest.sid = s2->base.handle;
dest.face = 0;
dest.mipmap = 0;
set_surface_value(fd, s1, 0);
set_surface_value(fd, s2, 16);
exec_surface_copy(cmd_buf, &cmd_fence, src, dest, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
exec_surface_copy(cmd_buf, &cmd_fence, dest, src, &box);
igt_assert(!are_surfaces_identical(fd, s1, s2));
vmw_execbuf_destroy(cmd_buf);
vmw_ioctl_surface_unref(fd, s1);
vmw_ioctl_surface_unref(fd, s2);
}
igt_main
{
int fd;
int32 cid;
igt_fixture
{
fd = drm_open_driver_render(DRIVER_VMWGFX);
igt_require(fd != -1);
cid = vmw_ioctl_context_create(fd);
igt_require(cid != SVGA3D_INVALID_ID);
}
igt_describe("Test surface copies (valid and invalid ones).");
igt_subtest("test_invalid_copies")
{
test_invalid_copies(fd, cid);
}
igt_describe("Test surface copies on 3D enabled contexts.");
igt_subtest("test_invalid_copies_3d")
{
igt_require(vmw_ioctl_get_param(fd, DRM_VMW_PARAM_3D));
test_invalid_copies_3d(fd, cid);
}
igt_fixture
{
vmw_ioctl_context_destroy(fd, cid);
drm_close_driver(fd);
}
}
|