Merge branch 'gallium-nopointsizeminmax'
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_span.c
1 /*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 #include "nouveau_driver.h"
28 #include "nouveau_fbo.h"
29 #include "nouveau_context.h"
30 #include "nouveau_bo.h"
31
32 #include "swrast/swrast.h"
33
34 #define LOCAL_VARS \
35 struct gl_framebuffer *fb = ctx->DrawBuffer; \
36 struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface; \
37 GLuint p; \
38 (void)p;
39
40 #define LOCAL_DEPTH_VARS LOCAL_VARS
41
42 #define HW_LOCK()
43 #define HW_UNLOCK()
44
45 #define HW_CLIPLOOP() { \
46 int minx = 0; \
47 int miny = 0; \
48 int maxx = fb->Width; \
49 int maxy = fb->Height;
50
51 #define HW_ENDCLIPLOOP() }
52
53 #define Y_FLIP(y) (fb->Name ? (y) : rb->Height - 1 - (y))
54
55 /* RGB565 span functions */
56 #define SPANTMP_PIXEL_FMT GL_RGB
57 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
58 #define TAG(x) nouveau_##x##_rgb565
59 #define TAG2(x, y) nouveau_##x##_rgb565##y
60 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
61
62 #include "spantmp2.h"
63
64 /* ARGB8888 span functions */
65 #define SPANTMP_PIXEL_FMT GL_BGRA
66 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
67 #define TAG(x) nouveau_##x##_argb8888
68 #define TAG2(x, y) nouveau_##x##_argb8888##y
69 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
70
71 #include "spantmp2.h"
72
73 /* Z16 span functions */
74 #define VALUE_TYPE uint16_t
75 #define READ_DEPTH(v, x, y) \
76 v = *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
77 #define WRITE_DEPTH(x, y, v) \
78 *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
79 #define TAG(x) nouveau_##x##_z16
80
81 #include "depthtmp.h"
82
83 /* Z24S8 span functions */
84 #define VALUE_TYPE uint32_t
85 #define READ_DEPTH(v, x, y) \
86 v = *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
87 #define WRITE_DEPTH(x, y, v) \
88 *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
89 #define TAG(x) nouveau_##x##_z24s8
90
91 #include "depthtmp.h"
92
93 static void
94 renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
95 {
96 struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
97
98 if (map) {
99 switch (rb->Format) {
100 case MESA_FORMAT_RGB565:
101 nouveau_InitPointers_rgb565(rb);
102 break;
103 case MESA_FORMAT_XRGB8888:
104 case MESA_FORMAT_ARGB8888:
105 nouveau_InitPointers_argb8888(rb);
106 break;
107 case MESA_FORMAT_Z16:
108 nouveau_InitDepthPointers_z16(rb);
109 break;
110 case MESA_FORMAT_Z24_S8:
111 nouveau_InitDepthPointers_z24s8(rb);
112 break;
113 default:
114 assert(0);
115 }
116
117 nouveau_bo_map(s->bo, NOUVEAU_BO_RDWR);
118 } else {
119 nouveau_bo_unmap(s->bo);
120 }
121 }
122
123 static void
124 texture_unit_map_unmap(GLcontext *ctx, struct gl_texture_unit *u, GLboolean map)
125 {
126 if (!u->_ReallyEnabled)
127 return;
128
129 if (map)
130 ctx->Driver.MapTexture(ctx, u->_Current);
131 else
132 ctx->Driver.UnmapTexture(ctx, u->_Current);
133 }
134
135 static void
136 span_map_unmap(GLcontext *ctx, GLboolean map)
137 {
138 int i;
139
140 for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++)
141 renderbuffer_map_unmap(ctx->DrawBuffer->_ColorDrawBuffers[i], map);
142
143 renderbuffer_map_unmap(ctx->DrawBuffer->_ColorReadBuffer, map);
144
145 if (ctx->DrawBuffer->_DepthBuffer)
146 renderbuffer_map_unmap(ctx->DrawBuffer->_DepthBuffer->Wrapped, map);
147
148 for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
149 texture_unit_map_unmap(ctx, &ctx->Texture.Unit[i], map);
150 }
151
152 static void
153 nouveau_span_start(GLcontext *ctx)
154 {
155 nouveau_fallback(ctx, SWRAST);
156 span_map_unmap(ctx, GL_TRUE);
157 }
158
159 static void
160 nouveau_span_finish(GLcontext *ctx)
161 {
162 span_map_unmap(ctx, GL_FALSE);
163 nouveau_fallback(ctx, HWTNL);
164 }
165
166 void
167 nouveau_span_functions_init(GLcontext *ctx)
168 {
169 struct swrast_device_driver *swdd =
170 _swrast_GetDeviceDriverReference(ctx);
171
172 swdd->SpanRenderStart = nouveau_span_start;
173 swdd->SpanRenderFinish = nouveau_span_finish;
174 }