2 * Copyright 2014, 2015 Red Hat.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef VIRGL_RESOURCE_H
25 #define VIRGL_RESOURCE_H
27 #include "util/u_resource.h"
28 #include "util/u_range.h"
29 #include "util/list.h"
30 #include "util/u_transfer.h"
33 #include "virgl_screen.h"
34 #define VR_MAX_TEXTURE_2D_LEVELS 15
40 struct virgl_resource_metadata
42 unsigned long level_offset
[VR_MAX_TEXTURE_2D_LEVELS
];
43 unsigned stride
[VR_MAX_TEXTURE_2D_LEVELS
];
44 unsigned layer_stride
[VR_MAX_TEXTURE_2D_LEVELS
];
48 struct virgl_resource
{
51 struct virgl_hw_res
*hw_res
;
52 struct virgl_resource_metadata metadata
;
55 enum virgl_transfer_map_type
{
56 VIRGL_TRANSFER_MAP_ERROR
= -1,
57 VIRGL_TRANSFER_MAP_HW_RES
,
60 struct virgl_transfer
{
61 struct pipe_transfer base
;
62 uint32_t offset
, l_stride
;
63 struct util_range range
;
64 struct list_head queue_link
;
65 struct pipe_transfer
*resolve_transfer
;
69 void virgl_resource_destroy(struct pipe_screen
*screen
,
70 struct pipe_resource
*resource
);
72 void virgl_init_screen_resource_functions(struct pipe_screen
*screen
);
74 void virgl_init_context_resource_functions(struct pipe_context
*ctx
);
76 void virgl_texture_init(struct virgl_resource
*res
);
78 static inline struct virgl_resource
*virgl_resource(struct pipe_resource
*r
)
80 return (struct virgl_resource
*)r
;
83 static inline struct virgl_transfer
*virgl_transfer(struct pipe_transfer
*trans
)
85 return (struct virgl_transfer
*)trans
;
88 void virgl_buffer_init(struct virgl_resource
*res
);
90 static inline unsigned pipe_to_virgl_bind(const struct virgl_screen
*vs
, unsigned pbind
)
93 if (pbind
& PIPE_BIND_DEPTH_STENCIL
)
94 outbind
|= VIRGL_BIND_DEPTH_STENCIL
;
95 if (pbind
& PIPE_BIND_RENDER_TARGET
)
96 outbind
|= VIRGL_BIND_RENDER_TARGET
;
97 if (pbind
& PIPE_BIND_SAMPLER_VIEW
)
98 outbind
|= VIRGL_BIND_SAMPLER_VIEW
;
99 if (pbind
& PIPE_BIND_VERTEX_BUFFER
)
100 outbind
|= VIRGL_BIND_VERTEX_BUFFER
;
101 if (pbind
& PIPE_BIND_INDEX_BUFFER
)
102 outbind
|= VIRGL_BIND_INDEX_BUFFER
;
103 if (pbind
& PIPE_BIND_CONSTANT_BUFFER
)
104 outbind
|= VIRGL_BIND_CONSTANT_BUFFER
;
105 if (pbind
& PIPE_BIND_DISPLAY_TARGET
)
106 outbind
|= VIRGL_BIND_DISPLAY_TARGET
;
107 if (pbind
& PIPE_BIND_STREAM_OUTPUT
)
108 outbind
|= VIRGL_BIND_STREAM_OUTPUT
;
109 if (pbind
& PIPE_BIND_CURSOR
)
110 outbind
|= VIRGL_BIND_CURSOR
;
111 if (pbind
& PIPE_BIND_CUSTOM
)
112 outbind
|= VIRGL_BIND_CUSTOM
;
113 if (pbind
& PIPE_BIND_SCANOUT
)
114 outbind
|= VIRGL_BIND_SCANOUT
;
115 if (pbind
& PIPE_BIND_SHADER_BUFFER
)
116 outbind
|= VIRGL_BIND_SHADER_BUFFER
;
117 if (pbind
& PIPE_BIND_QUERY_BUFFER
)
118 outbind
|= VIRGL_BIND_QUERY_BUFFER
;
119 if (pbind
& PIPE_BIND_COMMAND_ARGS_BUFFER
)
120 if (vs
->caps
.caps
.v2
.capability_bits
& VIRGL_CAP_BIND_COMMAND_ARGS
)
121 outbind
|= VIRGL_BIND_COMMAND_ARGS
;
125 enum virgl_transfer_map_type
126 virgl_resource_transfer_prepare(struct virgl_context
*vctx
,
127 struct virgl_transfer
*xfer
);
129 void virgl_resource_layout(struct pipe_resource
*pt
,
130 struct virgl_resource_metadata
*metadata
);
132 struct virgl_transfer
*
133 virgl_resource_create_transfer(struct slab_child_pool
*pool
,
134 struct pipe_resource
*pres
,
135 const struct virgl_resource_metadata
*metadata
,
136 unsigned level
, unsigned usage
,
137 const struct pipe_box
*box
);
139 void virgl_resource_destroy_transfer(struct slab_child_pool
*pool
,
140 struct virgl_transfer
*trans
);
142 void virgl_resource_destroy(struct pipe_screen
*screen
,
143 struct pipe_resource
*resource
);
145 boolean
virgl_resource_get_handle(struct pipe_screen
*screen
,
146 struct pipe_resource
*resource
,
147 struct winsys_handle
*whandle
);
149 void virgl_resource_dirty(struct virgl_resource
*res
, uint32_t level
);