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 boolean clean
[VR_MAX_TEXTURE_2D_LEVELS
];
50 struct virgl_hw_res
*hw_res
;
51 struct virgl_resource_metadata metadata
;
54 struct virgl_transfer
{
55 struct pipe_transfer base
;
56 uint32_t offset
, l_stride
;
57 struct util_range range
;
58 struct list_head queue_link
;
59 struct virgl_resource
*resolve_tmp
;
62 void virgl_resource_destroy(struct pipe_screen
*screen
,
63 struct pipe_resource
*resource
);
65 void virgl_init_screen_resource_functions(struct pipe_screen
*screen
);
67 void virgl_init_context_resource_functions(struct pipe_context
*ctx
);
69 void virgl_texture_init(struct virgl_resource
*res
);
71 static inline struct virgl_resource
*virgl_resource(struct pipe_resource
*r
)
73 return (struct virgl_resource
*)r
;
76 static inline struct virgl_transfer
*virgl_transfer(struct pipe_transfer
*trans
)
78 return (struct virgl_transfer
*)trans
;
81 void virgl_buffer_init(struct virgl_resource
*res
);
83 static inline unsigned pipe_to_virgl_bind(unsigned pbind
)
86 if (pbind
& PIPE_BIND_DEPTH_STENCIL
)
87 outbind
|= VIRGL_BIND_DEPTH_STENCIL
;
88 if (pbind
& PIPE_BIND_RENDER_TARGET
)
89 outbind
|= VIRGL_BIND_RENDER_TARGET
;
90 if (pbind
& PIPE_BIND_SAMPLER_VIEW
)
91 outbind
|= VIRGL_BIND_SAMPLER_VIEW
;
92 if (pbind
& PIPE_BIND_VERTEX_BUFFER
)
93 outbind
|= VIRGL_BIND_VERTEX_BUFFER
;
94 if (pbind
& PIPE_BIND_INDEX_BUFFER
)
95 outbind
|= VIRGL_BIND_INDEX_BUFFER
;
96 if (pbind
& PIPE_BIND_CONSTANT_BUFFER
)
97 outbind
|= VIRGL_BIND_CONSTANT_BUFFER
;
98 if (pbind
& PIPE_BIND_DISPLAY_TARGET
)
99 outbind
|= VIRGL_BIND_DISPLAY_TARGET
;
100 if (pbind
& PIPE_BIND_STREAM_OUTPUT
)
101 outbind
|= VIRGL_BIND_STREAM_OUTPUT
;
102 if (pbind
& PIPE_BIND_CURSOR
)
103 outbind
|= VIRGL_BIND_CURSOR
;
104 if (pbind
& PIPE_BIND_CUSTOM
)
105 outbind
|= VIRGL_BIND_CUSTOM
;
106 if (pbind
& PIPE_BIND_SCANOUT
)
107 outbind
|= VIRGL_BIND_SCANOUT
;
108 if (pbind
& PIPE_BIND_SHADER_BUFFER
)
109 outbind
|= VIRGL_BIND_SHADER_BUFFER
;
110 if (pbind
& PIPE_BIND_QUERY_BUFFER
)
111 outbind
|= VIRGL_BIND_QUERY_BUFFER
;
115 bool virgl_res_needs_flush_wait(struct virgl_context
*vctx
,
116 struct virgl_transfer
*transfer
);
117 bool virgl_res_needs_readback(struct virgl_context
*vctx
,
118 struct virgl_resource
*res
,
119 unsigned usage
, unsigned level
);
121 void virgl_resource_layout(struct pipe_resource
*pt
,
122 struct virgl_resource_metadata
*metadata
);
124 struct virgl_transfer
*
125 virgl_resource_create_transfer(struct slab_child_pool
*pool
,
126 struct pipe_resource
*pres
,
127 const struct virgl_resource_metadata
*metadata
,
128 unsigned level
, unsigned usage
,
129 const struct pipe_box
*box
);
131 void virgl_resource_destroy_transfer(struct slab_child_pool
*pool
,
132 struct virgl_transfer
*trans
);
134 void virgl_resource_destroy(struct pipe_screen
*screen
,
135 struct pipe_resource
*resource
);
137 boolean
virgl_resource_get_handle(struct pipe_screen
*screen
,
138 struct pipe_resource
*resource
,
139 struct winsys_handle
*whandle
);
141 void virgl_resource_dirty(struct virgl_resource
*res
, uint32_t level
);