2 * Copyright 2008 Ben Skeggs
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define __NOUVEAU_PUSH_H__
25 #include "nouveau/nouveau_pushbuf.h"
26 #include "nv50_context.h"
27 #include "pipe/p_defines.h"
28 #include "pipe/internal/p_winsys_screen.h"
29 #include "pipe/p_inlines.h"
31 #include "util/u_tile.h"
34 nv50_format(enum pipe_format format)
37 case PIPE_FORMAT_A8R8G8B8_UNORM:
38 case PIPE_FORMAT_Z24S8_UNORM:
39 return NV50_2D_DST_FORMAT_32BPP;
40 case PIPE_FORMAT_X8R8G8B8_UNORM:
41 return NV50_2D_DST_FORMAT_24BPP;
42 case PIPE_FORMAT_R5G6B5_UNORM:
43 return NV50_2D_DST_FORMAT_16BPP;
44 case PIPE_FORMAT_A8_UNORM:
45 return NV50_2D_DST_FORMAT_8BPP;
52 nv50_surface_set(struct nv50_screen *screen, struct pipe_surface *ps, int dst)
54 struct nv50_miptree *mt = nv50_miptree(ps->texture);
55 struct nouveau_channel *chan = screen->nvws->channel;
56 struct nouveau_grobj *eng2d = screen->eng2d;
57 struct nouveau_bo *bo;
58 int format, mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT;
59 int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD);
61 bo = screen->nvws->get_bo(nv50_miptree(ps->texture)->buffer);
65 format = nv50_format(ps->format);
70 BEGIN_RING(chan, eng2d, mthd, 2);
71 OUT_RING (chan, format);
73 BEGIN_RING(chan, eng2d, mthd + 0x14, 5);
74 OUT_RING (chan, mt->level[0].pitch);
75 OUT_RING (chan, ps->width);
76 OUT_RING (chan, ps->height);
77 OUT_RELOCh(chan, bo, ps->offset, flags);
78 OUT_RELOCl(chan, bo, ps->offset, flags);
80 BEGIN_RING(chan, eng2d, mthd, 5);
81 OUT_RING (chan, format);
86 BEGIN_RING(chan, eng2d, mthd + 0x18, 4);
87 OUT_RING (chan, ps->width);
88 OUT_RING (chan, ps->height);
89 OUT_RELOCh(chan, bo, ps->offset, flags);
90 OUT_RELOCl(chan, bo, ps->offset, flags);
95 BEGIN_RING(chan, eng2d, NV50_2D_CLIP_X, 4);
98 OUT_RING (chan, surf->width);
99 OUT_RING (chan, surf->height);
107 nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst,
108 int dx, int dy, struct pipe_surface *src, int sx, int sy,
111 struct nouveau_channel *chan = screen->nvws->channel;
112 struct nouveau_grobj *eng2d = screen->eng2d;
115 WAIT_RING (chan, 32);
117 ret = nv50_surface_set(screen, dst, 1);
121 ret = nv50_surface_set(screen, src, 0);
125 BEGIN_RING(chan, eng2d, 0x088c, 1);
127 BEGIN_RING(chan, eng2d, NV50_2D_BLIT_DST_X, 4);
132 BEGIN_RING(chan, eng2d, 0x08c0, 4);
137 BEGIN_RING(chan, eng2d, 0x08d0, 4);
147 nv50_surface_copy(struct pipe_context *pipe,
148 struct pipe_surface *dest, unsigned destx, unsigned desty,
149 struct pipe_surface *src, unsigned srcx, unsigned srcy,
150 unsigned width, unsigned height)
152 struct nv50_context *nv50 = (struct nv50_context *)pipe;
153 struct nv50_screen *screen = nv50->screen;
155 assert(src->format == dest->format);
157 nv50_surface_do_copy(screen, dest, destx, desty, src, srcx,
158 srcy, width, height);
162 nv50_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
163 unsigned destx, unsigned desty, unsigned width,
164 unsigned height, unsigned value)
166 struct nv50_context *nv50 = (struct nv50_context *)pipe;
167 struct nv50_screen *screen = nv50->screen;
168 struct nouveau_channel *chan = screen->nvws->channel;
169 struct nouveau_grobj *eng2d = screen->eng2d;
172 format = nv50_format(dest->format);
176 WAIT_RING (chan, 32);
178 ret = nv50_surface_set(screen, dest, 1);
182 BEGIN_RING(chan, eng2d, 0x0580, 3);
184 OUT_RING (chan, format);
185 OUT_RING (chan, value);
186 BEGIN_RING(chan, eng2d, NV50_2D_RECT_X1, 4);
187 OUT_RING (chan, destx);
188 OUT_RING (chan, desty);
189 OUT_RING (chan, width);
190 OUT_RING (chan, height);
194 nv50_init_surface_functions(struct nv50_context *nv50)
196 nv50->pipe.surface_copy = nv50_surface_copy;
197 nv50->pipe.surface_fill = nv50_surface_fill;