swr: [rasterizer core] implement InnerConservative input coverage
[mesa.git] / src / gallium / drivers / swr / rasterizer / core / rdtsc_core.h
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 FEProcessStoreTiles,
65 FEProcessInvalidateTiles,
66 WorkerWorkOnFifoBE,
67 WorkerFoundWork,
68 BELoadTiles,
69 BEDispatch,
70 BEClear,
71 BERasterizeLine,
72 BERasterizeTriangle,
73 BETriangleSetup,
74 BEStepSetup,
75 BECullZeroArea,
76 BEEmptyTriangle,
77 BETrivialAccept,
78 BETrivialReject,
79 BERasterizePartial,
80 BEPixelBackend,
81 BESetup,
82 BEBarycentric,
83 BEEarlyDepthTest,
84 BEPixelShader,
85 BESingleSampleBackend,
86 BEPixelRateBackend,
87 BESampleRateBackend,
88 BENullBackend,
89 BELateDepthTest,
90 BEOutputMerger,
91 BEStoreTiles,
92 BEEndTile,
93 WorkerWaitForThreadEvent,
94
95 NumBuckets
96 };
97
98 void rdtscReset();
99 void rdtscInit(int threadId);
100 void rdtscStart(uint32_t bucketId);
101 void rdtscStop(uint32_t bucketId, uint32_t count, uint64_t drawId);
102 void rdtscEvent(uint32_t bucketId, uint32_t count1, uint32_t count2);
103 void rdtscEndFrame();
104
105 #ifdef KNOB_ENABLE_RDTSC
106 #define RDTSC_RESET() rdtscReset()
107 #define RDTSC_INIT(threadId) rdtscInit(threadId)
108 #define RDTSC_START(bucket) rdtscStart(bucket)
109 #define RDTSC_STOP(bucket, count, draw) rdtscStop(bucket, count, draw)
110 #define RDTSC_EVENT(bucket, count1, count2) rdtscEvent(bucket, count1, count2)
111 #define RDTSC_ENDFRAME() rdtscEndFrame()
112 #else
113 #define RDTSC_RESET()
114 #define RDTSC_INIT(threadId)
115 #define RDTSC_START(bucket)
116 #define RDTSC_STOP(bucket, count, draw)
117 #define RDTSC_EVENT(bucket, count1, count2)
118 #define RDTSC_ENDFRAME()
119 #endif
120
121 extern std::vector<uint32_t> gBucketMap;
122 extern BucketManager gBucketMgr;
123 extern BUCKET_DESC gCoreBuckets[];
124 extern uint32_t gCurrentFrame;
125 extern bool gBucketsInitialized;
126
127 INLINE void rdtscReset()
128 {
129 gCurrentFrame = 0;
130 gBucketMgr.ClearThreads();
131 }
132
133 INLINE void rdtscInit(int threadId)
134 {
135 // register all the buckets once
136 if (!gBucketsInitialized && (threadId == 0))
137 {
138 gBucketMap.resize(NumBuckets);
139 for (uint32_t i = 0; i < NumBuckets; ++i)
140 {
141 gBucketMap[i] = gBucketMgr.RegisterBucket(gCoreBuckets[i]);
142 }
143 gBucketsInitialized = true;
144 }
145
146 std::string name = threadId == 0 ? "API" : "WORKER";
147 gBucketMgr.RegisterThread(name);
148 }
149
150 INLINE void rdtscStart(uint32_t bucketId)
151 {
152 uint32_t id = gBucketMap[bucketId];
153 gBucketMgr.StartBucket(id);
154 }
155
156 INLINE void rdtscStop(uint32_t bucketId, uint32_t count, uint64_t drawId)
157 {
158 uint32_t id = gBucketMap[bucketId];
159 gBucketMgr.StopBucket(id);
160 }
161
162 INLINE void rdtscEvent(uint32_t bucketId, uint32_t count1, uint32_t count2)
163 {
164 uint32_t id = gBucketMap[bucketId];
165 gBucketMgr.AddEvent(id, count1);
166 }
167
168 INLINE void rdtscEndFrame()
169 {
170 gCurrentFrame++;
171
172 if (gCurrentFrame == KNOB_BUCKETS_START_FRAME && KNOB_BUCKETS_START_FRAME < KNOB_BUCKETS_END_FRAME)
173 {
174 gBucketMgr.StartCapture();
175 }
176
177 if (gCurrentFrame == KNOB_BUCKETS_END_FRAME && KNOB_BUCKETS_START_FRAME < KNOB_BUCKETS_END_FRAME)
178 {
179 gBucketMgr.StopCapture();
180 gBucketMgr.PrintReport("rdtsc.txt");
181 }
182 }