nvc0_surface.c revision 8e1dd58a7e76834c1fb6d117b6ea5755e05cfb77
14c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller/* 24c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Copyright 2008 Ben Skeggs 34c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * 44c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Permission is hereby granted, free of charge, to any person obtaining a 54c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * copy of this software and associated documentation files (the "Software"), 64c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * to deal in the Software without restriction, including without limitation 74c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * the rights to use, copy, modify, merge, publish, distribute, sublicense, 84c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * and/or sell copies of the Software, and to permit persons to whom the 94c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * Software is furnished to do so, subject to the following conditions: 104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * 114c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * The above copyright notice and this permission notice shall be included in 124c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * all copies or substantial portions of the Software. 134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * 144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 154c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * SOFTWARE. 214c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */ 224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include <stdint.h> 244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 254c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "pipe/p_defines.h" 264c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "util/u_inlines.h" 284c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "util/u_pack_color.h" 294c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "util/u_format.h" 30883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák#include "util/u_surface.h" 314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller#include "os/os_thread.h" 3336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_context.h" 354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#include "nvc0_resource.h" 364c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 37e4c968cdbbdc020afbf869d12b536c0a0dbf9de8Christoph Bumiller#include "nv50/nv50_defs.xml.h" 388592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller#include "nv50/nv50_texture.xml.h" 394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 40d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller/* these are used in nv50_blit.h */ 41d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#define NV50_ENG2D_SUPPORTED_FORMATS 0xff9ccfe1cce3ccc9ULL 42d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#define NV50_ENG2D_NOCONVERT_FORMATS 0x009cc02000000000ULL 43d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#define NV50_ENG2D_LUMINANCE_FORMATS 0x001cc02000000000ULL 44d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#define NV50_ENG2D_INTENSITY_FORMATS 0x0080000000000000ULL 45d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#define NV50_ENG2D_OPERATION_FORMATS 0x060001c000638000ULL 461b4c0c8ea0b4e6065f23f9f2bbb954a7bd2549e4Christoph Bumiller 47d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#define NOUVEAU_DRIVER 0xc0 48d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller#include "nv50/nv50_blit.h" 494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic INLINE uint8_t 51d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumillernvc0_2d_format(enum pipe_format format, boolean dst, boolean dst_src_equal) 524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller uint8_t id = nvc0_format_table[format].rt; 544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 55d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller /* A8_UNORM is treated as I8_UNORM as far as the 2D engine is concerned. */ 56d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (!dst && unlikely(format == PIPE_FORMAT_I8_UNORM) && !dst_src_equal) 57d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller return NV50_SURFACE_FORMAT_A8_UNORM; 58d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller 594c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller /* Hardware values for color formats range from 0xc0 to 0xff, 604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller * but the 2D engine doesn't support all of them. 614c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller */ 62d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (nv50_2d_format_supported(format)) 634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return id; 64d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller assert(dst_src_equal); 654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 664c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller switch (util_format_get_blocksize(format)) { 674c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case 1: 684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return NV50_SURFACE_FORMAT_R8_UNORM; 694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case 2: 704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return NV50_SURFACE_FORMAT_R16_UNORM; 714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller case 4: 727e2827fad95071e04e382be0117c654445764c52Christoph Bumiller return NV50_SURFACE_FORMAT_BGRA8_UNORM; 731b4c0c8ea0b4e6065f23f9f2bbb954a7bd2549e4Christoph Bumiller case 8: 747e2827fad95071e04e382be0117c654445764c52Christoph Bumiller return NV50_SURFACE_FORMAT_RGBA16_UNORM; 751b4c0c8ea0b4e6065f23f9f2bbb954a7bd2549e4Christoph Bumiller case 16: 767e2827fad95071e04e382be0117c654445764c52Christoph Bumiller return NV50_SURFACE_FORMAT_RGBA32_FLOAT; 774c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller default: 78d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller assert(0); 794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return 0; 804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 814c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 824c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 834c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic int 846d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillernvc0_2d_texture_set(struct nouveau_pushbuf *push, boolean dst, 8536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nv50_miptree *mt, unsigned level, unsigned layer, 86d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller enum pipe_format pformat, boolean dst_src_pformat_equal) 874c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 88ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller struct nouveau_bo *bo = mt->base.bo; 89ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller uint32_t width, height, depth; 90ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller uint32_t format; 91ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller uint32_t mthd = dst ? NVC0_2D_DST_FORMAT : NVC0_2D_SRC_FORMAT; 92ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller uint32_t offset = mt->level[level].offset; 93ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller 94d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller format = nvc0_2d_format(pformat, dst, dst_src_pformat_equal); 954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (!format) { 964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NOUVEAU_ERR("invalid/unsupported surface format: %s\n", 9736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller util_format_name(pformat)); 984c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return 1; 994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1004c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 101b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller width = u_minify(mt->base.base.width0, level) << mt->ms_x; 102b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller height = u_minify(mt->base.base.height0, level) << mt->ms_y; 1034fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller depth = u_minify(mt->base.base.depth0, level); 1044fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller 1054fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller /* layer has to be < depth, and depth > tile depth / 2 */ 106ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller 107ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller if (!mt->layout_3d) { 108ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller offset += mt->layer_stride * layer; 1094fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller layer = 0; 110ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller depth = 1; 1114fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller } else 1124fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller if (!dst) { 113cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller offset += nvc0_mt_zslice_offset(mt, level, layer); 114ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller layer = 0; 115ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller } 116ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller 11736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!nouveau_bo_memtype(bo)) { 1186d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, SUBC_2D(mthd), 2); 1196d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, format); 1206d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 1); 1216d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, SUBC_2D(mthd + 0x14), 5); 1226d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mt->level[level].pitch); 1236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, width); 1246d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, height); 1256d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAh(push, bo->offset + offset); 1266d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, bo->offset + offset); 1274c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } else { 1286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, SUBC_2D(mthd), 5); 1296d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, format); 1306d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0); 1316d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mt->level[level].tile_mode); 1326d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, depth); 1336d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, layer); 1346d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, SUBC_2D(mthd + 0x18), 4); 1356d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, width); 1366d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, height); 1376d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAh(push, bo->offset + offset); 1386d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, bo->offset + offset); 1394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 140ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller 1414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#if 0 1424c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (dst) { 1436d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, SUBC_2D(NVC0_2D_CLIP_X), 4); 1446d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0); 1456d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0); 1466d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, width); 1476d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, height); 1484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 1494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller#endif 1504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return 0; 1514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 1524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic int 1546d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillernvc0_2d_texture_do_copy(struct nouveau_pushbuf *push, 155cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller struct nv50_miptree *dst, unsigned dst_level, 156ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned dx, unsigned dy, unsigned dz, 157cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller struct nv50_miptree *src, unsigned src_level, 158ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned sx, unsigned sy, unsigned sz, 159ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned w, unsigned h) 1604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 16136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const enum pipe_format dfmt = dst->base.base.format; 16236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const enum pipe_format sfmt = src->base.base.format; 1634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller int ret; 164d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller boolean eqfmt = dfmt == sfmt; 1654c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 166edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst if (!PUSH_SPACE(push, 2 * 16 + 32)) 167edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst return PIPE_ERROR; 1684c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 169d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller ret = nvc0_2d_texture_set(push, TRUE, dst, dst_level, dz, dfmt, eqfmt); 1704c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (ret) 1714c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return ret; 1724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 173d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller ret = nvc0_2d_texture_set(push, FALSE, src, src_level, sz, sfmt, eqfmt); 1744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (ret) 1754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return ret; 1764c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 17736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_2D(BLIT_CONTROL), 0x00); 1786d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_DST_X), 4); 1796d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, dx << dst->ms_x); 1806d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, dy << dst->ms_y); 1816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, w << dst->ms_x); 1826d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, h << dst->ms_y); 1836d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_DU_DX_FRACT), 4); 18436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0); 18536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 1); 18636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0); 18736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 1); 1886d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_SRC_X_FRACT), 4); 1896d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0); 1906d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, sx << src->ms_x); 1916d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0); 1926d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, sy << src->ms_x); 1934c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1944c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return 0; 1954c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 1964c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1974c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 198ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumillernvc0_resource_copy_region(struct pipe_context *pipe, 199ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller struct pipe_resource *dst, unsigned dst_level, 200ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned dstx, unsigned dsty, unsigned dstz, 201ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller struct pipe_resource *src, unsigned src_level, 202ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller const struct pipe_box *src_box) 2034c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 2046d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 205ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller int ret; 2069e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller boolean m2mf; 207ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned dst_layer = dstz, src_layer = src_box->z; 2084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 209883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { 2102a8145d36b0f04d0f26c1628222a8b5c4830f435Christoph Bumiller nouveau_copy_buffer(&nvc0->base, 2112a8145d36b0f04d0f26c1628222a8b5c4830f435Christoph Bumiller nv04_resource(dst), dstx, 2122a8145d36b0f04d0f26c1628222a8b5c4830f435Christoph Bumiller nv04_resource(src), src_box->x, src_box->width); 213198f514aa6f08bc43a3002519843b0fe94f340bdChristoph Bumiller NOUVEAU_DRV_STAT(&nvc0->screen->base, buf_copy_bytes, src_box->width); 214883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák return; 215883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák } 216198f514aa6f08bc43a3002519843b0fe94f340bdChristoph Bumiller NOUVEAU_DRV_STAT(&nvc0->screen->base, tex_copy_count, 1); 217883d8a0b449b53d83cc5970d2ce50df536aef55fMarek Olšák 218b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller /* 0 and 1 are equal, only supporting 0/1, 2, 4 and 8 */ 219b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller assert((src->nr_samples | 1) == (dst->nr_samples | 1)); 2209e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller 2219e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller m2mf = (src->format == dst->format) || 2229e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller (util_format_get_blocksizebits(src->format) == 2239e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller util_format_get_blocksizebits(dst->format)); 2249e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller 225f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller nv04_resource(dst)->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING; 226f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller 2279e466e87e6fde23f8ec0923be86005be81ac2d24Christoph Bumiller if (m2mf) { 228b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller struct nv50_m2mf_rect drect, srect; 229f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller unsigned i; 230f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller unsigned nx = util_format_get_nblocksx(src->format, src_box->width); 23111f07a35f4734401999c00749e36f39d3e7ad161Christoph Bumiller unsigned ny = util_format_get_nblocksy(src->format, src_box->height); 232f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller 233b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller nv50_m2mf_rect_setup(&drect, dst, dst_level, dstx, dsty, dstz); 234b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller nv50_m2mf_rect_setup(&srect, src, src_level, 235f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller src_box->x, src_box->y, src_box->z); 236f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller 237f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller for (i = 0; i < src_box->depth; ++i) { 238e44089b2f79aa2dcaacf348911433d1e21235c0cChristoph Bumiller nvc0->m2mf_copy_rect(nvc0, &drect, &srect, nx, ny); 239f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller 240cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller if (nv50_miptree(dst)->layout_3d) 241f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller drect.z++; 242f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller else 243cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller drect.base += nv50_miptree(dst)->layer_stride; 244f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller 245cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller if (nv50_miptree(src)->layout_3d) 246f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller srect.z++; 247f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller else 248cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller srect.base += nv50_miptree(src)->layer_stride; 249f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller } 250f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller return; 251f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller } 252f556b897eb5a41116529bec24d47f70a0c46789fChristoph Bumiller 253d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller assert(nv50_2d_dst_format_faithful(dst->format)); 254d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller assert(nv50_2d_src_format_faithful(src->format)); 255ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller 2566d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BCTX_REFN(nvc0->bufctx, 2D, nv04_resource(src), RD); 2576d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BCTX_REFN(nvc0->bufctx, 2D, nv04_resource(dst), WR); 2586d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx); 2596d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller nouveau_pushbuf_validate(nvc0->base.pushbuf); 2606d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller 261ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller for (; dst_layer < dstz + src_box->depth; ++dst_layer, ++src_layer) { 2626d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller ret = nvc0_2d_texture_do_copy(nvc0->base.pushbuf, 263cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller nv50_miptree(dst), dst_level, 264ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller dstx, dsty, dst_layer, 265cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller nv50_miptree(src), src_level, 266ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller src_box->x, src_box->y, src_layer, 267ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller src_box->width, src_box->height); 268ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller if (ret) 2696d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller break; 270ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller } 2716d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller nouveau_bufctx_reset(nvc0->bufctx, 0); 2724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 2734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 2744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 2754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_clear_render_target(struct pipe_context *pipe, 276ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller struct pipe_surface *dst, 2776dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie const union pipe_color_union *color, 278ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned dstx, unsigned dsty, 279ca5deb0c355cc4a120b754a228ff5f51007fbceaChristoph Bumiller unsigned width, unsigned height) 2804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 2816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 2826d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller struct nouveau_pushbuf *push = nvc0->base.pushbuf; 28328271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller struct nv50_surface *sf = nv50_surface(dst); 28428271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller struct nv04_resource *res = nv04_resource(sf->base.texture); 28528271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller unsigned z; 28628271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller 287edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst if (!PUSH_SPACE(push, 32 + sf->depth)) 288edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst return; 289edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst 290edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst PUSH_REFN (push, res->bo, res->domain | NOUVEAU_BO_WR); 291edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst 2926d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_COLOR(0)), 4); 2936d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[0]); 2946d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[1]); 2956d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[2]); 2966d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[3]); 2976d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller 2986d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2); 2996d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, ( width << 16) | dstx); 3006d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, (height << 16) | dsty); 3016d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller 3026d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(RT_CONTROL), 1); 3036d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 1); 3046d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(RT_ADDRESS_HIGH(0)), 9); 3056d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAh(push, res->address + sf->offset); 3066d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, res->address + sf->offset); 3076d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller if (likely(nouveau_bo_memtype(res->bo))) { 30828271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller struct nv50_miptree *mt = nv50_miptree(dst->texture); 30928271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller 3106d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, sf->width); 3116d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, sf->height); 3126d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, nvc0_format_table[dst->format].rt); 3136d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, (mt->layout_3d << 16) | 31428271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller mt->level[sf->base.u.tex.level].tile_mode); 3156d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, dst->u.tex.first_layer + sf->depth); 3166d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, mt->layer_stride >> 2); 3176d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, dst->u.tex.first_layer); 31828271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller } else { 31928271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller if (res->base.target == PIPE_BUFFER) { 3206d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, 262144); 3216d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, 1); 32228271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller } else { 3236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, nv50_miptree(&res->base)->level[0].pitch); 3246d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, sf->height); 32528271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller } 3266d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, nvc0_format_table[sf->base.format].rt); 3276d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, 1 << 12); 3286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, 1); 3296d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, 0); 3306d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA(push, 0); 33128271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller 3326d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(ZETA_ENABLE), 0); 33328271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller 33428271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller /* tiled textures don't have to be fenced, they're not mapped directly */ 33528271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller nvc0_resource_fence(res, NOUVEAU_BO_WR); 33628271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller } 33728271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller 338edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst BEGIN_NIC0(push, NVC0_3D(CLEAR_BUFFERS), sf->depth); 33928271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller for (z = 0; z < sf->depth; ++z) { 3406d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0x3c | 34128271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller (z << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT)); 34228271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller } 34328271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller 3446d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller nvc0->dirty |= NVC0_NEW_FRAMEBUFFER; 3454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 3464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3474c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillerstatic void 3484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_clear_depth_stencil(struct pipe_context *pipe, 3494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_surface *dst, 3504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned clear_flags, 3514c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller double depth, 3524c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned stencil, 3534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned dstx, unsigned dsty, 3544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned width, unsigned height) 3554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 3566d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 3576d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller struct nouveau_pushbuf *push = nvc0->base.pushbuf; 358cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller struct nv50_miptree *mt = nv50_miptree(dst->texture); 359cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller struct nv50_surface *sf = nv50_surface(dst); 3604c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller uint32_t mode = 0; 3614fae7da9a3a3849ca08ffc6fcbdccc6a9c065ad2Christoph Bumiller int unk = mt->base.base.target == PIPE_TEXTURE_2D; 362e104bb9f926ee4c0847327bc396f467a47e26582Christoph Bumiller unsigned z; 3634c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 364edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst if (!PUSH_SPACE(push, 32 + sf->depth)) 365edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst return; 366edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst 367edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst PUSH_REFN (push, mt->base.bo, mt->base.domain | NOUVEAU_BO_WR); 368edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst 3694c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (clear_flags & PIPE_CLEAR_DEPTH) { 3706d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_DEPTH), 1); 3716d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, depth); 3724c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller mode |= NVC0_3D_CLEAR_BUFFERS_Z; 3734c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3744c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3754c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (clear_flags & PIPE_CLEAR_STENCIL) { 3766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_STENCIL), 1); 3776d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, stencil & 0xff); 3784c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller mode |= NVC0_3D_CLEAR_BUFFERS_S; 3794c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 3804c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 3816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2); 3826d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, ( width << 16) | dstx); 3836d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, (height << 16) | dsty); 3846d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller 3856d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(ZETA_ADDRESS_HIGH), 5); 3866d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAh(push, mt->base.address + sf->offset); 3876d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mt->base.address + sf->offset); 3886d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, nvc0_format_table[dst->format].rt); 3896d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mt->level[sf->base.u.tex.level].tile_mode); 3906d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mt->layer_stride >> 2); 3916d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(ZETA_ENABLE), 1); 3926d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 1); 3936d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(ZETA_HORIZ), 3); 3946d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, sf->width); 3956d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, sf->height); 3966d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, (unk << 16) | (dst->u.tex.first_layer + sf->depth)); 3976d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(ZETA_BASE_LAYER), 1); 3986d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, dst->u.tex.first_layer); 3994c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 400edc8e8cbef874a37c721b576c3ecd2a9f2fd399bMaarten Lankhorst BEGIN_NIC0(push, NVC0_3D(CLEAR_BUFFERS), sf->depth); 401e104bb9f926ee4c0847327bc396f467a47e26582Christoph Bumiller for (z = 0; z < sf->depth; ++z) { 4026d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mode | 403e104bb9f926ee4c0847327bc396f467a47e26582Christoph Bumiller (z << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT)); 404e104bb9f926ee4c0847327bc396f467a47e26582Christoph Bumiller } 40519f2272e94895cf241f6b05117535e008e07d0a7Christoph Bumiller 4066d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller nvc0->dirty |= NVC0_NEW_FRAMEBUFFER; 4074c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4084c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4094c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid 4104c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_clear(struct pipe_context *pipe, unsigned buffers, 4116dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie const union pipe_color_union *color, 4126dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie double depth, unsigned stencil) 4134c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 4144c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 4156d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller struct nouveau_pushbuf *push = nvc0->base.pushbuf; 4164c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller struct pipe_framebuffer_state *fb = &nvc0->framebuffer; 4174c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller unsigned i; 4184c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller uint32_t mode = 0; 4194c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4204c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */ 421222b3ea653e5525a4afa57e6a2353335953012d4Christoph Bumiller if (!nvc0_state_validate(nvc0, NVC0_NEW_FRAMEBUFFER, 9 + (fb->nr_cbufs * 2))) 4224c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller return; 4234c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4244c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) { 4256d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_COLOR(0)), 4); 4266d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[0]); 4276d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[1]); 4286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[2]); 4296d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATAf(push, color->f[3]); 4304c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller mode = 4314c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NVC0_3D_CLEAR_BUFFERS_R | NVC0_3D_CLEAR_BUFFERS_G | 4324c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller NVC0_3D_CLEAR_BUFFERS_B | NVC0_3D_CLEAR_BUFFERS_A; 4334c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4344c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4354c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (buffers & PIPE_CLEAR_DEPTH) { 4366d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_DEPTH), 1); 4376d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, fui(depth)); 4384c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller mode |= NVC0_3D_CLEAR_BUFFERS_Z; 4394c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4404c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4414c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller if (buffers & PIPE_CLEAR_STENCIL) { 4426d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_STENCIL), 1); 4436d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, stencil & 0xff); 4444c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller mode |= NVC0_3D_CLEAR_BUFFERS_S; 4454c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4464c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4476d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 1); 4486d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, mode); 4494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller for (i = 1; i < fb->nr_cbufs; i++) { 4516d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 1); 4526d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, (i << 6) | 0x3c); 4534c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller } 4544c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 4554c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 4567744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 45736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller/* =============================== BLIT CODE =================================== 45836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller */ 45936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 46036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillerstruct nvc0_blitter 4617744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 46236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_program *fp[NV50_BLIT_MAX_TEXTURE_TYPES][NV50_BLIT_MODES]; 46336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_program vp; 46436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 46536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nv50_tsc_entry sampler[2]; /* nearest, bilinear */ 46636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 46736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe_mutex mutex; 46836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 4697744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct nvc0_screen *screen; 47036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller}; 47136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 47236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillerstruct nvc0_blitctx 47336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller{ 47436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_context *nvc0; 47536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_program *fp; 47636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint8_t mode; 47736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint16_t color_mask; 47836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint8_t filter; 47936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller enum pipe_texture_target target; 4807744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct { 4817744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct pipe_framebuffer_state fb; 4828aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller struct nvc0_rasterizer_stateobj *rast; 4837744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct nvc0_program *vp; 4847744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct nvc0_program *tcp; 4857744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct nvc0_program *tep; 4867744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct nvc0_program *gp; 4877744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct nvc0_program *fp; 4887744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller unsigned num_textures[5]; 4897744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller unsigned num_samplers[5]; 490b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller struct pipe_sampler_view *texture[2]; 491b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller struct nv50_tsc_entry *sampler[2]; 49236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint32_t dirty; 4937744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller } saved; 4948aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller struct nvc0_rasterizer_stateobj rast; 4957744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller}; 4967744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 4977744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 49836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitter_make_vp(struct nvc0_blitter *blit) 4997744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 50036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller static const uint32_t code_nvc0[] = 50136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller { 502443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0xfff11c26, 0x06000080, /* vfetch b64 $r4:$r5 a[0x80] */ 503443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0xfff01c46, 0x06000090, /* vfetch b96 $r0:$r1:$r2 a[0x90] */ 504443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0x13f01c26, 0x0a7e0070, /* export b64 o[0x70] $r4:$r5 */ 505443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0x03f01c46, 0x0a7e0080, /* export b96 o[0x80] $r0:$r1:$r2 */ 50636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 0x00001de7, 0x80000000, /* exit */ 50736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller }; 50836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller static const uint32_t code_nve4[] = 5097744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller { 51036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 0x00000007, 0x20000000, /* sched */ 511443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0xfff11c26, 0x06000080, /* vfetch b64 $r4:$r5 a[0x80] */ 512443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0xfff01c46, 0x06000090, /* vfetch b96 $r0:$r1:$r2 a[0x90] */ 513443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0x13f01c26, 0x0a7e0070, /* export b64 o[0x70] $r4:$r5 */ 514443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller 0x03f01c46, 0x0a7e0080, /* export b96 o[0x80] $r0:$r1:$r2 */ 5157744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 0x00001de7, 0x80000000, /* exit */ 5167744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller }; 5177744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5187744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->vp.type = PIPE_SHADER_VERTEX; 5197744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->vp.translated = TRUE; 52036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (blit->screen->base.class_3d >= NVE4_3D_CLASS) { 52136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->vp.code = (uint32_t *)code_nve4; /* const_cast */ 52236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->vp.code_size = sizeof(code_nve4); 52336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else { 52436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->vp.code = (uint32_t *)code_nvc0; /* const_cast */ 52536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->vp.code_size = sizeof(code_nvc0); 52636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 527443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller blit->vp.num_gprs = 6; 5287744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->vp.vp.edgeflag = PIPE_MAX_ATTRIBS; 5297744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5307744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->vp.hdr[0] = 0x00020461; /* vertprog magic */ 5317744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->vp.hdr[4] = 0x000ff000; /* no outputs read */ 532443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller blit->vp.hdr[6] = 0x00000073; /* a[0x80].xy, a[0x90].xyz */ 533443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller blit->vp.hdr[13] = 0x00073000; /* o[0x70].xy, o[0x80].xyz */ 5347744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 5357744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5367744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 53736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitter_make_sampler(struct nvc0_blitter *blit) 5387744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 5397744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* clamp to edge, min/max lod = 0, nearest filtering */ 5407744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5417744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->sampler[0].id = -1; 5427744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5438592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller blit->sampler[0].tsc[0] = NV50_TSC_0_SRGB_CONVERSION_ALLOWED | 5448592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller (NV50_TSC_WRAP_CLAMP_TO_EDGE << NV50_TSC_0_WRAPS__SHIFT) | 5458592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller (NV50_TSC_WRAP_CLAMP_TO_EDGE << NV50_TSC_0_WRAPT__SHIFT) | 5468592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller (NV50_TSC_WRAP_CLAMP_TO_EDGE << NV50_TSC_0_WRAPR__SHIFT); 5478592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller blit->sampler[0].tsc[1] = 5488592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller NV50_TSC_1_MAGF_NEAREST | NV50_TSC_1_MINF_NEAREST | NV50_TSC_1_MIPF_NONE; 5497744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5507744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* clamp to edge, min/max lod = 0, bilinear filtering */ 5517744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5527744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller blit->sampler[1].id = -1; 5537744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5548592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller blit->sampler[1].tsc[0] = blit->sampler[0].tsc[0]; 5558592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller blit->sampler[1].tsc[1] = 5568592933de82f7742f411cb2f2c339ff7d42266daChristoph Bumiller NV50_TSC_1_MAGF_LINEAR | NV50_TSC_1_MINF_LINEAR | NV50_TSC_1_MIPF_NONE; 5577744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 5587744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5597744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 56036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blit_select_fp(struct nvc0_blitctx *ctx, const struct pipe_blit_info *info) 5617744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 56236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_blitter *blitter = ctx->nvc0->screen->blitter; 56336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 56436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const enum pipe_texture_target ptarg = 565b9c8a98e216f4613dc0a40e26d08f2c1cb760e76Christoph Bumiller nv50_blit_reinterpret_pipe_texture_target(info->src.resource->target); 56636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 56736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const unsigned targ = nv50_blit_texture_type(ptarg); 56836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const unsigned mode = ctx->mode; 56936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 57036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!blitter->fp[targ][mode]) { 57136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe_mutex_lock(blitter->mutex); 57236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!blitter->fp[targ][mode]) 57336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blitter->fp[targ][mode] = 574b9c8a98e216f4613dc0a40e26d08f2c1cb760e76Christoph Bumiller nv50_blitter_make_fp(&ctx->nvc0->base.pipe, mode, ptarg); 57536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe_mutex_unlock(blitter->mutex); 5767744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller } 57736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->fp = blitter->fp[targ][mode]; 5787744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 5797744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5807744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 58136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blit_set_dst(struct nvc0_blitctx *ctx, 58236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct pipe_resource *res, unsigned level, unsigned layer, 58336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller enum pipe_format format) 5847744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 58536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_context *nvc0 = ctx->nvc0; 5866286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller struct pipe_context *pipe = &nvc0->base.pipe; 5876286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller struct pipe_surface templ; 5886286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller 58936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (util_format_is_depth_or_stencil(format)) 59036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.format = nv50_blit_zeta_to_colour_format(format); 5916286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller else 59236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.format = format; 5937744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 5946286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller templ.u.tex.level = level; 5956286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller templ.u.tex.first_layer = templ.u.tex.last_layer = layer; 5967744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 59736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (layer == -1) { 59836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.u.tex.first_layer = 0; 59936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.u.tex.last_layer = 60036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller (res->target == PIPE_TEXTURE_3D ? res->depth0 : res->array_size) - 1; 60136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 60236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 6036286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller nvc0->framebuffer.cbufs[0] = nvc0_miptree_surface_new(pipe, res, &templ); 6047744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.nr_cbufs = 1; 6057744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.zsbuf = NULL; 6066286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller nvc0->framebuffer.width = nvc0->framebuffer.cbufs[0]->width; 6076286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller nvc0->framebuffer.height = nvc0->framebuffer.cbufs[0]->height; 6087744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 6097744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6107744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 61136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blit_set_src(struct nvc0_blitctx *ctx, 612b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller struct pipe_resource *res, unsigned level, unsigned layer, 61336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller enum pipe_format format, const uint8_t filter) 6147744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 61536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_context *nvc0 = ctx->nvc0; 6167744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct pipe_context *pipe = &nvc0->base.pipe; 6177744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller struct pipe_sampler_view templ; 61836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint32_t flags; 61936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller unsigned s; 62036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller enum pipe_texture_target target; 6217744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 62236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller target = nv50_blit_reinterpret_pipe_texture_target(res->target); 62336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 62436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.format = format; 6257744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller templ.u.tex.first_layer = templ.u.tex.last_layer = layer; 6267744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller templ.u.tex.first_level = templ.u.tex.last_level = level; 6277744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller templ.swizzle_r = PIPE_SWIZZLE_RED; 6287744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller templ.swizzle_g = PIPE_SWIZZLE_GREEN; 6297744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller templ.swizzle_b = PIPE_SWIZZLE_BLUE; 6307744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller templ.swizzle_a = PIPE_SWIZZLE_ALPHA; 6317744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 63236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (layer == -1) { 63336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.u.tex.first_layer = 0; 63436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.u.tex.last_layer = 63536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller (res->target == PIPE_TEXTURE_3D ? res->depth0 : res->array_size) - 1; 63636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 6377744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6382149ce41ed6b10f7bff65d7b3f23fd03b89753e3Christoph Bumiller flags = res->last_level ? 0 : NV50_TEXVIEW_SCALED_COORDS; 63936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (filter && res->nr_samples == 8) 64036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller flags |= NV50_TEXVIEW_FILTER_MSAA8; 64136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 64236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->textures[4][0] = nvc0_create_texture_view( 64336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe, res, &templ, flags, target); 64436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->textures[4][1] = NULL; 6457744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6467744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller for (s = 0; s <= 3; ++s) 6477744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->num_textures[s] = 0; 6487744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->num_textures[4] = 1; 649b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller 65036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller templ.format = nv50_zs_to_s_format(format); 65136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (templ.format != format) { 65236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->textures[4][1] = nvc0_create_texture_view( 65336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe, res, &templ, flags, target); 654b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->num_textures[4] = 2; 655b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller } 6567744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 6577744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6587744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 6597744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillernvc0_blitctx_prepare_state(struct nvc0_blitctx *blit) 6607744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 66136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nouveau_pushbuf *push = blit->nvc0->base.pushbuf; 6627744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6637744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* TODO: maybe make this a MACRO (if we need more logic) ? */ 6647744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 66536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (blit->nvc0->cond_query) 66636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_3D(COND_MODE), NVC0_3D_COND_MODE_ALWAYS); 66736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 6687744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* blend state */ 6696d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(COLOR_MASK(0)), 1); 6706d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, blit->color_mask); 67136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_3D(BLEND_ENABLE(0)), 0); 6726d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(LOGIC_OP_ENABLE), 0); 6737744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6747744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* rasterizer state */ 67536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_3D(FRAG_COLOR_CLAMP_EN), 0); 6766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_ENABLE), 0); 6776d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(MSAA_MASK(0)), 4); 6786d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0xffff); 6796d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0xffff); 6806d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0xffff); 6816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller PUSH_DATA (push, 0xffff); 6827a40ae4a31f3ab526706fdfda7631d54f094512aChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(MACRO_POLYGON_MODE_FRONT), 1); 6837a40ae4a31f3ab526706fdfda7631d54f094512aChristoph Bumiller PUSH_DATA (push, NVC0_3D_MACRO_POLYGON_MODE_FRONT_FILL); 6847a40ae4a31f3ab526706fdfda7631d54f094512aChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(MACRO_POLYGON_MODE_BACK), 1); 6857a40ae4a31f3ab526706fdfda7631d54f094512aChristoph Bumiller PUSH_DATA (push, NVC0_3D_MACRO_POLYGON_MODE_BACK_FILL); 6866d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(POLYGON_SMOOTH_ENABLE), 0); 6876d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(POLYGON_OFFSET_FILL_ENABLE), 0); 6886d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(POLYGON_STIPPLE_ENABLE), 0); 6896d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(CULL_FACE_ENABLE), 0); 6907744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 6917744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* zsa state */ 6926d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(DEPTH_TEST_ENABLE), 0); 6936d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(STENCIL_ENABLE), 0); 6946d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(ALPHA_TEST_ENABLE), 0); 6957744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 69614bd9d764802b5fedb652c791faafe4d13b65262Christoph Bumiller /* disable transform feedback */ 6976d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(TFB_ENABLE), 0); 6987744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 6997744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7007744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 70136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx) 7027744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 70336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_context *nvc0 = ctx->nvc0; 70436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_blitter *blitter = nvc0->screen->blitter; 7057744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller int s; 7067744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 70736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.fb.width = nvc0->framebuffer.width; 70836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.fb.height = nvc0->framebuffer.height; 70936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.fb.nr_cbufs = nvc0->framebuffer.nr_cbufs; 71036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.fb.cbufs[0] = nvc0->framebuffer.cbufs[0]; 71136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.fb.zsbuf = nvc0->framebuffer.zsbuf; 7127744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7138aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller ctx->saved.rast = nvc0->rast; 7148aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller 71536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.vp = nvc0->vertprog; 71636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.tcp = nvc0->tctlprog; 71736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.tep = nvc0->tevlprog; 71836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.gp = nvc0->gmtyprog; 71936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.fp = nvc0->fragprog; 7207744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7218aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller nvc0->rast = &ctx->rast; 7228aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller 72336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->vertprog = &blitter->vp; 7247744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->tctlprog = NULL; 7257744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->tevlprog = NULL; 7267744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->gmtyprog = NULL; 72736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->fragprog = ctx->fp; 7287744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7297744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller for (s = 0; s <= 4; ++s) { 73036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.num_textures[s] = nvc0->num_textures[s]; 73136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.num_samplers[s] = nvc0->num_samplers[s]; 732b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->textures_dirty[s] = (1 << nvc0->num_textures[s]) - 1; 733b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->samplers_dirty[s] = (1 << nvc0->num_samplers[s]) - 1; 7347744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller } 73536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.texture[0] = nvc0->textures[4][0]; 73636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.texture[1] = nvc0->textures[4][1]; 73736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.sampler[0] = nvc0->samplers[4][0]; 73836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.sampler[1] = nvc0->samplers[4][1]; 7397744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 74036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->samplers[4][0] = &blitter->sampler[ctx->filter]; 74136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->samplers[4][1] = &blitter->sampler[ctx->filter]; 7427744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7437744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller for (s = 0; s <= 3; ++s) 7447744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->num_samplers[s] = 0; 745b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->num_samplers[4] = 2; 7467744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 74736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller ctx->saved.dirty = nvc0->dirty; 7487744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 749b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->textures_dirty[4] |= 3; 750b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->samplers_dirty[4] |= 3; 751b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller 75236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_FB); 75336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_TEX(4, 0)); 75436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_TEX(4, 1)); 75536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 7567744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->dirty = NVC0_NEW_FRAMEBUFFER | 7577744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller NVC0_NEW_VERTPROG | NVC0_NEW_FRAGPROG | 7587744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller NVC0_NEW_TCTLPROG | NVC0_NEW_TEVLPROG | NVC0_NEW_GMTYPROG | 7597744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller NVC0_NEW_TEXTURES | NVC0_NEW_SAMPLERS; 7607744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 7617744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7627744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 76336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitctx_post_blit(struct nvc0_blitctx *blit) 7647744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 76536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_context *nvc0 = blit->nvc0; 7667744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller int s; 7677744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7686286d9810b7ebae588060370cd7a63c327478a2fChristoph Bumiller pipe_surface_reference(&nvc0->framebuffer.cbufs[0], NULL); 7697744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7707744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.width = blit->saved.fb.width; 7717744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.height = blit->saved.fb.height; 7727744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.nr_cbufs = blit->saved.fb.nr_cbufs; 7737744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.cbufs[0] = blit->saved.fb.cbufs[0]; 7747744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->framebuffer.zsbuf = blit->saved.fb.zsbuf; 7757744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7768aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller nvc0->rast = blit->saved.rast; 7778aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller 7787744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->vertprog = blit->saved.vp; 7797744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->tctlprog = blit->saved.tcp; 7807744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->tevlprog = blit->saved.tep; 7817744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->gmtyprog = blit->saved.gp; 7827744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->fragprog = blit->saved.fp; 7837744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7847744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller pipe_sampler_view_reference(&nvc0->textures[4][0], NULL); 785b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller pipe_sampler_view_reference(&nvc0->textures[4][1], NULL); 7867744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 7877744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller for (s = 0; s <= 4; ++s) { 7887744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->num_textures[s] = blit->saved.num_textures[s]; 7897744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->num_samplers[s] = blit->saved.num_samplers[s]; 790b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->textures_dirty[s] = (1 << nvc0->num_textures[s]) - 1; 791b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->samplers_dirty[s] = (1 << nvc0->num_samplers[s]) - 1; 7927744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller } 793b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->textures[4][0] = blit->saved.texture[0]; 794b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->textures[4][1] = blit->saved.texture[1]; 795b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->samplers[4][0] = blit->saved.sampler[0]; 796b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->samplers[4][1] = blit->saved.sampler[1]; 797b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller 798b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->textures_dirty[4] |= 3; 799b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller nvc0->samplers_dirty[4] |= 3; 8007744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 80136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (nvc0->cond_query) 80236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->base.pipe.render_condition(&nvc0->base.pipe, nvc0->cond_query, 80336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->cond_mode); 80436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 80536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_FB); 80636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_TEX(4, 0)); 80736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_TEX(4, 1)); 80836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 8097744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0->dirty = blit->saved.dirty | 8107744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller (NVC0_NEW_FRAMEBUFFER | NVC0_NEW_SCISSOR | NVC0_NEW_SAMPLE_MASK | 8117744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller NVC0_NEW_RASTERIZER | NVC0_NEW_ZSA | NVC0_NEW_BLEND | 8127744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller NVC0_NEW_TEXTURES | NVC0_NEW_SAMPLERS | 8137744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller NVC0_NEW_VERTPROG | NVC0_NEW_FRAGPROG | 81414bd9d764802b5fedb652c791faafe4d13b65262Christoph Bumiller NVC0_NEW_TCTLPROG | NVC0_NEW_TEVLPROG | NVC0_NEW_GMTYPROG | 81514bd9d764802b5fedb652c791faafe4d13b65262Christoph Bumiller NVC0_NEW_TFB_TARGETS); 8167744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 8177744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 8187744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerstatic void 81936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blit_3d(struct nvc0_context *nvc0, const struct pipe_blit_info *info) 8207744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 82136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_blitctx *blit = nvc0->blit; 82236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nouveau_pushbuf *push = nvc0->base.pushbuf; 82336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct pipe_resource *src = info->src.resource; 82436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct pipe_resource *dst = info->dst.resource; 82536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller int32_t minx, maxx, miny, maxy; 82636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller int32_t i; 82736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller float x0, x1, y0, y1, z; 82836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller float dz; 8297744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller float x_range, y_range; 8307744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 83136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->mode = nv50_blit_select_mode(info); 83236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->color_mask = nv50_blit_derive_color_mask(info); 83336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->filter = nv50_blit_get_filter(info); 8347744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 83536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blit_select_fp(blit, info); 83636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blitctx_pre_blit(blit); 8377744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 838443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller nvc0_blit_set_dst(blit, dst, info->dst.level, -1, info->dst.format); 83936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blit_set_src(blit, src, info->src.level, -1, info->src.format, 84036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller blit->filter); 8417744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 8427744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller nvc0_blitctx_prepare_state(blit); 8437744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 84436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_state_validate(nvc0, ~0, 48); 8457744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 84636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller x_range = (float)info->src.box.width / (float)info->dst.box.width; 84736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller y_range = (float)info->src.box.height / (float)info->dst.box.height; 8487744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 84936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller x0 = (float)info->src.box.x - x_range * (float)info->dst.box.x; 85036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller y0 = (float)info->src.box.y - y_range * (float)info->dst.box.y; 8517744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 8522149ce41ed6b10f7bff65d7b3f23fd03b89753e3Christoph Bumiller x1 = x0 + 16384.0f * x_range; 8532149ce41ed6b10f7bff65d7b3f23fd03b89753e3Christoph Bumiller y1 = y0 + 16384.0f * y_range; 8547744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 8557744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller x0 *= (float)(1 << nv50_miptree(src)->ms_x); 8567744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller x1 *= (float)(1 << nv50_miptree(src)->ms_x); 8577744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller y0 *= (float)(1 << nv50_miptree(src)->ms_y); 8587744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller y1 *= (float)(1 << nv50_miptree(src)->ms_y); 8597744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 86036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (src->last_level > 0) { 86136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* If there are mip maps, GPU always assumes normalized coordinates. */ 86236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const unsigned l = info->src.level; 86336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const float fh = u_minify(src->width0 << nv50_miptree(src)->ms_x, l); 86436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const float fv = u_minify(src->height0 << nv50_miptree(src)->ms_y, l); 86536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller x0 /= fh; 86636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller x1 /= fh; 86736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller y0 /= fv; 86836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller y1 /= fv; 86936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 87036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 87136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dz = (float)info->src.box.depth / (float)info->dst.box.depth; 87236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller z = (float)info->src.box.z; 87336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (nv50_miptree(src)->layout_3d) 87436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller z += 0.5f * dz; 8757744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 8766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller IMMED_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 0); 8776417d56c1921c311a7b59001e0d37822a0ed1a65Christoph Bumiller IMMED_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 0x2 | 8786417d56c1921c311a7b59001e0d37822a0ed1a65Christoph Bumiller NVC0_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_RANGE_0_1); 8792149ce41ed6b10f7bff65d7b3f23fd03b89753e3Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VIEWPORT_HORIZ(0)), 2); 8802149ce41ed6b10f7bff65d7b3f23fd03b89753e3Christoph Bumiller PUSH_DATA (push, nvc0->framebuffer.width << 16); 8812149ce41ed6b10f7bff65d7b3f23fd03b89753e3Christoph Bumiller PUSH_DATA (push, nvc0->framebuffer.height << 16); 8827744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 8837744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller /* Draw a large triangle in screen coordinates covering the whole 8847744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller * render target, with scissors defining the destination region. 8857744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller * The vertex is supplied with non-normalized texture coordinates 8867744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller * arranged in a way to yield the desired offset and scale. 8877744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller */ 8887744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 88936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller minx = info->dst.box.x; 89036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller maxx = info->dst.box.x + info->dst.box.width; 89136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller miny = info->dst.box.y; 89236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller maxy = info->dst.box.y + info->dst.box.height; 89336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->scissor_enable) { 89436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller minx = MAX2(minx, info->scissor.minx); 89536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller maxx = MIN2(maxx, info->scissor.maxx); 89636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller miny = MAX2(miny, info->scissor.miny); 89736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller maxy = MIN2(maxy, info->scissor.maxy); 89836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 8996d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller BEGIN_NVC0(push, NVC0_3D(SCISSOR_HORIZ(0)), 2); 90036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, (maxx << 16) | minx); 90136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, (maxy << 16) | miny); 90236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 90336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller for (i = 0; i < info->dst.box.depth; ++i, z += dz) { 90436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->dst.box.z + i) { 90536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(LAYER), 1); 90636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, info->dst.box.z + i); 90736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 90836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 90936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_3D(VERTEX_BEGIN_GL), 91036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_TRIANGLES); 91136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 91236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 4); 91336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x74301); 91436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, x0); 91536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, y0); 91636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, z); 91736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 3); 91836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x74200); 91936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, 0.0f); 92036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, 0.0f); 92136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 4); 92236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x74301); 92336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, x1); 92436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, y0); 92536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, z); 92636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 3); 92736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x74200); 92836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, 16384 << nv50_miptree(dst)->ms_x); 92936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, 0.0f); 93036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 4); 93136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x74301); 93236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, x0); 93336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, y1); 93436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, z); 93536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 3); 93636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x74200); 93736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, 0.0f); 93836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAf(push, 16384 << nv50_miptree(dst)->ms_y); 93936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 94036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_3D(VERTEX_END_GL), 0); 94136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 94236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->dst.box.z + info->dst.box.depth - 1) 94336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_3D(LAYER), 0); 9447744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 945443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller nvc0_blitctx_post_blit(blit); 9467744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 947443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller /* restore viewport */ 9487744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 949443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller BEGIN_NVC0(push, NVC0_3D(VIEWPORT_HORIZ(0)), 2); 950443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller PUSH_DATA (push, nvc0->framebuffer.width << 16); 951443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller PUSH_DATA (push, nvc0->framebuffer.height << 16); 952443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller IMMED_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1); 95336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller} 95436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 95536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillerstatic void 95636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blit_eng2d(struct nvc0_context *nvc0, const struct pipe_blit_info *info) 95736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller{ 95836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nouveau_pushbuf *push = nvc0->base.pushbuf; 95936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nv50_miptree *dst = nv50_miptree(info->dst.resource); 96036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nv50_miptree *src = nv50_miptree(info->src.resource); 96136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const int32_t srcx_adj = info->src.box.width < 0 ? -1 : 0; 96236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const int32_t srcy_adj = info->src.box.height < 0 ? -1 : 0; 96336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const int dz = info->dst.box.z; 96436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const int sz = info->src.box.z; 96536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint32_t dstw, dsth; 96636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller int32_t dstx, dsty; 96736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller int64_t srcx, srcy; 96836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller int64_t du_dx, dv_dy; 96936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller int i; 97036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller uint32_t mode; 971d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller uint32_t mask = nv50_blit_eng2d_get_mask(info); 972d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller boolean b; 97336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 97436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller mode = nv50_blit_get_filter(info) ? 97536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NVC0_2D_BLIT_CONTROL_FILTER_BILINEAR : 97636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NVC0_2D_BLIT_CONTROL_FILTER_POINT_SAMPLE; 97736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller mode |= (src->base.base.nr_samples > dst->base.base.nr_samples) ? 97836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NVC0_2D_BLIT_CONTROL_ORIGIN_CORNER : NVC0_2D_BLIT_CONTROL_ORIGIN_CENTER; 97936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 98036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller du_dx = ((int64_t)info->src.box.width << 32) / info->dst.box.width; 98136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dv_dy = ((int64_t)info->src.box.height << 32) / info->dst.box.height; 98236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 983d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller b = info->dst.format == info->src.format; 984d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller nvc0_2d_texture_set(push, 1, dst, info->dst.level, dz, info->dst.format, b); 985d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller nvc0_2d_texture_set(push, 0, src, info->src.level, sz, info->src.format, b); 98636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 98736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->scissor_enable) { 98836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(CLIP_X), 5); 98936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, info->scissor.minx << dst->ms_x); 99036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, info->scissor.miny << dst->ms_y); 99136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, (info->scissor.maxx - info->scissor.minx) << dst->ms_x); 99236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, (info->scissor.maxy - info->scissor.miny) << dst->ms_y); 99336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 1); /* enable */ 99436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 99536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 99636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (mask != 0xffffffff) { 997351d3c59f2a1153047d45fcdb23cc487f231683dChristoph Bumiller IMMED_NVC0(push, NVC0_2D(ROP), 0xca); /* DPSDxax */ 99836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_2D(PATTERN_COLOR_FORMAT), 99936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NVC0_2D_PATTERN_COLOR_FORMAT_32BPP); 100036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(PATTERN_COLOR(0)), 4); 100136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0x00000000); 100236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, mask); 100336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0xffffffff); 100436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, 0xffffffff); 1005351d3c59f2a1153047d45fcdb23cc487f231683dChristoph Bumiller IMMED_NVC0(push, NVC0_2D(OPERATION), NVC0_2D_OPERATION_ROP); 1006d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller } else 1007d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (info->src.format != info->dst.format) { 1008d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (info->src.format == PIPE_FORMAT_R8_UNORM || 1009d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller info->src.format == PIPE_FORMAT_R8_SNORM || 1010d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller info->src.format == PIPE_FORMAT_R16_UNORM || 1011d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller info->src.format == PIPE_FORMAT_R16_SNORM || 1012d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller info->src.format == PIPE_FORMAT_R16_FLOAT || 1013d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller info->src.format == PIPE_FORMAT_R32_FLOAT) { 1014d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller mask = 0xffff0000; /* also makes condition for OPERATION reset true */ 1015d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller BEGIN_NVC0(push, NVC0_2D(BETA4), 2); 1016d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller PUSH_DATA (push, mask); 1017d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller PUSH_DATA (push, NVC0_2D_OPERATION_SRCCOPY_PREMULT); 1018d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller } else 1019d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (info->src.format == PIPE_FORMAT_A8_UNORM) { 1020d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller mask = 0xff000000; 1021d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller BEGIN_NVC0(push, NVC0_2D(BETA4), 2); 1022d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller PUSH_DATA (push, mask); 1023d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller PUSH_DATA (push, NVC0_2D_OPERATION_SRCCOPY_PREMULT); 1024d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller } 102536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 102636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 102736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (src->ms_x > dst->ms_x || src->ms_y > dst->ms_y) { 102836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* ms_x is always >= ms_y */ 102936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller du_dx <<= src->ms_x - dst->ms_x; 103036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dv_dy <<= src->ms_y - dst->ms_y; 103136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else { 103236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller du_dx >>= dst->ms_x - src->ms_x; 103336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dv_dy >>= dst->ms_y - src->ms_y; 103436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 103536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 103636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller srcx = (int64_t)(info->src.box.x + srcx_adj) << (src->ms_x + 32); 103736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller srcy = (int64_t)(info->src.box.y + srcy_adj) << (src->ms_y + 32); 103836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 103936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (src->base.base.nr_samples > dst->base.base.nr_samples) { 104036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* center src coorinates for proper MS resolve filtering */ 104136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller srcx += (int64_t)src->ms_x << 32; 104236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller srcy += (int64_t)src->ms_y << 32; 104336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 104436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 104536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dstx = info->dst.box.x << dst->ms_x; 104636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dsty = info->dst.box.y << dst->ms_y; 104736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 104836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dstw = info->dst.box.width << dst->ms_x; 104936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dsth = info->dst.box.height << dst->ms_y; 105036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 105136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (dstx < 0) { 105236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dstw += dstx; 105336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller srcx -= du_dx * dstx; 105436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dstx = 0; 105536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 105636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (dsty < 0) { 105736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dsth += dsty; 105836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller srcy -= dv_dy * dsty; 105936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller dsty = 0; 106036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 106136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 106236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_2D(BLIT_CONTROL), mode); 106336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_DST_X), 4); 106436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dstx); 106536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dsty); 106636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dstw); 106736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dsth); 106836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_DU_DX_FRACT), 4); 106936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, du_dx); 107036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, du_dx >> 32); 107136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dv_dy); 107236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dv_dy >> 32); 107336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 107436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BCTX_REFN(nvc0->bufctx, 2D, &dst->base, WR); 107536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BCTX_REFN(nvc0->bufctx, 2D, &src->base, RD); 107636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx); 107736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (nouveau_pushbuf_validate(nvc0->base.pushbuf)) 107836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller return; 107936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 108036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller for (i = 0; i < info->dst.box.depth; ++i) { 108136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (i > 0) { 108236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* no scaling in z-direction possible for eng2d blits */ 108336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (dst->layout_3d) { 108436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(DST_LAYER), 1); 108536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, info->dst.box.z + i); 108636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else { 108736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const unsigned z = info->dst.box.z + i; 108836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(DST_ADDRESS_HIGH), 2); 108936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAh(push, dst->base.address + z * dst->layer_stride); 109036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, dst->base.address + z * dst->layer_stride); 109136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 109236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (src->layout_3d) { 109336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* not possible because of depth tiling */ 109436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller assert(0); 109536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else { 109636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller const unsigned z = info->src.box.z + i; 109736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(SRC_ADDRESS_HIGH), 2); 109836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATAh(push, src->base.address + z * src->layer_stride); 109936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, src->base.address + z * src->layer_stride); 110036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 110136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_SRC_Y_INT), 1); /* trigger */ 110236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, srcy >> 32); 110336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else { 110436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller BEGIN_NVC0(push, NVC0_2D(BLIT_SRC_X_FRACT), 4); 110536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, srcx); 110636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, srcx >> 32); 110736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, srcy); 110836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller PUSH_DATA (push, srcy >> 32); 110936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 111036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 11118e1dd58a7e76834c1fb6d117b6ea5755e05cfb77Christoph Bumiller nvc0_resource_validate(&dst->base, NOUVEAU_BO_WR); 11128e1dd58a7e76834c1fb6d117b6ea5755e05cfb77Christoph Bumiller nvc0_resource_validate(&src->base, NOUVEAU_BO_RD); 111336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 111436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nouveau_bufctx_reset(nvc0->bufctx, NVC0_BIND_2D); 111536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 111636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->scissor_enable) 111736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_2D(CLIP_ENABLE), 0); 111836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (mask != 0xffffffff) 111936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller IMMED_NVC0(push, NVC0_2D(OPERATION), NVC0_2D_OPERATION_SRCCOPY); 11207744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 112136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 112236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillerstatic void 112336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blit(struct pipe_context *pipe, const struct pipe_blit_info *info) 112436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller{ 112536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_context *nvc0 = nvc0_context(pipe); 112636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller boolean eng3d = FALSE; 112736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 112836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (util_format_is_depth_or_stencil(info->dst.resource->format)) { 112936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!(info->mask & PIPE_MASK_ZS)) 113036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller return; 113136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->dst.resource->format == PIPE_FORMAT_Z32_FLOAT || 113236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller info->dst.resource->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) 113336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 113436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->filter != PIPE_TEX_FILTER_NEAREST) 113536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 113636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else { 113736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!(info->mask & PIPE_MASK_RGBA)) 113836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller return; 113936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->mask != PIPE_MASK_RGBA) 114036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 114136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 114236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 114336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (nv50_miptree(info->src.resource)->layout_3d) { 114436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 114536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } else 114636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->src.box.depth != info->dst.box.depth) { 114736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 114836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller debug_printf("blit: cannot filter array or cube textures in z direction"); 114936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 115036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 1151443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller if (!eng3d && info->dst.format != info->src.format) { 1152d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (!nv50_2d_dst_format_faithful(info->dst.format)) { 115336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 1154d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller } else 1155d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (!nv50_2d_src_format_faithful(info->src.format)) { 1156d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (!util_format_is_luminance(info->src.format)) { 1157d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (util_format_is_intensity(info->src.format)) 1158d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller eng3d = info->src.format != PIPE_FORMAT_I8_UNORM; 1159d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller else 1160d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (!nv50_2d_dst_format_ops_supported(info->dst.format)) 1161d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller eng3d = TRUE; 1162d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller else 1163d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller eng3d = !nv50_2d_format_supported(info->src.format); 1164d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller } 1165d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller } else 1166d801545964f8183bb17ed913b7c19482dad43b6cChristoph Bumiller if (util_format_is_luminance_alpha(info->src.format)) 1167443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller eng3d = TRUE; 1168443b247878edd6a67adc073b0c36e2941436b9a0Christoph Bumiller } 116936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 117036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->src.resource->nr_samples == 8 && 117136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller info->dst.resource->nr_samples <= 1) 117236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 117336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller#if 0 117436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* FIXME: can't make this work with eng2d anymore, at least not on nv50 */ 117536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (info->src.resource->nr_samples > 1 || 117636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller info->dst.resource->nr_samples > 1) 117736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 1178de80660c2bd43db112b6c82d970660ed9806cd33Marek Olšák#endif 117936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller /* FIXME: find correct src coordinates adjustments */ 118036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if ((info->src.box.width != info->dst.box.width && 118136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller info->src.box.width != -info->dst.box.width) || 118236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller (info->src.box.height != info->dst.box.height && 118336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller info->src.box.height != -info->dst.box.height)) 118436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller eng3d = TRUE; 118536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 118636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!eng3d) 118736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blit_eng2d(nvc0, info); 118836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller else 118936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blit_3d(nvc0, info); 1190198f514aa6f08bc43a3002519843b0fe94f340bdChristoph Bumiller 1191198f514aa6f08bc43a3002519843b0fe94f340bdChristoph Bumiller NOUVEAU_DRV_STAT(&nvc0->screen->base, tex_blit_count, 1); 119236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller} 11937744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 11947744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumillerboolean 119536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitter_create(struct nvc0_screen *screen) 11967744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller{ 119736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller screen->blitter = CALLOC_STRUCT(nvc0_blitter); 119836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!screen->blitter) { 119936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NOUVEAU_ERR("failed to allocate blitter struct\n"); 12007744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller return FALSE; 12017744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller } 120236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller screen->blitter->screen = screen; 12037744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 120436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe_mutex_init(screen->blitter->mutex); 12057744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 120636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blitter_make_vp(screen->blitter); 120736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_blitter_make_sampler(screen->blitter); 12087744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 120936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller return TRUE; 121036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller} 12117744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 121236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillervoid 121336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitter_destroy(struct nvc0_screen *screen) 121436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller{ 121536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_blitter *blitter = screen->blitter; 121636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller unsigned i, m; 121736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 121836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller for (i = 0; i < NV50_BLIT_MAX_TEXTURE_TYPES; ++i) { 121936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller for (m = 0; m < NV50_BLIT_MODES; ++m) { 122036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller struct nvc0_program *prog = blitter->fp[i][m]; 122136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (prog) { 122236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0_program_destroy(NULL, prog); 122336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller FREE((void *)prog->pipe.tokens); 122436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller FREE(prog); 122536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 122636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 122736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 12287744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 122936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller FREE(blitter); 12307744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller} 12317744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 123236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillerboolean 123336ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumillernvc0_blitctx_create(struct nvc0_context *nvc0) 123436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller{ 123536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->blit = CALLOC_STRUCT(nvc0_blitctx); 123636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller if (!nvc0->blit) { 123736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller NOUVEAU_ERR("failed to allocate blit context\n"); 123836ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller return FALSE; 123936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller } 124036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 124136ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller nvc0->blit->nvc0 = nvc0; 124236ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller 12438aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller nvc0->blit->rast.pipe.gl_rasterization_rules = 1; 12448aa8b0539eda00b9bafacb69774b26975db66ae4Christoph Bumiller 124536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller return TRUE; 124636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller} 12477744e867b7f45f3f9d763b61d7219dc28ca39c45Christoph Bumiller 12484c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillervoid 12494c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumillernvc0_init_surface_functions(struct nvc0_context *nvc0) 12504c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller{ 12511ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs struct pipe_context *pipe = &nvc0->base.pipe; 12521ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs 12531ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->resource_copy_region = nvc0_resource_copy_region; 125436ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller pipe->blit = nvc0_blit; 12551ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->clear_render_target = nvc0_clear_render_target; 12561ba8e9510812f155359d380bda6876cdee5ba21eBen Skeggs pipe->clear_depth_stencil = nvc0_clear_depth_stencil; 12574c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller} 12584c2247538394a313e1e90bfcd07c1ab9c7d41281Christoph Bumiller 1259