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