diff options
author | Charmaine Lee <[email protected]> | 2014-08-12 07:37:12 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2014-08-12 08:03:24 -0600 |
commit | 0c065270c0ff063edba03516b22d734023cac912 (patch) | |
tree | 33a6cf749f9a93cf1f24c3c9c747f659d28c3e97 | |
parent | d839be24b3b53717fcc153c3d00afb1c516d926e (diff) |
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 <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
-rw-r--r-- | src/gallium/drivers/svga/include/svga3d_surfacedefs.h | 5 | ||||
-rw-r--r-- | src/gallium/drivers/svga/include/svga_reg.h | 10 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_resource.c | 43 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_resource_texture.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/svga/svga_winsys.h | 12 | ||||
-rw-r--r-- | src/gallium/winsys/svga/drm/vmw_context.c | 19 | ||||
-rw-r--r-- | src/gallium/winsys/svga/drm/vmw_screen.h | 1 | ||||
-rw-r--r-- | src/gallium/winsys/svga/drm/vmw_screen_ioctl.c | 17 | ||||
-rw-r--r-- | src/gallium/winsys/svga/drm/vmw_screen_svga.c | 24 |
9 files changed, 130 insertions, 7 deletions
diff --git a/src/gallium/drivers/svga/include/svga3d_surfacedefs.h b/src/gallium/drivers/svga/include/svga3d_surfacedefs.h index 9afdd46ac67..8763cdf319e 100644 --- a/src/gallium/drivers/svga/include/svga3d_surfacedefs.h +++ b/src/gallium/drivers/svga/include/svga3d_surfacedefs.h @@ -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; } diff --git a/src/gallium/drivers/svga/include/svga_reg.h b/src/gallium/drivers/svga/include/svga_reg.h index 3ba010efbc6..e75b442f994 100644 --- a/src/gallium/drivers/svga/include/svga_reg.h +++ b/src/gallium/drivers/svga/include/svga_reg.h @@ -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 */ diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c index 79951b34db5..b295b44ea37 100644 --- a/src/gallium/drivers/svga/svga_resource.c +++ b/src/gallium/drivers/svga/svga_resource.c @@ -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; } diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c index 5c601f81fc7..75e27458e9c 100644 --- a/src/gallium/drivers/svga/svga_resource_texture.c +++ b/src/gallium/drivers/svga/svga_resource_texture.c @@ -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); diff --git a/src/gallium/drivers/svga/svga_winsys.h b/src/gallium/drivers/svga/svga_winsys.h index 879321f745c..19d074fd66d 100644 --- a/src/gallium/drivers/svga/svga_winsys.h +++ b/src/gallium/drivers/svga/svga_winsys.h @@ -335,6 +335,18 @@ struct svga_winsys_screen 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. * * @param usage bitmask of SVGA_BUFFER_USAGE_* flags. diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c index 1234a5edce3..4e1c41db886 100644 --- a/src/gallium/winsys/svga/drm/vmw_context.c +++ b/src/gallium/winsys/svga/drm/vmw_context.c @@ -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; } diff --git a/src/gallium/winsys/svga/drm/vmw_screen.h b/src/gallium/winsys/svga/drm/vmw_screen.h index 1a39039aabd..fd76e614a5e 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen.h +++ b/src/gallium/winsys/svga/drm/vmw_screen.h @@ -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; diff --git a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c index 9c0abe96204..c9a3b7544d2 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c +++ b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c @@ -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); } diff --git a/src/gallium/winsys/svga/drm/vmw_screen_svga.c b/src/gallium/winsys/svga/drm/vmw_screen_svga.c index 6d592f2a957..32f16cd447a 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen_svga.c +++ b/src/gallium/winsys/svga/drm/vmw_screen_svga.c @@ -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; |