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_screen.h"
43 #include "intel_span.h"
44 #include "intel_regions.h"
45 #include "intel_tex.h"
47 #include "swrast/swrast.h"
50 intel_set_span_functions(struct intel_context
*intel
,
51 struct gl_renderbuffer
*rb
);
57 struct intel_renderbuffer *irb = intel_renderbuffer(rb); \
58 int minx = 0, miny = 0; \
59 int maxx = rb->Width; \
60 int maxy = rb->Height; \
61 int pitch = rb->RowStride * irb->region->cpp; \
62 void *buf = rb->Data; \
67 #define HW_ENDCLIPLOOP()
69 #define Y_FLIP(_y) (_y)
75 /* r5g6b5 color span and pixel functions */
76 #define SPANTMP_PIXEL_FMT GL_RGB
77 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
78 #define TAG(x) intel_##x##_RGB565
79 #define TAG2(x,y) intel_##x##y_RGB565
82 /* a4r4g4b4 color span and pixel functions */
83 #define SPANTMP_PIXEL_FMT GL_BGRA
84 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4_REV
85 #define TAG(x) intel_##x##_ARGB4444
86 #define TAG2(x,y) intel_##x##y_ARGB4444
89 /* a1r5g5b5 color span and pixel functions */
90 #define SPANTMP_PIXEL_FMT GL_BGRA
91 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5_REV
92 #define TAG(x) intel_##x##_ARGB1555
93 #define TAG2(x,y) intel_##x##y##_ARGB1555
96 /* a8r8g8b8 color span and pixel functions */
97 #define SPANTMP_PIXEL_FMT GL_BGRA
98 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
99 #define TAG(x) intel_##x##_ARGB8888
100 #define TAG2(x,y) intel_##x##y##_ARGB8888
101 #include "spantmp2.h"
103 /* x8r8g8b8 color span and pixel functions */
104 #define SPANTMP_PIXEL_FMT GL_BGR
105 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
106 #define TAG(x) intel_##x##_xRGB8888
107 #define TAG2(x,y) intel_##x##y##_xRGB8888
108 #include "spantmp2.h"
110 /* a8 color span and pixel functions */
111 #define SPANTMP_PIXEL_FMT GL_ALPHA
112 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_BYTE
113 #define TAG(x) intel_##x##_A8
114 #define TAG2(x,y) intel_##x##y##_A8
115 #include "spantmp2.h"
118 * \brief Get pointer offset into stencil buffer.
120 * The stencil buffer is W tiled. Since the GTT is incapable of W fencing, we
121 * must decode the tile's layout in software.
124 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.2.1 W-Major Tile
126 * - PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section 4.5.3 Tiling Algorithm
128 * Even though the returned offset is always positive, the return type is
130 * commit e8b1c6d6f55f5be3bef25084fdd8b6127517e137
131 * mesa: Fix return type of _mesa_get_format_bytes() (#37351)
134 intel_offset_S8(uint32_t stride
, uint32_t x
, uint32_t y
)
136 uint32_t tile_size
= 4096;
137 uint32_t tile_width
= 64;
138 uint32_t tile_height
= 64;
139 uint32_t row_size
= 64 * stride
;
141 uint32_t tile_x
= x
/ tile_width
;
142 uint32_t tile_y
= y
/ tile_height
;
144 /* The byte's address relative to the tile's base addres. */
145 uint32_t byte_x
= x
% tile_width
;
146 uint32_t byte_y
= y
% tile_height
;
148 uintptr_t u
= tile_y
* row_size
152 + 32 * ((byte_y
/ 4) % 2)
153 + 16 * ((byte_x
/ 4) % 2)
154 + 8 * ((byte_y
/ 2) % 2)
155 + 4 * ((byte_x
/ 2) % 2)
162 * An additional offset is needed which is not documented in the PRM.
164 * if ((byte_x / 8) % 2 == 1) {
165 * if ((byte_y / 8) % 2) == 0) {
172 * The offset is expressed more tersely as
173 * u += ((int) x & 0x8) * (8 - (((int) y & 0x8) << 1));
180 intel_renderbuffer_map(struct intel_context
*intel
, struct gl_renderbuffer
*rb
)
182 struct gl_context
*ctx
= &intel
->ctx
;
183 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
191 /* Renderbuffer is already mapped. This usually happens when a single
192 * buffer is attached to the framebuffer's depth and stencil attachment
198 ctx
->Driver
.MapRenderbuffer(ctx
, rb
, 0, 0, rb
->Width
, rb
->Height
,
199 GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
,
202 rb
->RowStride
= stride
/ _mesa_get_format_bytes(rb
->Format
);
204 intel_set_span_functions(intel
, rb
);
208 intel_renderbuffer_unmap(struct intel_context
*intel
,
209 struct gl_renderbuffer
*rb
)
211 struct gl_context
*ctx
= &intel
->ctx
;
212 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
218 /* Renderbuffer is already unmapped. This usually happens when a single
219 * buffer is attached to the framebuffer's depth and stencil attachment
225 ctx
->Driver
.UnmapRenderbuffer(ctx
, rb
);
234 intel_framebuffer_map(struct intel_context
*intel
, struct gl_framebuffer
*fb
)
238 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
239 intel_renderbuffer_map(intel
, fb
->Attachment
[i
].Renderbuffer
);
242 intel_check_front_buffer_rendering(intel
);
246 intel_framebuffer_unmap(struct intel_context
*intel
, struct gl_framebuffer
*fb
)
250 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
251 intel_renderbuffer_unmap(intel
, fb
->Attachment
[i
].Renderbuffer
);
256 * Prepare for software rendering. Map current read/draw framebuffers'
257 * renderbuffes and all currently bound texture objects.
259 * Old note: Moved locking out to get reasonable span performance.
262 intelSpanRenderStart(struct gl_context
* ctx
)
264 struct intel_context
*intel
= intel_context(ctx
);
267 intel_flush(&intel
->ctx
);
268 intel_prepare_render(intel
);
270 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
271 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
272 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
274 intel_finalize_mipmap_tree(intel
, i
);
275 intel_tex_map_images(intel
, intel_texture_object(texObj
),
276 GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
);
280 intel_framebuffer_map(intel
, ctx
->DrawBuffer
);
281 if (ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
282 intel_framebuffer_map(intel
, ctx
->ReadBuffer
);
287 * Called when done software rendering. Unmap the buffers we mapped in
288 * the above function.
291 intelSpanRenderFinish(struct gl_context
* ctx
)
293 struct intel_context
*intel
= intel_context(ctx
);
298 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
299 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
300 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
301 intel_tex_unmap_images(intel
, intel_texture_object(texObj
));
305 intel_framebuffer_unmap(intel
, ctx
->DrawBuffer
);
306 if (ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
307 intel_framebuffer_unmap(intel
, ctx
->ReadBuffer
);
313 intelInitSpanFuncs(struct gl_context
* ctx
)
315 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
316 swdd
->SpanRenderStart
= intelSpanRenderStart
;
317 swdd
->SpanRenderFinish
= intelSpanRenderFinish
;
321 intel_map_vertex_shader_textures(struct gl_context
*ctx
)
323 struct intel_context
*intel
= intel_context(ctx
);
326 if (ctx
->VertexProgram
._Current
== NULL
)
329 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
330 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
331 ctx
->VertexProgram
._Current
->Base
.TexturesUsed
[i
] != 0) {
332 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
334 intel_tex_map_images(intel
, intel_texture_object(texObj
),
335 GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
);
341 intel_unmap_vertex_shader_textures(struct gl_context
*ctx
)
343 struct intel_context
*intel
= intel_context(ctx
);
346 if (ctx
->VertexProgram
._Current
== NULL
)
349 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
350 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
351 ctx
->VertexProgram
._Current
->Base
.TexturesUsed
[i
] != 0) {
352 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
354 intel_tex_unmap_images(intel
, intel_texture_object(texObj
));
359 typedef void (*span_init_func
)(struct gl_renderbuffer
*rb
);
361 static span_init_func intel_span_init_funcs
[MESA_FORMAT_COUNT
] =
363 [MESA_FORMAT_A8
] = intel_InitPointers_A8
,
364 [MESA_FORMAT_RGB565
] = intel_InitPointers_RGB565
,
365 [MESA_FORMAT_ARGB4444
] = intel_InitPointers_ARGB4444
,
366 [MESA_FORMAT_ARGB1555
] = intel_InitPointers_ARGB1555
,
367 [MESA_FORMAT_XRGB8888
] = intel_InitPointers_xRGB8888
,
368 [MESA_FORMAT_ARGB8888
] = intel_InitPointers_ARGB8888
,
369 [MESA_FORMAT_SARGB8
] = intel_InitPointers_ARGB8888
,
370 [MESA_FORMAT_Z16
] = _mesa_set_renderbuffer_accessors
,
371 [MESA_FORMAT_X8_Z24
] = _mesa_set_renderbuffer_accessors
,
372 [MESA_FORMAT_S8_Z24
] = _mesa_set_renderbuffer_accessors
,
373 [MESA_FORMAT_S8
] = _mesa_set_renderbuffer_accessors
,
374 [MESA_FORMAT_R8
] = _mesa_set_renderbuffer_accessors
,
375 [MESA_FORMAT_RG88
] = _mesa_set_renderbuffer_accessors
,
376 [MESA_FORMAT_R16
] = _mesa_set_renderbuffer_accessors
,
377 [MESA_FORMAT_RG1616
] = _mesa_set_renderbuffer_accessors
,
378 [MESA_FORMAT_RGBA_FLOAT32
] = _mesa_set_renderbuffer_accessors
,
379 [MESA_FORMAT_RG_FLOAT32
] = _mesa_set_renderbuffer_accessors
,
380 [MESA_FORMAT_R_FLOAT32
] = _mesa_set_renderbuffer_accessors
,
381 [MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_set_renderbuffer_accessors
,
382 [MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_set_renderbuffer_accessors
,
386 intel_span_supports_format(gl_format format
)
388 /* Rendering to/from integer textures will be done using MapRenderbuffer,
389 * rather than coding up new paths through GetRow/PutRow(), so claim support
390 * for those formats in here for now.
392 return (intel_span_init_funcs
[format
] != NULL
||
393 _mesa_is_format_integer_color(format
));
397 * Plug in appropriate span read/write functions for the given renderbuffer.
398 * These are used for the software fallbacks.
401 intel_set_span_functions(struct intel_context
*intel
,
402 struct gl_renderbuffer
*rb
)
404 struct intel_renderbuffer
*irb
= (struct intel_renderbuffer
*) rb
;
406 assert(intel_span_init_funcs
[irb
->Base
.Format
]);
407 intel_span_init_funcs
[irb
->Base
.Format
](rb
);
409 if (rb
->DataType
== GL_NONE
) {
411 "renderbuffer format %s is missing "
412 "intel_mesa_format_to_rb_datatype() support.",
413 _mesa_get_format_name(rb
->Format
));