From 5e0c956cb219e54dfc22e64ac3f00e22619c763f Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Tue, 29 Jan 2013 12:52:17 -0500 Subject: r600g: add cs memory usage accounting and limit it v3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are now seing cs that can go over the vram+gtt size to avoid failing flush early cs that goes over 70% (gtt+vram) usage. 70% is use to allow some fragmentation. The idea is to compute a gross estimate of memory requirement of each draw call. After each draw call, memory will be precisely accounted. So the uncertainty is only on the current draw call. In practice this gave very good estimate (+/- 10% of the target memory limit). v2: Remove left over from testing version, remove useless NULL checking. Improve commit message. v3: Add comment to code on memory accounting precision Signed-off-by: Jerome Glisse Reviewed-by: Marek Olšák --- src/gallium/winsys/radeon/drm/radeon_drm_cs.c | 11 +++++++++++ src/gallium/winsys/radeon/drm/radeon_winsys.h | 10 ++++++++++ 2 files changed, 21 insertions(+) (limited to 'src/gallium/winsys/radeon/drm') diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c index cab27040bba..6a7115ba76b 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c @@ -383,6 +383,16 @@ static boolean radeon_drm_cs_validate(struct radeon_winsys_cs *rcs) return status; } +static boolean radeon_drm_cs_memory_below_limit(struct radeon_winsys_cs *rcs, uint64_t vram, uint64_t gtt) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + boolean status = + (cs->csc->used_gart + gtt) < cs->ws->info.gart_size * 0.7 && + (cs->csc->used_vram + vram) < cs->ws->info.vram_size * 0.7; + + return status; +} + static void radeon_drm_cs_write_reloc(struct radeon_winsys_cs *rcs, struct radeon_winsys_cs_handle *buf) { @@ -575,6 +585,7 @@ void radeon_drm_cs_init_functions(struct radeon_drm_winsys *ws) ws->base.cs_destroy = radeon_drm_cs_destroy; ws->base.cs_add_reloc = radeon_drm_cs_add_reloc; ws->base.cs_validate = radeon_drm_cs_validate; + ws->base.cs_memory_below_limit = radeon_drm_cs_memory_below_limit; ws->base.cs_write_reloc = radeon_drm_cs_write_reloc; ws->base.cs_flush = radeon_drm_cs_flush; ws->base.cs_set_flush_callback = radeon_drm_cs_set_flush; diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h index 7fdef3fad87..8b64ef2e1a1 100644 --- a/src/gallium/winsys/radeon/drm/radeon_winsys.h +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h @@ -392,6 +392,16 @@ struct radeon_winsys { */ boolean (*cs_validate)(struct radeon_winsys_cs *cs); + /** + * Return TRUE if there is enough memory in VRAM and GTT for the relocs + * added so far. + * + * \param cs A command stream to validate. + * \param vram VRAM memory size pending to be use + * \param gtt GTT memory size pending to be use + */ + boolean (*cs_memory_below_limit)(struct radeon_winsys_cs *cs, uint64_t vram, uint64_t gtt); + /** * Write a relocated dword to a command buffer. * -- cgit v1.2.3