summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/svga
diff options
context:
space:
mode:
authorCharmaine Lee <charmainel@vmware.com>2014-08-12 07:37:12 -0600
committerBrian Paul <brianp@vmware.com>2014-08-12 08:03:24 -0600
commit0c065270c0ff063edba03516b22d734023cac912 (patch)
tree33a6cf749f9a93cf1f24c3c9c747f659d28c3e97 /src/gallium/drivers/svga
parentd839be24b3b53717fcc153c3d00afb1c516d926e (diff)
downloadexternal_mesa3d-0c065270c0ff063edba03516b22d734023cac912.zip
external_mesa3d-0c065270c0ff063edba03516b22d734023cac912.tar.gz
external_mesa3d-0c065270c0ff063edba03516b22d734023cac912.tar.bz2
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>
Diffstat (limited to 'src/gallium/drivers/svga')
-rw-r--r--src/gallium/drivers/svga/include/svga3d_surfacedefs.h5
-rw-r--r--src/gallium/drivers/svga/include/svga_reg.h10
-rw-r--r--src/gallium/drivers/svga/svga_resource.c43
-rw-r--r--src/gallium/drivers/svga/svga_resource_texture.c6
-rw-r--r--src/gallium/drivers/svga/svga_winsys.h12
5 files changed, 71 insertions, 5 deletions
diff --git a/src/gallium/drivers/svga/include/svga3d_surfacedefs.h b/src/gallium/drivers/svga/include/svga3d_surfacedefs.h
index 9afdd46..8763cdf 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 3ba010e..e75b442 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 79951b3..b295b44 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 5c601f8..75e2745 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 879321f..19d074f 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.