1// Copyright (C) 2024 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17import "VirtioGpuRingBlobSnapshot.proto";
18
19package gfxstream.host.snapshot;
20
21// LINT.IfChange(virtio_gpu_resource_type)
22enum VirtioGpuResourceType {
23    UNKNOWN = 0;
24    PIPE = 1;
25    BUFFER = 2;
26    COLOR_BUFFER = 3;
27    BLOB = 4;
28}
29// LINT.ThenChange(VirtioGpuResource.h:virtio_gpu_resource_type)
30
31message VirtioGpuResourceCreateArgs {
32    optional uint32 id = 1;
33    optional uint32 target = 2;
34    optional uint32 format = 3;
35    optional uint32 bind = 4;
36    optional uint32 width = 5;
37    optional uint32 height = 6;
38    optional uint32 depth = 7;
39    optional uint32 array_size = 8;
40    optional uint32 last_level = 9;
41    optional uint32 nr_samples = 10;
42    optional uint32 flags = 11;
43}
44
45message VirtioGpuResourceCreateBlobArgs {
46    optional uint32 mem = 1;
47    optional uint32 flags = 2;
48    optional uint32 id = 3;
49    optional uint64 size = 4;
50}
51
52// NOTE: This does not actually save the blob's external memory because the handle
53// or mapping may not be the same across snapshot and restore. This instead saves
54// the info needed to refetch either the descriptor or mapping from
55// `ExternalObjectManager` after a restore.
56message VirtioGpuBlobExternalMemoryInfo {
57    optional uint32 context_id = 1;
58    optional uint32 blob_id = 2;
59}
60
61// LINT.IfChange(virtio_gpu_resource)
62message VirtioGpuResourceSnapshot {
63    optional uint32 id = 1;
64    optional VirtioGpuResourceType type = 2;
65    optional VirtioGpuResourceCreateArgs create_args = 3;
66    optional VirtioGpuResourceCreateBlobArgs create_blob_args = 4;
67    // NOTE: `VirtioGpuResource::iovs` is not saved because the host virtual address
68    // may not be the same across snapshot and restore. VMMs are expected to re-call
69    // `stream_renderer_resource_attach_iov()` for resources with the new guest-memory
70    // host virtual addresses.
71    oneof blob_memory {
72        VirtioGpuRingBlobSnapshot ring_blob = 5;
73        VirtioGpuBlobExternalMemoryInfo external_memory_descriptor = 6;
74        VirtioGpuBlobExternalMemoryInfo external_memory_mapping = 7;
75    }
76    optional uint32 latest_attached_context = 8;
77    repeated uint32 attached_contexts = 9;
78}
79// LINT.ThenChange(VirtioGpuResource.h:virtio_gpu_resource)
80