Home | History | Annotate | Download | only in core
      1 /****************************************************************************
      2 * Copyright (C) 2014-2015 Intel Corporation.   All Rights Reserved.
      3 *
      4 * Permission is hereby granted, free of charge, to any person obtaining a
      5 * copy of this software and associated documentation files (the "Software"),
      6 * to deal in the Software without restriction, including without limitation
      7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 * and/or sell copies of the Software, and to permit persons to whom the
      9 * Software is furnished to do so, subject to the following conditions:
     10 *
     11 * The above copyright notice and this permission notice (including the next
     12 * paragraph) shall be included in all copies or substantial portions of the
     13 * Software.
     14 *
     15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     21 * IN THE SOFTWARE.
     22 ****************************************************************************/
     23 
     24 #pragma once
     25 #include "knobs.h"
     26 
     27 #include "common/os.h"
     28 #include "common/rdtsc_buckets.h"
     29 
     30 #include <vector>
     31 
     32 enum CORE_BUCKETS
     33 {
     34     APIClearRenderTarget,
     35     APIDraw,
     36     APIDrawWakeAllThreads,
     37     APIDrawIndexed,
     38     APIDispatch,
     39     APIStoreTiles,
     40     APIGetDrawContext,
     41     APISync,
     42     APIWaitForIdle,
     43     FEProcessDraw,
     44     FEProcessDrawIndexed,
     45     FEFetchShader,
     46     FEVertexShader,
     47     FEHullShader,
     48     FETessellation,
     49     FEDomainShader,
     50     FEGeometryShader,
     51     FEStreamout,
     52     FEPAAssemble,
     53     FEBinPoints,
     54     FEBinLines,
     55     FEBinTriangles,
     56     FETriangleSetup,
     57     FEViewportCull,
     58     FEGuardbandClip,
     59     FEClipPoints,
     60     FEClipLines,
     61     FEClipTriangles,
     62     FECullZeroAreaAndBackface,
     63     FECullBetweenCenters,
     64     FEEarlyRastEnter,
     65     FEEarlyRastExit,
     66     FEProcessStoreTiles,
     67     FEProcessInvalidateTiles,
     68     WorkerWorkOnFifoBE,
     69     WorkerFoundWork,
     70     BELoadTiles,
     71     BEDispatch,
     72     BEClear,
     73     BERasterizeLine,
     74     BERasterizeTriangle,
     75     BETriangleSetup,
     76     BEStepSetup,
     77     BECullZeroArea,
     78     BEEmptyTriangle,
     79     BETrivialAccept,
     80     BETrivialReject,
     81     BERasterizePartial,
     82     BEPixelBackend,
     83     BESetup,
     84     BEBarycentric,
     85     BEEarlyDepthTest,
     86     BEPixelShader,
     87     BESingleSampleBackend,
     88     BEPixelRateBackend,
     89     BESampleRateBackend,
     90     BENullBackend,
     91     BELateDepthTest,
     92     BEOutputMerger,
     93     BEStoreTiles,
     94     BEEndTile,
     95 
     96     NumBuckets
     97 };
     98 
     99 void rdtscReset();
    100 void rdtscInit(int threadId);
    101 void rdtscStart(uint32_t bucketId);
    102 void rdtscStop(uint32_t bucketId, uint32_t count, uint64_t drawId);
    103 void rdtscEvent(uint32_t bucketId, uint32_t count1, uint32_t count2);
    104 void rdtscEndFrame();
    105 
    106 #ifdef KNOB_ENABLE_RDTSC
    107 #define RDTSC_RESET() rdtscReset()
    108 #define RDTSC_INIT(threadId) rdtscInit(threadId)
    109 #define RDTSC_START(bucket) rdtscStart(bucket)
    110 #define RDTSC_STOP(bucket, count, draw) rdtscStop(bucket, count, draw)
    111 #define RDTSC_EVENT(bucket, count1, count2) rdtscEvent(bucket, count1, count2)
    112 #define RDTSC_ENDFRAME() rdtscEndFrame()
    113 #else
    114 #define RDTSC_RESET()
    115 #define RDTSC_INIT(threadId)
    116 #define RDTSC_START(bucket)
    117 #define RDTSC_STOP(bucket, count, draw)
    118 #define RDTSC_EVENT(bucket, count1, count2)
    119 #define RDTSC_ENDFRAME()
    120 #endif
    121 
    122 extern std::vector<uint32_t> gBucketMap;
    123 extern BucketManager gBucketMgr;
    124 extern BUCKET_DESC gCoreBuckets[];
    125 extern uint32_t gCurrentFrame;
    126 extern bool gBucketsInitialized;
    127 
    128 INLINE void rdtscReset()
    129 {
    130     gCurrentFrame = 0;
    131     gBucketMgr.ClearThreads();
    132 }
    133 
    134 INLINE void rdtscInit(int threadId)
    135 {
    136     // register all the buckets once
    137     if (!gBucketsInitialized && (threadId == 0))
    138     {
    139         gBucketMap.resize(NumBuckets);
    140         for (uint32_t i = 0; i < NumBuckets; ++i)
    141         {
    142             gBucketMap[i] = gBucketMgr.RegisterBucket(gCoreBuckets[i]);
    143         }
    144         gBucketsInitialized = true;
    145     }
    146 
    147     std::string name = threadId == 0 ? "API" : "WORKER";
    148     gBucketMgr.RegisterThread(name);
    149 }
    150 
    151 INLINE void rdtscStart(uint32_t bucketId)
    152 {
    153     uint32_t id = gBucketMap[bucketId];
    154     gBucketMgr.StartBucket(id);
    155 }
    156 
    157 INLINE void rdtscStop(uint32_t bucketId, uint32_t count, uint64_t drawId)
    158 {
    159     uint32_t id = gBucketMap[bucketId];
    160     gBucketMgr.StopBucket(id);
    161 }
    162 
    163 INLINE void rdtscEvent(uint32_t bucketId, uint32_t count1, uint32_t count2)
    164 {
    165     uint32_t id = gBucketMap[bucketId];
    166     gBucketMgr.AddEvent(id, count1);
    167 }
    168 
    169 INLINE void rdtscEndFrame()
    170 {
    171     gCurrentFrame++;
    172 
    173     if (gCurrentFrame == KNOB_BUCKETS_START_FRAME && KNOB_BUCKETS_START_FRAME < KNOB_BUCKETS_END_FRAME)
    174     {
    175         gBucketMgr.StartCapture();
    176     }
    177 
    178     if (gCurrentFrame == KNOB_BUCKETS_END_FRAME && KNOB_BUCKETS_START_FRAME < KNOB_BUCKETS_END_FRAME)
    179     {
    180         gBucketMgr.StopCapture();
    181         gBucketMgr.PrintReport("rdtsc.txt");
    182     }
    183 }
    184