Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
virtio-gpu-virgl: use D3D11_SHARE_TEXTURE when available
Enable D3D texture sharing when possible, and pass it to the texture
display callbacks.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20230606115658.677673-21-marcandre.lureau@redhat.com>
  • Loading branch information
elmarco committed Jun 27, 2023
1 parent bf41ab6 commit c1600f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 19 additions & 5 deletions hw/display/virtio-gpu-virgl.c
Expand Up @@ -153,8 +153,6 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
struct virgl_renderer_resource_info info;
void *d3d_tex2d = NULL;
int ret;

VIRTIO_GPU_FILL_CMD(ss);
Expand All @@ -169,10 +167,20 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
}
g->parent_obj.enable = 1;

memset(&info, 0, sizeof(info));

if (ss.resource_id && ss.r.width && ss.r.height) {
struct virgl_renderer_resource_info info;
void *d3d_tex2d = NULL;

#ifdef HAVE_VIRGL_D3D_INFO_EXT
struct virgl_renderer_resource_info_ext ext;
memset(&ext, 0, sizeof(ext));
ret = virgl_renderer_resource_get_info_ext(ss.resource_id, &ext);
info = ext.base;
d3d_tex2d = ext.d3d_tex2d;
#else
memset(&info, 0, sizeof(info));
ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
#endif
if (ret == -1) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: illegal resource specified %d\n",
Expand Down Expand Up @@ -617,15 +625,21 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)
int virtio_gpu_virgl_init(VirtIOGPU *g)
{
int ret;
uint32_t flags = 0;

#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
if (qemu_egl_display) {
virtio_gpu_3d_cbs.version = 4;
virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
}
#endif
#ifdef VIRGL_RENDERER_D3D11_SHARE_TEXTURE
if (qemu_egl_angle_d3d) {
flags |= VIRGL_RENDERER_D3D11_SHARE_TEXTURE;
}
#endif

ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
ret = virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs);
if (ret != 0) {
error_report("virgl could not be initialized: %d", ret);
return ret;
Expand Down
6 changes: 6 additions & 0 deletions meson.build
Expand Up @@ -1072,6 +1072,12 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
virgl = dependency('virglrenderer',
method: 'pkg-config',
required: get_option('virglrenderer'))
if virgl.found()
config_host_data.set('HAVE_VIRGL_D3D_INFO_EXT',
cc.has_member('struct virgl_renderer_resource_info_ext', 'd3d_tex2d',
prefix: '#include <virglrenderer.h>',
dependencies: virgl))
endif
endif
blkio = not_found
if not get_option('blkio').auto() or have_block
Expand Down

0 comments on commit c1600f8

Please sign in to comment.