#include "main/mipmap.h"
#include "drivers/common/meta.h"
#include "brw_context.h"
+#include "intel_buffer_objects.h"
#include "intel_mipmap_tree.h"
#include "intel_tex.h"
#include "intel_fbo.h"
static struct gl_texture_image *
intelNewTextureImage(struct gl_context * ctx)
{
- DBG("%s\n", __FUNCTION__);
+ DBG("%s\n", __func__);
(void) ctx;
return (struct gl_texture_image *) CALLOC_STRUCT(intel_texture_image);
}
(void) ctx;
- DBG("%s\n", __FUNCTION__);
+ DBG("%s\n", __func__);
if (obj == NULL)
return NULL;
return &obj->base;
}
-static void
+static void
intelDeleteTextureObject(struct gl_context *ctx,
struct gl_texture_object *texObj)
{
intel_miptree_match_image(intel_texobj->mt, image)) {
intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
DBG("%s: alloc obj %p level %d %dx%dx%d using object's miptree %p\n",
- __FUNCTION__, texobj, image->Level,
+ __func__, texobj, image->Level,
image->Width, image->Height, image->Depth, intel_texobj->mt);
} else {
intel_image->mt = intel_miptree_create_for_teximage(brw, intel_texobj,
intel_image,
- false);
+ 0);
/* Even if the object currently has a mipmap tree associated
* with it, this one is a more likely candidate to represent the
intel_miptree_reference(&intel_texobj->mt, intel_image->mt);
DBG("%s: alloc obj %p level %d %dx%dx%d using new miptree %p\n",
- __FUNCTION__, texobj, image->Level,
+ __func__, texobj, image->Level,
image->Width, image->Height, image->Depth, intel_image->mt);
}
/**
* ctx->Driver.AllocTextureStorage() handler.
*
- * Compare this to _mesa_alloc_texture_storage, which would call into
+ * Compare this to _mesa_AllocTextureStorage_sw, which would call into
* intel_alloc_texture_image_buffer() above.
*/
static GLboolean
first_image->TexFormat,
0, levels - 1,
width, height, depth,
- false, /* expect_accelerated */
num_samples,
- INTEL_MIPTREE_TILING_ANY);
+ MIPTREE_LAYOUT_ALLOC_ANY_TILED);
+ if (intel_texobj->mt == NULL) {
+ return false;
+ }
}
for (face = 0; face < numFaces; face++) {
intel_texobj->needs_validate = false;
intel_texobj->validated_first_level = 0;
intel_texobj->validated_last_level = levels - 1;
+ intel_texobj->_Format = intel_texobj->mt->format;
return true;
}
{
struct intel_texture_image *intelImage = intel_texture_image(texImage);
- DBG("%s\n", __FUNCTION__);
+ DBG("%s\n", __func__);
intel_miptree_release(&intelImage->mt);
GLuint x, GLuint y, GLuint w, GLuint h,
GLbitfield mode,
GLubyte **map,
- GLint *stride)
+ GLint *out_stride)
{
struct brw_context *brw = brw_context(ctx);
struct intel_texture_image *intel_image = intel_texture_image(tex_image);
struct intel_mipmap_tree *mt = intel_image->mt;
+ ptrdiff_t stride;
/* Our texture data is always stored in a miptree. */
assert(mt);
if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
slice = tex_image->Face;
- intel_miptree_map(brw, mt, tex_image->Level, slice, x, y, w, h, mode,
- (void **)map, stride);
+ intel_miptree_map(brw, mt,
+ tex_image->Level + tex_image->TexObject->MinLevel,
+ slice + tex_image->TexObject->MinLayer,
+ x, y, w, h, mode,
+ (void **)map, &stride);
+
+ *out_stride = stride;
}
static void
if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
slice = tex_image->Face;
- intel_miptree_unmap(brw, mt, tex_image->Level, slice);
+ intel_miptree_unmap(brw, mt,
+ tex_image->Level + tex_image->TexObject->MinLevel,
+ slice + tex_image->TexObject->MinLayer);
+}
+
+static GLboolean
+intel_texture_view(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ struct gl_texture_object *origTexObj)
+{
+ struct brw_context *brw = brw_context(ctx);
+ struct intel_texture_object *intel_tex = intel_texture_object(texObj);
+ struct intel_texture_object *intel_orig_tex = intel_texture_object(origTexObj);
+
+ assert(intel_orig_tex->mt);
+ intel_miptree_reference(&intel_tex->mt, intel_orig_tex->mt);
+
+ /* Since we can only make views of immutable-format textures,
+ * we can assume that everything is in origTexObj's miptree.
+ *
+ * Mesa core has already made us a copy of all the teximage objects,
+ * except it hasn't copied our mt pointers, etc.
+ */
+ const int numFaces = _mesa_num_tex_faces(texObj->Target);
+ const int numLevels = texObj->NumLevels;
+
+ int face;
+ int level;
+
+ for (face = 0; face < numFaces; face++) {
+ for (level = 0; level < numLevels; level++) {
+ struct gl_texture_image *image = texObj->Image[face][level];
+ struct intel_texture_image *intel_image = intel_texture_image(image);
+
+ intel_miptree_reference(&intel_image->mt, intel_orig_tex->mt);
+ }
+ }
+
+ /* The miptree is in a validated state, so no need to check later. */
+ intel_tex->needs_validate = false;
+ intel_tex->validated_first_level = 0;
+ intel_tex->validated_last_level = numLevels - 1;
+
+ /* Set the validated texture format, with the same adjustments that
+ * would have been applied to determine the underlying texture's
+ * mt->format.
+ */
+ intel_tex->_Format = intel_depth_format_for_depthstencil_format(
+ intel_lower_compressed_format(brw, texObj->Image[0][0]->TexFormat));
+
+ return GL_TRUE;
+}
+
+static bool
+intel_set_texture_storage_for_buffer_object(struct gl_context *ctx,
+ struct gl_texture_object *tex_obj,
+ struct gl_buffer_object *buffer_obj,
+ uint32_t buffer_offset,
+ uint32_t row_stride,
+ bool read_only)
+{
+ struct brw_context *brw = brw_context(ctx);
+ struct intel_texture_object *intel_texobj = intel_texture_object(tex_obj);
+ struct gl_texture_image *image = tex_obj->Image[0][0];
+ struct intel_texture_image *intel_image = intel_texture_image(image);
+ struct intel_buffer_object *intel_buffer_obj = intel_buffer_object(buffer_obj);
+
+ if (!read_only) {
+ /* Renderbuffers have the restriction that the buffer offset and
+ * surface pitch must be a multiple of the element size. If it's
+ * not, we have to fail and fall back to software.
+ */
+ int cpp = _mesa_get_format_bytes(image->TexFormat);
+ if (buffer_offset % cpp || row_stride % cpp) {
+ perf_debug("Bad PBO alignment; fallback to CPU mapping\n");
+ return false;
+ }
+
+ if (!brw->format_supported_as_render_target[image->TexFormat]) {
+ perf_debug("Non-renderable PBO format; fallback to CPU mapping\n");
+ return false;
+ }
+ }
+
+ assert(intel_texobj->mt == NULL);
+
+ drm_intel_bo *bo = intel_bufferobj_buffer(brw, intel_buffer_obj,
+ buffer_offset,
+ row_stride * image->Height);
+ intel_texobj->mt =
+ intel_miptree_create_for_bo(brw, bo,
+ image->TexFormat,
+ buffer_offset,
+ image->Width, image->Height, image->Depth,
+ row_stride,
+ 0);
+ if (!intel_texobj->mt)
+ return false;
+
+ if (!_swrast_init_texture_image(image))
+ return false;
+
+ intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
+
+ /* The miptree is in a validated state, so no need to check later. */
+ intel_texobj->needs_validate = false;
+ intel_texobj->validated_first_level = 0;
+ intel_texobj->validated_last_level = 0;
+ intel_texobj->_Format = intel_texobj->mt->format;
+
+ return true;
}
void
functions->AllocTextureStorage = intel_alloc_texture_storage;
functions->MapTextureImage = intel_map_texture_image;
functions->UnmapTextureImage = intel_unmap_texture_image;
+ functions->TextureView = intel_texture_view;
+ functions->SetTextureStorageForBufferObject =
+ intel_set_texture_storage_for_buffer_object;
}