1857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs/*
2857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * Copyright 2008 Ben Skeggs
3857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs *
447b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * copy of this software and associated documentation files (the "Software"),
6857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * to deal in the Software without restriction, including without limitation
7857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * Software is furnished to do so, subject to the following conditions:
10857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs *
11857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * The above copyright notice and this permission notice shall be included in
12857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * all copies or substantial portions of the Software.
13857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs *
14857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs * SOFTWARE.
21857a3294a959015bf893241199f7fd7f7882a6abBen Skeggs */
2247b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs
2313393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs#include <stdint.h>
24f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
2547b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs#include "pipe/p_defines.h"
26f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
2728486880ca3ec39419ccee0cb1a3bedc9ef7117cJosé Fonseca#include "util/u_inlines.h"
28e5b82c8222ef29c162d51a7ca9f553d85a63be22Roland Scheidegger#include "util/u_pack_color.h"
29e548babb1fc9230054674deb5e332f55319e5b91Christoph Bumiller#include "util/u_format.h"
30883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák#include "util/u_surface.h"
3147b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs
32f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller#include "nv50_context.h"
33f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller#include "nv50_resource.h"
34f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
35f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller#include "nv50_defs.xml.h"
368592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller#include "nv50_texture.xml.h"
37f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
38e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller#define NV50_ENG2D_SUPPORTED_FORMATS 0xff0843e080608409ULL
39e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller
4075ee309ca9f467ba80a88b07735fb2d654a8c433Christoph Bumiller/* return TRUE for formats that can be converted among each other by NV50_2D */
4175ee309ca9f467ba80a88b07735fb2d654a8c433Christoph Bumillerstatic INLINE boolean
4275ee309ca9f467ba80a88b07735fb2d654a8c433Christoph Bumillernv50_2d_format_faithful(enum pipe_format format)
4375ee309ca9f467ba80a88b07735fb2d654a8c433Christoph Bumiller{
44e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller   uint8_t id = nv50_format_table[format].rt;
45e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller
46e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller   return (id >= 0xc0) &&
47e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller      (NV50_ENG2D_SUPPORTED_FORMATS & (1ULL << (id - 0xc0)));
4875ee309ca9f467ba80a88b07735fb2d654a8c433Christoph Bumiller}
4975ee309ca9f467ba80a88b07735fb2d654a8c433Christoph Bumiller
50583bbfb3aed3ded6ca060155c1ebbd4f39138a31Christoph Bumillerstatic INLINE uint8_t
51583bbfb3aed3ded6ca060155c1ebbd4f39138a31Christoph Bumillernv50_2d_format(enum pipe_format format)
5213393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs{
53f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint8_t id = nv50_format_table[format].rt;
54f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
55f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   /* Hardware values for color formats range from 0xc0 to 0xff,
56f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller    * but the 2D engine doesn't support all of them.
57f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller    */
58e54354e8853c3521e71e5b94984722f18b7638e4Christoph Bumiller   if ((id >= 0xc0) && (NV50_ENG2D_SUPPORTED_FORMATS & (1ULL << (id - 0xc0))))
59f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return id;
60f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
61f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   switch (util_format_get_blocksize(format)) {
62f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   case 1:
63f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return NV50_SURFACE_FORMAT_R8_UNORM;
64f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   case 2:
65f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return NV50_SURFACE_FORMAT_R16_UNORM;
66f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   case 4:
677e2827fad95071e04e382be0117c654445764c52Christoph Bumiller      return NV50_SURFACE_FORMAT_BGRA8_UNORM;
68f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   default:
69f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return 0;
70f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
7113393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs}
7213393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs
7313393736dbab1087589f8dd788bc412d16b431d1Ben Skeggsstatic int
746d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillernv50_2d_texture_set(struct nouveau_pushbuf *push, int dst,
75f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                    struct nv50_miptree *mt, unsigned level, unsigned layer)
7613393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs{
77f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nouveau_bo *bo = mt->base.bo;
78f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t width, height, depth;
79f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t format;
80f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT;
81f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t offset = mt->level[level].offset;
82f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
83f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   format = nv50_2d_format(mt->base.base.format);
84f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (!format) {
85f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      NOUVEAU_ERR("invalid/unsupported surface format: %s\n",
86f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                  util_format_name(mt->base.base.format));
87f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return 1;
88f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
89f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
90b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   width = u_minify(mt->base.base.width0, level) << mt->ms_x;
91b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   height = u_minify(mt->base.base.height0, level) << mt->ms_y;
92f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
93f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   offset = mt->level[level].offset;
94f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (!mt->layout_3d) {
95f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      offset += mt->layer_stride * layer;
96f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      depth = 1;
97f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      layer = 0;
98f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   } else {
99f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      depth = u_minify(mt->base.base.depth0, level);
100f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
101f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
1026d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   if (!nouveau_bo_memtype(bo)) {
1036d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, SUBC_2D(mthd), 2);
1046d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, format);
1056d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, 1);
1066d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, SUBC_2D(mthd + 0x14), 5);
1076d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, mt->level[level].pitch);
1086d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, width);
1096d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, height);
1106d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAh(push, bo->offset + offset);
1116d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, bo->offset + offset);
112f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   } else {
1136d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, SUBC_2D(mthd), 5);
1146d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, format);
1156d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, 0);
1166d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, mt->level[level].tile_mode);
1176d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, depth);
1186d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, layer);
1196d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, SUBC_2D(mthd + 0x18), 4);
1206d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, width);
1216d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, height);
1226d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAh(push, bo->offset + offset);
1236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, bo->offset + offset);
124f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
125f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
12613393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs#if 0
127f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (dst) {
1286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, SUBC_2D(NV50_2D_CLIP_X), 4);
1296d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, 0);
1306d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, 0);
1316d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, width);
1326d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, height);
133f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
13413393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs#endif
135f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   return 0;
13613393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs}
13713393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs
138f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillerstatic int
1396d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillernv50_2d_texture_do_copy(struct nouveau_pushbuf *push,
140f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                        struct nv50_miptree *dst, unsigned dst_level,
141f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                        unsigned dx, unsigned dy, unsigned dz,
142f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                        struct nv50_miptree *src, unsigned src_level,
143f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                        unsigned sx, unsigned sy, unsigned sz,
144f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                        unsigned w, unsigned h)
14513393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs{
146b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   static const uint32_t duvdxy[5] =
147b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   {
148b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      0x40000000, 0x80000000, 0x00000001, 0x00000002, 0x00000004
149b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   };
150b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
151f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   int ret;
152b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   uint32_t ctrl;
1536d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#if 0
154f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   ret = MARK_RING(chan, 2 * 16 + 32, 4);
155f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (ret)
156f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return ret;
1576d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#endif
1586d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   ret = nv50_2d_texture_set(push, 1, dst, dst_level, dz);
159f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (ret)
160f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return ret;
161f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
1626d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   ret = nv50_2d_texture_set(push, 0, src, src_level, sz);
163f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (ret)
164f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return ret;
165f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
166b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   /* NOTE: 2D engine doesn't work for MS8 */
167b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   if (src->ms_x)
168b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      ctrl = 0x11;
169b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
170b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   /* 0/1 = CENTER/CORNER, 00/10 = POINT/BILINEAR */
1716d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_2D(BLIT_CONTROL), 1);
1726d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, ctrl);
1736d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_2D(BLIT_DST_X), 4);
1746d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, dx << dst->ms_x);
1756d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, dy << dst->ms_y);
1766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, w << dst->ms_x);
1776d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, h << dst->ms_y);
1786d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_2D(BLIT_DU_DX_FRACT), 4);
1796d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, duvdxy[2 + ((int)src->ms_x - (int)dst->ms_x)] & 0xf0000000);
1806d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, duvdxy[2 + ((int)src->ms_x - (int)dst->ms_x)] & 0x0000000f);
1816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, duvdxy[2 + ((int)src->ms_y - (int)dst->ms_y)] & 0xf0000000);
1826d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, duvdxy[2 + ((int)src->ms_y - (int)dst->ms_y)] & 0x0000000f);
1836d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_2D(BLIT_SRC_X_FRACT), 4);
1846d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
1856d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, sx << src->ms_x);
1866d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
1876d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, sy << src->ms_y);
188f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
189f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   return 0;
19013393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs}
19113393736dbab1087589f8dd788bc412d16b431d1Ben Skeggs
192b8965bee404cb36ccd97ac089fbd3ffc63268080Ben Skeggsstatic void
193f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillernv50_resource_copy_region(struct pipe_context *pipe,
194f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                          struct pipe_resource *dst, unsigned dst_level,
195f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                          unsigned dstx, unsigned dsty, unsigned dstz,
196f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                          struct pipe_resource *src, unsigned src_level,
197f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                          const struct pipe_box *src_box)
198b8965bee404cb36ccd97ac089fbd3ffc63268080Ben Skeggs{
1996d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nv50_context *nv50 = nv50_context(pipe);
200f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   int ret;
2019e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller   boolean m2mf;
202f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   unsigned dst_layer = dstz, src_layer = src_box->z;
203f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
204883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák   /* Fallback for buffers. */
205883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák   if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
206883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák      util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
207883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák                                src, src_level, src_box);
208883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák      return;
209883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák   }
210883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák
211b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   /* 0 and 1 are equal, only supporting 0/1, 2, 4 and 8 */
212b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   assert((src->nr_samples | 1) == (dst->nr_samples | 1));
2139e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller
2149e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller   m2mf = (src->format == dst->format) ||
2159e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller      (util_format_get_blocksizebits(src->format) ==
2169e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller       util_format_get_blocksizebits(dst->format));
2179e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller
218b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   nv04_resource(dst)->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
219b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
2209e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller   if (m2mf) {
221b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      struct nv50_m2mf_rect drect, srect;
222b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      unsigned i;
223b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      unsigned nx = util_format_get_nblocksx(src->format, src_box->width);
224b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      unsigned ny = util_format_get_nblocksy(src->format, src_box->height);
225b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
226b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      nv50_m2mf_rect_setup(&drect, dst, dst_level, dstx, dsty, dstz);
227b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      nv50_m2mf_rect_setup(&srect, src, src_level,
228b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller                           src_box->x, src_box->y, src_box->z);
229b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
230b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      for (i = 0; i < src_box->depth; ++i) {
2316d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller         nv50_m2mf_transfer_rect(nv50, &drect, &srect, nx, ny);
232b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
233b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller         if (nv50_miptree(dst)->layout_3d)
234b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller            drect.z++;
235b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller         else
236b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller            drect.base += nv50_miptree(dst)->layer_stride;
237b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
238b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller         if (nv50_miptree(src)->layout_3d)
239b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller            srect.z++;
240b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller         else
241b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller            srect.base += nv50_miptree(src)->layer_stride;
242b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      }
243b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller      return;
244b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller   }
245b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
246f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   assert((src->format == dst->format) ||
247f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller          (nv50_2d_format_faithful(src->format) &&
248f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller           nv50_2d_format_faithful(dst->format)));
249f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
2506d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BCTX_REFN(nv50->bufctx, 2D, nv04_resource(src), RD);
2516d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BCTX_REFN(nv50->bufctx, 2D, nv04_resource(dst), WR);
2526d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   nouveau_pushbuf_bufctx(nv50->base.pushbuf, nv50->bufctx);
2536d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   nouveau_pushbuf_validate(nv50->base.pushbuf);
2546d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
255f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   for (; dst_layer < dstz + src_box->depth; ++dst_layer, ++src_layer) {
2566d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      ret = nv50_2d_texture_do_copy(nv50->base.pushbuf,
257f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                                    nv50_miptree(dst), dst_level,
258f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                                    dstx, dsty, dst_layer,
259f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                                    nv50_miptree(src), src_level,
260f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                                    src_box->x, src_box->y, src_layer,
261f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                                    src_box->width, src_box->height);
262f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      if (ret)
2636d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller         break;
264f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
2656d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   nouveau_bufctx_reset(nv50->bufctx, NV50_BIND_2D);
26647b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs}
26747b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs
268b8965bee404cb36ccd97ac089fbd3ffc63268080Ben Skeggsstatic void
269a6e5c6c000df8655de3b41d5809547bb41c88c23Roland Scheideggernv50_clear_render_target(struct pipe_context *pipe,
270f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         struct pipe_surface *dst,
2716dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie			 const union pipe_color_union *color,
272f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         unsigned dstx, unsigned dsty,
273f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         unsigned width, unsigned height)
274b8965bee404cb36ccd97ac089fbd3ffc63268080Ben Skeggs{
275f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_context *nv50 = nv50_context(pipe);
2766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_pushbuf *push = nv50->base.pushbuf;
277f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_miptree *mt = nv50_miptree(dst->texture);
278f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_surface *sf = nv50_surface(dst);
279f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nouveau_bo *bo = mt->base.bo;
280f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
2816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(CLEAR_COLOR(0)), 4);
2826d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, color->f[0]);
2836d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, color->f[1]);
2846d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, color->f[2]);
2856d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, color->f[3]);
2866d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#if 0
287f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (MARK_RING(chan, 18, 2))
288f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return;
2896d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#endif
2906d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(RT_CONTROL), 1);
2916d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 1);
2926d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(RT_ADDRESS_HIGH(0)), 5);
2936d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAh(push, bo->offset + sf->offset);
2946d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, bo->offset + sf->offset);
2956d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, nv50_format_table[dst->format].rt);
2966d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, mt->level[sf->base.u.tex.level].tile_mode);
2976d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
2986d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(RT_HORIZ(0)), 2);
2996d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   if (nouveau_bo_memtype(bo))
3006d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA(push, sf->width);
3010a3f0ff2645d03d5f572cc26932595b8df400505Christoph Bumiller   else
3026d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA(push, NV50_3D_RT_HORIZ_LINEAR | mt->level[0].pitch);
3036d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, sf->height);
3046d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(RT_ARRAY_MODE), 1);
3056d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 1);
3066d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
3076d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   if (!nouveau_bo_memtype(bo)) {
3086d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(ZETA_ENABLE), 1);
3096d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, 0);
3100a3f0ff2645d03d5f572cc26932595b8df400505Christoph Bumiller   }
3110a3f0ff2645d03d5f572cc26932595b8df400505Christoph Bumiller
312f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */
313f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
3146d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VIEWPORT_HORIZ(0)), 2);
3156d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (width << 16) | dstx);
3166d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (height << 16) | dsty);
317f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
3186d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
3196d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0x3c);
320f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
321f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   nv50->dirty |= NV50_NEW_FRAMEBUFFER;
3222ef1d759b34fb6e9795d70a7c7b6c6c274c64bf8Christoph Bumiller}
3232ef1d759b34fb6e9795d70a7c7b6c6c274c64bf8Christoph Bumiller
3242ef1d759b34fb6e9795d70a7c7b6c6c274c64bf8Christoph Bumillerstatic void
3252ef1d759b34fb6e9795d70a7c7b6c6c274c64bf8Christoph Bumillernv50_clear_depth_stencil(struct pipe_context *pipe,
326f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         struct pipe_surface *dst,
327f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         unsigned clear_flags,
328f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         double depth,
329f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         unsigned stencil,
330f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         unsigned dstx, unsigned dsty,
331f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         unsigned width, unsigned height)
332f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller{
333f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_context *nv50 = nv50_context(pipe);
3346d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_pushbuf *push = nv50->base.pushbuf;
335f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_miptree *mt = nv50_miptree(dst->texture);
336f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_surface *sf = nv50_surface(dst);
337f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nouveau_bo *bo = mt->base.bo;
338f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t mode = 0;
339f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
3406d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   assert(nouveau_bo_memtype(bo)); /* ZETA cannot be linear */
3410a3f0ff2645d03d5f572cc26932595b8df400505Christoph Bumiller
342f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (clear_flags & PIPE_CLEAR_DEPTH) {
3436d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(CLEAR_DEPTH), 1);
3446d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAf(push, depth);
345f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      mode |= NV50_3D_CLEAR_BUFFERS_Z;
346f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
347f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
348f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (clear_flags & PIPE_CLEAR_STENCIL) {
3496d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(CLEAR_STENCIL), 1);
3506d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, stencil & 0xff);
351f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      mode |= NV50_3D_CLEAR_BUFFERS_S;
352f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
3536d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#if 0
354f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (MARK_RING(chan, 17, 2))
355f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return;
3566d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#endif
3576d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(ZETA_ADDRESS_HIGH), 5);
3586d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAh(push, bo->offset + sf->offset);
3596d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, bo->offset + sf->offset);
3606d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, nv50_format_table[dst->format].rt);
3616d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, mt->level[sf->base.u.tex.level].tile_mode);
3626d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
3636d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(ZETA_ENABLE), 1);
3646d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 1);
3656d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(ZETA_HORIZ), 3);
3666d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, sf->width);
3676d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, sf->height);
3686d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (1 << 16) | 1);
3696d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
3706d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VIEWPORT_HORIZ(0)), 2);
3716d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (width << 16) | dstx);
3726d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (height << 16) | dsty);
3736d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
3746d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
3756d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, mode);
376f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
377f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   nv50->dirty |= NV50_NEW_FRAMEBUFFER;
378f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller}
379f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
380f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillervoid
381f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillernv50_clear(struct pipe_context *pipe, unsigned buffers,
3826dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie           const union pipe_color_union *color,
3836dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie           double depth, unsigned stencil)
3842ef1d759b34fb6e9795d70a7c7b6c6c274c64bf8Christoph Bumiller{
385f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_context *nv50 = nv50_context(pipe);
3866d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_pushbuf *push = nv50->base.pushbuf;
387f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct pipe_framebuffer_state *fb = &nv50->framebuffer;
388f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   unsigned i;
389f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t mode = 0;
390f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
391f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
392222b3ea653e5525a4afa57e6a2353335953012d4Christoph Bumiller   if (!nv50_state_validate(nv50, NV50_NEW_FRAMEBUFFER, 9 + (fb->nr_cbufs * 2)))
393f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      return;
394f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
395f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {
3966d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(CLEAR_COLOR(0)), 4);
3976d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAf(push, color->f[0]);
3986d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAf(push, color->f[1]);
3996d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAf(push, color->f[2]);
4006d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATAf(push, color->f[3]);
401f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      mode =
402f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller         NV50_3D_CLEAR_BUFFERS_R | NV50_3D_CLEAR_BUFFERS_G |
403f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller         NV50_3D_CLEAR_BUFFERS_B | NV50_3D_CLEAR_BUFFERS_A;
404f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
405f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
406f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (buffers & PIPE_CLEAR_DEPTH) {
4076d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(CLEAR_DEPTH), 1);
4086d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, fui(depth));
409f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      mode |= NV50_3D_CLEAR_BUFFERS_Z;
410f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
411f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
412f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   if (buffers & PIPE_CLEAR_STENCIL) {
4136d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(CLEAR_STENCIL), 1);
4146d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, stencil & 0xff);
415f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller      mode |= NV50_3D_CLEAR_BUFFERS_S;
416f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
417f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
4186d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
4196d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, mode);
420f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
421f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   for (i = 1; i < fb->nr_cbufs; i++) {
4226d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
4236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller      PUSH_DATA (push, (i << 6) | 0x3c);
424f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   }
425b8965bee404cb36ccd97ac089fbd3ffc63268080Ben Skeggs}
42647b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs
427e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
428e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstruct nv50_blitctx
429e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
430e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_screen *screen;
431e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct {
432e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      struct pipe_framebuffer_state fb;
433e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      struct nv50_program *vp;
434e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      struct nv50_program *gp;
435e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      struct nv50_program *fp;
436e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      unsigned num_textures[3];
437e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      unsigned num_samplers[3];
438b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      struct pipe_sampler_view *texture[2];
439b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      struct nv50_tsc_entry *sampler[2];
440e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      unsigned dirty;
441e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   } saved;
442e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_program vp;
443e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_program fp;
444e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_tsc_entry sampler[2]; /* nearest, bilinear */
445e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   uint32_t fp_offset;
446e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   uint16_t color_mask;
447e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   uint8_t filter;
448e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller};
449e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
450e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
451e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_make_vp(struct nv50_blitctx *blit)
452e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
453e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   static const uint32_t code[] =
454e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   {
455e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x10000001, /* mov b32 o[0x00] s[0x00] */ /* HPOS.x */
456e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0423c788,
457e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x10000205, /* mov b32 o[0x04] s[0x04] */ /* HPOS.y */
458e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0423c788,
459e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x10000409, /* mov b32 o[0x08] s[0x08] */ /* TEXC.x */
460e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0423c788,
461e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x1000060d, /* mov b32 o[0x0c] s[0x0c] */ /* TEXC.y */
462e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0423c788,
463e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x10000811, /* exit mov b32 o[0x10] s[0x10] */ /* TEXC.z */
464e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0423c789,
465e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   };
466e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
467e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.type = PIPE_SHADER_VERTEX;
468e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.translated = TRUE;
469e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.code = (uint32_t *)code; /* const_cast */
470e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.code_size = sizeof(code);
471e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.max_gpr = 4;
472e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.max_out = 5;
473e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.out_nr = 2;
474e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.out[0].mask = 0x3;
475e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.out[0].sn = TGSI_SEMANTIC_POSITION;
476e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.out[1].hw = 2;
477e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.out[1].mask = 0x7;
478e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.out[1].sn = TGSI_SEMANTIC_GENERIC;
479e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.vp.attrs[0] = 0x73;
480e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.vp.psiz = 0x40;
481e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->vp.vp.edgeflag = 0x40;
482e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
483e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
484e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
485e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_make_fp(struct nv50_blitctx *blit)
486e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
487e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   static const uint32_t code[] =
488e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   {
489866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie      /* 3 coords RGBA in, RGBA out, also for Z32_FLOAT(_S8X24_UINT) */
490e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80000000, /* interp $r0 v[0x0] */
491e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80010004, /* interp $r1 v[0x4] */
492e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80020009, /* interp $r2 flat v[0x8] */
493e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x00040780,
494e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xf6800001, /* texauto live { $r0,1,2,3 } $t0 $s0 { $r0,1,2 } */
495e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0000c785, /* exit */
496e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
497e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      /* 3 coords ZS in, S encoded in R, Z encoded in GBA (8_UNORM) */
498e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80000000, /* interp $r0 v[0x00] */
499e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80010004, /* interp $r1 v[0x04] */
500b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x80020108, /* interp $r2 flat v[0x8] */
501b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x10008010, /* mov b32 $r4 $r0 */
502b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xf2820201, /* texauto live { $r0,#,#,# } $t1 $s1 { $r0,1,2 } */
503b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x00000784,
504b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xa000000d, /* cvt f32 $r3 s32 $r0 */
505b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x44014780,
506b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x10000801, /* mov b32 $r0 $r4 */
507b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x0403c780,
508b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xf2800001, /* texauto live { $r0,#,#,# } $t0 $s0 { $r0,1,2 } */
509e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x00000784,
510e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc03f0009, /* mul f32 $r2 $r0 (2^24 - 1) */
511e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x04b7ffff,
512e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000409, /* cvt rni s32 $r2 f32 $r2 */
513e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x8c004780,
514b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xc0010601, /* mul f32 $r0 $r3 1/0xff */
515e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x03b8080b,
516e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xd03f0405, /* and b32 $r1 $r2 0x0000ff */
517e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0000000f,
518e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xd000040d, /* and b32 $r3 $r2 0xff0000 */
519e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x000ff003,
520e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xd0000409, /* and b32 $r2 $r2 0x00ff00 */
521e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x00000ff3,
522e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000205, /* cvt f32 $r1 s32 $r1 */
523e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x44014780,
524e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa000060d, /* cvt f32 $r3 s32 $r3 */
525e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x44014780,
526e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000409, /* cvt f32 $r2 s32 $r2 */
527e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x44014780,
528e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc0010205, /* mul f32 $r1 $r1 1/0x0000ff */
529e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x03b8080b,
530e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc001060d, /* mul f32 $r3 $r3 1/0x00ff00 */
531e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0338080b,
532e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc0010409, /* mul f32 $r2 $r2 1/0xff0000 */
533e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0378080b,
534e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xf0000001, /* exit never nop */
535e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xe0000001,
536e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
537e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      /* 3 coords ZS in, Z encoded in RGB, S encoded in A (U8_UNORM) */
538e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80000000, /* interp $r0 v[0x00] */
539e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x80010004, /* interp $r1 v[0x04] */
540b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x80020108, /* interp $r2 flat v[0x8] */
541b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x10008010, /* mov b32 $r4 $r0 */
542b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xf2820201, /* texauto live { $r0,#,#,# } $t1 $s1 { $r0,1,2 } */
543b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x00000784,
544b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xa000000d, /* cvt f32 $r3 s32 $r0 */
545b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x44014780,
546b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x10000801, /* mov b32 $r0 $r4 */
547b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0x0403c780,
548b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      0xf2800001, /* texauto live { $r0,#,#,# } $t0 $s0 { $r0,1,2 } */
549e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x00000784,
550e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc03f0009, /* mul f32 $r2 $r0 (2^24 - 1) */
551e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x04b7ffff,
552e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000409, /* cvt rni s32 $r2 f32 $r2 */
553e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x8c004780,
554e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc001060d, /* mul f32 $r3 $r3 1/0xff */
555e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x03b8080b,
556e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xd03f0401, /* and b32 $r0 $r2 0x0000ff */
557e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0000000f,
558e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xd0000405, /* and b32 $r1 $r2 0x00ff00 */
559e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x00000ff3,
560e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xd0000409, /* and b32 $r2 $r2 0xff0000 */
561e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x000ff003,
562e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000001, /* cvt f32 $r0 s32 $r0 */
563e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x44014780,
564e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000205, /* cvt f32 $r1 s32 $r1 */
565e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x44014780,
566e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xa0000409, /* cvt f32 $r2 s32 $r2 */
567e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x44014780,
568e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc0010001, /* mul f32 $r0 $r0 1/0x0000ff */
569e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x03b8080b,
570e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc0010205, /* mul f32 $r1 $r1 1/0x00ff00 */
571e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0378080b,
572e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xc0010409, /* mul f32 $r2 $r2 1/0xff0000 */
573e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0x0338080b,
574e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xf0000001, /* exit never nop */
575e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      0xe0000001
576e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   };
577e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
578e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.type = PIPE_SHADER_FRAGMENT;
579e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.translated = TRUE;
580e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.code = (uint32_t *)code; /* const_cast */
581e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.code_size = sizeof(code);
582b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   blit->fp.max_gpr = 5;
583e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.max_out = 4;
584e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.in_nr = 1;
585e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.in[0].mask = 0x7; /* last component flat */
586e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.in[0].linear = 1;
587e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.in[0].sn = TGSI_SEMANTIC_GENERIC;
588e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.out_nr = 1;
589e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.out[0].mask = 0xf;
590e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.out[0].sn = TGSI_SEMANTIC_COLOR;
591e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.fp.interp = 0x00020403;
592e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->fp.gp.primid = 0x80;
593e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
594e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
595e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
596e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_make_sampler(struct nv50_blitctx *blit)
597e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
598e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* clamp to edge, min/max lod = 0, nearest filtering */
599e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
600e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->sampler[0].id = -1;
601e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
6028592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller   blit->sampler[0].tsc[0] = NV50_TSC_0_SRGB_CONVERSION_ALLOWED |
6038592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller      (NV50_TSC_WRAP_CLAMP_TO_EDGE << NV50_TSC_0_WRAPS__SHIFT) |
6048592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller      (NV50_TSC_WRAP_CLAMP_TO_EDGE << NV50_TSC_0_WRAPT__SHIFT) |
6058592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller      (NV50_TSC_WRAP_CLAMP_TO_EDGE << NV50_TSC_0_WRAPR__SHIFT);
6068592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller   blit->sampler[0].tsc[1] =
6078592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller      NV50_TSC_1_MAGF_NEAREST | NV50_TSC_1_MINF_NEAREST | NV50_TSC_1_MIPF_NONE;
608e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
609e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* clamp to edge, min/max lod = 0, bilinear filtering */
610e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
611e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->sampler[1].id = -1;
612e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
6138592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller   blit->sampler[1].tsc[0] = blit->sampler[0].tsc[0];
6148592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller   blit->sampler[1].tsc[1] =
6158592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller      NV50_TSC_1_MAGF_LINEAR | NV50_TSC_1_MINF_LINEAR | NV50_TSC_1_MIPF_NONE;
616e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
617e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
618e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller/* Since shaders cannot export stencil, we cannot copy stencil values when
619e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller * rendering to ZETA, so we attach the ZS surface to a colour render target.
620e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller */
621e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic INLINE enum pipe_format
622e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blit_zeta_to_colour_format(enum pipe_format format)
623e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
624e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   switch (format) {
625e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   case PIPE_FORMAT_Z16_UNORM:               return PIPE_FORMAT_R16_UNORM;
626866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
627866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
628e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   case PIPE_FORMAT_Z24X8_UNORM:             return PIPE_FORMAT_R8G8B8A8_UNORM;
629e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   case PIPE_FORMAT_Z32_FLOAT:               return PIPE_FORMAT_R32_FLOAT;
630866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: return PIPE_FORMAT_R32G32_FLOAT;
631e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   default:
632e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      assert(0);
633e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      return PIPE_FORMAT_NONE;
634e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   }
635e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
636e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
637e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
638e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_get_color_mask_and_fp(struct nv50_blitctx *blit,
639e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller                                   enum pipe_format format, uint8_t mask)
640e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
641e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->color_mask = 0;
642e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
643e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   switch (format) {
644e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   case PIPE_FORMAT_Z24X8_UNORM:
645866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
646cd3d85b63daf59a0574fe99dc516e043a1c9c329Christoph Bumiller      blit->fp_offset = 0xb0;
647e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & PIPE_MASK_Z)
648e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller         blit->color_mask |= 0x0111;
649e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & PIPE_MASK_S)
650e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller         blit->color_mask |= 0x1000;
651e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      break;
652866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
653cd3d85b63daf59a0574fe99dc516e043a1c9c329Christoph Bumiller      blit->fp_offset = 0x18;
654e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & PIPE_MASK_Z)
655e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller         blit->color_mask |= 0x1110;
656e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & PIPE_MASK_S)
657e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller         blit->color_mask |= 0x0001;
658e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      break;
659e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   default:
660e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      blit->fp_offset = 0;
661e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & (PIPE_MASK_R | PIPE_MASK_Z)) blit->color_mask |= 0x0001;
662e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & (PIPE_MASK_G | PIPE_MASK_S)) blit->color_mask |= 0x0010;
663e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & PIPE_MASK_B) blit->color_mask |= 0x0100;
664e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      if (mask & PIPE_MASK_A) blit->color_mask |= 0x1000;
665e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      break;
666e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   }
667e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
668e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
669e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
6706286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumillernv50_blit_set_dst(struct nv50_context *nv50,
6716286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller                  struct pipe_resource *res, unsigned level, unsigned layer)
672e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
6736286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   struct pipe_context *pipe = &nv50->base.pipe;
6746286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   struct pipe_surface templ;
675e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
6766286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   if (util_format_is_depth_or_stencil(res->format))
6776286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller      templ.format = nv50_blit_zeta_to_colour_format(res->format);
6786286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   else
6796286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller      templ.format = res->format;
6806286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller
6816286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   templ.usage = PIPE_USAGE_STREAM;
6826286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   templ.u.tex.level = level;
6836286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   templ.u.tex.first_layer = templ.u.tex.last_layer = layer;
684e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
6856286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   nv50->framebuffer.cbufs[0] = nv50_miptree_surface_new(pipe, res, &templ);
686e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.nr_cbufs = 1;
687e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.zsbuf = NULL;
6886286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   nv50->framebuffer.width = nv50->framebuffer.cbufs[0]->width;
6896286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   nv50->framebuffer.height = nv50->framebuffer.cbufs[0]->height;
690e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
691e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
692e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic INLINE void
693e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blit_fixup_tic_entry(struct pipe_sampler_view *view)
694e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
695e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_tic_entry *ent = nv50_tic_entry(view);
696e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
697e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   ent->tic[2] &= ~(1 << 31); /* scaled coordinates, ok with 3d textures ? */
698e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
699e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* magic: */
700e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
701e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   ent->tic[3] = 0x20000000; /* affects quality of near vertical edges in MS8 */
702e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
703e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
704e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
705e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blit_set_src(struct nv50_context *nv50,
706e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller                  struct pipe_resource *res, unsigned level, unsigned layer)
707e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
708e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct pipe_context *pipe = &nv50->base.pipe;
709e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct pipe_sampler_view templ;
710e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
711e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.format = res->format;
712e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.u.tex.first_layer = templ.u.tex.last_layer = layer;
713e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.u.tex.first_level = templ.u.tex.last_level = level;
714e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.swizzle_r = PIPE_SWIZZLE_RED;
715e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.swizzle_g = PIPE_SWIZZLE_GREEN;
716e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.swizzle_b = PIPE_SWIZZLE_BLUE;
717e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   templ.swizzle_a = PIPE_SWIZZLE_ALPHA;
718e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
719e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->textures[2][0] = nv50_create_sampler_view(pipe, res, &templ);
7209ef549d7cd9aa14ab7c404609f38e2e6195b4335Christoph Bumiller   nv50->textures[2][1] = NULL;
721e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
722e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blit_fixup_tic_entry(nv50->textures[2][0]);
723e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
724e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->num_textures[0] = nv50->num_textures[1] = 0;
725e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->num_textures[2] = 1;
726b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller
727b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   templ.format = nv50_zs_to_s_format(res->format);
728b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   if (templ.format != res->format) {
729b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      nv50->textures[2][1] = nv50_create_sampler_view(pipe, res, &templ);
730b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      nv50_blit_fixup_tic_entry(nv50->textures[2][1]);
731b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      nv50->num_textures[2] = 2;
732b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   }
733e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
734e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
735e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
736e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_prepare_state(struct nv50_blitctx *blit)
737e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
7386d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_pushbuf *push = blit->screen->base.pushbuf;
739e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
740e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* blend state */
7416d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(COLOR_MASK(0)), 1);
7426d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, blit->color_mask);
7436d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(BLEND_ENABLE(0)), 1);
7446d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7456d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(LOGIC_OP_ENABLE), 1);
7466d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
747e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
748e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* rasterizer state */
749e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller#ifndef NV50_SCISSORS_CLIPPING
7506d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(SCISSOR_ENABLE(0)), 1);
7516d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 1);
752e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller#endif
7536d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VERTEX_TWO_SIDE_ENABLE), 1);
7546d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7556d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(FRAG_COLOR_CLAMP_EN), 1);
7566d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7576d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(MULTISAMPLE_ENABLE), 1);
7586d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7596d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(MSAA_MASK(0)), 4);
7606d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0xffff);
7616d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0xffff);
7626d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0xffff);
7636d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0xffff);
7646d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(POLYGON_MODE_FRONT), 3);
7656d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, NV50_3D_POLYGON_MODE_FRONT_FILL);
7666d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, NV50_3D_POLYGON_MODE_BACK_FILL);
7676d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7686d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(CULL_FACE_ENABLE), 1);
7696d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7706d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(POLYGON_STIPPLE_ENABLE), 1);
7716d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7726d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(POLYGON_OFFSET_FILL_ENABLE), 1);
7736d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
774e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
775e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* zsa state */
7766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(DEPTH_TEST_ENABLE), 1);
7776d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7786d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(STENCIL_ENABLE), 1);
7796d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
7806d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(ALPHA_TEST_ENABLE), 1);
7816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
782e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
783e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
784e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
785e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_pre_blit(struct nv50_blitctx *blit, struct nv50_context *nv50)
786e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
787e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   int s;
788e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
789e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.fb.width = nv50->framebuffer.width;
790e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.fb.height = nv50->framebuffer.height;
791e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.fb.nr_cbufs = nv50->framebuffer.nr_cbufs;
792e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.fb.cbufs[0] = nv50->framebuffer.cbufs[0];
793e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.fb.zsbuf = nv50->framebuffer.zsbuf;
794e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
795e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.vp = nv50->vertprog;
796e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.gp = nv50->gmtyprog;
797e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.fp = nv50->fragprog;
798e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
799e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->vertprog = &blit->vp;
800e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->gmtyprog = NULL;
801e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->fragprog = &blit->fp;
802e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
803e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   for (s = 0; s < 3; ++s) {
804e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      blit->saved.num_textures[s] = nv50->num_textures[s];
805e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      blit->saved.num_samplers[s] = nv50->num_samplers[s];
806e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   }
807b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   blit->saved.texture[0] = nv50->textures[2][0];
808b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   blit->saved.texture[1] = nv50->textures[2][1];
809b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   blit->saved.sampler[0] = nv50->samplers[2][0];
810b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   blit->saved.sampler[1] = nv50->samplers[2][1];
811e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
812e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->samplers[2][0] = &blit->sampler[blit->filter];
813b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   nv50->samplers[2][1] = &blit->sampler[blit->filter];
814e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
815e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->num_samplers[0] = nv50->num_samplers[1] = 0;
816b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   nv50->num_samplers[2] = 2;
817e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
818e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->saved.dirty = nv50->dirty;
819e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
820e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->dirty =
821e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      NV50_NEW_FRAMEBUFFER |
822e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      NV50_NEW_VERTPROG | NV50_NEW_FRAGPROG | NV50_NEW_GMTYPROG |
823e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      NV50_NEW_TEXTURES | NV50_NEW_SAMPLERS;
824e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
825e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
826e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
827e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_post_blit(struct nv50_context *nv50, struct nv50_blitctx *blit)
828e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
829e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   int s;
830e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
8316286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   pipe_surface_reference(&nv50->framebuffer.cbufs[0], NULL);
832e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
833e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.width = blit->saved.fb.width;
834e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.height = blit->saved.fb.height;
835e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.nr_cbufs = blit->saved.fb.nr_cbufs;
836e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.cbufs[0] = blit->saved.fb.cbufs[0];
837e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->framebuffer.zsbuf = blit->saved.fb.zsbuf;
838e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
839e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->vertprog = blit->saved.vp;
840e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->gmtyprog = blit->saved.gp;
841e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->fragprog = blit->saved.fp;
842e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
843e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   pipe_sampler_view_reference(&nv50->textures[2][0], NULL);
844b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   pipe_sampler_view_reference(&nv50->textures[2][1], NULL);
845e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
846e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   for (s = 0; s < 3; ++s) {
847e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      nv50->num_textures[s] = blit->saved.num_textures[s];
848e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      nv50->num_samplers[s] = blit->saved.num_samplers[s];
849e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   }
850b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   nv50->textures[2][0] = blit->saved.texture[0];
851b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   nv50->textures[2][1] = blit->saved.texture[1];
852b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   nv50->samplers[2][0] = blit->saved.sampler[0];
853b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   nv50->samplers[2][1] = blit->saved.sampler[1];
854e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
855e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50->dirty = blit->saved.dirty |
856e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      (NV50_NEW_FRAMEBUFFER | NV50_NEW_SCISSOR | NV50_NEW_SAMPLE_MASK |
857e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller       NV50_NEW_RASTERIZER | NV50_NEW_ZSA | NV50_NEW_BLEND |
858e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller       NV50_NEW_TEXTURES | NV50_NEW_SAMPLERS |
859e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller       NV50_NEW_VERTPROG | NV50_NEW_GMTYPROG | NV50_NEW_FRAGPROG);
860e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
861e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
862e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerstatic void
863e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_resource_resolve(struct pipe_context *pipe,
864e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller                      const struct pipe_resolve_info *info)
865e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
866e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_context *nv50 = nv50_context(pipe);
867e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_screen *screen = nv50->screen;
868e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct nv50_blitctx *blit = screen->blitctx;
8696d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_pushbuf *push = nv50->base.pushbuf;
870e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   struct pipe_resource *src = info->src.res;
8716286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   struct pipe_resource *dst = info->dst.res;
872e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   float x0, x1, y0, y1, z;
873e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   float x_range, y_range;
874e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
875e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_get_color_mask_and_fp(blit, dst->format, info->mask);
876e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
877e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   blit->filter = util_format_is_depth_or_stencil(dst->format) ? 0 : 1;
878e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
879e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_pre_blit(blit, nv50);
880e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
8816286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   nv50_blit_set_dst(nv50, dst, info->dst.level, info->dst.layer);
8826286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller   nv50_blit_set_src(nv50, src, 0,               info->src.layer);
883e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
884e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_prepare_state(blit);
885e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
886222b3ea653e5525a4afa57e6a2353335953012d4Christoph Bumiller   nv50_state_validate(nv50, ~0, 36);
887e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
888e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   x_range =
889e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      (float)(info->src.x1 - info->src.x0) /
890e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      (float)(info->dst.x1 - info->dst.x0);
891e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   y_range =
892e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      (float)(info->src.y1 - info->src.y0) /
893e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      (float)(info->dst.y1 - info->dst.y0);
894e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
895e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   x0 = (float)info->src.x0 - x_range * (float)info->dst.x0;
896e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   y0 = (float)info->src.y0 - y_range * (float)info->dst.y0;
897e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
898e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   x1 = x0 + 16384.0f * x_range;
899e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   y1 = y0 + 16384.0f * y_range;
900e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
901e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   x0 *= (float)(1 << nv50_miptree(src)->ms_x);
902e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   x1 *= (float)(1 << nv50_miptree(src)->ms_x);
903e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   y0 *= (float)(1 << nv50_miptree(src)->ms_y);
904e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   y1 *= (float)(1 << nv50_miptree(src)->ms_y);
905e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
906e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   z = (float)info->src.layer;
907e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
9086d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(FP_START_ID), 1);
9096d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push,
910e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller              blit->fp.code_base + blit->fp_offset);
911e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
9126d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VIEWPORT_TRANSFORM_EN), 1);
9136d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
914e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
915e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* Draw a large triangle in screen coordinates covering the whole
916e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller    * render target, with scissors defining the destination region.
917e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller    * The vertex is supplied with non-normalized texture coordinates
918e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller    * arranged in a way to yield the desired offset and scale.
919e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller    */
920e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
9216d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(SCISSOR_HORIZ(0)), 2);
9226d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (info->dst.x1 << 16) | info->dst.x0);
9236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, (info->dst.y1 << 16) | info->dst.y0);
9246d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
9256d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VERTEX_BEGIN_GL), 1);
9266d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_TRIANGLES);
9276d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VTX_ATTR_3F_X(1)), 3);
9286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, x0);
9296d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, y0);
9306d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, z);
9316d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VTX_ATTR_2F_X(0)), 2);
9326d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, 0.0f);
9336d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, 0.0f);
9346d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VTX_ATTR_3F_X(1)), 3);
9356d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, x1);
9366d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, y0);
9376d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, z);
9386d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VTX_ATTR_2F_X(0)), 2);
9396d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, 16384 << nv50_miptree(dst)->ms_x);
9406d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, 0.0f);
9416d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VTX_ATTR_3F_X(1)), 3);
9426d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, x0);
9436d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, y1);
9446d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, z);
9456d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VTX_ATTR_2F_X(0)), 2);
9466d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, 0.0f);
9476d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATAf(push, 16384 << nv50_miptree(dst)->ms_y);
9486d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VERTEX_END_GL), 1);
9496d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 0);
950e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
951e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   /* re-enable normally constant state */
952e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
9536d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   BEGIN_NV04(push, NV50_3D(VIEWPORT_TRANSFORM_EN), 1);
9546d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, 1);
955e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
956e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_post_blit(nv50, blit);
957e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
958e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
959e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillerboolean
960e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumillernv50_blitctx_create(struct nv50_screen *screen)
961e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller{
962e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   screen->blitctx = CALLOC_STRUCT(nv50_blitctx);
963e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   if (!screen->blitctx) {
964e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      NOUVEAU_ERR("failed to allocate blit context\n");
965e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller      return FALSE;
966e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   }
967e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
968e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   screen->blitctx->screen = screen;
969e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
970e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_make_vp(screen->blitctx);
971e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_make_fp(screen->blitctx);
972e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
973e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   nv50_blitctx_make_sampler(screen->blitctx);
974e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
975e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   screen->blitctx->color_mask = 0x1111;
976e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
977e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   return TRUE;
978e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller}
979e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller
98047b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggsvoid
98147b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggsnv50_init_surface_functions(struct nv50_context *nv50)
98247b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs{
9831ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   struct pipe_context *pipe = &nv50->base.pipe;
9841ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs
9851ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->resource_copy_region = nv50_resource_copy_region;
986e9d84dab8817a0a7e463229b9a2820b00a9ce667Christoph Bumiller   pipe->resource_resolve = nv50_resource_resolve;
9871ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->clear_render_target = nv50_clear_render_target;
9881ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs   pipe->clear_depth_stencil = nv50_clear_depth_stencil;
98947b418b8fa5fd242e9021503d6ec329ac3d56fb0Ben Skeggs}
99065ad8176ca91b5ed2a01b1b3ee145cfdce369419Ben Skeggs
99165ad8176ca91b5ed2a01b1b3ee145cfdce369419Ben Skeggs
992