/**************************************************************************
*
- * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2006 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- * Michel Dänzer <michel@tungstengraphics.com>
+ * Keith Whitwell <keithw@vmware.com>
+ * Michel Dänzer <daenzer@vmware.com>
*/
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_transfer.h"
+#include "util/u_surface.h"
#include "sp_context.h"
#include "sp_flush.h"
unsigned width = pt->width0;
unsigned height = pt->height0;
unsigned depth = pt->depth0;
- unsigned buffer_size = 0;
+ uint64_t buffer_size = 0;
for (level = 0; level <= pt->last_level; level++) {
- unsigned slices;
+ unsigned slices, nblocksy;
+
+ nblocksy = util_format_get_nblocksy(pt->format, height);
if (pt->target == PIPE_TEXTURE_CUBE)
- slices = 6;
- else if (pt->target == PIPE_TEXTURE_3D)
+ assert(pt->array_size == 6);
+
+ if (pt->target == PIPE_TEXTURE_3D)
slices = depth;
else
slices = pt->array_size;
spr->level_offset[level] = buffer_size;
- buffer_size += (util_format_get_nblocksy(pt->format, height) *
- slices * spr->stride[level]);
+ /* if row_stride * height > SP_MAX_TEXTURE_SIZE */
+ if ((uint64_t)spr->stride[level] * nblocksy > SP_MAX_TEXTURE_SIZE) {
+ /* image too large */
+ return FALSE;
+ }
+
+ spr->img_stride[level] = spr->stride[level] * nblocksy;
+
+ buffer_size += (uint64_t) spr->img_stride[level] * slices;
width = u_minify(width, 1);
height = u_minify(height, 1);
return FALSE;
if (allocate) {
- spr->data = align_malloc(buffer_size, 16);
+ spr->data = align_malloc(buffer_size, 64);
return spr->data != NULL;
}
else {
*/
static boolean
softpipe_displaytarget_layout(struct pipe_screen *screen,
- struct softpipe_resource *spr)
+ struct softpipe_resource *spr,
+ const void *map_front_private)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
spr->base.format,
spr->base.width0,
spr->base.height0,
- 16,
+ 64,
+ map_front_private,
&spr->stride[0] );
return spr->dt != NULL;
* Create new pipe_resource given the template information.
*/
static struct pipe_resource *
-softpipe_resource_create(struct pipe_screen *screen,
- const struct pipe_resource *templat)
+softpipe_resource_create_front(struct pipe_screen *screen,
+ const struct pipe_resource *templat,
+ const void *map_front_private)
{
struct softpipe_resource *spr = CALLOC_STRUCT(softpipe_resource);
if (!spr)
if (spr->base.bind & (PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT |
PIPE_BIND_SHARED)) {
- if (!softpipe_displaytarget_layout(screen, spr))
+ if (!softpipe_displaytarget_layout(screen, spr, map_front_private))
goto fail;
}
else {
return NULL;
}
+static struct pipe_resource *
+softpipe_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *templat)
+{
+ return softpipe_resource_create_front(screen, templat, NULL);
+}
static void
softpipe_resource_destroy(struct pipe_screen *pscreen,
static struct pipe_resource *
softpipe_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templat,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
struct softpipe_resource *spr = CALLOC_STRUCT(softpipe_resource);
static boolean
softpipe_resource_get_handle(struct pipe_screen *screen,
+ struct pipe_context *ctx,
struct pipe_resource *pt,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
struct softpipe_resource *spr = softpipe_resource(pt);
* Helper function to compute offset (in bytes) for a particular
* texture level/face/slice from the start of the buffer.
*/
-static unsigned
-sp_get_tex_image_offset(const struct softpipe_resource *spr,
- unsigned level, unsigned layer)
+unsigned
+softpipe_get_tex_image_offset(const struct softpipe_resource *spr,
+ unsigned level, unsigned layer)
{
- const unsigned hgt = u_minify(spr->base.height0, level);
- const unsigned nblocksy = util_format_get_nblocksy(spr->base.format, hgt);
unsigned offset = spr->level_offset[level];
- if (spr->base.target == PIPE_TEXTURE_CUBE ||
- spr->base.target == PIPE_TEXTURE_CUBE_ARRAY ||
- spr->base.target == PIPE_TEXTURE_3D ||
- spr->base.target == PIPE_TEXTURE_2D_ARRAY) {
- offset += layer * nblocksy * spr->stride[level];
- }
- else if (spr->base.target == PIPE_TEXTURE_1D_ARRAY) {
- offset += layer * spr->stride[level];
- }
- else {
- assert(layer == 0);
- }
+ offset += layer * spr->img_stride[level];
return offset;
}
struct softpipe_transfer *spt;
struct pipe_transfer *pt;
enum pipe_format format = resource->format;
- const unsigned hgt = u_minify(spr->base.height0, level);
- const unsigned nblocksy = util_format_get_nblocksy(format, hgt);
uint8_t *map;
assert(resource);
assert(level <= resource->last_level);
/* make sure the requested region is in the image bounds */
- assert(box->x + box->width <= u_minify(resource->width0, level));
+ assert(box->x + box->width <= (int) u_minify(resource->width0, level));
if (resource->target == PIPE_TEXTURE_1D_ARRAY) {
- assert(box->y + box->height <= resource->array_size);
+ assert(box->y + box->height <= (int) resource->array_size);
}
else {
- assert(box->y + box->height <= u_minify(resource->height0, level));
+ assert(box->y + box->height <= (int) u_minify(resource->height0, level));
if (resource->target == PIPE_TEXTURE_2D_ARRAY) {
- assert(box->z + box->depth <= resource->array_size);
+ assert(box->z + box->depth <= (int) resource->array_size);
}
else if (resource->target == PIPE_TEXTURE_CUBE) {
assert(box->z < 6);
}
else if (resource->target == PIPE_TEXTURE_CUBE_ARRAY) {
- assert(box->z <= resource->array_size);
+ assert(box->z <= (int) resource->array_size);
}
else {
- assert(box->z + box->depth <= (u_minify(resource->depth0, level)));
+ assert(box->z + box->depth <= (int) u_minify(resource->depth0, level));
}
}
pt->usage = usage;
pt->box = *box;
pt->stride = spr->stride[level];
- pt->layer_stride = pt->stride * nblocksy;
+ pt->layer_stride = spr->img_stride[level];
- spt->offset = sp_get_tex_image_offset(spr, level, box->z);
+ spt->offset = softpipe_get_tex_image_offset(spr, level, box->z);
spt->offset +=
box->y / util_format_get_blockheight(format) * spt->base.stride +
map = spr->data;
}
- if (map == NULL) {
+ if (!map) {
pipe_resource_reference(&pt->resource, NULL);
FREE(spt);
return NULL;
pipe->transfer_unmap = softpipe_transfer_unmap;
pipe->transfer_flush_region = u_default_transfer_flush_region;
- pipe->transfer_inline_write = u_default_transfer_inline_write;
+ pipe->buffer_subdata = u_default_buffer_subdata;
+ pipe->texture_subdata = u_default_texture_subdata;
pipe->create_surface = softpipe_create_surface;
pipe->surface_destroy = softpipe_surface_destroy;
+ pipe->clear_texture = util_clear_texture;
}
softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
{
screen->resource_create = softpipe_resource_create;
+ screen->resource_create_front = softpipe_resource_create_front;
screen->resource_destroy = softpipe_resource_destroy;
screen->resource_from_handle = softpipe_resource_from_handle;
screen->resource_get_handle = softpipe_resource_get_handle;