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 struct virgl_transfer
{
56 struct pipe_transfer base
;
57 uint32_t offset
, l_stride
;
58 struct util_range range
;
59 struct list_head queue_link
;
60 struct pipe_transfer
*resolve_transfer
;
64 void virgl_resource_destroy(struct pipe_screen
*screen
,
65 struct pipe_resource
*resource
);
67 void virgl_init_screen_resource_functions(struct pipe_screen
*screen
);
69 void virgl_init_context_resource_functions(struct pipe_context
*ctx
);
71 void virgl_texture_init(struct virgl_resource
*res
);
73 static inline struct virgl_resource
*virgl_resource(struct pipe_resource
*r
)
75 return (struct virgl_resource
*)r
;
78 static inline struct virgl_transfer
*virgl_transfer(struct pipe_transfer
*trans
)
80 return (struct virgl_transfer
*)trans
;
83 void virgl_buffer_init(struct virgl_resource
*res
);
85 static inline unsigned pipe_to_virgl_bind(const struct virgl_screen
*vs
, unsigned pbind
)
88 if (pbind
& PIPE_BIND_DEPTH_STENCIL
)
89 outbind
|= VIRGL_BIND_DEPTH_STENCIL
;
90 if (pbind
& PIPE_BIND_RENDER_TARGET
)
91 outbind
|= VIRGL_BIND_RENDER_TARGET
;
92 if (pbind
& PIPE_BIND_SAMPLER_VIEW
)
93 outbind
|= VIRGL_BIND_SAMPLER_VIEW
;
94 if (pbind
& PIPE_BIND_VERTEX_BUFFER
)
95 outbind
|= VIRGL_BIND_VERTEX_BUFFER
;
96 if (pbind
& PIPE_BIND_INDEX_BUFFER
)
97 outbind
|= VIRGL_BIND_INDEX_BUFFER
;
98 if (pbind
& PIPE_BIND_CONSTANT_BUFFER
)
99 outbind
|= VIRGL_BIND_CONSTANT_BUFFER
;
100 if (pbind
& PIPE_BIND_DISPLAY_TARGET
)
101 outbind
|= VIRGL_BIND_DISPLAY_TARGET
;
102 if (pbind
& PIPE_BIND_STREAM_OUTPUT
)
103 outbind
|= VIRGL_BIND_STREAM_OUTPUT
;
104 if (pbind
& PIPE_BIND_CURSOR
)
105 outbind
|= VIRGL_BIND_CURSOR
;
106 if (pbind
& PIPE_BIND_CUSTOM
)
107 outbind
|= VIRGL_BIND_CUSTOM
;
108 if (pbind
& PIPE_BIND_SCANOUT
)
109 outbind
|= VIRGL_BIND_SCANOUT
;
110 if (pbind
& PIPE_BIND_SHADER_BUFFER
)
111 outbind
|= VIRGL_BIND_SHADER_BUFFER
;
112 if (pbind
& PIPE_BIND_QUERY_BUFFER
)
113 outbind
|= VIRGL_BIND_QUERY_BUFFER
;
114 if (pbind
& PIPE_BIND_COMMAND_ARGS_BUFFER
)
115 if (vs
->caps
.caps
.v2
.capability_bits
& VIRGL_CAP_BIND_COMMAND_ARGS
)
116 outbind
|= VIRGL_BIND_COMMAND_ARGS
;
120 bool virgl_res_needs_flush(struct virgl_context
*vctx
,
121 struct virgl_transfer
*transfer
);
122 bool virgl_res_needs_readback(struct virgl_context
*vctx
,
123 struct virgl_resource
*res
,
124 unsigned usage
, unsigned level
);
126 void virgl_resource_layout(struct pipe_resource
*pt
,
127 struct virgl_resource_metadata
*metadata
);
129 struct virgl_transfer
*
130 virgl_resource_create_transfer(struct slab_child_pool
*pool
,
131 struct pipe_resource
*pres
,
132 const struct virgl_resource_metadata
*metadata
,
133 unsigned level
, unsigned usage
,
134 const struct pipe_box
*box
);
136 void virgl_resource_destroy_transfer(struct slab_child_pool
*pool
,
137 struct virgl_transfer
*trans
);
139 void virgl_resource_destroy(struct pipe_screen
*screen
,
140 struct pipe_resource
*resource
);
142 boolean
virgl_resource_get_handle(struct pipe_screen
*screen
,
143 struct pipe_resource
*resource
,
144 struct winsys_handle
*whandle
);
146 void virgl_resource_dirty(struct virgl_resource
*res
, uint32_t level
);