diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2019-01-29 11:08:07 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2019-01-29 11:08:07 +0000 |
commit | 6b139c2063623e9310025247cd966490b9aa57ea (patch) | |
tree | 375acfd898ca3d721250aa17291bbb90a8d7250a /lib/mesa/src/gallium/winsys/virgl | |
parent | cce99579dcfb1d54c54cff65573be3430e77f2c5 (diff) |
Import Mesa 18.3.2
Diffstat (limited to 'lib/mesa/src/gallium/winsys/virgl')
7 files changed, 311 insertions, 18 deletions
diff --git a/lib/mesa/src/gallium/winsys/virgl/drm/Makefile.am b/lib/mesa/src/gallium/winsys/virgl/drm/Makefile.am index 2473b88ad..e543227e3 100644 --- a/lib/mesa/src/gallium/winsys/virgl/drm/Makefile.am +++ b/lib/mesa/src/gallium/winsys/virgl/drm/Makefile.am @@ -31,3 +31,5 @@ AM_CFLAGS = \ noinst_LTLIBRARIES = libvirgldrm.la libvirgldrm_la_SOURCES = $(C_SOURCES) + +EXTRA_DIST = meson.build diff --git a/lib/mesa/src/gallium/winsys/virgl/drm/meson.build b/lib/mesa/src/gallium/winsys/virgl/drm/meson.build new file mode 100644 index 000000000..89626e786 --- /dev/null +++ b/lib/mesa/src/gallium/winsys/virgl/drm/meson.build @@ -0,0 +1,27 @@ +# Copyright © 2017 Intel Corporation + +# 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. + +libvirgldrm = static_library( + 'virgldrm', + 'virgl_drm_winsys.c', + c_args : c_vis_args, + include_directories : [inc_common, inc_gallium_drivers], + dependencies : dep_libdrm, +) diff --git a/lib/mesa/src/gallium/winsys/virgl/drm/virtgpu_drm.h b/lib/mesa/src/gallium/winsys/virgl/drm/virtgpu_drm.h index 30bc3afdd..8596febe9 100644 --- a/lib/mesa/src/gallium/winsys/virgl/drm/virtgpu_drm.h +++ b/lib/mesa/src/gallium/winsys/virgl/drm/virtgpu_drm.h @@ -60,6 +60,7 @@ struct drm_virtgpu_execbuffer { }; #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */ +#define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2 struct drm_virtgpu_getparam { uint64_t param; diff --git a/lib/mesa/src/gallium/winsys/virgl/vtest/Makefile.am b/lib/mesa/src/gallium/winsys/virgl/vtest/Makefile.am index b15a3afd6..0a31477a1 100644 --- a/lib/mesa/src/gallium/winsys/virgl/vtest/Makefile.am +++ b/lib/mesa/src/gallium/winsys/virgl/vtest/Makefile.am @@ -30,3 +30,5 @@ AM_CFLAGS = \ noinst_LTLIBRARIES = libvirglvtest.la libvirglvtest_la_SOURCES = $(C_SOURCES) + +EXTRA_DIST = meson.build diff --git a/lib/mesa/src/gallium/winsys/virgl/vtest/meson.build b/lib/mesa/src/gallium/winsys/virgl/vtest/meson.build new file mode 100644 index 000000000..319bc8e24 --- /dev/null +++ b/lib/mesa/src/gallium/winsys/virgl/vtest/meson.build @@ -0,0 +1,26 @@ +# Copyright © 2017 Intel Corporation + +# 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. + +libvirglvtest = static_library( + 'virglvtest', + ['virgl_vtest_socket.c', 'virgl_vtest_winsys.c'], + c_args : c_vis_args, + include_directories : [inc_common, inc_gallium_drivers], +) diff --git a/lib/mesa/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c b/lib/mesa/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c index 4541419d8..ff69accf5 100644 --- a/lib/mesa/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c +++ b/lib/mesa/src/gallium/winsys/virgl/vtest/virgl_vtest_socket.c @@ -101,6 +101,57 @@ static int virgl_vtest_send_init(struct virgl_vtest_winsys *vws) return 0; } +static int virgl_vtest_negotiate_version(struct virgl_vtest_winsys *vws) +{ + uint32_t vtest_hdr[VTEST_HDR_SIZE]; + uint32_t version_buf[VCMD_PROTOCOL_VERSION_SIZE]; + uint32_t busy_wait_buf[VCMD_BUSY_WAIT_SIZE]; + uint32_t busy_wait_result[1]; + int ret; + + vtest_hdr[VTEST_CMD_LEN] = VCMD_PING_PROTOCOL_VERSION_SIZE; + vtest_hdr[VTEST_CMD_ID] = VCMD_PING_PROTOCOL_VERSION; + virgl_block_write(vws->sock_fd, &vtest_hdr, sizeof(vtest_hdr)); + + vtest_hdr[VTEST_CMD_LEN] = VCMD_BUSY_WAIT_SIZE; + vtest_hdr[VTEST_CMD_ID] = VCMD_RESOURCE_BUSY_WAIT; + busy_wait_buf[VCMD_BUSY_WAIT_HANDLE] = 0; + busy_wait_buf[VCMD_BUSY_WAIT_FLAGS] = 0; + virgl_block_write(vws->sock_fd, &vtest_hdr, sizeof(vtest_hdr)); + virgl_block_write(vws->sock_fd, &busy_wait_buf, sizeof(busy_wait_buf)); + + ret = virgl_block_read(vws->sock_fd, vtest_hdr, sizeof(vtest_hdr)); + assert(ret); + + if (vtest_hdr[VTEST_CMD_ID] == VCMD_PING_PROTOCOL_VERSION) { + /* Read dummy busy_wait response */ + ret = virgl_block_read(vws->sock_fd, vtest_hdr, sizeof(vtest_hdr)); + assert(ret); + ret = virgl_block_read(vws->sock_fd, busy_wait_result, sizeof(busy_wait_result)); + assert(ret); + + vtest_hdr[VTEST_CMD_LEN] = VCMD_PROTOCOL_VERSION_SIZE; + vtest_hdr[VTEST_CMD_ID] = VCMD_PROTOCOL_VERSION; + version_buf[VCMD_PROTOCOL_VERSION_VERSION] = VTEST_PROTOCOL_VERSION; + virgl_block_write(vws->sock_fd, &vtest_hdr, sizeof(vtest_hdr)); + virgl_block_write(vws->sock_fd, &version_buf, sizeof(version_buf)); + + ret = virgl_block_read(vws->sock_fd, vtest_hdr, sizeof(vtest_hdr)); + assert(ret); + ret = virgl_block_read(vws->sock_fd, version_buf, sizeof(version_buf)); + assert(ret); + return version_buf[VCMD_PROTOCOL_VERSION_VERSION]; + } + + /* Read dummy busy_wait response */ + assert(vtest_hdr[VTEST_CMD_ID] == VCMD_RESOURCE_BUSY_WAIT); + ret = virgl_block_read(vws->sock_fd, busy_wait_result, sizeof(busy_wait_result)); + assert(ret); + + /* Old server, return version 0 */ + return 0; +} + int virgl_vtest_connect(struct virgl_vtest_winsys *vws) { struct sockaddr_un un; @@ -123,18 +174,21 @@ int virgl_vtest_connect(struct virgl_vtest_winsys *vws) vws->sock_fd = sock; virgl_vtest_send_init(vws); + vws->protocol_version = virgl_vtest_negotiate_version(vws); return 0; } int virgl_vtest_send_get_caps(struct virgl_vtest_winsys *vws, struct virgl_drm_caps *caps) { - uint32_t get_caps_buf[VTEST_HDR_SIZE]; + uint32_t get_caps_buf[VTEST_HDR_SIZE * 2]; uint32_t resp_buf[VTEST_HDR_SIZE]; - + uint32_t caps_size = sizeof(struct virgl_caps_v2); int ret; get_caps_buf[VTEST_CMD_LEN] = 0; - get_caps_buf[VTEST_CMD_ID] = VCMD_GET_CAPS; + get_caps_buf[VTEST_CMD_ID] = VCMD_GET_CAPS2; + get_caps_buf[VTEST_CMD_LEN + 2] = 0; + get_caps_buf[VTEST_CMD_ID + 2] = VCMD_GET_CAPS; virgl_block_write(vws->sock_fd, &get_caps_buf, sizeof(get_caps_buf)); @@ -142,7 +196,63 @@ int virgl_vtest_send_get_caps(struct virgl_vtest_winsys *vws, if (ret <= 0) return 0; - ret = virgl_block_read(vws->sock_fd, &caps->caps, sizeof(union virgl_caps)); + if (resp_buf[1] == 2) { + struct virgl_caps_v1 dummy; + uint32_t resp_size = resp_buf[0] - 1; + uint32_t dummy_size = 0; + if (resp_size > caps_size) { + dummy_size = resp_size - caps_size; + resp_size = caps_size; + } + + ret = virgl_block_read(vws->sock_fd, &caps->caps, resp_size); + + if (dummy_size) + ret = virgl_block_read(vws->sock_fd, &dummy, dummy_size); + + /* now read back the pointless caps v1 we requested */ + ret = virgl_block_read(vws->sock_fd, resp_buf, sizeof(resp_buf)); + if (ret <= 0) + return 0; + ret = virgl_block_read(vws->sock_fd, &dummy, sizeof(struct virgl_caps_v1)); + } else + ret = virgl_block_read(vws->sock_fd, &caps->caps, sizeof(struct virgl_caps_v1)); + + return 0; +} + +static int virgl_vtest_send_resource_create2(struct virgl_vtest_winsys *vws, + uint32_t handle, + enum pipe_texture_target target, + uint32_t format, + uint32_t bind, + uint32_t width, + uint32_t height, + uint32_t depth, + uint32_t array_size, + uint32_t last_level, + uint32_t nr_samples, + uint32_t size) +{ + uint32_t res_create_buf[VCMD_RES_CREATE2_SIZE], vtest_hdr[VTEST_HDR_SIZE]; + + vtest_hdr[VTEST_CMD_LEN] = VCMD_RES_CREATE2_SIZE; + vtest_hdr[VTEST_CMD_ID] = VCMD_RESOURCE_CREATE2; + + res_create_buf[VCMD_RES_CREATE2_RES_HANDLE] = handle; + res_create_buf[VCMD_RES_CREATE2_TARGET] = target; + res_create_buf[VCMD_RES_CREATE2_FORMAT] = format; + res_create_buf[VCMD_RES_CREATE2_BIND] = bind; + res_create_buf[VCMD_RES_CREATE2_WIDTH] = width; + res_create_buf[VCMD_RES_CREATE2_HEIGHT] = height; + res_create_buf[VCMD_RES_CREATE2_DEPTH] = depth; + res_create_buf[VCMD_RES_CREATE2_ARRAY_SIZE] = array_size; + res_create_buf[VCMD_RES_CREATE2_LAST_LEVEL] = last_level; + res_create_buf[VCMD_RES_CREATE2_NR_SAMPLES] = nr_samples; + res_create_buf[VCMD_RES_CREATE2_DATA_SIZE] = size; + + virgl_block_write(vws->sock_fd, &vtest_hdr, sizeof(vtest_hdr)); + virgl_block_write(vws->sock_fd, &res_create_buf, sizeof(res_create_buf)); return 0; } @@ -157,10 +267,17 @@ int virgl_vtest_send_resource_create(struct virgl_vtest_winsys *vws, uint32_t depth, uint32_t array_size, uint32_t last_level, - uint32_t nr_samples) + uint32_t nr_samples, + uint32_t size) { uint32_t res_create_buf[VCMD_RES_CREATE_SIZE], vtest_hdr[VTEST_HDR_SIZE]; + if (vws->protocol_version >= 1) + return virgl_vtest_send_resource_create2(vws, handle, target, format, + bind, width, height, depth, + array_size, last_level, + nr_samples, size); + vtest_hdr[VTEST_CMD_LEN] = VCMD_RES_CREATE_SIZE; vtest_hdr[VTEST_CMD_ID] = VCMD_RESOURCE_CREATE; @@ -208,7 +325,7 @@ int virgl_vtest_send_resource_unref(struct virgl_vtest_winsys *vws, return 0; } -int virgl_vtest_send_transfer_cmd(struct virgl_vtest_winsys *vws, +static int virgl_vtest_send_transfer_cmd(struct virgl_vtest_winsys *vws, uint32_t vcmd, uint32_t handle, uint32_t level, uint32_t stride, @@ -221,8 +338,10 @@ int virgl_vtest_send_transfer_cmd(struct virgl_vtest_winsys *vws, vtest_hdr[VTEST_CMD_LEN] = VCMD_TRANSFER_HDR_SIZE; vtest_hdr[VTEST_CMD_ID] = vcmd; + /* The host expects the size in dwords so calculate the rounded up + * value here. */ if (vcmd == VCMD_TRANSFER_PUT) - vtest_hdr[VTEST_CMD_LEN] += data_size + 3 / 4; + vtest_hdr[VTEST_CMD_LEN] += (data_size + 3) / 4; cmd[0] = handle; cmd[1] = level; @@ -241,6 +360,74 @@ int virgl_vtest_send_transfer_cmd(struct virgl_vtest_winsys *vws, return 0; } +static int virgl_vtest_send_transfer_cmd2(struct virgl_vtest_winsys *vws, + uint32_t vcmd, + uint32_t handle, + uint32_t level, + const struct pipe_box *box, + uint32_t data_size, + uint32_t offset) +{ + uint32_t vtest_hdr[VTEST_HDR_SIZE]; + uint32_t cmd[VCMD_TRANSFER2_HDR_SIZE]; + vtest_hdr[VTEST_CMD_LEN] = VCMD_TRANSFER2_HDR_SIZE; + vtest_hdr[VTEST_CMD_ID] = vcmd; + + /* The host expects the size in dwords so calculate the rounded up + * value here. */ + if (vcmd == VCMD_TRANSFER_PUT2) + vtest_hdr[VTEST_CMD_LEN] += (data_size + 3) / 4; + + cmd[VCMD_TRANSFER2_RES_HANDLE] = handle; + cmd[VCMD_TRANSFER2_LEVEL] = level; + cmd[VCMD_TRANSFER2_X] = box->x; + cmd[VCMD_TRANSFER2_Y] = box->y; + cmd[VCMD_TRANSFER2_Z] = box->z; + cmd[VCMD_TRANSFER2_WIDTH] = box->width; + cmd[VCMD_TRANSFER2_HEIGHT] = box->height; + cmd[VCMD_TRANSFER2_DEPTH] = box->depth; + cmd[VCMD_TRANSFER2_DATA_SIZE] = data_size; + cmd[VCMD_TRANSFER2_OFFSET] = offset; + virgl_block_write(vws->sock_fd, &vtest_hdr, sizeof(vtest_hdr)); + virgl_block_write(vws->sock_fd, &cmd, sizeof(cmd)); + + return 0; +} + +int virgl_vtest_send_transfer_get(struct virgl_vtest_winsys *vws, + uint32_t handle, + uint32_t level, uint32_t stride, + uint32_t layer_stride, + const struct pipe_box *box, + uint32_t data_size, + uint32_t offset) +{ + if (vws->protocol_version < 1) + return virgl_vtest_send_transfer_cmd(vws, VCMD_TRANSFER_GET, handle, + level, stride, layer_stride, box, + data_size); + + return virgl_vtest_send_transfer_cmd2(vws, VCMD_TRANSFER_GET2, handle, + level, box, data_size, offset); +} + +int virgl_vtest_send_transfer_put(struct virgl_vtest_winsys *vws, + uint32_t handle, + uint32_t level, uint32_t stride, + uint32_t layer_stride, + const struct pipe_box *box, + uint32_t data_size, + uint32_t offset) +{ + if (vws->protocol_version < 1) + return virgl_vtest_send_transfer_cmd(vws, VCMD_TRANSFER_PUT, handle, + level, stride, layer_stride, box, + data_size); + + return virgl_vtest_send_transfer_cmd2(vws, VCMD_TRANSFER_PUT2, handle, + level, box, data_size, offset); +} + int virgl_vtest_send_transfer_put_data(struct virgl_vtest_winsys *vws, void *data, uint32_t data_size) @@ -253,20 +440,27 @@ int virgl_vtest_recv_transfer_get_data(struct virgl_vtest_winsys *vws, uint32_t data_size, uint32_t stride, const struct pipe_box *box, - uint32_t format) + uint32_t format, uint32_t res_stride) { - void *line; - void *ptr = data; - int hblocks = util_format_get_nblocksy(format, box->height); - - line = malloc(stride); - while (hblocks) { - virgl_block_read(vws->sock_fd, line, stride); - memcpy(ptr, line, util_format_get_stride(format, box->width)); + char *ptr = data; + uint32_t bytes_to_read = data_size; + char dump[1024]; + + /* Copy the date from the IOV to the target resource respecting + * the different strides */ + for (int y = 0 ; y < box->height && bytes_to_read > 0; ++y) { + uint32_t btr = MIN2(res_stride, bytes_to_read); + virgl_block_read(vws->sock_fd, ptr, btr); ptr += stride; - hblocks--; + bytes_to_read -= btr; + } + + /* It seems that there may be extra bytes that need to be read */ + while (bytes_to_read > 0 && bytes_to_read < data_size) { + uint32_t btr = MIN2(sizeof(dump), bytes_to_read); + virgl_block_read(vws->sock_fd, dump, btr); + bytes_to_read -= btr; } - free(line); return 0; } diff --git a/lib/mesa/src/gallium/winsys/virgl/vtest/vtest_protocol.h b/lib/mesa/src/gallium/winsys/virgl/vtest/vtest_protocol.h index 86d197f00..c299c3141 100644 --- a/lib/mesa/src/gallium/winsys/virgl/vtest/vtest_protocol.h +++ b/lib/mesa/src/gallium/winsys/virgl/vtest/vtest_protocol.h @@ -24,6 +24,7 @@ #define VTEST_PROTOCOL #define VTEST_DEFAULT_SOCKET_NAME "/tmp/.virgl_test" +#define VTEST_PROTOCOL_VERSION 1 /* 32-bit length field */ /* 32-bit cmd field */ @@ -47,10 +48,20 @@ /* pass the process cmd line for debugging */ #define VCMD_CREATE_RENDERER 8 + +#define VCMD_GET_CAPS2 9 /* get caps */ /* 0 length cmd */ /* resp VCMD_GET_CAPS + caps */ +#define VCMD_PING_PROTOCOL_VERSION 10 + +#define VCMD_PROTOCOL_VERSION 11 + +#define VCMD_RESOURCE_CREATE2 12 +#define VCMD_TRANSFER_GET2 13 +#define VCMD_TRANSFER_PUT2 14 + #define VCMD_RES_CREATE_SIZE 10 #define VCMD_RES_CREATE_RES_HANDLE 0 #define VCMD_RES_CREATE_TARGET 1 @@ -63,6 +74,19 @@ #define VCMD_RES_CREATE_LAST_LEVEL 8 #define VCMD_RES_CREATE_NR_SAMPLES 9 +#define VCMD_RES_CREATE2_SIZE 11 +#define VCMD_RES_CREATE2_RES_HANDLE 0 +#define VCMD_RES_CREATE2_TARGET 1 +#define VCMD_RES_CREATE2_FORMAT 2 +#define VCMD_RES_CREATE2_BIND 3 +#define VCMD_RES_CREATE2_WIDTH 4 +#define VCMD_RES_CREATE2_HEIGHT 5 +#define VCMD_RES_CREATE2_DEPTH 6 +#define VCMD_RES_CREATE2_ARRAY_SIZE 7 +#define VCMD_RES_CREATE2_LAST_LEVEL 8 +#define VCMD_RES_CREATE2_NR_SAMPLES 9 +#define VCMD_RES_CREATE2_DATA_SIZE 10 + #define VCMD_RES_UNREF_SIZE 1 #define VCMD_RES_UNREF_RES_HANDLE 0 @@ -79,10 +103,27 @@ #define VCMD_TRANSFER_DEPTH 9 #define VCMD_TRANSFER_DATA_SIZE 10 +#define VCMD_TRANSFER2_HDR_SIZE 10 +#define VCMD_TRANSFER2_RES_HANDLE 0 +#define VCMD_TRANSFER2_LEVEL 1 +#define VCMD_TRANSFER2_X 2 +#define VCMD_TRANSFER2_Y 3 +#define VCMD_TRANSFER2_Z 4 +#define VCMD_TRANSFER2_WIDTH 5 +#define VCMD_TRANSFER2_HEIGHT 6 +#define VCMD_TRANSFER2_DEPTH 7 +#define VCMD_TRANSFER2_DATA_SIZE 8 +#define VCMD_TRANSFER2_OFFSET 9 + #define VCMD_BUSY_WAIT_FLAG_WAIT 1 #define VCMD_BUSY_WAIT_SIZE 2 #define VCMD_BUSY_WAIT_HANDLE 0 #define VCMD_BUSY_WAIT_FLAGS 1 +#define VCMD_PING_PROTOCOL_VERSION_SIZE 1 + +#define VCMD_PROTOCOL_VERSION_SIZE 1 +#define VCMD_PROTOCOL_VERSION_VERSION 0 + #endif |