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 "util/u_framebuffer.h"
29 #include "util/u_inlines.h"
31 #include "svga_context.h"
32 #include "svga_screen.h"
33 #include "svga_surface.h"
34 #include "svga_resource_texture.h"
37 static void svga_set_scissor_states( struct pipe_context
*pipe
,
39 unsigned num_scissors
,
40 const struct pipe_scissor_state
*scissors
)
42 struct svga_context
*svga
= svga_context(pipe
);
44 memcpy( &svga
->curr
.scissor
, scissors
, sizeof(*scissors
) );
45 svga
->dirty
|= SVGA_NEW_SCISSOR
;
49 static void svga_set_polygon_stipple( struct pipe_context
*pipe
,
50 const struct pipe_poly_stipple
*stipple
)
52 /* overridden by the draw module */
56 void svga_cleanup_framebuffer(struct svga_context
*svga
)
58 struct svga_screen
*svgascreen
= svga_screen(svga
->pipe
.screen
);
59 struct pipe_framebuffer_state
*curr
= &svga
->curr
.framebuffer
;
60 struct pipe_framebuffer_state
*hw
= &svga
->state
.hw_clear
.framebuffer
;
63 for (i
= 0; i
< svgascreen
->max_color_buffers
; i
++) {
64 pipe_surface_reference(&curr
->cbufs
[i
], NULL
);
65 pipe_surface_reference(&hw
->cbufs
[i
], NULL
);
68 pipe_surface_reference(&curr
->zsbuf
, NULL
);
69 pipe_surface_reference(&hw
->zsbuf
, NULL
);
73 #define DEPTH_BIAS_SCALE_FACTOR_D16 ((float)(1<<15))
74 #define DEPTH_BIAS_SCALE_FACTOR_D24S8 ((float)(1<<23))
75 #define DEPTH_BIAS_SCALE_FACTOR_D32 ((float)(1<<31))
78 static void svga_set_framebuffer_state(struct pipe_context
*pipe
,
79 const struct pipe_framebuffer_state
*fb
)
81 struct svga_context
*svga
= svga_context(pipe
);
82 struct pipe_framebuffer_state
*dst
= &svga
->curr
.framebuffer
;
83 boolean propagate
= FALSE
;
86 dst
->width
= fb
->width
;
87 dst
->height
= fb
->height
;
88 dst
->nr_cbufs
= fb
->nr_cbufs
;
90 /* check if we need to propagate any of the target surfaces */
91 for (i
= 0; i
< dst
->nr_cbufs
; i
++) {
92 struct pipe_surface
*s
= i
< fb
->nr_cbufs
? fb
->cbufs
[i
] : NULL
;
93 if (dst
->cbufs
[i
] && dst
->cbufs
[i
] != s
) {
94 if (svga_surface_needs_propagation(dst
->cbufs
[i
])) {
102 /* make sure that drawing calls comes before propagation calls */
103 svga_hwtnl_flush_retry( svga
);
105 for (i
= 0; i
< dst
->nr_cbufs
; i
++) {
106 struct pipe_surface
*s
= i
< fb
->nr_cbufs
? fb
->cbufs
[i
] : NULL
;
107 if (dst
->cbufs
[i
] && dst
->cbufs
[i
] != s
)
108 svga_propagate_surface(svga
, dst
->cbufs
[i
]);
112 /* XXX: Actually the virtual hardware may support rendertargets with
113 * different size, depending on the host API and driver, but since we cannot
114 * know that make no such assumption here. */
115 for(i
= 0; i
< fb
->nr_cbufs
; ++i
) {
116 if (fb
->zsbuf
&& fb
->cbufs
[i
]) {
117 assert(fb
->zsbuf
->width
== fb
->cbufs
[i
]->width
);
118 assert(fb
->zsbuf
->height
== fb
->cbufs
[i
]->height
);
122 util_copy_framebuffer_state(dst
, fb
);
124 /* Set the rendered-to flags */
125 for (i
= 0; i
< dst
->nr_cbufs
; i
++) {
126 struct pipe_surface
*s
= dst
->cbufs
[i
];
128 struct svga_texture
*t
= svga_texture(s
->texture
);
129 svga_set_texture_rendered_to(t
, s
->u
.tex
.first_layer
, s
->u
.tex
.level
);
133 if (svga
->curr
.framebuffer
.zsbuf
)
135 switch (svga
->curr
.framebuffer
.zsbuf
->format
) {
136 case PIPE_FORMAT_Z16_UNORM
:
137 svga
->curr
.depthscale
= 1.0f
/ DEPTH_BIAS_SCALE_FACTOR_D16
;
139 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
140 case PIPE_FORMAT_Z24X8_UNORM
:
141 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
142 case PIPE_FORMAT_X8Z24_UNORM
:
143 svga
->curr
.depthscale
= 1.0f
/ DEPTH_BIAS_SCALE_FACTOR_D24S8
;
145 case PIPE_FORMAT_Z32_UNORM
:
146 svga
->curr
.depthscale
= 1.0f
/ DEPTH_BIAS_SCALE_FACTOR_D32
;
148 case PIPE_FORMAT_Z32_FLOAT
:
149 svga
->curr
.depthscale
= 1.0f
/ ((float)(1<<23));
152 svga
->curr
.depthscale
= 0.0f
;
156 /* Set rendered-to flag */
158 struct pipe_surface
*s
= dst
->zsbuf
;
159 struct svga_texture
*t
= svga_texture(s
->texture
);
160 svga_set_texture_rendered_to(t
, s
->u
.tex
.first_layer
, s
->u
.tex
.level
);
164 svga
->curr
.depthscale
= 0.0f
;
167 svga
->dirty
|= SVGA_NEW_FRAME_BUFFER
;
172 static void svga_set_clip_state( struct pipe_context
*pipe
,
173 const struct pipe_clip_state
*clip
)
175 struct svga_context
*svga
= svga_context(pipe
);
177 svga
->curr
.clip
= *clip
; /* struct copy */
179 svga
->dirty
|= SVGA_NEW_CLIP
;
184 /* Called when driver state tracker notices changes to the viewport
187 static void svga_set_viewport_states( struct pipe_context
*pipe
,
189 unsigned num_viewports
,
190 const struct pipe_viewport_state
*viewports
)
192 struct svga_context
*svga
= svga_context(pipe
);
194 svga
->curr
.viewport
= *viewports
; /* struct copy */
196 svga
->dirty
|= SVGA_NEW_VIEWPORT
;
201 void svga_init_misc_functions( struct svga_context
*svga
)
203 svga
->pipe
.set_scissor_states
= svga_set_scissor_states
;
204 svga
->pipe
.set_polygon_stipple
= svga_set_polygon_stipple
;
205 svga
->pipe
.set_framebuffer_state
= svga_set_framebuffer_state
;
206 svga
->pipe
.set_clip_state
= svga_set_clip_state
;
207 svga
->pipe
.set_viewport_states
= svga_set_viewport_states
;