nv50_surface.c revision 28486880ca3ec39419ccee0cb1a3bedc9ef7117c
1/* 2 * Copyright 2008 Ben Skeggs 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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 20 * SOFTWARE. 21 */ 22 23#define __NOUVEAU_PUSH_H__ 24#include <stdint.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 "util/u_inlines.h" 30 31#include "util/u_tile.h" 32 33static INLINE int 34nv50_format(enum pipe_format format) 35{ 36 switch (format) { 37 case PIPE_FORMAT_A8R8G8B8_UNORM: 38 return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM; 39 case PIPE_FORMAT_X8R8G8B8_UNORM: 40 return NV50_2D_DST_FORMAT_X8R8G8B8_UNORM; 41 case PIPE_FORMAT_R5G6B5_UNORM: 42 return NV50_2D_DST_FORMAT_R5G6B5_UNORM; 43 case PIPE_FORMAT_A8_UNORM: 44 return NV50_2D_DST_FORMAT_R8_UNORM; 45 default: 46 return -1; 47 } 48} 49 50static int 51nv50_surface_set(struct nv50_screen *screen, struct pipe_surface *ps, int dst) 52{ 53 struct nv50_miptree *mt = nv50_miptree(ps->texture); 54 struct nouveau_channel *chan = screen->eng2d->channel; 55 struct nouveau_grobj *eng2d = screen->eng2d; 56 struct nouveau_bo *bo = nv50_miptree(ps->texture)->base.bo; 57 int format, mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT; 58 int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD); 59 60 format = nv50_format(ps->format); 61 if (format < 0) 62 return 1; 63 64 if (!bo->tile_flags) { 65 MARK_RING (chan, 9, 2); /* flush on lack of space or relocs */ 66 BEGIN_RING(chan, eng2d, mthd, 2); 67 OUT_RING (chan, format); 68 OUT_RING (chan, 1); 69 BEGIN_RING(chan, eng2d, mthd + 0x14, 5); 70 OUT_RING (chan, mt->level[ps->level].pitch); 71 OUT_RING (chan, ps->width); 72 OUT_RING (chan, ps->height); 73 OUT_RELOCh(chan, bo, ps->offset, flags); 74 OUT_RELOCl(chan, bo, ps->offset, flags); 75 } else { 76 MARK_RING (chan, 11, 2); /* flush on lack of space or relocs */ 77 BEGIN_RING(chan, eng2d, mthd, 5); 78 OUT_RING (chan, format); 79 OUT_RING (chan, 0); 80 OUT_RING (chan, mt->level[ps->level].tile_mode << 4); 81 OUT_RING (chan, 1); 82 OUT_RING (chan, 0); 83 BEGIN_RING(chan, eng2d, mthd + 0x18, 4); 84 OUT_RING (chan, ps->width); 85 OUT_RING (chan, ps->height); 86 OUT_RELOCh(chan, bo, ps->offset, flags); 87 OUT_RELOCl(chan, bo, ps->offset, flags); 88 } 89 90#if 0 91 if (dst) { 92 BEGIN_RING(chan, eng2d, NV50_2D_CLIP_X, 4); 93 OUT_RING (chan, 0); 94 OUT_RING (chan, 0); 95 OUT_RING (chan, surf->width); 96 OUT_RING (chan, surf->height); 97 } 98#endif 99 100 return 0; 101} 102 103int 104nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst, 105 int dx, int dy, struct pipe_surface *src, int sx, int sy, 106 int w, int h) 107{ 108 struct nouveau_channel *chan = screen->eng2d->channel; 109 struct nouveau_grobj *eng2d = screen->eng2d; 110 int ret; 111 112 WAIT_RING (chan, 32); 113 114 ret = nv50_surface_set(screen, dst, 1); 115 if (ret) 116 return ret; 117 118 ret = nv50_surface_set(screen, src, 0); 119 if (ret) 120 return ret; 121 122 BEGIN_RING(chan, eng2d, 0x088c, 1); 123 OUT_RING (chan, 0); 124 BEGIN_RING(chan, eng2d, NV50_2D_BLIT_DST_X, 4); 125 OUT_RING (chan, dx); 126 OUT_RING (chan, dy); 127 OUT_RING (chan, w); 128 OUT_RING (chan, h); 129 BEGIN_RING(chan, eng2d, 0x08c0, 4); 130 OUT_RING (chan, 0); 131 OUT_RING (chan, 1); 132 OUT_RING (chan, 0); 133 OUT_RING (chan, 1); 134 BEGIN_RING(chan, eng2d, 0x08d0, 4); 135 OUT_RING (chan, 0); 136 OUT_RING (chan, sx); 137 OUT_RING (chan, 0); 138 OUT_RING (chan, sy); 139 140 return 0; 141} 142 143static void 144nv50_surface_copy(struct pipe_context *pipe, 145 struct pipe_surface *dest, unsigned destx, unsigned desty, 146 struct pipe_surface *src, unsigned srcx, unsigned srcy, 147 unsigned width, unsigned height) 148{ 149 struct nv50_context *nv50 = nv50_context(pipe); 150 struct nv50_screen *screen = nv50->screen; 151 152 assert(src->format == dest->format); 153 154 nv50_surface_do_copy(screen, dest, destx, desty, src, srcx, 155 srcy, width, height); 156} 157 158static void 159nv50_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest, 160 unsigned destx, unsigned desty, unsigned width, 161 unsigned height, unsigned value) 162{ 163 struct nv50_context *nv50 = nv50_context(pipe); 164 struct nv50_screen *screen = nv50->screen; 165 struct nouveau_channel *chan = screen->eng2d->channel; 166 struct nouveau_grobj *eng2d = screen->eng2d; 167 int format, ret; 168 169 format = nv50_format(dest->format); 170 if (format < 0) 171 return; 172 173 WAIT_RING (chan, 32); 174 175 ret = nv50_surface_set(screen, dest, 1); 176 if (ret) 177 return; 178 179 BEGIN_RING(chan, eng2d, NV50_2D_DRAW_SHAPE, 3); 180 OUT_RING (chan, NV50_2D_DRAW_SHAPE_RECTANGLES); 181 OUT_RING (chan, format); 182 OUT_RING (chan, value); 183 BEGIN_RING(chan, eng2d, NV50_2D_DRAW_POINT32_X(0), 4); 184 OUT_RING (chan, destx); 185 OUT_RING (chan, desty); 186 OUT_RING (chan, width); 187 OUT_RING (chan, height); 188} 189 190void 191nv50_init_surface_functions(struct nv50_context *nv50) 192{ 193 nv50->pipe.surface_copy = nv50_surface_copy; 194 nv50->pipe.surface_fill = nv50_surface_fill; 195} 196 197 198