summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker/st_cb_texture.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/state_tracker/st_cb_texture.c')
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c130
1 files changed, 81 insertions, 49 deletions
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 92eefca2e7..ed113b5dbc 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -49,7 +49,6 @@
#include "state_tracker/st_cb_fbo.h"
#include "state_tracker/st_cb_texture.h"
#include "state_tracker/st_format.h"
-#include "state_tracker/st_public.h"
#include "state_tracker/st_texture.h"
#include "state_tracker/st_gen_mipmap.h"
#include "state_tracker/st_inlines.h"
@@ -63,6 +62,7 @@
#include "util/u_blit.h"
#include "util/u_format.h"
#include "util/u_surface.h"
+#include "util/u_sampler.h"
#include "util/u_math.h"
@@ -122,8 +122,18 @@ st_DeleteTextureObject(GLcontext *ctx,
{
struct st_texture_object *stObj = st_texture_object(texObj);
if (stObj->pt)
- pipe_texture_reference(&stObj->pt, NULL);
-
+ pipe_resource_reference(&stObj->pt, NULL);
+ if (stObj->sampler_view) {
+ if (stObj->sampler_view->context != ctx->st->pipe) {
+ /* Take "ownership" of this texture sampler view by setting
+ * its context pointer to this context. This avoids potential
+ * crashes when the texture object is shared among contexts
+ * and the original/owner context has already been destroyed.
+ */
+ stObj->sampler_view->context = ctx->st->pipe;
+ }
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+ }
_mesa_delete_texture_object(ctx, texObj);
}
@@ -137,7 +147,7 @@ st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
DBG("%s\n", __FUNCTION__);
if (stImage->pt) {
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
}
if (texImage->Data) {
@@ -203,17 +213,17 @@ do_memcpy(void *dest, const void *src, size_t n)
static GLuint
default_usage(enum pipe_format fmt)
{
- GLuint usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ GLuint usage = PIPE_BIND_SAMPLER_VIEW;
if (util_format_is_depth_or_stencil(fmt))
- usage |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ usage |= PIPE_BIND_DEPTH_STENCIL;
else
- usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ usage |= PIPE_BIND_RENDER_TARGET;
return usage;
}
/**
- * Allocate a pipe_texture object for the given st_texture_object using
+ * Allocate a pipe_resource object for the given st_texture_object using
* the given st_texture_image to guess the mipmap size/levels.
*
* [comments...]
@@ -371,10 +381,13 @@ compress_with_blit(GLcontext * ctx,
{
const GLuint dstImageOffsets[1] = {0};
struct st_texture_image *stImage = st_texture_image(texImage);
- struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct pipe_screen *screen = pipe->screen;
gl_format mesa_format;
- struct pipe_texture templ;
- struct pipe_texture *src_tex;
+ struct pipe_resource templ;
+ struct pipe_resource *src_tex;
+ struct pipe_sampler_view view_templ;
+ struct pipe_sampler_view *src_view;
struct pipe_surface *dst_surface;
struct pipe_transfer *tex_xfer;
void *map;
@@ -387,7 +400,7 @@ compress_with_blit(GLcontext * ctx,
/* get destination surface (in the compressed texture) */
dst_surface = screen->get_tex_surface(screen, stImage->pt,
stImage->face, stImage->level, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
if (!dst_surface) {
/* can't render into this format (or other problem) */
return GL_FALSE;
@@ -409,8 +422,9 @@ compress_with_blit(GLcontext * ctx,
templ.height0 = height;
templ.depth0 = 1;
templ.last_level = 0;
- templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
- src_tex = screen->texture_create(screen, &templ);
+ templ.usage = PIPE_USAGE_DEFAULT;
+ templ.bind = PIPE_BIND_SAMPLER_VIEW;
+ src_tex = screen->resource_create(screen, &templ);
if (!src_tex)
return GL_FALSE;
@@ -421,7 +435,7 @@ compress_with_blit(GLcontext * ctx,
0, 0, 0, /* face, level are zero */
PIPE_TRANSFER_WRITE,
0, 0, width, height); /* x, y, w, h */
- map = screen->transfer_map(screen, tex_xfer);
+ map = pipe_transfer_map(pipe, tex_xfer);
_mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
map, /* dest ptr */
@@ -433,12 +447,19 @@ compress_with_blit(GLcontext * ctx,
pixels, /* source data */
unpack); /* source data packing */
- screen->transfer_unmap(screen, tex_xfer);
- screen->tex_transfer_destroy(tex_xfer);
+ pipe_transfer_unmap(pipe, tex_xfer);
+ pipe->transfer_destroy(pipe, tex_xfer);
+
+ /* Create temporary sampler view */
+ u_sampler_view_default_template(&view_templ,
+ src_tex,
+ src_tex->format);
+ src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ);
+
/* copy / compress image */
util_blit_pixels_tex(ctx->st->blit,
- src_tex, /* pipe_texture (src) */
+ src_view, /* sampler view (src) */
0, 0, /* src x0, y0 */
width, height, /* src x1, y1 */
dst_surface, /* pipe_surface (dst) */
@@ -449,7 +470,8 @@ compress_with_blit(GLcontext * ctx,
PIPE_TEX_MIPFILTER_NEAREST);
pipe_surface_reference(&dst_surface, NULL);
- pipe_texture_reference(&src_tex, NULL);
+ pipe_resource_reference(&src_tex, NULL);
+ pipe_sampler_view_reference(&src_view, NULL);
return GL_TRUE;
}
@@ -536,7 +558,7 @@ st_TexImage(GLcontext * ctx,
* Release any old malloced memory.
*/
if (stImage->pt) {
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
assert(!texImage->Data);
}
else if (texImage->Data) {
@@ -553,8 +575,9 @@ st_TexImage(GLcontext * ctx,
!st_texture_match_image(stObj->pt, &stImage->base,
stImage->face, stImage->level)) {
DBG("release it\n");
- pipe_texture_reference(&stObj->pt, NULL);
+ pipe_resource_reference(&stObj->pt, NULL);
assert(!stObj->pt);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
stObj->teximage_realloc = FALSE;
}
}
@@ -585,7 +608,7 @@ st_TexImage(GLcontext * ctx,
st_texture_match_image(stObj->pt, &stImage->base,
stImage->face, stImage->level)) {
- pipe_texture_reference(&stImage->pt, stObj->pt);
+ pipe_resource_reference(&stImage->pt, stObj->pt);
assert(stImage->pt);
}
@@ -619,7 +642,7 @@ st_TexImage(GLcontext * ctx,
screen->is_format_supported(screen,
stImage->pt->format,
stImage->pt->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
if (!pixels)
goto done;
@@ -809,16 +832,23 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct pipe_screen *screen = pipe->screen;
struct st_texture_image *stImage = st_texture_image(texImage);
+ struct st_texture_object *stObj = st_texture_object(texObj);
+ struct pipe_sampler_view *src_view =
+ st_get_texture_sampler_view(stObj, pipe);
const GLuint width = texImage->Width;
const GLuint height = texImage->Height;
struct pipe_surface *dst_surface;
- struct pipe_texture *dst_texture;
+ struct pipe_resource *dst_texture;
struct pipe_transfer *tex_xfer;
+ unsigned bind = (PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
+ PIPE_BIND_TRANSFER_READ);
/* create temp / dest surface */
- if (!util_create_rgba_surface(screen, width, height,
+ if (!util_create_rgba_surface(screen, width, height, bind,
&dst_texture, &dst_surface)) {
_mesa_problem(ctx, "util_create_rgba_surface() failed "
"in decompress_with_blit()");
@@ -827,7 +857,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
/* blit/render/decompress */
util_blit_pixels_tex(ctx->st->blit,
- stImage->pt, /* pipe_texture (src) */
+ src_view, /* pipe_resource (src) */
0, 0, /* src x0, y0 */
width, height, /* src x1, y1 */
dst_surface, /* pipe_surface (dst) */
@@ -848,7 +878,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
if (st_equal_formats(stImage->pt->format, format, type)) {
/* memcpy */
const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
- ubyte *map = screen->transfer_map(screen, tex_xfer);
+ ubyte *map = pipe_transfer_map(pipe, tex_xfer);
GLuint row;
for (row = 0; row < height; row++) {
GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
@@ -856,7 +886,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
memcpy(dest, map, bytesPerRow);
map += tex_xfer->stride;
}
- screen->transfer_unmap(screen, tex_xfer);
+ pipe_transfer_unmap(pipe, tex_xfer);
}
else {
/* format translation via floats */
@@ -871,7 +901,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
debug_printf("%s: fallback format translation\n", __FUNCTION__);
/* get float[4] rgba row from surface */
- pipe_get_tile_rgba(tex_xfer, 0, row, width, 1, rgba);
+ pipe_get_tile_rgba(pipe, tex_xfer, 0, row, width, 1, rgba);
_mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
type, dest, &ctx->Pack, transferOps);
@@ -880,7 +910,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
- screen->tex_transfer_destroy(tex_xfer);
+ pipe->transfer_destroy(pipe, tex_xfer);
/* destroy the temp / dest surface */
util_destroy_rgba_surface(dst_texture, dst_surface);
@@ -906,7 +936,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
GLubyte *dest;
if (stImage->pt &&
- util_format_is_compressed(stImage->pt->format) &&
+ util_format_is_s3tc(stImage->pt->format) &&
!compressed_dst) {
/* Need to decompress the texture.
* We'll do this by rendering a textured quad.
@@ -1041,7 +1071,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
screen->is_format_supported(screen,
stImage->pt->format,
stImage->pt->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
if (compress_with_blit(ctx, target, level,
xoffset, yoffset, zoffset,
width, height, depth,
@@ -1182,10 +1212,11 @@ st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
int srcBlockStride;
int dstBlockStride;
int y;
- enum pipe_format pformat= stImage->pt->format;
+ enum pipe_format pformat;
if (stImage->pt) {
unsigned face = _mesa_tex_target_to_face(target);
+ pformat = stImage->pt->format;
st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
PIPE_TRANSFER_WRITE);
@@ -1258,7 +1289,6 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
GLsizei width, GLsizei height)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *src_trans;
GLvoid *texDest;
enum pipe_transfer_usage transfer_usage;
@@ -1311,11 +1341,11 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
/* To avoid a large temp memory allocation, do copy row by row */
for (row = 0; row < height; row++, srcY += yStep) {
uint data[MAX_WIDTH];
- pipe_get_tile_z(src_trans, 0, srcY, width, 1, data);
+ pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
if (scaleOrBias) {
_mesa_scale_and_bias_depth_uint(ctx, width, data);
}
- pipe_put_tile_z(stImage->transfer, 0, row, width, 1, data);
+ pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
}
}
else {
@@ -1337,7 +1367,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
/* XXX this usually involves a lot of int/float conversion.
* try to avoid that someday.
*/
- pipe_get_tile_rgba(src_trans, 0, 0, width, height, tempSrc);
+ pipe_get_tile_rgba(pipe, src_trans, 0, 0, width, height, tempSrc);
/* Store into texture memory.
* Note that this does some special things such as pixel transfer
@@ -1365,7 +1395,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
}
st_texture_image_unmap(ctx->st, stImage);
- screen->tex_transfer_destroy(src_trans);
+ pipe->transfer_destroy(pipe, src_trans);
}
@@ -1541,8 +1571,7 @@ st_copy_texsubimage(GLcontext *ctx,
if (ctx->_ImageTransferState == 0x0) {
- if (pipe->surface_copy &&
- matching_base_formats &&
+ if (matching_base_formats &&
src_format == dest_format &&
!do_flip)
{
@@ -1551,7 +1580,7 @@ st_copy_texsubimage(GLcontext *ctx,
dest_surface = screen->get_tex_surface(screen, stImage->pt,
stImage->face, stImage->level,
destZ,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
/* for surface_copy(), y=0=top, always */
pipe->surface_copy(pipe,
@@ -1570,11 +1599,11 @@ st_copy_texsubimage(GLcontext *ctx,
texBaseFormat != GL_DEPTH_STENCIL &&
screen->is_format_supported(screen, src_format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER,
+ PIPE_BIND_SAMPLER_VIEW,
0) &&
screen->is_format_supported(screen, dest_format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET,
+ PIPE_BIND_RENDER_TARGET,
0)) {
/* draw textured quad to do the copy */
GLint srcY0, srcY1;
@@ -1582,7 +1611,7 @@ st_copy_texsubimage(GLcontext *ctx,
dest_surface = screen->get_tex_surface(screen, stImage->pt,
stImage->face, stImage->level,
destZ,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
if (do_flip) {
srcY1 = strb->Base.Height - srcY - height;
@@ -1594,6 +1623,7 @@ st_copy_texsubimage(GLcontext *ctx,
}
util_blit_pixels_writemask(ctx->st->blit,
strb->surface,
+ st_get_renderbuffer_sampler_view(strb, pipe),
srcX, srcY0,
srcX + width, srcY1,
dest_surface,
@@ -1721,7 +1751,7 @@ copy_image_data_to_texture(struct st_context *st,
stImage->pt, /* src texture */
stImage->face);
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
}
else if (stImage->base.Data) {
/* More straightforward upload.
@@ -1743,7 +1773,7 @@ copy_image_data_to_texture(struct st_context *st,
stImage->base.Data = NULL;
}
- pipe_texture_reference(&stImage->pt, stObj->pt);
+ pipe_resource_reference(&stImage->pt, stObj->pt);
}
@@ -1789,7 +1819,8 @@ st_finalize_texture(GLcontext *ctx,
if (firstImage->pt &&
firstImage->pt != stObj->pt &&
firstImage->pt->last_level >= stObj->lastLevel) {
- pipe_texture_reference(&stObj->pt, firstImage->pt);
+ pipe_resource_reference(&stObj->pt, firstImage->pt);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
}
/* bytes per pixel block (blocks are usually 1x1) */
@@ -1808,7 +1839,8 @@ st_finalize_texture(GLcontext *ctx,
stObj->pt->height0 != firstImage->base.Height2 ||
stObj->pt->depth0 != firstImage->base.Depth2)
{
- pipe_texture_reference(&stObj->pt, NULL);
+ pipe_resource_reference(&stObj->pt, NULL);
+ pipe_sampler_view_reference(&stObj->sampler_view, NULL);
ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
}
}