winsys/radeon: fix a race condition between winsys_create and winsys_destroy
[mesa.git] / src / gallium / drivers / radeonsi / si_pm4.c
index 5b13285027287c9b5c3cf0080f45f28e84c43191..082da85e03dd3d7caf359102d0e3d01adbaa9bdc 100644 (file)
@@ -27,7 +27,6 @@
 #include "../radeon/r600_cs.h"
 #include "util/u_memory.h"
 #include "si_pipe.h"
-#include "si_pm4.h"
 #include "sid.h"
 
 #define NUMBER_OF_STATES (sizeof(union si_state) / sizeof(struct si_pm4_state *))
@@ -93,13 +92,15 @@ void si_pm4_set_reg(struct si_pm4_state *state, unsigned reg, uint32_t val)
 
 void si_pm4_add_bo(struct si_pm4_state *state,
                    struct r600_resource *bo,
-                   enum radeon_bo_usage usage)
+                   enum radeon_bo_usage usage,
+                  enum radeon_bo_priority priority)
 {
        unsigned idx = state->nbo++;
        assert(idx < SI_PM4_MAX_BO);
 
        r600_resource_reference(&state->bo[idx], bo);
        state->bo_usage[idx] = usage;
+       state->bo_priority[idx] = priority;
 }
 
 void si_pm4_sh_data_begin(struct si_pm4_state *state)
@@ -202,7 +203,7 @@ unsigned si_pm4_dirty_dw(struct si_context *sctx)
                count += state->ndw;
 #if SI_TRACE_CS
                /* for tracing each states */
-               if (sctx->screen->trace_bo) {
+               if (sctx->screen->b.trace_bo) {
                        count += SI_TRACE_CS_DWORDS;
                }
 #endif
@@ -216,7 +217,7 @@ void si_pm4_emit(struct si_context *sctx, struct si_pm4_state *state)
        struct radeon_winsys_cs *cs = sctx->b.rings.gfx.cs;
        for (int i = 0; i < state->nbo; ++i) {
                r600_context_bo_reloc(&sctx->b, &sctx->b.rings.gfx, state->bo[i],
-                                     state->bo_usage[i]);
+                                     state->bo_usage[i], state->bo_priority[i]);
        }
 
        memcpy(&cs->buf[cs->cdw], state->pm4, state->ndw * 4);
@@ -228,7 +229,7 @@ void si_pm4_emit(struct si_context *sctx, struct si_pm4_state *state)
        cs->cdw += state->ndw;
 
 #if SI_TRACE_CS
-       if (sctx->screen->trace_bo) {
+       if (sctx->screen->b.trace_bo) {
                si_trace_emit(sctx);
        }
 #endif
@@ -252,3 +253,10 @@ void si_pm4_reset_emitted(struct si_context *sctx)
 {
        memset(&sctx->emitted, 0, sizeof(sctx->emitted));
 }
+
+void si_pm4_cleanup(struct si_context *sctx)
+{
+       for (int i = 0; i < NUMBER_OF_STATES; ++i) {
+               si_pm4_free_state(sctx, sctx->queued.array[i], i);
+       }
+}