static __DRIbuffer * intelAllocateBuffer(__DRIscreen *screen, unsigned attachment, unsigned format, int width, int height) { struct intel_buffer *intelBuffer; struct intel_screen *intelScreen = screen->driverPrivate; assert(attachment == __DRI_BUFFER_FRONT_LEFT || attachment == __DRI_BUFFER_BACK_LEFT); intelBuffer = calloc(1, sizeof *intelBuffer); if (intelBuffer == NULL) return NULL; /* The front and back buffers are color buffers, which are X tiled. */ intelBuffer->region = intel_region_alloc(intelScreen, I915_TILING_X, format / 8, width, height, true); if (intelBuffer->region == NULL) { free(intelBuffer); return NULL; } intel_region_flink(intelBuffer->region, &intelBuffer->base.name); intelBuffer->base.attachment = attachment; intelBuffer->base.cpp = intelBuffer->region->cpp; intelBuffer->base.pitch = intelBuffer->region->pitch; return &intelBuffer->base; }
struct intel_mipmap_tree * intel_miptree_create(struct intel_context *intel, GLenum target, GLenum internal_format, GLuint first_level, GLuint last_level, GLuint width0, GLuint height0, GLuint depth0, GLuint cpp, GLuint compress_byte, GLboolean expect_accelerated_upload) { struct intel_mipmap_tree *mt; mt = intel_miptree_create_internal(intel, target, internal_format, first_level, last_level, width0, height0, depth0, cpp, compress_byte); /* * pitch == 0 || height == 0 indicates the null texture */ if (!mt || !mt->pitch || !mt->total_height) return NULL; mt->region = intel_region_alloc(intel, mt->cpp, mt->pitch, mt->total_height, mt->pitch, expect_accelerated_upload); if (!mt->region) { free(mt); return NULL; } return mt; }
struct intel_mipmap_tree * intel_miptree_create(struct intel_context *intel, GLenum target, mesa_format format, GLuint first_level, GLuint last_level, GLuint width0, GLuint height0, GLuint depth0, bool expect_accelerated_upload, enum intel_miptree_tiling_mode requested_tiling) { struct intel_mipmap_tree *mt; GLuint total_width, total_height; mt = intel_miptree_create_layout(intel, target, format, first_level, last_level, width0, height0, depth0, false); /* * pitch == 0 || height == 0 indicates the null texture */ if (!mt || !mt->total_width || !mt->total_height) { intel_miptree_release(&mt); return NULL; } total_width = mt->total_width; total_height = mt->total_height; uint32_t tiling = intel_miptree_choose_tiling(intel, format, width0, requested_tiling, mt); bool y_or_x = tiling == (I915_TILING_Y | I915_TILING_X); mt->region = intel_region_alloc(intel->intelScreen, y_or_x ? I915_TILING_Y : tiling, mt->cpp, total_width, total_height, expect_accelerated_upload); /* If the region is too large to fit in the aperture, we need to use the * BLT engine to support it. The BLT paths can't currently handle Y-tiling, * so we need to fall back to X. */ if (y_or_x && mt->region->bo->size >= intel->max_gtt_map_object_size) { perf_debug("%dx%d miptree larger than aperture; falling back to X-tiled\n", mt->total_width, mt->total_height); intel_region_release(&mt->region); mt->region = intel_region_alloc(intel->intelScreen, I915_TILING_X, mt->cpp, total_width, total_height, expect_accelerated_upload); } mt->offset = 0; if (!mt->region) { intel_miptree_release(&mt); return NULL; } return mt; }
/** * Called via glRenderbufferStorageEXT() to set the format and allocate * storage for a user-created renderbuffer. */ static GLboolean intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height) { struct intel_context *intel = intel_context(ctx); struct intel_renderbuffer *irb = intel_renderbuffer(rb); int cpp; GLuint pitch; ASSERT(rb->Name != 0); switch (internalFormat) { case GL_R3_G3_B2: case GL_RGB4: case GL_RGB5: rb->Format = MESA_FORMAT_RGB565; rb->DataType = GL_UNSIGNED_BYTE; break; case GL_RGB: case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: rb->Format = MESA_FORMAT_XRGB8888; rb->DataType = GL_UNSIGNED_BYTE; break; case GL_RGBA: case GL_RGBA2: case GL_RGBA4: case GL_RGB5_A1: case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: case GL_RGBA16: rb->Format = MESA_FORMAT_ARGB8888; rb->DataType = GL_UNSIGNED_BYTE; break; case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: /* alloc a depth+stencil buffer */ rb->Format = MESA_FORMAT_S8_Z24; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; break; case GL_DEPTH_COMPONENT16: rb->Format = MESA_FORMAT_Z16; rb->DataType = GL_UNSIGNED_SHORT; break; case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT32: rb->Format = MESA_FORMAT_S8_Z24; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; break; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: rb->Format = MESA_FORMAT_S8_Z24; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; break; default: _mesa_problem(ctx, "Unexpected format in intel_alloc_renderbuffer_storage"); return GL_FALSE; } rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat); cpp = _mesa_get_format_bytes(rb->Format); intelFlush(ctx); /* free old region */ if (irb->region) { intel_region_release(&irb->region); } /* allocate new memory region/renderbuffer */ /* Choose a pitch to match hardware requirements: */ pitch = ((cpp * width + 63) & ~63) / cpp; /* alloc hardware renderbuffer */ DBG("Allocating %d x %d Intel RBO (pitch %d)\n", width, height, pitch); irb->region = intel_region_alloc(intel, I915_TILING_NONE, cpp, width, height, pitch, GL_TRUE); if (!irb->region) return GL_FALSE; /* out of memory? */ ASSERT(irb->region->buffer); rb->Width = width; rb->Height = height; return GL_TRUE; }
struct intel_mipmap_tree * intel_miptree_create(struct intel_context *intel, GLenum target, GLenum internal_format, GLuint first_level, GLuint last_level, GLuint width0, GLuint height0, GLuint depth0, GLuint cpp, GLuint compress_byte) { GLboolean ok; struct intel_mipmap_tree *mt = calloc(sizeof(*mt), 1); DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); mt->target = target_to_target(target); mt->internal_format = internal_format; mt->first_level = first_level; mt->last_level = last_level; mt->width0 = width0; mt->height0 = height0; mt->depth0 = depth0; mt->cpp = compress_byte ? compress_byte : cpp; mt->compressed = compress_byte ? 1 : 0; mt->refcount = 1; mt->pitch = 0; switch (intel->intelScreen->deviceID) { case PCI_CHIP_I945_G: case PCI_CHIP_I945_GM: case PCI_CHIP_I945_GME: case PCI_CHIP_G33_G: case PCI_CHIP_Q33_G: case PCI_CHIP_Q35_G: ok = i945_miptree_layout(intel, mt); break; case PCI_CHIP_I915_G: case PCI_CHIP_I915_GM: case PCI_CHIP_I830_M: case PCI_CHIP_I855_GM: case PCI_CHIP_I865_G: default: /* All the i830 chips and the i915 use this layout: */ ok = i915_miptree_layout(intel, mt); break; } if (ok) { assert (mt->pitch); mt->region = intel_region_alloc(intel->intelScreen, mt->cpp, mt->pitch, mt->total_height); } if (!mt->region) { free(mt); return NULL; } return mt; }
/** * Called via glRenderbufferStorageEXT() to set the format and allocate * storage for a user-created renderbuffer. */ static GLboolean intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height) { struct intel_context *intel = intel_context(ctx); struct intel_renderbuffer *irb = intel_renderbuffer(rb); GLboolean softwareBuffer = GL_FALSE; int cpp; ASSERT(rb->Name != 0); switch (internalFormat) { case GL_R3_G3_B2: case GL_RGB4: case GL_RGB5: rb->_ActualFormat = GL_RGB5; rb->DataType = GL_UNSIGNED_BYTE; rb->RedBits = 5; rb->GreenBits = 6; rb->BlueBits = 5; cpp = 2; break; case GL_RGB: case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: case GL_RGBA: case GL_RGBA2: case GL_RGBA4: case GL_RGB5_A1: case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: case GL_RGBA16: rb->_ActualFormat = GL_RGBA8; rb->DataType = GL_UNSIGNED_BYTE; rb->RedBits = 8; rb->GreenBits = 8; rb->BlueBits = 8; rb->AlphaBits = 8; cpp = 4; break; case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: /* alloc a depth+stencil buffer */ rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; rb->StencilBits = 8; cpp = 4; break; case GL_DEPTH_COMPONENT16: rb->_ActualFormat = GL_DEPTH_COMPONENT16; rb->DataType = GL_UNSIGNED_SHORT; rb->DepthBits = 16; cpp = 2; break; case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT32: rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; rb->DepthBits = 24; cpp = 4; break; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT; rb->DataType = GL_UNSIGNED_INT_24_8_EXT; rb->DepthBits = 24; rb->StencilBits = 8; cpp = 4; break; default: _mesa_problem(ctx, "Unexpected format in intel_alloc_renderbuffer_storage"); return GL_FALSE; } intelFlush(ctx); /* free old region */ if (irb->region) { intel_region_release(&irb->region); } /* allocate new memory region/renderbuffer */ if (softwareBuffer) { return _mesa_soft_renderbuffer_storage(ctx, rb, internalFormat, width, height); } else { /* Choose a pitch to match hardware requirements: */ GLuint pitch = ((cpp * width + 63) & ~63) / cpp; /* alloc hardware renderbuffer */ DBG("Allocating %d x %d Intel RBO (pitch %d)\n", width, height, pitch); irb->region = intel_region_alloc(intel, cpp, pitch, height); if (!irb->region) return GL_FALSE; /* out of memory? */ ASSERT(irb->region->buffer); rb->Width = width; rb->Height = height; /* This sets the Get/PutRow/Value functions */ intel_set_span_functions(&irb->Base); return GL_TRUE; } }