summaryrefslogtreecommitdiff
path: root/src/sna/gen6_common.h
blob: 4bf69b110102f802c5c557c82097ff2f699107d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * Copyright © 2011-2013 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Authors:
 *    Chris Wilson <chris@chris-wilson.co.uk>
 *
 */

#ifndef GEN6_COMMON_H
#define GEN6_COMMON_H

#include "sna.h"

#define NO_RING_SWITCH(sna) (!(sna)->kgem.has_semaphores)
#define PREFER_RENDER 0 /* -1 -> BLT, 1 -> RENDER */

static inline bool is_uncached(struct sna *sna,
			       struct kgem_bo *bo)
{
	return bo->io || (bo->scanout && !sna->kgem.has_wt);
}

inline static bool can_switch_to_blt(struct sna *sna,
				     struct kgem_bo *bo,
				     unsigned flags)
{
	if (sna->kgem.ring != KGEM_RENDER)
		return true;

	if (NO_RING_SWITCH(sna))
		return false;

	if (bo && RQ_IS_BLT(bo->rq))
		return true;

	if (bo && bo->tiling == I915_TILING_Y)
		return false;

	if (sna->render_state.gt < 2)
		return true;

	if (bo && RQ_IS_RENDER(bo->rq))
		return false;

	if (flags & COPY_LAST)
		return true;

	return kgem_ring_is_idle(&sna->kgem, KGEM_BLT);
}

static inline bool untiled_tlb_miss(struct kgem_bo *bo)
{
	if (kgem_bo_is_render(bo))
		return false;

	return bo->tiling == I915_TILING_NONE && bo->pitch >= 4096;
}

static int prefer_blt_bo(struct sna *sna,
			 struct kgem_bo *src,
			 struct kgem_bo *dst)
{
	assert(dst != NULL);

	if (PREFER_RENDER)
		return PREFER_RENDER < 0;

	if (dst->rq)
		return RQ_IS_BLT(dst->rq);

	if (sna->flags & SNA_POWERSAVE)
		return true;

	if (src) {
		if (sna->render_state.gt > 1)
			return false;

		if (src->rq)
			return RQ_IS_BLT(src->rq);

		if (src->tiling == I915_TILING_Y)
			return false;
        } else {
                if (sna->render_state.gt > 2)
                        return false;
        }

	if (sna->render_state.gt < 2)
		return true;

	return dst->tiling == I915_TILING_NONE || is_uncached(sna, dst);
}

inline static bool force_blt_ring(struct sna *sna)
{
	if (sna->kgem.mode == KGEM_RENDER)
		return false;

	if (NO_RING_SWITCH(sna))
		return sna->kgem.ring == KGEM_BLT;

	if (sna->flags & SNA_POWERSAVE)
		return true;

	if (sna->render_state.gt < 2)
		return true;

	return false;
}

nonnull inline static bool
prefer_blt_ring(struct sna *sna, struct kgem_bo *bo, unsigned flags)
{
	if (PREFER_RENDER)
		return PREFER_RENDER < 0;

	assert(!force_blt_ring(sna));
	assert(!kgem_bo_is_render(bo) || NO_RING_SWITCH(sna));

	if (kgem_bo_is_blt(bo))
		return true;

	return can_switch_to_blt(sna, bo, flags);
}

nonnull inline static bool
prefer_render_ring(struct sna *sna, struct kgem_bo *bo)
{
	if (sna->kgem.ring == KGEM_RENDER)
		return true;

	if (sna->kgem.ring != KGEM_NONE && NO_RING_SWITCH(sna))
                return false;

	if (kgem_bo_is_render(bo))
		return true;

	if (sna->flags & SNA_POWERSAVE)
		return false;

	if (!prefer_blt_bo(sna, NULL, bo))
		return true;

	return !kgem_ring_is_idle(&sna->kgem, KGEM_RENDER);
}

inline static bool
prefer_blt_composite(struct sna *sna, struct sna_composite_op *tmp)
{
	if (PREFER_RENDER)
		return PREFER_RENDER < 0;

	if (untiled_tlb_miss(tmp->dst.bo) ||
	    untiled_tlb_miss(tmp->src.bo))
		return true;

	if (force_blt_ring(sna))
		return true;

	if (prefer_render_ring(sna, tmp->dst.bo))
		return false;

	if (!prefer_blt_ring(sna, tmp->dst.bo, 0))
		return false;

	return prefer_blt_bo(sna, tmp->src.bo, tmp->dst.bo);
}

nonnull static inline bool
prefer_blt_fill(struct sna *sna, struct kgem_bo *bo, unsigned flags)
{
	if (PREFER_RENDER)
		return PREFER_RENDER < 0;

	if (untiled_tlb_miss(bo))
		return true;

	if (force_blt_ring(sna))
		return true;

	if ((flags & (FILL_POINTS | FILL_SPANS)) == 0) {
		if (prefer_render_ring(sna, bo))
			return false;

		if (!prefer_blt_ring(sna, bo, 0))
			return false;
	} else {
	    if (can_switch_to_blt(sna, bo, 0))
		    return true;
	}

	return prefer_blt_bo(sna, NULL, bo);
}

void gen6_render_context_switch(struct kgem *kgem, int new_mode);
void gen6_render_retire(struct kgem *kgem);

#endif /* GEN6_COMMON_H */