Re: [Mesa-dev] [PATCH] Anisotropic filtering extension for swrast

2011-05-19 Thread Andreas Fänger
I will have a look at it. This might take a while, though, as I'm currently
quite busy with other projects.

/ Andreas

-Ursprüngliche Nachricht-
Von: Brian Paul [mailto:bri...@vmware.com] 
Gesendet: Mittwoch, 18. Mai 2011 16:06
An: Andreas Faenger
Cc: mesa-dev@lists.freedesktop.org
Betreff: Re: [Mesa-dev] [PATCH] Anisotropic filtering extension for swrast

On 05/17/2011 05:08 AM, Andreas Faenger wrote:
 Hi,

 this patch makes it possible to have high quality texture filtering
 with the pure software renderer. The main purpose is to use it with
 osmesa. The anisotropic filtering is based on Elliptical Weighted Avarage
(EWA).

 The patch was designed to make as little changes to the existing codebase
as possible. Therefore, the existing texture_sample_func
 signature has not been adjusted although this was required; a hack
 was used instead to pass the required arguments.

 I provide this patch as other people might be interessted in
 using anisotropic filtering for osmesa, especially when rendering
 images in a headless environment.

Thanks.  I'm about to commit your patch (with some formatting fixes).

Would you be interested in implementing this feature in the Gallium 
softpipe driver too?

-Brian

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


Re: [Mesa-dev] [PATCH] Anisotropic filtering extension for swrast

2011-05-18 Thread Brian Paul

On 05/17/2011 05:08 AM, Andreas Faenger wrote:

Hi,

this patch makes it possible to have high quality texture filtering
with the pure software renderer. The main purpose is to use it with
osmesa. The anisotropic filtering is based on Elliptical Weighted Avarage (EWA).

The patch was designed to make as little changes to the existing codebase as 
possible. Therefore, the existing texture_sample_func
signature has not been adjusted although this was required; a hack
was used instead to pass the required arguments.

I provide this patch as other people might be interessted in
using anisotropic filtering for osmesa, especially when rendering
images in a headless environment.


Thanks.  I'm about to commit your patch (with some formatting fixes).

Would you be interested in implementing this feature in the Gallium 
softpipe driver too?


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


Re: [Mesa-dev] [PATCH] Anisotropic filtering extension for swrast

2011-05-18 Thread Maxim Levitsky
On Wed, 2011-05-18 at 08:06 -0600, Brian Paul wrote: 
 On 05/17/2011 05:08 AM, Andreas Faenger wrote:
  Hi,
 
  this patch makes it possible to have high quality texture filtering
  with the pure software renderer. The main purpose is to use it with
  osmesa. The anisotropic filtering is based on Elliptical Weighted Avarage 
  (EWA).
 
  The patch was designed to make as little changes to the existing codebase 
  as possible. Therefore, the existing texture_sample_func
  signature has not been adjusted although this was required; a hack
  was used instead to pass the required arguments.
 
  I provide this patch as other people might be interessted in
  using anisotropic filtering for osmesa, especially when rendering
  images in a headless environment.
 
 Thanks.  I'm about to commit your patch (with some formatting fixes).
 
 Would you be interested in implementing this feature in the Gallium 
 softpipe driver too?

Offtopic: @phoronix: please don't write an excitement article about how
mesa now supports anisotropic filtering (with writing in very small text
that is only for software renderer...) :-)

Best regards,
Maxim Levitsly

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


[Mesa-dev] [PATCH] Anisotropic filtering extension for swrast

2011-05-17 Thread Andreas Faenger
Anisotropic filtering extension for swrast intended to be used by osmesato 
create high quality renderings.
Based on Higher Quality Elliptical Weighted Avarage Filter (EWA).
A 2nd implementation using footprint assembly is also provided.

---
 src/mesa/main/extensions.c |3 +
 src/mesa/swrast/s_span.c   |7 +
 src/mesa/swrast/s_texcombine.c |   13 ++
 src/mesa/swrast/s_texfilter.c  |  387 
 4 files changed, 410 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 8672ac2..77fc47b 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -503,6 +503,9 @@ _mesa_enable_sw_extensions(struct gl_context *ctx)
ctx-Extensions.EXT_texture_env_add = GL_TRUE;
ctx-Extensions.EXT_texture_env_combine = GL_TRUE;
ctx-Extensions.EXT_texture_env_dot3 = GL_TRUE;
+   /* Anisotropic filtering extension begin */
+   ctx-Extensions.EXT_texture_filter_anisotropic = GL_TRUE;
+   /* Anisotropic filtering extension end */
ctx-Extensions.EXT_texture_mirror_clamp = GL_TRUE;
ctx-Extensions.EXT_texture_lod_bias = GL_TRUE;
ctx-Extensions.EXT_texture_shared_exponent = GL_TRUE;
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index f0524e0..6ea5531 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -492,6 +492,13 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span)
 const struct gl_texture_image *img = obj-Image[0][obj-BaseLevel];
 needLambda = (obj-Sampler.MinFilter != obj-Sampler.MagFilter)
|| ctx-FragmentProgram._Current;
+/* Anisotropic filtering extension begin */
+/* LOD is calculated directly in the ansiotropic filter, we can 
skip the normal lambda
+ * function as the result is ignored anyways
+ */
+if (obj-Sampler.MaxAnisotropy  1.0 
+ obj-Sampler.MinFilter == GL_LINEAR_MIPMAP_LINEAR) needLambda 
= GL_FALSE;
+/* Anisotropic filtering extension end */
 texW = img-WidthScale;
 texH = img-HeightScale;
  }
diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c
index 7f49b6f..178d360 100644
--- a/src/mesa/swrast/s_texcombine.c
+++ b/src/mesa/swrast/s_texcombine.c
@@ -710,6 +710,19 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span 
)
}
 }
  }
+ /* Anisotropic filtering extension begin */
+ else if(curObj-Sampler.MaxAnisotropy  1.0 
+  curObj-Sampler.MinFilter == GL_LINEAR_MIPMAP_LINEAR) {
+/* sample_lambda_2d_aniso is beeing used as texture_sample_func,
+ * it requires the current SWspan *span as an additional parameter.
+ * In order to keep the same function signature, the unused lambda
+ * parameter will be modified to actually contain the SWspan 
pointer.
+ * This is a Hack. To make it right, the texture_sample_func
+ * signature and all implementing functions need to be modified.
+ */
+lambda = (GLfloat *)span; /* hide SWspan struct; cast to 
(GLfloat *) to suppress warning */
+ }
+ /* Anisotropic filtering extension end */
 
  /* Sample the texture (span-end = number of fragments) */
  swrast-TextureSample[unit]( ctx, texUnit-_Current, span-end,
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index 106f8b7..6b1d7f4 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -1531,6 +1531,388 @@ sample_lambda_2d(struct gl_context *ctx,
 }
 
 
+/* Anisotropic filtering extension begin */
+
+#define WEIGHT_LUT_SIZE 1024
+
+static GLfloat *weightLut;
+
+/**
+ * Creates the lookup table used to speedup ewa sampling
+ */
+static void
+create_filter_table()
+{
+   GLuint i;
+   if (!weightLut) {
+  weightLut = (GLfloat *) malloc(WEIGHT_LUT_SIZE * sizeof(GLfloat));
+
+  for (i = 0; i  WEIGHT_LUT_SIZE; ++i) {
+ GLfloat alpha = 2;
+ GLfloat r2 = (GLfloat)i / (GLfloat)(WEIGHT_LUT_SIZE - 1);
+ GLfloat weight = (GLfloat)exp(-alpha * r2);
+ weightLut[i] = weight;
+  }
+   }
+}
+
+/**
+ * Elliptical weighted average (EWA) filter for producing high quality
+ * anisotropic filtered results.
+ * Based on the Higher Quality Elliptical Weighted Avarage Filter
+ * published by Paul S. Heckbert in his Master's Thesis
+ * Fundamentals of Texture Mapping and Image Warping (1989)
+ */
+static void
+sample_2d_ewa(struct gl_context *ctx,
+ const struct gl_texture_object *tObj,
+ const GLfloat texcoord[4],
+ const GLfloat dudx, const GLfloat dvdx,
+ const GLfloat dudy, const GLfloat dvdy, const GLint lod,
+ GLfloat rgba[])
+{
+   GLint level=lod  0 ? lod : 0;
+   GLfloat scaling = 1.0 / (1  level);
+
+   const 

[Mesa-dev] [PATCH] Anisotropic filtering extension for swrast

2011-05-17 Thread Andreas Faenger
Hi,

this patch makes it possible to have high quality texture filtering
with the pure software renderer. The main purpose is to use it with
osmesa. The anisotropic filtering is based on Elliptical Weighted Avarage 
(EWA). 

The patch was designed to make as little changes to the existing codebase as 
possible. Therefore, the existing texture_sample_func
signature has not been adjusted although this was required; a hack
was used instead to pass the required arguments.

I provide this patch as other people might be interessted in
using anisotropic filtering for osmesa, especially when rendering
images in a headless environment.

/ Andreas

Andreas Faenger (1):
  Anisotropic filtering extension for swrast intended to be used by
osmesa to create high quality renderings. Based on Higher
Quality Elliptical Weighted Avarage Filter (EWA). A 2nd
implementation using footprint assembly is also provided.

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