python/tests: Get the tests running again.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 31 Mar 2010 11:28:49 +0000 (12:28 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 31 Mar 2010 12:12:24 +0000 (13:12 +0100)
progs/gallium/python/samples/tri.py
progs/gallium/python/tests/base.py
progs/gallium/python/tests/surface_copy.py
progs/gallium/python/tests/texture_sample.py
progs/gallium/python/tests/texture_transfer.py

index 9f6d787dcb263889226d76a6c64b1e83ef1cfc7c..8cc272db812fa6b2f972ea35678e92e1b97b0827 100644 (file)
@@ -128,6 +128,7 @@ def test(dev):
     scissor.maxy = height
     ctx.set_scissor(scissor)
 
+    # clip
     clip = Clip()
     clip.nr = 0
     ctx.set_clip(clip)
index bd82f50811f9bb89b91f565846afe7708e74f330..3699af81451a2f272ad8bc21ddba736af3133920 100755 (executable)
@@ -127,16 +127,16 @@ class Test:
         self._run(result)
         result.summary()
 
-    def assert_rgba(self, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
+    def assert_rgba(self, ctx, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
         total = h*w
-        different = surface.compare_tile_rgba(x, y, w, h, expected_rgba, tol=pixel_tol)
+        different = ctx.surface_compare_rgba(surface, x, y, w, h, expected_rgba, tol=pixel_tol)
         if different:
             sys.stderr.write("%u out of %u pixels differ\n" % (different, total))
 
         if float(total - different)/float(total) < surface_tol:
             if 0:
                 rgba = FloatArray(h*w*4)
-                surface.get_tile_rgba(x, y, w, h, rgba)
+                ctx.surface_read_rgba(surface, x, y, w, h, rgba)
                 show_image(w, h, Result=rgba, Expected=expected_rgba)
                 save_image(w, h, rgba, "result.png")
                 save_image(w, h, expected_rgba, "expected.png")
index a3f1b3e130c73faabbdb0eea3dc68ae605e45bb9..37d210d904e6e3e9f0108af063dfbd87548acc52 100755 (executable)
@@ -99,21 +99,18 @@ class TextureTest(TestCase):
         w = dst_surface.width
         h = dst_surface.height
 
-        # ???
-        stride = pf_get_stride(texture->format, w)
-        size = pf_get_nblocksy(texture->format) * stride
+        stride = util_format_get_stride(format, w)
+        size = util_format_get_nblocksy(format, h) * stride
         src_raw = os.urandom(size)
 
-        src_surface.put_tile_raw(0, 0, w, h, src_raw, stride)
-
         ctx = self.dev.context_create()
     
+        ctx.surface_write_raw(src_surface, 0, 0, w, h, src_raw, stride)
+
         ctx.surface_copy(dst_surface, 0, 0, 
                          src_surface, 0, 0, w, h)
     
-        ctx.flush()
-
-        dst_raw = dst_surface.get_tile_raw(0, 0, w, h)
+        dst_raw = ctx.surface_read_raw(dst_surface, 0, 0, w, h)
 
         if dst_raw != src_raw:
             raise TestFailure
index 49545c2e07aee083ff5ae2d5e567277e0ff98dec..9b5c15ad1da678f8d5d4faa428cc6671d6f024fe 100755 (executable)
@@ -115,6 +115,7 @@ class TextureColorSampleTest(TestCase):
 
     def test(self):
         dev = self.dev
+        ctx = self.ctx
         
         target = self.target
         format = self.format
@@ -125,6 +126,8 @@ class TextureColorSampleTest(TestCase):
         face = self.face
         level = self.level
         zslice = self.zslice
+        minz = 0.0
+        maxz = 1.0
         
         tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
         geom_flags = 0
@@ -136,8 +139,6 @@ class TextureColorSampleTest(TestCase):
         if not dev.is_format_supported(format, target, tex_usage, geom_flags):
             raise TestSkip
         
-        ctx = self.dev.context_create()
-    
         # disabled blending/masking
         blend = Blend()
         blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -155,7 +156,6 @@ class TextureColorSampleTest(TestCase):
         rasterizer = Rasterizer()
         rasterizer.front_winding = PIPE_WINDING_CW
         rasterizer.cull_mode = PIPE_WINDING_NONE
-        rasterizer.bypass_vs_clip_and_viewport = 1
         ctx.set_rasterizer(rasterizer)
     
         # samplers
@@ -183,14 +183,45 @@ class TextureColorSampleTest(TestCase):
         )
         
         expected_rgba = FloatArray(height*width*4) 
-        texture.get_surface(
+        surface = texture.get_surface(
             face = face,
             level = level,
             zslice = zslice,
-        ).sample_rgba(expected_rgba)
+        )
+        
+        ctx.surface_sample_rgba(surface, expected_rgba)
         
         ctx.set_fragment_sampler_texture(0, texture)
 
+        # viewport
+        viewport = Viewport()
+        scale = FloatArray(4)
+        scale[0] = width
+        scale[1] = height
+        scale[2] = (maxz - minz) / 2.0
+        scale[3] = 1.0
+        viewport.scale = scale
+        translate = FloatArray(4)
+        translate[0] = 0.0
+        translate[1] = 0.0
+        translate[2] = (maxz - minz) / 2.0
+        translate[3] = 0.0
+        viewport.translate = translate
+        ctx.set_viewport(viewport)
+
+        # scissor
+        scissor = Scissor()
+        scissor.minx = 0
+        scissor.miny = 0
+        scissor.maxx = width
+        scissor.maxy = height
+        ctx.set_scissor(scissor)
+
+        # clip
+        clip = Clip()
+        clip.nr = 0
+        ctx.set_clip(clip)
+
         #  framebuffer 
         cbuf_tex = dev.texture_create(
             PIPE_FORMAT_B8G8R8A8_UNORM, 
@@ -265,8 +296,8 @@ class TextureColorSampleTest(TestCase):
     
         for i in range(0, 4):
             j = 8*i
-            verts[j + 0] = pos[i][0] # x
-            verts[j + 1] = pos[i][1] # y
+            verts[j + 0] = pos[i][0]/float(width) # x
+            verts[j + 1] = pos[i][1]/float(height) # y
             verts[j + 2] = 0.0 # z
             verts[j + 3] = 1.0 # w
             verts[j + 4] = tex[i][0] # s
@@ -283,7 +314,7 @@ class TextureColorSampleTest(TestCase):
     
         cbuf = cbuf_tex.get_surface()
         
-        self.assert_rgba(cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
+        self.assert_rgba(ctx, cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
         
 
 class TextureDepthSampleTest(TestCase):
@@ -302,6 +333,7 @@ class TextureDepthSampleTest(TestCase):
 
     def test(self):
         dev = self.dev
+        ctx = self.ctx
         
         target = self.target
         format = self.format
@@ -312,6 +344,8 @@ class TextureDepthSampleTest(TestCase):
         face = self.face
         level = self.level
         zslice = self.zslice
+        minz = 0.0
+        maxz = 1.0
         
         tex_usage = PIPE_TEXTURE_USAGE_SAMPLER
         geom_flags = 0
@@ -323,8 +357,6 @@ class TextureDepthSampleTest(TestCase):
         if not dev.is_format_supported(format, target, tex_usage, geom_flags):
             raise TestSkip
         
-        ctx = self.dev.context_create()
-    
         # disabled blending/masking
         blend = Blend()
         blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
@@ -345,9 +377,24 @@ class TextureDepthSampleTest(TestCase):
         rasterizer = Rasterizer()
         rasterizer.front_winding = PIPE_WINDING_CW
         rasterizer.cull_mode = PIPE_WINDING_NONE
-        rasterizer.bypass_vs_clip_and_viewport = 1
         ctx.set_rasterizer(rasterizer)
     
+        # viewport
+        viewport = Viewport()
+        scale = FloatArray(4)
+        scale[0] = width
+        scale[1] = height
+        scale[2] = (maxz - minz) / 2.0
+        scale[3] = 1.0
+        viewport.scale = scale
+        translate = FloatArray(4)
+        translate[0] = 0.0
+        translate[1] = 0.0
+        translate[2] = (maxz - minz) / 2.0
+        translate[3] = 0.0
+        viewport.translate = translate
+        ctx.set_viewport(viewport)
+
         # samplers
         sampler = Sampler()
         sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
@@ -373,14 +420,29 @@ class TextureDepthSampleTest(TestCase):
         )
         
         expected_rgba = FloatArray(height*width*4) 
-        texture.get_surface(
+        surface = texture.get_surface(
             face = face,
             level = level,
             zslice = zslice,
-        ).sample_rgba(expected_rgba)
+        )
+
+        ctx.surface_sample_rgba(surface, expected_rgba)
         
         ctx.set_fragment_sampler_texture(0, texture)
 
+        # scissor
+        scissor = Scissor()
+        scissor.minx = 0
+        scissor.miny = 0
+        scissor.maxx = width
+        scissor.maxy = height
+        ctx.set_scissor(scissor)
+
+        # clip
+        clip = Clip()
+        clip.nr = 0
+        ctx.set_clip(clip)
+
         #  framebuffer 
         cbuf_tex = dev.texture_create(
             PIPE_FORMAT_B8G8R8A8_UNORM, 
@@ -464,8 +526,8 @@ class TextureDepthSampleTest(TestCase):
     
         for i in range(0, 4):
             j = 8*i
-            verts[j + 0] = pos[i][0] # x
-            verts[j + 1] = pos[i][1] # y
+            verts[j + 0] = pos[i][0]/float(width) # x
+            verts[j + 1] = pos[i][1]/float(height) # y
             verts[j + 2] = 0.0 # z
             verts[j + 3] = 1.0 # w
             verts[j + 4] = tex[i][0] # s
@@ -482,7 +544,7 @@ class TextureDepthSampleTest(TestCase):
     
         zsbuf = zsbuf_tex.get_surface()
         
-        self.assert_rgba(zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
+        self.assert_rgba(ctx, zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
         
 
 
@@ -534,6 +596,8 @@ def main():
         PIPE_TEX_FACE_NEG_Z,
     ]
 
+    ctx = dev.context_create()
+    
     for format in color_formats:
         for target in targets:
             for size in sizes:
@@ -551,6 +615,7 @@ def main():
                             while zslice < depth >> level:
                                 test = TextureColorSampleTest(
                                     dev = dev,
+                                    ctx = ctx,
                                     target = target,
                                     format = format, 
                                     width = size,
@@ -573,6 +638,7 @@ def main():
         for size in sizes:
             test = TextureDepthSampleTest(
                 dev = dev,
+                ctx = ctx,
                 target = target,
                 format = format, 
                 width = size,
index 7da00e42550193e278a80e14c58979f767b10bac..3595e9c614bd482b511b5adf61a76776858d7e4d 100755 (executable)
@@ -86,15 +86,16 @@ class TextureTest(TestCase):
         
         surface = texture.get_surface(face, level, zslice)
         
-        # ???
-        stride = pf_get_stride(texture->format, w)
-        size = pf_get_nblocksy(texture->format) * stride
+        stride = util_format_get_stride(format, width)
+        size = util_format_get_nblocksy(format, height) * stride
 
         in_raw = os.urandom(size)
 
-        surface.put_tile_raw(0, 0, surface.width, surface.height, in_raw, stride)
+        ctx = self.dev.context_create()
 
-        out_raw = surface.get_tile_raw(0, 0, surface.width, surface.height)
+        ctx.surface_write_raw(surface, 0, 0, surface.width, surface.height, in_raw, stride)
+
+        out_raw = ctx.surface_read_raw(surface, 0, 0, surface.width, surface.height)
 
         if in_raw != out_raw:
             raise TestFailure