freedreno: add robustness support
authorRob Clark <robdclark@chromium.org>
Tue, 16 Apr 2019 18:10:01 +0000 (11:10 -0700)
committerRob Clark <robdclark@chromium.org>
Thu, 25 Apr 2019 21:13:31 +0000 (14:13 -0700)
Signed-off-by: Rob Clark <robdclark@chromium.org>
docs/features.txt
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/freedreno/freedreno_screen.h

index 4a1f1913efd635d068f839c3c9b64d8a8b318c55..f9aa5f06d894633453eb169b9ce4b47077b90ceb 100644 (file)
@@ -274,7 +274,7 @@ GLES3.2, GLSL ES 3.2 -- all DONE: i965/gen9+, radeonsi, virgl
   GL_EXT_color_buffer_float                             DONE (all drivers)
   GL_KHR_blend_equation_advanced                        DONE (i965, nvc0)
   GL_KHR_debug                                          DONE (all drivers)
-  GL_KHR_robustness                                     DONE (i965, nvc0)
+  GL_KHR_robustness                                     DONE (freedreno, i965, nvc0)
   GL_KHR_texture_compression_astc_ldr                   DONE (freedreno, i965/gen9+)
   GL_OES_copy_image                                     DONE (all drivers)
   GL_OES_draw_buffers_indexed                           DONE (all drivers that support GL_ARB_draw_buffers_blend)
index 4e86d099974ba7878c87ca8e08289c74d69ea8c5..bf26d00bc1efe53697bb1e1c8f1d8fa2625eb13d 100644 (file)
@@ -208,6 +208,39 @@ fd_set_debug_callback(struct pipe_context *pctx,
                memset(&ctx->debug, 0, sizeof(ctx->debug));
 }
 
+static uint32_t
+fd_get_reset_count(struct fd_context *ctx, bool per_context)
+{
+       uint64_t val;
+       enum fd_param_id param =
+               per_context ? FD_CTX_FAULTS : FD_GLOBAL_FAULTS;
+       int ret = fd_pipe_get_param(ctx->pipe, param, &val);
+       debug_assert(!ret);
+       return val;
+}
+
+static enum pipe_reset_status
+fd_get_device_reset_status(struct pipe_context *pctx)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       int context_faults = fd_get_reset_count(ctx, true);
+       int global_faults  = fd_get_reset_count(ctx, false);
+       enum pipe_reset_status status;
+
+       if (context_faults != ctx->context_reset_count) {
+               status = PIPE_GUILTY_CONTEXT_RESET;
+       } else if (global_faults != ctx->global_reset_count) {
+               status = PIPE_INNOCENT_CONTEXT_RESET;
+       } else {
+               status = PIPE_NO_RESET;
+       }
+
+       ctx->context_reset_count = context_faults;
+       ctx->global_reset_count = global_faults;
+
+       return status;
+}
+
 /* TODO we could combine a few of these small buffers (solid_vbuf,
  * blit_texcoord_vbuf, and vsc_size_mem, into a single buffer and
  * save a tiny bit of memory
@@ -304,6 +337,11 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen,
        ctx->screen = screen;
        ctx->pipe = fd_pipe_new2(screen->dev, FD_PIPE_3D, prio);
 
+       if (fd_device_version(screen->dev) >= FD_VERSION_ROBUSTNESS) {
+               ctx->context_reset_count = fd_get_reset_count(ctx, true);
+               ctx->global_reset_count = fd_get_reset_count(ctx, false);
+       }
+
        ctx->primtypes = primtypes;
        ctx->primtype_mask = 0;
        for (i = 0; i < PIPE_PRIM_MAX; i++)
@@ -321,6 +359,7 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen,
        pctx->flush = fd_context_flush;
        pctx->emit_string_marker = fd_emit_string_marker;
        pctx->set_debug_callback = fd_set_debug_callback;
+       pctx->get_device_reset_status = fd_get_device_reset_status;
        pctx->create_fence_fd = fd_create_fence_fd;
        pctx->fence_server_sync = fd_fence_server_sync;
        pctx->texture_barrier = fd_texture_barrier;
index 85f17c81a9d549a533ffa471f5e7beb593717eb8..d389a42e62dfcbe5eb631fd4bb560a0df8c24360 100644 (file)
@@ -228,6 +228,14 @@ struct fd_context {
         */
        struct pipe_fence_handle *last_fence;
 
+       /* track last known reset status globally and per-context to
+        * determine if more resets occurred since then.  If global reset
+        * count increases, it means some other context crashed.  If
+        * per-context reset count increases, it means we crashed the
+        * gpu.
+        */
+       uint32_t context_reset_count, global_reset_count;
+
        /* Are we in process of shadowing a resource? Used to detect recursion
         * in transfer_map, and skip unneeded synchronization.
         */
index fdf2639071807d08bc88c6336410f3a7d553e318..58640a82b0bba992c04587caf161e308c9201d5a 100644 (file)
@@ -200,6 +200,10 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
        case PIPE_CAP_PACKED_UNIFORMS:
                return !is_a2xx(screen);
 
+       case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
+       case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
+               return screen->has_robustness;
+
        case PIPE_CAP_VERTEXID_NOBASE:
                return is_a3xx(screen) || is_a4xx(screen);
 
@@ -819,6 +823,11 @@ fd_screen_create(struct fd_device *dev, struct renderonly *ro)
                screen->priority_mask = (1 << val) - 1;
        }
 
+       if ((fd_device_version(dev) >= FD_VERSION_ROBUSTNESS) &&
+                       (fd_pipe_get_param(screen->pipe, FD_PP_PGTABLE, &val) == 0)) {
+               screen->has_robustness = val;
+       }
+
        struct sysinfo si;
        sysinfo(&si);
        screen->ram_size = si.totalram;
index d8d045a464276e51d8d479a7eb768730d0426c04..35685be1d22a85ba8ccf63dfc14ace8b2a8ad04c 100644 (file)
@@ -70,6 +70,7 @@ struct fd_screen {
        uint32_t num_vsc_pipes;
        uint32_t priority_mask;
        bool has_timestamp;
+       bool has_robustness;
 
        unsigned num_perfcntr_groups;
        const struct fd_perfcntr_group *perfcntr_groups;