1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32 #include "main/colormac.h"
34 #include "intel_buffers.h"
35 #include "intel_fbo.h"
36 #include "intel_screen.h"
37 #include "intel_span.h"
38 #include "intel_regions.h"
39 #include "intel_tex.h"
41 #include "swrast/swrast.h"
44 intel_set_span_functions(struct intel_context
*intel
,
45 struct gl_renderbuffer
*rb
);
51 struct intel_renderbuffer *irb = intel_renderbuffer(rb); \
52 const GLint yScale = rb->Name ? 1 : -1; \
53 const GLint yBias = rb->Name ? 0 : rb->Height - 1; \
54 int minx = 0, miny = 0; \
55 int maxx = rb->Width; \
56 int maxy = rb->Height; \
57 int pitch = irb->region->pitch * irb->region->cpp; \
58 void *buf = irb->region->buffer->virtual; \
61 (void)buf; (void)pitch; /* unused for non-gttmap. */ \
64 #define HW_ENDCLIPLOOP()
66 #define Y_FLIP(_y) ((_y) * yScale + yBias)
72 /* Convenience macros to avoid typing the address argument over and over */
73 #define NO_TILE(_X, _Y) (((_Y) * irb->region->pitch + (_X)) * irb->region->cpp)
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"
117 #define SPANTMP_MESA_FMT MESA_FORMAT_R8
118 #define TAG(x) intel_##x##_R8
119 #define TAG2(x,y) intel_##x##y##_R8
120 #include "spantmp2.h"
122 #define SPANTMP_MESA_FMT MESA_FORMAT_RG88
123 #define TAG(x) intel_##x##_RG88
124 #define TAG2(x,y) intel_##x##y##_RG88
125 #include "spantmp2.h"
127 #define SPANTMP_MESA_FMT MESA_FORMAT_R16
128 #define TAG(x) intel_##x##_R16
129 #define TAG2(x,y) intel_##x##y##_R16
130 #include "spantmp2.h"
132 #define SPANTMP_MESA_FMT MESA_FORMAT_RG1616
133 #define TAG(x) intel_##x##_RG1616
134 #define TAG2(x,y) intel_##x##y##_RG1616
135 #include "spantmp2.h"
137 #define LOCAL_DEPTH_VARS \
138 struct intel_renderbuffer *irb = intel_renderbuffer(rb); \
139 const GLint yScale = rb->Name ? 1 : -1; \
140 const GLint yBias = rb->Name ? 0 : rb->Height - 1; \
141 int minx = 0, miny = 0; \
142 int maxx = rb->Width; \
143 int maxy = rb->Height; \
144 int pitch = irb->region->pitch * irb->region->cpp; \
145 void *buf = irb->region->buffer->virtual; \
146 (void)buf; (void)pitch; /* unused for non-gttmap. */ \
148 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
150 /* z16 depthbuffer functions. */
151 #define VALUE_TYPE GLushort
152 #define WRITE_DEPTH(_x, _y, d) \
153 (*(uint16_t *)(irb->region->buffer->virtual + NO_TILE(_x, _y)) = d)
154 #define READ_DEPTH(d, _x, _y) \
155 d = *(uint16_t *)(irb->region->buffer->virtual + NO_TILE(_x, _y))
156 #define TAG(x) intel_##x##_z16
157 #include "depthtmp.h"
159 /* z24_s8 and z24_x8 depthbuffer functions. */
160 #define VALUE_TYPE GLuint
161 #define WRITE_DEPTH(_x, _y, d) \
162 (*(uint32_t *)(irb->region->buffer->virtual + NO_TILE(_x, _y)) = d)
163 #define READ_DEPTH(d, _x, _y) \
164 d = *(uint32_t *)(irb->region->buffer->virtual + NO_TILE(_x, _y))
165 #define TAG(x) intel_##x##_z24_s8
166 #include "depthtmp.h"
169 intel_renderbuffer_map(struct intel_context
*intel
, struct gl_renderbuffer
*rb
)
171 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
173 if (irb
== NULL
|| irb
->region
== NULL
)
176 drm_intel_gem_bo_map_gtt(irb
->region
->buffer
);
178 intel_set_span_functions(intel
, rb
);
182 intel_renderbuffer_unmap(struct intel_context
*intel
,
183 struct gl_renderbuffer
*rb
)
185 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
187 if (irb
== NULL
|| irb
->region
== NULL
)
190 drm_intel_gem_bo_unmap_gtt(irb
->region
->buffer
);
197 * Map or unmap all the renderbuffers which we may need during
198 * software rendering.
199 * XXX in the future, we could probably convey extra information to
200 * reduce the number of mappings needed. I.e. if doing a glReadPixels
201 * from the depth buffer, we really only need one mapping.
203 * XXX Rewrite this function someday.
204 * We can probably just loop over all the renderbuffer attachments,
205 * map/unmap all of them, and not worry about the _ColorDrawBuffers
206 * _ColorReadBuffer, _DepthBuffer or _StencilBuffer fields.
209 intel_map_unmap_framebuffer(struct intel_context
*intel
,
210 struct gl_framebuffer
*fb
,
215 /* color draw buffers */
216 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
218 intel_renderbuffer_map(intel
, fb
->_ColorDrawBuffers
[i
]);
220 intel_renderbuffer_unmap(intel
, fb
->_ColorDrawBuffers
[i
]);
223 /* color read buffer */
225 intel_renderbuffer_map(intel
, fb
->_ColorReadBuffer
);
227 intel_renderbuffer_unmap(intel
, fb
->_ColorReadBuffer
);
229 /* check for render to textures */
230 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
231 struct gl_renderbuffer_attachment
*att
=
233 struct gl_texture_object
*tex
= att
->Texture
;
235 /* render to texture */
236 ASSERT(att
->Renderbuffer
);
238 intel_tex_map_images(intel
, intel_texture_object(tex
));
240 intel_tex_unmap_images(intel
, intel_texture_object(tex
));
244 /* depth buffer (Note wrapper!) */
245 if (fb
->_DepthBuffer
) {
247 intel_renderbuffer_map(intel
, fb
->_DepthBuffer
->Wrapped
);
249 intel_renderbuffer_unmap(intel
, fb
->_DepthBuffer
->Wrapped
);
252 /* stencil buffer (Note wrapper!) */
253 if (fb
->_StencilBuffer
) {
255 intel_renderbuffer_map(intel
, fb
->_StencilBuffer
->Wrapped
);
257 intel_renderbuffer_unmap(intel
, fb
->_StencilBuffer
->Wrapped
);
260 intel_check_front_buffer_rendering(intel
);
264 * Prepare for software rendering. Map current read/draw framebuffers'
265 * renderbuffes and all currently bound texture objects.
267 * Old note: Moved locking out to get reasonable span performance.
270 intelSpanRenderStart(struct gl_context
* ctx
)
272 struct intel_context
*intel
= intel_context(ctx
);
275 intel_flush(&intel
->ctx
);
276 intel_prepare_render(intel
);
278 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
279 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
280 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
282 intel_finalize_mipmap_tree(intel
, i
);
283 intel_tex_map_images(intel
, intel_texture_object(texObj
));
287 intel_map_unmap_framebuffer(intel
, ctx
->DrawBuffer
, GL_TRUE
);
288 if (ctx
->ReadBuffer
!= ctx
->DrawBuffer
)
289 intel_map_unmap_framebuffer(intel
, ctx
->ReadBuffer
, GL_TRUE
);
293 * Called when done software rendering. Unmap the buffers we mapped in
294 * the above function.
297 intelSpanRenderFinish(struct gl_context
* ctx
)
299 struct intel_context
*intel
= intel_context(ctx
);
304 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
305 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
306 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
307 intel_tex_unmap_images(intel
, intel_texture_object(texObj
));
311 intel_map_unmap_framebuffer(intel
, ctx
->DrawBuffer
, GL_FALSE
);
312 if (ctx
->ReadBuffer
!= ctx
->DrawBuffer
)
313 intel_map_unmap_framebuffer(intel
, ctx
->ReadBuffer
, GL_FALSE
);
318 intelInitSpanFuncs(struct gl_context
* ctx
)
320 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
321 swdd
->SpanRenderStart
= intelSpanRenderStart
;
322 swdd
->SpanRenderFinish
= intelSpanRenderFinish
;
326 intel_map_vertex_shader_textures(struct gl_context
*ctx
)
328 struct intel_context
*intel
= intel_context(ctx
);
331 if (ctx
->VertexProgram
._Current
== NULL
)
334 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
335 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
336 ctx
->VertexProgram
._Current
->Base
.TexturesUsed
[i
] != 0) {
337 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
339 intel_tex_map_images(intel
, intel_texture_object(texObj
));
345 intel_unmap_vertex_shader_textures(struct gl_context
*ctx
)
347 struct intel_context
*intel
= intel_context(ctx
);
350 if (ctx
->VertexProgram
._Current
== NULL
)
353 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
354 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
355 ctx
->VertexProgram
._Current
->Base
.TexturesUsed
[i
] != 0) {
356 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[i
]._Current
;
358 intel_tex_unmap_images(intel
, intel_texture_object(texObj
));
363 typedef void (*span_init_func
)(struct gl_renderbuffer
*rb
);
365 static span_init_func intel_span_init_funcs
[MESA_FORMAT_COUNT
] =
367 [MESA_FORMAT_A8
] = intel_InitPointers_A8
,
368 [MESA_FORMAT_RGB565
] = intel_InitPointers_RGB565
,
369 [MESA_FORMAT_ARGB4444
] = intel_InitPointers_ARGB4444
,
370 [MESA_FORMAT_ARGB1555
] = intel_InitPointers_ARGB1555
,
371 [MESA_FORMAT_XRGB8888
] = intel_InitPointers_xRGB8888
,
372 [MESA_FORMAT_ARGB8888
] = intel_InitPointers_ARGB8888
,
373 [MESA_FORMAT_SARGB8
] = intel_InitPointers_ARGB8888
,
374 [MESA_FORMAT_Z16
] = intel_InitDepthPointers_z16
,
375 [MESA_FORMAT_X8_Z24
] = intel_InitDepthPointers_z24_s8
,
376 [MESA_FORMAT_S8_Z24
] = intel_InitDepthPointers_z24_s8
,
377 [MESA_FORMAT_R8
] = intel_InitPointers_R8
,
378 [MESA_FORMAT_RG88
] = intel_InitPointers_RG88
,
379 [MESA_FORMAT_R16
] = intel_InitPointers_R16
,
380 [MESA_FORMAT_RG1616
] = intel_InitPointers_RG1616
,
384 intel_span_supports_format(gl_format format
)
386 return intel_span_init_funcs
[format
] != NULL
;
390 * Plug in appropriate span read/write functions for the given renderbuffer.
391 * These are used for the software fallbacks.
394 intel_set_span_functions(struct intel_context
*intel
,
395 struct gl_renderbuffer
*rb
)
397 struct intel_renderbuffer
*irb
= (struct intel_renderbuffer
*) rb
;
399 assert(intel_span_init_funcs
[irb
->Base
.Format
]);
400 intel_span_init_funcs
[irb
->Base
.Format
](rb
);