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