svga: remove local variable in create_backed_surface_view()
[mesa.git] / src / gallium / drivers / svga / svga_surface.c
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #include "svga_cmd.h"
27
28 #include "pipe/p_state.h"
29 #include "pipe/p_defines.h"
30 #include "util/u_inlines.h"
31 #include "os/os_thread.h"
32 #include "util/u_bitmask.h"
33 #include "util/u_format.h"
34 #include "util/u_math.h"
35 #include "util/u_memory.h"
36
37 #include "svga_format.h"
38 #include "svga_screen.h"
39 #include "svga_context.h"
40 #include "svga_sampler_view.h"
41 #include "svga_resource_texture.h"
42 #include "svga_surface.h"
43 #include "svga_debug.h"
44
45 static void svga_mark_surface_dirty(struct pipe_surface *surf);
46
47 void
48 svga_texture_copy_handle(struct svga_context *svga,
49 struct svga_winsys_surface *src_handle,
50 unsigned src_x, unsigned src_y, unsigned src_z,
51 unsigned src_level, unsigned src_layer,
52 struct svga_winsys_surface *dst_handle,
53 unsigned dst_x, unsigned dst_y, unsigned dst_z,
54 unsigned dst_level, unsigned dst_layer,
55 unsigned width, unsigned height, unsigned depth)
56 {
57 struct svga_surface dst, src;
58 enum pipe_error ret;
59 SVGA3dCopyBox box, *boxes;
60
61 assert(svga);
62
63 src.handle = src_handle;
64 src.real_level = src_level;
65 src.real_layer = src_layer;
66 src.real_zslice = 0;
67
68 dst.handle = dst_handle;
69 dst.real_level = dst_level;
70 dst.real_layer = dst_layer;
71 dst.real_zslice = 0;
72
73 box.x = dst_x;
74 box.y = dst_y;
75 box.z = dst_z;
76 box.w = width;
77 box.h = height;
78 box.d = depth;
79 box.srcx = src_x;
80 box.srcy = src_y;
81 box.srcz = src_z;
82
83 /*
84 SVGA_DBG(DEBUG_VIEWS, "mipcopy src: %p %u (%ux%ux%u), dst: %p %u (%ux%ux%u)\n",
85 src_handle, src_level, src_x, src_y, src_z,
86 dst_handle, dst_level, dst_x, dst_y, dst_z);
87 */
88
89 ret = SVGA3D_BeginSurfaceCopy(svga->swc,
90 &src.base,
91 &dst.base,
92 &boxes, 1);
93 if (ret != PIPE_OK) {
94 svga_context_flush(svga, NULL);
95 ret = SVGA3D_BeginSurfaceCopy(svga->swc,
96 &src.base,
97 &dst.base,
98 &boxes, 1);
99 assert(ret == PIPE_OK);
100 }
101 *boxes = box;
102 SVGA_FIFOCommitAll(svga->swc);
103 }
104
105
106 struct svga_winsys_surface *
107 svga_texture_view_surface(struct svga_context *svga,
108 struct svga_texture *tex,
109 unsigned bind_flags,
110 SVGA3dSurfaceFlags flags,
111 SVGA3dSurfaceFormat format,
112 unsigned start_mip,
113 unsigned num_mip,
114 int layer_pick,
115 unsigned num_layers,
116 int zslice_pick,
117 struct svga_host_surface_cache_key *key) /* OUT */
118 {
119 struct svga_screen *ss = svga_screen(svga->pipe.screen);
120 struct svga_winsys_surface *handle;
121 uint32_t i, j;
122 unsigned z_offset = 0;
123
124 SVGA_DBG(DEBUG_PERF,
125 "svga: Create surface view: layer %d zslice %d mips %d..%d\n",
126 layer_pick, zslice_pick, start_mip, start_mip+num_mip-1);
127
128 key->flags = flags;
129 key->format = format;
130 key->numMipLevels = num_mip;
131 key->size.width = u_minify(tex->b.b.width0, start_mip);
132 key->size.height = u_minify(tex->b.b.height0, start_mip);
133 key->size.depth = zslice_pick < 0 ? u_minify(tex->b.b.depth0, start_mip) : 1;
134 key->cachable = 1;
135 key->arraySize = 1;
136 key->numFaces = 1;
137 key->sampleCount = tex->b.b.nr_samples;
138
139 if (key->sampleCount > 1) {
140 key->flags |= SVGA3D_SURFACE_MASKABLE_ANTIALIAS;
141 }
142
143 if (tex->b.b.target == PIPE_TEXTURE_CUBE && layer_pick < 0) {
144 key->flags |= SVGA3D_SURFACE_CUBEMAP;
145 key->numFaces = 6;
146 } else if (tex->b.b.target == PIPE_TEXTURE_1D_ARRAY ||
147 tex->b.b.target == PIPE_TEXTURE_2D_ARRAY) {
148 key->arraySize = num_layers;
149 }
150
151 if (key->format == SVGA3D_FORMAT_INVALID) {
152 key->cachable = 0;
153 return NULL;
154 }
155
156 SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n");
157 handle = svga_screen_surface_create(ss, bind_flags, PIPE_USAGE_DEFAULT, key);
158 if (!handle) {
159 key->cachable = 0;
160 return NULL;
161 }
162
163 SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle);
164
165 if (layer_pick < 0)
166 layer_pick = 0;
167
168 if (zslice_pick >= 0)
169 z_offset = zslice_pick;
170
171 for (i = 0; i < key->numMipLevels; i++) {
172 for (j = 0; j < key->numFaces * key->arraySize; j++) {
173 if (svga_is_texture_level_defined(tex, j + layer_pick, i + start_mip)) {
174 unsigned depth = (zslice_pick < 0 ?
175 u_minify(tex->b.b.depth0, i + start_mip) :
176 1);
177
178 svga_texture_copy_handle(svga,
179 tex->handle,
180 0, 0, z_offset,
181 i + start_mip,
182 j + layer_pick,
183 handle, 0, 0, 0, i, j,
184 u_minify(tex->b.b.width0, i + start_mip),
185 u_minify(tex->b.b.height0, i + start_mip),
186 depth);
187 }
188 }
189 }
190
191 return handle;
192 }
193
194
195 /**
196 * A helper function to create a surface view.
197 * The view boolean flag specifies whether svga_texture_view_surface()
198 * will be called to create a cloned surface and resource for the view.
199 */
200 static struct pipe_surface *
201 svga_create_surface_view(struct pipe_context *pipe,
202 struct pipe_resource *pt,
203 const struct pipe_surface *surf_tmpl,
204 boolean view)
205 {
206 struct svga_context *svga = svga_context(pipe);
207 struct svga_texture *tex = svga_texture(pt);
208 struct pipe_screen *screen = pipe->screen;
209 struct svga_screen *ss = svga_screen(screen);
210 struct svga_surface *s;
211 unsigned layer, zslice, bind;
212 unsigned nlayers = 1;
213 SVGA3dSurfaceFlags flags = 0;
214 SVGA3dSurfaceFormat format;
215 struct pipe_surface *retVal = NULL;
216
217 s = CALLOC_STRUCT(svga_surface);
218 if (!s)
219 return NULL;
220
221 SVGA_STATS_TIME_PUSH(ss->sws, SVGA_STATS_TIME_CREATESURFACEVIEW);
222
223 if (pt->target == PIPE_TEXTURE_CUBE) {
224 layer = surf_tmpl->u.tex.first_layer;
225 zslice = 0;
226 }
227 else if (pt->target == PIPE_TEXTURE_1D_ARRAY ||
228 pt->target == PIPE_TEXTURE_2D_ARRAY) {
229 layer = surf_tmpl->u.tex.first_layer;
230 zslice = 0;
231 nlayers = surf_tmpl->u.tex.last_layer - surf_tmpl->u.tex.first_layer + 1;
232 }
233 else {
234 layer = 0;
235 zslice = surf_tmpl->u.tex.first_layer;
236 }
237
238 pipe_reference_init(&s->base.reference, 1);
239 pipe_resource_reference(&s->base.texture, pt);
240 s->base.context = pipe;
241 s->base.format = surf_tmpl->format;
242 s->base.width = u_minify(pt->width0, surf_tmpl->u.tex.level);
243 s->base.height = u_minify(pt->height0, surf_tmpl->u.tex.level);
244 s->base.u.tex.level = surf_tmpl->u.tex.level;
245 s->base.u.tex.first_layer = surf_tmpl->u.tex.first_layer;
246 s->base.u.tex.last_layer = surf_tmpl->u.tex.last_layer;
247 s->view_id = SVGA3D_INVALID_ID;
248
249 s->backed = NULL;
250
251 if (util_format_is_depth_or_stencil(surf_tmpl->format)) {
252 flags = SVGA3D_SURFACE_HINT_DEPTHSTENCIL |
253 SVGA3D_SURFACE_BIND_DEPTH_STENCIL;
254 bind = PIPE_BIND_DEPTH_STENCIL;
255 }
256 else {
257 flags = SVGA3D_SURFACE_HINT_RENDERTARGET |
258 SVGA3D_SURFACE_BIND_RENDER_TARGET;
259 bind = PIPE_BIND_RENDER_TARGET;
260 }
261
262 if (tex->imported)
263 format = tex->key.format;
264 else
265 format = svga_translate_format(ss, surf_tmpl->format, bind);
266
267 assert(format != SVGA3D_FORMAT_INVALID);
268
269 if (view) {
270 SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u layer %u z %u, %p\n",
271 pt, surf_tmpl->u.tex.level, layer, zslice, s);
272
273 if (svga_have_vgpu10(svga)) {
274 switch (pt->target) {
275 case PIPE_TEXTURE_1D:
276 flags |= SVGA3D_SURFACE_1D;
277 break;
278 case PIPE_TEXTURE_1D_ARRAY:
279 flags |= SVGA3D_SURFACE_1D | SVGA3D_SURFACE_ARRAY;
280 break;
281 case PIPE_TEXTURE_2D_ARRAY:
282 flags |= SVGA3D_SURFACE_ARRAY;
283 break;
284 case PIPE_TEXTURE_3D:
285 flags |= SVGA3D_SURFACE_VOLUME;
286 break;
287 case PIPE_TEXTURE_CUBE:
288 if (nlayers == 6)
289 flags |= SVGA3D_SURFACE_CUBEMAP;
290 break;
291 default:
292 break;
293 }
294 }
295
296 /* When we clone the surface view resource, use the format used in
297 * the creation of the original resource.
298 */
299 s->handle = svga_texture_view_surface(svga, tex, bind, flags,
300 tex->key.format,
301 surf_tmpl->u.tex.level, 1,
302 layer, nlayers, zslice, &s->key);
303 if (!s->handle) {
304 FREE(s);
305 goto done;
306 }
307
308 s->key.format = format;
309 s->real_layer = 0;
310 s->real_level = 0;
311 s->real_zslice = 0;
312 } else {
313 SVGA_DBG(DEBUG_VIEWS,
314 "svga: Surface view: no %p, level %u, layer %u, z %u, %p\n",
315 pt, surf_tmpl->u.tex.level, layer, zslice, s);
316
317 memset(&s->key, 0, sizeof s->key);
318 s->key.format = format;
319 s->handle = tex->handle;
320 s->real_layer = layer;
321 s->real_zslice = zslice;
322 s->real_level = surf_tmpl->u.tex.level;
323 }
324
325 svga->hud.num_surface_views++;
326 retVal = &s->base;
327
328 done:
329 SVGA_STATS_TIME_POP(ss->sws);
330 return retVal;
331 }
332
333
334 static struct pipe_surface *
335 svga_create_surface(struct pipe_context *pipe,
336 struct pipe_resource *pt,
337 const struct pipe_surface *surf_tmpl)
338 {
339 struct svga_context *svga = svga_context(pipe);
340 struct pipe_screen *screen = pipe->screen;
341 struct pipe_surface *surf = NULL;
342 boolean view = FALSE;
343
344 SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATESURFACE);
345
346 if (svga_screen(screen)->debug.force_surface_view)
347 view = TRUE;
348
349 if (surf_tmpl->u.tex.level != 0 &&
350 svga_screen(screen)->debug.force_level_surface_view)
351 view = TRUE;
352
353 if (pt->target == PIPE_TEXTURE_3D)
354 view = TRUE;
355
356 if (svga_have_vgpu10(svga) || svga_screen(screen)->debug.no_surface_view)
357 view = FALSE;
358
359 surf = svga_create_surface_view(pipe, pt, surf_tmpl, view);
360
361 SVGA_STATS_TIME_POP(svga_sws(svga));
362
363 return surf;
364 }
365
366
367 /**
368 * Clone the surface view and its associated resource.
369 */
370 static struct svga_surface *
371 create_backed_surface_view(struct svga_context *svga, struct svga_surface *s)
372 {
373 SVGA_STATS_TIME_PUSH(svga_sws(svga),
374 SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW);
375
376 if (!s->backed) {
377 struct svga_texture *tex = svga_texture(s->base.texture);
378 struct pipe_surface *backed_view;
379
380 backed_view = svga_create_surface_view(&svga->pipe,
381 &tex->b.b,
382 &s->base,
383 TRUE);
384 if (!backed_view)
385 return NULL;
386
387 s->backed = svga_surface(backed_view);
388 }
389
390 svga_mark_surface_dirty(&s->backed->base);
391
392 SVGA_STATS_TIME_POP(svga_sws(svga));
393
394 return s->backed;
395 }
396
397 /**
398 * Create a DX RenderTarget/DepthStencil View for the given surface,
399 * if needed.
400 */
401 struct pipe_surface *
402 svga_validate_surface_view(struct svga_context *svga, struct svga_surface *s)
403 {
404 enum pipe_error ret = PIPE_OK;
405 unsigned shader;
406 struct pipe_surface *surf = NULL;
407
408 assert(svga_have_vgpu10(svga));
409
410 SVGA_STATS_TIME_PUSH(svga_sws(svga),
411 SVGA_STATS_TIME_VALIDATESURFACEVIEW);
412
413 /**
414 * DX spec explicitly specifies that no resource can be bound to a render
415 * target view and a shader resource view simultanously.
416 * So first check if the resource bound to this surface view collides with
417 * a sampler view. If so, then we will clone this surface view and its
418 * associated resource. We will then use the cloned surface view for
419 * render target.
420 */
421 for (shader = PIPE_SHADER_VERTEX; shader <= PIPE_SHADER_GEOMETRY; shader++) {
422 if (svga_check_sampler_view_resource_collision(svga, s->handle, shader)) {
423 SVGA_DBG(DEBUG_VIEWS,
424 "same resource used in shaderResource and renderTarget 0x%x\n",
425 s->handle);
426 s = create_backed_surface_view(svga, s);
427 if (!s)
428 goto done;
429
430 break;
431 }
432 }
433
434 if (s->view_id == SVGA3D_INVALID_ID) {
435 SVGA3dResourceType resType;
436 SVGA3dRenderTargetViewDesc desc;
437
438 desc.tex.mipSlice = s->real_level;
439 desc.tex.firstArraySlice = s->real_layer + s->real_zslice;
440 desc.tex.arraySize =
441 s->base.u.tex.last_layer - s->base.u.tex.first_layer + 1;
442
443 s->view_id = util_bitmask_add(svga->surface_view_id_bm);
444
445 switch (s->base.texture->target) {
446 case PIPE_TEXTURE_1D:
447 case PIPE_TEXTURE_1D_ARRAY:
448 resType = SVGA3D_RESOURCE_TEXTURE1D;
449 break;
450 case PIPE_TEXTURE_RECT:
451 case PIPE_TEXTURE_2D:
452 case PIPE_TEXTURE_2D_ARRAY:
453 case PIPE_TEXTURE_CUBE:
454 /* drawing to cube map is treated as drawing to 2D array */
455 resType = SVGA3D_RESOURCE_TEXTURE2D;
456 break;
457 case PIPE_TEXTURE_3D:
458 resType = SVGA3D_RESOURCE_TEXTURE3D;
459 break;
460 default:
461 assert(!"Unexpected texture target");
462 resType = SVGA3D_RESOURCE_TEXTURE2D;
463 }
464
465 if (util_format_is_depth_or_stencil(s->base.format)) {
466 ret = SVGA3D_vgpu10_DefineDepthStencilView(svga->swc,
467 s->view_id,
468 s->handle,
469 s->key.format,
470 resType,
471 &desc);
472 }
473 else {
474 SVGA3dSurfaceFormat view_format = s->key.format;
475 const struct svga_texture *stex = svga_texture(s->base.texture);
476
477 /* Can't create RGBA render target view of a RGBX surface so adjust
478 * the view format. We do something similar for texture samplers in
479 * svga_validate_pipe_sampler_view().
480 */
481 if (view_format == SVGA3D_B8G8R8A8_UNORM &&
482 stex->key.format == SVGA3D_B8G8R8X8_TYPELESS) {
483 view_format = SVGA3D_B8G8R8X8_UNORM;
484 }
485
486 ret = SVGA3D_vgpu10_DefineRenderTargetView(svga->swc,
487 s->view_id,
488 s->handle,
489 view_format,
490 resType,
491 &desc);
492 }
493
494 if (ret != PIPE_OK) {
495 util_bitmask_clear(svga->surface_view_id_bm, s->view_id);
496 s->view_id = SVGA3D_INVALID_ID;
497 goto done;
498 }
499 }
500 surf = &s->base;
501
502 done:
503 SVGA_STATS_TIME_POP(svga_sws(svga));
504
505 return surf;
506 }
507
508
509
510 static void
511 svga_surface_destroy(struct pipe_context *pipe,
512 struct pipe_surface *surf)
513 {
514 struct svga_context *svga = svga_context(pipe);
515 struct svga_surface *s = svga_surface(surf);
516 struct svga_texture *t = svga_texture(surf->texture);
517 struct svga_screen *ss = svga_screen(surf->texture->screen);
518 enum pipe_error ret = PIPE_OK;
519
520 SVGA_STATS_TIME_PUSH(ss->sws, SVGA_STATS_TIME_DESTROYSURFACE);
521
522 /* Destroy the backed view surface if it exists */
523 if (s->backed) {
524 svga_surface_destroy(pipe, &s->backed->base);
525 s->backed = NULL;
526 }
527
528 if (s->handle != t->handle) {
529 SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle);
530 svga_screen_surface_destroy(ss, &s->key, &s->handle);
531 }
532
533 if (s->view_id != SVGA3D_INVALID_ID) {
534 unsigned try;
535
536 assert(svga_have_vgpu10(svga));
537 for (try = 0; try < 2; try++) {
538 if (util_format_is_depth_or_stencil(s->base.format)) {
539 ret = SVGA3D_vgpu10_DestroyDepthStencilView(svga->swc, s->view_id);
540 }
541 else {
542 ret = SVGA3D_vgpu10_DestroyRenderTargetView(svga->swc, s->view_id);
543 }
544 if (ret == PIPE_OK)
545 break;
546 svga_context_flush(svga, NULL);
547 }
548 assert(ret == PIPE_OK);
549 util_bitmask_clear(svga->surface_view_id_bm, s->view_id);
550 }
551
552 pipe_resource_reference(&surf->texture, NULL);
553 FREE(surf);
554
555 svga->hud.num_surface_views--;
556 SVGA_STATS_TIME_POP(ss->sws);
557 }
558
559
560 static void
561 svga_mark_surface_dirty(struct pipe_surface *surf)
562 {
563 struct svga_surface *s = svga_surface(surf);
564 struct svga_texture *tex = svga_texture(surf->texture);
565
566 if (!s->dirty) {
567 s->dirty = TRUE;
568
569 if (s->handle == tex->handle) {
570 /* hmm so 3d textures always have all their slices marked ? */
571 svga_define_texture_level(tex, surf->u.tex.first_layer,
572 surf->u.tex.level);
573 }
574 else {
575 /* this will happen later in svga_propagate_surface */
576 }
577 }
578
579 /* Increment the view_age and texture age for this surface's mipmap
580 * level so that any sampler views into the texture are re-validated too.
581 */
582 svga_age_texture_view(tex, surf->u.tex.level);
583 }
584
585
586 void
587 svga_mark_surfaces_dirty(struct svga_context *svga)
588 {
589 unsigned i;
590
591 for (i = 0; i < svga->curr.framebuffer.nr_cbufs; i++) {
592 if (svga->curr.framebuffer.cbufs[i])
593 svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]);
594 }
595 if (svga->curr.framebuffer.zsbuf)
596 svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf);
597 }
598
599
600 /**
601 * Progagate any changes from surfaces to texture.
602 * pipe is optional context to inline the blit command in.
603 */
604 void
605 svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf)
606 {
607 struct svga_surface *s = svga_surface(surf);
608 struct svga_texture *tex = svga_texture(surf->texture);
609 struct svga_screen *ss = svga_screen(surf->texture->screen);
610 unsigned zslice, layer;
611 unsigned nlayers = 1;
612 unsigned i;
613
614 if (!s->dirty)
615 return;
616
617 SVGA_STATS_TIME_PUSH(ss->sws, SVGA_STATS_TIME_PROPAGATESURFACE);
618
619 if (surf->texture->target == PIPE_TEXTURE_CUBE) {
620 zslice = 0;
621 layer = surf->u.tex.first_layer;
622 }
623 else if (surf->texture->target == PIPE_TEXTURE_1D_ARRAY ||
624 surf->texture->target == PIPE_TEXTURE_2D_ARRAY) {
625 zslice = 0;
626 layer = surf->u.tex.first_layer;
627 nlayers = surf->u.tex.last_layer - surf->u.tex.first_layer + 1;
628 }
629 else {
630 zslice = surf->u.tex.first_layer;
631 layer = 0;
632 }
633
634 s->dirty = FALSE;
635 ss->texture_timestamp++;
636 svga_age_texture_view(tex, surf->u.tex.level);
637
638 if (s->handle != tex->handle) {
639 SVGA_DBG(DEBUG_VIEWS,
640 "svga: Surface propagate: tex %p, level %u, from %p\n",
641 tex, surf->u.tex.level, surf);
642 for (i = 0; i < nlayers; i++) {
643 svga_texture_copy_handle(svga,
644 s->handle, 0, 0, 0, s->real_level,
645 s->real_layer + i,
646 tex->handle, 0, 0, zslice, surf->u.tex.level,
647 layer + i,
648 u_minify(tex->b.b.width0, surf->u.tex.level),
649 u_minify(tex->b.b.height0, surf->u.tex.level),
650 1);
651 svga_define_texture_level(tex, layer + i, surf->u.tex.level);
652 }
653 }
654
655 SVGA_STATS_TIME_POP(ss->sws);
656 }
657
658
659 /**
660 * Check if we should call svga_propagate_surface on the surface.
661 */
662 boolean
663 svga_surface_needs_propagation(const struct pipe_surface *surf)
664 {
665 const struct svga_surface *s = svga_surface_const(surf);
666 struct svga_texture *tex = svga_texture(surf->texture);
667
668 return s->dirty && s->handle != tex->handle;
669 }
670
671
672 static void
673 svga_get_sample_position(struct pipe_context *context,
674 unsigned sample_count, unsigned sample_index,
675 float *pos_out)
676 {
677 /* We can't actually query the device to learn the sample positions.
678 * These were grabbed from nvidia's driver.
679 */
680 static const float pos1[1][2] = {
681 { 0.5, 0.5 }
682 };
683 static const float pos4[4][2] = {
684 { 0.375000, 0.125000 },
685 { 0.875000, 0.375000 },
686 { 0.125000, 0.625000 },
687 { 0.625000, 0.875000 }
688 };
689 static const float pos8[8][2] = {
690 { 0.562500, 0.312500 },
691 { 0.437500, 0.687500 },
692 { 0.812500, 0.562500 },
693 { 0.312500, 0.187500 },
694 { 0.187500, 0.812500 },
695 { 0.062500, 0.437500 },
696 { 0.687500, 0.937500 },
697 { 0.937500, 0.062500 }
698 };
699 static const float pos16[16][2] = {
700 { 0.187500, 0.062500 },
701 { 0.437500, 0.187500 },
702 { 0.062500, 0.312500 },
703 { 0.312500, 0.437500 },
704 { 0.687500, 0.062500 },
705 { 0.937500, 0.187500 },
706 { 0.562500, 0.312500 },
707 { 0.812500, 0.437500 },
708 { 0.187500, 0.562500 },
709 { 0.437500, 0.687500 },
710 { 0.062500, 0.812500 },
711 { 0.312500, 0.937500 },
712 { 0.687500, 0.562500 },
713 { 0.937500, 0.687500 },
714 { 0.562500, 0.812500 },
715 { 0.812500, 0.937500 }
716 };
717 const float (*positions)[2];
718
719 switch (sample_count) {
720 case 4:
721 positions = pos4;
722 break;
723 case 8:
724 positions = pos8;
725 break;
726 case 16:
727 positions = pos16;
728 break;
729 default:
730 positions = pos1;
731 }
732
733 pos_out[0] = positions[sample_index][0];
734 pos_out[1] = positions[sample_index][1];
735 }
736
737
738 void
739 svga_init_surface_functions(struct svga_context *svga)
740 {
741 svga->pipe.create_surface = svga_create_surface;
742 svga->pipe.surface_destroy = svga_surface_destroy;
743 svga->pipe.get_sample_position = svga_get_sample_position;
744 }