Commit 8911b7d7a1d6ddce6bfe149cd785e163e10a1fd5

  • avatar
  • Chia-I Wu <olvaffe @gm…l.com>
  • Thu Sep 24 04:09:32 CEST 2009
egl_android: Merge tiling support from eagle.
  
4242#include "droid.h"
4343#include "droid_ui.h"
4444
45#define INTEL_IS_I965(x) ((x) & INTEL_GEN_4)
46#define INTEL_IS_I915(x) ((x) & INTEL_GEN_3)
47#define INTEL_IS_I9xx(x) ((x) & (INTEL_GEN_3 | INTEL_GEN_4))
48#define INTEL_IS_I8xx(x) ((x) & (INTEL_GEN_1 | INTEL_GEN_2))
49
4550#define INTEL_STRIDE_ALIGNMENT 64
4651
52#define INTEL_HAS_128_BYTE_Y_TILING(x) \
53 (((x) & (INTEL_GEN_3 | INTEL_GEN_4 | INTEL_GEN_MINOR_MASK)) > INTEL_GEN_3)
54
4755enum {
4856 INTEL_SURFACE_TYPE_WINDOW,
4957 INTEL_SURFACE_TYPE_IMAGE,
5058};
5159
60/* Look at xf86-video-intel/src/common.h for the full horror of device
61 * identification.
62 */
63enum {
64 INTEL_GEN_1 = 0x10,
65 INTEL_GEN_2 = 0x20,
66 INTEL_GEN_3 = 0x40,
67 INTEL_GEN_31 = 0x41,
68 INTEL_GEN_4 = 0x80,
69
70 INTEL_GEN_MAJOR_MASK = 0xf0,
71 INTEL_GEN_MINOR_MASK = 0x0f,
72};
73
5274struct droid_backend_intel {
5375 struct droid_backend base;
5476 int fd;
132132 return (value + align - 1) & ~(align - 1);
133133}
134134
135static uint32_t
136tiling_stride(int dev, int tiling_mode, uint32_t pitch)
137{
138 uint32_t tile_width;
139
140 if (tiling_mode == I915_TILING_NONE)
141 return pitch;
142
143 if (tiling_mode == I915_TILING_Y && INTEL_HAS_128_BYTE_Y_TILING(dev))
144 tile_width = 128;
145 else
146 tile_width = 512;
147
148 /* 965+ just needs multiples of tile width */
149 if (INTEL_IS_I965(dev))
150 return align_to(pitch, tile_width);
151
152 /* Pre-965 needs power of two tile widths */
153 while (tile_width < pitch)
154 tile_width <<= 1;
155
156 return tile_width;
157}
158
159static uint32_t
160tiling_size(int dev, uint32_t tiling, uint32_t size)
161{
162 uint32_t fence;
163
164 if (tiling == I915_TILING_NONE)
165 return size;
166
167 /* The 965 can have fences at any page boundary. */
168 if (INTEL_IS_I965(dev))
169 return align_to(size, 4096);
170
171 /* Align the size to a power of two greater than the smallest fence. */
172 if (INTEL_IS_I9xx(dev))
173 fence = 1024 * 1024; /* 1 MiB */
174 else
175 fence = 512 * 1024; /* 512 KiB */
176 while (fence < size)
177 fence <<= 1;
178
179 return fence;
180}
181
135182static int
136183create_buffer(int fd, GLint width, GLint height, GLint cpp, __DRIbuffer *buffer)
137184{
138185 struct drm_i915_gem_create create;
139186 struct drm_gem_flink flink;
140187 uint32_t size;
188 int tiling;
189 int dev = INTEL_GEN_4; /* XXX query using I915_GETPARAM + PARAM_CHIPSET_ID */
141190
191 tiling = I915_TILING_X;
142192 buffer->pitch = align_to(width * cpp, INTEL_STRIDE_ALIGNMENT);
143 size = buffer->pitch * height;
193 if (tiling != I915_TILING_NONE) {
194 buffer->pitch = tiling_stride(dev, tiling, buffer->pitch);
195 size = buffer->pitch * height;
196 size = tiling_size(dev, tiling, size);
197 } else {
198 size = buffer->pitch * height;
199 }
200
144201 create.size = size;
145202 if (ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create)) {
146203 LOGE("failed to create buffer");
147204 return 0;
205 }
206
207 if (tiling != I915_TILING_NONE) {
208 struct drm_i915_gem_set_tiling set_tiling;
209
210 memset(&set_tiling, 0, sizeof(set_tiling));
211 set_tiling.handle = create.handle;
212 set_tiling.tiling_mode = tiling;
213 set_tiling.stride = buffer->pitch;
214
215 if (ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling))
216 LOGW("failed to enable tiling");
148217 }
149218
150219 flink.handle = create.handle;