1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
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"
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"
45 static void svga_mark_surface_dirty(struct pipe_surface
*surf
);
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
)
57 struct svga_surface dst
, src
;
59 SVGA3dCopyBox box
, *boxes
;
63 src
.handle
= src_handle
;
64 src
.real_level
= src_level
;
65 src
.real_layer
= src_layer
;
68 dst
.handle
= dst_handle
;
69 dst
.real_level
= dst_level
;
70 dst
.real_layer
= dst_layer
;
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);
89 ret
= SVGA3D_BeginSurfaceCopy(svga
->swc
,
94 svga_context_flush(svga
, NULL
);
95 ret
= SVGA3D_BeginSurfaceCopy(svga
->swc
,
99 assert(ret
== PIPE_OK
);
102 SVGA_FIFOCommitAll(svga
->swc
);
106 /* A helper function to sync up the two surface handles.
109 svga_texture_copy_handle_resource(struct svga_context
*svga
,
110 struct svga_texture
*src_tex
,
111 struct svga_winsys_surface
*dst
,
112 unsigned int numMipLevels
,
113 unsigned int numLayers
,
115 unsigned int mipoffset
,
116 unsigned int layeroffset
)
119 unsigned int zoffset
= 0;
121 /* A negative zslice_pick implies zoffset at 0, and depth to copy is
122 * from the depth of the texture at the particular mipmap level.
124 if (zslice_pick
>= 0)
125 zoffset
= zslice_pick
;
127 for (i
= 0; i
< numMipLevels
; i
++) {
128 unsigned int miplevel
= i
+ mipoffset
;
130 for (j
= 0; j
< numLayers
; j
++) {
131 if (svga_is_texture_level_defined(src_tex
, j
+layeroffset
, miplevel
)) {
132 unsigned depth
= (zslice_pick
< 0 ?
133 u_minify(src_tex
->b
.b
.depth0
, miplevel
) : 1);
135 svga_texture_copy_handle(svga
,
141 u_minify(src_tex
->b
.b
.width0
, miplevel
),
142 u_minify(src_tex
->b
.b
.height0
, miplevel
),
150 struct svga_winsys_surface
*
151 svga_texture_view_surface(struct svga_context
*svga
,
152 struct svga_texture
*tex
,
154 SVGA3dSurfaceAllFlags flags
,
155 SVGA3dSurfaceFormat format
,
162 struct svga_host_surface_cache_key
*key
) /* OUT */
164 struct svga_screen
*ss
= svga_screen(svga
->pipe
.screen
);
165 struct svga_winsys_surface
*handle
= NULL
;
167 boolean needCopyResource
;
170 "svga: Create surface view: layer %d zslice %d mips %d..%d\n",
171 layer_pick
, zslice_pick
, start_mip
, start_mip
+num_mip
-1);
173 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_EMULATESURFACEVIEW
);
176 key
->format
= format
;
177 key
->numMipLevels
= num_mip
;
178 key
->size
.width
= u_minify(tex
->b
.b
.width0
, start_mip
);
179 key
->size
.height
= u_minify(tex
->b
.b
.height0
, start_mip
);
180 key
->size
.depth
= zslice_pick
< 0 ? u_minify(tex
->b
.b
.depth0
, start_mip
) : 1;
185 /* single sample surface can be treated as non-multisamples surface */
186 key
->sampleCount
= tex
->b
.b
.nr_samples
> 1 ? tex
->b
.b
.nr_samples
: 0;
188 if (key
->sampleCount
> 1) {
189 key
->flags
|= SVGA3D_SURFACE_MASKABLE_ANTIALIAS
;
192 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
&& layer_pick
< 0) {
193 key
->flags
|= SVGA3D_SURFACE_CUBEMAP
;
195 } else if (tex
->b
.b
.target
== PIPE_TEXTURE_1D_ARRAY
||
196 tex
->b
.b
.target
== PIPE_TEXTURE_2D_ARRAY
) {
197 key
->arraySize
= num_layers
;
200 if (key
->format
== SVGA3D_FORMAT_INVALID
) {
205 if (cacheable
&& tex
->backed_handle
&&
206 memcmp(key
, &tex
->backed_key
, sizeof *key
) == 0) {
207 handle
= tex
->backed_handle
;
208 needCopyResource
= tex
->backed_age
< tex
->age
;
210 SVGA_DBG(DEBUG_DMA
, "surface_create for texture view\n");
211 handle
= svga_screen_surface_create(ss
, bind_flags
, PIPE_USAGE_DEFAULT
,
213 needCopyResource
= TRUE
;
215 if (cacheable
&& !tex
->backed_handle
) {
216 tex
->backed_handle
= handle
;
217 memcpy(&tex
->backed_key
, key
, sizeof *key
);
226 SVGA_DBG(DEBUG_DMA
, " --> got sid %p (texture view)\n", handle
);
231 if (needCopyResource
) {
232 svga_texture_copy_handle_resource(svga
, tex
, handle
,
234 key
->numFaces
* key
->arraySize
,
235 zslice_pick
, start_mip
, layer_pick
);
236 tex
->backed_age
= tex
->age
;
240 SVGA_STATS_TIME_POP(ss
->sws
);
247 * A helper function to create a surface view.
248 * The view boolean flag specifies whether svga_texture_view_surface()
249 * will be called to create a cloned surface and resource for the view.
251 static struct pipe_surface
*
252 svga_create_surface_view(struct pipe_context
*pipe
,
253 struct pipe_resource
*pt
,
254 const struct pipe_surface
*surf_tmpl
,
257 struct svga_context
*svga
= svga_context(pipe
);
258 struct svga_texture
*tex
= svga_texture(pt
);
259 struct pipe_screen
*screen
= pipe
->screen
;
260 struct svga_screen
*ss
= svga_screen(screen
);
261 struct svga_surface
*s
;
262 unsigned layer
, zslice
, bind
;
263 unsigned nlayers
= 1;
264 SVGA3dSurfaceAllFlags flags
= 0;
265 SVGA3dSurfaceFormat format
;
266 struct pipe_surface
*retVal
= NULL
;
268 s
= CALLOC_STRUCT(svga_surface
);
272 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_CREATESURFACEVIEW
);
274 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
275 layer
= surf_tmpl
->u
.tex
.first_layer
;
278 else if (pt
->target
== PIPE_TEXTURE_1D_ARRAY
||
279 pt
->target
== PIPE_TEXTURE_2D_ARRAY
) {
280 layer
= surf_tmpl
->u
.tex
.first_layer
;
282 nlayers
= surf_tmpl
->u
.tex
.last_layer
- surf_tmpl
->u
.tex
.first_layer
+ 1;
286 zslice
= surf_tmpl
->u
.tex
.first_layer
;
289 pipe_reference_init(&s
->base
.reference
, 1);
290 pipe_resource_reference(&s
->base
.texture
, pt
);
291 s
->base
.context
= pipe
;
292 s
->base
.format
= surf_tmpl
->format
;
293 s
->base
.width
= u_minify(pt
->width0
, surf_tmpl
->u
.tex
.level
);
294 s
->base
.height
= u_minify(pt
->height0
, surf_tmpl
->u
.tex
.level
);
295 s
->base
.u
.tex
.level
= surf_tmpl
->u
.tex
.level
;
296 s
->base
.u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
297 s
->base
.u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
298 s
->view_id
= SVGA3D_INVALID_ID
;
302 if (util_format_is_depth_or_stencil(surf_tmpl
->format
)) {
303 flags
= SVGA3D_SURFACE_HINT_DEPTHSTENCIL
|
304 SVGA3D_SURFACE_BIND_DEPTH_STENCIL
;
305 bind
= PIPE_BIND_DEPTH_STENCIL
;
308 flags
= SVGA3D_SURFACE_HINT_RENDERTARGET
|
309 SVGA3D_SURFACE_BIND_RENDER_TARGET
;
310 bind
= PIPE_BIND_RENDER_TARGET
;
314 /* imported resource (a window) */
315 format
= tex
->key
.format
;
316 if (util_format_is_srgb(surf_tmpl
->format
)) {
317 /* sRGB rendering to window */
318 format
= svga_linear_to_srgb(format
);
322 format
= svga_translate_format(ss
, surf_tmpl
->format
, bind
);
325 assert(format
!= SVGA3D_FORMAT_INVALID
);
328 SVGA_DBG(DEBUG_VIEWS
,
329 "New backed surface view: resource %p, level %u layer %u z %u, %p\n",
330 pt
, surf_tmpl
->u
.tex
.level
, layer
, zslice
, s
);
332 if (svga_have_vgpu10(svga
)) {
333 switch (pt
->target
) {
334 case PIPE_TEXTURE_1D
:
335 flags
|= SVGA3D_SURFACE_1D
;
337 case PIPE_TEXTURE_1D_ARRAY
:
338 flags
|= SVGA3D_SURFACE_1D
| SVGA3D_SURFACE_ARRAY
;
340 case PIPE_TEXTURE_2D_ARRAY
:
341 flags
|= SVGA3D_SURFACE_ARRAY
;
343 case PIPE_TEXTURE_3D
:
344 flags
|= SVGA3D_SURFACE_VOLUME
;
346 case PIPE_TEXTURE_CUBE
:
348 flags
|= SVGA3D_SURFACE_CUBEMAP
;
355 /* When we clone the surface view resource, use the format used in
356 * the creation of the original resource.
358 s
->handle
= svga_texture_view_surface(svga
, tex
, bind
, flags
,
360 surf_tmpl
->u
.tex
.level
, 1,
361 layer
, nlayers
, zslice
,
368 s
->key
.format
= format
;
373 SVGA_DBG(DEBUG_VIEWS
,
374 "New surface view: resource %p, level %u, layer %u, z %u, %p\n",
375 pt
, surf_tmpl
->u
.tex
.level
, layer
, zslice
, s
);
377 memset(&s
->key
, 0, sizeof s
->key
);
378 s
->key
.format
= format
;
379 s
->handle
= tex
->handle
;
380 s
->real_layer
= layer
;
381 s
->real_zslice
= zslice
;
382 s
->real_level
= surf_tmpl
->u
.tex
.level
;
385 svga
->hud
.num_surface_views
++;
389 SVGA_STATS_TIME_POP(ss
->sws
);
394 static struct pipe_surface
*
395 svga_create_surface(struct pipe_context
*pipe
,
396 struct pipe_resource
*pt
,
397 const struct pipe_surface
*surf_tmpl
)
399 struct svga_context
*svga
= svga_context(pipe
);
400 struct pipe_screen
*screen
= pipe
->screen
;
401 struct pipe_surface
*surf
= NULL
;
402 boolean view
= FALSE
;
404 SVGA_STATS_TIME_PUSH(svga_sws(svga
), SVGA_STATS_TIME_CREATESURFACE
);
406 if (svga_screen(screen
)->debug
.force_surface_view
)
409 if (surf_tmpl
->u
.tex
.level
!= 0 &&
410 svga_screen(screen
)->debug
.force_level_surface_view
)
413 if (pt
->target
== PIPE_TEXTURE_3D
)
416 if (svga_have_vgpu10(svga
) || svga_screen(screen
)->debug
.no_surface_view
)
419 surf
= svga_create_surface_view(pipe
, pt
, surf_tmpl
, view
);
421 SVGA_STATS_TIME_POP(svga_sws(svga
));
428 * Clone the surface view and its associated resource.
430 static struct svga_surface
*
431 create_backed_surface_view(struct svga_context
*svga
, struct svga_surface
*s
)
433 struct svga_texture
*tex
= svga_texture(s
->base
.texture
);
436 struct pipe_surface
*backed_view
;
438 SVGA_STATS_TIME_PUSH(svga_sws(svga
),
439 SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW
);
441 backed_view
= svga_create_surface_view(&svga
->pipe
,
448 s
->backed
= svga_surface(backed_view
);
450 SVGA_STATS_TIME_POP(svga_sws(svga
));
452 else if (s
->backed
->age
< tex
->age
) {
454 * There is already an existing backing surface, but we still need to
455 * sync the backing resource if the original resource has been modified
456 * since the last copy.
458 struct svga_surface
*bs
= s
->backed
;
459 unsigned int layer
, zslice
;
463 switch (tex
->b
.b
.target
) {
464 case PIPE_TEXTURE_CUBE
:
465 case PIPE_TEXTURE_1D_ARRAY
:
466 case PIPE_TEXTURE_2D_ARRAY
:
467 layer
= s
->base
.u
.tex
.first_layer
;
472 zslice
= s
->base
.u
.tex
.first_layer
;
475 svga_texture_copy_handle_resource(svga
, tex
, bs
->handle
,
476 bs
->key
.numMipLevels
,
477 bs
->key
.numFaces
* bs
->key
.arraySize
,
478 zslice
, s
->base
.u
.tex
.level
, layer
);
481 svga_mark_surface_dirty(&s
->backed
->base
);
482 s
->backed
->age
= tex
->age
;
489 * Create a DX RenderTarget/DepthStencil View for the given surface,
492 struct pipe_surface
*
493 svga_validate_surface_view(struct svga_context
*svga
, struct svga_surface
*s
)
495 enum pipe_error ret
= PIPE_OK
;
496 enum pipe_shader_type shader
;
498 assert(svga_have_vgpu10(svga
));
501 SVGA_STATS_TIME_PUSH(svga_sws(svga
),
502 SVGA_STATS_TIME_VALIDATESURFACEVIEW
);
505 * DX spec explicitly specifies that no resource can be bound to a render
506 * target view and a shader resource view simultanously.
507 * So first check if the resource bound to this surface view collides with
508 * a sampler view. If so, then we will clone this surface view and its
509 * associated resource. We will then use the cloned surface view for
512 for (shader
= PIPE_SHADER_VERTEX
; shader
<= PIPE_SHADER_GEOMETRY
; shader
++) {
513 if (svga_check_sampler_view_resource_collision(svga
, s
->handle
, shader
)) {
514 SVGA_DBG(DEBUG_VIEWS
,
515 "same resource used in shaderResource and renderTarget 0x%x\n",
517 s
= create_backed_surface_view(svga
, s
);
520 svga
->state
.hw_draw
.has_backed_views
= TRUE
;
522 /* s may be null here if the function failed */
527 if (s
&& s
->view_id
== SVGA3D_INVALID_ID
) {
528 SVGA3dResourceType resType
;
529 SVGA3dRenderTargetViewDesc desc
;
530 struct svga_texture
*stex
= svga_texture(s
->base
.texture
);
532 if (stex
->validated
== FALSE
) {
533 assert(stex
->handle
);
535 /* We are about to render into a surface that has not been validated.
536 * First invalidate the surface so that the device does not
537 * need to update the host-side copy with the invalid
538 * content when the associated mob is first bound to the surface.
540 if (svga
->swc
->surface_invalidate(svga
->swc
, stex
->handle
) != PIPE_OK
) {
541 svga_context_flush(svga
, NULL
);
542 ret
= svga
->swc
->surface_invalidate(svga
->swc
, stex
->handle
);
543 assert(ret
== PIPE_OK
);
545 stex
->validated
= TRUE
;
548 desc
.tex
.mipSlice
= s
->real_level
;
549 desc
.tex
.firstArraySlice
= s
->real_layer
+ s
->real_zslice
;
551 s
->base
.u
.tex
.last_layer
- s
->base
.u
.tex
.first_layer
+ 1;
553 s
->view_id
= util_bitmask_add(svga
->surface_view_id_bm
);
555 resType
= svga_resource_type(s
->base
.texture
->target
);
557 if (util_format_is_depth_or_stencil(s
->base
.format
)) {
558 ret
= SVGA3D_vgpu10_DefineDepthStencilView(svga
->swc
,
566 SVGA3dSurfaceFormat view_format
= s
->key
.format
;
567 const struct svga_texture
*stex
= svga_texture(s
->base
.texture
);
569 /* Can't create RGBA render target view of a RGBX surface so adjust
570 * the view format. We do something similar for texture samplers in
571 * svga_validate_pipe_sampler_view().
573 if (view_format
== SVGA3D_B8G8R8A8_UNORM
&&
574 (stex
->key
.format
== SVGA3D_B8G8R8X8_UNORM
||
575 stex
->key
.format
== SVGA3D_B8G8R8X8_TYPELESS
)) {
576 view_format
= SVGA3D_B8G8R8X8_UNORM
;
579 ret
= SVGA3D_vgpu10_DefineRenderTargetView(svga
->swc
,
587 if (ret
!= PIPE_OK
) {
588 util_bitmask_clear(svga
->surface_view_id_bm
, s
->view_id
);
589 s
->view_id
= SVGA3D_INVALID_ID
;
594 SVGA_STATS_TIME_POP(svga_sws(svga
));
596 return s
? &s
->base
: NULL
;
602 svga_surface_destroy(struct pipe_context
*pipe
,
603 struct pipe_surface
*surf
)
605 struct svga_context
*svga
= svga_context(pipe
);
606 struct svga_surface
*s
= svga_surface(surf
);
607 struct svga_texture
*t
= svga_texture(surf
->texture
);
608 struct svga_screen
*ss
= svga_screen(surf
->texture
->screen
);
609 enum pipe_error ret
= PIPE_OK
;
611 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_DESTROYSURFACE
);
613 /* Destroy the backed view surface if it exists */
615 svga_surface_destroy(pipe
, &s
->backed
->base
);
619 /* Destroy the surface handle if this is a backed handle and
620 * it is not being cached in the texture.
622 if (s
->handle
!= t
->handle
&& s
->handle
!= t
->backed_handle
) {
623 SVGA_DBG(DEBUG_DMA
, "unref sid %p (tex surface)\n", s
->handle
);
624 svga_screen_surface_destroy(ss
, &s
->key
, &s
->handle
);
627 if (s
->view_id
!= SVGA3D_INVALID_ID
) {
630 /* The SVGA3D device will generate a device error if the
631 * render target view or depth stencil view is destroyed from
632 * a context other than the one it was created with.
633 * Similar to shader resource view, in this case, we will skip
634 * the destroy for now.
636 if (surf
->context
!= pipe
) {
637 _debug_printf("context mismatch in %s\n", __func__
);
640 assert(svga_have_vgpu10(svga
));
641 for (try = 0; try < 2; try++) {
642 if (util_format_is_depth_or_stencil(s
->base
.format
)) {
643 ret
= SVGA3D_vgpu10_DestroyDepthStencilView(svga
->swc
, s
->view_id
);
646 ret
= SVGA3D_vgpu10_DestroyRenderTargetView(svga
->swc
, s
->view_id
);
650 svga_context_flush(svga
, NULL
);
652 assert(ret
== PIPE_OK
);
653 util_bitmask_clear(svga
->surface_view_id_bm
, s
->view_id
);
657 pipe_resource_reference(&surf
->texture
, NULL
);
660 svga
->hud
.num_surface_views
--;
661 SVGA_STATS_TIME_POP(ss
->sws
);
666 svga_mark_surface_dirty(struct pipe_surface
*surf
)
668 struct svga_surface
*s
= svga_surface(surf
);
669 struct svga_texture
*tex
= svga_texture(surf
->texture
);
674 if (s
->handle
== tex
->handle
) {
675 /* hmm so 3d textures always have all their slices marked ? */
676 svga_define_texture_level(tex
, surf
->u
.tex
.first_layer
,
680 /* this will happen later in svga_propagate_surface */
684 /* Increment the view_age and texture age for this surface's mipmap
685 * level so that any sampler views into the texture are re-validated too.
686 * Note: we age the texture for backed surface view only when the
687 * backed surface is propagated to the original surface.
689 if (s
->handle
== tex
->handle
)
690 svga_age_texture_view(tex
, surf
->u
.tex
.level
);
695 svga_mark_surfaces_dirty(struct svga_context
*svga
)
698 struct svga_hw_clear_state
*hw
= &svga
->state
.hw_clear
;
700 if (svga_have_vgpu10(svga
)) {
702 /* For VGPU10, mark the dirty bit in the rendertarget/depth stencil view surface.
703 * This surface can be the backed surface.
705 for (i
= 0; i
< hw
->num_rendertargets
; i
++) {
707 svga_mark_surface_dirty(hw
->rtv
[i
]);
710 svga_mark_surface_dirty(hw
->dsv
);
712 for (i
= 0; i
< svga
->curr
.framebuffer
.nr_cbufs
; i
++) {
713 if (svga
->curr
.framebuffer
.cbufs
[i
])
714 svga_mark_surface_dirty(svga
->curr
.framebuffer
.cbufs
[i
]);
716 if (svga
->curr
.framebuffer
.zsbuf
)
717 svga_mark_surface_dirty(svga
->curr
.framebuffer
.zsbuf
);
723 * Progagate any changes from surfaces to texture.
724 * pipe is optional context to inline the blit command in.
727 svga_propagate_surface(struct svga_context
*svga
, struct pipe_surface
*surf
,
730 struct svga_surface
*s
= svga_surface(surf
);
731 struct svga_texture
*tex
= svga_texture(surf
->texture
);
732 struct svga_screen
*ss
= svga_screen(surf
->texture
->screen
);
737 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_PROPAGATESURFACE
);
739 /* Reset the dirty flag if specified. This is to ensure that
740 * the dirty flag will not be reset and stay unset when the backing
741 * surface is still being bound and rendered to.
742 * The reset flag will be set to TRUE when the surface is propagated
743 * and will be unbound.
747 ss
->texture_timestamp
++;
748 svga_age_texture_view(tex
, surf
->u
.tex
.level
);
750 if (s
->handle
!= tex
->handle
) {
751 unsigned zslice
, layer
;
752 unsigned nlayers
= 1;
755 if (surf
->texture
->target
== PIPE_TEXTURE_CUBE
) {
757 layer
= surf
->u
.tex
.first_layer
;
759 else if (surf
->texture
->target
== PIPE_TEXTURE_1D_ARRAY
||
760 surf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
) {
762 layer
= surf
->u
.tex
.first_layer
;
763 nlayers
= surf
->u
.tex
.last_layer
- surf
->u
.tex
.first_layer
+ 1;
766 zslice
= surf
->u
.tex
.first_layer
;
770 SVGA_DBG(DEBUG_VIEWS
,
771 "Propagate surface %p to resource %p, level %u\n",
772 surf
, tex
, surf
->u
.tex
.level
);
773 for (i
= 0; i
< nlayers
; i
++) {
774 svga_texture_copy_handle(svga
,
775 s
->handle
, 0, 0, 0, s
->real_level
,
777 tex
->handle
, 0, 0, zslice
, surf
->u
.tex
.level
,
779 u_minify(tex
->b
.b
.width0
, surf
->u
.tex
.level
),
780 u_minify(tex
->b
.b
.height0
, surf
->u
.tex
.level
),
782 svga_define_texture_level(tex
, layer
+ i
, surf
->u
.tex
.level
);
785 /* Sync the surface view age with the texture age */
788 /* If this backed surface is cached in the texture,
789 * update the backed age as well.
791 if (tex
->backed_handle
== s
->handle
) {
792 tex
->backed_age
= tex
->age
;
796 SVGA_STATS_TIME_POP(ss
->sws
);
801 * If any of the render targets are in backing texture views, propagate any
802 * changes to them back to the original texture.
805 svga_propagate_rendertargets(struct svga_context
*svga
)
809 /* Early exit if there is no backing texture views in use */
810 if (!svga
->state
.hw_draw
.has_backed_views
)
813 /* Note that we examine the svga->state.hw_draw.framebuffer surfaces,
814 * not the svga->curr.framebuffer surfaces, because it's the former
815 * surfaces which may be backing surface views (the actual render targets).
817 for (i
= 0; i
< svga
->state
.hw_clear
.num_rendertargets
; i
++) {
818 struct pipe_surface
*s
= svga
->state
.hw_clear
.rtv
[i
];
820 svga_propagate_surface(svga
, s
, FALSE
);
824 if (svga
->state
.hw_clear
.dsv
) {
825 svga_propagate_surface(svga
, svga
->state
.hw_clear
.dsv
, FALSE
);
831 * Check if we should call svga_propagate_surface on the surface.
834 svga_surface_needs_propagation(const struct pipe_surface
*surf
)
836 const struct svga_surface
*s
= svga_surface_const(surf
);
837 struct svga_texture
*tex
= svga_texture(surf
->texture
);
839 return s
->dirty
&& s
->handle
!= tex
->handle
;
844 svga_get_sample_position(struct pipe_context
*context
,
845 unsigned sample_count
, unsigned sample_index
,
848 /* We can't actually query the device to learn the sample positions.
849 * These were grabbed from nvidia's driver.
851 static const float pos1
[1][2] = {
854 static const float pos4
[4][2] = {
855 { 0.375000, 0.125000 },
856 { 0.875000, 0.375000 },
857 { 0.125000, 0.625000 },
858 { 0.625000, 0.875000 }
860 static const float pos8
[8][2] = {
861 { 0.562500, 0.312500 },
862 { 0.437500, 0.687500 },
863 { 0.812500, 0.562500 },
864 { 0.312500, 0.187500 },
865 { 0.187500, 0.812500 },
866 { 0.062500, 0.437500 },
867 { 0.687500, 0.937500 },
868 { 0.937500, 0.062500 }
870 static const float pos16
[16][2] = {
871 { 0.187500, 0.062500 },
872 { 0.437500, 0.187500 },
873 { 0.062500, 0.312500 },
874 { 0.312500, 0.437500 },
875 { 0.687500, 0.062500 },
876 { 0.937500, 0.187500 },
877 { 0.562500, 0.312500 },
878 { 0.812500, 0.437500 },
879 { 0.187500, 0.562500 },
880 { 0.437500, 0.687500 },
881 { 0.062500, 0.812500 },
882 { 0.312500, 0.937500 },
883 { 0.687500, 0.562500 },
884 { 0.937500, 0.687500 },
885 { 0.562500, 0.812500 },
886 { 0.812500, 0.937500 }
888 const float (*positions
)[2];
890 switch (sample_count
) {
904 pos_out
[0] = positions
[sample_index
][0];
905 pos_out
[1] = positions
[sample_index
][1];
910 svga_init_surface_functions(struct svga_context
*svga
)
912 svga
->pipe
.create_surface
= svga_create_surface
;
913 svga
->pipe
.surface_destroy
= svga_surface_destroy
;
914 svga
->pipe
.get_sample_position
= svga_get_sample_position
;