[Mesa-dev] [Bug 43629] mesa># gmake freebsd-dri-amd64 breaks

2011-12-18 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=43629

--- Comment #5 from zap...@berentweb.com 2011-12-18 01:17:11 PST ---
EDIT: I have conflicting information here about NOUVEAU.  Since my card is
Radeon, I should not be using any nouveau (NVidia) modules as far as I
understand. However, the build is checking for nouveau. So I am confused now.
Should I use nouveau or not? If not, how do I modify the build / autogen?

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
--- You are receiving this mail because: ---
You are the assignee for the bug.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 0/2 v3] Add support for clip distances in Gallium

2011-12-18 Thread Christoph Bumiller
On 17.12.2011 23:15, Bryan Cain wrote:
> This is the third revision of my changes to add support for gl_ClipDistance
> with Gallium.  The difference between this set and v2 is that this set does
> not add a new TGSI_PROPERTY indicating the number of clip distances used.
> Instead, the UsageMask of the CLIPDIST output registers is set to indicate
> which clip distances are used.  Some changes to ureg were necessary to set
> the UsageMask to a value other than XYZW.
 
Looks like it would work, except that the final write to the clip
distance output writes invalid (undeclared) components.

const char *vertprog = "#version 130\n"
   "out float gl_ClipDistance[3];\n"
   "uniform int i;\n"
   "void main() {\n"
   "   gl_FrontColor = gl_Color;\n"
   "   gl_Position = ftransform();\n"
   "   gl_ClipDistance[0] = 1.0;\n"
   "   gl_ClipDistance[1] = 1.0;\n"
   "   gl_ClipDistance[2] = 1.0;\n"
   "   gl_ClipDistance[i] = -0.56;\n"
   "}\n";

VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL OUT[2].xyz, CLIPDIST
DCL CONST[0..4]
DCL TEMP[0..4]
DCL ADDR[0]
IMM FLT32 {1.,-0.5600, 0., 0.}
IMM INT32 {3, 0, 1, 2}
  0: MOV OUT[1], IN[1]
  1: MUL TEMP[0], CONST[1], IN[0].
  2: MAD TEMP[1], CONST[2], IN[0]., TEMP[0]
  3: MAD TEMP[1], CONST[3], IN[0]., TEMP[1]
  4: MAD OUT[0], CONST[4], IN[0]., TEMP[1]
  5: MOV TEMP[0].x, IMM[0]. (gl_ClipDistance[0] = 0.0)
  6: MOV TEMP[0].y, IMM[0].
  7: MOV TEMP[0].z, IMM[0].
  8: AND TEMP[1].x, CONST[0]., IMM[1].
  9: USEQ TEMP[1], TEMP[1]., IMM[1].yzwx (TEMP[1] = booleans for
each component)
 10: ISHR TEMP[2].x, CONST[0]., IMM[1]. (TEMP[2] == which vec4)
 11: I2F TEMP[3], TEMP[1]. (TEMP[3] == whether to modify x component
(-1.0f if true))
 12: UARL ADDR[0].x, TEMP[2].
 13: UARL ADDR[0].x, TEMP[2].
 14: MOV TEMP[4], TEMP[ADDR[0].x] (load last value written)
 15: UARL ADDR[0].x, TEMP[2].
 16: CMP TEMP[ADDR[0].x].x, TEMP[3]., IMM[0]., TEMP[4]
(conditional set)
(repeat for y, z and w)
 38: MOV OUT[2], TEMP[0]
 39: END

Oh, and it's horribly ugly compared to the 1 instruction it could be had
we proper support for arrays.

But, until that's resolved doing it like this will do ...
There's some work going on to make TGSI suitable for OpenCL which will
hopefully bring the necessary changes.

> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 43896] Mesa assembly breaks Super Meat Boy, Shank

2011-12-18 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=43896

Marti  changed:

   What|Removed |Added

 CC||ma...@juffo.org

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
--- You are receiving this mail because: ---
You are the assignee for the bug.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PROPOSAL] gallium: move state enable bits from clip_state to rasterizer_state

2011-12-18 Thread Christoph Bumiller
On 17.12.2011 20:54, Marek Olšák wrote:
> On Sat, Dec 17, 2011 at 4:45 PM, Christoph Bumiller
>  wrote:
>> On 17.12.2011 15:45, Marek Olšák wrote:
>>> ---
>>>
>>> This was suggested by Keith Whitwell in this email addressed to me on 
>>> 8/6/2010:
>>> http://lists.freedesktop.org/archives/mesa-dev/2010-August/001810.html
>>>
>>>
>>>  src/gallium/include/pipe/p_defines.h |2 +-
>>>  src/gallium/include/pipe/p_state.h   |   14 --
>>>  2 files changed, 13 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/src/gallium/include/pipe/p_defines.h 
>>> b/src/gallium/include/pipe/p_defines.h
>>> index 800a04c..c441a1f 100644
>>> --- a/src/gallium/include/pipe/p_defines.h
>>> +++ b/src/gallium/include/pipe/p_defines.h
>>> @@ -453,7 +453,7 @@ enum pipe_cap {
>>> PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT = 38,
>>> PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER = 39,
>>> PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER = 40,
>>> -   PIPE_CAP_DEPTH_CLAMP = 41,
>>> +   PIPE_CAP_DEPTH_CLIP_DISABLE = 41,
>>> PIPE_CAP_SHADER_STENCIL_EXPORT = 42,
>>> PIPE_CAP_TGSI_INSTANCEID = 43,
>>> PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR = 44,
>>> diff --git a/src/gallium/include/pipe/p_state.h 
>>> b/src/gallium/include/pipe/p_state.h
>>> index f943ca5..3aedada 100644
>>> --- a/src/gallium/include/pipe/p_state.h
>>> +++ b/src/gallium/include/pipe/p_state.h
>>> @@ -127,6 +127,18 @@ struct pipe_rasterizer_state
>>>  */
>>> unsigned rasterizer_discard:1;
>>>
>>> +   /**
>>> +* When false, depth clipping is disabled and the depth value will be
>>> +* clamped later at the per-pixel level before depth testing.
>>> +* This depends on PIPE_CAP_DEPTH_CLIP_DISABLE.
>>> +*/
>>> +   unsigned depth_clip:1;
>>> +
>>> +   /**
>>> +* Enable bits for user clip planes.
>>> +*/
>>> +   unsigned user_clip_plane_enable:PIPE_MAX_CLIP_PLANES;
>>> +
>> The first is fine, but I don't like having user clip plane enables here,
>> can't make them part of a hardware state buffer since whether a clip
>> plane is enabled or not also depends on the vertex (or domain or
>> geometry) shader, using both UCPs and gl_ClipDistance at the same time
>> doesn't work.
> I don't expect anyone to use both. Anyway, the user clip planes are
> fixed-function and neither r300 nor r600 clip state has any dependency
> on shaders. The UCP state is pretty much separate from everything
> else. I'd like to keep depth_clip and UCP enables together, because
> they are set via the same register on r600.

*Sigh*.
Fine then, I think it doesn't really matter for nv50, so I'm not
opposing the change, do it if it helps r600.

> The problem with pipe_clip_state is that if I want to enable UCPs, I
> must also set the clip planes = 32 floats at most. I can't re-use the
> 32 floats which were set last time.
>
>> The rasterizer cso is already so large ... if we keep going like this at
>> some point you have re-validate everything when the rasterizer CSO
>> changes, because of interdependencies, and we'll get larger and larger
>> numbers of rasterizer CSOs with slow lookup and hashing.
> I double-checked and there should be no change in the size of
> pipe_rasterizer_state with the patch. The state currently has 3 dwords
> + 5 floats. However, some or all of the floats could be put in its own
> state struct, because they are changed at a pretty low frequency. For
> example:
>
> struct pipe_poly_offset_state {
>float offset_units;
>float offset_scale;
>float offset_clamp;
> };
>
> pipe->set_poly_offset_state(pipe, &poly_offset_state);

And keeping the enable bits in the rasterizer ? Yes, that would be the
same way we treat stencil ref, and speed up the hashing.
Also, depth_clip and poly_offset are somewhat related (at least more
than depth_clip and clip planes), so keeping the enable bits of both in
the rasterizer state seems nicer.

I don't expect people to use many different combinations of values there
though.

>
> Marek
>

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 7.11] gallium/dri: Handle xserver that doesn't send needless DRI2 invalidate events

2011-12-18 Thread Ville Syrjälä
Ever since xserver commit 531869448d07e00ae241120b59f35709d59c,
the server no longer sends invalidate events to clients, unless they
have performed a GetBuffers request since the drawable was last
invalidated.

If the drawable gets invalidated immediately after the GetBuffers
request was processed by the X server, it's possible that Xlib
will process the invalidate event while waiting for the GetBuffers
reply. So the server, thinking the client knows that the buffers
are invalid, is waiting for another GetBuffers request before
sending any more invalidate events. The client, on the other hand,
believes the buffers to be valid, and thus is expecting to receive
another invalidate event before it has to send another GetBuffers
request. The end result is that the client never again sends
a GetBuffers request.

To avoid this problem, take a snapshot of lastStamp before
doing GetBuffers, and retry if the snapshot and the current
lastStamp no longer match after the GetBuffers reply has been
processed.

Signed-off-by: Ville Syrjälä 
---
It looks like master should already handle this, as there's a
retry loop inside st_framebuffer_validate(). I didn't test that
in practice though.

 .../state_trackers/dri/common/dri_drawable.c   |   30 +++
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c 
b/src/gallium/state_trackers/dri/common/dri_drawable.c
index 28a33ac..6748fbc 100644
--- a/src/gallium/state_trackers/dri/common/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/common/dri_drawable.c
@@ -51,6 +51,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface 
*stfbi,
unsigned statt_mask, new_mask;
boolean new_stamp;
int i;
+   unsigned int lastStamp;
 
statt_mask = 0x0;
for (i = 0; i < count; i++)
@@ -64,23 +65,26 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface 
*stfbi,
 * least for DRI1.  dPriv->lastStamp is the client stamp.  It has the value
 * of the server stamp when last checked.
 */
-   new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp);
+   do {
+  lastStamp = drawable->dPriv->lastStamp;
+  new_stamp = (drawable->texture_stamp != lastStamp);
 
-   if (new_stamp || new_mask || screen->broken_invalidate) {
-  if (new_stamp && drawable->update_drawable_info)
- drawable->update_drawable_info(drawable);
+  if (new_stamp || new_mask || screen->broken_invalidate) {
+ if (new_stamp && drawable->update_drawable_info)
+drawable->update_drawable_info(drawable);
 
-  drawable->allocate_textures(drawable, statts, count);
+ drawable->allocate_textures(drawable, statts, count);
 
-  /* add existing textures */
-  for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
- if (drawable->textures[i])
-statt_mask |= (1 << i);
-  }
+ /* add existing textures */
+ for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
+if (drawable->textures[i])
+   statt_mask |= (1 << i);
+ }
 
-  drawable->texture_stamp = drawable->dPriv->lastStamp;
-  drawable->texture_mask = statt_mask;
-   }
+ drawable->texture_stamp = lastStamp;
+ drawable->texture_mask = statt_mask;
+  }
+   } while (lastStamp != drawable->dPriv->lastStamp);
 
if (!out)
   return TRUE;
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 42128] Crash when visiting a site with Firefox

2011-12-18 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=42128

--- Comment #6 from Thiago  2011-12-18 10:59:59 PST ---
It also happens to me with mesa 7.11.2
same glxinfo as Thor's

https://bugs.archlinux.org/task/27573

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
--- You are receiving this mail because: ---
You are the assignee for the bug.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/2] softpipe: fix texture sampling from 1D texture array

2011-12-18 Thread Dave Airlie
From: Dave Airlie 

This is the first part of a fix to piglit glsl-fs-shadow1DArray

Signed-off-by: Dave Airlie 
---
 src/gallium/auxiliary/tgsi/tgsi_exec.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 1fb7f8f..060549f 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -1794,9 +1794,22 @@ exec_tex(struct tgsi_exec_machine *mach,
   break;
 
case TGSI_TEXTURE_1D_ARRAY:
+  FETCH(&r[0], 0, CHAN_X);
+  FETCH(&r[1], 0, CHAN_Y);
+
+  if (modifier == TEX_MODIFIER_PROJECTED) {
+ micro_div(&r[0], &r[0], &r[3]);
+  }
+
+  fetch_texel(mach->Samplers[unit],
+  &r[0], &r[1], &r[2], lod, /* S, T, P, LOD */
+  control,
+  &r[0], &r[1], &r[2], &r[3]);  /* outputs */
+  break;
case TGSI_TEXTURE_SHADOW1D_ARRAY:
   FETCH(&r[0], 0, CHAN_X);
   FETCH(&r[1], 0, CHAN_Y);
+  FETCH(&r[2], 0, CHAN_Z);
 
   if (modifier == TEX_MODIFIER_PROJECTED) {
  micro_div(&r[0], &r[0], &r[3]);
-- 
1.7.7.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] softpipe: fix depth sampling for linear vs nearest.

2011-12-18 Thread Dave Airlie
From: Dave Airlie 

This sample compare was always doing linear, and this makes the
glsl-fs-shadow1DArray test render like the Intel driver.

Signed-off-by: Dave Airlie 
---
 src/gallium/drivers/softpipe/sp_tex_sample.c |   23 ---
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c 
b/src/gallium/drivers/softpipe/sp_tex_sample.c
index 72629a0..40ad786 100644
--- a/src/gallium/drivers/softpipe/sp_tex_sample.c
+++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
@@ -2172,13 +2172,22 @@ sample_compare(struct tgsi_sampler *tgsi_sampler,
   break;
}
 
-   /* convert four pass/fail values to an intensity in [0,1] */
-   val = 0.25F * (k0 + k1 + k2 + k3);
-
-   /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */
-   for (j = 0; j < 4; j++) {
-  rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
-  rgba[3][j] = 1.0F;
+   if (sampler->mag_img_filter == PIPE_TEX_FILTER_LINEAR) {
+  /* convert four pass/fail values to an intensity in [0,1] */
+  val = 0.25F * (k0 + k1 + k2 + k3);
+
+  /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE 
*/
+  for (j = 0; j < 4; j++) {
+rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
+rgba[3][j] = 1.0F;
+  }
+   } else {
+  for (j = 0; j < 4; j++) {
+rgba[0][j] = k0;
+rgba[1][j] = k1;
+rgba[2][j] = k2;
+rgba[3][0] = 1.0F;
+  }
}
 }
 
-- 
1.7.7.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 6/8] i965: Use the miptree format for texture surface format choice.

2011-12-18 Thread Kenneth Graunke
On 12/15/2011 08:43 PM, Eric Anholt wrote:
> With separate stencil GL_DEPTH32F_STENCIL8, the miptree will have a
> really different format (MESA_FORMAT_Z32_FLOAT) from the teximage
> (MESA_FORMAT_Z32_FLOAT_X24S8).
> 
> v2: Do it for gen7, too.
> 
> Reviewed-by: Kenneth Graunke  (v1)

Oops.  Yeah, thanks for catching this.

Reviewed-by: Kenneth Graunke 
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/8] intel: Reuse intel_miptree_match_image().

2011-12-18 Thread Kenneth Graunke
On 12/15/2011 08:43 PM, Eric Anholt wrote:
> This little bit of logic was duplicated, which isn't much, but I was
> going to need to duplicate a bit of additional logic in the next
> commit.
> ---
>  src/mesa/drivers/dri/intel/intel_tex_validate.c |   15 ++-
>  1 files changed, 6 insertions(+), 9 deletions(-)

For this patch:
Reviewed-by: Kenneth Graunke 

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] softpipe: fix depth sampling for linear vs nearest.

2011-12-18 Thread Dave Airlie
On Sun, Dec 18, 2011 at 9:27 PM, Dave Airlie  wrote:
> From: Dave Airlie 
>
> This sample compare was always doing linear, and this makes the
> glsl-fs-shadow1DArray test render like the Intel driver.
>
> Signed-off-by: Dave Airlie 
> ---
>  src/gallium/drivers/softpipe/sp_tex_sample.c |   23 ---
>  1 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c 
> b/src/gallium/drivers/softpipe/sp_tex_sample.c
> index 72629a0..40ad786 100644
> --- a/src/gallium/drivers/softpipe/sp_tex_sample.c
> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
> @@ -2172,13 +2172,22 @@ sample_compare(struct tgsi_sampler *tgsi_sampler,
>       break;
>    }
>
> -   /* convert four pass/fail values to an intensity in [0,1] */
> -   val = 0.25F * (k0 + k1 + k2 + k3);
> -
> -   /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE 
> */
> -   for (j = 0; j < 4; j++) {
> -      rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
> -      rgba[3][j] = 1.0F;
> +   if (sampler->mag_img_filter == PIPE_TEX_FILTER_LINEAR) {
> +      /* convert four pass/fail values to an intensity in [0,1] */
> +      val = 0.25F * (k0 + k1 + k2 + k3);
> +
> +      /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = 
> GL_LUMINANCE */
> +      for (j = 0; j < 4; j++) {
> +        rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
> +        rgba[3][j] = 1.0F;
> +      }
> +   } else {
> +      for (j = 0; j < 4; j++) {
> +        rgba[0][j] = k0;
> +        rgba[1][j] = k1;
> +        rgba[2][j] = k2;
> +        rgba[3][0] = 1.0F;

^ assume 0 should be j here, though it would be good if someone could
check my thinking, I mostly ported from swrast.

Dave.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 5/6] vl: Remove most members of pipe_video_decoder

2011-12-18 Thread Andy Furniss

Maarten Lankhorst wrote:

Hey Andy,

On 12/07/2011 05:48 PM, Andy Furniss wrote:

Maarten Lankhorst wrote:


Hm, could you test with some added sanity checks?


mplayer: vl/vl_vlc.h:139: vl_vlc_eatbits: Assertion `vlc->valid_bits>  
num_bits' failed.


If that works, maybe remove the vl_vlc_fillbits call I added in 
vl_mpeg12_bs_decode
to see if that is what caused it. Unfortunately the bitstream parser just fails 
to work
correctly here on a lot of my test videos, but that happens even without this 
patch.


Yea, since the rewrite I have seen some crashes - only at the end of some 
transport streams and only so far with svn mplayer, release mplayer doesn't do 
it.


You might want to check with valgrind to see if it tosses any warning, too.
I don't suppose you have a short clip of the failing video that reproduces the 
problem?


Anything should do - I haven't found one that works yet, mpeg1, mpeg2 
progressive/interlaced, TS, PS, SD, HD with release mplayer or svn, all crash 
before rendering anything.



Ok looks like I found the issue, could you try the version below?


It doesn't crash anymore, but there are regressions.

On the plus side - some transport streams that used to crash/hang at the 
end with -vc ffmpeg12vdpau are now OK.


Playing dvd from disc without -cache 8192 is still problematic. This 
only affects vdpau decode, xvmc was and still is OK.


With the patch I get an assert rather than a hang/crash.
mplayer: vl/vl_vlc.h:138: vl_vlc_eatbits: Assertion `vlc->valid_bits >= 
num_bits' failed.


although -cache  mostly works around it. I can still rarely trigger 
it by doing a lot of skipping forward/back.


With the patch and vdpau decode on some streams there is occasional 
corruption where a few of the bottom right macroblocks render as solid 
colours.


The next issue affects xvmc as well as vdpau - performance is quite 
severely reduced. Looking at top it seems that less Cpu is used with the 
patch, but fps is 50-60% worse - meaning with vdpau decode I can't even 
play some 30fps HD with my card on high, these would normally be OK on 
low.


In addition with vdpau decode I get some 1/4 - 1/2 second stalls when 
testing HD (this was in benchmark mode so I don't think it's just 
because I haven't got the perf to reach fps).

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] mesa: split get_tex_rgba() into compressed/uncompressed versions

2011-12-18 Thread Brian Paul
From: Brian Paul 

This just splits one big function into two smaller ones for better
readability.
---
 src/mesa/main/texgetimage.c |  322 +++---
 1 files changed, 176 insertions(+), 146 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 3f24187..81863be 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -216,183 +216,213 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions,
 
 
 /**
- * glGetTexImage for color formats (RGBA, RGB, alpha, LA, etc).
- * Compressed textures are handled here as well.
+ * Get a color texture image with decompression.
  */
 static void
-get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_image *texImage)
+get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
+GLenum format, GLenum type, GLvoid *pixels,
+struct gl_texture_image *texImage,
+GLbitfield transferOps)
 {
/* don't want to apply sRGB -> RGB conversion here so override the format */
-   const gl_format texFormat = 
_mesa_get_srgb_format_linear(texImage->TexFormat);
+   const gl_format texFormat =
+  _mesa_get_srgb_format_linear(texImage->TexFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(texFormat);
const GLuint width = texImage->Width;
const GLuint height = texImage->Height;
const GLuint depth = texImage->Depth;
-   const GLenum dataType = _mesa_get_format_datatype(texFormat);
-   const GLenum baseFormat = _mesa_get_format_base_format(texFormat);
-   /* Normally, no pixel transfer ops are performed during glGetTexImage.
-* The only possible exception is component clamping to [0,1].
-*/
-   GLbitfield transferOps = 0x0;
-
-   /* In general, clamping does not apply to glGetTexImage, except when
-* the returned type of the image can't hold negative values.
-*/
-   if (type_needs_clamping(type)) {
-  /* the returned image type can't have negative values */
-  if (dataType == GL_FLOAT ||
-  dataType == GL_SIGNED_NORMALIZED ||
-  format == GL_LUMINANCE ||
-  format == GL_LUMINANCE_ALPHA) {
- transferOps |= IMAGE_CLAMP_BIT;
-  }
+   GLfloat *tempImage, *srcRow;
+   GLuint row;
+
+   /* Decompress into temp float buffer, then pack into user buffer */
+   tempImage = (GLfloat *) malloc(width * height * depth
+  * 4 * sizeof(GLfloat));
+   if (!tempImage) {
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
+  return;
}
 
-   if (_mesa_is_format_compressed(texFormat)) {
-  /* Decompress into temp buffer, then pack into user buffer */
-  GLfloat *tempImage, *srcRow;
-  GLuint row;
+   /* Decompress the texture image - results in 'tempImage' */
+   {
+  GLubyte *srcMap;
+  GLint srcRowStride;
+  GLuint bytes, bw, bh;
 
-  tempImage = (GLfloat *) malloc(texImage->Width * texImage->Height *
- texImage->Depth * 4 * sizeof(GLfloat));
-  if (!tempImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
- return;
-  }
+  bytes = _mesa_get_format_bytes(texFormat);
+  _mesa_get_format_block_size(texFormat, &bw, &bh);
 
-  /* Decompress the texture image - results in 'tempImage' */
-  {
- GLubyte *srcMap;
- GLint srcRowStride;
- GLuint bytes, bw, bh;
+  ctx->Driver.MapTextureImage(ctx, texImage, 0,
+  0, 0, width, height,
+  GL_MAP_READ_BIT,
+  &srcMap, &srcRowStride);
+  if (srcMap) {
+ /* XXX This line is a bit of a hack to work around the
+  * mismatch of compressed row strides as returned by
+  * MapTextureImage() vs. what the texture decompression code
+  * uses.  This will be fixed in the future.
+  */
+ srcRowStride = srcRowStride * bh / bytes;
 
- bytes = _mesa_get_format_bytes(texImage->TexFormat);
- _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
+ _mesa_decompress_image(texFormat, width, height,
+srcMap, srcRowStride, tempImage);
 
- ctx->Driver.MapTextureImage(ctx, texImage, 0,
- 0, 0, width, height,
- GL_MAP_READ_BIT,
- &srcMap, &srcRowStride);
+ ctx->Driver.UnmapTextureImage(ctx, texImage, 0);
+  }
+  else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
+  }
+   }
 
- if (srcMap) {
-/* XXX This line is a bit of a hack to work around the
- * mismatch of compressed row strides as returned by
- * MapTextureImage() vs. what the texture decompression code
- 

[Mesa-dev] [PATCH 1/2] mesa: update comment for MapTextureImage()

2011-12-18 Thread Brian Paul
From: Brian Paul 

---
 src/mesa/main/dd.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 01cfff8..5816faa 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -491,6 +491,8 @@ struct dd_function_table {
void (*FreeTextureImageBuffer)( struct gl_context *ctx, struct 
gl_texture_image *tImage );
 
/** Map a slice of a texture image into user space.
+* Note: for GL_TEXTURE_1D_ARRAY, height must be 1, y must be 0 and slice
+* indicates the 1D array index.
 * \param texImage  the texture image
 * \param slice  the 3D image slice or array texture slice
 * \param x, y, w, h  region of interest
-- 
1.7.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] mesa: fix _mesa_store_texsubimage2d() for GL_TEXTURE_1D_ARRAY

2011-12-18 Thread Brian Paul
From: Brian Paul 

For 1D arrays, map each slice separately.  Note that this was handled
correctly in _mesa_store_teximage2d() but not here.
---
 src/mesa/main/texstore.c |   67 ++
 1 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index a57a38e..fb1ad04 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -4888,35 +4888,56 @@ _mesa_store_texsubimage2d(struct gl_context *ctx, 
GLenum target, GLint level,
   struct gl_texture_image *texImage)
 {
const GLbitfield rwMode = get_read_write_mode(format, texImage->TexFormat);
-   GLubyte *dstMap;
-   GLint dstRowStride;
-   GLboolean success;
+   GLboolean success = GL_FALSE;
+   GLuint slice, numSlices, sliceOffset, srcImageStride;
+   const GLubyte *src;
 
/* get pointer to src pixels (may be in a pbo which we'll map here) */
-   pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
-pixels, packing, "glTexSubImage2D");
-   if (!pixels)
+   src = (const GLubyte *)
+  _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
+  pixels, packing, "glTexSubImage2D");
+   if (!src)
   return;
 
-   /* Map dest texture buffer */
-   ctx->Driver.MapTextureImage(ctx, texImage, 0,
-   xoffset, yoffset, width, height,
-   rwMode,
-   &dstMap, &dstRowStride);
-
-   if (dstMap) {
-  success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
-   texImage->TexFormat,
-   0, 0, 0,  /* dstX/Y/Zoffset */
-   dstRowStride,
-   &dstMap,
-   width, height, 1,
-   format, type, pixels, packing);
-
-  ctx->Driver.UnmapTextureImage(ctx, texImage, 0);
+   if (target == GL_TEXTURE_1D_ARRAY) {
+  /* map each slice of the 1D array separately */
+  numSlices = height;
+  sliceOffset = yoffset;
+  height = 1;
+  yoffset = 0;
+  srcImageStride = _mesa_image_row_stride(packing, width, format, type);
}
else {
-  success = GL_FALSE;
+  /* regular 2D image */
+  numSlices = 1;
+  sliceOffset = 0;
+  srcImageStride = 0;
+   }
+
+   for (slice = 0; slice < numSlices; slice++) {
+  GLubyte *dstMap;
+  GLint dstRowStride;
+
+  ctx->Driver.MapTextureImage(ctx, texImage,
+  slice + sliceOffset,
+  xoffset, yoffset, width, height,
+  rwMode, &dstMap, &dstRowStride);
+  if (dstMap) {
+ success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
+  texImage->TexFormat,
+  0, 0, 0,  /* dstX/Y/Zoffset */
+  dstRowStride,
+  &dstMap,
+  width, height, 1,  /* w, h, d */
+  format, type, src, packing);
+
+ ctx->Driver.UnmapTextureImage(ctx, texImage, slice + sliceOffset);
+  }
+
+  src += srcImageStride;
+
+  if (!success)
+ break;
}
 
if (!success)
-- 
1.7.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/4] swrast: do depth/stencil clearing with Map/UnmapRenderbuffer()

2011-12-18 Thread Brian Paul
Another step toward getting rid of the renderbuffer PutRow/etc functions.

v2: fix assorted depth/stencil clear bugs found by Eric
---
 src/mesa/swrast/s_clear.c   |   49 ++---
 src/mesa/swrast/s_depth.c   |  235 ---
 src/mesa/swrast/s_depth.h   |5 +-
 src/mesa/swrast/s_stencil.c |  154 +---
 src/mesa/swrast/s_stencil.h |2 +-
 5 files changed, 305 insertions(+), 140 deletions(-)

diff --git a/src/mesa/swrast/s_clear.c b/src/mesa/swrast/s_clear.c
index 851f6d1..3566370 100644
--- a/src/mesa/swrast/s_clear.c
+++ b/src/mesa/swrast/s_clear.c
@@ -195,6 +195,8 @@ clear_color_buffers(struct gl_context *ctx)
 void
 _swrast_Clear(struct gl_context *ctx, GLbitfield buffers)
 {
+   const GLbitfield BUFFER_DS = BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL;
+
 #ifdef DEBUG_FOO
{
   const GLbitfield legalBits =
@@ -216,24 +218,39 @@ _swrast_Clear(struct gl_context *ctx, GLbitfield buffers)
if (SWRAST_CONTEXT(ctx)->NewState)
   _swrast_validate_derived(ctx);
 
-   swrast_render_start(ctx);
+   if ((buffers & BUFFER_BITS_COLOR)
+   && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) {
+  /* XXX remove the swrast_render_start/finish() calls after
+   * clear_color_buffers() is converted to use Map/UnmapRenderbuffer()
+   * The other clearing functions don't need these calls.
+   */
+  swrast_render_start(ctx);
+  clear_color_buffers(ctx);
+  swrast_render_finish(ctx);
+   }
 
-   /* do software clearing here */
-   if (buffers) {
-  if ((buffers & BUFFER_BITS_COLOR)
-  && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) {
- clear_color_buffers(ctx);
-  }
-  if (buffers & BUFFER_BIT_DEPTH) {
- _swrast_clear_depth_buffer(ctx, ctx->DrawBuffer->_DepthBuffer);
-  }
-  if (buffers & BUFFER_BIT_ACCUM) {
- _mesa_clear_accum_buffer(ctx);
+   if (buffers & BUFFER_BIT_ACCUM) {
+  _mesa_clear_accum_buffer(ctx);
+   }
+
+   if (buffers & BUFFER_DS) {
+  struct gl_renderbuffer *depthRb =
+ ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+  struct gl_renderbuffer *stencilRb =
+ ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
+
+  if ((buffers & BUFFER_DS) == BUFFER_DS && depthRb == stencilRb) {
+ /* clear depth and stencil together */
+ _swrast_clear_depth_stencil_buffer(ctx);
   }
-  if (buffers & BUFFER_BIT_STENCIL) {
- _swrast_clear_stencil_buffer(ctx, ctx->DrawBuffer->_StencilBuffer);
+  else {
+ /* clear depth, stencil separately */
+ if (buffers & BUFFER_BIT_DEPTH) {
+_swrast_clear_depth_buffer(ctx);
+ }
+ if (buffers & BUFFER_BIT_STENCIL) {
+_swrast_clear_stencil_buffer(ctx);
+ }
   }
}
-
-   swrast_render_finish(ctx);
 }
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 8d3ad10..09c0be6 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -26,6 +26,7 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/formats.h"
+#include "main/format_pack.h"
 #include "main/macros.h"
 #include "main/imports.h"
 
@@ -1312,14 +1313,21 @@ _swrast_read_depth_span_float( struct gl_context *ctx, 
struct gl_renderbuffer *r
}
 }
 
+
 /**
- * Clear the given z/depth renderbuffer.
+ * Clear the given z/depth renderbuffer.  If the buffer is a combined
+ * depth+stencil buffer, only the Z bits will be touched.
  */
 void
-_swrast_clear_depth_buffer( struct gl_context *ctx, struct gl_renderbuffer *rb 
)
+_swrast_clear_depth_buffer(struct gl_context *ctx)
 {
+   struct gl_renderbuffer *rb =
+  ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
GLuint clearValue;
GLint x, y, width, height;
+   GLubyte *map;
+   GLint rowStride, i, j;
+   GLbitfield mapMode;
 
if (!rb || !ctx->Depth.Mask) {
   /* no depth buffer, or writing to it is disabled */
@@ -1334,67 +1342,218 @@ _swrast_clear_depth_buffer( struct gl_context *ctx, 
struct gl_renderbuffer *rb )
   clearValue = (GLuint) (ctx->Depth.Clear * ctx->DrawBuffer->_DepthMaxF);
}
 
-   assert(rb->_BaseFormat == GL_DEPTH_COMPONENT);
-
/* compute region to clear */
x = ctx->DrawBuffer->_Xmin;
y = ctx->DrawBuffer->_Ymin;
width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
 
-   if (rb->GetPointer(ctx, rb, 0, 0)) {
-  /* Direct buffer access is possible.  Either this is just malloc'd
-   * memory, or perhaps the driver mmap'd the zbuffer memory.
-   */
-  if (rb->DataType == GL_UNSIGNED_SHORT) {
- if ((clearValue & 0xff) == ((clearValue >> 8) & 0xff) &&
- ((GLushort *) rb->GetPointer(ctx, rb, 0, 0) + width ==
-  (GLushort *) rb->GetPointer(ctx, rb, 0, 1))) {
-/* optimized case */
-GLushort *dst = (GLushort *) rb->GetPointer(ctx, rb, x, y);
-

[Mesa-dev] [PATCH 2/4] mesa: add _mesa_get_format_max_bits()

2011-12-18 Thread Brian Paul
Returns max bits per channel for the given format.
---
 src/mesa/main/formats.c |   16 
 src/mesa/main/formats.h |3 +++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 1f83a53..cca0014 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -27,6 +27,7 @@
 #include "imports.h"
 #include "formats.h"
 #include "mfeatures.h"
+#include "macros.h"
 
 
 /**
@@ -1613,6 +1614,21 @@ _mesa_get_format_bits(gl_format format, GLenum pname)
 }
 
 
+GLuint
+_mesa_get_format_max_bits(gl_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   GLuint max = MAX2(info->RedBits, info->GreenBits);
+   max = MAX2(max, info->BlueBits);
+   max = MAX2(max, info->AlphaBits);
+   max = MAX2(max, info->LuminanceBits);
+   max = MAX2(max, info->IntensityBits);
+   max = MAX2(max, info->DepthBits);
+   max = MAX2(max, info->StencilBits);
+   return max;
+}
+
+
 /**
  * Return the data type (or more specifically, the data representation)
  * for the given format.
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index e6b429d..9609343 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -290,6 +290,9 @@ _mesa_get_format_bytes(gl_format format);
 extern GLint
 _mesa_get_format_bits(gl_format format, GLenum pname);
 
+extern GLuint
+_mesa_get_format_max_bits(gl_format format);
+
 extern GLenum
 _mesa_get_format_datatype(gl_format format);
 
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/4] mesa: add _mesa_pack_colormask()

2011-12-18 Thread Brian Paul
For generating bit-wise colormasks for arbitrary pixel formats.
---
 src/mesa/main/format_pack.c |   75 +++
 src/mesa/main/format_pack.h |3 ++
 2 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 390b494..840559b 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -2494,3 +2494,78 @@ _mesa_pack_uint_24_8_depth_stencil_row(gl_format format, 
GLuint n,
   return;
}
 }
+
+
+
+/**
+ * Convert a boolean color mask to a packed color where each channel of
+ * the packed value at dst will be 0 or ~0 depending on the colorMask.
+ */
+void
+_mesa_pack_colormask(gl_format format, const GLubyte colorMask[4], void *dst)
+{
+   GLfloat maskColor[4];
+
+   switch (_mesa_get_format_datatype(format)) {
+   case GL_UNSIGNED_NORMALIZED:
+  /* simple: 1.0 will convert to ~0 in the right bit positions */
+  maskColor[0] = colorMask[0] ? 1.0 : 0.0;
+  maskColor[1] = colorMask[1] ? 1.0 : 0.0;
+  maskColor[2] = colorMask[2] ? 1.0 : 0.0;
+  maskColor[3] = colorMask[3] ? 1.0 : 0.0;
+  _mesa_pack_float_rgba_row(format, 1,
+(const GLfloat (*)[4]) maskColor, dst);
+  break;
+   case GL_SIGNED_NORMALIZED:
+   case GL_FLOAT:
+  /* These formats are harder because it's hard to know the floating
+   * point values that will convert to ~0 for each color channel's bits.
+   * This solution just generates a non-zero value for each color channel
+   * then fixes up the non-zero values to be ~0.
+   * Note: we'll need to add special case code if we ever have to deal
+   * with formats with unequal color channel sizes, like R11_G11_B10.
+   * We issue a warning below for channel sizes other than 8,16,32.
+   */
+  {
+ GLuint bits = _mesa_get_format_max_bits(format); /* bits per chan */
+ GLuint bytes = _mesa_get_format_bytes(format);
+ GLuint i;
+
+ /* this should put non-zero values into the channels of dst */
+ maskColor[0] = colorMask[0] ? -1.0 : 0.0;
+ maskColor[1] = colorMask[1] ? -1.0 : 0.0;
+ maskColor[2] = colorMask[2] ? -1.0 : 0.0;
+ maskColor[3] = colorMask[3] ? -1.0 : 0.0;
+ _mesa_pack_float_rgba_row(format, 1,
+   (const GLfloat (*)[4]) maskColor, dst);
+
+ /* fix-up the dst channels by converting non-zero values to ~0 */
+ if (bits == 8) {
+GLubyte *d = (GLubyte *) dst;
+for (i = 0; i < bytes; i++) {
+   d[i] = d[i] ? 0x : 0x0;
+}
+ }
+ else if (bits == 16) {
+GLushort *d = (GLushort *) dst;
+for (i = 0; i < bytes / 2; i++) {
+   d[i] = d[i] ? 0x : 0x0;
+}
+ }
+ else if (bits == 32) {
+GLuint *d = (GLuint *) dst;
+for (i = 0; i < bytes / 4; i++) {
+   d[i] = d[i] ? 0xU : 0x0;
+}
+ }
+ else {
+_mesa_problem(NULL, "unexpected size in _mesa_pack_colormask()");
+return;
+ }
+  }
+  break;
+   default:
+  _mesa_problem(NULL, "unexpected format data type in gen_color_mask()");
+  return;
+   }
+}
diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
index 7df1356..f1b4805 100644
--- a/src/mesa/main/format_pack.h
+++ b/src/mesa/main/format_pack.h
@@ -95,4 +95,7 @@ _mesa_pack_uint_24_8_depth_stencil_row(gl_format format, 
GLuint n,
const GLuint *src, void *dst);
 
 
+extern void
+_mesa_pack_colormask(gl_format format, const GLubyte colorMask[4], void *dst);
+
 #endif
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 4/4] swrast: rewrite color buffer clearing to use Map/UnmapRenderbuffer()

2011-12-18 Thread Brian Paul
v2: use _mesa_pack_colormask() helper and fix incorrect masking arithmetic
---
 src/mesa/swrast/s_clear.c |  225 +++--
 1 files changed, 113 insertions(+), 112 deletions(-)

diff --git a/src/mesa/swrast/s_clear.c b/src/mesa/swrast/s_clear.c
index 3566370..d942e6e 100644
--- a/src/mesa/swrast/s_clear.c
+++ b/src/mesa/swrast/s_clear.c
@@ -24,131 +24,146 @@
 
 #include "main/glheader.h"
 #include "main/accum.h"
-#include "main/colormac.h"
 #include "main/condrender.h"
+#include "main/format_pack.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/mtypes.h"
 
 #include "s_context.h"
 #include "s_depth.h"
-#include "s_masking.h"
 #include "s_stencil.h"
 
 
+
 /**
- * Clear the color buffer when glColorMask is in effect.
+ * Clear an rgba color buffer with masking if needed.
  */
 static void
-clear_rgba_buffer_with_masking(struct gl_context *ctx, struct gl_renderbuffer 
*rb,
-   GLuint buf)
+clear_rgba_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb,
+  const GLubyte colorMask[4])
 {
const GLint x = ctx->DrawBuffer->_Xmin;
const GLint y = ctx->DrawBuffer->_Ymin;
const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
-   SWspan span;
-   GLint i;
-
-   ASSERT(rb->PutRow);
+   const GLuint pixelSize = _mesa_get_format_bytes(rb->Format);
+   const GLboolean doMasking = (colorMask[0] == 0 ||
+colorMask[1] == 0 ||
+colorMask[2] == 0 ||
+colorMask[3] == 0);
+   const GLfloat (*clearColor)[4] =
+  (const GLfloat (*)[4]) ctx->Color.ClearColor.f;
+   GLbitfield mapMode = GL_MAP_WRITE_BIT;
+   GLubyte *map;
+   GLint rowStride;
+   GLint i, j;
 
-   /* Initialize color span with clear color */
-   /* XXX optimize for clearcolor == black/zero (bzero) */
-   INIT_SPAN(span, GL_BITMAP);
-   span.end = width;
-   span.arrayMask = SPAN_RGBA;
-   span.array->ChanType = rb->DataType;
-   if (span.array->ChanType == GL_UNSIGNED_BYTE) {
-  GLubyte clearColor[4];
-  _mesa_unclamped_float_rgba_to_ubyte(clearColor, ctx->Color.ClearColor.f);
-  for (i = 0; i < width; i++) {
- COPY_4UBV(span.array->rgba[i], clearColor);
-  }
-   }
-   else if (span.array->ChanType == GL_UNSIGNED_SHORT) {
-  GLushort clearColor[4];
-  UNCLAMPED_FLOAT_TO_USHORT(clearColor[RCOMP], ctx->Color.ClearColor.f[0]);
-  UNCLAMPED_FLOAT_TO_USHORT(clearColor[GCOMP], ctx->Color.ClearColor.f[1]);
-  UNCLAMPED_FLOAT_TO_USHORT(clearColor[BCOMP], ctx->Color.ClearColor.f[2]);
-  UNCLAMPED_FLOAT_TO_USHORT(clearColor[ACOMP], ctx->Color.ClearColor.f[3]);
-  for (i = 0; i < width; i++) {
- COPY_4V_CAST(span.array->rgba[i], clearColor, GLchan);
-  }
-   }
-   else {
-  ASSERT(span.array->ChanType == GL_FLOAT);
-  for (i = 0; i < width; i++) {
- UNCLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][0], 
ctx->Color.ClearColor.f[0]);
- UNCLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][1], 
ctx->Color.ClearColor.f[1]);
- UNCLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][2], 
ctx->Color.ClearColor.f[2]);
- UNCLAMPED_FLOAT_TO_CHAN(span.array->rgba[i][3], 
ctx->Color.ClearColor.f[3]);
-  }
+   if (doMasking) {
+  /* we'll need to read buffer values too */
+  mapMode |= GL_MAP_READ_BIT;
}
 
-   /* Note that masking will change the color values, but only the
-* channels for which the write mask is GL_FALSE.  The channels
-* which which are write-enabled won't get modified.
-*/
-   for (i = 0; i < height; i++) {
-  span.x = x;
-  span.y = y + i;
-  _swrast_mask_rgba_span(ctx, rb, &span, buf);
-  /* write masked row */
-  rb->PutRow(ctx, rb, width, x, y + i, span.array->rgba, NULL);
+   /* map dest buffer */
+   ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
+   mapMode, &map, &rowStride);
+   if (!map) {
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glClear(color)");
+  return;
}
-}
-
 
-/**
- * Clear an rgba color buffer without channel masking.
- */
-static void
-clear_rgba_buffer(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint 
buf)
-{
-   const GLint x = ctx->DrawBuffer->_Xmin;
-   const GLint y = ctx->DrawBuffer->_Ymin;
-   const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
-   const GLint width  = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
-   GLubyte clear8[4];
-   GLushort clear16[4];
-   GLvoid *clearVal;
-   GLfloat clearFloat[4];
-   GLint i;
+   /* for 1, 2, 4-byte clearing */
+#define SIMPLE_TYPE_CLEAR(TYPE) \
+   do { \
+  TYPE pixel, pixelMask;\
+  _mesa_pack_float_rgba_row(rb->Format, 1, clearColor, &pixe

[Mesa-dev] [PATCH 01/22] swrast: replace GetRow() call with _mesa_unpack_ubyte_stencil_row()

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_stencil.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 5f81fe8..aa9ab16 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -26,6 +26,7 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/imports.h"
+#include "main/format_unpack.h"
 
 #include "s_context.h"
 #include "s_depth.h"
@@ -1044,6 +1045,8 @@ void
 _swrast_read_stencil_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
   GLint n, GLint x, GLint y, GLubyte stencil[])
 {
+   GLubyte *src;
+
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
   /* span is completely outside framebuffer */
@@ -1064,7 +1067,8 @@ _swrast_read_stencil_span(struct gl_context *ctx, struct 
gl_renderbuffer *rb,
   return;
}
 
-   rb->GetRow(ctx, rb, n, x, y, stencil);
+   src = (GLubyte *) rb->Data + y * rb->RowStride +x;
+   _mesa_unpack_ubyte_stencil_row(rb->Format, n, src, stencil);
 }
 
 
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 02/22] swrast: do fast_copy_pixels() with Map/UnmapRenderbuffer()

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_copypix.c |  131 +--
 1 files changed, 88 insertions(+), 43 deletions(-)

diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 3bdf48b..2a789ab 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -600,6 +600,7 @@ copy_depth_stencil_pixels(struct gl_context *ctx,
 
 /**
  * Try to do a fast copy pixels.
+ * \return GL_TRUE if successful, GL_FALSE otherwise.
  */
 static GLboolean
 fast_copy_pixels(struct gl_context *ctx,
@@ -609,8 +610,10 @@ fast_copy_pixels(struct gl_context *ctx,
struct gl_framebuffer *srcFb = ctx->ReadBuffer;
struct gl_framebuffer *dstFb = ctx->DrawBuffer;
struct gl_renderbuffer *srcRb, *dstRb;
-   GLint row, yStep;
-   void *temp;
+   GLint row;
+   GLuint pixelBytes, widthInBytes;
+   GLubyte *srcMap, *dstMap;
+   GLint srcRowStride, dstRowStride;
 
if (SWRAST_CONTEXT(ctx)->_RasterMask != 0x0 ||
ctx->Pixel.ZoomX != 1.0F ||
@@ -641,10 +644,8 @@ fast_copy_pixels(struct gl_context *ctx,
   dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer;
}
 
-   /* src and dst renderbuffers must be same format and type */
-   if (!srcRb || !dstRb ||
-   srcRb->DataType != dstRb->DataType ||
-   srcRb->_BaseFormat != dstRb->_BaseFormat) {
+   /* src and dst renderbuffers must be same format */
+   if (!srcRb || !dstRb || srcRb->Format != dstRb->Format) {
   return GL_FALSE;
}
 
@@ -656,32 +657,72 @@ fast_copy_pixels(struct gl_context *ctx,
   return GL_FALSE;
}
 
-   /* overlapping src/dst doesn't matter, just determine Y direction */
-   if (srcY < dstY) {
-  /* top-down  max-to-min */
-  srcY = srcY + height - 1;
-  dstY = dstY + height - 1;
-  yStep = -1;
+   pixelBytes = _mesa_get_format_bytes(srcRb->Format);
+   widthInBytes = width * pixelBytes;
+
+   if (srcRb == dstRb) {
+  /* map whole buffer for read/write */
+  /* XXX we could be clever and just map the union region of the
+   * source and dest rects.
+   */
+  GLubyte *map;
+  GLint rowStride;
+
+  ctx->Driver.MapRenderbuffer(ctx, srcRb, 0, 0,
+  srcRb->Width, srcRb->Height,
+  GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+  &map, &rowStride);
+  if (!srcMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+ return GL_TRUE; /* don't retry with slow path */
+  }
+
+  srcMap = map + srcY * rowStride + srcX * pixelBytes;
+  dstMap = map + dstY * rowStride + dstX * pixelBytes;
+
+  /* this handles overlapping copies */
+  if (srcY < dstY) {
+ /* copy in reverse (top->down) order */
+ srcMap += rowStride * (height - 1);
+ dstMap += rowStride * (height - 1);
+ srcRowStride = -rowStride;
+ dstRowStride = -rowStride;
+  }
+  else {
+ /* copy in normal (bottom->up) order */
+ srcRowStride = rowStride;
+ dstRowStride = rowStride;
+  }
}
else {
-  /* bottom-up  min-to-max */
-  yStep = 1;
-   }
-
-   temp = malloc(width * MAX_PIXEL_BYTES);
-   if (!temp) {
-  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
-  return GL_FALSE;
+  /* different src/dst buffers */
+  ctx->Driver.MapRenderbuffer(ctx, srcRb, srcX, srcY,
+  width, height,
+  GL_MAP_READ_BIT, &srcMap, &srcRowStride);
+  if (!srcMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+ return GL_TRUE; /* don't retry with slow path */
+  }
+  ctx->Driver.MapRenderbuffer(ctx, dstRb, dstX, dstY,
+  width, height,
+  GL_MAP_WRITE_BIT, &dstMap, &dstRowStride);
+  if (!dstMap) {
+ ctx->Driver.UnmapRenderbuffer(ctx, srcRb);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+ return GL_TRUE; /* don't retry with slow path */
+  }
}
 
for (row = 0; row < height; row++) {
-  srcRb->GetRow(ctx, srcRb, width, srcX, srcY, temp);
-  dstRb->PutRow(ctx, dstRb, width, dstX, dstY, temp, NULL);
-  srcY += yStep;
-  dstY += yStep;
+  memcpy(dstMap, srcMap, widthInBytes);
+  dstMap += dstRowStride;
+  srcMap += srcRowStride;
}
 
-   free(temp);
+   ctx->Driver.UnmapRenderbuffer(ctx, srcRb);
+   if (dstRb != srcRb) {
+  ctx->Driver.UnmapRenderbuffer(ctx, dstRb);
+   }
 
return GL_TRUE;
 }
@@ -697,7 +738,6 @@ _swrast_CopyPixels( struct gl_context *ctx,
GLint destx, GLint desty, GLenum type )
 {
SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   swrast_render_start(ctx);
   
if (!_mesa_check_conditional_render(ctx))
   return; /* don't copy */
@@ -705,23 +745,28 @@ _swrast_CopyPixels( struct gl_context *ctx,
if (swrast->NewState)
   _swrast_validate_derived( ctx );
 
-   if (!fast_copy_pi

[Mesa-dev] [PATCH 03/22] swrast: stop using _swrast_get_values() in stencil code

2011-12-18 Thread Brian Paul
That function will go a way in the future.
---
 src/mesa/swrast/s_stencil.c |   31 ++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index aa9ab16..17b3b12 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -879,6 +879,35 @@ stencil_test_pixels( struct gl_context *ctx, GLuint face, 
GLuint n,
 
 
 
+static void
+get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+  GLuint count, const GLint x[], const GLint y[],
+  GLubyte stencil[])
+{
+   const GLint w = rb->Width, h = rb->Height;
+   const GLubyte *map = (const GLubyte *) rb->Data;
+   GLuint i;
+
+   if (rb->Format == MESA_FORMAT_S8) {
+  const GLuint rowStride = rb->RowStride;
+  for (i = 0; i < count; i++) {
+ if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
+stencil[i] = *(map + y[i] * rowStride + x[i]);
+ }
+  }
+   }
+   else {
+  const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+  const GLuint rowStride = rb->RowStride * bpp;
+  for (i = 0; i < count; i++) {
+ if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
+const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
+_mesa_unpack_ubyte_stencil_row(rb->Format, 1, src, &stencil[i]);
+ }
+  }
+   }
+}
+
 
 /**
  * Apply stencil and depth testing to an array of pixels.
@@ -916,7 +945,7 @@ stencil_and_ztest_pixels( struct gl_context *ctx, SWspan 
*span, GLuint face )
   GLubyte stencil[MAX_WIDTH];
 
   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-  _swrast_get_values(ctx, rb, n, x, y, stencil, sizeof(GLubyte));
+  get_s8_values(ctx, rb, n, x, y, stencil);
 
   memcpy(origMask, mask, n * sizeof(GLubyte));  
 
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 04/22] swrast: stop using _swrast_get_values() in z/depth code

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_depth.c |   81 +---
 1 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 09c0be6..cedc7fd 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -26,6 +26,7 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/formats.h"
+#include "main/format_unpack.h"
 #include "main/format_pack.h"
 #include "main/macros.h"
 #include "main/imports.h"
@@ -548,6 +549,74 @@ _swrast_depth_clamp_span( struct gl_context *ctx, SWspan 
*span )
 }
 
 
+/**
+ * Get array of 16-bit z values from the depth buffer.  With clipping.
+ */
+static void
+get_z16_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+   GLuint count, const GLint x[], const GLint y[],
+   GLushort zbuffer[])
+{
+   const GLint w = rb->Width, h = rb->Height;
+   const GLubyte *map = (const GLubyte *) rb->Data;
+   GLuint i;
+
+   if (rb->Format == MESA_FORMAT_Z16) {
+  const GLuint rowStride = rb->RowStride * 2;
+  for (i = 0; i < count; i++) {
+ if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
+zbuffer[i] = *((GLushort *) (map + y[i] * rowStride + x[i] * 2));
+ }
+  }
+   }
+   else {
+  const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+  const GLuint rowStride = rb->RowStride * bpp;
+  for (i = 0; i < count; i++) {
+ if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
+GLuint d32;
+const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
+_mesa_unpack_uint_z_row(rb->Format, 1, src, &d32);
+zbuffer[i] = d32 >> 16;
+ }
+  }
+   }
+}
+
+
+/**
+ * Get array of 32-bit z values from the depth buffer.  With clipping.
+ */
+static void
+get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+   GLuint count, const GLint x[], const GLint y[],
+   GLuint zbuffer[])
+{
+   const GLint w = rb->Width, h = rb->Height;
+   const GLubyte *map = (const GLubyte *) rb->Data;
+   GLuint i;
+
+   if (rb->Format == MESA_FORMAT_Z32) {
+  const GLuint rowStride = rb->RowStride * 4;
+  for (i = 0; i < count; i++) {
+ if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
+zbuffer[i] = *((GLuint *) (map + y[i] * rowStride + x[i] * 4));
+ }
+  }
+   }
+   else {
+  const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+  const GLuint rowStride = rb->RowStride * bpp;
+  for (i = 0; i < count; i++) {
+ if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
+const GLubyte *src = map + y[i] * rowStride+ x[i] * bpp;
+_mesa_unpack_uint_z_row(rb->Format, 1, src, &zbuffer[i]);
+ }
+  }
+   }
+}
+
+
 
 /*
  * Apply depth test to span of fragments.
@@ -1129,14 +1198,14 @@ depth_test_pixels( struct gl_context *ctx, SWspan *span 
)
   /* read depth values from buffer, test, write back */
   if (rb->DataType == GL_UNSIGNED_SHORT) {
  GLushort zbuffer[MAX_WIDTH];
- _swrast_get_values(ctx, rb, count, x, y, zbuffer, sizeof(GLushort));
+ get_z16_values(ctx, rb, count, x, y, zbuffer);
  depth_test_span16(ctx, count, zbuffer, z, mask);
  rb->PutValues(ctx, rb, count, x, y, zbuffer, mask);
   }
   else {
  GLuint zbuffer[MAX_WIDTH];
  ASSERT(rb->DataType == GL_UNSIGNED_INT);
- _swrast_get_values(ctx, rb, count, x, y, zbuffer, sizeof(GLuint));
+ get_z32_values(ctx, rb, count, x, y, zbuffer);
  depth_test_span32(ctx, count, zbuffer, z, mask);
  rb->PutValues(ctx, rb, count, x, y, zbuffer, mask);
   }
@@ -1183,8 +1252,8 @@ _swrast_depth_bounds_test( struct gl_context *ctx, SWspan 
*span )
   /* get 16-bit values */
   GLushort zbuffer16[MAX_WIDTH], *zbuffer;
   if (span->arrayMask & SPAN_XY) {
- _swrast_get_values(ctx, rb, count, span->array->x, span->array->y,
-zbuffer16, sizeof(GLushort));
+ get_z16_values(ctx, rb, count, span->array->x, span->array->y,
+zbuffer16);
  zbuffer = zbuffer16;
   }
   else {
@@ -1211,8 +1280,8 @@ _swrast_depth_bounds_test( struct gl_context *ctx, SWspan 
*span )
   GLuint zbuffer32[MAX_WIDTH], *zbuffer;
   ASSERT(rb->DataType == GL_UNSIGNED_INT);
   if (span->arrayMask & SPAN_XY) {
- _swrast_get_values(ctx, rb, count, span->array->x, span->array->y,
-zbuffer32, sizeof(GLuint));
+ get_z32_values(ctx, rb, count, span->array->x, span->array->y,
+zbuffer32);
  zbuffer = zbuffer32;
   }
   else {
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 05/22] swrast: rewrite depth-testing code

2011-12-18 Thread Brian Paul
Consolidate code, stop using the deprecateted renderbuffer Put/Get
Row/Values() functions.
---
 src/mesa/swrast/s_depth.c | 1227 -
 1 files changed, 208 insertions(+), 1019 deletions(-)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index cedc7fd..4d72d5a 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -35,471 +35,124 @@
 #include "s_span.h"
 
 
+
+#define Z_TEST(COMPARE)  \
+   do {  \
+  GLuint i;  \
+  for (i = 0; i < n; i++) {  \
+ if (mask[i]) {  \
+if (COMPARE) {   \
+   /* pass */\
+   if (write) {  \
+  zbuffer[i] = zfrag[i]; \
+   } \
+   passed++; \
+}\
+else {   \
+   /* fail */\
+   mask[i] = 0;  \
+}\
+ }   \
+  }  \
+   } while (0)
+
+
 /**
- * Do depth test for a horizontal span of fragments.
- * Input:  zbuffer - array of z values in the zbuffer
- * z - array of fragment z values
- * Return:  number of fragments which pass the test.
+ * Do depth test for an array of 16-bit Z values.
+ * @param zbuffer  array of Z buffer values (16-bit)
+ * @param zfrag  array of fragment Z values (use 16-bit in 32-bit uint)
+ * @param mask  which fragments are alive, killed afterward
+ * @return  number of fragments which pass the test.
  */
 static GLuint
 depth_test_span16( struct gl_context *ctx, GLuint n,
-   GLushort zbuffer[], const GLuint z[], GLubyte mask[] )
+   GLushort zbuffer[], const GLuint zfrag[], GLubyte mask[] )
 {
+   const GLboolean write = ctx->Depth.Mask;
GLuint passed = 0;
 
/* switch cases ordered from most frequent to less frequent */
switch (ctx->Depth.Func) {
-  case GL_LESS:
- if (ctx->Depth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0; iDepth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0;iDepth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0;i= zbuffer[i]) {
-zbuffer[i] = z[i];
-passed++;
- }
- else {
-mask[i] = 0;
- }
-  }
-   }
-}
-else {
-   /* Don't update Z buffer */
-GLuint i;
-   for (i=0;i= zbuffer[i]) {
-/* pass */
-passed++;
- }
- else {
-mask[i] = 0;
- }
-  }
-   }
-}
-break;
-  case GL_GREATER:
-if (ctx->Depth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0;i zbuffer[i]) {
-zbuffer[i] = z[i];
-passed++;
- }
- else {
-mask[i] = 0;
- }
-  }
-   }
-}
-else {
-   /* Don't update Z buffer */
-GLuint i;
-   for (i=0;i zbuffer[i]) {
-/* pass */
-passed++;
- }
- else {
-mask[i] = 0;
- }
-  }
-   }
-}
-break;
-  case GL_NOTEQUAL:
-if (ctx->Depth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0;iDepth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0;iDepth.Mask) {
-   /* Update Z buffer */
-GLuint i;
-   for (i=0;i= zbuffer[i]);
+  break;
+   case GL_GREATER:
+  Z_TEST(zfrag[i] > zbuffer[i]);
+  break;
+   case GL_NOTEQUAL:
+  Z_TEST(zfrag[i] != zbuffer[i]);
+  break;
+   case GL_EQUAL:
+  Z_TEST(zfrag[i] == zbuffer[i]);
+  break;
+   case GL_ALWAYS:
+  Z_TEST(1);
+  break;
+   case GL_NEVER:
+  memset(mask, 0, n * sizeof(GLubyte));
+  break;
+   default:
+  _mesa_problem(ctx, "Bad depth func in depth_test_span16");
}
 
return passed;
 }
 
 
+/**
+ * Do depth test for an array of 32-bit Z values.
+ * @param zbuffer  array of Z buffer values (32-bit)
+ * @param zfrag  array of fragment Z values (use 32-bits in 32-bit uint)
+ * @param mask  which fragments are alive, killed afterward
+ * @return  number of fragments which pass the test.
+ */
 static GLuint
 depth_test_span32( struct gl_context *ctx, GLuint n,
-

[Mesa-dev] [PATCH 06/22] mesa: rewrite _swrast_depth_bounds_test()

2011-12-18 Thread Brian Paul
Stop using the deprecated renderbuffer functions.
---
 src/mesa/swrast/s_depth.c |  103 +---
 1 files changed, 21 insertions(+), 82 deletions(-)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 4d72d5a..f441795 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -203,41 +203,6 @@ _swrast_depth_clamp_span( struct gl_context *ctx, SWspan 
*span )
 
 
 /**
- * Get array of 16-bit z values from the depth buffer.  With clipping.
- */
-static void
-get_z16_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
-   GLuint count, const GLint x[], const GLint y[],
-   GLushort zbuffer[])
-{
-   const GLint w = rb->Width, h = rb->Height;
-   const GLubyte *map = (const GLubyte *) rb->Data;
-   GLuint i;
-
-   if (rb->Format == MESA_FORMAT_Z16) {
-  const GLuint rowStride = rb->RowStride * 2;
-  for (i = 0; i < count; i++) {
- if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
-zbuffer[i] = *((GLushort *) (map + y[i] * rowStride + x[i] * 2));
- }
-  }
-   }
-   else {
-  const GLuint bpp = _mesa_get_format_bytes(rb->Format);
-  const GLuint rowStride = rb->RowStride * bpp;
-  for (i = 0; i < count; i++) {
- if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
-GLuint d32;
-const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
-_mesa_unpack_uint_z_row(rb->Format, 1, src, &d32);
-zbuffer[i] = d32 >> 16;
- }
-  }
-   }
-}
-
-
-/**
  * Get array of 32-bit z values from the depth buffer.  With clipping.
  */
 static void
@@ -313,7 +278,6 @@ get_z_address(struct gl_renderbuffer *rb, GLint x, GLint y)
 }
 
 
-
 /**
  * Apply depth (Z) buffer testing to the span.
  * \return approx number of pixels that passed (only zero is reliable)
@@ -429,67 +393,42 @@ GLboolean
 _swrast_depth_bounds_test( struct gl_context *ctx, SWspan *span )
 {
struct gl_framebuffer *fb = ctx->DrawBuffer;
-   struct gl_renderbuffer *rb = fb->_DepthBuffer;
+   struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+   const GLint bpp = _mesa_get_format_bytes(rb->Format);
+   const GLint rowStride = rb->RowStride * bpp;
+   GLubyte *zStart = (GLubyte*) rb->Data + span->y * rowStride + span->x * bpp;
GLuint zMin = (GLuint) (ctx->Depth.BoundsMin * fb->_DepthMaxF + 0.5F);
GLuint zMax = (GLuint) (ctx->Depth.BoundsMax * fb->_DepthMaxF + 0.5F);
GLubyte *mask = span->array->mask;
const GLuint count = span->end;
GLuint i;
GLboolean anyPass = GL_FALSE;
+   GLuint zBufferTemp[MAX_WIDTH];
+   const GLuint *zBufferVals;
 
-   if (rb->DataType == GL_UNSIGNED_SHORT) {
-  /* get 16-bit values */
-  GLushort zbuffer16[MAX_WIDTH], *zbuffer;
-  if (span->arrayMask & SPAN_XY) {
- get_z16_values(ctx, rb, count, span->array->x, span->array->y,
-zbuffer16);
- zbuffer = zbuffer16;
-  }
-  else {
- zbuffer = (GLushort*) rb->GetPointer(ctx, rb, span->x, span->y);
- if (!zbuffer) {
-rb->GetRow(ctx, rb, count, span->x, span->y, zbuffer16);
-zbuffer = zbuffer16;
- }
-  }
-  assert(zbuffer);
-
-  /* Now do the tests */
-  for (i = 0; i < count; i++) {
- if (mask[i]) {
-if (zbuffer[i] < zMin || zbuffer[i] > zMax)
-   mask[i] = GL_FALSE;
-else
-   anyPass = GL_TRUE;
- }
-  }
+   if (rb->Format == MESA_FORMAT_Z32 && !(span->arrayMask & SPAN_XY)) {
+  /* directly access 32-bit values in the depth buffer */
+  zBufferVals = (const GLuint *) zStart;
}
else {
-  /* get 32-bit values */
-  GLuint zbuffer32[MAX_WIDTH], *zbuffer;
-  ASSERT(rb->DataType == GL_UNSIGNED_INT);
+  /* unpack Z values into a temporary array */
   if (span->arrayMask & SPAN_XY) {
  get_z32_values(ctx, rb, count, span->array->x, span->array->y,
-zbuffer32);
- zbuffer = zbuffer32;
+zBufferTemp);
   }
   else {
- zbuffer = (GLuint*) rb->GetPointer(ctx, rb, span->x, span->y);
- if (!zbuffer) {
-rb->GetRow(ctx, rb, count, span->x, span->y, zbuffer32);
-zbuffer = zbuffer32;
- }
+ _mesa_unpack_uint_z_row(rb->Format, count, zStart, zBufferTemp);
   }
-  assert(zbuffer);
+  zBufferVals = zBufferTemp;
+   }
 
-  /* Now do the tests */
-  for (i = 0; i < count; i++) {
- if (mask[i]) {
-if (zbuffer[i] < zMin || zbuffer[i] > zMax)
-   mask[i] = GL_FALSE;
-else
-   anyPass = GL_TRUE;
- }
+   /* Now do the tests */
+   for (i = 0; i < count; i++) {
+  if (mask[i]) {
+ if (zBufferVals[i] < zMin || zBufferVals[i] > zMax)
+mask[i] = GL_FALSE;
+ else
+anyPass = GL_TRUE;
   }

[Mesa-dev] [PATCH 07/22] swrast: rewrite _swrast_read_depth_span_float()

2011-12-18 Thread Brian Paul
Stop using the deprecated renderbuffer GetRow() function.
---
 src/mesa/swrast/s_depth.c |   29 -
 1 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index f441795..806e62b 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -449,19 +449,16 @@ _swrast_depth_bounds_test( struct gl_context *ctx, SWspan 
*span )
  * bounds.
  */
 void
-_swrast_read_depth_span_float( struct gl_context *ctx, struct gl_renderbuffer 
*rb,
-   GLint n, GLint x, GLint y, GLfloat depth[] )
+_swrast_read_depth_span_float(struct gl_context *ctx,
+  struct gl_renderbuffer *rb,
+  GLint n, GLint x, GLint y, GLfloat depth[])
 {
-   const GLfloat scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
-
if (!rb) {
   /* really only doing this to prevent FP exceptions later */
   memset(depth, 0, n * sizeof(GLfloat));
   return;
}
 
-   ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
-
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
   /* span is completely outside framebuffer */
@@ -489,25 +486,7 @@ _swrast_read_depth_span_float( struct gl_context *ctx, 
struct gl_renderbuffer *r
   return;
}
 
-   if (rb->DataType == GL_UNSIGNED_INT) {
-  GLuint temp[MAX_WIDTH];
-  GLint i;
-  rb->GetRow(ctx, rb, n, x, y, temp);
-  for (i = 0; i < n; i++) {
- depth[i] = temp[i] * scale;
-  }
-   }
-   else if (rb->DataType == GL_UNSIGNED_SHORT) {
-  GLushort temp[MAX_WIDTH];
-  GLint i;
-  rb->GetRow(ctx, rb, n, x, y, temp);
-  for (i = 0; i < n; i++) {
- depth[i] = temp[i] * scale;
-  }
-   }
-   else {
-  _mesa_problem(ctx, "Invalid depth renderbuffer data type");
-   }
+   _mesa_unpack_float_z_row(rb->Format, n, get_z_address(rb, x, y), depth);
 }
 
 
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 08/22] swrast: rewrite _swrast_read_stencil_span()

2011-12-18 Thread Brian Paul
Use format pack/unpack functions instead of deprecated renderbuffer
GetRow/PutRow functions.
---
 src/mesa/swrast/s_stencil.c |   31 ++-
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 17b3b12..1d78e97 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -26,6 +26,7 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/imports.h"
+#include "main/format_pack.h"
 #include "main/format_unpack.h"
 
 #include "s_context.h"
@@ -52,6 +53,20 @@ ENDIF
 
 
 /**
+ * Return the address of a stencil value in a renderbuffer.
+ */
+static inline GLubyte *
+get_stencil_address(struct gl_renderbuffer *rb, GLint x, GLint y)
+{
+   const GLint bpp = _mesa_get_format_bytes(rb->Format);
+   const GLint rowStride = rb->RowStride * bpp;
+   assert(rb->Data);
+   return (GLubyte *) rb->Data + y * rowStride + x * bpp;
+}
+
+
+
+/**
  * Apply the given stencil operator to the array of stencil values.
  * Don't touch stencil[i] if mask[i] is zero.
  * Input:  n - size of stencil array
@@ -1075,6 +1090,8 @@ _swrast_read_stencil_span(struct gl_context *ctx, struct 
gl_renderbuffer *rb,
   GLint n, GLint x, GLint y, GLubyte stencil[])
 {
GLubyte *src;
+   const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+   const GLuint rowStride = rb->RowStride * bpp;
 
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
@@ -1096,7 +1113,7 @@ _swrast_read_stencil_span(struct gl_context *ctx, struct 
gl_renderbuffer *rb,
   return;
}
 
-   src = (GLubyte *) rb->Data + y * rb->RowStride +x;
+   src = (GLubyte *) rb->Data + y * rowStride + x * bpp;
_mesa_unpack_ubyte_stencil_row(rb->Format, n, src, stencil);
 }
 
@@ -1115,9 +1132,10 @@ _swrast_write_stencil_span(struct gl_context *ctx, GLint 
n, GLint x, GLint y,
const GLubyte stencil[] )
 {
struct gl_framebuffer *fb = ctx->DrawBuffer;
-   struct gl_renderbuffer *rb = fb->_StencilBuffer;
+   struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
const GLuint stencilMax = (1 << fb->Visual.stencilBits) - 1;
const GLuint stencilMask = ctx->Stencil.WriteMask[0];
+   GLubyte *stencilBuf;
 
if (y < 0 || y >= (GLint) rb->Height ||
x + n <= 0 || x >= (GLint) rb->Width) {
@@ -1138,19 +1156,22 @@ _swrast_write_stencil_span(struct gl_context *ctx, 
GLint n, GLint x, GLint y,
   return;
}
 
+   stencilBuf = get_stencil_address(rb, x, y);
+
if ((stencilMask & stencilMax) != stencilMax) {
   /* need to apply writemask */
   GLubyte destVals[MAX_WIDTH], newVals[MAX_WIDTH];
   GLint i;
-  rb->GetRow(ctx, rb, n, x, y, destVals);
+
+  _mesa_unpack_ubyte_stencil_row(rb->Format, n, stencilBuf, destVals);
   for (i = 0; i < n; i++) {
  newVals[i]
 = (stencil[i] & stencilMask) | (destVals[i] & ~stencilMask);
   }
-  rb->PutRow(ctx, rb, n, x, y, newVals, NULL);
+  _mesa_pack_ubyte_stencil_row(rb->Format, n, destVals, stencilBuf);
}
else {
-  rb->PutRow(ctx, rb, n, x, y, stencil, NULL);
+  _mesa_pack_ubyte_stencil_row(rb->Format, n, stencil, stencilBuf);
}
 }
 
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 09/22] swrast: remove dead code in s_stencil.c

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_stencil.c |   33 -
 1 files changed, 0 insertions(+), 33 deletions(-)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 1d78e97..5abf817 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -1045,39 +1045,6 @@ _swrast_stencil_and_ztest_span(struct gl_context *ctx, 
SWspan *span)
 }
 
 
-#if 0
-GLuint
-clip_span(GLuint bufferWidth, GLuint bufferHeight,
-  GLint x, GLint y, GLuint *count)
-{
-   GLuint n = *count;
-   GLuint skipPixels = 0;
-
-   if (y < 0 || y >= bufferHeight || x + n <= 0 || x >= bufferWidth) {
-  /* totally out of bounds */
-  n = 0;
-   }
-   else {
-  /* left clip */
-  if (x < 0) {
- skipPixels = -x;
- x = 0;
- n -= skipPixels;
-  }
-  /* right clip */
-  if (x + n > bufferWidth) {
- GLint dx = x + n - bufferWidth;
- n -= dx;
-  }
-   }
-
-   *count = n;
-
-   return skipPixels;
-}
-#endif
-
-
 /**
  * Return a span of stencil values from the stencil buffer.
  * Used for glRead/CopyPixels
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 10/22] swrast: rewrite stencil test code

2011-12-18 Thread Brian Paul
Stop using the deprecated renderbuffer Get/Put Row/Values functions.
Consolidate code paths, etc.  The file is nearly half the size it used
to be!
---
 src/mesa/swrast/s_stencil.c | 1119 ++-
 1 files changed, 260 insertions(+), 859 deletions(-)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 5abf817..41aff9b 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -65,194 +65,170 @@ get_stencil_address(struct gl_renderbuffer *rb, GLint x, 
GLint y)
 }
 
 
+/**
+ * Compute/return the offset of the stencil value in a pixel.
+ * For example, if the format is Z24+S8, the position of the stencil bits
+ * within the 4-byte pixel will be either 0 or 3.
+ */
+static GLint
+get_stencil_offset(gl_format format)
+{
+   const GLubyte one = 1;
+   GLubyte pixel[MAX_PIXEL_BYTES];
+   GLint bpp = _mesa_get_format_bytes(format);
+   GLint i;
+
+   assert(_mesa_get_format_bits(format, GL_STENCIL_BITS) == 8);
+   memset(pixel, 0, sizeof(pixel));
+   _mesa_pack_ubyte_stencil_row(format, 1, &one, pixel);
+
+   for (i = 0; i < bpp; i++) {
+  if (pixel[i])
+ return i;
+   }
+
+   _mesa_problem(NULL, "get_stencil_offset() failed\n");
+   return 0;
+}
+
+
+/** Clamp the stencil value to [0, 255] */
+static inline GLubyte
+clamp(GLint val)
+{
+   if (val < 0)
+  return 0;
+   else if (val > 255)
+  return 255;
+   else
+  return val;
+}
+
+
+#define STENCIL_OP(NEW_VAL) \
+   if (invmask == 0) {  \
+  for (i = j = 0; i < n; i++, j += stride) {\
+ if (mask[i]) { \
+GLubyte s = stencil[j]; \
+(void) s;   \
+stencil[j] = (GLubyte) (NEW_VAL);   \
+ }  \
+  } \
+   }\
+   else {   \
+  for (i = j = 0; i < n; i++, j += stride) {\
+ if (mask[i]) { \
+GLubyte s = stencil[j]; \
+stencil[j] = (GLubyte) ((invmask & s) | (wrtmask & (NEW_VAL))); \
+ }  \
+  } \
+   }
+
 
 /**
  * Apply the given stencil operator to the array of stencil values.
  * Don't touch stencil[i] if mask[i] is zero.
- * Input:  n - size of stencil array
- * oper - the stencil buffer operator
- * face - 0 or 1 for front or back face operation
- * stencil - array of stencil values
- * mask - array [n] of flag:  1=apply operator, 0=don't apply operator
- * Output:  stencil - modified values
+ * @param n   number of stencil values
+ * @param oper  the stencil buffer operator
+ * @param face  0 or 1 for front or back face operation
+ * @param stencil  array of stencil values (in/out)
+ * @param mask  array [n] of flag:  1=apply operator, 0=don't apply operator
+ * @param stride  stride between stencil values
  */
 static void
-apply_stencil_op( const struct gl_context *ctx, GLenum oper, GLuint face,
-  GLuint n, GLubyte stencil[], const GLubyte mask[] )
+apply_stencil_op(const struct gl_context *ctx, GLenum oper, GLuint face,
+ GLuint n, GLubyte stencil[], const GLubyte mask[],
+ GLint stride)
 {
const GLubyte ref = ctx->Stencil.Ref[face];
const GLubyte wrtmask = ctx->Stencil.WriteMask[face];
const GLubyte invmask = (GLubyte) (~wrtmask);
-   const GLubyte stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
-   GLuint i;
+   GLuint i, j;
 
switch (oper) {
-  case GL_KEEP:
- /* do nothing */
- break;
-  case GL_ZERO:
-if (invmask==0) {
-   for (i=0;i0) {
-stencil[i] = (GLubyte) (s-1);
- }
-  }
-   }
-}
-else {
-   for (i=0;i0) {
-stencil[i] = (GLubyte) ((invmask & s) | (wrtmask & (s-1)));
- }
-  }
-   }
-}
-break;
-  case GL_INCR_WRAP_EXT:
-if (invmask==0) {
-   for (i=0;iStencil.ValueMask[face];
-   const GLubyte r = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
+   const GLubyte ref = (GLubyte) (ctx->Stencil.Ref[face] & valueMask);
GLubyte s;
 
-   ASSERT(n <= MAX_WIDTH);
-
/*
 * Perform stencil test.  The results of this operat

[Mesa-dev] [PATCH 11/22] swrast: use _swrast_pixel_address() helper function

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_context.h |   12 
 src/mesa/swrast/s_depth.c   |   18 --
 src/mesa/swrast/s_stencil.c |   18 +++---
 3 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 446b990..af9e49e 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -422,5 +422,17 @@ _swrast_unmap_renderbuffers(struct gl_context *ctx);
 #define ATTRIB_LOOP_END } }
 
 
+/**
+ * Return the address of a pixel value in a mapped renderbuffer.
+ */
+static inline GLubyte *
+_swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
+{
+   const GLint bpp = _mesa_get_format_bytes(rb->Format);
+   const GLint rowStride = rb->RowStride * bpp;
+   return (GLubyte *) rb->Data + y * rowStride + x * bpp;
+}
+
+
 
 #endif
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 806e62b..f87adaa 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -31,6 +31,7 @@
 #include "main/macros.h"
 #include "main/imports.h"
 
+#include "s_context.h"
 #include "s_depth.h"
 #include "s_span.h"
 
@@ -267,18 +268,6 @@ put_z32_values(struct gl_context *ctx, struct 
gl_renderbuffer *rb,
 
 
 /**
- * Return the address of a Z value in a renderbuffer.
- */
-static INLINE void *
-get_z_address(struct gl_renderbuffer *rb, GLint x, GLint y)
-{
-   const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStride * bpp;
-   return (GLubyte *) rb->Data + y * rowStride + x * bpp;
-}
-
-
-/**
  * Apply depth (Z) buffer testing to the span.
  * \return approx number of pixels that passed (only zero is reliable)
  */
@@ -288,7 +277,7 @@ _swrast_depth_test_span(struct gl_context *ctx, SWspan 
*span)
struct gl_framebuffer *fb = ctx->DrawBuffer;
struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   void *zStart = get_z_address(rb, span->x, span->y);
+   void *zStart = _swrast_pixel_address(rb, span->x, span->y);
const GLuint count = span->end;
const GLuint *fragZ = span->array->z;
GLubyte *mask = span->array->mask;
@@ -486,7 +475,8 @@ _swrast_read_depth_span_float(struct gl_context *ctx,
   return;
}
 
-   _mesa_unpack_float_z_row(rb->Format, n, get_z_address(rb, x, y), depth);
+   _mesa_unpack_float_z_row(rb->Format, n, _swrast_pixel_address(rb, x, y),
+depth);
 }
 
 
diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 41aff9b..c2d5edf 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -52,18 +52,6 @@ ENDIF
 */
 
 
-/**
- * Return the address of a stencil value in a renderbuffer.
- */
-static inline GLubyte *
-get_stencil_address(struct gl_renderbuffer *rb, GLint x, GLint y)
-{
-   const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStride * bpp;
-   assert(rb->Data);
-   return (GLubyte *) rb->Data + y * rowStride + x * bpp;
-}
-
 
 /**
  * Compute/return the offset of the stencil value in a pixel.
@@ -342,7 +330,7 @@ put_s8_values(struct gl_context *ctx, struct 
gl_renderbuffer *rb,
 
for (i = 0; i < count; i++) {
   if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
- GLubyte *dst = get_stencil_address(rb, x[i], y[i]);
+ GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
  _mesa_pack_ubyte_stencil_row(rb->Format, 1, &stencil[i], dst);
   }
}
@@ -377,7 +365,7 @@ _swrast_stencil_and_ztest_span(struct gl_context *ctx, 
SWspan *span)
* 8 bits for all MESA_FORMATs, we just need to use the right offset
* and stride to access them.
*/
-  stencilBuf = get_stencil_address(rb, span->x, span->y) + stencilOffset;
+  stencilBuf = _swrast_pixel_address(rb, span->x, span->y) + stencilOffset;
}
 
/*
@@ -524,7 +512,7 @@ _swrast_write_stencil_span(struct gl_context *ctx, GLint n, 
GLint x, GLint y,
   return;
}
 
-   stencilBuf = get_stencil_address(rb, x, y);
+   stencilBuf = _swrast_pixel_address(rb, x, y);
 
if ((stencilMask & stencilMax) != stencilMax) {
   /* need to apply writemask */
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 12/22] swast: replace renderbuffer->GetPointer() with _swrast_pixel_address()

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_linetemp.h |2 +-
 src/mesa/swrast/s_triangle.c |4 ++--
 src/mesa/swrast/s_tritemp.h  |2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/mesa/swrast/s_linetemp.h b/src/mesa/swrast/s_linetemp.h
index f9f2d29..1668f7d 100644
--- a/src/mesa/swrast/s_linetemp.h
+++ b/src/mesa/swrast/s_linetemp.h
@@ -166,7 +166,7 @@ NAME( struct gl_context *ctx, const SWvertex *vert0, const 
SWvertex *vert1 )
*/
 
 #ifdef DEPTH_TYPE
-   zPtr = (DEPTH_TYPE *) zrb->GetPointer(ctx, zrb, x0, y0);
+   zPtr = (DEPTH_TYPE *) _swrast_pixel_address(zrb, x0, y0);
 #endif
 #ifdef PIXEL_ADDRESS
pixelPtr = (PIXEL_TYPE *) PIXEL_ADDRESS(x0,y0);
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index b4f8e74..10d077f 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -887,7 +887,7 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
if (rb->Format == MESA_FORMAT_Z16) {
\
   GLuint i;
\
   const GLushort *zRow = (const GLushort *)
\
- rb->GetPointer(ctx, rb, span.x, span.y);  \
+ _swrast_pixel_address(rb, span.x, span.y); \
   for (i = 0; i < span.end; i++) { \
  GLuint z = FixedToDepth(span.z);  \
  if (z < zRow[i]) {\
@@ -899,7 +899,7 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
else {  \
   GLuint i;
\
   const GLuint *zRow = (const GLuint *)\
- rb->GetPointer(ctx, rb, span.x, span.y);  \
+ _swrast_pixel_address(rb, span.x, span.y);\
   for (i = 0; i < span.end; i++) { \
  if ((GLuint)span.z < zRow[i]) {   \
 q->Result++;   \
diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h
index 4d6309b..061759d 100644
--- a/src/mesa/swrast/s_tritemp.h
+++ b/src/mesa/swrast/s_tritemp.h
@@ -631,7 +631,7 @@ static void NAME(struct gl_context *ctx, const SWvertex *v0,
   }
 #  ifdef DEPTH_TYPE
   zRow = (DEPTH_TYPE *)
-zrb->GetPointer(ctx, zrb, FixedToInt(fxLeftEdge), span.y);
+_swrast_pixel_address(zrb, FixedToInt(fxLeftEdge), span.y);
   dZRowOuter = (ctx->DrawBuffer->Width + idxOuter) * 
sizeof(DEPTH_TYPE);
 #  endif
}
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 13/22] swrast: remove needless assignment in draw_depth_stencil_pixels()

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_drawpix.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 7259881..4a661a0 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -617,7 +617,6 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, 
GLint y,
   GLint i;
 
   depthRb = ctx->DrawBuffer->_DepthBuffer;
-  stencilRb = ctx->DrawBuffer->_StencilBuffer;
 
   for (i = 0; i < height; i++) {
  const GLuint *depthStencilSrc = (const GLuint *)
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 14/22] swrast: stop using depth/stencil wrappers in CopyPixels code

2011-12-18 Thread Brian Paul
The functions that read depth/stencil values understand all (packed)
depth/stencil buffer formats now so there's no reason to use the
wrappers.

Also, improve the format checks in fast_copy_pixels() to catch mismatched
depth/stencil cases.
---
 src/mesa/swrast/s_copypix.c |   29 +
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 2a789ab..3b6502e 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -245,7 +245,7 @@ copy_depth_pixels( struct gl_context *ctx, GLint srcx, 
GLint srcy,
GLint destx, GLint desty )
 {
struct gl_framebuffer *fb = ctx->ReadBuffer;
-   struct gl_renderbuffer *readRb = fb->_DepthBuffer;
+   struct gl_renderbuffer *readRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
GLfloat *p, *tmpImage;
GLint sy, dy, stepy;
GLint j;
@@ -339,7 +339,7 @@ copy_stencil_pixels( struct gl_context *ctx, GLint srcx, 
GLint srcy,
  GLint destx, GLint desty )
 {
struct gl_framebuffer *fb = ctx->ReadBuffer;
-   struct gl_renderbuffer *rb = fb->_StencilBuffer;
+   struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
GLint sy, dy, stepy;
GLint j;
GLubyte *p, *tmpImage;
@@ -446,7 +446,7 @@ copy_depth_stencil_pixels(struct gl_context *ctx,
 
depthDrawRb = ctx->DrawBuffer->_DepthBuffer;
depthReadRb = ctx->ReadBuffer->_DepthBuffer;
-   stencilReadRb = ctx->ReadBuffer->_StencilBuffer;
+   stencilReadRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
 
ASSERT(depthDrawRb);
ASSERT(depthReadRb);
@@ -599,7 +599,7 @@ copy_depth_stencil_pixels(struct gl_context *ctx,
 
 
 /**
- * Try to do a fast copy pixels.
+ * Try to do a fast copy pixels with memcpy.
  * \return GL_TRUE if successful, GL_FALSE otherwise.
  */
 static GLboolean
@@ -630,12 +630,12 @@ fast_copy_pixels(struct gl_context *ctx,
   dstRb = dstFb->_ColorDrawBuffers[0];
}
else if (type == GL_STENCIL) {
-  srcRb = srcFb->_StencilBuffer;
-  dstRb = dstFb->_StencilBuffer;
+  srcRb = srcFb->Attachment[BUFFER_STENCIL].Renderbuffer;
+  dstRb = dstFb->Attachment[BUFFER_STENCIL].Renderbuffer;
}
else if (type == GL_DEPTH) {
-  srcRb = srcFb->_DepthBuffer;
-  dstRb = dstFb->_DepthBuffer;
+  srcRb = srcFb->Attachment[BUFFER_DEPTH].Renderbuffer;
+  dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer;
}
else {
   ASSERT(type == GL_DEPTH_STENCIL_EXT);
@@ -649,6 +649,19 @@ fast_copy_pixels(struct gl_context *ctx,
   return GL_FALSE;
}
 
+   if (type == GL_STENCIL || type == GL_DEPTH_COMPONENT) {
+  /* can't handle packed depth+stencil here */
+  if (_mesa_is_format_packed_depth_stencil(srcRb->Format) ||
+  _mesa_is_format_packed_depth_stencil(dstRb->Format))
+ return GL_FALSE;
+   }
+   else if (type == GL_DEPTH_STENCIL) {
+  /* can't handle separate depth/stencil buffers */
+  if (!_mesa_is_format_packed_depth_stencil(srcRb->Format) ||
+  !_mesa_is_format_packed_depth_stencil(dstRb->Format))
+ return GL_FALSE;
+   }
+
/* clipping not supported */
if (srcX < 0 || srcX + width > (GLint) srcFb->Width ||
srcY < 0 || srcY + height > (GLint) srcFb->Height ||
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 15/22] swrast: remove the copy_depth_stencil_pixels() function

2011-12-18 Thread Brian Paul
Hopefully glCopyPixels(GL_DEPTH_STENCIL) will be handled by the
fast copy function.  Otherwise, just do the copy with separate
depth + stencil copies.  That's effectively what the removed code
did anyway.
---
 src/mesa/swrast/s_copypix.c |  181 +--
 1 files changed, 3 insertions(+), 178 deletions(-)

diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 3b6502e..14583bd 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -422,183 +422,6 @@ copy_stencil_pixels( struct gl_context *ctx, GLint srcx, 
GLint srcy,
 
 
 /**
- * This isn't terribly efficient.  If a driver really has combined
- * depth/stencil buffers the driver should implement an optimized
- * CopyPixels function.
- */
-static void
-copy_depth_stencil_pixels(struct gl_context *ctx,
-  const GLint srcX, const GLint srcY,
-  const GLint width, const GLint height,
-  const GLint destX, const GLint destY)
-{
-   struct gl_renderbuffer *stencilReadRb, *depthReadRb, *depthDrawRb;
-   GLint sy, dy, stepy;
-   GLint j;
-   GLubyte *tempStencilImage = NULL, *stencilPtr = NULL;
-   GLfloat *tempDepthImage = NULL, *depthPtr = NULL;
-   const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;
-   const GLuint stencilMask = ctx->Stencil.WriteMask[0];
-   const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
-   const GLboolean scaleOrBias
-  = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
-   GLint overlapping;
-
-   depthDrawRb = ctx->DrawBuffer->_DepthBuffer;
-   depthReadRb = ctx->ReadBuffer->_DepthBuffer;
-   stencilReadRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
-
-   ASSERT(depthDrawRb);
-   ASSERT(depthReadRb);
-   ASSERT(stencilReadRb);
-
-   if (ctx->DrawBuffer == ctx->ReadBuffer) {
-  overlapping = regions_overlap(srcX, srcY, destX, destY, width, height,
-ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
-   }
-   else {
-  overlapping = GL_FALSE;
-   }
-
-   /* Determine if copy should be bottom-to-top or top-to-bottom */
-   if (!overlapping && srcY < destY) {
-  /* top-down  max-to-min */
-  sy = srcY + height - 1;
-  dy = destY + height - 1;
-  stepy = -1;
-   }
-   else {
-  /* bottom-up  min-to-max */
-  sy = srcY;
-  dy = destY;
-  stepy = 1;
-   }
-
-   if (overlapping) {
-  GLint ssy = sy;
-
-  if (stencilMask != 0x0) {
- tempStencilImage
-= (GLubyte *) malloc(width * height * sizeof(GLubyte));
- if (!tempStencilImage) {
-_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
-return;
- }
-
- /* get copy of stencil pixels */
- stencilPtr = tempStencilImage;
- for (j = 0; j < height; j++, ssy += stepy) {
-_swrast_read_stencil_span(ctx, stencilReadRb,
-  width, srcX, ssy, stencilPtr);
-stencilPtr += width;
- }
- stencilPtr = tempStencilImage;
-  }
-
-  if (ctx->Depth.Mask) {
- tempDepthImage
-= (GLfloat *) malloc(width * height * sizeof(GLfloat));
- if (!tempDepthImage) {
-_mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
-free(tempStencilImage);
-return;
- }
-
- /* get copy of depth pixels */
- depthPtr = tempDepthImage;
- for (j = 0; j < height; j++, ssy += stepy) {
-_swrast_read_depth_span_float(ctx, depthReadRb,
-  width, srcX, ssy, depthPtr);
-depthPtr += width;
- }
- depthPtr = tempDepthImage;
-  }
-   }
-
-   for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
-  if (stencilMask != 0x0) {
- GLubyte stencil[MAX_WIDTH];
-
- /* Get stencil values */
- if (overlapping) {
-memcpy(stencil, stencilPtr, width * sizeof(GLubyte));
-stencilPtr += width;
- }
- else {
-_swrast_read_stencil_span(ctx, stencilReadRb,
-  width, srcX, sy, stencil);
- }
-
- _mesa_apply_stencil_transfer_ops(ctx, width, stencil);
-
- /* Write values */
- if (zoom) {
-_swrast_write_zoomed_stencil_span(ctx, destX, destY, width,
-  destX, dy, stencil);
- }
- else {
-_swrast_write_stencil_span( ctx, width, destX, dy, stencil );
- }
-  }
-
-  if (ctx->Depth.Mask) {
- GLfloat depth[MAX_WIDTH];
- GLuint zVals32[MAX_WIDTH];
- GLushort zVals16[MAX_WIDTH];
- GLvoid *zVals;
- GLuint zBytes;
-
- /* get depth values */
- if (overlapping) {
-memcpy(depth, depthPtr, width * sizeof(GLfloat));
-depthPtr += width;
- }
- e

[Mesa-dev] [PATCH 16/22] swrast: fast_draw_depth_stencil() for glDrawPixels(GL_DEPTH_STENCIL)

2011-12-18 Thread Brian Paul
Stop using deprecated renderbuffer PutRow() function.  Note that we
aren't using Map/UnmapRenderbuffer() yet because this call is inside
a swrast_render_start/finish() pair.
---
 src/mesa/swrast/s_drawpix.c |   64 ---
 1 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 4a661a0..19b43f6 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -551,6 +551,49 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
 
 
 /**
+ * Draw depth+stencil values into a MESA_FORAMT_Z24_S8 or MESA_FORMAT_S8_Z24
+ * renderbuffer.  No masking, zooming, scaling, etc.
+ */
+static void
+fast_draw_depth_stencil(struct gl_context *ctx, GLint x, GLint y,
+GLsizei width, GLsizei height,
+const struct gl_pixelstore_attrib *unpack,
+const GLvoid *pixels)
+{
+   const GLenum format = GL_DEPTH_STENCIL_EXT;
+   const GLenum type = GL_UNSIGNED_INT_24_8;
+   struct gl_renderbuffer *rb =
+  ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+   GLubyte *src, *dst;
+   GLint srcRowStride, dstRowStride;
+   GLint i;
+
+   src = _mesa_image_address2d(unpack, pixels, width, height,
+   format, type, 0, 0);
+   srcRowStride = _mesa_image_row_stride(unpack, width, format, type);
+
+   dst = _swrast_pixel_address(rb, x, y);
+   dstRowStride = rb->RowStride * 4;
+
+   for (i = 0; i < height; i++) {
+  if (rb->Format == MESA_FORMAT_Z24_S8) {
+ memcpy(dst, src, width * 4);
+  }
+  else {
+ /* swap Z24_S8 -> S8_Z24 */
+ GLuint j, *dst4 = (GLuint *) dst, *src4 = (GLuint *) src;
+ for (j = 0; j < width; j++) {
+dst4[j] = (src4[j] << 24) | (src4[j] >> 8);
+ }
+  }
+  dst += dstRowStride;
+  src += srcRowStride;
+   }
+}
+
+
+
+/**
  * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
  * The only per-pixel operations that apply are depth scale/bias,
  * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
@@ -587,27 +630,16 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint 
x, GLint y,
ASSERT(depthRb);
ASSERT(stencilRb);
 
-   if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
-   depthRb->Format == MESA_FORMAT_Z24_S8 &&
+   if (depthRb == stencilRb &&
+   (depthRb->Format == MESA_FORMAT_Z24_S8 ||
+depthRb->Format == MESA_FORMAT_S8_Z24) &&
type == GL_UNSIGNED_INT_24_8 &&
-   depthRb == stencilRb &&
-   depthRb->GetRow &&  /* May be null if depthRb is a wrapper around
-   * separate depth and stencil buffers. */
!scaleOrBias &&
!zoom &&
ctx->Depth.Mask &&
(stencilMask & 0xff) == 0xff) {
-  /* This is the ideal case.
-   * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
-   * Plus, no pixel transfer ops, zooming, or masking needed.
-   */
-  GLint i;
-  for (i = 0; i < height; i++) {
- const GLuint *src = (const GLuint *) 
-_mesa_image_address2d(&clippedUnpack, pixels, width, height,
-  GL_DEPTH_STENCIL_EXT, type, i, 0);
- depthRb->PutRow(ctx, depthRb, width, x, y + i, src, NULL);
-  }
+  fast_draw_depth_stencil(ctx, x, y, width, height,
+  &clippedUnpack, pixels);
}
else {
   /* sub-optimal cases:
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 17/22] swrast: move swrast_render_start/finish() call in drawpixels code

2011-12-18 Thread Brian Paul
We don't want to call these functions if where we'll be using
Map/UnmapRenderbuffer().  So push them further down in the drawpixels
cases so that we can switch over to Map/UnmapRenderbuffer() step by step.
---
 src/mesa/swrast/s_drawpix.c |   34 --
 1 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 19b43f6..b4d91c0 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -111,6 +111,7 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, 
GLint y,
/*
 * Ready to draw!
 */
+   swrast_render_start(ctx);
 
if (format == GL_RGBA && type == rbType) {
   const GLubyte *src
@@ -139,7 +140,7 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, 
GLint y,
  }
  span.array->ChanType = CHAN_TYPE;
   }
-  return GL_TRUE;
+  goto end;
}
 
if (format == GL_RGB && type == rbType) {
@@ -170,12 +171,14 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, 
GLint y,
  }
  span.array->ChanType = CHAN_TYPE;
   }
-  return GL_TRUE;
+  goto end;
}
 
/* Remaining cases haven't been tested with alignment != 1 */
-   if (userUnpack->Alignment != 1)
+   if (userUnpack->Alignment != 1) {
+  swrast_render_finish(ctx);
   return GL_FALSE;
+   }
 
if (format == GL_LUMINANCE && type == CHAN_TYPE && rbType == CHAN_TYPE) {
   const GLchan *src = (const GLchan *) pixels
@@ -217,7 +220,7 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, 
GLint y,
 destY++;
  }
   }
-  return GL_TRUE;
+  goto end;
}
 
if (format == GL_LUMINANCE_ALPHA && type == CHAN_TYPE && rbType == 
CHAN_TYPE) {
@@ -263,7 +266,7 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, 
GLint y,
 destY++;
  }
   }
-  return GL_TRUE;
+  goto end;
}
 
if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
@@ -299,12 +302,17 @@ fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, 
GLint y,
destY++;
 }
  }
- return GL_TRUE;
+ goto end;
   }
}
 
/* can't handle this pixel format and/or data type */
return GL_FALSE;
+
+end:
+   /* success, unmap render buffers */
+   swrast_render_finish(ctx);
+   return GL_TRUE;
 }
 
 
@@ -480,6 +488,8 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
   return;
}
 
+   swrast_render_start(ctx);
+
INIT_SPAN(span, GL_BITMAP);
_swrast_span_default_attribs(ctx, &span);
span.arrayMask = SPAN_RGBA;
@@ -547,6 +557,8 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
if (convImage) {
   free(convImage);
}
+
+   swrast_render_finish(ctx);
 }
 
 
@@ -747,8 +759,6 @@ _swrast_DrawPixels( struct gl_context *ctx,
 */
_mesa_set_vp_override(ctx, GL_TRUE);
 
-   swrast_render_start(ctx);
-
if (ctx->NewState)
   _mesa_update_state(ctx);
 
@@ -757,7 +767,6 @@ _swrast_DrawPixels( struct gl_context *ctx,
 
pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
if (!pixels) {
-  swrast_render_finish(ctx);
   _mesa_set_vp_override(ctx, save_vp_override);
   return;
}
@@ -767,20 +776,25 @@ _swrast_DrawPixels( struct gl_context *ctx,
 */
switch (format) {
case GL_STENCIL_INDEX:
+  swrast_render_start(ctx);
   draw_stencil_pixels( ctx, x, y, width, height, type, unpack, pixels );
+  swrast_render_finish(ctx);
   break;
case GL_DEPTH_COMPONENT:
+  swrast_render_start(ctx);
   draw_depth_pixels( ctx, x, y, width, height, type, unpack, pixels );
+  swrast_render_finish(ctx);
   break;
case GL_DEPTH_STENCIL_EXT:
+  swrast_render_start(ctx);
   draw_depth_stencil_pixels(ctx, x, y, width, height, type, unpack, 
pixels);
+  swrast_render_finish(ctx);
   break;
default:
   /* all other formats should be color formats */
   draw_rgba_pixels(ctx, x, y, width, height, format, type, unpack, pixels);
}
 
-   swrast_render_finish(ctx);
_mesa_set_vp_override(ctx, save_vp_override);
 
_mesa_unmap_pbo_source(ctx, unpack);
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 18/22] swrast: refactor fast_draw_rgba_pixels()

2011-12-18 Thread Brian Paul
Use Map/UnmapRenderbuffer() for the special, optimized cases we care about.
---
 src/mesa/swrast/s_drawpix.c |  401 ++-
 1 files changed, 167 insertions(+), 234 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index b4d91c0..c14fd02 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -25,6 +25,7 @@
 
 #include "main/glheader.h"
 #include "main/bufferobj.h"
+#include "main/colormac.h"
 #include "main/condrender.h"
 #include "main/context.h"
 #include "main/image.h"
@@ -41,6 +42,146 @@
 #include "s_zoom.h"
 
 
+/**
+ * Handle a common case of drawing GL_RGB/GL_UNSIGNED_BYTE into a
+ * MESA_FORMAT_XRGB888 or MESA_FORMAT_ARGB888 renderbuffer.
+ */
+static void
+fast_draw_rgb_ubyte_pixels(struct gl_context *ctx,
+   struct gl_renderbuffer *rb,
+   GLint x, GLint y,
+   GLsizei width, GLsizei height,
+   const struct gl_pixelstore_attrib *unpack,
+   const GLvoid *pixels)
+{
+   const GLubyte *src = (const GLubyte *)
+  _mesa_image_address2d(unpack, pixels, width,
+height, GL_RGB, GL_UNSIGNED_BYTE, 0, 0);
+   const GLint srcRowStride = _mesa_image_row_stride(unpack, width,
+ GL_RGB, GL_UNSIGNED_BYTE);
+   GLint i, j;
+   GLubyte *dst;
+   GLint dstRowStride;
+
+   ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
+   GL_MAP_WRITE_BIT, &dst, &dstRowStride);
+
+   if (!dst) {
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
+  return;
+   }
+
+   if (ctx->Pixel.ZoomY == -1.0f) {
+  dst = dst + (height - 1) * dstRowStride;
+  dstRowStride = -dstRowStride;
+   }
+
+   for (i = 0; i < height; i++) {
+  GLuint *dst4 = (GLuint *) dst;
+  for (j = 0; j < width; j++) {
+ dst4[j] = PACK_COLOR_(0xff, src[j*3+0], src[j*3+1], src[j*3+2]);
+  }
+  dst += dstRowStride;
+  src += srcRowStride;
+   }
+
+   ctx->Driver.UnmapRenderbuffer(ctx, rb);
+}
+
+
+/**
+ * Handle a common case of drawing GL_RGBA/GL_UNSIGNED_BYTE into a
+ * MESA_FORMAT_ARGB888 or MESA_FORMAT_xRGB888 renderbuffer.
+ */
+static void
+fast_draw_rgba_ubyte_pixels(struct gl_context *ctx,
+   struct gl_renderbuffer *rb,
+   GLint x, GLint y,
+   GLsizei width, GLsizei height,
+   const struct gl_pixelstore_attrib *unpack,
+   const GLvoid *pixels)
+{
+   const GLubyte *src = (const GLubyte *)
+  _mesa_image_address2d(unpack, pixels, width,
+height, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
+   const GLint srcRowStride =
+  _mesa_image_row_stride(unpack, width, GL_RGBA, GL_UNSIGNED_BYTE);
+   GLint i, j;
+   GLubyte *dst;
+   GLint dstRowStride;
+
+   ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
+   GL_MAP_WRITE_BIT, &dst, &dstRowStride);
+
+   if (!dst) {
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
+  return;
+   }
+
+   if (ctx->Pixel.ZoomY == -1.0f) {
+  dst = dst + (height - 1) * dstRowStride;
+  dstRowStride = -dstRowStride;
+   }
+
+   for (i = 0; i < height; i++) {
+  GLuint *dst4 = (GLuint *) dst;
+  for (j = 0; j < width; j++) {
+ dst4[j] = PACK_COLOR_(src[j*4+0], src[j*4+1],
+   src[j*4+2], src[j*4+3]);
+  }
+  dst += dstRowStride;
+  src += srcRowStride;
+   }
+
+   ctx->Driver.UnmapRenderbuffer(ctx, rb);
+}
+
+
+/**
+ * Handle a common case of drawing a format/type combination that
+ * exactly matches the renderbuffer format.
+ */
+static void
+fast_draw_generic_pixels(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const struct gl_pixelstore_attrib *unpack,
+ const GLvoid *pixels)
+{
+   const GLubyte *src = (const GLubyte *)
+  _mesa_image_address2d(unpack, pixels, width,
+height, format, type, 0, 0);
+   const GLint srcRowStride =
+  _mesa_image_row_stride(unpack, width, format, type);
+   const GLint rowLength = width * _mesa_get_format_bytes(rb->Format);
+   GLint i;
+   GLubyte *dst;
+   GLint dstRowStride;
+
+   ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
+   GL_MAP_WRITE_BIT, &dst, &dstRowStride);
+
+   if (!dst) {
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
+  return;
+   }
+
+   if (ctx->Pixel.ZoomY == -1.0f) {
+  dst = dst + (height - 1) * dstRowStride;
+  dstRowStride = -dstRowStride;
+   }
+
+   for (i = 0; i < height; i++) {
+  memcpy(dst,

[Mesa-dev] [PATCH 19/22] swrast: stop using PutRowRGB() in triangle code

2011-12-18 Thread Brian Paul
---
 src/mesa/swrast/s_triangle.c |   22 --
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 10d077f..c4d504b 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -142,7 +142,7 @@ _swrast_culltriangle( struct gl_context *ctx,
 
 #define RENDER_SPAN( span )\
GLuint i;   \
-   GLubyte rgb[MAX_WIDTH][3];  \
+   GLubyte rgba[MAX_WIDTH][4]; \
span.intTex[0] -= FIXED_HALF; /* off-by-one error? */   \
span.intTex[1] -= FIXED_HALF;   \
for (i = 0; i < span.end; i++) {\
@@ -150,13 +150,14 @@ _swrast_culltriangle( struct gl_context *ctx,
   GLint t = FixedToInt(span.intTex[1]) & tmask;\
   GLint pos = (t << twidth_log2) + s;  \
   pos = pos + pos + pos;  /* multiply by 3 */  \
-  rgb[i][RCOMP] = texture[pos+2];  \
-  rgb[i][GCOMP] = texture[pos+1];  \
-  rgb[i][BCOMP] = texture[pos+0];  \
+  rgba[i][RCOMP] = texture[pos+2]; \
+  rgba[i][GCOMP] = texture[pos+1]; \
+  rgba[i][BCOMP] = texture[pos+0]; \
+  rgba[i][ACOMP] = 0xff;\
   span.intTex[0] += span.intTexStep[0];\
   span.intTex[1] += span.intTexStep[1];\
}   \
-   rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, rgb, NULL);
+   rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, NULL);
 
 #include "s_tritemp.h"
 
@@ -198,7 +199,7 @@ _swrast_culltriangle( struct gl_context *ctx,
 
 #define RENDER_SPAN( span )\
GLuint i;   \
-   GLubyte rgb[MAX_WIDTH][3];  \
+   GLubyte rgba[MAX_WIDTH][4]; \
span.intTex[0] -= FIXED_HALF; /* off-by-one error? */   \
span.intTex[1] -= FIXED_HALF;   \
for (i = 0; i < span.end; i++) {\
@@ -208,9 +209,10 @@ _swrast_culltriangle( struct gl_context *ctx,
  GLint t = FixedToInt(span.intTex[1]) & tmask; \
  GLint pos = (t << twidth_log2) + s;   \
  pos = pos + pos + pos;  /* multiply by 3 */   \
- rgb[i][RCOMP] = texture[pos+2];   \
- rgb[i][GCOMP] = texture[pos+1];   \
- rgb[i][BCOMP] = texture[pos+0];   \
+ rgba[i][RCOMP] = texture[pos+2];  \
+ rgba[i][GCOMP] = texture[pos+1];  \
+ rgba[i][BCOMP] = texture[pos+0];  \
+ rgba[i][ACOMP] = 0xff;\
  zRow[i] = z;  \
  span.array->mask[i] = 1;  \
   }
\
@@ -221,7 +223,7 @@ _swrast_culltriangle( struct gl_context *ctx,
   span.intTex[1] += span.intTexStep[1];\
   span.z += span.zStep;\
}   \
-   rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, rgb, span.array->mask);
+   rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, span.array->mask);
 
 #include "s_tritemp.h"
 
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 20/22] mesa: remove gl_renderbuffer::PutRowRGB()

2011-12-18 Thread Brian Paul
No longer used anywhere.
---
 src/mesa/drivers/dri/common/depthtmp.h|1 -
 src/mesa/drivers/dri/common/spantmp2.h|   41 --
 src/mesa/drivers/dri/common/stenciltmp.h  |1 -
 src/mesa/drivers/dri/swrast/swrast_span.c |8 -
 src/mesa/drivers/dri/swrast/swrast_spantemp.h |   41 --
 src/mesa/drivers/osmesa/osmesa.c  |   16 -
 src/mesa/drivers/windows/gdi/wmesa.c  |  123 -
 src/mesa/drivers/x11/xm_span.c|  601 -
 src/mesa/main/mtypes.h|9 -
 src/mesa/main/renderbuffer.c  |1 -
 src/mesa/swrast/s_depthstencil.c  |3 -
 src/mesa/swrast/s_renderbuffer.c  |   84 
 src/mesa/swrast/s_spantemp.h  |   26 --
 src/mesa/swrast/s_texrender.c |   62 ---
 14 files changed, 0 insertions(+), 1017 deletions(-)

diff --git a/src/mesa/drivers/dri/common/depthtmp.h 
b/src/mesa/drivers/dri/common/depthtmp.h
index 31ebc68..d8f259f 100644
--- a/src/mesa/drivers/dri/common/depthtmp.h
+++ b/src/mesa/drivers/dri/common/depthtmp.h
@@ -201,7 +201,6 @@ static void TAG(InitDepthPointers)(struct gl_renderbuffer 
*rb)
rb->GetRow = TAG(ReadDepthSpan);
rb->GetValues = TAG(ReadDepthPixels);
rb->PutRow = TAG(WriteDepthSpan);
-   rb->PutRowRGB = NULL;
rb->PutValues = TAG(WriteDepthPixels);
 }
 
diff --git a/src/mesa/drivers/dri/common/spantmp2.h 
b/src/mesa/drivers/dri/common/spantmp2.h
index 6030ca1..744dfcd 100644
--- a/src/mesa/drivers/dri/common/spantmp2.h
+++ b/src/mesa/drivers/dri/common/spantmp2.h
@@ -475,46 +475,6 @@ static void TAG(WriteRGBASpan)( struct gl_context *ctx,
HW_WRITE_UNLOCK();
 }
 
-static void TAG(WriteRGBSpan)( struct gl_context *ctx,
-   struct gl_renderbuffer *rb,
-  GLuint n, GLint x, GLint y,
-  const void *values, const GLubyte mask[] )
-{
-   (void) ctx;
-
-   HW_WRITE_LOCK()
-  {
- const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
-GLint x1;
-GLint n1;
-LOCAL_VARS;
-
-y = Y_FLIP(y);
-
-HW_WRITE_CLIPLOOP()
-   {
-  GLint i = 0;
-  CLIPSPAN(x,y,n,x1,n1,i);
-
-  if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
-   (int)i, (int)n1, (int)x1);
-
-  if (mask)
-  {
- for (;n1>0;i++,x1++,n1--)
-if (mask[i])
-   WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 
);
-  }
-  else
-  {
- for (;n1>0;i++,x1++,n1--)
-WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
-  }
-   }
-HW_ENDCLIPLOOP();
-  }
-   HW_WRITE_UNLOCK();
-}
 
 static void TAG(WriteRGBAPixels)( struct gl_context *ctx,
   struct gl_renderbuffer *rb,
@@ -763,7 +723,6 @@ static void TAG(ReadRGBAPixels)( struct gl_context *ctx,
 static void TAG(InitPointers)(struct gl_renderbuffer *rb)
 {
rb->PutRow = TAG(WriteRGBASpan);
-   rb->PutRowRGB = TAG(WriteRGBSpan);
rb->PutValues = TAG(WriteRGBAPixels);
rb->GetValues = TAG(ReadRGBAPixels);
 
diff --git a/src/mesa/drivers/dri/common/stenciltmp.h 
b/src/mesa/drivers/dri/common/stenciltmp.h
index e4e39c7..950d3c4 100644
--- a/src/mesa/drivers/dri/common/stenciltmp.h
+++ b/src/mesa/drivers/dri/common/stenciltmp.h
@@ -177,7 +177,6 @@ static void TAG(InitStencilPointers)(struct gl_renderbuffer 
*rb)
rb->GetRow = TAG(ReadStencilSpan);
rb->GetValues = TAG(ReadStencilPixels);
rb->PutRow = TAG(WriteStencilSpan);
-   rb->PutRowRGB = NULL;
rb->PutValues = TAG(WriteStencilPixels);
 }
 
diff --git a/src/mesa/drivers/dri/swrast/swrast_span.c 
b/src/mesa/drivers/dri/swrast/swrast_span.c
index 35993fa..ba6174f 100644
--- a/src/mesa/drivers/dri/swrast/swrast_span.c
+++ b/src/mesa/drivers/dri/swrast/swrast_span.c
@@ -276,28 +276,24 @@ swrast_set_span_funcs_back(struct swrast_renderbuffer 
*xrb,
xrb->Base.GetRow = get_row_A8R8G8B8;
xrb->Base.GetValues = get_values_A8R8G8B8;
xrb->Base.PutRow = put_row_A8R8G8B8;
-   xrb->Base.PutRowRGB = put_row_rgb_A8R8G8B8;
xrb->Base.PutValues = put_values_A8R8G8B8;
break;
 case PF_X8R8G8B8:
xrb->Base.GetRow = get_row_X8R8G8B8;
xrb->Base.GetValues = get_values_X8R8G8B8;
xrb->Base.PutRow = put_row_X8R8G8B8;
-   xrb->Base.PutRowRGB = put_row_rgb_X8R8G8B8;
xrb->Base.PutValues = put_values_X8R8G8B8;
break;
 case PF_R5G6B5:
xrb->Base.GetRow = get_row_R5G6B5;
xrb->Base.GetValues = get_values_R5G6B5;
xrb->Base.PutRow = put_row_R5G6B5;
-   xrb->Base.PutRowRGB = put_row_rgb_R5G6B5;
xrb->Base.PutValues = put_values_R5G6B5;
break;
 case PF_R3G3B2:
xrb->Base.GetRow = get_row_R3G3B

[Mesa-dev] [PATCH 21/22] swrast: stop using _DepthBuffer in triangle code

2011-12-18 Thread Brian Paul
The only consequence is we can only use the occlusion_zless_16_triangle()
function with MESA_FORMAT_Z16.
---
 src/mesa/swrast/s_triangle.c |   27 +++
 1 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index c4d504b..43deaf4 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -874,19 +874,21 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
 /*
  * Special tri function for occlusion testing
  */
-#define NAME occlusion_zless_triangle
+#define NAME occlusion_zless_16_triangle
 #define INTERP_Z 1
 #define SETUP_CODE \
-   struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer; \
+   struct gl_renderbuffer *rb = \
+  ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;   \
struct gl_query_object *q = ctx->Query.CurrentOcclusionObject;  \
ASSERT(ctx->Depth.Test);\
ASSERT(!ctx->Depth.Mask);   \
ASSERT(ctx->Depth.Func == GL_LESS); \
+   assert(rb->Format == MESA_FORMAT_Z16);   \
if (!q) {   \
   return;  \
}
 #define RENDER_SPAN( span )\
-   if (rb->Format == MESA_FORMAT_Z16) {
\
+   {\
   GLuint i;
\
   const GLushort *zRow = (const GLushort *)
\
  _swrast_pixel_address(rb, span.x, span.y); \
@@ -897,17 +899,6 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
  } \
  span.z += span.zStep; \
   }
\
-   }   \
-   else {  \
-  GLuint i;
\
-  const GLuint *zRow = (const GLuint *)\
- _swrast_pixel_address(rb, span.x, span.y);\
-  for (i = 0; i < span.end; i++) { \
- if ((GLuint)span.z < zRow[i]) {   \
-q->Result++;   \
- } \
- span.z += span.zStep; \
-  }
\
}
 #include "s_tritemp.h"
 
@@ -1014,6 +1005,8 @@ _swrast_choose_triangle( struct gl_context *ctx )
}
 
if (ctx->RenderMode==GL_RENDER) {
+  struct gl_renderbuffer *depthRb =
+ ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
 
   if (ctx->Polygon.SmoothFlag) {
  _swrast_set_aa_triangle_function(ctx);
@@ -1026,12 +1019,14 @@ _swrast_choose_triangle( struct gl_context *ctx )
   ctx->Depth.Test &&
   ctx->Depth.Mask == GL_FALSE &&
   ctx->Depth.Func == GL_LESS &&
-  !ctx->Stencil._Enabled) {
+  !ctx->Stencil._Enabled &&
+  depthRb &&
+  depthRb->Format == MESA_FORMAT_Z16) {
  if (ctx->Color.ColorMask[0][0] == 0 &&
 ctx->Color.ColorMask[0][1] == 0 &&
 ctx->Color.ColorMask[0][2] == 0 &&
 ctx->Color.ColorMask[0][3] == 0) {
-USE(occlusion_zless_triangle);
+USE(occlusion_zless_16_triangle);
 return;
  }
   }
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 22/22] swrast: rewrite glDrawPixels(GL_DEPTH) with zoom

2011-12-18 Thread Brian Paul
This gets rid of another renderbuffer->PutRow() call and _DepthBuffer
usage.  We always work with 32-bit uint Z values now.
---
 src/mesa/swrast/s_drawpix.c |   58 ++
 src/mesa/swrast/s_zoom.c|   37 +-
 src/mesa/swrast/s_zoom.h|2 +-
 3 files changed, 28 insertions(+), 69 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index c14fd02..bef2ff1 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -28,6 +28,7 @@
 #include "main/colormac.h"
 #include "main/condrender.h"
 #include "main/context.h"
+#include "main/format_pack.h"
 #include "main/image.h"
 #include "main/imports.h"
 #include "main/macros.h"
@@ -555,7 +556,6 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, 
GLint y,
const GLint imgX = x, imgY = y;
const GLboolean scaleOrBias
   = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
-   const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
const GLuint stencilMask = ctx->Stencil.WriteMask[0];
const GLenum stencilType = GL_UNSIGNED_BYTE;
const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
@@ -593,57 +593,27 @@ draw_depth_stencil_pixels(struct gl_context *ctx, GLint 
x, GLint y,
   /* XXX need to handle very wide images (skippixels) */
   GLint i;
 
-  depthRb = ctx->DrawBuffer->_DepthBuffer;
-
   for (i = 0; i < height; i++) {
  const GLuint *depthStencilSrc = (const GLuint *)
 _mesa_image_address2d(&clippedUnpack, pixels, width, height,
   GL_DEPTH_STENCIL_EXT, type, i, 0);
 
  if (ctx->Depth.Mask) {
-if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 24 &&
-   type == GL_UNSIGNED_INT_24_8) {
-   /* fast path 24-bit zbuffer */
-   GLuint zValues[MAX_WIDTH];
-   GLint j;
-   ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
-   for (j = 0; j < width; j++) {
-  zValues[j] = depthStencilSrc[j] >> 8;
-   }
-   if (zoom)
-  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
-  x, y + i, zValues);
-   else
-  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
-}
-else if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 16 &&
-type == GL_UNSIGNED_INT_24_8) {
-   /* fast path 16-bit zbuffer */
-   GLushort zValues[MAX_WIDTH];
-   GLint j;
-   ASSERT(depthRb->DataType == GL_UNSIGNED_SHORT);
-   for (j = 0; j < width; j++) {
-  zValues[j] = depthStencilSrc[j] >> 16;
-   }
-   if (zoom)
-  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
-  x, y + i, zValues);
-   else
-  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
+GLuint zValues[MAX_WIDTH];  /* 32-bit Z values */
+_mesa_unpack_depth_span(ctx, width,
+GL_UNSIGNED_INT, /* dest type */
+zValues, /* dest addr */
+0x,  /* depth max */
+type,/* src type */
+depthStencilSrc, /* src addr */
+&clippedUnpack);
+if (zoom) {
+   _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
+   y + i, zValues);
 }
 else {
-   /* general case */
-   GLuint zValues[MAX_WIDTH];  /* 16 or 32-bit Z value storage */
-   _mesa_unpack_depth_span(ctx, width,
-   depthRb->DataType, zValues, depthMax,
-   type, depthStencilSrc, &clippedUnpack);
-   if (zoom) {
-  _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
-  y + i, zValues);
-   }
-   else {
-  depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
-   }
+   GLubyte *dst = _swrast_pixel_address(depthRb, x, y + i);
+   _mesa_pack_uint_z_row(depthRb->Format, width, zValues, dst);
 }
  }
 
diff --git a/src/mesa/swrast/s_zoom.c b/src/mesa/swrast/s_zoom.c
index f407fdc..73bff48 100644
--- a/src/mesa/swrast/s_zoom.c
+++ b/src/mesa/swrast/s_zoom.c
@@ -25,6 +25,7 @@
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/imports.h"
+#include "main/format_pack.h"
 #include "main/colormac.h"
 
 #include "s_context.h"
@@ -390,17 +391,17 @@ _swras

Re: [Mesa-dev] [PATCH 2/2] softpipe: fix depth sampling for linear vs nearest.

2011-12-18 Thread Brian Paul
On Sun, Dec 18, 2011 at 2:39 PM, Dave Airlie  wrote:
> On Sun, Dec 18, 2011 at 9:27 PM, Dave Airlie  wrote:
>> From: Dave Airlie 
>>
>> This sample compare was always doing linear, and this makes the
>> glsl-fs-shadow1DArray test render like the Intel driver.
>>
>> Signed-off-by: Dave Airlie 
>> ---
>>  src/gallium/drivers/softpipe/sp_tex_sample.c |   23 ---
>>  1 files changed, 16 insertions(+), 7 deletions(-)
>>
>> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c 
>> b/src/gallium/drivers/softpipe/sp_tex_sample.c
>> index 72629a0..40ad786 100644
>> --- a/src/gallium/drivers/softpipe/sp_tex_sample.c
>> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
>> @@ -2172,13 +2172,22 @@ sample_compare(struct tgsi_sampler *tgsi_sampler,
>>       break;
>>    }
>>
>> -   /* convert four pass/fail values to an intensity in [0,1] */
>> -   val = 0.25F * (k0 + k1 + k2 + k3);
>> -
>> -   /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE 
>> */
>> -   for (j = 0; j < 4; j++) {
>> -      rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
>> -      rgba[3][j] = 1.0F;
>> +   if (sampler->mag_img_filter == PIPE_TEX_FILTER_LINEAR) {
>> +      /* convert four pass/fail values to an intensity in [0,1] */
>> +      val = 0.25F * (k0 + k1 + k2 + k3);
>> +
>> +      /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = 
>> GL_LUMINANCE */
>> +      for (j = 0; j < 4; j++) {
>> +        rgba[0][j] = rgba[1][j] = rgba[2][j] = val;
>> +        rgba[3][j] = 1.0F;
>> +      }
>> +   } else {
>> +      for (j = 0; j < 4; j++) {
>> +        rgba[0][j] = k0;
>> +        rgba[1][j] = k1;
>> +        rgba[2][j] = k2;
>> +        rgba[3][0] = 1.0F;
>
> ^ assume 0 should be j here, though it would be good if someone could
> check my thinking, I mostly ported from swrast.

Yes, it should be rgba[3][j].

Reviewed-by: Brian Paul 
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] softpipe: fix texture sampling from 1D texture array

2011-12-18 Thread Brian Paul
On Sun, Dec 18, 2011 at 2:27 PM, Dave Airlie  wrote:
> From: Dave Airlie 
>
> This is the first part of a fix to piglit glsl-fs-shadow1DArray
>
> Signed-off-by: Dave Airlie 
> ---
>  src/gallium/auxiliary/tgsi/tgsi_exec.c |   13 +
>  1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
> b/src/gallium/auxiliary/tgsi/tgsi_exec.c
> index 1fb7f8f..060549f 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
> @@ -1794,9 +1794,22 @@ exec_tex(struct tgsi_exec_machine *mach,
>       break;
>
>    case TGSI_TEXTURE_1D_ARRAY:
> +      FETCH(&r[0], 0, CHAN_X);
> +      FETCH(&r[1], 0, CHAN_Y);
> +
> +      if (modifier == TEX_MODIFIER_PROJECTED) {
> +         micro_div(&r[0], &r[0], &r[3]);
> +      }
> +
> +      fetch_texel(mach->Samplers[unit],
> +                  &r[0], &r[1], &r[2], lod,     /* S, T, P, LOD */
> +                  control,
> +                  &r[0], &r[1], &r[2], &r[3]);  /* outputs */

Where does r[2] come from?  Off hand, I think we want to pass ZeroVec
there instead.

Looks like that was wrong in the original code too.

-Brian


> +      break;
>    case TGSI_TEXTURE_SHADOW1D_ARRAY:
>       FETCH(&r[0], 0, CHAN_X);
>       FETCH(&r[1], 0, CHAN_Y);
> +      FETCH(&r[2], 0, CHAN_Z);
>
>       if (modifier == TEX_MODIFIER_PROJECTED) {
>          micro_div(&r[0], &r[0], &r[3]);
> --
> 1.7.7.3
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 5/6] vl: Remove most members of pipe_video_decoder

2011-12-18 Thread Maarten Lankhorst
Hey Andy,

2011/12/19 Andy Furniss :
> Maarten Lankhorst wrote:
>>
>> Hey Andy,
>>
>> On 12/07/2011 05:48 PM, Andy Furniss wrote:
>>>
>>> Maarten Lankhorst wrote:
>>>
 Hm, could you test with some added sanity checks?
>>>
>>>
>>> mplayer: vl/vl_vlc.h:139: vl_vlc_eatbits: Assertion `vlc->valid_bits>
>>>  num_bits' failed.
>>>
 If that works, maybe remove the vl_vlc_fillbits call I added in
 vl_mpeg12_bs_decode
 to see if that is what caused it. Unfortunately the bitstream parser
 just fails to work
 correctly here on a lot of my test videos, but that happens even without
 this patch.
>>>
>>>
>>> Yea, since the rewrite I have seen some crashes - only at the end of some
>>> transport streams and only so far with svn mplayer, release mplayer doesn't
>>> do it.
>>>
 You might want to check with valgrind to see if it tosses any warning,
 too.
 I don't suppose you have a short clip of the failing video that
 reproduces the problem?
>>>
>>>
>>> Anything should do - I haven't found one that works yet, mpeg1, mpeg2
>>> progressive/interlaced, TS, PS, SD, HD with release mplayer or svn, all
>>> crash before rendering anything.
>>>
>>>
>> Ok looks like I found the issue, could you try the version below?
>
>
> It doesn't crash anymore, but there are regressions.
>
> On the plus side - some transport streams that used to crash/hang at the end
> with -vc ffmpeg12vdpau are now OK.
>
> Playing dvd from disc without -cache 8192 is still problematic. This only
> affects vdpau decode, xvmc was and still is OK.
>
> With the patch I get an assert rather than a hang/crash.
> mplayer: vl/vl_vlc.h:138: vl_vlc_eatbits: Assertion `vlc->valid_bits >=
> num_bits' failed.
Full backtrace please?

> although -cache  mostly works around it. I can still rarely trigger it
> by doing a lot of skipping forward/back.
No idea why this would even affect things.

> With the patch and vdpau decode on some streams there is occasional
> corruption where a few of the bottom right macroblocks render as solid
> colours.
Might be related to previous issue.

> The next issue affects xvmc as well as vdpau - performance is quite severely
> reduced. Looking at top it seems that less Cpu is used with the patch, but
> fps is 50-60% worse - meaning with vdpau decode I can't even play some 30fps
> HD with my card on high, these would normally be OK on low.
Hm, I was using only a single decode buffer which removed all
batching, might be related. Just wanted to be sure this worked before
re-enabling it.

> In addition with vdpau decode I get some 1/4 - 1/2 second stalls when
> testing HD (this was in benchmark mode so I don't think it's just because I
> haven't got the perf to reach fps).
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev