[Mesa-dev] [PATCH] gallium: specify resource_resolve destination via a pipe_surface

2012-07-25 Thread Christoph Bumiller
The format member of pipe_surface may differ from that of the
pipe_resource, which is used to communicate, for instance, whether
sRGB encode should be enabled in the resolve operation or not.

Fixes resolve to sRGB surfaces in mesa/st when GL_FRAMEBUFFER_SRGB
is disabled.
---
 src/gallium/drivers/nv30/nv30_miptree.c |5 +++-
 src/gallium/drivers/nv50/nv50_surface.c |   32 --
 src/gallium/drivers/nvc0/nvc0_surface.c |   32 --
 src/gallium/drivers/r300/r300_render.c  |7 +-
 src/gallium/include/pipe/p_state.h  |6 +---
 src/mesa/state_tracker/st_cb_blit.c |   15 +
 6 files changed, 39 insertions(+), 58 deletions(-)

diff --git a/src/gallium/drivers/nv30/nv30_miptree.c 
b/src/gallium/drivers/nv30/nv30_miptree.c
index 7e67729..cd6a814 100644
--- a/src/gallium/drivers/nv30/nv30_miptree.c
+++ b/src/gallium/drivers/nv30/nv30_miptree.c
@@ -153,7 +153,10 @@ nv30_resource_resolve(struct pipe_context *pipe,
 
define_rect(info-src.res, 0, 0, info-src.x0, info-src.y0,
info-src.x1 - info-src.x0, info-src.y1 - info-src.y0, src);
-   define_rect(info-dst.res, info-dst.level, 0, info-dst.x0, info-dst.y0,
+   define_rect(info-dst.surface-texture,
+   info-dst.surface-u.tex.level,
+   info-dst.surface-u.tex.first_layer,
+   info-dst.x0, info-dst.y0,
info-dst.x1 - info-dst.x0, info-dst.y1 - info-dst.y0, dst);
 
nv30_transfer_rect(nv30, BILINEAR, src, dst);
diff --git a/src/gallium/drivers/nv50/nv50_surface.c 
b/src/gallium/drivers/nv50/nv50_surface.c
index 0872f8d..ed5223b 100644
--- a/src/gallium/drivers/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nv50/nv50_surface.c
@@ -436,6 +436,7 @@ struct nv50_blitctx
   unsigned num_samplers[3];
   struct pipe_sampler_view *texture[2];
   struct nv50_tsc_entry *sampler[2];
+  enum pipe_format format;
   unsigned dirty;
} saved;
struct nv50_program vp;
@@ -661,26 +662,19 @@ nv50_blitctx_get_color_mask_and_fp(struct nv50_blitctx 
*blit,
 }
 
 static void
-nv50_blit_set_dst(struct nv50_context *nv50,
-  struct pipe_resource *res, unsigned level, unsigned layer)
+nv50_blit_set_dst(struct nv50_context *nv50, struct pipe_surface *surf,
+  struct nv50_blitctx *blit)
 {
-   struct pipe_context *pipe = nv50-base.pipe;
-   struct pipe_surface templ;
+   blit-saved.format = surf-format;
 
-   if (util_format_is_depth_or_stencil(res-format))
-  templ.format = nv50_blit_zeta_to_colour_format(res-format);
-   else
-  templ.format = res-format;
-
-   templ.usage = PIPE_USAGE_STREAM;
-   templ.u.tex.level = level;
-   templ.u.tex.first_layer = templ.u.tex.last_layer = layer;
+   if (util_format_is_depth_or_stencil(surf-format))
+  surf-format = nv50_blit_zeta_to_colour_format(surf-format);
 
-   nv50-framebuffer.cbufs[0] = nv50_miptree_surface_new(pipe, res, templ);
+   nv50-framebuffer.cbufs[0] = surf;
nv50-framebuffer.nr_cbufs = 1;
nv50-framebuffer.zsbuf = NULL;
-   nv50-framebuffer.width = nv50-framebuffer.cbufs[0]-width;
-   nv50-framebuffer.height = nv50-framebuffer.cbufs[0]-height;
+   nv50-framebuffer.width = surf-width;
+   nv50-framebuffer.height = surf-height;
 }
 
 static INLINE void
@@ -822,7 +816,7 @@ nv50_blitctx_post_blit(struct nv50_context *nv50, struct 
nv50_blitctx *blit)
 {
int s;
 
-   pipe_surface_reference(nv50-framebuffer.cbufs[0], NULL);
+   nv50-framebuffer.cbufs[0]-format = blit-saved.format;
 
nv50-framebuffer.width = blit-saved.fb.width;
nv50-framebuffer.height = blit-saved.fb.height;
@@ -862,7 +856,7 @@ nv50_resource_resolve(struct pipe_context *pipe,
struct nv50_blitctx *blit = screen-blitctx;
struct nouveau_pushbuf *push = nv50-base.pushbuf;
struct pipe_resource *src = info-src.res;
-   struct pipe_resource *dst = info-dst.res;
+   struct pipe_resource *dst = info-dst.surface-texture;
float x0, x1, y0, y1, z;
float x_range, y_range;
 
@@ -872,8 +866,8 @@ nv50_resource_resolve(struct pipe_context *pipe,
 
nv50_blitctx_pre_blit(blit, nv50);
 
-   nv50_blit_set_dst(nv50, dst, info-dst.level, info-dst.layer);
-   nv50_blit_set_src(nv50, src, 0,   info-src.layer);
+   nv50_blit_set_dst(nv50, info-dst.surface, blit);
+   nv50_blit_set_src(nv50, src, 0, info-src.layer);
 
nv50_blitctx_prepare_state(blit);
 
diff --git a/src/gallium/drivers/nvc0/nvc0_surface.c 
b/src/gallium/drivers/nvc0/nvc0_surface.c
index 607b02e..6773f96 100644
--- a/src/gallium/drivers/nvc0/nvc0_surface.c
+++ b/src/gallium/drivers/nvc0/nvc0_surface.c
@@ -457,6 +457,7 @@ struct nvc0_blitctx
   unsigned num_samplers[5];
   struct pipe_sampler_view *texture[2];
   struct nv50_tsc_entry *sampler[2];
+  enum pipe_format format;
   unsigned dirty;
} saved;
struct nvc0_program vp;
@@ -727,26 +728,19 @@ nvc0_blitctx_get_color_mask_and_fp(struct nvc0_blitctx 
*blit,
 }
 
 static void

Re: [Mesa-dev] [PATCH] gallium: specify resource_resolve destination via a pipe_surface

2012-07-25 Thread Brian Paul

On 07/25/2012 05:54 AM, Christoph Bumiller wrote:

The format member of pipe_surface may differ from that of the
pipe_resource, which is used to communicate, for instance, whether
sRGB encode should be enabled in the resolve operation or not.

Fixes resolve to sRGB surfaces in mesa/st when GL_FRAMEBUFFER_SRGB
is disabled.
---
  src/gallium/drivers/nv30/nv30_miptree.c |5 +++-
  src/gallium/drivers/nv50/nv50_surface.c |   32 --
  src/gallium/drivers/nvc0/nvc0_surface.c |   32 --
  src/gallium/drivers/r300/r300_render.c  |7 +-
  src/gallium/include/pipe/p_state.h  |6 +---
  src/mesa/state_tracker/st_cb_blit.c |   15 +
  6 files changed, 39 insertions(+), 58 deletions(-)

diff --git a/src/gallium/drivers/nv30/nv30_miptree.c 
b/src/gallium/drivers/nv30/nv30_miptree.c
index 7e67729..cd6a814 100644
--- a/src/gallium/drivers/nv30/nv30_miptree.c
+++ b/src/gallium/drivers/nv30/nv30_miptree.c
@@ -153,7 +153,10 @@ nv30_resource_resolve(struct pipe_context *pipe,

 define_rect(info-src.res, 0, 0, info-src.x0, info-src.y0,
 info-src.x1 - info-src.x0, info-src.y1 - info-src.y0,src);
-   define_rect(info-dst.res, info-dst.level, 0, info-dst.x0, info-dst.y0,
+   define_rect(info-dst.surface-texture,
+   info-dst.surface-u.tex.level,
+   info-dst.surface-u.tex.first_layer,
+   info-dst.x0, info-dst.y0,
 info-dst.x1 - info-dst.x0, info-dst.y1 - info-dst.y0,dst);

 nv30_transfer_rect(nv30, BILINEAR,src,dst);
diff --git a/src/gallium/drivers/nv50/nv50_surface.c 
b/src/gallium/drivers/nv50/nv50_surface.c
index 0872f8d..ed5223b 100644
--- a/src/gallium/drivers/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nv50/nv50_surface.c
@@ -436,6 +436,7 @@ struct nv50_blitctx
unsigned num_samplers[3];
struct pipe_sampler_view *texture[2];
struct nv50_tsc_entry *sampler[2];
+  enum pipe_format format;
unsigned dirty;
 } saved;
 struct nv50_program vp;
@@ -661,26 +662,19 @@ nv50_blitctx_get_color_mask_and_fp(struct nv50_blitctx 
*blit,
  }

  static void
-nv50_blit_set_dst(struct nv50_context *nv50,
-  struct pipe_resource *res, unsigned level, unsigned layer)
+nv50_blit_set_dst(struct nv50_context *nv50, struct pipe_surface *surf,
+  struct nv50_blitctx *blit)
  {
-   struct pipe_context *pipe =nv50-base.pipe;
-   struct pipe_surface templ;
+   blit-saved.format = surf-format;

-   if (util_format_is_depth_or_stencil(res-format))
-  templ.format = nv50_blit_zeta_to_colour_format(res-format);
-   else
-  templ.format = res-format;
-
-   templ.usage = PIPE_USAGE_STREAM;
-   templ.u.tex.level = level;
-   templ.u.tex.first_layer = templ.u.tex.last_layer = layer;
+   if (util_format_is_depth_or_stencil(surf-format))
+  surf-format = nv50_blit_zeta_to_colour_format(surf-format);

-   nv50-framebuffer.cbufs[0] = nv50_miptree_surface_new(pipe, res,templ);
+   nv50-framebuffer.cbufs[0] = surf;
 nv50-framebuffer.nr_cbufs = 1;
 nv50-framebuffer.zsbuf = NULL;
-   nv50-framebuffer.width = nv50-framebuffer.cbufs[0]-width;
-   nv50-framebuffer.height = nv50-framebuffer.cbufs[0]-height;
+   nv50-framebuffer.width = surf-width;
+   nv50-framebuffer.height = surf-height;
  }

  static INLINE void
@@ -822,7 +816,7 @@ nv50_blitctx_post_blit(struct nv50_context *nv50, struct 
nv50_blitctx *blit)
  {
 int s;

-   pipe_surface_reference(nv50-framebuffer.cbufs[0], NULL);
+   nv50-framebuffer.cbufs[0]-format = blit-saved.format;

 nv50-framebuffer.width = blit-saved.fb.width;
 nv50-framebuffer.height = blit-saved.fb.height;
@@ -862,7 +856,7 @@ nv50_resource_resolve(struct pipe_context *pipe,
 struct nv50_blitctx *blit = screen-blitctx;
 struct nouveau_pushbuf *push = nv50-base.pushbuf;
 struct pipe_resource *src = info-src.res;
-   struct pipe_resource *dst = info-dst.res;
+   struct pipe_resource *dst = info-dst.surface-texture;
 float x0, x1, y0, y1, z;
 float x_range, y_range;

@@ -872,8 +866,8 @@ nv50_resource_resolve(struct pipe_context *pipe,

 nv50_blitctx_pre_blit(blit, nv50);

-   nv50_blit_set_dst(nv50, dst, info-dst.level, info-dst.layer);
-   nv50_blit_set_src(nv50, src, 0,   info-src.layer);
+   nv50_blit_set_dst(nv50, info-dst.surface, blit);
+   nv50_blit_set_src(nv50, src, 0, info-src.layer);

 nv50_blitctx_prepare_state(blit);

diff --git a/src/gallium/drivers/nvc0/nvc0_surface.c 
b/src/gallium/drivers/nvc0/nvc0_surface.c
index 607b02e..6773f96 100644
--- a/src/gallium/drivers/nvc0/nvc0_surface.c
+++ b/src/gallium/drivers/nvc0/nvc0_surface.c
@@ -457,6 +457,7 @@ struct nvc0_blitctx
unsigned num_samplers[5];
struct pipe_sampler_view *texture[2];
struct nv50_tsc_entry *sampler[2];
+  enum pipe_format format;
unsigned dirty;
 } saved;
 struct nvc0_program vp;
@@ -727,26 +728,19 @@