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 #define VR_MAX_TEXTURE_2D_LEVELS 15
39 struct virgl_resource_metadata
41 unsigned long level_offset
[VR_MAX_TEXTURE_2D_LEVELS
];
42 unsigned stride
[VR_MAX_TEXTURE_2D_LEVELS
];
43 unsigned layer_stride
[VR_MAX_TEXTURE_2D_LEVELS
];
47 struct virgl_resource
{
49 struct virgl_hw_res
*hw_res
;
54 struct virgl_resource base
;
56 struct list_head flush_list
;
59 /* The buffer range which is initialized (with a write transfer,
60 * streamout, DMA, or as a random access target). The rest of
61 * the buffer is considered invalid and can be mapped unsynchronized.
63 * This allows unsychronized mapping of a buffer range which hasn't
64 * been used yet. It's for applications which forget to use
65 * the unsynchronized map flag and expect the driver to figure it out.
67 struct util_range valid_buffer_range
;
70 struct virgl_texture
{
71 struct virgl_resource base
;
72 struct virgl_resource_metadata metadata
;
75 struct virgl_transfer
{
76 struct pipe_transfer base
;
77 uint32_t offset
, l_stride
;
78 struct util_range range
;
79 struct virgl_resource
*resolve_tmp
;
82 void virgl_resource_destroy(struct pipe_screen
*screen
,
83 struct pipe_resource
*resource
);
85 void virgl_init_screen_resource_functions(struct pipe_screen
*screen
);
87 void virgl_init_context_resource_functions(struct pipe_context
*ctx
);
89 struct pipe_resource
*virgl_texture_create(struct virgl_screen
*vs
,
90 const struct pipe_resource
*templ
);
92 struct pipe_resource
*virgl_texture_from_handle(struct virgl_screen
*vs
,
93 const struct pipe_resource
*templ
,
94 struct winsys_handle
*whandle
);
96 static inline struct virgl_resource
*virgl_resource(struct pipe_resource
*r
)
98 return (struct virgl_resource
*)r
;
101 static inline struct virgl_buffer
*virgl_buffer(struct pipe_resource
*r
)
103 return (struct virgl_buffer
*)r
;
106 static inline struct virgl_texture
*virgl_texture(struct pipe_resource
*r
)
108 return (struct virgl_texture
*)r
;
111 static inline struct virgl_transfer
*virgl_transfer(struct pipe_transfer
*trans
)
113 return (struct virgl_transfer
*)trans
;
116 struct pipe_resource
*virgl_buffer_create(struct virgl_screen
*vs
,
117 const struct pipe_resource
*templ
);
119 static inline unsigned pipe_to_virgl_bind(unsigned pbind
)
121 unsigned outbind
= 0;
122 if (pbind
& PIPE_BIND_DEPTH_STENCIL
)
123 outbind
|= VIRGL_BIND_DEPTH_STENCIL
;
124 if (pbind
& PIPE_BIND_RENDER_TARGET
)
125 outbind
|= VIRGL_BIND_RENDER_TARGET
;
126 if (pbind
& PIPE_BIND_SAMPLER_VIEW
)
127 outbind
|= VIRGL_BIND_SAMPLER_VIEW
;
128 if (pbind
& PIPE_BIND_VERTEX_BUFFER
)
129 outbind
|= VIRGL_BIND_VERTEX_BUFFER
;
130 if (pbind
& PIPE_BIND_INDEX_BUFFER
)
131 outbind
|= VIRGL_BIND_INDEX_BUFFER
;
132 if (pbind
& PIPE_BIND_CONSTANT_BUFFER
)
133 outbind
|= VIRGL_BIND_CONSTANT_BUFFER
;
134 if (pbind
& PIPE_BIND_DISPLAY_TARGET
)
135 outbind
|= VIRGL_BIND_DISPLAY_TARGET
;
136 if (pbind
& PIPE_BIND_STREAM_OUTPUT
)
137 outbind
|= VIRGL_BIND_STREAM_OUTPUT
;
138 if (pbind
& PIPE_BIND_CURSOR
)
139 outbind
|= VIRGL_BIND_CURSOR
;
140 if (pbind
& PIPE_BIND_CUSTOM
)
141 outbind
|= VIRGL_BIND_CUSTOM
;
142 if (pbind
& PIPE_BIND_SCANOUT
)
143 outbind
|= VIRGL_BIND_SCANOUT
;
144 if (pbind
& PIPE_BIND_SHADER_BUFFER
)
145 outbind
|= VIRGL_BIND_SHADER_BUFFER
;
149 bool virgl_res_needs_flush_wait(struct virgl_context
*vctx
,
150 struct virgl_resource
*res
,
152 bool virgl_res_needs_readback(struct virgl_context
*vctx
,
153 struct virgl_resource
*res
,
156 void virgl_resource_layout(struct pipe_resource
*pt
,
157 struct virgl_resource_metadata
*metadata
);
159 struct virgl_transfer
*
160 virgl_resource_create_transfer(struct pipe_context
*ctx
,
161 struct pipe_resource
*pres
,
162 const struct virgl_resource_metadata
*metadata
,
163 unsigned level
, unsigned usage
,
164 const struct pipe_box
*box
);
166 void virgl_resource_destroy_transfer(struct virgl_context
*vctx
,
167 struct virgl_transfer
*trans
);