1bf215546Sopenharmony_ci#include "crocus_context.h" 2bf215546Sopenharmony_ci#include "crocus_fine_fence.h" 3bf215546Sopenharmony_ci#include "util/u_upload_mgr.h" 4bf215546Sopenharmony_ci 5bf215546Sopenharmony_cistatic void 6bf215546Sopenharmony_cicrocus_fine_fence_reset(struct crocus_batch *batch) 7bf215546Sopenharmony_ci{ 8bf215546Sopenharmony_ci u_upload_alloc(batch->fine_fences.uploader, 9bf215546Sopenharmony_ci 0, sizeof(uint64_t), sizeof(uint64_t), 10bf215546Sopenharmony_ci &batch->fine_fences.ref.offset, &batch->fine_fences.ref.res, 11bf215546Sopenharmony_ci (void **)&batch->fine_fences.map); 12bf215546Sopenharmony_ci WRITE_ONCE(*batch->fine_fences.map, 0); 13bf215546Sopenharmony_ci batch->fine_fences.next++; 14bf215546Sopenharmony_ci} 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_civoid 17bf215546Sopenharmony_cicrocus_fine_fence_init(struct crocus_batch *batch) 18bf215546Sopenharmony_ci{ 19bf215546Sopenharmony_ci batch->fine_fences.ref.res = NULL; 20bf215546Sopenharmony_ci batch->fine_fences.next = 0; 21bf215546Sopenharmony_ci if (batch_has_fine_fence(batch)) 22bf215546Sopenharmony_ci crocus_fine_fence_reset(batch); 23bf215546Sopenharmony_ci} 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_cistatic uint32_t 26bf215546Sopenharmony_cicrocus_fine_fence_next(struct crocus_batch *batch) 27bf215546Sopenharmony_ci{ 28bf215546Sopenharmony_ci if (!batch_has_fine_fence(batch)) 29bf215546Sopenharmony_ci return UINT32_MAX; 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci uint32_t seqno = batch->fine_fences.next++; 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci if (batch->fine_fences.next == 0) 34bf215546Sopenharmony_ci crocus_fine_fence_reset(batch); 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci return seqno; 37bf215546Sopenharmony_ci} 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_civoid 40bf215546Sopenharmony_cicrocus_fine_fence_destroy(struct crocus_screen *screen, 41bf215546Sopenharmony_ci struct crocus_fine_fence *fine) 42bf215546Sopenharmony_ci{ 43bf215546Sopenharmony_ci crocus_syncobj_reference(screen, &fine->syncobj, NULL); 44bf215546Sopenharmony_ci pipe_resource_reference(&fine->ref.res, NULL); 45bf215546Sopenharmony_ci free(fine); 46bf215546Sopenharmony_ci} 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistruct crocus_fine_fence * 49bf215546Sopenharmony_cicrocus_fine_fence_new(struct crocus_batch *batch, unsigned flags) 50bf215546Sopenharmony_ci{ 51bf215546Sopenharmony_ci struct crocus_fine_fence *fine = calloc(1, sizeof(*fine)); 52bf215546Sopenharmony_ci if (!fine) 53bf215546Sopenharmony_ci return NULL; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci pipe_reference_init(&fine->reference, 1); 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci fine->seqno = crocus_fine_fence_next(batch); 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci crocus_syncobj_reference(batch->screen, &fine->syncobj, 60bf215546Sopenharmony_ci crocus_batch_get_signal_syncobj(batch)); 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci if (!batch_has_fine_fence(batch)) 63bf215546Sopenharmony_ci return fine; 64bf215546Sopenharmony_ci pipe_resource_reference(&fine->ref.res, batch->fine_fences.ref.res); 65bf215546Sopenharmony_ci fine->ref.offset = batch->fine_fences.ref.offset; 66bf215546Sopenharmony_ci fine->map = batch->fine_fences.map; 67bf215546Sopenharmony_ci fine->flags = flags; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci unsigned pc; 70bf215546Sopenharmony_ci if (flags & CROCUS_FENCE_TOP_OF_PIPE) { 71bf215546Sopenharmony_ci pc = PIPE_CONTROL_WRITE_IMMEDIATE | PIPE_CONTROL_CS_STALL; 72bf215546Sopenharmony_ci } else { 73bf215546Sopenharmony_ci pc = PIPE_CONTROL_WRITE_IMMEDIATE | 74bf215546Sopenharmony_ci PIPE_CONTROL_RENDER_TARGET_FLUSH | 75bf215546Sopenharmony_ci PIPE_CONTROL_TILE_CACHE_FLUSH | 76bf215546Sopenharmony_ci PIPE_CONTROL_DEPTH_CACHE_FLUSH | 77bf215546Sopenharmony_ci PIPE_CONTROL_DATA_CACHE_FLUSH; 78bf215546Sopenharmony_ci } 79bf215546Sopenharmony_ci crocus_emit_pipe_control_write(batch, "fence: fine", pc, 80bf215546Sopenharmony_ci crocus_resource_bo(fine->ref.res), 81bf215546Sopenharmony_ci fine->ref.offset, 82bf215546Sopenharmony_ci fine->seqno); 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci return fine; 85bf215546Sopenharmony_ci} 86