@@ -72,6 +72,8 @@ create_virtgpu() {
7272 INFO (" Created shm at %p" , shmem);
7373 }
7474
75+ virtgpu_submit (gpu, shmem);
76+
7577 breakpoint ();
7678}
7779
@@ -347,3 +349,87 @@ virtgpu_ioctl_getparam(struct virtgpu *gpu, uint64_t param)
347349 const int ret = virtgpu_ioctl (gpu, DRM_IOCTL_VIRTGPU_GETPARAM, &args);
348350 return ret ? 0 : val;
349351}
352+
353+
354+
355+ #define PK_COMMAND_TYPE_pkCreateThread 255
356+
357+ static int virtgpu_submit (struct virtgpu *gpu, struct vn_renderer_shmem *shmem)
358+ {
359+
360+ /*
361+ * Data passed to the host
362+ */
363+ int32_t command[3 ];
364+ // command identifier
365+ command[0 ] = PK_COMMAND_TYPE_pkCreateThread;
366+ command[1 ] = 0 ; // ?
367+ // arguments
368+ command[2 ] = shmem->res_id ;
369+
370+ /*
371+ * Reply notification pointer
372+ */
373+
374+ volatile std::atomic_uint *atomic_reply_notif = (volatile std::atomic_uint *) shmem->mmap_ptr ;
375+ *atomic_reply_notif = 0 ;
376+
377+ /*
378+ * Trigger the execbuf ioctl
379+ */
380+
381+ struct drm_virtgpu_execbuffer args = {
382+ .flags = VIRTGPU_EXECBUF_RING_IDX,
383+ .size = sizeof (command),
384+ .command = (uintptr_t ) &command,
385+
386+ .bo_handles = 0 ,
387+ .num_bo_handles = 0 ,
388+
389+ .fence_fd = 0 ,
390+ .ring_idx = 0 ,
391+ .syncobj_stride = 0 ,
392+ .num_in_syncobjs = 0 ,
393+ .num_out_syncobjs = 0 ,
394+ .in_syncobjs = 0 ,
395+ .out_syncobjs = 0 ,
396+ };
397+
398+ int ret = drmIoctl (gpu->fd , DRM_IOCTL_VIRTGPU_EXECBUFFER, &args);
399+
400+ /*
401+ * Wait for the response notification
402+ */
403+
404+ int resp = std::atomic_load_explicit (atomic_reply_notif, std::memory_order_acquire);
405+ printf (" waiting for the response ... | %d | %p\n " , resp, (void *) atomic_reply_notif);
406+
407+ while (std::atomic_load_explicit (atomic_reply_notif, std::memory_order_acquire) == 0 ) {
408+ int64_t base_sleep_us = 160 ;
409+
410+ os_time_sleep (base_sleep_us);
411+ }
412+ printf (" got the response!\n " );
413+ /*
414+ * Read the reply
415+ */
416+
417+ printf (" virtgpu_submit() --> 0x%x\n " , ((uint32_t *)shmem->mmap_ptr )[1 ]);
418+ printf (" virtgpu_submit() --> 0x%x\n " , ((uint32_t *)shmem->mmap_ptr )[2 ]);
419+ printf (" virtgpu_submit() --> 0x%x\n " , ((uint32_t *)shmem->mmap_ptr )[3 ]);
420+
421+ #if 0
422+ VkCommandTypeEXT command_type;
423+ vn_decode_VkCommandTypeEXT(dec, &command_type);
424+ assert(command_type == VK_COMMAND_TYPE_vkEnumerateInstanceVersion_EXT);
425+ VkResult ret;
426+ vn_decode_VkResult(dec, &ret);
427+ if (vn_decode_simple_pointer(dec)) {
428+ vn_decode_uint32_t(dec, pApiVersion);
429+ } else {
430+ pApiVersion = NULL;
431+ }
432+ #endif
433+
434+ return ret;
435+ }
0 commit comments