* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include "util/u_format.h"
#include "util/u_inlines.h"
#include "virgl_context.h"
#include "virgl_resource.h"
ctx->buffer_subdata = virgl_buffer_subdata;
ctx->texture_subdata = u_default_texture_subdata;
}
+
+void virgl_resource_layout(struct pipe_resource *pt,
+ struct virgl_resource_metadata *metadata)
+{
+ unsigned level;
+ unsigned width = pt->width0;
+ unsigned height = pt->height0;
+ unsigned depth = pt->depth0;
+ unsigned buffer_size = 0;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ unsigned slices;
+
+ if (pt->target == PIPE_TEXTURE_CUBE)
+ slices = 6;
+ else if (pt->target == PIPE_TEXTURE_3D)
+ slices = depth;
+ else
+ slices = pt->array_size;
+
+ metadata->stride[level] = util_format_get_stride(pt->format, width);
+ metadata->level_offset[level] = buffer_size;
+
+ buffer_size += (util_format_get_nblocksy(pt->format, height) *
+ slices * metadata->stride[level]);
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ depth = u_minify(depth, 1);
+ }
+
+ if (pt->nr_samples <= 1)
+ metadata->total_size = buffer_size;
+ else /* don't create guest backing store for MSAA */
+ metadata->total_size = 0;
+}
slab_free(&vctx->transfer_pool, trans);
}
-
-static void
-vrend_resource_layout(struct virgl_texture *res,
- uint32_t *total_size)
-{
- struct pipe_resource *pt = &res->base.u.b;
- unsigned level;
- unsigned width = pt->width0;
- unsigned height = pt->height0;
- unsigned depth = pt->depth0;
- unsigned buffer_size = 0;
-
- for (level = 0; level <= pt->last_level; level++) {
- unsigned slices;
-
- if (pt->target == PIPE_TEXTURE_CUBE)
- slices = 6;
- else if (pt->target == PIPE_TEXTURE_3D)
- slices = depth;
- else
- slices = pt->array_size;
-
- res->metadata.stride[level] = util_format_get_stride(pt->format, width);
- res->metadata.level_offset[level] = buffer_size;
-
- buffer_size += (util_format_get_nblocksy(pt->format, height) *
- slices * res->metadata.stride[level]);
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- depth = u_minify(depth, 1);
- }
-
- if (pt->nr_samples <= 1)
- *total_size = buffer_size;
- else /* don't create guest backing store for MSAA */
- *total_size = 0;
-}
-
static boolean virgl_texture_get_handle(struct pipe_screen *screen,
struct pipe_resource *ptex,
struct winsys_handle *whandle)
const struct pipe_resource *template)
{
struct virgl_texture *tex;
- uint32_t size;
unsigned vbind;
tex = CALLOC_STRUCT(virgl_texture);
tex->base.u.b.screen = &vs->base;
pipe_reference_init(&tex->base.u.b.reference, 1);
tex->base.u.vtbl = &virgl_texture_vtbl;
- vrend_resource_layout(tex, &size);
+ virgl_resource_layout(&tex->base.u.b, &tex->metadata);
vbind = pipe_to_virgl_bind(template->bind);
- tex->base.hw_res = vs->vws->resource_create(vs->vws, template->target, template->format, vbind, template->width0, template->height0, template->depth0, template->array_size, template->last_level, template->nr_samples, size);
+ tex->base.hw_res = vs->vws->resource_create(vs->vws, template->target,
+ template->format, vbind,
+ template->width0,
+ template->height0,
+ template->depth0,
+ template->array_size,
+ template->last_level,
+ template->nr_samples,
+ tex->metadata.total_size);
if (!tex->base.hw_res) {
FREE(tex);
return NULL;