~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/gallium/tests/python/tests/regress/vertex-shader/vertex-shader.py

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
##########################################################################
 
3
 
4
# Copyright 2009 VMware, Inc.
 
5
# All Rights Reserved.
 
6
 
7
# Permission is hereby granted, free of charge, to any person obtaining a
 
8
# copy of this software and associated documentation files (the
 
9
# "Software"), to deal in the Software without restriction, including
 
10
# without limitation the rights to use, copy, modify, merge, publish,
 
11
# distribute, sub license, and/or sell copies of the Software, and to
 
12
# permit persons to whom the Software is furnished to do so, subject to
 
13
# the following conditions:
 
14
 
15
# The above copyright notice and this permission notice (including the
 
16
# next paragraph) shall be included in all copies or substantial portions
 
17
# of the Software.
 
18
 
19
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
20
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 
22
# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
 
23
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 
24
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 
25
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
26
 
27
##########################################################################
 
28
 
 
29
 
 
30
import struct
 
31
 
 
32
from gallium import *
 
33
 
 
34
def make_image(surface):
 
35
    data = surface.get_tile_rgba8(0, 0, surface.width, surface.height)
 
36
 
 
37
    import Image
 
38
    outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1)
 
39
    return outimage
 
40
 
 
41
def save_image(filename, surface):
 
42
    outimage = make_image(surface)
 
43
    outimage.save(filename, "PNG")
 
44
 
 
45
def test(dev, name):
 
46
    ctx = dev.context_create()
 
47
 
 
48
    width = 320
 
49
    height = 320
 
50
    minz = 0.0
 
51
    maxz = 1.0
 
52
 
 
53
    # disabled blending/masking
 
54
    blend = Blend()
 
55
    blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE
 
56
    blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE
 
57
    blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO
 
58
    blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO
 
59
    blend.rt[0].colormask = PIPE_MASK_RGBA
 
60
    ctx.set_blend(blend)
 
61
 
 
62
    # depth/stencil/alpha
 
63
    depth_stencil_alpha = DepthStencilAlpha()
 
64
    depth_stencil_alpha.depth.enabled = 0
 
65
    depth_stencil_alpha.depth.writemask = 1
 
66
    depth_stencil_alpha.depth.func = PIPE_FUNC_LESS
 
67
    ctx.set_depth_stencil_alpha(depth_stencil_alpha)
 
68
 
 
69
    # rasterizer
 
70
    rasterizer = Rasterizer()
 
71
    rasterizer.front_winding = PIPE_WINDING_CW
 
72
    rasterizer.cull_mode = PIPE_WINDING_NONE
 
73
    rasterizer.scissor = 1
 
74
    ctx.set_rasterizer(rasterizer)
 
75
 
 
76
    # viewport
 
77
    viewport = Viewport()
 
78
    scale = FloatArray(4)
 
79
    scale[0] = width / 2.0
 
80
    scale[1] = -height / 2.0
 
81
    scale[2] = (maxz - minz) / 2.0
 
82
    scale[3] = 1.0
 
83
    viewport.scale = scale
 
84
    translate = FloatArray(4)
 
85
    translate[0] = width / 2.0
 
86
    translate[1] = height / 2.0
 
87
    translate[2] = (maxz - minz) / 2.0
 
88
    translate[3] = 0.0
 
89
    viewport.translate = translate
 
90
    ctx.set_viewport(viewport)
 
91
 
 
92
    # samplers
 
93
    sampler = Sampler()
 
94
    sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE
 
95
    sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE
 
96
    sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE
 
97
    sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE
 
98
    sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
 
99
    sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
 
100
    sampler.normalized_coords = 1
 
101
    ctx.set_fragment_sampler(0, sampler)
 
102
 
 
103
    # scissor
 
104
    scissor = Scissor()
 
105
    scissor.minx = 0
 
106
    scissor.miny = 0
 
107
    scissor.maxx = width
 
108
    scissor.maxy = height
 
109
    ctx.set_scissor(scissor)
 
110
 
 
111
    clip = Clip()
 
112
    clip.nr = 0
 
113
    ctx.set_clip(clip)
 
114
 
 
115
    # framebuffer
 
116
    cbuf = dev.resource_create(
 
117
        PIPE_FORMAT_B8G8R8X8_UNORM,
 
118
        width, height,
 
119
        bind=PIPE_BIND_RENDER_TARGET,
 
120
    ).get_surface()
 
121
    fb = Framebuffer()
 
122
    fb.width = width
 
123
    fb.height = height
 
124
    fb.nr_cbufs = 1
 
125
    fb.set_cbuf(0, cbuf)
 
126
    ctx.set_framebuffer(fb)
 
127
    rgba = FloatArray(4);
 
128
    rgba[0] = 0.5
 
129
    rgba[1] = 0.5
 
130
    rgba[2] = 0.5
 
131
    rgba[3] = 0.5
 
132
    ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0)
 
133
 
 
134
    # vertex shader
 
135
    vs = Shader(file('vert-' + name + '.sh', 'rt').read())
 
136
    ctx.set_vertex_shader(vs)
 
137
 
 
138
    # fragment shader
 
139
    fs = Shader('''
 
140
        FRAG
 
141
        DCL IN[0], COLOR, LINEAR
 
142
        DCL OUT[0], COLOR, CONSTANT
 
143
        0:MOV OUT[0], IN[0]
 
144
        1:END
 
145
    ''')
 
146
    ctx.set_fragment_shader(fs)
 
147
 
 
148
    constbuf0 = dev.buffer_create(64,
 
149
                                  (PIPE_BUFFER_USAGE_CONSTANT |
 
150
                                   PIPE_BUFFER_USAGE_GPU_READ |
 
151
                                   PIPE_BUFFER_USAGE_CPU_WRITE),
 
152
                                  4 * 4 * 4)
 
153
 
 
154
    cbdata = ''
 
155
    cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0)
 
156
    cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0)
 
157
    cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0)
 
158
    cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0)
 
159
 
 
160
    constbuf0.write(cbdata, 0)
 
161
 
 
162
    ctx.set_constant_buffer(PIPE_SHADER_VERTEX,
 
163
                            0,
 
164
                            constbuf0)
 
165
 
 
166
    constbuf1 = dev.buffer_create(64,
 
167
                                  (PIPE_BUFFER_USAGE_CONSTANT |
 
168
                                   PIPE_BUFFER_USAGE_GPU_READ |
 
169
                                   PIPE_BUFFER_USAGE_CPU_WRITE),
 
170
                                  4 * 4 * 4)
 
171
 
 
172
    cbdata = ''
 
173
    cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1)
 
174
    cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25)
 
175
    cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5)
 
176
    cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75)
 
177
 
 
178
    constbuf1.write(cbdata, 0)
 
179
 
 
180
    ctx.set_constant_buffer(PIPE_SHADER_VERTEX,
 
181
                            1,
 
182
                            constbuf1)
 
183
 
 
184
    xy = [
 
185
         0.0,  0.8,
 
186
        -0.2,  0.4,
 
187
         0.2,  0.4,
 
188
        -0.4,  0.0,
 
189
         0.0,  0.0,
 
190
         0.4,  0.0,
 
191
        -0.6, -0.4,
 
192
        -0.2, -0.4,
 
193
         0.2, -0.4,
 
194
         0.6, -0.4,
 
195
        -0.8, -0.8,
 
196
        -0.4, -0.8,
 
197
         0.0, -0.8,
 
198
         0.4, -0.8,
 
199
         0.8, -0.8,
 
200
    ]
 
201
    color = [
 
202
        1.0, 0.0, 0.0,
 
203
        0.0, 1.0, 0.0,
 
204
        0.0, 0.0, 1.0,
 
205
    ]
 
206
    tri = [
 
207
         1,  2,  0,
 
208
         3,  4,  1,
 
209
         4,  2,  1,
 
210
         4,  5,  2,
 
211
         6,  7,  3,
 
212
         7,  4,  3,
 
213
         7,  8,  4,
 
214
         8,  5,  4,
 
215
         8,  9,  5,
 
216
        10, 11,  6,
 
217
        11,  7,  6,
 
218
        11, 12,  7,
 
219
        12,  8,  7,
 
220
        12, 13,  8,
 
221
        13,  9,  8,
 
222
        13, 14,  9,
 
223
    ]
 
224
 
 
225
    nverts = 16 * 3
 
226
    nattrs = 2
 
227
    verts = FloatArray(nverts * nattrs * 4)
 
228
 
 
229
    for i in range(0, nverts):
 
230
        verts[i * nattrs * 4 + 0] = xy[tri[i] * 2 + 0] # x
 
231
        verts[i * nattrs * 4 + 1] = xy[tri[i] * 2 + 1] # y
 
232
        verts[i * nattrs * 4 + 2] = 0.5 # z
 
233
        verts[i * nattrs * 4 + 3] = 1.0 # w
 
234
        verts[i * nattrs * 4 + 4] = color[(i % 3) * 3 + 0] # r
 
235
        verts[i * nattrs * 4 + 5] = color[(i % 3) * 3 + 1] # g
 
236
        verts[i * nattrs * 4 + 6] = color[(i % 3) * 3 + 2] # b
 
237
        verts[i * nattrs * 4 + 7] = 1.0 # a
 
238
 
 
239
    ctx.draw_vertices(PIPE_PRIM_TRIANGLES,
 
240
                      nverts,
 
241
                      nattrs,
 
242
                      verts)
 
243
 
 
244
    ctx.flush()
 
245
 
 
246
    save_image('vert-' + name + '.png', cbuf)
 
247
 
 
248
def main():
 
249
    tests = [
 
250
        'abs',
 
251
        'add',
 
252
        'arl',
 
253
        'arr',
 
254
        'cb-1d',
 
255
        'cb-2d',
 
256
        'dp3',
 
257
        'dp4',
 
258
        'dst',
 
259
        'ex2',
 
260
        'flr',
 
261
        'frc',
 
262
        'lg2',
 
263
        'lit',
 
264
        'lrp',
 
265
        'mad',
 
266
        'max',
 
267
        'min',
 
268
        'mov',
 
269
        'mul',
 
270
        'rcp',
 
271
        'rsq',
 
272
        'sge',
 
273
        'slt',
 
274
        'srcmod-abs',
 
275
        'srcmod-absneg',
 
276
        'srcmod-neg',
 
277
        'srcmod-swz',
 
278
        'sub',
 
279
        'xpd',
 
280
    ]
 
281
 
 
282
    dev = Device()
 
283
    for t in tests:
 
284
        test(dev, t)
 
285
 
 
286
if __name__ == '__main__':
 
287
    main()