From b9ad95d3ee9178dce9320d28b20d23d97370f7bd Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:29:27 +0100 Subject: util: Distinguish between the different compression formats. In particular, all current uses of util_format_is_compressed() actually mean s3tc. --- src/gallium/auxiliary/util/u_format.csv | 20 ++++++++++++-------- src/gallium/auxiliary/util/u_format.h | 20 ++++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index d2a925141b1..d819bbbde1c 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -110,14 +110,18 @@ PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv # Compressed formats -PIPE_FORMAT_DXT1_RGB , compressed, 4, 4, x64 , , , , xyz1, rgb -PIPE_FORMAT_DXT1_RGBA , compressed, 4, 4, x64 , , , , xyzw, rgb -PIPE_FORMAT_DXT3_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT5_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT1_SRGB , compressed, 4, 4, x64 , , , , xyz1, srgb -PIPE_FORMAT_DXT1_SRGBA , compressed, 4, 4, x64 , , , , xyzw, srgb -PIPE_FORMAT_DXT3_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb -PIPE_FORMAT_DXT5_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb +# - http://en.wikipedia.org/wiki/S3_Texture_Compression +# - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt +# - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt +# - http://msdn.microsoft.com/en-us/library/bb694531.aspx +PIPE_FORMAT_DXT1_RGB , s3tc, 4, 4, x64 , , , , xyz1, rgb +PIPE_FORMAT_DXT1_RGBA , s3tc, 4, 4, x64 , , , , xyzw, rgb +PIPE_FORMAT_DXT3_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT5_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT1_SRGB , s3tc, 4, 4, x64 , , , , xyz1, srgb +PIPE_FORMAT_DXT1_SRGBA , s3tc, 4, 4, x64 , , , , xyzw, srgb +PIPE_FORMAT_DXT3_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb +PIPE_FORMAT_DXT5_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb # Straightforward D3D10-like formats (also used for # vertex buffer element description) diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index c08fdcafcc8..98d4b98ebb5 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -56,15 +56,23 @@ enum util_format_layout { * * This is for formats like YV12 where there is less than one sample per * pixel. - * - * XXX: This could actually b */ UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3, /** - * An unspecified compression algorithm. + * S3 Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_S3TC = 4, + + /** + * Red-Green Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_RGTC = 5, + + /** + * Everything else that doesn't fit in any of the above layouts. */ - UTIL_FORMAT_LAYOUT_COMPRESSED = 4 + UTIL_FORMAT_LAYOUT_OTHER = 6 }; @@ -210,7 +218,7 @@ util_format_name(enum pipe_format format) } static INLINE boolean -util_format_is_compressed(enum pipe_format format) +util_format_is_s3tc(enum pipe_format format) { const struct util_format_description *desc = util_format_description(format); @@ -219,7 +227,7 @@ util_format_is_compressed(enum pipe_format format) return FALSE; } - return desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED ? TRUE : FALSE; + return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE; } static INLINE boolean -- cgit v1.2.3 From 28cf5e1191077e063fe2a81d9d35934b71d001e2 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:30:09 +0100 Subject: r300: UTIL_FORMAT_LAYOUT_COMPRESSED -> UTIL_FORMAT_LAYOUT_S3TC. --- src/gallium/drivers/r300/r300_texture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 7c86bdb4bdc..22ccadfe3dd 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -159,7 +159,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format) } /* Compressed formats. */ - if (desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED) { + if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { switch (format) { case PIPE_FORMAT_DXT1_RGB: case PIPE_FORMAT_DXT1_RGBA: -- cgit v1.2.3 From bade76191a3a429176694b3d7fd4f68409359735 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:30:35 +0100 Subject: svga: util_format_is_compressed() -> util_format_is_s3tc(). --- src/gallium/drivers/svga/svga_screen_texture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c index 4a058eda885..70d3a8a46ae 100644 --- a/src/gallium/drivers/svga/svga_screen_texture.c +++ b/src/gallium/drivers/svga/svga_screen_texture.c @@ -330,7 +330,7 @@ svga_texture_create(struct pipe_screen *screen, */ #if 0 if((templat->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) && - !util_format_is_compressed(templat->format)) + !util_format_is_s3tc(templat->format)) tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET; #endif @@ -969,7 +969,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt, if (min_lod == 0 && max_lod >= pt->last_level) view = FALSE; - if (util_format_is_compressed(pt->format) && view) { + if (util_format_is_s3tc(pt->format) && view) { format = svga_translate_format_render(pt->format); } -- cgit v1.2.3 From cfbbe244d7438a60d389ae9d996dd430f79f362f Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:30:56 +0100 Subject: mesa/st: util_format_is_compressed() -> util_format_is_s3tc(). --- src/mesa/state_tracker/st_cb_texture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 8cdd3ff2ae2..390ada5489c 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -934,7 +934,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, GLubyte *dest; if (stImage->pt && - util_format_is_compressed(stImage->pt->format) && + util_format_is_s3tc(stImage->pt->format) && !compressed_dst) { /* Need to decompress the texture. * We'll do this by rendering a textured quad. -- cgit v1.2.3 From f3cb08f3dd81bc6479e8aa926fb74e73bb83cb6f Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:31:16 +0100 Subject: i965g: util_format_is_compressed() -> util_format_is_s3tc(). --- src/gallium/drivers/i965/brw_screen_texture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/i965/brw_screen_texture.c b/src/gallium/drivers/i965/brw_screen_texture.c index cadcb7cee2a..f9f17bdabac 100644 --- a/src/gallium/drivers/i965/brw_screen_texture.c +++ b/src/gallium/drivers/i965/brw_screen_texture.c @@ -206,7 +206,7 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, /* XXX: compressed textures need special treatment here */ tex->cpp = util_format_get_blocksize(tex->base.format); - tex->compressed = util_format_is_compressed(tex->base.format); + tex->compressed = util_format_is_s3tc(tex->base.format); make_empty_list(&tex->views[0]); make_empty_list(&tex->views[1]); @@ -321,7 +321,7 @@ brw_texture_from_handle(struct pipe_screen *screen, templ->depth0 != 1) return NULL; - if (util_format_is_compressed(templ->format)) + if (util_format_is_s3tc(templ->format)) return NULL; tex = CALLOC_STRUCT(brw_texture); -- cgit v1.2.3 From 588dd187c45490368354f340f5175d2c4d7cbd3c Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:52:10 +0100 Subject: Revert "python: Temporarily disable python state tracker until transfers are done by contexts" This reverts commit 50a778661930ec7aa875a9c5235e9910143ec700. --- src/gallium/state_trackers/python/SConscript | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript index d0d141fd249..781f54bf2b9 100644 --- a/src/gallium/state_trackers/python/SConscript +++ b/src/gallium/state_trackers/python/SConscript @@ -3,8 +3,7 @@ import os.path Import('*') -if 'python' in env['statetrackers'] and 0: - # FIXME: Disable python state tracker until transfers are done by contexts +if 'python' in env['statetrackers']: env = env.Clone() -- cgit v1.2.3 From ab0b9f80f45fcab55155b0a16b91a56ff4b3db1e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 29 Mar 2010 11:21:26 -0600 Subject: glsl: remove rcp from sqrt() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per a patch from Marek Olšák, we can simply multiply the incoming value by 1/sqrt(x) instead of using rcp. We're keeping the x==0 check to avoid generating NaN for sqrt(0). --- src/mesa/shader/slang/library/slang_common_builtin.gc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index a25ca55bc42..3d464630df2 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -605,7 +605,7 @@ float sqrt(const float x) const float nx = -x; float r; __asm float_rsq r, x; - __asm float_rcp r, r; + r = r * x; __asm vec4_cmp __retVal, nx, r, 0.0; } @@ -615,8 +615,7 @@ vec2 sqrt(const vec2 x) vec2 r; __asm float_rsq r.x, x.x; __asm float_rsq r.y, x.y; - __asm float_rcp r.x, r.x; - __asm float_rcp r.y, r.y; + r = r * x; __asm vec4_cmp __retVal, nx, r, zero; } @@ -627,9 +626,7 @@ vec3 sqrt(const vec3 x) __asm float_rsq r.x, x.x; __asm float_rsq r.y, x.y; __asm float_rsq r.z, x.z; - __asm float_rcp r.x, r.x; - __asm float_rcp r.y, r.y; - __asm float_rcp r.z, r.z; + r = r * x; __asm vec4_cmp __retVal, nx, r, zero; } @@ -641,10 +638,7 @@ vec4 sqrt(const vec4 x) __asm float_rsq r.y, x.y; __asm float_rsq r.z, x.z; __asm float_rsq r.w, x.w; - __asm float_rcp r.x, r.x; - __asm float_rcp r.y, r.y; - __asm float_rcp r.z, r.z; - __asm float_rcp r.w, r.w; + r = r * x; __asm vec4_cmp __retVal, nx, r, zero; } -- cgit v1.2.3 From 1cbd51068802a3aa530b9c12d86c40cb3a1bbfa4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 29 Mar 2010 11:31:02 -0600 Subject: glsl: avoid using rcp in length() functions See prev commit for related info. --- src/mesa/shader/slang/library/slang_common_builtin.gc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index 3d464630df2..d75354deffe 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -1160,7 +1160,7 @@ float length(const vec2 v) float r; const float p = dot(v, v); // p = v.x * v.x + v.y * v.y __asm float_rsq r, p; // r = 1 / sqrt(p) - __asm float_rcp __retVal.x, r; // retVal = 1 / r + __retVal = p * r; // p * r = sqrt(p); } float length(const vec3 v) @@ -1168,7 +1168,7 @@ float length(const vec3 v) float r; const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + v.z * v.z __asm float_rsq r, p; // r = 1 / sqrt(p) - __asm float_rcp __retVal, r; // retVal = 1 / r + __retVal = p * r; // p * r = sqrt(p); } float length(const vec4 v) @@ -1176,7 +1176,7 @@ float length(const vec4 v) float r; const float p = dot(v, v); // p = v.x * v.x + v.y * v.y + ... __asm float_rsq r, p; // r = 1 / sqrt(p) - __asm float_rcp __retVal, r; // retVal = 1 / r + __retVal = p * r; // p * r = sqrt(p); } -- cgit v1.2.3 From 8ca937fc3b1bf15c820a1c7d3bf0283a91bec72c Mon Sep 17 00:00:00 2001 From: "RALOVICH, Kristóf" Date: Sat, 27 Mar 2010 22:11:29 -0400 Subject: progs/glsl: let the mouse rotate the scene --- progs/glsl/fsraytrace.c | 67 +++++++++++++++++++++++++++++++------------------ progs/glsl/vsraytrace.c | 47 ++++++++++++++++++++++++++++------ 2 files changed, 83 insertions(+), 31 deletions(-) diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c index 8d54757e590..357da67b9c6 100644 --- a/progs/glsl/fsraytrace.c +++ b/progs/glsl/fsraytrace.c @@ -27,23 +27,23 @@ #include #include #include "shaderutil.h" - +#include static int Win; static int WinWidth = 512, WinHeight = 512; -static GLfloat Xrot = 0, Yrot = 0; static int mouseGrabbed = 0; static GLuint vertShader; static GLuint fragShader; static GLuint program; +static float rot[9] = {1,0,0, 0,1,0, 0,0,1}; static const char* vsSource = - "varying vec2 rayDir;\n" - "\n" - "void main()\n" - "{\n" - " rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5);\n" - " gl_Position = gl_ProjectionMatrix * gl_Vertex;\n" + "varying vec2 rayDir; \n" + " \n" + "void main() \n" + "{ \n" + " rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5); \n" + " gl_Position = gl_ProjectionMatrix * gl_Vertex; \n" "}\n"; static const char* fsSource = @@ -213,29 +213,46 @@ static const char* fsSource = " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n" "} \n" " \n" - "\n" - "void\n" - "main()\n" - "{\n" - " const float z = -0.5;\n" + "void main() \n" + "{ \n" + " const float z = -0.5; \n" " const vec3 cameraPos = vec3(0,0,3); \n" - " Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot));\n" - " gl_FragColor = trace1(r);\n" + " Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot)); \n" + " gl_FragColor = trace1(r); \n" "}\n"; +static inline +float +deg2rad(const float degree) +{ + return( degree * 0.017453292519943295769236907684886F); +} - -static void -Idle(void) +static inline void +rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) { - glutPostRedisplay(); + const float rad1 = deg2rad(degreesAroundX); + const float c1 = cosf(rad1); + const float s1 = sinf(rad1); + const float rad2 = deg2rad(degreesAroundY); + const float c2 = cosf(rad2); + const float s2 = sinf(rad2); + mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2; + mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2; + mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2; } +static inline void +identity(float* mat3) +{ + mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F; + mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F; + mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F; +} static void Draw(void) { - float rot[9] = {1,0,0, 0,1,0, 0,0,1}; GLint location = glGetUniformLocation(program, "rot"); static const float m = -10.F; static const float p = 10.F; @@ -311,9 +328,11 @@ drag(int x, int y) float scale = 1.5F; if(mouseGrabbed) { - Xrot = (float)(x - WinWidth/2) / scale; - Yrot = (float)(y - WinHeight/2) / scale; - printf("%4.2f %4.2f\n", Xrot, Yrot); + static GLfloat xRot = 0, yRot = 0; + xRot = (float)(x - WinWidth/2) / scale; + yRot = (float)(y - WinHeight/2) / scale; + identity(rot); + rotate_xy(rot, yRot, xRot); } } @@ -380,7 +399,7 @@ main(int argc, char *argv[]) glutDisplayFunc(Draw); glutMouseFunc(mouse); glutPassiveMotionFunc(drag); - glutIdleFunc(Idle); + glutIdleFunc(Draw); Init(); glutMainLoop(); return 0; diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c index 962b1bdb4c1..327d48b897e 100644 --- a/progs/glsl/vsraytrace.c +++ b/progs/glsl/vsraytrace.c @@ -27,11 +27,14 @@ #include #include #include "shaderutil.h" - +#include static int Win; static int WinWidth = 256, WinHeight = 256; static int mouseGrabbed = 0; +static GLuint vertShader; +static GLuint program; +float rot[9] = {1,0,0, 0,1,0, 0,0,1}; static const char* vsSource = "const float INF = 9999.9; \n" @@ -206,11 +209,37 @@ static const char* vsSource = " Ray ray = Ray(cameraPos, rayDir); \n" " gl_Position = gl_Vertex; \n" " gl_FrontColor = trace1(ray); \n" - "} \n"; + "}\n"; -static GLuint vertShader; -static GLuint program; +static inline +float +deg2rad(const float degree) +{ + return( degree * 0.017453292519943295769236907684886F); +} + +static inline void +rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) +{ + const float rad1 = deg2rad(degreesAroundX); + const float c1 = cosf(rad1); + const float s1 = sinf(rad1); + const float rad2 = deg2rad(degreesAroundY); + const float c2 = cosf(rad2); + const float s2 = sinf(rad2); + mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2; + mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2; + mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2; +} + +static inline void +identity(float* mat3) +{ + mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F; + mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F; + mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F; +} static void Draw(void) @@ -219,7 +248,6 @@ Draw(void) const float h = 0.5F * WinHeight; int x,y; - float rot[9] = {1,0,0, 0,1,0, 0,0,1}; GLint location = glGetUniformLocation(program, "rot"); glUseProgram(program); @@ -287,9 +315,14 @@ static void drag(int x, int y) { + float scale = 1.5F; if(mouseGrabbed) { - printf("%4d %4d\n", x, y); + static GLfloat xRot = 0, yRot = 0; + xRot = (float)(x - WinWidth/2) / scale; + yRot = (float)(y - WinHeight/2) / scale; + identity(rot); + rotate_xy(rot, yRot, xRot); } } @@ -355,7 +388,7 @@ main(int argc, char *argv[]) glutDisplayFunc(Draw); glutIdleFunc(Draw); glutMouseFunc(mouse); - glutMotionFunc(drag); + glutPassiveMotionFunc(drag); Init(); glutMainLoop(); return 0; -- cgit v1.2.3 From 909f0b356eab04f03389ea36ebf0a83dbb930f5d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 29 Mar 2010 11:44:39 -0600 Subject: progs/glsl: improve the mouse drag/rotate code a little --- progs/glsl/fsraytrace.c | 8 +++----- progs/glsl/vsraytrace.c | 10 ++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c index 357da67b9c6..392f01b200d 100644 --- a/progs/glsl/fsraytrace.c +++ b/progs/glsl/fsraytrace.c @@ -333,6 +333,7 @@ drag(int x, int y) yRot = (float)(y - WinHeight/2) / scale; identity(rot); rotate_xy(rot, yRot, xRot); + glutPostRedisplay(); } } @@ -341,10 +342,7 @@ static void mouse(int button, int state, int x, int y) { - if(state == GLUT_DOWN) - { - mouseGrabbed = !mouseGrabbed; - } + mouseGrabbed = (state == GLUT_DOWN); } @@ -398,7 +396,7 @@ main(int argc, char *argv[]) glutKeyboardFunc(Key); glutDisplayFunc(Draw); glutMouseFunc(mouse); - glutPassiveMotionFunc(drag); + glutMotionFunc(drag); glutIdleFunc(Draw); Init(); glutMainLoop(); diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c index 327d48b897e..ee4fe477619 100644 --- a/progs/glsl/vsraytrace.c +++ b/progs/glsl/vsraytrace.c @@ -31,7 +31,7 @@ static int Win; static int WinWidth = 256, WinHeight = 256; -static int mouseGrabbed = 0; +static GLboolean mouseGrabbed = GL_FALSE; static GLuint vertShader; static GLuint program; float rot[9] = {1,0,0, 0,1,0, 0,0,1}; @@ -323,6 +323,7 @@ drag(int x, int y) yRot = (float)(y - WinHeight/2) / scale; identity(rot); rotate_xy(rot, yRot, xRot); + glutPostRedisplay(); } } @@ -331,10 +332,7 @@ static void mouse(int button, int state, int x, int y) { - if(state == GLUT_DOWN) - { - mouseGrabbed = !mouseGrabbed; - } + mouseGrabbed = (state == GLUT_DOWN); } @@ -388,7 +386,7 @@ main(int argc, char *argv[]) glutDisplayFunc(Draw); glutIdleFunc(Draw); glutMouseFunc(mouse); - glutPassiveMotionFunc(drag); + glutMotionFunc(drag); Init(); glutMainLoop(); return 0; -- cgit v1.2.3 From 6cc5fbd76b8994da8174c39f8eacb6605f4aa3b2 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 29 Mar 2010 21:06:53 +0300 Subject: ws/sw/dri: s/xm/dri_sw/ --- src/gallium/winsys/sw/dri/dri_sw_winsys.c | 147 +++++++++++++++--------------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index 1c1e5612d28..fb4722fc75f 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -37,126 +37,127 @@ #include "dri_sw_winsys.h" -struct xm_displaytarget +struct dri_sw_displaytarget { void *data; void *mapped; }; +struct dri_sw_winsys +{ + struct sw_winsys base; +}; -/** Cast wrapper */ -static INLINE struct xm_displaytarget * -xm_displaytarget( struct sw_displaytarget *dt ) +static INLINE struct dri_sw_displaytarget * +dri_sw_displaytarget( struct sw_displaytarget *dt ) { - return (struct xm_displaytarget *)dt; + return (struct dri_sw_displaytarget *)dt; +} + +static INLINE struct dri_sw_winsys * +dri_sw_winsys( struct sw_winsys *ws ) +{ + return (struct dri_sw_winsys *)ws; } -/* pipe_screen::is_format_supported */ static boolean -xm_is_displaytarget_format_supported( struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) +dri_sw_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) { /* TODO: check visuals or other sensible thing here */ return TRUE; } -/* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */ static struct sw_displaytarget * -xm_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) +dri_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) { - struct xm_displaytarget *xm_dt; - unsigned nblocksy, size, xm_stride, format_stride; + struct dri_sw_displaytarget *dri_sw_dt; + unsigned nblocksy, size, dri_sw_stride, format_stride; - xm_dt = CALLOC_STRUCT(xm_displaytarget); - if(!xm_dt) - goto no_xm_dt; + dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget); + if(!dri_sw_dt) + goto no_dt; format_stride = util_format_get_stride(format, width); - xm_stride = align(format_stride, alignment); + dri_sw_stride = align(format_stride, alignment); nblocksy = util_format_get_nblocksy(format, height); - size = xm_stride * nblocksy; + size = dri_sw_stride * nblocksy; - xm_dt->data = align_malloc(size, alignment); - if(!xm_dt->data) + dri_sw_dt->data = align_malloc(size, alignment); + if(!dri_sw_dt->data) goto no_data; - *stride = xm_stride; - return (struct sw_displaytarget *)xm_dt; + *stride = dri_sw_stride; + return (struct sw_displaytarget *)dri_sw_dt; no_data: - FREE(xm_dt); -no_xm_dt: + FREE(dri_sw_dt); +no_dt: return NULL; } -/* pipe_screen::texture_destroy */ static void -xm_displaytarget_destroy(struct sw_winsys *ws, - struct sw_displaytarget *dt) +dri_sw_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) { - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); - if (xm_dt->data) { - FREE(xm_dt->data); + if (dri_sw_dt->data) { + FREE(dri_sw_dt->data); } - FREE(xm_dt); + FREE(dri_sw_dt); } -/* pipe_context::transfer_map */ static void * -xm_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags) +dri_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) { - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = xm_dt->data; - return xm_dt->mapped; + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + dri_sw_dt->mapped = dri_sw_dt->data; + return dri_sw_dt->mapped; } -/* pipe_context::transfer_unmap */ static void -xm_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt) +dri_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) { - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = NULL; + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + dri_sw_dt->mapped = NULL; } -/* pipe_screen::texture_from_handle */ static struct sw_displaytarget * -xm_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templ, - struct winsys_handle *whandle, - unsigned *stride) +dri_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templ, + struct winsys_handle *whandle, + unsigned *stride) { assert(0); return NULL; } -/* pipe_screen::texture_get_handle */ static boolean -xm_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) +dri_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) { assert(0); return FALSE; } -/* pipe_screen::flush_frontbuffer */ static void -xm_displaytarget_display(struct sw_winsys *ws, - struct sw_displaytarget *dt, - void *context_private) +dri_sw_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) { assert(0); } @@ -171,29 +172,29 @@ dri_destroy_sw_winsys(struct sw_winsys *winsys) struct sw_winsys * dri_create_sw_winsys(void) { - struct sw_winsys *ws; + struct dri_sw_winsys *ws; - ws = CALLOC_STRUCT(sw_winsys); + ws = CALLOC_STRUCT(dri_sw_winsys); if (!ws) return NULL; - ws->destroy = dri_destroy_sw_winsys; + ws->base.destroy = dri_destroy_sw_winsys; - ws->is_displaytarget_format_supported = xm_is_displaytarget_format_supported; + ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported; /* screen texture functions */ - ws->displaytarget_create = xm_displaytarget_create; - ws->displaytarget_destroy = xm_displaytarget_destroy; - ws->displaytarget_from_handle = xm_displaytarget_from_handle; - ws->displaytarget_get_handle = xm_displaytarget_get_handle; + ws->base.displaytarget_create = dri_sw_displaytarget_create; + ws->base.displaytarget_destroy = dri_sw_displaytarget_destroy; + ws->base.displaytarget_from_handle = dri_sw_displaytarget_from_handle; + ws->base.displaytarget_get_handle = dri_sw_displaytarget_get_handle; /* texture functions */ - ws->displaytarget_map = xm_displaytarget_map; - ws->displaytarget_unmap = xm_displaytarget_unmap; + ws->base.displaytarget_map = dri_sw_displaytarget_map; + ws->base.displaytarget_unmap = dri_sw_displaytarget_unmap; - ws->displaytarget_display = xm_displaytarget_display; + ws->base.displaytarget_display = dri_sw_displaytarget_display; - return ws; + return &ws->base; } /* vim: set sw=3 ts=8 sts=3 expandtab: */ -- cgit v1.2.3 From 625e024b186829f199458679921916971a5b00cb Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 29 Mar 2010 21:06:54 +0300 Subject: st/dri/sw: add drisw_api similarly to dri1_api I am pretty sure that this is in gallium spirit, so commit. Thanks to Chia-I for suggesting this. --- src/gallium/include/state_tracker/dri1_api.h | 8 +- src/gallium/include/state_tracker/drisw_api.h | 35 ++++++++ src/gallium/state_trackers/dri/common/dri_st_api.c | 2 +- src/gallium/state_trackers/dri/drm/dri1.c | 30 +++---- src/gallium/state_trackers/dri/sw/drisw.c | 100 ++++++++------------- src/gallium/state_trackers/dri/sw/drisw.h | 2 +- src/gallium/targets/dri-swrast/swrast_drm_api.c | 17 ++-- src/gallium/targets/libgl-xlib/xlib.c | 8 ++ src/gallium/winsys/sw/dri/dri_sw_winsys.c | 37 ++++++-- src/gallium/winsys/sw/dri/dri_sw_winsys.h | 4 +- 10 files changed, 141 insertions(+), 102 deletions(-) create mode 100644 src/gallium/include/state_tracker/drisw_api.h diff --git a/src/gallium/include/state_tracker/dri1_api.h b/src/gallium/include/state_tracker/dri1_api.h index 27b7a28c467..bb1cd6d1d82 100644 --- a/src/gallium/include/state_tracker/dri1_api.h +++ b/src/gallium/include/state_tracker/dri1_api.h @@ -7,14 +7,14 @@ #include "state_tracker/drm_api.h" -struct drm_clip_rect; - struct pipe_screen; struct pipe_winsys; struct pipe_buffer; struct pipe_context; struct pipe_texture; +struct drm_clip_rect; + struct dri1_api_version { int major; @@ -31,8 +31,8 @@ struct dri1_api_lock_funcs { void (*lock) (struct pipe_context * pipe); void (*unlock) (struct pipe_context * locked_pipe); - boolean(*is_locked) (struct pipe_context * locked_pipe); - boolean(*is_lock_lost) (struct pipe_context * locked_pipe); + boolean(*is_locked) (struct pipe_context * locked_pipe); + boolean(*is_lock_lost) (struct pipe_context * locked_pipe); void (*clear_lost_lock) (struct pipe_context * locked_pipe); }; diff --git a/src/gallium/include/state_tracker/drisw_api.h b/src/gallium/include/state_tracker/drisw_api.h new file mode 100644 index 00000000000..c6adebb4ec5 --- /dev/null +++ b/src/gallium/include/state_tracker/drisw_api.h @@ -0,0 +1,35 @@ +#ifndef _DRISW_API_H_ +#define _DRISW_API_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_screen.h" +#include "pipe/p_format.h" + +#include "state_tracker/drm_api.h" + +struct pipe_screen; +struct pipe_winsys; +struct pipe_buffer; +struct pipe_context; +struct pipe_texture; + +struct dri_drawable; + +/** + * This callback struct is intended for the winsys to call the loader. + */ + +struct drisw_loader_funcs +{ + void (*put_image) (struct dri_drawable *dri_drawable, + void *data, unsigned width, unsigned height); +}; + +struct drisw_create_screen_arg +{ + struct drm_create_screen_arg base; + + struct drisw_loader_funcs *lf; +}; + +#endif diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.c b/src/gallium/state_trackers/dri/common/dri_st_api.c index 40b24b18e9f..7ba7ec383d8 100644 --- a/src/gallium/state_trackers/dri/common/dri_st_api.c +++ b/src/gallium/state_trackers/dri/common/dri_st_api.c @@ -80,7 +80,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, } #else if (new_stamp) - drisw_update_drawable_info(drawable->dPriv); + drisw_update_drawable_info(drawable); drisw_allocate_textures(drawable, statt_mask); #endif diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c index aad098bb301..9b5842ba2bf 100644 --- a/src/gallium/state_trackers/dri/drm/dri1.c +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -404,6 +404,19 @@ dri1_allocate_textures(struct dri_drawable *drawable, drawable->old_h = height; } +/* + * Backend function for init_screen. + */ + +static const __DRIextension *dri1_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + NULL +}; + static void st_dri_lock(struct pipe_context *pipe) { @@ -442,21 +455,6 @@ static struct dri1_api_lock_funcs dri1_lf = { .clear_lost_lock = st_dri_clear_lost_lock }; -/* - * Backend function for init_screen. - */ - -static const __DRIextension *dri1_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - NULL -}; - -struct dri1_api *__dri1_api_hooks = NULL; - static INLINE void dri1_copy_version(struct dri1_api_version *dst, const struct __DRIversionRec *src) @@ -466,6 +464,8 @@ dri1_copy_version(struct dri1_api_version *dst, dst->patch_level = src->patch; } +struct dri1_api *__dri1_api_hooks = NULL; + const __DRIconfig ** dri1_init_screen(__DRIscreen * sPriv) { diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index b7eba63bcb9..b8256710972 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -27,38 +27,18 @@ **************************************************************************/ /* TODO: - * - * stride: - * - * The driver and the loaders (libGL, xserver/glx) compute the stride from the - * width independently. winsys has a workaround that works for softpipe but may - * explode for other drivers or platforms, rendering- or performance-wise. - * Solving this issue properly requires extending the DRISW loader extension, - * in order to make the stride available to the putImage callback. - * - * drisw_api: - * - * Define drisw_api similarly to dri1_api and use it to call the loader. This - * is predicated on support for calling the loader from the winsys, which has - * to grow for DRI2 as well. * * xshm / texture_from_pixmap / EGLImage: * * Allow the loaders to use the XSHM extension. It probably requires callbacks - * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth - * it, given the scope of DRISW, unless it falls naturally from properly - * solving the other issues. - * - * fences: - * - * No fences are used, are they needed for llvmpipe / cell ? + * for createImage/destroyImage similar to DRI2 getBuffers. */ #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_inlines.h" #include "pipe/p_context.h" -#include "state_tracker/drm_api.h" +#include "state_tracker/drisw_api.h" #include "dri_screen.h" #include "dri_context.h" @@ -80,60 +60,47 @@ get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) dPriv->loaderPrivate); } -/* - * Set the width to 'stride / cpp'. PutImage seems to correctly clip the width - * to the actual width of the dst drawable. Even if this is not specified but - * an implementation detail, it is the correct thing to do, so rely on it. XXX - */ static INLINE void -put_image(__DRIdrawable *dPriv, void *data, unsigned width) +put_image(__DRIdrawable *dPriv, void *data, unsigned width, unsigned height) { __DRIscreen *sPriv = dPriv->driScreenPriv; const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, - 0, 0, width, dPriv->h, + 0, 0, width, height, data, dPriv->loaderPrivate); } void -drisw_update_drawable_info(__DRIdrawable *dPriv) +drisw_update_drawable_info(struct dri_drawable *drawable) { + __DRIdrawable *dPriv = drawable->dPriv; + get_drawable_info(dPriv, &dPriv->w, &dPriv->h); } +static void +drisw_put_image(struct dri_drawable *drawable, + void *data, unsigned width, unsigned height) +{ + __DRIdrawable *dPriv = drawable->dPriv; + + put_image(dPriv, data, width, height); +} + static INLINE void drisw_present_texture(__DRIdrawable *dPriv, struct pipe_texture *ptex) { struct dri_drawable *drawable = dri_drawable(dPriv); struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe; struct pipe_surface *psurf; - struct pipe_transfer *ptrans; - void *pmap; - unsigned width; - pipe = dri1_get_pipe_context(screen); psurf = dri1_get_pipe_surface(drawable, ptex); - if (!pipe || !psurf) + if (!psurf) return; - ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, dPriv->w, dPriv->h); - - width = ptrans->stride / util_format_get_blocksize(ptex->format); - - pmap = pipe->transfer_map(pipe, ptrans); - - assert(pmap); - - put_image(dPriv, pmap, width); - - pipe->transfer_unmap(pipe, ptrans); - - pipe->tex_transfer_destroy(pipe, ptrans); + screen->pipe_screen->flush_frontbuffer(screen->pipe_screen, psurf, drawable); } static INLINE void @@ -163,38 +130,38 @@ drisw_copy_to_front(__DRIdrawable * dPriv, */ void -drisw_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) +drisw_swap_buffers(__DRIdrawable *dPriv) { struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); struct pipe_texture *ptex; if (!ctx) return; - ptex = drawable->textures[statt]; + ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; if (ptex) { - drisw_copy_to_front(ctx->dPriv, ptex); + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + + drisw_copy_to_front(dPriv, ptex); } } void -drisw_swap_buffers(__DRIdrawable *dPriv) +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) { struct dri_context *ctx = dri_get_current(); - struct dri_drawable *drawable = dri_drawable(dPriv); struct pipe_texture *ptex; if (!ctx) return; - ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; + ptex = drawable->textures[statt]; if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - - drisw_copy_to_front(dPriv, ptex); + drisw_copy_to_front(ctx->dPriv, ptex); } } @@ -286,12 +253,16 @@ static const __DRIextension *drisw_screen_extensions[] = { NULL }; +static struct drisw_loader_funcs drisw_lf = { + .put_image = drisw_put_image +}; + const __DRIconfig ** drisw_init_screen(__DRIscreen * sPriv) { const __DRIconfig **configs; struct dri_screen *screen; - struct drm_create_screen_arg arg; + struct drisw_create_screen_arg arg; screen = CALLOC_STRUCT(dri_screen); if (!screen) @@ -304,9 +275,10 @@ drisw_init_screen(__DRIscreen * sPriv) sPriv->private = (void *)screen; sPriv->extensions = drisw_screen_extensions; - arg.mode = DRM_CREATE_DRISW; + arg.base.mode = DRM_CREATE_DRISW; + arg.lf = &drisw_lf; - configs = dri_init_screen_helper(screen, &arg, 32); + configs = dri_init_screen_helper(screen, &arg.base, 32); if (!configs) goto fail; diff --git a/src/gallium/state_trackers/dri/sw/drisw.h b/src/gallium/state_trackers/dri/sw/drisw.h index 2c0d5610fac..c0c874f7326 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.h +++ b/src/gallium/state_trackers/dri/sw/drisw.h @@ -39,7 +39,7 @@ const __DRIconfig ** drisw_init_screen(__DRIscreen * sPriv); void -drisw_update_drawable_info(__DRIdrawable *dPriv); +drisw_update_drawable_info(struct dri_drawable *drawable); void drisw_flush_frontbuffer(struct dri_drawable *drawable, diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c index 1f24d7650d7..63b935bb07b 100644 --- a/src/gallium/targets/dri-swrast/swrast_drm_api.c +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -32,15 +32,7 @@ #include "state_tracker/sw_winsys.h" #include "dri_sw_winsys.h" -/* Copied from targets/libgl-xlib. - * - * TODO: - * This function should be put in targets/common or winsys/sw/common and shared - * with targets/libgl-xlib and winsys/sw/drm. - * - * For targets/common, you get layering violations unless all of drm_api's are - * moved under targets. - */ +/* Copied from targets/libgl-xlib */ #ifdef GALLIUM_SOFTPIPE #include "softpipe/sp_public.h" @@ -98,19 +90,24 @@ swrast_drm_create_screen(struct drm_api *api, { struct sw_winsys *winsys = NULL; struct pipe_screen *screen = NULL; + struct drisw_create_screen_arg *drisw; (void) drmFD; if (arg != NULL) { switch(arg->mode) { case DRM_CREATE_DRISW: + drisw = (struct drisw_create_screen_arg *)arg; break; default: return NULL; } } + else { + return NULL; + } - winsys = dri_create_sw_winsys(); + winsys = dri_create_sw_winsys(drisw->lf); if (winsys == NULL) return NULL; diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 4a8366280d8..48e5bdff429 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -55,6 +55,14 @@ PUBLIC const struct st_module st_module_OpenGL = { * GALLIUM_CELL, etc. Scons already eliminates those #defines, so * things that are painful for it now are likely to be painful for * other build systems in the future. + * + * Copies (full or partial): + * targets/libgl-xlib + * targets/graw-xlib + * targets/dri-swrast + * winsys/sw/drm + * drivers/sw + * */ #ifdef GALLIUM_SOFTPIPE diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index fb4722fc75f..870c6afc124 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -39,6 +39,11 @@ struct dri_sw_displaytarget { + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + void *data; void *mapped; }; @@ -46,6 +51,8 @@ struct dri_sw_displaytarget struct dri_sw_winsys { struct sw_winsys base; + + struct drisw_loader_funcs *lf; }; static INLINE struct dri_sw_displaytarget * @@ -79,23 +86,27 @@ dri_sw_displaytarget_create(struct sw_winsys *winsys, unsigned *stride) { struct dri_sw_displaytarget *dri_sw_dt; - unsigned nblocksy, size, dri_sw_stride, format_stride; + unsigned nblocksy, size, format_stride; dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget); if(!dri_sw_dt) goto no_dt; + dri_sw_dt->format = format; + dri_sw_dt->width = width; + dri_sw_dt->height = height; + format_stride = util_format_get_stride(format, width); - dri_sw_stride = align(format_stride, alignment); + dri_sw_dt->stride = align(format_stride, alignment); nblocksy = util_format_get_nblocksy(format, height); - size = dri_sw_stride * nblocksy; + size = dri_sw_dt->stride * nblocksy; dri_sw_dt->data = align_malloc(size, alignment); if(!dri_sw_dt->data) goto no_data; - *stride = dri_sw_stride; + *stride = dri_sw_dt->stride; return (struct sw_displaytarget *)dri_sw_dt; no_data: @@ -159,7 +170,20 @@ dri_sw_displaytarget_display(struct sw_winsys *ws, struct sw_displaytarget *dt, void *context_private) { - assert(0); + struct dri_sw_winsys *dri_sw_ws = dri_sw_winsys(ws); + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + struct dri_drawable *dri_drawable = (struct dri_drawable *)context_private; + unsigned width, height; + + /* Set the width to 'stride / cpp'. + * + * PutImage correctly clips to the width of the dst drawable. + */ + width = dri_sw_dt->stride / util_format_get_blocksize(dri_sw_dt->format); + + height = dri_sw_dt->height; + + dri_sw_ws->lf->put_image(dri_drawable, dri_sw_dt->data, width, height); } @@ -170,7 +194,7 @@ dri_destroy_sw_winsys(struct sw_winsys *winsys) } struct sw_winsys * -dri_create_sw_winsys(void) +dri_create_sw_winsys(struct drisw_loader_funcs *lf) { struct dri_sw_winsys *ws; @@ -178,6 +202,7 @@ dri_create_sw_winsys(void) if (!ws) return NULL; + ws->lf = lf; ws->base.destroy = dri_destroy_sw_winsys; ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported; diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.h b/src/gallium/winsys/sw/dri/dri_sw_winsys.h index c2382a68d78..329ac06a05b 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.h +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.h @@ -29,8 +29,10 @@ #ifndef DRI_SW_WINSYS #define DRI_SW_WINSYS +#include "state_tracker/drisw_api.h" + struct sw_winsys; -struct sw_winsys *dri_create_sw_winsys(void); +struct sw_winsys *dri_create_sw_winsys(struct drisw_loader_funcs *lf); #endif -- cgit v1.2.3 From 012fabca722494162c244a367913562b8cfa4677 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 29 Mar 2010 16:17:17 -0400 Subject: gallivm: make sure that the alloca's are the very first thing in the function otherwise mem2reg can't put them in registers --- src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index f160be878f8..95cd6a0ecf3 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -651,6 +651,19 @@ emit_declaration( unsigned first = decl->Range.First; unsigned last = decl->Range.Last; unsigned idx, i; + LLVMBasicBlockRef current_block = + LLVMGetInsertBlock(bld->base.builder); + LLVMBasicBlockRef first_block = + LLVMGetEntryBasicBlock( + LLVMGetBasicBlockParent(current_block)); + LLVMValueRef first_inst = + LLVMGetFirstInstruction(first_block); + + /* we want alloca's to be the first instruction + * in the function so we need to rewind the builder + * to the very beginning */ + LLVMPositionBuilderBefore(bld->base.builder, + first_inst); for (idx = first; idx <= last; ++idx) { boolean ok; @@ -673,10 +686,15 @@ emit_declaration( ok = TRUE; } - if (!ok) + if (!ok) { + LLVMPositionBuilderAtEnd(bld->base.builder, + current_block); return FALSE; + } } + LLVMPositionBuilderAtEnd(bld->base.builder, + current_block); return TRUE; } -- cgit v1.2.3 From 69492c3aca8361b903a7daaa697c0660faa22b04 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:09:21 +0100 Subject: st/python: Move surface read/write methods to context. --- src/gallium/state_trackers/python/p_context.i | 249 +++++++++++++++++++++++++- src/gallium/state_trackers/python/p_texture.i | 226 ----------------------- src/gallium/state_trackers/python/st_sample.c | 30 ++-- src/gallium/state_trackers/python/st_sample.h | 7 +- 4 files changed, 267 insertions(+), 245 deletions(-) diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index df700bc663c..a8e164a072b 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -362,10 +362,253 @@ error1: pipe_surface_reference(&_dst, NULL); } - void clear(unsigned buffers, const float *rgba, double depth = 0.0f, - unsigned stencil = 0) + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + surface_read_raw(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + char **STRING, int *LENGTH) + { + struct pipe_texture *texture = surface->texture; + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + unsigned stride; + + stride = util_format_get_stride(texture->format, w); + *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + %cstring_input_binary(const char *STRING, unsigned LENGTH); + void + surface_write_raw(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const char *STRING, unsigned LENGTH, unsigned stride = 0) { - $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); + struct pipe_texture *texture = surface->texture; + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + + if(stride == 0) + stride = util_format_get_stride(texture->format, w); + + if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) + SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(!transfer) + SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); + + pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); + + fail: + return; + } + + void + surface_read_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + float *rgba) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_write_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *rgba) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(transfer) { + pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + surface_read_rgba8(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + char **STRING, int *LENGTH) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + float *rgba; + unsigned char *rgba8; + unsigned i, j, k; + + *LENGTH = 0; + *STRING = NULL; + + if (!surface) + return; + + *LENGTH = h*w*4; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + rgba = malloc(h*w*4*sizeof(float)); + if(!rgba) + return; + + rgba8 = (unsigned char *) *STRING; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, + w, h); + if(transfer) { + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + for(j = 0; j < h; ++j) { + for(i = 0; i < w; ++i) + for(k = 0; k <4; ++k) + rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); + } + pipe->tex_transfer_destroy(pipe, transfer); + } + + free(rgba); + } + + void + surface_read_z(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + unsigned *z) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_write_z(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const unsigned *z) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(transfer) { + pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_sample_rgba(struct st_surface *surface, + float *rgba) + { + st_sample_surface($self->pipe, surface, rgba); + } + + unsigned + surface_compare_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *rgba, float tol = 0.0) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + float *rgba2; + const float *p1; + const float *p2; + unsigned i, j, n; + + rgba2 = MALLOC(h*w*4*sizeof(float)); + if(!rgba2) + return ~0; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(!transfer) { + FREE(rgba2); + return ~0; + } + + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); + pipe->tex_transfer_destroy(pipe, transfer); + + p1 = rgba; + p2 = rgba2; + n = 0; + for(i = h*w; i; --i) { + unsigned differs = 0; + for(j = 4; j; --j) { + float delta = *p2++ - *p1++; + if (delta < -tol || delta > tol) + differs = 1; + } + n += differs; + } + + FREE(rgba2); + + return n; } }; diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 2dd9e5050ea..923a6285289 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -124,232 +124,6 @@ struct st_surface FREE($self); } - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void get_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) - { - struct pipe_texture *texture = $self->texture; - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - unsigned stride; - - stride = util_format_get_stride(texture->format, w); - *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void put_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) - { - struct pipe_texture *texture = $self->texture; - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - - if(stride == 0) - stride = util_format_get_stride(texture->format, w); - - if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) - SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(!transfer) - SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); - - pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); - - fail: - return; - } - - void get_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - void - put_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void - get_tile_rgba8(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - float *rgba; - unsigned char *rgba8; - unsigned i, j, k; - - *LENGTH = 0; - *STRING = NULL; - - if (!$self) - return; - - *LENGTH = h*w*4; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - rgba = malloc(h*w*4*sizeof(float)); - if(!rgba) - return; - - rgba8 = (unsigned char *) *STRING; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, - w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - for(j = 0; j < h; ++j) { - for(i = 0; i < w; ++i) - for(k = 0; k <4; ++k) - rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); - } - pipe->tex_transfer_destroy(pipe, transfer); - } - - free(rgba); - } - - void get_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - void put_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - -/* - void - sample_rgba(float *rgba) { - st_sample_surface($self, rgba); - } -*/ - - unsigned compare_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - float *rgba2; - const float *p1; - const float *p2; - unsigned i, j, n; - - rgba2 = MALLOC(h*w*4*sizeof(float)); - if(!rgba2) - return ~0; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(!transfer) { - FREE(rgba2); - return ~0; - } - - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); - pipe->tex_transfer_destroy(pipe, transfer); - - p1 = rgba; - p2 = rgba2; - n = 0; - for(i = h*w; i; --i) { - unsigned differs = 0; - for(j = 4; j; --j) { - float delta = *p2++ - *p1++; - if (delta < -tol || delta > tol) - differs = 1; - } - n += differs; - } - - FREE(rgba2); - - return n; - } }; diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index f9622533fbc..e2c1e060174 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -521,12 +521,13 @@ st_sample_pixel_block(enum pipe_format format, } } -#if 0 + void -st_sample_surface(struct st_surface *surface, float *rgba) +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba) { struct pipe_texture *texture = surface->texture; - struct pipe_screen *screen = texture->screen; unsigned width = u_minify(texture->width0, surface->level); unsigned height = u_minify(texture->height0, surface->level); uint rgba_stride = width * 4; @@ -534,18 +535,18 @@ st_sample_surface(struct st_surface *surface, float *rgba) void *raw; transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - 0, 0, - width, - height); + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + 0, 0, + width, + height); if (!transfer) return; - raw = screen->transfer_map(screen, transfer); + raw = pipe->transfer_map(pipe, transfer); if (raw) { enum pipe_format format = texture->format; uint x, y; @@ -567,9 +568,8 @@ st_sample_surface(struct st_surface *surface, float *rgba) } } - screen->transfer_unmap(screen, transfer); + pipe->transfer_unmap(pipe, transfer); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } -#endif diff --git a/src/gallium/state_trackers/python/st_sample.h b/src/gallium/state_trackers/python/st_sample.h index 888114d3021..6fb8417add8 100644 --- a/src/gallium/state_trackers/python/st_sample.h +++ b/src/gallium/state_trackers/python/st_sample.h @@ -32,6 +32,9 @@ #include "pipe/p_format.h" +struct pipe_context; +struct st_surface; + void st_sample_pixel_block(enum pipe_format format, @@ -40,7 +43,9 @@ st_sample_pixel_block(enum pipe_format format, unsigned w, unsigned h); void -st_sample_surface(struct st_surface *surface, float *rgba); +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba); #endif /* ST_SAMPLE_H_ */ -- cgit v1.2.3 From d0e7aa25a9258aaf0bf9b22c1e75eda1515a69f7 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:09:37 +0100 Subject: st/python: Update for util_draw_vertex_buffer changes. --- src/gallium/state_trackers/python/p_context.i | 38 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index a8e164a072b..bccaeead015 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -280,8 +280,11 @@ struct st_context { struct pipe_context *pipe = $self->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_buffer *vbuf; + struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; + struct pipe_vertex_buffer vbuffer; float *map; unsigned size; + unsigned i; size = num_verts * num_attribs * 4 * sizeof(float); @@ -297,15 +300,44 @@ struct st_context { goto error2; memcpy(map, vertices, size); pipe_buffer_unmap(screen, vbuf); - - util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs); - + + cso_save_vertex_elements($self->cso); + + /* tell pipe about the vertex attributes */ + for (i = 0; i < num_attribs; i++) { + velements[i].src_offset = i * 4 * sizeof(float); + velements[i].instance_divisor = 0; + velements[i].vertex_buffer_index = 0; + velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + cso_set_vertex_elements($self->cso, num_attribs, velements); + + /* tell pipe about the vertex buffer */ + memset(&vbuffer, 0, sizeof(vbuffer)); + vbuffer.buffer = vbuf; + vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = 0; + vbuffer.max_index = num_verts - 1; + pipe->set_vertex_buffers(pipe, 1, &vbuffer); + + /* draw */ + pipe->draw_arrays(pipe, prim, 0, num_verts); + + cso_restore_vertex_elements($self->cso); + error2: pipe_buffer_reference(&vbuf, NULL); error1: ; } + void + clear(unsigned buffers, const float *rgba, double depth = 0.0f, + unsigned stencil = 0) + { + $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); + } + void flush(unsigned flags = 0) { struct pipe_fence_handle *fence = NULL; -- cgit v1.2.3 From bbe6788807db1fd1cbb1b227cf0ecfcc02db90d8 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:10:03 +0100 Subject: progs/gallium/python: Get tri.py sample working again. --- progs/gallium/python/samples/tri.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/progs/gallium/python/samples/tri.py b/progs/gallium/python/samples/tri.py index d7fbdb10ac3..9f6d787dcb2 100644 --- a/progs/gallium/python/samples/tri.py +++ b/progs/gallium/python/samples/tri.py @@ -30,19 +30,19 @@ from gallium import * -def make_image(surface): - data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) +def make_image(ctx, surface): + data = ctx.surface_read_rgba8(surface, 0, 0, surface.width, surface.height) import Image outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) return outimage -def save_image(filename, surface): - outimage = make_image(surface) +def save_image(ctx, surface, filename): + outimage = make_image(ctx, surface) outimage.save(filename, "PNG") -def show_image(surface): - outimage = make_image(surface) +def show_image(ctx, surface): + outimage = make_image(ctx, surface) import Tkinter as tk from PIL import Image, ImageTk @@ -216,10 +216,10 @@ def test(dev): ctx.flush() - show_image(cbuf) - #show_image(zbuf) - #save_image('cbuf.png', cbuf) - #save_image('zbuf.png', zbuf) + show_image(ctx, cbuf) + show_image(ctx, zbuf) + save_image(ctx, cbuf, 'cbuf.png') + save_image(ctx, zbuf, 'zbuf.png') -- cgit v1.2.3 From 52f728921563192ccbabf5ffe98234d8d330b933 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 29 Mar 2010 13:58:39 -0700 Subject: progs/glsl: Remove inline keyword. Fixes MSVC build. --- progs/glsl/fsraytrace.c | 6 +++--- progs/glsl/vsraytrace.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c index 392f01b200d..dcfc1949874 100644 --- a/progs/glsl/fsraytrace.c +++ b/progs/glsl/fsraytrace.c @@ -221,14 +221,14 @@ static const char* fsSource = " gl_FragColor = trace1(r); \n" "}\n"; -static inline +static float deg2rad(const float degree) { return( degree * 0.017453292519943295769236907684886F); } -static inline void +static void rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) { const float rad1 = deg2rad(degreesAroundX); @@ -242,7 +242,7 @@ rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2; } -static inline void +static void identity(float* mat3) { mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F; diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c index ee4fe477619..67832b8a46d 100644 --- a/progs/glsl/vsraytrace.c +++ b/progs/glsl/vsraytrace.c @@ -212,14 +212,14 @@ static const char* vsSource = "}\n"; -static inline +static float deg2rad(const float degree) { return( degree * 0.017453292519943295769236907684886F); } -static inline void +static void rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) { const float rad1 = deg2rad(degreesAroundX); @@ -233,7 +233,7 @@ rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY) mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2; } -static inline void +static void identity(float* mat3) { mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F; -- cgit v1.2.3 From 90075f34e24a6d6c16198c5b99fb25d713910e8a Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 29 Mar 2010 14:56:12 -0700 Subject: progs/glsl: Add workarounds for Apple GLSL compiler crash. fsraytrace and vsraytrace were crashing on Mac OS X 10.6.3 in the Apple GLSL compiler function TPPStreamCompiler::assignOperands. Removing some const qualifers made the crashes go away. --- progs/glsl/fsraytrace.c | 7 +++++++ progs/glsl/vsraytrace.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c index dcfc1949874..af72a99099d 100644 --- a/progs/glsl/fsraytrace.c +++ b/progs/glsl/fsraytrace.c @@ -76,10 +76,17 @@ static const char* fsSource = " vec3 n; \n" "}; \n" " \n" +#ifdef __APPLE__ + "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#else "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#endif " \n" "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n" "// sqrt, let's work around. \n" diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c index 67832b8a46d..64d928883ed 100644 --- a/progs/glsl/vsraytrace.c +++ b/progs/glsl/vsraytrace.c @@ -64,10 +64,17 @@ static const char* vsSource = " vec3 n; \n" "}; \n" " \n" +#ifdef __APPLE__ + "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" + "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" + "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" + "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#else "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n" "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n" "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n" "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n" +#endif " \n" "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n" "// sqrt, let's work around. \n" -- cgit v1.2.3 From 3b1a8d9d5ba286da568b4176ed533a7dde60ad18 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 26 Mar 2010 10:23:03 -0700 Subject: gallivm: added lp_bld_printf() function --- src/gallium/auxiliary/Makefile | 1 + src/gallium/auxiliary/SConscript | 1 + src/gallium/auxiliary/gallivm/lp_bld_printf.c | 109 ++++++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_printf.h | 39 +++++++++ 4 files changed, 150 insertions(+) create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_printf.c create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_printf.h diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index e1c3bc43a24..452eceb7f4f 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -155,6 +155,7 @@ GALLIVM_SOURCES = \ gallivm/lp_bld_intr.c \ gallivm/lp_bld_logic.c \ gallivm/lp_bld_pack.c \ + gallivm/lp_bld_printf.c \ gallivm/lp_bld_sample.c \ gallivm/lp_bld_sample_soa.c \ gallivm/lp_bld_struct.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 65e1dc8a58d..0a23da47b2a 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -200,6 +200,7 @@ if drawllvm: 'gallivm/lp_bld_logic.c', 'gallivm/lp_bld_init.cpp', 'gallivm/lp_bld_pack.c', + 'gallivm/lp_bld_printf.c', 'gallivm/lp_bld_sample.c', 'gallivm/lp_bld_sample_soa.c', 'gallivm/lp_bld_struct.c', diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c new file mode 100644 index 00000000000..ae4d400af39 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c @@ -0,0 +1,109 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include + +#include "lp_bld_printf.h" + + +static int +lp_get_printf_arg_count(const char *fmt) +{ + int count =0; + const char *p = fmt; + int c; + + while ((c = *p++)) { + if (c != '%') + continue; + switch (*p) { + case '\0': + continue; + case '%': + p++; + continue; + case '.': + if (p[1] == '*' && p[2] == 's') { + count += 2; + p += 3; + continue; + } + default: + count ++; + } + } + return count; +} + +LLVMValueRef +lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len) +{ + LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), len + 1), ""); + LLVMSetGlobalConstant(string, TRUE); + LLVMSetLinkage(string, LLVMInternalLinkage); + LLVMSetInitializer(string, LLVMConstString(str, len + 1, TRUE)); + return string; +} + + +/** + * lp_build_printf. + * + * Build printf call in LLVM IR. The output goes to stdout. + * The additional variable arguments need to have type + * LLVMValueRef. + */ +LLVMValueRef +lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...) +{ + va_list arglist; + int i = 0; + int argcount = lp_get_printf_arg_count(fmt); + LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); + LLVMValueRef params[argcount + 1]; + LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1); + LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0); + LLVMValueRef index[2]; + LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf"); + + index[0] = index[1] = int0; + + if (!func_printf) { + LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntType(32), NULL, 0, 1); + func_printf = LLVMAddFunction(module, "printf", printf_type); + } + + params[0] = LLVMBuildGEP(builder, fmtarg, index, 2, ""); + + va_start(arglist, fmt); + for (i = 1; i <= argcount; i++) + params[i] = va_arg(arglist, LLVMValueRef); + va_end(arglist); + + return LLVMBuildCall(builder, func_printf, params, argcount + 1, ""); +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h new file mode 100644 index 00000000000..83bd8f1d557 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h @@ -0,0 +1,39 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_BLD_PRINTF_H +#define LP_BLD_PRINTF_H + + +#include "pipe/p_compiler.h" +#include "lp_bld.h" + +LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len); +LLVMValueRef lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...); + +#endif + -- cgit v1.2.3 From 5fa09846618ed702493f054a1d4b0ec2a28fbbd0 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 26 Mar 2010 10:24:34 -0700 Subject: Add test case for lp_bld_printf() --- src/gallium/drivers/llvmpipe/Makefile | 3 +- src/gallium/drivers/llvmpipe/lp_test_printf.c | 162 ++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/gallium/drivers/llvmpipe/lp_test_printf.c diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile index 74d728ddb39..b37c6754c08 100644 --- a/src/gallium/drivers/llvmpipe/Makefile +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -44,7 +44,8 @@ CPP_SOURCES = \ PROGS := lp_test_format \ lp_test_blend \ - lp_test_conv + lp_test_conv \ + lp_test_printf include ../../Makefile.template diff --git a/src/gallium/drivers/llvmpipe/lp_test_printf.c b/src/gallium/drivers/llvmpipe/lp_test_printf.c new file mode 100644 index 00000000000..e5e5925012a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_printf.c @@ -0,0 +1,162 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_printf.h" + +#include +#include +#include +#include + +#include "lp_test.h" + + +struct printf_test_case { +}; + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "format\n"); + + fflush(fp); +} + + + +typedef void (*test_printf_t)(int i); + +static LLVMValueRef +add_printf_test(LLVMModuleRef module) +{ + LLVMTypeRef args[1] = { LLVMIntType(32) }; + LLVMValueRef func = LLVMAddFunction(module, "test_printf", LLVMFunctionType(LLVMVoidType(), args, 1, 0)); + LLVMBuilderRef builder = LLVMCreateBuilder(); + LLVMBasicBlockRef block = LLVMAppendBasicBlock(func, "entry"); + + LLVMSetFunctionCallConv(func, LLVMCCallConv); + + LLVMPositionBuilderAtEnd(builder, block); + lp_build_printf(builder, "hello, world\n"); + lp_build_printf(builder, "print 5 6: %d %d\n", LLVMConstInt(LLVMInt32Type(), 5, 0), + LLVMConstInt(LLVMInt32Type(), 6, 0)); + LLVMBuildRetVoid(builder); + LLVMDisposeBuilder(builder); + return func; +} + + +PIPE_ALIGN_STACK +static boolean +test_printf(unsigned verbose, FILE *fp, const struct printf_test_case *testcase) +{ + LLVMModuleRef module = NULL; + LLVMValueRef test = NULL; + LLVMExecutionEngineRef engine = NULL; + LLVMModuleProviderRef provider = NULL; + LLVMPassManagerRef pass = NULL; + char *error = NULL; + test_printf_t test_printf; + float unpacked[4]; + unsigned packed; + boolean success = TRUE; + + module = LLVMModuleCreateWithName("test"); + + test = add_printf_test(module); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + provider = LLVMCreateModuleProviderForExistingModule(module); + if (LLVMCreateJITCompiler(&engine, provider, 1, &error)) { + fprintf(stderr, "%s\n", error); + LLVMDisposeMessage(error); + abort(); + } + +#if 0 + pass = LLVMCreatePassManager(); + LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass); + /* These are the passes currently listed in llvm-c/Transforms/Scalar.h, + * but there are more on SVN. */ + LLVMAddConstantPropagationPass(pass); + LLVMAddInstructionCombiningPass(pass); + LLVMAddPromoteMemoryToRegisterPass(pass); + LLVMAddGVNPass(pass); + LLVMAddCFGSimplificationPass(pass); + LLVMRunPassManager(pass, module); +#else + (void)pass; +#endif + + test_printf = (test_printf_t)LLVMGetPointerToGlobal(engine, test); + + memset(unpacked, 0, sizeof unpacked); + packed = 0; + + + // LLVMDumpModule(module); + + test_printf(0); + + LLVMFreeMachineCodeForFunction(engine, test); + + LLVMDisposeExecutionEngine(engine); + if(pass) + LLVMDisposePassManager(pass); + + return success; +} + + +boolean +test_all(unsigned verbose, FILE *fp) +{ + bool success = TRUE; + + test_printf(verbose, fp, NULL); + + return success; +} + + +boolean +test_some(unsigned verbose, FILE *fp, unsigned long n) +{ + return test_all(verbose, fp); +} -- cgit v1.2.3