17ec681f3Smrg/*
27ec681f3Smrg * Copyright © 2019 Intel Corporation
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice shall be included
127ec681f3Smrg * in all copies or substantial portions of the Software.
137ec681f3Smrg *
147ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
157ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
177ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
197ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
207ec681f3Smrg * DEALINGS IN THE SOFTWARE.
217ec681f3Smrg */
227ec681f3Smrg
237ec681f3Smrg#include "iris_perf.h"
247ec681f3Smrg#include "iris_context.h"
257ec681f3Smrg
267ec681f3Smrgstatic void *
277ec681f3Smrgiris_oa_bo_alloc(void *bufmgr, const char *name, uint64_t size)
287ec681f3Smrg{
297ec681f3Smrg   return iris_bo_alloc(bufmgr, name, size, 1, IRIS_MEMZONE_OTHER, BO_ALLOC_SMEM);
307ec681f3Smrg}
317ec681f3Smrg
327ec681f3Smrgstatic void
337ec681f3Smrgiris_perf_emit_stall_at_pixel_scoreboard(struct iris_context *ice)
347ec681f3Smrg{
357ec681f3Smrg   iris_emit_end_of_pipe_sync(&ice->batches[IRIS_BATCH_RENDER],
367ec681f3Smrg                              "OA metrics",
377ec681f3Smrg                              PIPE_CONTROL_STALL_AT_SCOREBOARD);
387ec681f3Smrg}
397ec681f3Smrg
407ec681f3Smrgstatic void
417ec681f3Smrgiris_perf_emit_mi_report_perf_count(void *c,
427ec681f3Smrg                                       void *bo,
437ec681f3Smrg                                       uint32_t offset_in_bytes,
447ec681f3Smrg                                       uint32_t report_id)
457ec681f3Smrg{
467ec681f3Smrg   struct iris_context *ice = c;
477ec681f3Smrg   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
487ec681f3Smrg   batch->screen->vtbl.emit_mi_report_perf_count(batch, bo, offset_in_bytes, report_id);
497ec681f3Smrg}
507ec681f3Smrg
517ec681f3Smrgstatic void
527ec681f3Smrgiris_perf_batchbuffer_flush(void *c, const char *file, int line)
537ec681f3Smrg{
547ec681f3Smrg   struct iris_context *ice = c;
557ec681f3Smrg   _iris_batch_flush(&ice->batches[IRIS_BATCH_RENDER], __FILE__, __LINE__);
567ec681f3Smrg}
577ec681f3Smrg
587ec681f3Smrgstatic void
597ec681f3Smrgiris_perf_store_register_mem(void *ctx, void *bo,
607ec681f3Smrg                             uint32_t reg, uint32_t reg_size,
617ec681f3Smrg                             uint32_t offset)
627ec681f3Smrg{
637ec681f3Smrg   struct iris_context *ice = ctx;
647ec681f3Smrg   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
657ec681f3Smrg   if (reg_size == 8) {
667ec681f3Smrg      batch->screen->vtbl.store_register_mem64(batch, reg, bo, offset, false);
677ec681f3Smrg   } else {
687ec681f3Smrg      assert(reg_size == 4);
697ec681f3Smrg      batch->screen->vtbl.store_register_mem32(batch, reg, bo, offset, false);
707ec681f3Smrg   }
717ec681f3Smrg}
727ec681f3Smrg
737ec681f3Smrgtypedef void (*bo_unreference_t)(void *);
747ec681f3Smrgtypedef void *(*bo_map_t)(void *, void *, unsigned flags);
757ec681f3Smrgtypedef void (*bo_unmap_t)(void *);
767ec681f3Smrgtypedef void (*emit_mi_report_t)(void *, void *, uint32_t, uint32_t);
777ec681f3Smrgtypedef void (*emit_mi_flush_t)(void *);
787ec681f3Smrgtypedef void (*store_register_mem_t)(void *ctx, void *bo,
797ec681f3Smrg                                     uint32_t reg, uint32_t reg_size,
807ec681f3Smrg                                     uint32_t offset);
817ec681f3Smrgtypedef bool (*batch_references_t)(void *batch, void *bo);
827ec681f3Smrgtypedef void (*bo_wait_rendering_t)(void *bo);
837ec681f3Smrgtypedef int (*bo_busy_t)(void *bo);
847ec681f3Smrg
857ec681f3Smrgvoid
867ec681f3Smrgiris_perf_init_vtbl(struct intel_perf_config *perf_cfg)
877ec681f3Smrg{
887ec681f3Smrg   perf_cfg->vtbl.bo_alloc = iris_oa_bo_alloc;
897ec681f3Smrg   perf_cfg->vtbl.bo_unreference = (bo_unreference_t)iris_bo_unreference;
907ec681f3Smrg   perf_cfg->vtbl.bo_map = (bo_map_t)iris_bo_map;
917ec681f3Smrg   perf_cfg->vtbl.bo_unmap = (bo_unmap_t)iris_bo_unmap;
927ec681f3Smrg   perf_cfg->vtbl.emit_stall_at_pixel_scoreboard =
937ec681f3Smrg      (emit_mi_flush_t)iris_perf_emit_stall_at_pixel_scoreboard;
947ec681f3Smrg
957ec681f3Smrg   perf_cfg->vtbl.emit_mi_report_perf_count =
967ec681f3Smrg      (emit_mi_report_t)iris_perf_emit_mi_report_perf_count;
977ec681f3Smrg   perf_cfg->vtbl.batchbuffer_flush = iris_perf_batchbuffer_flush;
987ec681f3Smrg   perf_cfg->vtbl.store_register_mem =
997ec681f3Smrg      (store_register_mem_t) iris_perf_store_register_mem;
1007ec681f3Smrg   perf_cfg->vtbl.batch_references = (batch_references_t)iris_batch_references;
1017ec681f3Smrg   perf_cfg->vtbl.bo_wait_rendering =
1027ec681f3Smrg      (bo_wait_rendering_t)iris_bo_wait_rendering;
1037ec681f3Smrg   perf_cfg->vtbl.bo_busy = (bo_busy_t)iris_bo_busy;
1047ec681f3Smrg}
105