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 SVGA3dSurfaceFlags 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
;
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);
174 key
->format
= format
;
175 key
->numMipLevels
= num_mip
;
176 key
->size
.width
= u_minify(tex
->b
.b
.width0
, start_mip
);
177 key
->size
.height
= u_minify(tex
->b
.b
.height0
, start_mip
);
178 key
->size
.depth
= zslice_pick
< 0 ? u_minify(tex
->b
.b
.depth0
, start_mip
) : 1;
183 /* single sample surface can be treated as non-multisamples surface */
184 key
->sampleCount
= tex
->b
.b
.nr_samples
> 1 ? tex
->b
.b
.nr_samples
: 0;
186 if (key
->sampleCount
> 1) {
187 key
->flags
|= SVGA3D_SURFACE_MASKABLE_ANTIALIAS
;
190 if (tex
->b
.b
.target
== PIPE_TEXTURE_CUBE
&& layer_pick
< 0) {
191 key
->flags
|= SVGA3D_SURFACE_CUBEMAP
;
193 } else if (tex
->b
.b
.target
== PIPE_TEXTURE_1D_ARRAY
||
194 tex
->b
.b
.target
== PIPE_TEXTURE_2D_ARRAY
) {
195 key
->arraySize
= num_layers
;
198 if (key
->format
== SVGA3D_FORMAT_INVALID
) {
203 if (cacheable
&& tex
->backed_handle
&&
204 memcmp(key
, &tex
->backed_key
, sizeof *key
) == 0) {
205 handle
= tex
->backed_handle
;
206 needCopyResource
= tex
->backed_age
< tex
->age
;
208 SVGA_DBG(DEBUG_DMA
, "surface_create for texture view\n");
209 handle
= svga_screen_surface_create(ss
, bind_flags
, PIPE_USAGE_DEFAULT
,
211 needCopyResource
= TRUE
;
213 if (cacheable
&& !tex
->backed_handle
) {
214 tex
->backed_handle
= handle
;
215 memcpy(&tex
->backed_key
, key
, sizeof *key
);
224 SVGA_DBG(DEBUG_DMA
, " --> got sid %p (texture view)\n", handle
);
229 if (needCopyResource
) {
230 svga_texture_copy_handle_resource(svga
, tex
, handle
,
232 key
->numFaces
* key
->arraySize
,
233 zslice_pick
, start_mip
, layer_pick
);
234 tex
->backed_age
= tex
->age
;
242 * A helper function to create a surface view.
243 * The view boolean flag specifies whether svga_texture_view_surface()
244 * will be called to create a cloned surface and resource for the view.
246 static struct pipe_surface
*
247 svga_create_surface_view(struct pipe_context
*pipe
,
248 struct pipe_resource
*pt
,
249 const struct pipe_surface
*surf_tmpl
,
252 struct svga_context
*svga
= svga_context(pipe
);
253 struct svga_texture
*tex
= svga_texture(pt
);
254 struct pipe_screen
*screen
= pipe
->screen
;
255 struct svga_screen
*ss
= svga_screen(screen
);
256 struct svga_surface
*s
;
257 unsigned layer
, zslice
, bind
;
258 unsigned nlayers
= 1;
259 SVGA3dSurfaceFlags flags
= 0;
260 SVGA3dSurfaceFormat format
;
261 struct pipe_surface
*retVal
= NULL
;
263 s
= CALLOC_STRUCT(svga_surface
);
267 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_CREATESURFACEVIEW
);
269 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
270 layer
= surf_tmpl
->u
.tex
.first_layer
;
273 else if (pt
->target
== PIPE_TEXTURE_1D_ARRAY
||
274 pt
->target
== PIPE_TEXTURE_2D_ARRAY
) {
275 layer
= surf_tmpl
->u
.tex
.first_layer
;
277 nlayers
= surf_tmpl
->u
.tex
.last_layer
- surf_tmpl
->u
.tex
.first_layer
+ 1;
281 zslice
= surf_tmpl
->u
.tex
.first_layer
;
284 pipe_reference_init(&s
->base
.reference
, 1);
285 pipe_resource_reference(&s
->base
.texture
, pt
);
286 s
->base
.context
= pipe
;
287 s
->base
.format
= surf_tmpl
->format
;
288 s
->base
.width
= u_minify(pt
->width0
, surf_tmpl
->u
.tex
.level
);
289 s
->base
.height
= u_minify(pt
->height0
, surf_tmpl
->u
.tex
.level
);
290 s
->base
.u
.tex
.level
= surf_tmpl
->u
.tex
.level
;
291 s
->base
.u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
292 s
->base
.u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
293 s
->view_id
= SVGA3D_INVALID_ID
;
297 if (util_format_is_depth_or_stencil(surf_tmpl
->format
)) {
298 flags
= SVGA3D_SURFACE_HINT_DEPTHSTENCIL
|
299 SVGA3D_SURFACE_BIND_DEPTH_STENCIL
;
300 bind
= PIPE_BIND_DEPTH_STENCIL
;
303 flags
= SVGA3D_SURFACE_HINT_RENDERTARGET
|
304 SVGA3D_SURFACE_BIND_RENDER_TARGET
;
305 bind
= PIPE_BIND_RENDER_TARGET
;
309 /* imported resource (a window) */
310 format
= tex
->key
.format
;
311 if (util_format_is_srgb(surf_tmpl
->format
)) {
312 /* sRGB rendering to window */
313 format
= svga_linear_to_srgb(format
);
317 format
= svga_translate_format(ss
, surf_tmpl
->format
, bind
);
320 assert(format
!= SVGA3D_FORMAT_INVALID
);
323 SVGA_DBG(DEBUG_VIEWS
,
324 "New backed surface view: resource %p, level %u layer %u z %u, %p\n",
325 pt
, surf_tmpl
->u
.tex
.level
, layer
, zslice
, s
);
327 if (svga_have_vgpu10(svga
)) {
328 switch (pt
->target
) {
329 case PIPE_TEXTURE_1D
:
330 flags
|= SVGA3D_SURFACE_1D
;
332 case PIPE_TEXTURE_1D_ARRAY
:
333 flags
|= SVGA3D_SURFACE_1D
| SVGA3D_SURFACE_ARRAY
;
335 case PIPE_TEXTURE_2D_ARRAY
:
336 flags
|= SVGA3D_SURFACE_ARRAY
;
338 case PIPE_TEXTURE_3D
:
339 flags
|= SVGA3D_SURFACE_VOLUME
;
341 case PIPE_TEXTURE_CUBE
:
343 flags
|= SVGA3D_SURFACE_CUBEMAP
;
350 /* When we clone the surface view resource, use the format used in
351 * the creation of the original resource.
353 s
->handle
= svga_texture_view_surface(svga
, tex
, bind
, flags
,
355 surf_tmpl
->u
.tex
.level
, 1,
356 layer
, nlayers
, zslice
,
363 s
->key
.format
= format
;
368 SVGA_DBG(DEBUG_VIEWS
,
369 "New surface view: resource %p, level %u, layer %u, z %u, %p\n",
370 pt
, surf_tmpl
->u
.tex
.level
, layer
, zslice
, s
);
372 memset(&s
->key
, 0, sizeof s
->key
);
373 s
->key
.format
= format
;
374 s
->handle
= tex
->handle
;
375 s
->real_layer
= layer
;
376 s
->real_zslice
= zslice
;
377 s
->real_level
= surf_tmpl
->u
.tex
.level
;
380 svga
->hud
.num_surface_views
++;
384 SVGA_STATS_TIME_POP(ss
->sws
);
389 static struct pipe_surface
*
390 svga_create_surface(struct pipe_context
*pipe
,
391 struct pipe_resource
*pt
,
392 const struct pipe_surface
*surf_tmpl
)
394 struct svga_context
*svga
= svga_context(pipe
);
395 struct pipe_screen
*screen
= pipe
->screen
;
396 struct pipe_surface
*surf
= NULL
;
397 boolean view
= FALSE
;
399 SVGA_STATS_TIME_PUSH(svga_sws(svga
), SVGA_STATS_TIME_CREATESURFACE
);
401 if (svga_screen(screen
)->debug
.force_surface_view
)
404 if (surf_tmpl
->u
.tex
.level
!= 0 &&
405 svga_screen(screen
)->debug
.force_level_surface_view
)
408 if (pt
->target
== PIPE_TEXTURE_3D
)
411 if (svga_have_vgpu10(svga
) || svga_screen(screen
)->debug
.no_surface_view
)
414 surf
= svga_create_surface_view(pipe
, pt
, surf_tmpl
, view
);
416 SVGA_STATS_TIME_POP(svga_sws(svga
));
423 * Clone the surface view and its associated resource.
425 static struct svga_surface
*
426 create_backed_surface_view(struct svga_context
*svga
, struct svga_surface
*s
)
428 struct svga_texture
*tex
= svga_texture(s
->base
.texture
);
430 SVGA_STATS_TIME_PUSH(svga_sws(svga
),
431 SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW
);
434 struct pipe_surface
*backed_view
;
436 backed_view
= svga_create_surface_view(&svga
->pipe
,
443 s
->backed
= svga_surface(backed_view
);
445 else if (s
->backed
->age
< tex
->age
) {
447 * There is already an existing backing surface, but we still need to
448 * sync the backing resource if the original resource has been modified
449 * since the last copy.
451 struct svga_surface
*bs
= s
->backed
;
452 unsigned int layer
, zslice
;
456 switch (tex
->b
.b
.target
) {
457 case PIPE_TEXTURE_CUBE
:
458 case PIPE_TEXTURE_1D_ARRAY
:
459 case PIPE_TEXTURE_2D_ARRAY
:
460 layer
= s
->base
.u
.tex
.first_layer
;
465 zslice
= s
->base
.u
.tex
.first_layer
;
468 svga_texture_copy_handle_resource(svga
, tex
, bs
->handle
,
469 bs
->key
.numMipLevels
,
470 bs
->key
.numFaces
* bs
->key
.arraySize
,
471 zslice
, s
->base
.u
.tex
.level
, layer
);
474 svga_mark_surface_dirty(&s
->backed
->base
);
475 s
->backed
->age
= tex
->age
;
477 SVGA_STATS_TIME_POP(svga_sws(svga
));
483 * Create a DX RenderTarget/DepthStencil View for the given surface,
486 struct pipe_surface
*
487 svga_validate_surface_view(struct svga_context
*svga
, struct svga_surface
*s
)
489 enum pipe_error ret
= PIPE_OK
;
490 enum pipe_shader_type shader
;
492 assert(svga_have_vgpu10(svga
));
495 SVGA_STATS_TIME_PUSH(svga_sws(svga
),
496 SVGA_STATS_TIME_VALIDATESURFACEVIEW
);
499 * DX spec explicitly specifies that no resource can be bound to a render
500 * target view and a shader resource view simultanously.
501 * So first check if the resource bound to this surface view collides with
502 * a sampler view. If so, then we will clone this surface view and its
503 * associated resource. We will then use the cloned surface view for
506 for (shader
= PIPE_SHADER_VERTEX
; shader
<= PIPE_SHADER_GEOMETRY
; shader
++) {
507 if (svga_check_sampler_view_resource_collision(svga
, s
->handle
, shader
)) {
508 SVGA_DBG(DEBUG_VIEWS
,
509 "same resource used in shaderResource and renderTarget 0x%x\n",
511 s
= create_backed_surface_view(svga
, s
);
514 svga
->state
.hw_draw
.has_backed_views
= TRUE
;
516 /* s may be null here if the function failed */
521 if (s
&& s
->view_id
== SVGA3D_INVALID_ID
) {
522 SVGA3dResourceType resType
;
523 SVGA3dRenderTargetViewDesc desc
;
524 struct svga_texture
*stex
= svga_texture(s
->base
.texture
);
526 if (stex
->validated
== FALSE
) {
527 assert(stex
->handle
);
529 /* We are about to render into a surface that has not been validated.
530 * First invalidate the surface so that the device does not
531 * need to update the host-side copy with the invalid
532 * content when the associated mob is first bound to the surface.
534 svga
->swc
->surface_invalidate(svga
->swc
, stex
->handle
);
535 stex
->validated
= TRUE
;
538 desc
.tex
.mipSlice
= s
->real_level
;
539 desc
.tex
.firstArraySlice
= s
->real_layer
+ s
->real_zslice
;
541 s
->base
.u
.tex
.last_layer
- s
->base
.u
.tex
.first_layer
+ 1;
543 s
->view_id
= util_bitmask_add(svga
->surface_view_id_bm
);
545 resType
= svga_resource_type(s
->base
.texture
->target
);
547 if (util_format_is_depth_or_stencil(s
->base
.format
)) {
548 ret
= SVGA3D_vgpu10_DefineDepthStencilView(svga
->swc
,
556 SVGA3dSurfaceFormat view_format
= s
->key
.format
;
557 const struct svga_texture
*stex
= svga_texture(s
->base
.texture
);
559 /* Can't create RGBA render target view of a RGBX surface so adjust
560 * the view format. We do something similar for texture samplers in
561 * svga_validate_pipe_sampler_view().
563 if (view_format
== SVGA3D_B8G8R8A8_UNORM
&&
564 (stex
->key
.format
== SVGA3D_B8G8R8X8_UNORM
||
565 stex
->key
.format
== SVGA3D_B8G8R8X8_TYPELESS
)) {
566 view_format
= SVGA3D_B8G8R8X8_UNORM
;
569 ret
= SVGA3D_vgpu10_DefineRenderTargetView(svga
->swc
,
577 if (ret
!= PIPE_OK
) {
578 util_bitmask_clear(svga
->surface_view_id_bm
, s
->view_id
);
579 s
->view_id
= SVGA3D_INVALID_ID
;
584 SVGA_STATS_TIME_POP(svga_sws(svga
));
586 return s
? &s
->base
: NULL
;
592 svga_surface_destroy(struct pipe_context
*pipe
,
593 struct pipe_surface
*surf
)
595 struct svga_context
*svga
= svga_context(pipe
);
596 struct svga_surface
*s
= svga_surface(surf
);
597 struct svga_texture
*t
= svga_texture(surf
->texture
);
598 struct svga_screen
*ss
= svga_screen(surf
->texture
->screen
);
599 enum pipe_error ret
= PIPE_OK
;
601 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_DESTROYSURFACE
);
603 /* Destroy the backed view surface if it exists */
605 svga_surface_destroy(pipe
, &s
->backed
->base
);
609 /* Destroy the surface handle if this is a backed handle and
610 * it is not being cached in the texture.
612 if (s
->handle
!= t
->handle
&& s
->handle
!= t
->backed_handle
) {
613 SVGA_DBG(DEBUG_DMA
, "unref sid %p (tex surface)\n", s
->handle
);
614 svga_screen_surface_destroy(ss
, &s
->key
, &s
->handle
);
617 if (s
->view_id
!= SVGA3D_INVALID_ID
) {
620 /* The SVGA3D device will generate a device error if the
621 * render target view or depth stencil view is destroyed from
622 * a context other than the one it was created with.
623 * Similar to shader resource view, in this case, we will skip
624 * the destroy for now.
626 if (surf
->context
!= pipe
) {
627 _debug_printf("context mismatch in %s\n", __func__
);
630 assert(svga_have_vgpu10(svga
));
631 for (try = 0; try < 2; try++) {
632 if (util_format_is_depth_or_stencil(s
->base
.format
)) {
633 ret
= SVGA3D_vgpu10_DestroyDepthStencilView(svga
->swc
, s
->view_id
);
636 ret
= SVGA3D_vgpu10_DestroyRenderTargetView(svga
->swc
, s
->view_id
);
640 svga_context_flush(svga
, NULL
);
642 assert(ret
== PIPE_OK
);
643 util_bitmask_clear(svga
->surface_view_id_bm
, s
->view_id
);
647 pipe_resource_reference(&surf
->texture
, NULL
);
650 svga
->hud
.num_surface_views
--;
651 SVGA_STATS_TIME_POP(ss
->sws
);
656 svga_mark_surface_dirty(struct pipe_surface
*surf
)
658 struct svga_surface
*s
= svga_surface(surf
);
659 struct svga_texture
*tex
= svga_texture(surf
->texture
);
664 if (s
->handle
== tex
->handle
) {
665 /* hmm so 3d textures always have all their slices marked ? */
666 svga_define_texture_level(tex
, surf
->u
.tex
.first_layer
,
670 /* this will happen later in svga_propagate_surface */
674 /* Increment the view_age and texture age for this surface's mipmap
675 * level so that any sampler views into the texture are re-validated too.
676 * Note: we age the texture for backed surface view only when the
677 * backed surface is propagated to the original surface.
679 if (s
->handle
== tex
->handle
)
680 svga_age_texture_view(tex
, surf
->u
.tex
.level
);
685 svga_mark_surfaces_dirty(struct svga_context
*svga
)
688 struct svga_hw_clear_state
*hw
= &svga
->state
.hw_clear
;
690 if (svga_have_vgpu10(svga
)) {
692 /* For VGPU10, mark the dirty bit in the rendertarget/depth stencil view surface.
693 * This surface can be the backed surface.
695 for (i
= 0; i
< hw
->num_rendertargets
; i
++) {
697 svga_mark_surface_dirty(hw
->rtv
[i
]);
700 svga_mark_surface_dirty(hw
->dsv
);
702 for (i
= 0; i
< svga
->curr
.framebuffer
.nr_cbufs
; i
++) {
703 if (svga
->curr
.framebuffer
.cbufs
[i
])
704 svga_mark_surface_dirty(svga
->curr
.framebuffer
.cbufs
[i
]);
706 if (svga
->curr
.framebuffer
.zsbuf
)
707 svga_mark_surface_dirty(svga
->curr
.framebuffer
.zsbuf
);
713 * Progagate any changes from surfaces to texture.
714 * pipe is optional context to inline the blit command in.
717 svga_propagate_surface(struct svga_context
*svga
, struct pipe_surface
*surf
,
720 struct svga_surface
*s
= svga_surface(surf
);
721 struct svga_texture
*tex
= svga_texture(surf
->texture
);
722 struct svga_screen
*ss
= svga_screen(surf
->texture
->screen
);
727 SVGA_STATS_TIME_PUSH(ss
->sws
, SVGA_STATS_TIME_PROPAGATESURFACE
);
729 /* Reset the dirty flag if specified. This is to ensure that
730 * the dirty flag will not be reset and stay unset when the backing
731 * surface is still being bound and rendered to.
732 * The reset flag will be set to TRUE when the surface is propagated
733 * and will be unbound.
737 ss
->texture_timestamp
++;
738 svga_age_texture_view(tex
, surf
->u
.tex
.level
);
740 if (s
->handle
!= tex
->handle
) {
741 unsigned zslice
, layer
;
742 unsigned nlayers
= 1;
745 if (surf
->texture
->target
== PIPE_TEXTURE_CUBE
) {
747 layer
= surf
->u
.tex
.first_layer
;
749 else if (surf
->texture
->target
== PIPE_TEXTURE_1D_ARRAY
||
750 surf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
) {
752 layer
= surf
->u
.tex
.first_layer
;
753 nlayers
= surf
->u
.tex
.last_layer
- surf
->u
.tex
.first_layer
+ 1;
756 zslice
= surf
->u
.tex
.first_layer
;
760 SVGA_DBG(DEBUG_VIEWS
,
761 "Propagate surface %p to resource %p, level %u\n",
762 surf
, tex
, surf
->u
.tex
.level
);
763 for (i
= 0; i
< nlayers
; i
++) {
764 svga_texture_copy_handle(svga
,
765 s
->handle
, 0, 0, 0, s
->real_level
,
767 tex
->handle
, 0, 0, zslice
, surf
->u
.tex
.level
,
769 u_minify(tex
->b
.b
.width0
, surf
->u
.tex
.level
),
770 u_minify(tex
->b
.b
.height0
, surf
->u
.tex
.level
),
772 svga_define_texture_level(tex
, layer
+ i
, surf
->u
.tex
.level
);
775 /* Sync the surface view age with the texture age */
778 /* If this backed surface is cached in the texture,
779 * update the backed age as well.
781 if (tex
->backed_handle
== s
->handle
) {
782 tex
->backed_age
= tex
->age
;
786 SVGA_STATS_TIME_POP(ss
->sws
);
791 * If any of the render targets are in backing texture views, propagate any
792 * changes to them back to the original texture.
795 svga_propagate_rendertargets(struct svga_context
*svga
)
799 /* Early exit if there is no backing texture views in use */
800 if (!svga
->state
.hw_draw
.has_backed_views
)
803 /* Note that we examine the svga->state.hw_draw.framebuffer surfaces,
804 * not the svga->curr.framebuffer surfaces, because it's the former
805 * surfaces which may be backing surface views (the actual render targets).
807 for (i
= 0; i
< svga
->state
.hw_clear
.num_rendertargets
; i
++) {
808 struct pipe_surface
*s
= svga
->state
.hw_clear
.rtv
[i
];
810 svga_propagate_surface(svga
, s
, FALSE
);
814 if (svga
->state
.hw_clear
.dsv
) {
815 svga_propagate_surface(svga
, svga
->state
.hw_clear
.dsv
, FALSE
);
821 * Check if we should call svga_propagate_surface on the surface.
824 svga_surface_needs_propagation(const struct pipe_surface
*surf
)
826 const struct svga_surface
*s
= svga_surface_const(surf
);
827 struct svga_texture
*tex
= svga_texture(surf
->texture
);
829 return s
->dirty
&& s
->handle
!= tex
->handle
;
834 svga_get_sample_position(struct pipe_context
*context
,
835 unsigned sample_count
, unsigned sample_index
,
838 /* We can't actually query the device to learn the sample positions.
839 * These were grabbed from nvidia's driver.
841 static const float pos1
[1][2] = {
844 static const float pos4
[4][2] = {
845 { 0.375000, 0.125000 },
846 { 0.875000, 0.375000 },
847 { 0.125000, 0.625000 },
848 { 0.625000, 0.875000 }
850 static const float pos8
[8][2] = {
851 { 0.562500, 0.312500 },
852 { 0.437500, 0.687500 },
853 { 0.812500, 0.562500 },
854 { 0.312500, 0.187500 },
855 { 0.187500, 0.812500 },
856 { 0.062500, 0.437500 },
857 { 0.687500, 0.937500 },
858 { 0.937500, 0.062500 }
860 static const float pos16
[16][2] = {
861 { 0.187500, 0.062500 },
862 { 0.437500, 0.187500 },
863 { 0.062500, 0.312500 },
864 { 0.312500, 0.437500 },
865 { 0.687500, 0.062500 },
866 { 0.937500, 0.187500 },
867 { 0.562500, 0.312500 },
868 { 0.812500, 0.437500 },
869 { 0.187500, 0.562500 },
870 { 0.437500, 0.687500 },
871 { 0.062500, 0.812500 },
872 { 0.312500, 0.937500 },
873 { 0.687500, 0.562500 },
874 { 0.937500, 0.687500 },
875 { 0.562500, 0.812500 },
876 { 0.812500, 0.937500 }
878 const float (*positions
)[2];
880 switch (sample_count
) {
894 pos_out
[0] = positions
[sample_index
][0];
895 pos_out
[1] = positions
[sample_index
][1];
900 svga_init_surface_functions(struct svga_context
*svga
)
902 svga
->pipe
.create_surface
= svga_create_surface
;
903 svga
->pipe
.surface_destroy
= svga_surface_destroy
;
904 svga
->pipe
.get_sample_position
= svga_get_sample_position
;