@ -804,15 +804,22 @@ static int vtest_create_resource_setup_shm(struct vtest_resource *res,
}
}
static int vtest_create_resource_internal ( struct vtest_context * ctx ,
static int vtest_create_resource_internal ( struct vtest_context * ctx ,
uint32_t cmd_id ,
struct virgl_renderer_resource_create_args * args ,
struct virgl_renderer_resource_create_args * args ,
size_t shm_size )
size_t shm_size )
{
{
struct vtest_resource * res ;
struct vtest_resource * res ;
int ret ;
int ret ;
// Check that the handle doesn't already exist.
if ( ctx - > protocol_version > = 3 ) {
if ( util_hash_table_get ( ctx - > resource_table , intptr_to_pointer ( args - > handle ) ) )
if ( args - > handle )
return - EEXIST ;
return - EINVAL ;
} else {
// Check that the handle doesn't already exist.
if ( util_hash_table_get ( ctx - > resource_table , intptr_to_pointer ( args - > handle ) ) ) {
return - EEXIST ;
}
}
res = vtest_new_resource ( args - > handle ) ;
res = vtest_new_resource ( args - > handle ) ;
if ( ! res )
if ( ! res )
@ -827,6 +834,19 @@ static int vtest_create_resource_internal(struct vtest_context *ctx,
virgl_renderer_ctx_attach_resource ( ctx - > ctx_id , res - > res_id ) ;
virgl_renderer_ctx_attach_resource ( ctx - > ctx_id , res - > res_id ) ;
if ( ctx - > protocol_version > = 3 ) {
uint32_t resp_buf [ VTEST_HDR_SIZE + 1 ] = {
[ VTEST_CMD_LEN ] = 1 ,
[ VTEST_CMD_ID ] = cmd_id ,
[ VTEST_CMD_DATA_START ] = res - > res_id ,
} ;
ret = vtest_block_write ( ctx - > out_fd , resp_buf , sizeof ( resp_buf ) ) ;
if ( ret < 0 ) {
vtest_unref_resource ( res ) ;
return ret ;
}
}
/* no shm for v1 resources or v2 multi-sample resources */
/* no shm for v1 resources or v2 multi-sample resources */
if ( shm_size ) {
if ( shm_size ) {
int fd ;
int fd ;
@ -866,7 +886,7 @@ int vtest_create_resource(UNUSED uint32_t length_dw)
return ret ;
return ret ;
}
}
return vtest_create_resource_internal ( ctx , & args , 0 ) ;
return vtest_create_resource_internal ( ctx , VCMD_RESOURCE_CREATE , & args , 0 ) ;
}
}
int vtest_create_resource2 ( UNUSED uint32_t length_dw )
int vtest_create_resource2 ( UNUSED uint32_t length_dw )
@ -881,7 +901,7 @@ int vtest_create_resource2(UNUSED uint32_t length_dw)
return ret ;
return ret ;
}
}
return vtest_create_resource_internal ( ctx , & args , shm_size ) ;
return vtest_create_resource_internal ( ctx , VCMD_RESOURCE_CREATE2 , & args , shm_size ) ;
}
}
int vtest_resource_unref ( UNUSED uint32_t length_dw )
int vtest_resource_unref ( UNUSED uint32_t length_dw )