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 pt
->target
== PIPE_TEXTURE_CUBE_ARRAY
) {
281 layer
= surf_tmpl
->u
.tex
.first_layer
;
283 nlayers
= surf_tmpl
->u
.tex
.last_layer
- surf_tmpl
->u
.tex
.first_layer
+ 1;
287 zslice
= surf_tmpl
->u
.tex
.first_layer
;
290 pipe_reference_init(&s
->base
.reference
, 1);
291 pipe_resource_reference(&s
->base
.texture
, pt
);
292 s
->base
.context
= pipe
;
293 s
->base
.format
= surf_tmpl
->format
;
294 s
->base
.width
= u_minify(pt
->width0
, surf_tmpl
->u
.tex
.level
);
295 s
->base
.height
= u_minify(pt
->height0
, surf_tmpl
->u
.tex
.level
);
296 s
->base
.u
.tex
.level
= surf_tmpl
->u
.tex
.level
;
297 s
->base
.u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
298 s
->base
.u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
299 s
->view_id
= SVGA3D_INVALID_ID
;
303 if (util_format_is_depth_or_stencil(surf_tmpl
->format
)) {
304 flags
= SVGA3D_SURFACE_HINT_DEPTHSTENCIL
|
305 SVGA3D_SURFACE_BIND_DEPTH_STENCIL
;
306 bind
= PIPE_BIND_DEPTH_STENCIL
;
309 flags
= SVGA3D_SURFACE_HINT_RENDERTARGET
|
310 SVGA3D_SURFACE_BIND_RENDER_TARGET
;
311 bind
= PIPE_BIND_RENDER_TARGET
;
315 /* imported resource (a window) */
316 format
= tex
->key
.format
;
317 if (util_format_is_srgb(surf_tmpl
->format
)) {
318 /* sRGB rendering to window */
319 format
= svga_linear_to_srgb(format
);
323 format
= svga_translate_format(ss
, surf_tmpl
->format
, bind
);
326 assert(format
!= SVGA3D_FORMAT_INVALID
);
329 SVGA_DBG(DEBUG_VIEWS
,
330 "New backed surface view: resource %p, level %u layer %u z %u, %p\n",
331 pt
, surf_tmpl
->u
.tex
.level
, layer
, zslice
, s
);
333 if (svga_have_vgpu10(svga
)) {
334 switch (pt
->target
) {
335 case PIPE_TEXTURE_1D
:
336 flags
|= SVGA3D_SURFACE_1D
;
338 case PIPE_TEXTURE_1D_ARRAY
:
339 flags
|= SVGA3D_SURFACE_1D
| SVGA3D_SURFACE_ARRAY
;
341 case PIPE_TEXTURE_2D_ARRAY
:
342 flags
|= SVGA3D_SURFACE_ARRAY
;
344 case PIPE_TEXTURE_3D
:
345 flags
|= SVGA3D_SURFACE_VOLUME
;
347 case PIPE_TEXTURE_CUBE
:
349 flags
|= SVGA3D_SURFACE_CUBEMAP
;
351 case PIPE_TEXTURE_CUBE_ARRAY
:
352 flags
|= SVGA3D_SURFACE_CUBEMAP
| SVGA3D_SURFACE_ARRAY
;
359 /* When we clone the surface view resource, use the format used in
360 * the creation of the original resource.
362 s
->handle
= svga_texture_view_surface(svga
, tex
, bind
, flags
,
364 surf_tmpl
->u
.tex
.level
, 1,
365 layer
, nlayers
, zslice
,
372 s
->key
.format
= format
;
377 SVGA_DBG(DEBUG_VIEWS
,
378 "New surface view: resource %p, level %u, layer %u, z %u, %p\n",
379 pt
, surf_tmpl
->u
.tex
.level
, layer
, zslice
, s
);
381 memset(&s
->key
, 0, sizeof s
->key
);
382 s
->key
.format
= format
;
383 s
->handle
= tex
->handle
;
384 s
->real_layer
= layer
;
385 s
->real_zslice
= zslice
;
386 s
->real_level
= surf_tmpl
->u
.tex
.level
;
389 svga
->hud
.num_surface_views
++;
393 SVGA_STATS_TIME_POP(ss
->sws
);
398 static struct pipe_surface
*
399 svga_create_surface(struct pipe_context
*pipe
,
400 struct pipe_resource
*pt
,
401 const struct pipe_surface
*surf_tmpl
)
403 struct svga_context
*svga
= svga_context(pipe
);
404 struct pipe_screen
*screen
= pipe
->screen
;
405 struct pipe_surface
*surf
= NULL
;
406 boolean view
= FALSE
;
408 SVGA_STATS_TIME_PUSH(svga_sws(svga
), SVGA_STATS_TIME_CREATESURFACE
);
410 if (svga_screen(screen
)->debug
.force_surface_view
)
413 if (surf_tmpl
->u
.tex
.level
!= 0 &&
414 svga_screen(screen
)->debug
.force_level_surface_view
)
417 if (pt
->target
== PIPE_TEXTURE_3D
)
420 if (svga_have_vgpu10(svga
) || svga_screen(screen
)->debug
.no_surface_view
)
423 surf
= svga_create_surface_view(pipe
, pt
, surf_tmpl
, view
);
425 SVGA_STATS_TIME_POP(svga_sws(svga
));
432 * Clone the surface view and its associated resource.
434 static struct svga_surface
*
435 create_backed_surface_view(struct svga_context
*svga
, struct svga_surface
*s
)
437 struct svga_texture
*tex
= svga_texture(s
->base
.texture
);
440 struct pipe_surface
*backed_view
;
442 SVGA_STATS_TIME_PUSH(svga_sws(svga
),
443 SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW
);
445 backed_view
= svga_create_surface_view(&svga
->pipe
,
452 s
->backed
= svga_surface(backed_view
);
454 SVGA_STATS_TIME_POP(svga_sws(svga
));
456 else if (s
->backed
->age
< tex
->age
) {
458 * There is already an existing backing surface, but we still need to
459 * sync the backing resource if the original resource has been modified
460 * since the last copy.
462 struct svga_surface
*bs
= s
->backed
;
463 unsigned int layer
, zslice
;
467 switch (tex
->b
.b
.target
) {
468 case PIPE_TEXTURE_CUBE
:
469 case PIPE_TEXTURE_1D_ARRAY
:
470 case PIPE_TEXTURE_2D_ARRAY
:
471 layer
= s
->base
.u
.tex
.first_layer
;
476 zslice
= s
->base
.u
.tex
.first_layer
;
479 svga_texture_copy_handle_resource(svga
, tex
, bs
->handle
,
480 bs
->key
.numMipLevels
,
481 bs
->key
.numFaces
* bs
->key
.arraySize
,
482 zslice
, s
->base
.u
.tex
.level
, layer
);
485 svga_mark_surface_dirty(&s
->backed
->base
);
486 s
->backed
->age
= tex
->age
;
493 * Create a DX RenderTarget/DepthStencil View for the given surface,
496 struct pipe_surface
*
497 svga_validate_surface_view(struct svga_context
*svga
, struct svga_surface
*s
)
499 enum pipe_error ret
= PIPE_OK
;
500 enum pipe_shader_type shader
;
502 assert(svga_have_vgpu10(svga
));
505 SVGA_STATS_TIME_PUSH(svga_sws(svga
),
506 SVGA_STATS_TIME_VALIDATESURFACEVIEW
);
509 * DX spec explicitly specifies that no resource can be bound to a render
510 * target view and a shader resource view simultanously.
511 * So first check if the resource bound to this surface view collides with
512 * a sampler view. If so, then we will clone this surface view and its
513 * associated resource. We will then use the cloned surface view for
516 for (shader
= PIPE_SHADER_VERTEX
; shader
<= PIPE_SHADER_GEOMETRY
; shader
++) {
517 if (svga_check_sampler_view_resource_collision(svga
, s
->handle
, shader
)) {
518 SVGA_DBG(DEBUG_VIEWS
,
519 "same resource used in shaderResource and renderTarget 0x%x\n",
521 s
= create_backed_surface_view(svga
, s
);
524 svga
->state
.hw_draw
.has_backed_views
= TRUE
;
526 /* s may be null here if the function failed */
531 if (s
&& s
->view_id
== SVGA3D_INVALID_ID
) {
532 SVGA3dResourceType resType
;
533 SVGA3dRenderTargetViewDesc desc
;
534 struct svga_texture
*stex
= svga_texture(s
->base
.texture
);
536 if (stex
->validated
== FALSE
) {
537 assert(stex
->handle
);
539 /* We are about to render into a surface that has not been validated.
540 * First invalidate the surface so that the device does not
541 * need to update the host-side copy with the invalid
542 * content when the associated mob is first bound to the surface.
544 if (svga
->swc
->surface_invalidate(svga
->swc
, stex
->handle
) != PIPE_OK
) {
545 svga_context_flush(svga
, NULL
);
546 ret
= svga
->swc
->surface_invalidate(svga
->swc
, stex
->handle
);
547 assert(ret
== PIPE_OK
);
549 stex
->validated
= TRUE
;
552 desc
.tex
.mipSlice
= s
->real_level
;
553 desc
.tex
.firstArraySlice
= s
->real_layer
+ s
->real_zslice
;
555 s
->base
.u
.tex
.last_layer
- s
->base
.u
.tex
.first_layer
+ 1;
557 s
->view_id
= util_bitmask_add(svga
->surface_view_id_bm
);
559 resType
= svga_resource_type(s
->base
.texture
->target
);
561 if (util_format_is_depth_or_stencil(s
->base
.format
)) {
562 ret
= SVGA3D_vgpu10_DefineDepthStencilView(svga
->swc
,
570 SVGA3dSurfaceFormat view_format
= s
->key
.format
;
571 const struct svga_texture
*stex
= svga_texture(s
->base
.texture
);
573 /* Can't create RGBA render target view of a RGBX surface so adjust
574 * the view format. We do something similar for texture samplers in
575 * svga_validate_pipe_sampler_view().
577 if (view_format
== SVGA3D_B8G8R8A8_UNORM
&&
578 (stex
->key
.format
== SVGA3D_B8G8R8X8_UNORM
||
579 stex
->key
.format
== SVGA3D_B8G8R8X8_TYPELESS
)) {
580 view_format
= SVGA3D_B8G8R8X8_UNORM
;
583 ret
= SVGA3D_vgpu10_DefineRenderTargetView(svga
->swc
,
591 if (ret
!= PIPE_OK
) {
592 util_bitmask_clear(svga
->surface_view_id_bm
, s
->view_id
);
593 s
->view_id
= SVGA3D_INVALID_ID
;
598 SVGA_STATS_TIME_POP(svga_sws(svga
));
600 return s
? &s
->base
: NULL
;
606 svga_surface_destroy(struct pipe_context
*pipe
,
607 struct pipe_surface
*surf
)
609 struct svga_context
*svga
= svga_context(pipe
);
610 struct svga_surface
*s
= svga_surface(surf
);
611 struct svga_texture
*t
= svga_texture(surf
->texture
);
612 struct svga_screen
*ss
= svga_screen(surf
->texture
->screen
);
613 enum pipe_error ret
= PIPE_OK
;
615 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_DESTROYSURFACE
);
617 /* Destroy the backed view surface if it exists */
619 svga_surface_destroy(pipe
, &s
->backed
->base
);
623 /* Destroy the surface handle if this is a backed handle and
624 * it is not being cached in the texture.
626 if (s
->handle
!= t
->handle
&& s
->handle
!= t
->backed_handle
) {
627 SVGA_DBG(DEBUG_DMA
, "unref sid %p (tex surface)\n", s
->handle
);
628 svga_screen_surface_destroy(ss
, &s
->key
, &s
->handle
);
631 if (s
->view_id
!= SVGA3D_INVALID_ID
) {
634 /* The SVGA3D device will generate a device error if the
635 * render target view or depth stencil view is destroyed from
636 * a context other than the one it was created with.
637 * Similar to shader resource view, in this case, we will skip
638 * the destroy for now.
640 if (surf
->context
!= pipe
) {
641 _debug_printf("context mismatch in %s\n", __func__
);
644 assert(svga_have_vgpu10(svga
));
645 for (try = 0; try < 2; try++) {
646 if (util_format_is_depth_or_stencil(s
->base
.format
)) {
647 ret
= SVGA3D_vgpu10_DestroyDepthStencilView(svga
->swc
, s
->view_id
);
650 ret
= SVGA3D_vgpu10_DestroyRenderTargetView(svga
->swc
, s
->view_id
);
654 svga_context_flush(svga
, NULL
);
656 assert(ret
== PIPE_OK
);
657 util_bitmask_clear(svga
->surface_view_id_bm
, s
->view_id
);
661 pipe_resource_reference(&surf
->texture
, NULL
);
664 svga
->hud
.num_surface_views
--;
665 SVGA_STATS_TIME_POP(ss
->sws
);
670 svga_mark_surface_dirty(struct pipe_surface
*surf
)
672 struct svga_surface
*s
= svga_surface(surf
);
673 struct svga_texture
*tex
= svga_texture(surf
->texture
);
678 if (s
->handle
== tex
->handle
) {
679 /* hmm so 3d textures always have all their slices marked ? */
680 svga_define_texture_level(tex
, surf
->u
.tex
.first_layer
,
684 /* this will happen later in svga_propagate_surface */
688 /* Increment the view_age and texture age for this surface's mipmap
689 * level so that any sampler views into the texture are re-validated too.
690 * Note: we age the texture for backed surface view only when the
691 * backed surface is propagated to the original surface.
693 if (s
->handle
== tex
->handle
)
694 svga_age_texture_view(tex
, surf
->u
.tex
.level
);
699 svga_mark_surfaces_dirty(struct svga_context
*svga
)
702 struct svga_hw_clear_state
*hw
= &svga
->state
.hw_clear
;
704 if (svga_have_vgpu10(svga
)) {
706 /* For VGPU10, mark the dirty bit in the rendertarget/depth stencil view surface.
707 * This surface can be the backed surface.
709 for (i
= 0; i
< hw
->num_rendertargets
; i
++) {
711 svga_mark_surface_dirty(hw
->rtv
[i
]);
714 svga_mark_surface_dirty(hw
->dsv
);
716 for (i
= 0; i
< svga
->curr
.framebuffer
.nr_cbufs
; i
++) {
717 if (svga
->curr
.framebuffer
.cbufs
[i
])
718 svga_mark_surface_dirty(svga
->curr
.framebuffer
.cbufs
[i
]);
720 if (svga
->curr
.framebuffer
.zsbuf
)
721 svga_mark_surface_dirty(svga
->curr
.framebuffer
.zsbuf
);
727 * Progagate any changes from surfaces to texture.
728 * pipe is optional context to inline the blit command in.
731 svga_propagate_surface(struct svga_context
*svga
, struct pipe_surface
*surf
,
734 struct svga_surface
*s
= svga_surface(surf
);
735 struct svga_texture
*tex
= svga_texture(surf
->texture
);
736 struct svga_screen
*ss
= svga_screen(surf
->texture
->screen
);
741 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_PROPAGATESURFACE
);
743 /* Reset the dirty flag if specified. This is to ensure that
744 * the dirty flag will not be reset and stay unset when the backing
745 * surface is still being bound and rendered to.
746 * The reset flag will be set to TRUE when the surface is propagated
747 * and will be unbound.
751 ss
->texture_timestamp
++;
752 svga_age_texture_view(tex
, surf
->u
.tex
.level
);
754 if (s
->handle
!= tex
->handle
) {
755 unsigned zslice
, layer
;
756 unsigned nlayers
= 1;
759 if (surf
->texture
->target
== PIPE_TEXTURE_CUBE
) {
761 layer
= surf
->u
.tex
.first_layer
;
763 else if (surf
->texture
->target
== PIPE_TEXTURE_1D_ARRAY
||
764 surf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
) {
766 layer
= surf
->u
.tex
.first_layer
;
767 nlayers
= surf
->u
.tex
.last_layer
- surf
->u
.tex
.first_layer
+ 1;
770 zslice
= surf
->u
.tex
.first_layer
;
774 SVGA_DBG(DEBUG_VIEWS
,
775 "Propagate surface %p to resource %p, level %u\n",
776 surf
, tex
, surf
->u
.tex
.level
);
777 for (i
= 0; i
< nlayers
; i
++) {
778 svga_texture_copy_handle(svga
,
779 s
->handle
, 0, 0, 0, s
->real_level
,
781 tex
->handle
, 0, 0, zslice
, surf
->u
.tex
.level
,
783 u_minify(tex
->b
.b
.width0
, surf
->u
.tex
.level
),
784 u_minify(tex
->b
.b
.height0
, surf
->u
.tex
.level
),
786 svga_define_texture_level(tex
, layer
+ i
, surf
->u
.tex
.level
);
789 /* Sync the surface view age with the texture age */
792 /* If this backed surface is cached in the texture,
793 * update the backed age as well.
795 if (tex
->backed_handle
== s
->handle
) {
796 tex
->backed_age
= tex
->age
;
800 SVGA_STATS_TIME_POP(ss
->sws
);
805 * If any of the render targets are in backing texture views, propagate any
806 * changes to them back to the original texture.
809 svga_propagate_rendertargets(struct svga_context
*svga
)
813 /* Early exit if there is no backing texture views in use */
814 if (!svga
->state
.hw_draw
.has_backed_views
)
817 /* Note that we examine the svga->state.hw_draw.framebuffer surfaces,
818 * not the svga->curr.framebuffer surfaces, because it's the former
819 * surfaces which may be backing surface views (the actual render targets).
821 for (i
= 0; i
< svga
->state
.hw_clear
.num_rendertargets
; i
++) {
822 struct pipe_surface
*s
= svga
->state
.hw_clear
.rtv
[i
];
824 svga_propagate_surface(svga
, s
, FALSE
);
828 if (svga
->state
.hw_clear
.dsv
) {
829 svga_propagate_surface(svga
, svga
->state
.hw_clear
.dsv
, FALSE
);
835 * Check if we should call svga_propagate_surface on the surface.
838 svga_surface_needs_propagation(const struct pipe_surface
*surf
)
840 const struct svga_surface
*s
= svga_surface_const(surf
);
841 struct svga_texture
*tex
= svga_texture(surf
->texture
);
843 return s
->dirty
&& s
->handle
!= tex
->handle
;
848 svga_get_sample_position(struct pipe_context
*context
,
849 unsigned sample_count
, unsigned sample_index
,
852 /* We can't actually query the device to learn the sample positions.
853 * These were grabbed from nvidia's driver.
855 static const float pos1
[1][2] = {
858 static const float pos4
[4][2] = {
859 { 0.375000, 0.125000 },
860 { 0.875000, 0.375000 },
861 { 0.125000, 0.625000 },
862 { 0.625000, 0.875000 }
864 static const float pos8
[8][2] = {
865 { 0.562500, 0.312500 },
866 { 0.437500, 0.687500 },
867 { 0.812500, 0.562500 },
868 { 0.312500, 0.187500 },
869 { 0.187500, 0.812500 },
870 { 0.062500, 0.437500 },
871 { 0.687500, 0.937500 },
872 { 0.937500, 0.062500 }
874 static const float pos16
[16][2] = {
875 { 0.187500, 0.062500 },
876 { 0.437500, 0.187500 },
877 { 0.062500, 0.312500 },
878 { 0.312500, 0.437500 },
879 { 0.687500, 0.062500 },
880 { 0.937500, 0.187500 },
881 { 0.562500, 0.312500 },
882 { 0.812500, 0.437500 },
883 { 0.187500, 0.562500 },
884 { 0.437500, 0.687500 },
885 { 0.062500, 0.812500 },
886 { 0.312500, 0.937500 },
887 { 0.687500, 0.562500 },
888 { 0.937500, 0.687500 },
889 { 0.562500, 0.812500 },
890 { 0.812500, 0.937500 }
892 const float (*positions
)[2];
894 switch (sample_count
) {
908 pos_out
[0] = positions
[sample_index
][0];
909 pos_out
[1] = positions
[sample_index
][1];
914 svga_init_surface_functions(struct svga_context
*svga
)
916 svga
->pipe
.create_surface
= svga_create_surface
;
917 svga
->pipe
.surface_destroy
= svga_surface_destroy
;
918 svga
->pipe
.get_sample_position
= svga_get_sample_position
;