1 /**************************************************************************
3 * Copyright © 2010 Jakob Bornecrantz
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 **************************************************************************/
28 #include "i915_context.h"
29 #include "i915_state.h"
30 #include "i915_resource.h"
34 /***********************************************************************
35 * Update framebuffer state
37 static unsigned translate_format(enum pipe_format format
)
40 case PIPE_FORMAT_B8G8R8A8_UNORM
:
41 return COLOR_BUF_ARGB8888
;
42 case PIPE_FORMAT_B5G6R5_UNORM
:
43 return COLOR_BUF_RGB565
;
50 static unsigned translate_depth_format(enum pipe_format zformat
)
53 case PIPE_FORMAT_Z24X8_UNORM
:
54 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
55 return DEPTH_FRMT_24_FIXED_8_OTHER
;
56 case PIPE_FORMAT_Z16_UNORM
:
57 return DEPTH_FRMT_16_FIXED
;
64 static inline uint32_t
65 buf_3d_tiling_bits(enum i915_winsys_buffer_tile tiling
)
67 uint32_t tiling_bits
= 0;
71 tiling_bits
|= BUF_3D_TILE_WALK_Y
;
73 tiling_bits
|= BUF_3D_TILED_SURFACE
;
81 static void update_framebuffer(struct i915_context
*i915
)
83 struct pipe_surface
*cbuf_surface
= i915
->framebuffer
.cbufs
[0];
84 struct pipe_surface
*depth_surface
= i915
->framebuffer
.zsbuf
;
85 unsigned cformat
, zformat
;
88 uint32_t draw_offset
, draw_size
, dst_buf_vars
;
91 struct i915_texture
*tex
= i915_texture(cbuf_surface
->texture
);
94 i915
->current
.cbuf_bo
= tex
->buffer
;
95 i915
->current
.cbuf_flags
= BUF_3D_ID_COLOR_BACK
|
96 BUF_3D_PITCH(tex
->stride
) | /* pitch in bytes */
97 buf_3d_tiling_bits(tex
->tiling
);
98 cformat
= cbuf_surface
->format
;
100 layer
= cbuf_surface
->u
.tex
.first_layer
;
102 x
= tex
->image_offset
[cbuf_surface
->u
.tex
.level
][layer
].nblocksx
;
103 y
= tex
->image_offset
[cbuf_surface
->u
.tex
.level
][layer
].nblocksy
;
105 i915
->current
.cbuf_bo
= NULL
;
106 cformat
= PIPE_FORMAT_B8G8R8A8_UNORM
; /* arbitrary */
109 cformat
= translate_format(cformat
);
110 i915
->static_dirty
|= I915_DST_BUF_COLOR
;
112 /* What happens if no zbuf??
115 struct i915_texture
*tex
= i915_texture(depth_surface
->texture
);
116 unsigned offset
= i915_texture_offset(tex
, depth_surface
->u
.tex
.level
,
117 depth_surface
->u
.tex
.first_layer
);
121 i915
->current
.depth_bo
= tex
->buffer
;
122 i915
->current
.depth_flags
= BUF_3D_ID_DEPTH
|
123 BUF_3D_PITCH(tex
->stride
) | /* pitch in bytes */
124 buf_3d_tiling_bits(tex
->tiling
);
125 zformat
= translate_depth_format(depth_surface
->format
);
127 i915
->current
.depth_bo
= NULL
;
130 i915
->static_dirty
|= I915_DST_BUF_DEPTH
;
132 dst_buf_vars
= DSTORG_HORT_BIAS(0x8) | /* .5 */
133 DSTORG_VERT_BIAS(0x8) | /* .5 */
135 TEX_DEFAULT_COLOR_OGL
|
138 if (i915
->current
.dst_buf_vars
!= dst_buf_vars
) {
139 i915
->current
.dst_buf_vars
= dst_buf_vars
;
140 i915
->static_dirty
|= I915_DST_VARS
;
143 /* drawing rect calculations */
144 draw_offset
= x
| (y
<< 16);
145 draw_size
= (i915
->framebuffer
.width
- 1 + x
) |
146 ((i915
->framebuffer
.height
- 1 + y
) << 16);
147 if (i915
->current
.draw_offset
!= draw_offset
) {
148 i915
->current
.draw_offset
= draw_offset
;
149 i915_set_flush_dirty(i915
, I915_PIPELINE_FLUSH
);
150 i915
->static_dirty
|= I915_DST_RECT
;
151 } else if (i915
->current
.draw_size
!= draw_size
) {
152 i915
->current
.draw_size
= draw_size
;
153 i915
->static_dirty
|= I915_DST_RECT
;
156 i915
->hardware_dirty
|= I915_HW_STATIC
;
158 /* flush the cache in case we sample from the old renderbuffers */
159 i915_set_flush_dirty(i915
, I915_FLUSH_CACHE
);
162 struct i915_tracked_state i915_hw_framebuffer
= {