29
29
#include "intel_mipmap_tree.h"
30
30
#include "intel_regions.h"
31
31
#include "intel_tex_layout.h"
33
#include "brw_state.h"
35
32
#include "main/enums.h"
33
#include "main/formats.h"
37
35
#define FILE_DEBUG_FLAG DEBUG_MIPTREE
136
133
* pitch == 0 || height == 0 indicates the null texture
138
if (!mt || !mt->pitch || !mt->total_height) {
135
if (!mt || !mt->total_height) {
143
mt->region = intel_region_alloc(intel,
140
mt->region = intel_region_alloc(intel->intelScreen,
147
144
mt->total_height,
148
145
expect_accelerated_upload);
149
mt->pitch = mt->region->pitch;
151
147
if (!mt->region) {
180
/* The mipmap tree pitch is aligned to 64 bytes to make sure render
181
* to texture works, but we don't need that for texturing from a
182
* pixmap. Just override it here. */
183
mt->pitch = region->pitch;
185
176
intel_region_reference(&mt->region, region);
192
* intel_miptree_pitch_align:
194
* @intel: intel context pointer
196
* @mt: the miptree to compute pitch alignment for
198
* @pitch: the natural pitch value
200
* Given @pitch, compute a larger value which accounts for
201
* any necessary alignment required by the device
203
int intel_miptree_pitch_align (struct intel_context *intel,
204
struct intel_mipmap_tree *mt,
209
GLcontext *ctx = &intel->ctx;
212
if (!mt->compressed) {
215
/* XXX: Align pitch to multiple of 64 bytes for now to allow
216
* render-to-texture to work in all cases. This should probably be
217
* replaced at some point by some scheme to only do this when really
222
if (tiling == I915_TILING_X)
224
else if (tiling == I915_TILING_Y)
227
pitch = ALIGN(pitch * mt->cpp, pitch_align);
230
/* Do a little adjustment to linear allocations so that we avoid
231
* hitting the same channel of memory for 2 different pages when
232
* reading a 2x2 subspan or doing bilinear filtering.
234
if (tiling == I915_TILING_NONE && !(pitch & 511) &&
235
(pitch + pitch_align) < (1 << ctx->Const.MaxTextureLevels))
236
pitch += pitch_align;
246
182
intel_miptree_reference(struct intel_mipmap_tree **dst,
247
183
struct intel_mipmap_tree *src)
266
202
DBG("%s deleting %p\n", __FUNCTION__, *mt);
269
/* Free up cached binding tables holding a reference on our buffer, to
270
* avoid excessive memory consumption.
272
* This isn't as aggressive as we could be, as we'd like to do
273
* it from any time we free the last ref on a region. But intel_region.c
274
* is context-agnostic. Perhaps our constant state cache should be, as
277
brw_state_cache_bo_delete(&brw_context(&intel->ctx)->surface_cache,
278
(*mt)->region->buffer);
281
204
intel_region_release(&((*mt)->region));
283
206
for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
341
264
mt->level[level].width = w;
342
265
mt->level[level].height = h;
343
266
mt->level[level].depth = d;
344
mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp;
345
267
mt->level[level].level_x = x;
346
268
mt->level[level].level_y = y;
347
269
mt->level[level].nr_images = nr_images;
349
DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
350
level, w, h, d, x, y, mt->level[level].level_offset);
271
DBG("%s level %d size: %d,%d,%d offset %d,%d\n", __FUNCTION__,
272
level, w, h, d, x, y);
352
274
assert(nr_images);
353
275
assert(!mt->level[level].x_offset);
414
336
DBG("%s \n", __FUNCTION__);
417
*row_stride = mt->pitch * mt->cpp;
339
*row_stride = mt->region->pitch * mt->cpp;
419
341
if (mt->target == GL_TEXTURE_3D) {
424
346
intel_miptree_get_image_offset(mt, level, face, i,
426
image_offsets[i] = x + y * mt->pitch;
348
image_offsets[i] = x + y * mt->region->pitch;
429
351
return intel_region_map(intel, mt->region);
526
448
src_ptr = intel_region_map(intel, src->region);
527
449
dst_ptr = intel_region_map(intel, dst->region);
529
_mesa_copy_rect(dst_ptr + dst->cpp * (dst_x + dst_y * dst->pitch),
451
_mesa_copy_rect(dst_ptr,
533
src_ptr + src->cpp * (src_x + src_y * src->pitch),
454
dst_x, dst_y, width, height,
536
458
intel_region_unmap(intel, src->region);
537
459
intel_region_unmap(intel, dst->region);