1 #include "iris_context.h"
2 #include "iris_fine_fence.h"
3 #include "util/u_upload_mgr.h"
4
5 static void
iris_fine_fence_reset(struct iris_batch * batch)6 iris_fine_fence_reset(struct iris_batch *batch)
7 {
8 u_upload_alloc(batch->fine_fences.uploader,
9 0, sizeof(uint64_t), sizeof(uint64_t),
10 &batch->fine_fences.ref.offset, &batch->fine_fences.ref.res,
11 (void **)&batch->fine_fences.map);
12 WRITE_ONCE(*batch->fine_fences.map, 0);
13 batch->fine_fences.next++;
14 }
15
16 void
iris_fine_fence_init(struct iris_batch * batch)17 iris_fine_fence_init(struct iris_batch *batch)
18 {
19 batch->fine_fences.ref.res = NULL;
20 batch->fine_fences.next = 0;
21 iris_fine_fence_reset(batch);
22 }
23
24 static uint32_t
iris_fine_fence_next(struct iris_batch * batch)25 iris_fine_fence_next(struct iris_batch *batch)
26 {
27 uint32_t seqno = batch->fine_fences.next++;
28
29 if (batch->fine_fences.next == 0)
30 iris_fine_fence_reset(batch);
31
32 return seqno;
33 }
34
35 void
iris_fine_fence_destroy(struct iris_screen * screen,struct iris_fine_fence * fine)36 iris_fine_fence_destroy(struct iris_screen *screen,
37 struct iris_fine_fence *fine)
38 {
39 iris_syncobj_reference(screen->bufmgr, &fine->syncobj, NULL);
40 pipe_resource_reference(&fine->ref.res, NULL);
41 free(fine);
42 }
43
44 struct iris_fine_fence *
iris_fine_fence_new(struct iris_batch * batch,unsigned flags)45 iris_fine_fence_new(struct iris_batch *batch, unsigned flags)
46 {
47 struct iris_fine_fence *fine = calloc(1, sizeof(*fine));
48 if (!fine)
49 return NULL;
50
51 pipe_reference_init(&fine->reference, 1);
52
53 fine->seqno = iris_fine_fence_next(batch);
54
55 iris_syncobj_reference(batch->screen->bufmgr, &fine->syncobj,
56 iris_batch_get_signal_syncobj(batch));
57
58 pipe_resource_reference(&fine->ref.res, batch->fine_fences.ref.res);
59 fine->ref.offset = batch->fine_fences.ref.offset;
60 fine->map = batch->fine_fences.map;
61 fine->flags = flags;
62
63 unsigned pc;
64 if (flags & IRIS_FENCE_TOP_OF_PIPE) {
65 pc = PIPE_CONTROL_WRITE_IMMEDIATE | PIPE_CONTROL_CS_STALL;
66 } else {
67 pc = PIPE_CONTROL_WRITE_IMMEDIATE |
68 PIPE_CONTROL_RENDER_TARGET_FLUSH |
69 PIPE_CONTROL_TILE_CACHE_FLUSH |
70 PIPE_CONTROL_DEPTH_CACHE_FLUSH |
71 PIPE_CONTROL_DATA_CACHE_FLUSH;
72 }
73 iris_emit_pipe_control_write(batch, "fence: fine", pc,
74 iris_resource_bo(fine->ref.res),
75 fine->ref.offset,
76 fine->seqno);
77
78 return fine;
79 }
80