svga: Add a limit to the maximum surface size

This patch adds a limit to the maximum surface size which is
based on the maximum size of a single mob. If this value is not
available, the maximum surface size is by default set to 128 MB.

Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Charmaine Lee
2014-08-12 07:37:12 -06:00
committed by Brian Paul
parent d839be24b3
commit 0c065270c0
9 changed files with 130 additions and 7 deletions
@@ -872,7 +872,7 @@ svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format,
bool cubemap)
{
const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format);
uint32 total_size = 0;
uint64_t total_size = 0;
uint32 mip;
for (mip = 0; mip < num_mip_levels; mip++) {
@@ -885,7 +885,8 @@ svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format,
if (cubemap)
total_size *= SVGA3D_MAX_SURFACE_FACES;
return total_size;
return (total_size > (uint64_t) MAX_UINT32) ? MAX_UINT32 :
(uint32) total_size;
}
+9 -1
View File
@@ -180,7 +180,15 @@ enum {
SVGA_REG_MEMORY_SIZE = 47, /* Total dedicated device memory excluding FIFO */
SVGA_REG_COMMAND_LOW = 48, /* Lower 32 bits and submits commands */
SVGA_REG_COMMAND_HIGH = 49, /* Upper 32 bits of command buffer PA */
SVGA_REG_TOP = 50, /* Must be 1 more than the last register */
SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM = 50, /* Max primary memory */
SVGA_REG_SUGGESTED_GBOBJECT_MEM_SIZE_KB = 51, /* Suggested limit on mob mem */
SVGA_REG_DEV_CAP = 52, /* Write dev cap index, read value */
SVGA_REG_CMD_PREPEND_LOW = 53,
SVGA_REG_iCMD_PREPEND_HIGH = 54,
SVGA_REG_SCREENTARGET_MAX_WIDTH = 55,
SVGA_REG_SCREENTARGET_MAX_HEIGHT = 56,
SVGA_REG_MOB_MAX_SIZE = 57,
SVGA_REG_TOP = 58, /* Must be 1 more than the last register */
SVGA_PALETTE_BASE = 1024, /* Base of SVGA color map */
/* Next 768 (== 256*3) registers exist for colormap */
+43
View File
@@ -30,6 +30,7 @@
#include "svga_resource_texture.h"
#include "svga_context.h"
#include "svga_screen.h"
#include "svga_format.h"
static struct pipe_resource *
@@ -55,6 +56,47 @@ svga_resource_from_handle(struct pipe_screen * screen,
}
/**
* Check if a resource (texture, buffer) of the given size
* and format can be created.
* \Return TRUE if OK, FALSE if too large.
*/
static boolean
svga_can_create_resource(struct pipe_screen *screen,
const struct pipe_resource *res)
{
struct svga_screen *svgascreen = svga_screen(screen);
struct svga_winsys_screen *sws = svgascreen->sws;
SVGA3dSurfaceFormat format;
SVGA3dSize base_level_size;
uint32 numFaces;
uint32 numMipLevels;
if (res->target == PIPE_BUFFER) {
format = SVGA3D_BUFFER;
base_level_size.width = res->width0;
base_level_size.height = 1;
base_level_size.depth = 1;
numFaces = 1;
numMipLevels = 1;
} else {
format = svga_translate_format(svgascreen, res->format, res->bind);
if (format == SVGA3D_FORMAT_INVALID)
return FALSE;
base_level_size.width = res->width0;
base_level_size.height = res->height0;
base_level_size.depth = res->depth0;
numFaces = (res->target == PIPE_TEXTURE_CUBE) ? 6 : 1;
numMipLevels = res->last_level + 1;
}
return sws->surface_can_create(sws, format, base_level_size,
numFaces, numMipLevels);
}
void
svga_init_resource_functions(struct svga_context *svga)
{
@@ -71,4 +113,5 @@ svga_init_screen_resource_functions(struct svga_screen *is)
is->screen.resource_from_handle = svga_resource_from_handle;
is->screen.resource_get_handle = u_resource_get_handle_vtbl;
is->screen.resource_destroy = u_resource_destroy_vtbl;
is->screen.can_create_resource = svga_can_create_resource;
}
@@ -727,8 +727,10 @@ svga_texture_create(struct pipe_screen *screen,
SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle);
tex->handle = svga_screen_surface_create(svgascreen, &tex->key);
if (tex->handle)
SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle);
if (!tex->handle)
goto error2;
SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle);
debug_reference(&tex->b.b.reference,
(debug_reference_descriptor)debug_describe_resource, 0);
+12
View File
@@ -334,6 +334,18 @@ struct svga_winsys_screen
struct svga_winsys_surface **pdst,
struct svga_winsys_surface *src);
/**
* Check if a resource (texture, buffer) of the given size
* and format can be created.
* \Return TRUE if OK, FALSE if too large.
*/
boolean
(*surface_can_create)(struct svga_winsys_screen *sws,
SVGA3dSurfaceFormat format,
SVGA3dSize size,
uint32 numFaces,
uint32 numMipLevels);
/**
* Buffer management. Buffer attributes are mostly fixed over its lifetime.
*
+17 -2
View File
@@ -49,6 +49,21 @@
#define VMW_MUST_FLUSH_STACK 8
/*
* A factor applied to the maximum mob memory size to determine
* the optimial time to preemptively flush the command buffer.
* The constant is based on some performance trials with SpecViewperf.
*/
#define VMW_MAX_MOB_MEM_FACTOR 2
/*
* A factor applied to the maximum surface memory size to determine
* the optimial time to preemptively flush the command buffer.
* The constant is based on some performance trials with SpecViewperf.
*/
#define VMW_MAX_SURF_MEM_FACTOR 2
struct vmw_buffer_relocation
{
struct pb_buffer *buffer;
@@ -395,7 +410,7 @@ vmw_swc_mob_relocation(struct svga_winsys_context *swc,
if (vmw_swc_add_validate_buffer(vswc, reloc->buffer, flags)) {
vswc->seen_mobs += reloc->buffer->size;
/* divide by 5, tested for best performance */
if (vswc->seen_mobs >= vswc->vws->ioctl.max_mob_memory / 5)
if (vswc->seen_mobs >= vswc->vws->ioctl.max_mob_memory / VMW_MAX_MOB_MEM_FACTOR)
vswc->preemptive_flush = TRUE;
}
@@ -457,7 +472,7 @@ vmw_swc_surface_only_relocation(struct svga_winsys_context *swc,
vswc->seen_surfaces += vsurf->size;
/* divide by 5 not well tuned for performance */
if (vswc->seen_surfaces >= vswc->vws->ioctl.max_surface_memory / 5)
if (vswc->seen_surfaces >= vswc->vws->ioctl.max_surface_memory / VMW_MAX_SURF_MEM_FACTOR)
vswc->preemptive_flush = TRUE;
}
+1
View File
@@ -74,6 +74,7 @@ struct vmw_winsys_screen
struct vmw_cap_3d *cap_3d;
uint64_t max_mob_memory;
uint64_t max_surface_memory;
uint64_t max_texture_size;
boolean have_drm_2_6;
} ioctl;
@@ -51,6 +51,8 @@
#include <errno.h>
#include <unistd.h>
#define VMW_MAX_DEFAULT_TEXTURE_SIZE (128 * 1024 * 1024)
struct vmw_region
{
uint32_t handle;
@@ -904,6 +906,18 @@ vmw_ioctl_init(struct vmw_winsys_screen *vws)
} else {
vws->ioctl.max_mob_memory = gp_arg.value;
}
memset(&gp_arg, 0, sizeof(gp_arg));
gp_arg.param = DRM_VMW_PARAM_MAX_MOB_SIZE;
ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM,
&gp_arg, sizeof(gp_arg));
if (ret || gp_arg.value == 0) {
vws->ioctl.max_texture_size = VMW_MAX_DEFAULT_TEXTURE_SIZE;
} else {
vws->ioctl.max_texture_size = gp_arg.value;
}
/* Never early flush surfaces, mobs do accounting. */
vws->ioctl.max_surface_memory = -1;
} else {
@@ -920,6 +934,9 @@ vmw_ioctl_init(struct vmw_winsys_screen *vws)
} else {
vws->ioctl.max_surface_memory = gp_arg.value;
}
vws->ioctl.max_texture_size = VMW_MAX_DEFAULT_TEXTURE_SIZE;
size = SVGA_FIFO_3D_CAPS_SIZE * sizeof(uint32_t);
}
@@ -164,6 +164,10 @@ vmw_svga_winsys_surface_create(struct svga_winsys_screen *sws,
* when to flush on non-GB hosts.
*/
buffer_size = svga3dsurface_get_serialized_size(format, size, numMipLevels, (numFaces == 6));
if (buffer_size > vws->ioctl.max_texture_size) {
goto no_sid;
}
if (sws->have_gb_objects) {
SVGAGuestPtr ptr = {0,0};
@@ -249,6 +253,25 @@ no_surface:
return NULL;
}
static boolean
vmw_svga_winsys_surface_can_create(struct svga_winsys_screen *sws,
SVGA3dSurfaceFormat format,
SVGA3dSize size,
uint32 numFaces,
uint32 numMipLevels)
{
struct vmw_winsys_screen *vws = vmw_winsys_screen(sws);
uint32_t buffer_size;
buffer_size = svga3dsurface_get_serialized_size(format, size,
numMipLevels,
(numFaces == 6));
if (buffer_size > vws->ioctl.max_texture_size) {
return FALSE;
}
return TRUE;
}
static boolean
vmw_svga_winsys_surface_is_flushed(struct svga_winsys_screen *sws,
@@ -371,6 +394,7 @@ vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws)
vws->base.surface_create = vmw_svga_winsys_surface_create;
vws->base.surface_is_flushed = vmw_svga_winsys_surface_is_flushed;
vws->base.surface_reference = vmw_svga_winsys_surface_ref;
vws->base.surface_can_create = vmw_svga_winsys_surface_can_create;
vws->base.buffer_create = vmw_svga_winsys_buffer_create;
vws->base.buffer_map = vmw_svga_winsys_buffer_map;
vws->base.buffer_unmap = vmw_svga_winsys_buffer_unmap;