summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/softpipe
diff options
context:
space:
mode:
authorMichel Dänzer <michel@tungstengraphics.com>2007-11-30 20:48:03 +0100
committerMichel Dänzer <michel@tungstengraphics.com>2007-12-06 11:18:11 +0100
commit753db0d8407147393a7b0622ae3fa28f68d0353d (patch)
tree8c11ae7b18cb34ae65e984fc7d9be50616bf99d4 /src/mesa/pipe/softpipe
parent59356268187470c5fda9e9a1a7058607f938fb3b (diff)
Hide texture layout details from the state tracker.
pipe->get_tex_surface() has to be used for access to texture image data.
Diffstat (limited to 'src/mesa/pipe/softpipe')
-rw-r--r--src/mesa/pipe/softpipe/Makefile2
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c17
-rw-r--r--src/mesa/pipe/softpipe/sp_context.h2
-rw-r--r--src/mesa/pipe/softpipe/sp_quad_fs.c2
-rw-r--r--src/mesa/pipe/softpipe/sp_state.h31
-rw-r--r--src/mesa/pipe/softpipe/sp_state_fs.c2
-rw-r--r--src/mesa/pipe/softpipe/sp_state_sampler.c4
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.c25
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.h2
-rw-r--r--src/mesa/pipe/softpipe/sp_tex_layout.h16
-rw-r--r--src/mesa/pipe/softpipe/sp_tex_sample.c18
-rw-r--r--src/mesa/pipe/softpipe/sp_texture.c (renamed from src/mesa/pipe/softpipe/sp_tex_layout.c)214
-rw-r--r--src/mesa/pipe/softpipe/sp_texture.h18
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_cache.c4
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_cache.h2
15 files changed, 229 insertions, 130 deletions
diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile
index 59628531cc..9978884c9b 100644
--- a/src/mesa/pipe/softpipe/Makefile
+++ b/src/mesa/pipe/softpipe/Makefile
@@ -34,7 +34,7 @@ DRIVER_SOURCES = \
sp_state_rasterizer.c \
sp_state_surface.c \
sp_state_vertex.c \
- sp_tex_layout.c \
+ sp_texture.c \
sp_tex_sample.c \
sp_tile_cache.c \
sp_surface.c
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
index d5e68c189d..7a9fccce9a 100644
--- a/src/mesa/pipe/softpipe/sp_context.c
+++ b/src/mesa/pipe/softpipe/sp_context.c
@@ -40,7 +40,7 @@
#include "sp_state.h"
#include "sp_surface.h"
#include "sp_tile_cache.h"
-#include "sp_tex_layout.h"
+#include "sp_texture.h"
#include "sp_winsys.h"
@@ -98,9 +98,9 @@ softpipe_map_texture_surfaces(struct softpipe_context *sp)
uint i;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
- struct pipe_mipmap_tree *mt = sp->texture[i];
- if (mt) {
- pipe->region_map(pipe, mt->region);
+ struct softpipe_texture *spt = sp->texture[i];
+ if (spt) {
+ pipe->region_map(pipe, spt->region);
}
}
}
@@ -146,9 +146,9 @@ softpipe_unmap_texture_surfaces(struct softpipe_context *sp)
struct pipe_context *pipe = &sp->pipe;
uint i;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
- struct pipe_mipmap_tree *mt = sp->texture[i];
- if (mt) {
- pipe->region_unmap(pipe, mt->region);
+ struct softpipe_texture *spt = sp->texture[i];
+ if (spt) {
+ pipe->region_unmap(pipe, spt->region);
}
}
}
@@ -351,7 +351,8 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
softpipe->pipe.get_vendor = softpipe_get_vendor;
/* textures */
- softpipe->pipe.mipmap_tree_layout = softpipe_mipmap_tree_layout;
+ softpipe->pipe.texture_create = softpipe_texture_create;
+ softpipe->pipe.texture_release = softpipe_texture_release;
softpipe->pipe.get_tex_surface = softpipe_get_tex_surface;
/*
diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h
index 872766101d..d4763a98c6 100644
--- a/src/mesa/pipe/softpipe/sp_context.h
+++ b/src/mesa/pipe/softpipe/sp_context.h
@@ -89,7 +89,7 @@ struct softpipe_context {
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
- struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS];
+ struct softpipe_texture *texture[PIPE_MAX_SAMPLERS];
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c
index 24c8a44c47..7184fcda52 100644
--- a/src/mesa/pipe/softpipe/sp_quad_fs.c
+++ b/src/mesa/pipe/softpipe/sp_quad_fs.c
@@ -277,7 +277,7 @@ static void shade_begin(struct quad_stage *qs)
/* set TGSI sampler state that varies */
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
qss->samplers[i].state = softpipe->sampler[i];
- qss->samplers[i].texture = softpipe->texture[i];
+ qss->samplers[i].texture = &softpipe->texture[i]->base;
}
#ifdef MESA_LLVM
diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h
index 2f096a9cc9..a543735b52 100644
--- a/src/mesa/pipe/softpipe/sp_state.h
+++ b/src/mesa/pipe/softpipe/sp_state.h
@@ -52,6 +52,35 @@ struct sp_fragment_shader_state {
#endif
};
+struct softpipe_texture
+{
+ struct pipe_texture base;
+
+ /* Derived from the above:
+ */
+ unsigned pitch;
+ unsigned depth_pitch; /* per-image on i945? */
+ unsigned total_height;
+
+ unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS];
+
+ /* Explicitly store the offset of each image for each cube face or
+ * depth value. Pretty much have to accept that hardware formats
+ * are going to be so diverse that there is no unified way to
+ * compute the offsets of depth/cube images within a mipmap level,
+ * so have to store them as a lookup table:
+ */
+ unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */
+
+ /* Includes image offset tables:
+ */
+ unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS];
+
+ /* The data is held here:
+ */
+ struct pipe_region *region;
+};
+
void *
softpipe_create_alpha_test_state(struct pipe_context *,
const struct pipe_alpha_test_state *);
@@ -125,7 +154,7 @@ void softpipe_set_scissor_state( struct pipe_context *,
void softpipe_set_texture_state( struct pipe_context *,
unsigned unit,
- struct pipe_mipmap_tree * );
+ struct pipe_texture * );
void softpipe_set_viewport_state( struct pipe_context *,
const struct pipe_viewport_state * );
diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c
index 912f42d568..a360b4f02b 100644
--- a/src/mesa/pipe/softpipe/sp_state_fs.c
+++ b/src/mesa/pipe/softpipe/sp_state_fs.c
@@ -34,6 +34,8 @@
#include "pipe/draw/draw_context.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/llvm/gallivm.h"
+#include "pipe/tgsi/util/tgsi_dump.h"
+#include "pipe/tgsi/exec/tgsi_sse2.h"
void * softpipe_create_fs_state(struct pipe_context *pipe,
diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c
index 246a7d6eda..e71b9159e3 100644
--- a/src/mesa/pipe/softpipe/sp_state_sampler.c
+++ b/src/mesa/pipe/softpipe/sp_state_sampler.c
@@ -68,12 +68,12 @@ softpipe_delete_sampler_state(struct pipe_context *pipe,
void
softpipe_set_texture_state(struct pipe_context *pipe,
unsigned unit,
- struct pipe_mipmap_tree *texture)
+ struct pipe_texture *texture)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
assert(unit < PIPE_MAX_SAMPLERS);
- softpipe->texture[unit] = texture; /* ptr, not struct */
+ softpipe->texture[unit] = (struct softpipe_texture *)texture; /* ptr, not struct */
sp_tile_cache_set_texture(softpipe->tex_cache[unit], texture);
diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c
index a6ab404603..c41bbc59b9 100644
--- a/src/mesa/pipe/softpipe/sp_surface.c
+++ b/src/mesa/pipe/softpipe/sp_surface.c
@@ -565,34 +565,35 @@ z24s8_get_tile(struct pipe_surface *ps,
*/
struct pipe_surface *
softpipe_get_tex_surface(struct pipe_context *pipe,
- struct pipe_mipmap_tree *mt,
+ struct pipe_texture *pt,
unsigned face, unsigned level, unsigned zslice)
{
+ struct softpipe_texture *spt = (struct softpipe_texture *)pt;
struct pipe_surface *ps;
unsigned offset; /* in bytes */
- offset = mt->level[level].level_offset;
+ offset = spt->level_offset[level];
- if (mt->target == PIPE_TEXTURE_CUBE) {
- offset += mt->level[level].image_offset[face] * mt->cpp;
+ if (pt->target == PIPE_TEXTURE_CUBE) {
+ offset += spt->image_offset[level][face] * pt->cpp;
}
- else if (mt->target == PIPE_TEXTURE_3D) {
- offset += mt->level[level].image_offset[zslice] * mt->cpp;
+ else if (pt->target == PIPE_TEXTURE_3D) {
+ offset += spt->image_offset[level][zslice] * pt->cpp;
}
else {
assert(face == 0);
assert(zslice == 0);
}
- ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format);
+ ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format);
if (ps) {
assert(ps->format);
assert(ps->refcount);
- pipe_region_reference(&ps->region, mt->region);
- ps->cpp = mt->cpp;
- ps->width = mt->level[level].width;
- ps->height = mt->level[level].height;
- ps->pitch = mt->pitch;
+ pipe_region_reference(&ps->region, spt->region);
+ ps->cpp = pt->cpp;
+ ps->width = pt->width[level];
+ ps->height = pt->height[level];
+ ps->pitch = spt->pitch;
ps->offset = offset;
}
return ps;
diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h
index cf87e1a92c..b652e7598e 100644
--- a/src/mesa/pipe/softpipe/sp_surface.h
+++ b/src/mesa/pipe/softpipe/sp_surface.h
@@ -41,7 +41,7 @@ struct softpipe_tile_cache;
extern struct pipe_surface *
softpipe_get_tex_surface(struct pipe_context *pipe,
- struct pipe_mipmap_tree *mt,
+ struct pipe_texture *pt,
unsigned face, unsigned level, unsigned zslice);
diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.h b/src/mesa/pipe/softpipe/sp_tex_layout.h
deleted file mode 100644
index ea19c13b23..0000000000
--- a/src/mesa/pipe/softpipe/sp_tex_layout.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef SP_TEX_LAYOUT_H
-#define SP_TEX_LAYOUT_H
-
-
-struct pipe_context;
-struct pipe_mipmap_tree;
-
-
-extern boolean
-softpipe_mipmap_tree_layout(struct pipe_context *pipe,
- struct pipe_mipmap_tree *mt);
-
-
-#endif /* SP_TEX_LAYOUT_H */
-
-
diff --git a/src/mesa/pipe/softpipe/sp_tex_sample.c b/src/mesa/pipe/softpipe/sp_tex_sample.c
index 92958400fc..9e48ed0cd2 100644
--- a/src/mesa/pipe/softpipe/sp_tex_sample.c
+++ b/src/mesa/pipe/softpipe/sp_tex_sample.c
@@ -422,7 +422,7 @@ compute_lambda(struct tgsi_sampler *sampler,
dsdy = FABSF(dsdy);
rho = MAX2(dsdx, dsdy);
if (sampler->state->normalized_coords)
- rho *= sampler->texture->width0;
+ rho *= sampler->texture->width[0];
}
if (t) {
float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT];
@@ -432,7 +432,7 @@ compute_lambda(struct tgsi_sampler *sampler,
dtdy = FABSF(dtdy);
max = MAX2(dtdx, dtdy);
if (sampler->state->normalized_coords)
- max *= sampler->texture->height0;
+ max *= sampler->texture->height[0];
rho = MAX2(rho, max);
}
if (p) {
@@ -443,7 +443,7 @@ compute_lambda(struct tgsi_sampler *sampler,
dpdy = FABSF(dpdy);
max = MAX2(dpdx, dpdy);
if (sampler->state->normalized_coords)
- max *= sampler->texture->depth0;
+ max *= sampler->texture->depth[0];
rho = MAX2(rho, max);
}
@@ -620,8 +620,8 @@ sp_get_samples_2d_common(struct tgsi_sampler *sampler,
&level0, &level1, &levelBlend, &imgFilter);
if (sampler->state->normalized_coords) {
- width = sampler->texture->level[level0].width;
- height = sampler->texture->level[level0].height;
+ width = sampler->texture->width[level0];
+ height = sampler->texture->height[level0];
}
else {
width = height = 1;
@@ -757,9 +757,9 @@ sp_get_samples_3d(struct tgsi_sampler *sampler,
&level0, &level1, &levelBlend, &imgFilter);
if (sampler->state->normalized_coords) {
- width = sampler->texture->level[level0].width;
- height = sampler->texture->level[level0].height;
- depth = sampler->texture->level[level0].depth;
+ width = sampler->texture->width[level0];
+ height = sampler->texture->height[level0];
+ depth = sampler->texture->depth[level0];
}
else {
width = height = depth = 1;
@@ -883,7 +883,7 @@ sp_get_samples_cube(struct tgsi_sampler *sampler,
/**
* Called via tgsi_sampler::get_samples()
* Use the sampler's state setting to get a filtered RGBA value
- * from the sampler's texture (mipmap tree).
+ * from the sampler's texture.
*
* XXX we can implement many versions of this function, each
* tightly coded for a specific combination of sampler state
diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.c b/src/mesa/pipe/softpipe/sp_texture.c
index 8156b00301..2f9a1e9837 100644
--- a/src/mesa/pipe/softpipe/sp_tex_layout.c
+++ b/src/mesa/pipe/softpipe/sp_texture.c
@@ -33,7 +33,11 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_util.h"
-#include "sp_tex_layout.h"
+#include "pipe/p_winsys.h"
+
+#include "sp_context.h"
+#include "sp_state.h"
+#include "sp_texture.h"
/* At the moment, just make softpipe use the same layout for its
@@ -54,100 +58,105 @@ static int align(int value, int alignment)
static void
-sp_miptree_set_level_info(struct pipe_mipmap_tree *mt,
- unsigned level,
- unsigned nr_images,
- unsigned x, unsigned y, unsigned w, unsigned h, unsigned d)
+sp_miptree_set_level_info(struct softpipe_texture *spt,
+ unsigned level,
+ unsigned nr_images,
+ unsigned x, unsigned y, unsigned w, unsigned h,
+ unsigned d)
{
+ struct pipe_texture *pt = &spt->base;
+
assert(level < PIPE_MAX_TEXTURE_LEVELS);
- mt->level[level].width = w;
- mt->level[level].height = h;
- mt->level[level].depth = d;
- mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp;
- mt->level[level].nr_images = nr_images;
+ pt->width[level] = w;
+ pt->height[level] = h;
+ pt->depth[level] = d;
+
+ spt->nr_images[level] = nr_images;
+ spt->level_offset[level] = (x + y * spt->pitch) * pt->cpp;
/*
DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
- level, w, h, d, x, y, mt->level[level].level_offset);
+ level, w, h, d, x, y, spt->level_offset[level]);
*/
/* Not sure when this would happen, but anyway:
*/
- if (mt->level[level].image_offset) {
- FREE( mt->level[level].image_offset );
- mt->level[level].image_offset = NULL;
+ if (spt->image_offset[level]) {
+ FREE( spt->image_offset[level] );
+ spt->image_offset[level] = NULL;
}
assert(nr_images);
- assert(!mt->level[level].image_offset);
+ assert(!spt->image_offset[level]);
- mt->level[level].image_offset = (unsigned *) MALLOC( nr_images * sizeof(unsigned) );
- mt->level[level].image_offset[0] = 0;
+ spt->image_offset[level] = (unsigned *) MALLOC( nr_images * sizeof(unsigned) );
+ spt->image_offset[level][0] = 0;
}
static void
-sp_miptree_set_image_offset(struct pipe_mipmap_tree *mt,
- unsigned level, unsigned img, unsigned x, unsigned y)
+sp_miptree_set_image_offset(struct softpipe_texture *spt,
+ unsigned level, unsigned img, unsigned x, unsigned y)
{
if (img == 0 && level == 0)
assert(x == 0 && y == 0);
- assert(img < mt->level[level].nr_images);
+ assert(img < spt->nr_images[level]);
- mt->level[level].image_offset[img] = (x + y * mt->pitch);
+ spt->image_offset[level][img] = (x + y * spt->pitch);
/*
DBG("%s level %d img %d pos %d,%d image_offset %x\n",
- __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]);
+ __FUNCTION__, level, img, x, y, spt->image_offset[level][img]);
*/
}
static void
-sp_miptree_layout_2d( struct pipe_mipmap_tree *mt )
+sp_miptree_layout_2d( struct softpipe_texture *spt )
{
+ struct pipe_texture *pt = &spt->base;
int align_h = 2, align_w = 4;
unsigned level;
unsigned x = 0;
unsigned y = 0;
- unsigned width = mt->width0;
- unsigned height = mt->height0;
+ unsigned width = pt->width[0];
+ unsigned height = pt->height[0];
- mt->pitch = mt->width0;
+ spt->pitch = pt->width[0];
/* XXX FIX THIS:
* we use alignment=64 bytes in sp_region_alloc(). If we change
* that, change this too.
*/
- if (mt->pitch < 16)
- mt->pitch = 16;
+ if (spt->pitch < 16)
+ spt->pitch = 16;
/* May need to adjust pitch to accomodate the placement of
* the 2nd mipmap. This occurs when the alignment
* constraints of mipmap placement push the right edge of the
* 2nd mipmap out past the width of its parent.
*/
- if (mt->first_level != mt->last_level) {
- unsigned mip1_width = align(minify(mt->width0), align_w)
- + minify(minify(mt->width0));
+ if (pt->first_level != pt->last_level) {
+ unsigned mip1_width = align(minify(pt->width[0]), align_w)
+ + minify(minify(pt->width[0]));
- if (mip1_width > mt->width0)
- mt->pitch = mip1_width;
+ if (mip1_width > pt->width[0])
+ spt->pitch = mip1_width;
}
/* Pitch must be a whole number of dwords, even though we
* express it in texels.
*/
- mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp;
- mt->total_height = 0;
+ spt->pitch = align(spt->pitch * pt->cpp, 4) / pt->cpp;
+ spt->total_height = 0;
- for ( level = mt->first_level ; level <= mt->last_level ; level++ ) {
+ for ( level = pt->first_level ; level <= pt->last_level ; level++ ) {
unsigned img_height;
- sp_miptree_set_level_info(mt, level, 1, x, y, width, height, 1);
+ sp_miptree_set_level_info(spt, level, 1, x, y, width, height, 1);
- if (mt->compressed)
+ if (pt->compressed)
img_height = MAX2(1, height/4);
else
img_height = align(height, align_h);
@@ -156,11 +165,11 @@ sp_miptree_layout_2d( struct pipe_mipmap_tree *mt )
/* Because the images are packed better, the final offset
* might not be the maximal one:
*/
- mt->total_height = MAX2(mt->total_height, y + img_height);
+ spt->total_height = MAX2(spt->total_height, y + img_height);
/* Layout_below: step right after second mipmap.
*/
- if (level == mt->first_level + 1) {
+ if (level == pt->first_level + 1) {
x += align(width, align_w);
}
else {
@@ -193,16 +202,17 @@ static const int step_offsets[6][2] = {
-boolean
-softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt)
+static boolean
+softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct softpipe_texture * spt)
{
+ struct pipe_texture *pt = &spt->base;
unsigned level;
- switch (mt->target) {
+ switch (pt->target) {
case PIPE_TEXTURE_CUBE:{
- const unsigned dim = mt->width0;
+ const unsigned dim = pt->width[0];
unsigned face;
- unsigned lvlWidth = mt->width0, lvlHeight = mt->height0;
+ unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0];
assert(lvlWidth == lvlHeight); /* cubemap images are square */
@@ -211,16 +221,16 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
* or the final row of 4x4, 2x2 and 1x1 faces below this.
*/
if (dim > 32)
- mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp;
+ spt->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp;
else
- mt->pitch = 14 * 8;
+ spt->pitch = 14 * 8;
- mt->total_height = dim * 4 + 4;
+ spt->total_height = dim * 4 + 4;
/* Set all the levels to effectively occupy the whole rectangular region.
*/
- for (level = mt->first_level; level <= mt->last_level; level++) {
- sp_miptree_set_level_info(mt, level, 6,
+ for (level = pt->first_level; level <= pt->last_level; level++) {
+ sp_miptree_set_level_info(spt, level, 6,
0, 0,
lvlWidth, lvlHeight, 1);
lvlWidth /= 2;
@@ -234,16 +244,16 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
unsigned d = dim;
if (dim == 4 && face >= 4) {
- y = mt->total_height - 4;
+ y = spt->total_height - 4;
x = (face - 4) * 8;
}
- else if (dim < 4 && (face > 0 || mt->first_level > 0)) {
- y = mt->total_height - 4;
+ else if (dim < 4 && (face > 0 || pt->first_level > 0)) {
+ y = spt->total_height - 4;
x = face * 8;
}
- for (level = mt->first_level; level <= mt->last_level; level++) {
- sp_miptree_set_image_offset(mt, level, face, x, y);
+ for (level = pt->first_level; level <= pt->last_level; level++) {
+ sp_miptree_set_image_offset(spt, level, face, x, y);
d >>= 1;
@@ -262,13 +272,13 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
break;
case PIPE_TEX_FACE_POS_Z:
case PIPE_TEX_FACE_NEG_Z:
- y = mt->total_height - 4;
+ y = spt->total_height - 4;
x = (face - 4) * 8;
break;
}
case 2:
- y = mt->total_height - 4;
+ y = spt->total_height - 4;
x = 16 + face * 8;
break;
@@ -286,33 +296,33 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
break;
}
case PIPE_TEXTURE_3D:{
- unsigned width = mt->width0;
- unsigned height = mt->height0;
- unsigned depth = mt->depth0;
+ unsigned width = pt->width[0];
+ unsigned height = pt->height[0];
+ unsigned depth = pt->depth[0];
unsigned pack_x_pitch, pack_x_nr;
unsigned pack_y_pitch;
unsigned level;
- mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
- mt->total_height = 0;
+ spt->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp;
+ spt->total_height = 0;
- pack_y_pitch = MAX2(mt->height0, 2);
- pack_x_pitch = mt->pitch;
+ pack_y_pitch = MAX2(pt->height[0], 2);
+ pack_x_pitch = spt->pitch;
pack_x_nr = 1;
- for (level = mt->first_level; level <= mt->last_level; level++) {
- unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6;
+ for (level = pt->first_level; level <= pt->last_level; level++) {
+ unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6;
int x = 0;
int y = 0;
unsigned q, j;
- sp_miptree_set_level_info(mt, level, nr_images,
- 0, mt->total_height,
- width, height, depth);
+ sp_miptree_set_level_info(spt, level, nr_images,
+ 0, spt->total_height,
+ width, height, depth);
for (q = 0; q < nr_images;) {
for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
- sp_miptree_set_image_offset(mt, level, q, x, y);
+ sp_miptree_set_image_offset(spt, level, q, x, y);
x += pack_x_pitch;
}
@@ -321,12 +331,12 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
}
- mt->total_height += y;
+ spt->total_height += y;
if (pack_x_pitch > 4) {
pack_x_pitch >>= 1;
pack_x_nr <<= 1;
- assert(pack_x_pitch * pack_x_nr <= mt->pitch);
+ assert(pack_x_pitch * pack_x_nr <= spt->pitch);
}
if (pack_y_pitch > 2) {
@@ -343,7 +353,7 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
case PIPE_TEXTURE_1D:
case PIPE_TEXTURE_2D:
// case PIPE_TEXTURE_RECTANGLE:
- sp_miptree_layout_2d(mt);
+ sp_miptree_layout_2d(spt);
break;
default:
assert(0);
@@ -352,10 +362,64 @@ softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree *
/*
DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
- mt->pitch,
- mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp);
+ spt->pitch,
+ spt->total_height, pt->cpp, spt->pitch * spt->total_height * pt->cpp);
*/
return TRUE;
}
+void
+softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt)
+{
+ struct softpipe_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture),
+ sizeof(struct softpipe_texture));
+
+ if (spt) {
+ memset(&spt->base + 1, 0,
+ sizeof(struct softpipe_texture) - sizeof(struct pipe_texture));
+
+ if (softpipe_mipmap_tree_layout(pipe, spt)) {
+ spt->region = pipe->winsys->region_alloc(pipe->winsys,
+ spt->pitch * (*pt)->cpp *
+ spt->total_height,
+ PIPE_SURFACE_FLAG_TEXTURE);
+ }
+
+ if (!spt->region) {
+ FREE(spt);
+ spt = NULL;
+ }
+ }
+
+ *pt = &spt->base;
+}
+
+void
+softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt)
+{
+ if (!*pt)
+ return;
+
+ /*
+ DBG("%s %p refcount will be %d\n",
+ __FUNCTION__, (void *) *pt, (*pt)->refcount - 1);
+ */
+ if (--(*pt)->refcount <= 0) {
+ struct softpipe_texture *spt = (struct softpipe_texture *)*pt;
+ uint i;
+
+ /*
+ DBG("%s deleting %p\n", __FUNCTION__, (void *) spt);
+ */
+
+ pipe->winsys->region_release(pipe->winsys, &spt->region);
+
+ for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++)
+ if (spt->image_offset[i])
+ free(spt->image_offset[i]);
+
+ free(spt);
+ }
+ *pt = NULL;
+}
diff --git a/src/mesa/pipe/softpipe/sp_texture.h b/src/mesa/pipe/softpipe/sp_texture.h
new file mode 100644
index 0000000000..2aca57bd1d
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_texture.h
@@ -0,0 +1,18 @@
+#ifndef SP_TEXTURE_H
+#define SP_TEXTURE_H
+
+
+struct pipe_context;
+struct pipe_texture;
+
+
+extern void
+softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt);
+
+extern void
+softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt);
+
+
+#endif /* SP_TEXTURE */
+
+
diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c
index ea0c8b8f91..62ee6a27c9 100644
--- a/src/mesa/pipe/softpipe/sp_tile_cache.c
+++ b/src/mesa/pipe/softpipe/sp_tile_cache.c
@@ -51,7 +51,7 @@
struct softpipe_tile_cache
{
struct pipe_surface *surface; /**< the surface we're caching */
- struct pipe_mipmap_tree *texture; /**< if caching a texture */
+ struct pipe_texture *texture; /**< if caching a texture */
struct softpipe_cached_tile entries[NUM_ENTRIES];
uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32];
float clear_value[4];
@@ -139,7 +139,7 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc)
void
sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
- struct pipe_mipmap_tree *texture)
+ struct pipe_texture *texture)
{
uint i;
diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h
index e66fec2e20..9967aa5044 100644
--- a/src/mesa/pipe/softpipe/sp_tile_cache.h
+++ b/src/mesa/pipe/softpipe/sp_tile_cache.h
@@ -71,7 +71,7 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc);
extern void
sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
- struct pipe_mipmap_tree *texture);
+ struct pipe_texture *texture);
extern void
sp_flush_tile_cache(struct softpipe_context *softpipe,