[Mesa-dev] [PATCH 7/7] i965: Drop non-LLC lunacy in the program cache code.

Chris Wilson chris at chris-wilson.co.uk
Sat Jul 22 09:28:06 UTC 2017


Quoting Kenneth Graunke (2017-07-22 00:17:47)
>  src/mesa/drivers/dri/i965/brw_program_cache.c | 83 +++++++--------------------
>  1 file changed, 21 insertions(+), 62 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_program_cache.c b/src/mesa/drivers/dri/i965/brw_program_cache.c
> index 04682bef34c..8d83af71d3a 100644
> --- a/src/mesa/drivers/dri/i965/brw_program_cache.c
> +++ b/src/mesa/drivers/dri/i965/brw_program_cache.c
> @@ -45,6 +45,8 @@
>   */
>  
>  #include "main/imports.h"
> +#include "main/streaming-load-memcpy.h"
> +#include "x86/common_x86_asm.h"
>  #include "intel_batchbuffer.h"
>  #include "brw_state.h"
>  #include "brw_wm.h"
> @@ -214,32 +216,28 @@ brw_cache_new_bo(struct brw_cache *cache, uint32_t new_size)
>  {
>     struct brw_context *brw = cache->brw;
>     struct brw_bo *new_bo;
> -   void *llc_map;
>  
>     new_bo = brw_bo_alloc(brw->bufmgr, "program cache", new_size, 64);
>     if (can_do_exec_capture(brw->screen))
>        new_bo->kflags = EXEC_OBJECT_CAPTURE;
> -   if (brw->has_llc) {
> -      llc_map = brw_bo_map(brw, new_bo, MAP_READ | MAP_WRITE |
> -                                        MAP_ASYNC | MAP_PERSISTENT);
> -   }
> +
> +   void *map = brw_bo_map(brw, new_bo, MAP_READ | MAP_WRITE |
> +                                       MAP_ASYNC | MAP_PERSISTENT);
>  
>     /* Copy any existing data that needs to be saved. */
>     if (cache->next_offset != 0) {
> -      if (brw->has_llc) {
> -         memcpy(llc_map, cache->map, cache->next_offset);
> -      } else {
> -         void *map = brw_bo_map(brw, cache->bo, MAP_READ);
> -         brw_bo_subdata(new_bo, 0, cache->next_offset, map);
> -         brw_bo_unmap(cache->bo);
> -      }
> +#ifdef USE_SSE41
> +      if (!cache->bo->cache_coherent && cpu_has_sse4_1)
> +         _mesa_streaming_load_memcpy(map, cache->map, cache->next_offset);
> +      else
> +#endif
> +         memcpy(map, cache->map, cache->next_offset);

Considering the prevalence of sse4.1, another candidate is
brw_get_buffer_subdata(), we could use a WC map there as well.

diff --git a/src/mesa/drivers/dri/i965/intel_buffer_objects.c b/src/mesa/drivers/dri/i965/intel_buffer_objects.c
index e932badaaf..705ade8021 100644
--- a/src/mesa/drivers/dri/i965/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/i965/intel_buffer_objects.c
@@ -32,7 +32,9 @@
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "main/macros.h"
+#include "main/streaming-load-memcpy.h"
 #include "main/bufferobj.h"
+#include "x86/common_x86_asm.h"
 
 #include "brw_context.h"
 #include "intel_blit.h"
@@ -337,16 +339,24 @@ brw_get_buffer_subdata(struct gl_context *ctx,
       intel_batchbuffer_flush(brw);
    }
 
-   void *map = brw_bo_map(brw, intel_obj->buffer, MAP_READ);
-
-   if (unlikely(!map)) {
-      _mesa_error_no_memory(__func__);
-      return;
+   if (!intel_obj->buffer->cache_coherent && cpu_has_sse4_1) {
+      void *map = brw_bo_map(brw, intel_obj->buffer, MAP_READ | MAP_COHERENT);
+      if (unlikely(!map)) {
+         _mesa_error_no_memory(__func__);
+         return;
+      }
+      _mesa_streaming_load_memcpy(data, map + offset, size);
+      brw_bo_unmap(intel_obj->buffer);
+   } else {
+      void *map = brw_bo_map(brw, intel_obj->buffer, MAP_READ);
+      if (unlikely(!map)) {
+         _mesa_error_no_memory(__func__);
+         return;
+      }
+      memcpy(data, map + offset, size);
+      brw_bo_unmap(intel_obj->buffer);
    }
 
-   memcpy(data, map + offset, size);
-   brw_bo_unmap(intel_obj->buffer);
-
    mark_buffer_inactive(intel_obj);
 }
 

I didn't see any other obvious candidates, the query readback objects I
suggest to use snooping instead.
-Chris


More information about the mesa-dev mailing list