summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2018-08-31 20:58:10 -0400
committerMarek Olšák <[email protected]>2018-09-07 17:59:02 -0400
commit21ca322e637291b89a445159fc45b8dbf638e6c9 (patch)
treec0f2417651f7c6dba6c0ec9da1ee6755132e7181 /src/mesa
parent9ce2cef68f37a05cd2e4e4128395af38e7be963f (diff)
st/mesa: throttle texture uploads if their memory usage goes beyond a limit
This prevents radeonsi from running out of memory. It also increases texture upload performance by being nice to the kernel memory manager.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c16
-rw-r--r--src/mesa/state_tracker/st_context.c5
-rw-r--r--src/mesa/state_tracker/st_context.h7
3 files changed, 28 insertions, 0 deletions
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 5406d0247c5..e6e27a852f5 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -1392,6 +1392,7 @@ try_pbo_upload(struct gl_context *ctx, GLuint dims,
return success;
}
+
static void
st_TexSubImage(struct gl_context *ctx, GLuint dims,
struct gl_texture_image *texImage,
@@ -1417,6 +1418,7 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims,
GLubyte *map;
unsigned dstz = texImage->Face + texImage->TexObject->MinLayer;
unsigned dst_level = 0;
+ bool throttled = false;
st_flush_bitmap_cache(st);
st_invalidate_readpix_cache(st);
@@ -1456,6 +1458,10 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims,
layer_stride = stride;
}
+ util_throttle_memory_usage(pipe, &st->throttle,
+ width * height * depth *
+ util_format_get_blocksize(dst->format));
+
u_box_3d(xoffset, yoffset, zoffset + dstz, width, height, depth, &box);
pipe->texture_subdata(pipe, dst, dst_level, 0,
&box, data, stride, layer_stride);
@@ -1561,6 +1567,11 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims,
goto fallback;
}
+ util_throttle_memory_usage(pipe, &st->throttle,
+ width * height * depth *
+ util_format_get_blocksize(src_templ.format));
+ throttled = true;
+
/* Create the source texture. */
src = screen->resource_create(screen, &src_templ);
if (!src) {
@@ -1651,6 +1662,11 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims,
return;
fallback:
+ if (!throttled) {
+ util_throttle_memory_usage(pipe, &st->throttle,
+ width * height * depth *
+ _mesa_get_format_bytes(texImage->TexFormat));
+ }
_mesa_store_texsubimage(ctx, dims, texImage, xoffset, yoffset, zoffset,
width, height, depth, format, type, pixels,
unpack);
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 146d9c629ab..354876746f4 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -275,6 +275,7 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
/* free glReadPixels cache data */
st_invalidate_readpix_cache(st);
+ util_throttle_deinit(st->pipe->screen, &st->throttle);
cso_destroy_context(st->cso_context);
@@ -467,6 +468,10 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS)
? true : false;
+ util_throttle_init(&st->throttle,
+ screen->get_param(screen,
+ PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET));
+
/* GL limits and extensions */
st_init_limits(pipe->screen, &ctx->Const, &ctx->Extensions, ctx->API);
st_init_extensions(pipe->screen, &ctx->Const,
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 6b1b5633ecc..14b9b018809 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -32,6 +32,7 @@
#include "state_tracker/st_api.h"
#include "main/fbobject.h"
#include "state_tracker/st_atom.h"
+#include "util/u_helpers.h"
#include "util/u_inlines.h"
#include "util/list.h"
#include "vbo/vbo.h"
@@ -302,6 +303,12 @@ struct st_context
/* Winsys buffers */
struct list_head winsys_buffers;
+
+ /* Throttling for texture uploads and similar operations to limit memory
+ * usage by limiting the number of in-flight operations based on
+ * the estimated allocated size needed to execute those operations.
+ */
+ struct util_throttle throttle;
};