3645720c060b9780fee5cdfb10c6130af3d2e9b7
1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright 2011 Intel Corporation
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Chad Versace <chad@chad-versace.us>
30 **************************************************************************/
34 #include "main/glheader.h"
35 #include "main/macros.h"
36 #include "main/mtypes.h"
37 #include "main/colormac.h"
38 #include "main/renderbuffer.h"
40 #include "intel_buffers.h"
41 #include "intel_fbo.h"
42 #include "intel_mipmap_tree.h"
43 #include "intel_screen.h"
44 #include "intel_span.h"
45 #include "intel_regions.h"
46 #include "intel_tex.h"
48 #include "swrast/swrast.h"
49 #include "swrast/s_renderbuffer.h"
52 * \brief Get pointer offset into stencil buffer.
54 * The stencil buffer is W tiled. Since the GTT is incapable of W fencing, we
55 * must decode the tile's layout in software.
58 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.2.1 W-Major Tile
60 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.3 Tiling Algorithm
62 * Even though the returned offset is always positive, the return type is
64 * commit e8b1c6d6f55f5be3bef25084fdd8b6127517e137
65 * mesa: Fix return type of _mesa_get_format_bytes() (#37351)
68 intel_offset_S8(uint32_t stride
, uint32_t x
, uint32_t y
)
70 uint32_t tile_size
= 4096;
71 uint32_t tile_width
= 64;
72 uint32_t tile_height
= 64;
73 uint32_t row_size
= 64 * stride
;
75 uint32_t tile_x
= x
/ tile_width
;
76 uint32_t tile_y
= y
/ tile_height
;
78 /* The byte's address relative to the tile's base addres. */
79 uint32_t byte_x
= x
% tile_width
;
80 uint32_t byte_y
= y
% tile_height
;
82 uintptr_t u
= tile_y
* row_size
86 + 32 * ((byte_y
/ 4) % 2)
87 + 16 * ((byte_x
/ 4) % 2)
88 + 8 * ((byte_y
/ 2) % 2)
89 + 4 * ((byte_x
/ 2) % 2)
96 * An additional offset is needed which is not documented in the PRM.
98 * if ((byte_x / 8) % 2 == 1) {
99 * if ((byte_y / 8) % 2) == 0) {
106 * The offset is expressed more tersely as
107 * u += ((int) x & 0x8) * (8 - (((int) y & 0x8) << 1));
115 * Resolve all buffers that will be mapped by intelSpanRenderStart().
117 * Resolve the depth buffer of each enabled texture and of the read and draw
120 * (Note: In the future this will also perform MSAA resolves.)
123 intel_span_resolve_buffers(struct intel_context
*intel
)
125 struct gl_context
*ctx
= &intel
->ctx
;
126 struct intel_renderbuffer
*draw_irb
;
127 struct intel_renderbuffer
*read_irb
;
128 struct intel_texture_object
*tex_obj
;
130 /* Resolve depth buffer of each enabled texture. */
131 for (int i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
132 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
134 tex_obj
= intel_texture_object(ctx
->Texture
.Unit
[i
]._Current
);
135 intel_finalize_mipmap_tree(intel
, i
);
136 if (!tex_obj
|| !tex_obj
->mt
)
138 intel_miptree_all_slices_resolve_depth(intel
, tex_obj
->mt
);
141 /* Resolve each attached depth buffer. */
142 draw_irb
= intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
143 read_irb
= intel_get_renderbuffer(ctx
->ReadBuffer
, BUFFER_DEPTH
);
145 intel_renderbuffer_resolve_depth(intel
, draw_irb
);
146 if (read_irb
!= draw_irb
&& read_irb
)
147 intel_renderbuffer_resolve_depth(intel
, read_irb
);
151 * Map the regions needed by intelSpanRenderStart().
154 intel_span_map_buffers(struct intel_context
*intel
)
156 struct gl_context
*ctx
= &intel
->ctx
;
157 struct intel_texture_object
*tex_obj
;
159 for (int i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
160 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
162 tex_obj
= intel_texture_object(ctx
->Texture
.Unit
[i
]._Current
);
163 intel_finalize_mipmap_tree(intel
, i
);
164 intel_tex_map_images(intel
, tex_obj
,
165 GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
);
168 _swrast_map_renderbuffers(ctx
);
172 * Prepare for software rendering. Map current read/draw framebuffers'
173 * renderbuffes and all currently bound texture objects.
175 * Old note: Moved locking out to get reasonable span performance.
178 intelSpanRenderStart(struct gl_context
* ctx
)
180 struct intel_context
*intel
= intel_context(ctx
);
183 intel_prepare_render(intel
);
184 intel_span_resolve_buffers(intel
);
186 intel_span_map_buffers(intel
);
190 * Called when done software rendering. Unmap the buffers we mapped in
191 * the above function.
194 intelSpanRenderFinish(struct gl_context
* ctx
)
196 struct intel_context
*intel
= intel_context(ctx
);
201 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
202 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
203 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
204 intel_tex_unmap_images(intel
, intel_texture_object(texObj
));
208 _swrast_unmap_renderbuffers(ctx
);
213 intelInitSpanFuncs(struct gl_context
* ctx
)
215 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
216 swdd
->SpanRenderStart
= intelSpanRenderStart
;
217 swdd
->SpanRenderFinish
= intelSpanRenderFinish
;
221 intel_map_vertex_shader_textures(struct gl_context
*ctx
)
223 struct intel_context
*intel
= intel_context(ctx
);
226 if (ctx
->VertexProgram
._Current
== NULL
)
229 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
230 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
231 ctx
->VertexProgram
._Current
->Base
.TexturesUsed
[i
] != 0) {
232 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
234 intel_tex_map_images(intel
, intel_texture_object(texObj
),
235 GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
);
241 intel_unmap_vertex_shader_textures(struct gl_context
*ctx
)
243 struct intel_context
*intel
= intel_context(ctx
);
246 if (ctx
->VertexProgram
._Current
== NULL
)
249 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
250 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
251 ctx
->VertexProgram
._Current
->Base
.TexturesUsed
[i
] != 0) {
252 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
254 intel_tex_unmap_images(intel
, intel_texture_object(texObj
));