Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
4574 views
/*1* Copyright 2008 Ben Skeggs2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#include <stdint.h>2324#include "pipe/p_defines.h"2526#include "util/u_inlines.h"27#include "util/u_pack_color.h"28#include "util/format/u_format.h"29#include "util/u_surface.h"3031#include "tgsi/tgsi_ureg.h"3233#include "os/os_thread.h"3435#include "nvc0/nvc0_context.h"36#include "nvc0/nvc0_resource.h"3738#include "nv50/g80_defs.xml.h"39#include "nv50/g80_texture.xml.h"4041/* these are used in nv50_blit.h */42#define NV50_ENG2D_SUPPORTED_FORMATS 0xff9ccfe1cce3ccc9ULL43#define NV50_ENG2D_NOCONVERT_FORMATS 0x009cc02000000000ULL44#define NV50_ENG2D_LUMINANCE_FORMATS 0x001cc02000000000ULL45#define NV50_ENG2D_INTENSITY_FORMATS 0x0080000000000000ULL46#define NV50_ENG2D_OPERATION_FORMATS 0x060001c000638000ULL4748#define NOUVEAU_DRIVER 0xc049#include "nv50/nv50_blit.h"5051static inline uint8_t52nvc0_2d_format(enum pipe_format format, bool dst, bool dst_src_equal)53{54uint8_t id = nvc0_format_table[format].rt;5556/* A8_UNORM is treated as I8_UNORM as far as the 2D engine is concerned. */57if (!dst && unlikely(format == PIPE_FORMAT_I8_UNORM) && !dst_src_equal)58return G80_SURFACE_FORMAT_A8_UNORM;5960/* Hardware values for color formats range from 0xc0 to 0xff,61* but the 2D engine doesn't support all of them.62*/63if (nv50_2d_format_supported(format))64return id;65assert(dst_src_equal);6667switch (util_format_get_blocksize(format)) {68case 1:69return G80_SURFACE_FORMAT_R8_UNORM;70case 2:71return G80_SURFACE_FORMAT_RG8_UNORM;72case 4:73return G80_SURFACE_FORMAT_BGRA8_UNORM;74case 8:75return G80_SURFACE_FORMAT_RGBA16_UNORM;76case 16:77return G80_SURFACE_FORMAT_RGBA32_FLOAT;78default:79assert(0);80return 0;81}82}8384static int85nvc0_2d_texture_set(struct nouveau_pushbuf *push, bool dst,86struct nv50_miptree *mt, unsigned level, unsigned layer,87enum pipe_format pformat, bool dst_src_pformat_equal)88{89struct nouveau_bo *bo = mt->base.bo;90uint32_t width, height, depth;91uint32_t format;92uint32_t mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT;93uint32_t offset = mt->level[level].offset;9495format = nvc0_2d_format(pformat, dst, dst_src_pformat_equal);96if (!format) {97NOUVEAU_ERR("invalid/unsupported surface format: %s\n",98util_format_name(pformat));99return 1;100}101102width = u_minify(mt->base.base.width0, level) << mt->ms_x;103height = u_minify(mt->base.base.height0, level) << mt->ms_y;104depth = u_minify(mt->base.base.depth0, level);105106/* layer has to be < depth, and depth > tile depth / 2 */107108if (!mt->layout_3d) {109offset += mt->layer_stride * layer;110layer = 0;111depth = 1;112} else113if (!dst) {114offset += nvc0_mt_zslice_offset(mt, level, layer);115layer = 0;116}117118if (!nouveau_bo_memtype(bo)) {119BEGIN_NVC0(push, SUBC_2D(mthd), 2);120PUSH_DATA (push, format);121PUSH_DATA (push, 1);122BEGIN_NVC0(push, SUBC_2D(mthd + 0x14), 5);123PUSH_DATA (push, mt->level[level].pitch);124PUSH_DATA (push, width);125PUSH_DATA (push, height);126PUSH_DATAh(push, bo->offset + offset);127PUSH_DATA (push, bo->offset + offset);128} else {129BEGIN_NVC0(push, SUBC_2D(mthd), 5);130PUSH_DATA (push, format);131PUSH_DATA (push, 0);132PUSH_DATA (push, mt->level[level].tile_mode);133PUSH_DATA (push, depth);134PUSH_DATA (push, layer);135BEGIN_NVC0(push, SUBC_2D(mthd + 0x18), 4);136PUSH_DATA (push, width);137PUSH_DATA (push, height);138PUSH_DATAh(push, bo->offset + offset);139PUSH_DATA (push, bo->offset + offset);140}141142if (dst) {143IMMED_NVC0(push, SUBC_2D(NVC0_2D_SET_DST_COLOR_RENDER_TO_ZETA_SURFACE),144util_format_is_depth_or_stencil(pformat));145}146147#if 0148if (dst) {149BEGIN_NVC0(push, SUBC_2D(NVC0_2D_CLIP_X), 4);150PUSH_DATA (push, 0);151PUSH_DATA (push, 0);152PUSH_DATA (push, width);153PUSH_DATA (push, height);154}155#endif156return 0;157}158159static int160nvc0_2d_texture_do_copy(struct nouveau_pushbuf *push,161struct nv50_miptree *dst, unsigned dst_level,162unsigned dx, unsigned dy, unsigned dz,163struct nv50_miptree *src, unsigned src_level,164unsigned sx, unsigned sy, unsigned sz,165unsigned w, unsigned h)166{167const enum pipe_format dfmt = dst->base.base.format;168const enum pipe_format sfmt = src->base.base.format;169int ret;170bool eqfmt = dfmt == sfmt;171172if (!PUSH_SPACE(push, 2 * 16 + 32))173return PIPE_ERROR;174175ret = nvc0_2d_texture_set(push, true, dst, dst_level, dz, dfmt, eqfmt);176if (ret)177return ret;178179ret = nvc0_2d_texture_set(push, false, src, src_level, sz, sfmt, eqfmt);180if (ret)181return ret;182183IMMED_NVC0(push, NVC0_2D(BLIT_CONTROL), 0x00);184BEGIN_NVC0(push, NVC0_2D(BLIT_DST_X), 4);185PUSH_DATA (push, dx << dst->ms_x);186PUSH_DATA (push, dy << dst->ms_y);187PUSH_DATA (push, w << dst->ms_x);188PUSH_DATA (push, h << dst->ms_y);189BEGIN_NVC0(push, NVC0_2D(BLIT_DU_DX_FRACT), 4);190PUSH_DATA (push, 0);191PUSH_DATA (push, 1);192PUSH_DATA (push, 0);193PUSH_DATA (push, 1);194BEGIN_NVC0(push, NVC0_2D(BLIT_SRC_X_FRACT), 4);195PUSH_DATA (push, 0);196PUSH_DATA (push, sx << src->ms_x);197PUSH_DATA (push, 0);198PUSH_DATA (push, sy << src->ms_y);199200return 0;201}202203static void204nvc0_resource_copy_region(struct pipe_context *pipe,205struct pipe_resource *dst, unsigned dst_level,206unsigned dstx, unsigned dsty, unsigned dstz,207struct pipe_resource *src, unsigned src_level,208const struct pipe_box *src_box)209{210struct nvc0_context *nvc0 = nvc0_context(pipe);211int ret;212bool m2mf;213unsigned dst_layer = dstz, src_layer = src_box->z;214215if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {216nouveau_copy_buffer(&nvc0->base,217nv04_resource(dst), dstx,218nv04_resource(src), src_box->x, src_box->width);219NOUVEAU_DRV_STAT(&nvc0->screen->base, buf_copy_bytes, src_box->width);220return;221}222NOUVEAU_DRV_STAT(&nvc0->screen->base, tex_copy_count, 1);223224/* 0 and 1 are equal, only supporting 0/1, 2, 4 and 8 */225assert((src->nr_samples | 1) == (dst->nr_samples | 1));226227m2mf = (src->format == dst->format) ||228(util_format_get_blocksizebits(src->format) ==229util_format_get_blocksizebits(dst->format));230231nv04_resource(dst)->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;232233if (m2mf) {234struct nv50_miptree *src_mt = nv50_miptree(src);235struct nv50_miptree *dst_mt = nv50_miptree(dst);236struct nv50_m2mf_rect drect, srect;237unsigned i;238unsigned nx = util_format_get_nblocksx(src->format, src_box->width)239<< src_mt->ms_x;240unsigned ny = util_format_get_nblocksy(src->format, src_box->height)241<< src_mt->ms_y;242243nv50_m2mf_rect_setup(&drect, dst, dst_level, dstx, dsty, dstz);244nv50_m2mf_rect_setup(&srect, src, src_level,245src_box->x, src_box->y, src_box->z);246247for (i = 0; i < src_box->depth; ++i) {248nvc0->m2mf_copy_rect(nvc0, &drect, &srect, nx, ny);249250if (dst_mt->layout_3d)251drect.z++;252else253drect.base += dst_mt->layer_stride;254255if (src_mt->layout_3d)256srect.z++;257else258srect.base += src_mt->layer_stride;259}260return;261}262263assert(nv50_2d_dst_format_faithful(dst->format));264assert(nv50_2d_src_format_faithful(src->format));265266BCTX_REFN(nvc0->bufctx, 2D, nv04_resource(src), RD);267BCTX_REFN(nvc0->bufctx, 2D, nv04_resource(dst), WR);268nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx);269nouveau_pushbuf_validate(nvc0->base.pushbuf);270271for (; dst_layer < dstz + src_box->depth; ++dst_layer, ++src_layer) {272ret = nvc0_2d_texture_do_copy(nvc0->base.pushbuf,273nv50_miptree(dst), dst_level,274dstx, dsty, dst_layer,275nv50_miptree(src), src_level,276src_box->x, src_box->y, src_layer,277src_box->width, src_box->height);278if (ret)279break;280}281nouveau_bufctx_reset(nvc0->bufctx, 0);282}283284static void285nvc0_clear_render_target(struct pipe_context *pipe,286struct pipe_surface *dst,287const union pipe_color_union *color,288unsigned dstx, unsigned dsty,289unsigned width, unsigned height,290bool render_condition_enabled)291{292struct nvc0_context *nvc0 = nvc0_context(pipe);293struct nouveau_pushbuf *push = nvc0->base.pushbuf;294struct nv50_surface *sf = nv50_surface(dst);295struct nv04_resource *res = nv04_resource(sf->base.texture);296unsigned z;297298assert(dst->texture->target != PIPE_BUFFER);299300if (!PUSH_SPACE(push, 32 + sf->depth))301return;302303PUSH_REFN (push, res->bo, res->domain | NOUVEAU_BO_WR);304305BEGIN_NVC0(push, NVC0_3D(CLEAR_COLOR(0)), 4);306PUSH_DATAf(push, color->f[0]);307PUSH_DATAf(push, color->f[1]);308PUSH_DATAf(push, color->f[2]);309PUSH_DATAf(push, color->f[3]);310311BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);312PUSH_DATA (push, ( width << 16) | dstx);313PUSH_DATA (push, (height << 16) | dsty);314315BEGIN_NVC0(push, NVC0_3D(RT_CONTROL), 1);316PUSH_DATA (push, 1);317BEGIN_NVC0(push, NVC0_3D(RT_ADDRESS_HIGH(0)), 9);318PUSH_DATAh(push, res->address + sf->offset);319PUSH_DATA (push, res->address + sf->offset);320if (likely(nouveau_bo_memtype(res->bo))) {321struct nv50_miptree *mt = nv50_miptree(dst->texture);322323PUSH_DATA(push, sf->width);324PUSH_DATA(push, sf->height);325PUSH_DATA(push, nvc0_format_table[dst->format].rt);326PUSH_DATA(push, (mt->layout_3d << 16) |327mt->level[sf->base.u.tex.level].tile_mode);328PUSH_DATA(push, dst->u.tex.first_layer + sf->depth);329PUSH_DATA(push, mt->layer_stride >> 2);330PUSH_DATA(push, dst->u.tex.first_layer);331IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), mt->ms_mode);332} else {333if (res->base.target == PIPE_BUFFER) {334PUSH_DATA(push, 262144);335PUSH_DATA(push, 1);336} else {337PUSH_DATA(push, nv50_miptree(&res->base)->level[0].pitch);338PUSH_DATA(push, sf->height);339}340PUSH_DATA(push, nvc0_format_table[sf->base.format].rt);341PUSH_DATA(push, 1 << 12);342PUSH_DATA(push, 1);343PUSH_DATA(push, 0);344PUSH_DATA(push, 0);345346IMMED_NVC0(push, NVC0_3D(ZETA_ENABLE), 0);347IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), 0);348349/* tiled textures don't have to be fenced, they're not mapped directly */350nvc0_resource_fence(res, NOUVEAU_BO_WR);351}352353if (!render_condition_enabled)354IMMED_NVC0(push, NVC0_3D(COND_MODE), NVC0_3D_COND_MODE_ALWAYS);355356BEGIN_NIC0(push, NVC0_3D(CLEAR_BUFFERS), sf->depth);357for (z = 0; z < sf->depth; ++z) {358PUSH_DATA (push, 0x3c |359(z << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT));360}361362if (!render_condition_enabled)363IMMED_NVC0(push, NVC0_3D(COND_MODE), nvc0->cond_condmode);364365nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;366}367368static void369nvc0_clear_buffer_push_nvc0(struct pipe_context *pipe,370struct pipe_resource *res,371unsigned offset, unsigned size,372const void *data, int data_size)373{374struct nvc0_context *nvc0 = nvc0_context(pipe);375struct nouveau_pushbuf *push = nvc0->base.pushbuf;376struct nv04_resource *buf = nv04_resource(res);377unsigned i;378379nouveau_bufctx_refn(nvc0->bufctx, 0, buf->bo, buf->domain | NOUVEAU_BO_WR);380nouveau_pushbuf_bufctx(push, nvc0->bufctx);381nouveau_pushbuf_validate(push);382383unsigned count = (size + 3) / 4;384unsigned data_words = data_size / 4;385386while (count) {387unsigned nr_data = MIN2(count, NV04_PFIFO_MAX_PACKET_LEN) / data_words;388unsigned nr = nr_data * data_words;389390if (!PUSH_SPACE(push, nr + 9))391break;392393BEGIN_NVC0(push, NVC0_M2MF(OFFSET_OUT_HIGH), 2);394PUSH_DATAh(push, buf->address + offset);395PUSH_DATA (push, buf->address + offset);396BEGIN_NVC0(push, NVC0_M2MF(LINE_LENGTH_IN), 2);397PUSH_DATA (push, MIN2(size, nr * 4));398PUSH_DATA (push, 1);399BEGIN_NVC0(push, NVC0_M2MF(EXEC), 1);400PUSH_DATA (push, 0x100111);401402/* must not be interrupted (trap on QUERY fence, 0x50 works however) */403BEGIN_NIC0(push, NVC0_M2MF(DATA), nr);404for (i = 0; i < nr_data; i++)405PUSH_DATAp(push, data, data_words);406407count -= nr;408offset += nr * 4;409size -= nr * 4;410}411412nvc0_resource_validate(buf, NOUVEAU_BO_WR);413414nouveau_bufctx_reset(nvc0->bufctx, 0);415}416417static void418nvc0_clear_buffer_push_nve4(struct pipe_context *pipe,419struct pipe_resource *res,420unsigned offset, unsigned size,421const void *data, int data_size)422{423struct nvc0_context *nvc0 = nvc0_context(pipe);424struct nouveau_pushbuf *push = nvc0->base.pushbuf;425struct nv04_resource *buf = nv04_resource(res);426unsigned i;427428nouveau_bufctx_refn(nvc0->bufctx, 0, buf->bo, buf->domain | NOUVEAU_BO_WR);429nouveau_pushbuf_bufctx(push, nvc0->bufctx);430nouveau_pushbuf_validate(push);431432unsigned count = (size + 3) / 4;433unsigned data_words = data_size / 4;434435while (count) {436unsigned nr_data = MIN2(count, NV04_PFIFO_MAX_PACKET_LEN) / data_words;437unsigned nr = nr_data * data_words;438439if (!PUSH_SPACE(push, nr + 10))440break;441442BEGIN_NVC0(push, NVE4_P2MF(UPLOAD_DST_ADDRESS_HIGH), 2);443PUSH_DATAh(push, buf->address + offset);444PUSH_DATA (push, buf->address + offset);445BEGIN_NVC0(push, NVE4_P2MF(UPLOAD_LINE_LENGTH_IN), 2);446PUSH_DATA (push, MIN2(size, nr * 4));447PUSH_DATA (push, 1);448/* must not be interrupted (trap on QUERY fence, 0x50 works however) */449BEGIN_1IC0(push, NVE4_P2MF(UPLOAD_EXEC), nr + 1);450PUSH_DATA (push, 0x1001);451for (i = 0; i < nr_data; i++)452PUSH_DATAp(push, data, data_words);453454count -= nr;455offset += nr * 4;456size -= nr * 4;457}458459nvc0_resource_validate(buf, NOUVEAU_BO_WR);460461nouveau_bufctx_reset(nvc0->bufctx, 0);462}463464static void465nvc0_clear_buffer_push(struct pipe_context *pipe,466struct pipe_resource *res,467unsigned offset, unsigned size,468const void *data, int data_size)469{470struct nvc0_context *nvc0 = nvc0_context(pipe);471unsigned tmp;472473if (data_size == 1) {474tmp = *(unsigned char *)data;475tmp = (tmp << 24) | (tmp << 16) | (tmp << 8) | tmp;476data = &tmp;477data_size = 4;478} else if (data_size == 2) {479tmp = *(unsigned short *)data;480tmp = (tmp << 16) | tmp;481data = &tmp;482data_size = 4;483}484485if (nvc0->screen->base.class_3d < NVE4_3D_CLASS)486nvc0_clear_buffer_push_nvc0(pipe, res, offset, size, data, data_size);487else488nvc0_clear_buffer_push_nve4(pipe, res, offset, size, data, data_size);489}490491static void492nvc0_clear_buffer(struct pipe_context *pipe,493struct pipe_resource *res,494unsigned offset, unsigned size,495const void *data, int data_size)496{497struct nvc0_context *nvc0 = nvc0_context(pipe);498struct nouveau_pushbuf *push = nvc0->base.pushbuf;499struct nv04_resource *buf = nv04_resource(res);500union pipe_color_union color;501enum pipe_format dst_fmt;502unsigned width, height, elements;503504assert(res->target == PIPE_BUFFER);505assert(nouveau_bo_memtype(buf->bo) == 0);506507switch (data_size) {508case 16:509dst_fmt = PIPE_FORMAT_R32G32B32A32_UINT;510memcpy(&color.ui, data, 16);511break;512case 12:513/* RGB32 is not a valid RT format. This will be handled by the pushbuf514* uploader.515*/516dst_fmt = PIPE_FORMAT_NONE; /* Init dst_fmt to silence gcc warning */517break;518case 8:519dst_fmt = PIPE_FORMAT_R32G32_UINT;520memcpy(&color.ui, data, 8);521memset(&color.ui[2], 0, 8);522break;523case 4:524dst_fmt = PIPE_FORMAT_R32_UINT;525memcpy(&color.ui, data, 4);526memset(&color.ui[1], 0, 12);527break;528case 2:529dst_fmt = PIPE_FORMAT_R16_UINT;530color.ui[0] = util_cpu_to_le32(531util_le16_to_cpu(*(unsigned short *)data));532memset(&color.ui[1], 0, 12);533break;534case 1:535dst_fmt = PIPE_FORMAT_R8_UINT;536color.ui[0] = util_cpu_to_le32(*(unsigned char *)data);537memset(&color.ui[1], 0, 12);538break;539default:540assert(!"Unsupported element size");541return;542}543544util_range_add(&buf->base, &buf->valid_buffer_range, offset, offset + size);545546assert(size % data_size == 0);547548if (data_size == 12) {549nvc0_clear_buffer_push(pipe, res, offset, size, data, data_size);550return;551}552553if (offset & 0xff) {554unsigned fixup_size = MIN2(size, align(offset, 0x100) - offset);555assert(fixup_size % data_size == 0);556nvc0_clear_buffer_push(pipe, res, offset, fixup_size, data, data_size);557offset += fixup_size;558size -= fixup_size;559if (!size)560return;561}562563elements = size / data_size;564height = (elements + 16383) / 16384;565width = elements / height;566if (height > 1)567width &= ~0xff;568assert(width > 0);569570if (!PUSH_SPACE(push, 40))571return;572573PUSH_REFN (push, buf->bo, buf->domain | NOUVEAU_BO_WR);574575BEGIN_NVC0(push, NVC0_3D(CLEAR_COLOR(0)), 4);576PUSH_DATA (push, color.ui[0]);577PUSH_DATA (push, color.ui[1]);578PUSH_DATA (push, color.ui[2]);579PUSH_DATA (push, color.ui[3]);580BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);581PUSH_DATA (push, width << 16);582PUSH_DATA (push, height << 16);583584IMMED_NVC0(push, NVC0_3D(RT_CONTROL), 1);585586BEGIN_NVC0(push, NVC0_3D(RT_ADDRESS_HIGH(0)), 9);587PUSH_DATAh(push, buf->address + offset);588PUSH_DATA (push, buf->address + offset);589PUSH_DATA (push, align(width * data_size, 0x100));590PUSH_DATA (push, height);591PUSH_DATA (push, nvc0_format_table[dst_fmt].rt);592PUSH_DATA (push, NVC0_3D_RT_TILE_MODE_LINEAR);593PUSH_DATA (push, 1);594PUSH_DATA (push, 0);595PUSH_DATA (push, 0);596597IMMED_NVC0(push, NVC0_3D(ZETA_ENABLE), 0);598IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), 0);599600IMMED_NVC0(push, NVC0_3D(COND_MODE), NVC0_3D_COND_MODE_ALWAYS);601602IMMED_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 0x3c);603604IMMED_NVC0(push, NVC0_3D(COND_MODE), nvc0->cond_condmode);605606nvc0_resource_validate(buf, NOUVEAU_BO_WR);607608if (width * height != elements) {609offset += width * height * data_size;610width = elements - width * height;611nvc0_clear_buffer_push(pipe, res, offset, width * data_size,612data, data_size);613}614615nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;616}617618static void619nvc0_clear_depth_stencil(struct pipe_context *pipe,620struct pipe_surface *dst,621unsigned clear_flags,622double depth,623unsigned stencil,624unsigned dstx, unsigned dsty,625unsigned width, unsigned height,626bool render_condition_enabled)627{628struct nvc0_context *nvc0 = nvc0_context(pipe);629struct nouveau_pushbuf *push = nvc0->base.pushbuf;630struct nv50_miptree *mt = nv50_miptree(dst->texture);631struct nv50_surface *sf = nv50_surface(dst);632uint32_t mode = 0;633int unk = mt->base.base.target == PIPE_TEXTURE_2D;634unsigned z;635636assert(dst->texture->target != PIPE_BUFFER);637638if (!PUSH_SPACE(push, 32 + sf->depth))639return;640641PUSH_REFN (push, mt->base.bo, mt->base.domain | NOUVEAU_BO_WR);642643if (clear_flags & PIPE_CLEAR_DEPTH) {644BEGIN_NVC0(push, NVC0_3D(CLEAR_DEPTH), 1);645PUSH_DATAf(push, depth);646mode |= NVC0_3D_CLEAR_BUFFERS_Z;647}648649if (clear_flags & PIPE_CLEAR_STENCIL) {650BEGIN_NVC0(push, NVC0_3D(CLEAR_STENCIL), 1);651PUSH_DATA (push, stencil & 0xff);652mode |= NVC0_3D_CLEAR_BUFFERS_S;653}654655BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);656PUSH_DATA (push, ( width << 16) | dstx);657PUSH_DATA (push, (height << 16) | dsty);658659BEGIN_NVC0(push, NVC0_3D(ZETA_ADDRESS_HIGH), 5);660PUSH_DATAh(push, mt->base.address + sf->offset);661PUSH_DATA (push, mt->base.address + sf->offset);662PUSH_DATA (push, nvc0_format_table[dst->format].rt);663PUSH_DATA (push, mt->level[sf->base.u.tex.level].tile_mode);664PUSH_DATA (push, mt->layer_stride >> 2);665BEGIN_NVC0(push, NVC0_3D(ZETA_ENABLE), 1);666PUSH_DATA (push, 1);667BEGIN_NVC0(push, NVC0_3D(ZETA_HORIZ), 3);668PUSH_DATA (push, sf->width);669PUSH_DATA (push, sf->height);670PUSH_DATA (push, (unk << 16) | (dst->u.tex.first_layer + sf->depth));671BEGIN_NVC0(push, NVC0_3D(ZETA_BASE_LAYER), 1);672PUSH_DATA (push, dst->u.tex.first_layer);673IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), mt->ms_mode);674675if (!render_condition_enabled)676IMMED_NVC0(push, NVC0_3D(COND_MODE), NVC0_3D_COND_MODE_ALWAYS);677678BEGIN_NIC0(push, NVC0_3D(CLEAR_BUFFERS), sf->depth);679for (z = 0; z < sf->depth; ++z) {680PUSH_DATA (push, mode |681(z << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT));682}683684if (!render_condition_enabled)685IMMED_NVC0(push, NVC0_3D(COND_MODE), nvc0->cond_condmode);686687nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER;688}689690void691nvc0_clear(struct pipe_context *pipe, unsigned buffers,692const struct pipe_scissor_state *scissor_state,693const union pipe_color_union *color,694double depth, unsigned stencil)695{696struct nvc0_context *nvc0 = nvc0_context(pipe);697struct nouveau_pushbuf *push = nvc0->base.pushbuf;698struct pipe_framebuffer_state *fb = &nvc0->framebuffer;699unsigned i, j, k;700uint32_t mode = 0;701702/* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */703if (!nvc0_state_validate_3d(nvc0, NVC0_NEW_3D_FRAMEBUFFER))704return;705706if (scissor_state) {707uint32_t minx = scissor_state->minx;708uint32_t maxx = MIN2(fb->width, scissor_state->maxx);709uint32_t miny = scissor_state->miny;710uint32_t maxy = MIN2(fb->height, scissor_state->maxy);711if (maxx <= minx || maxy <= miny)712return;713714BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);715PUSH_DATA (push, minx | (maxx - minx) << 16);716PUSH_DATA (push, miny | (maxy - miny) << 16);717}718719if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {720BEGIN_NVC0(push, NVC0_3D(CLEAR_COLOR(0)), 4);721PUSH_DATAf(push, color->f[0]);722PUSH_DATAf(push, color->f[1]);723PUSH_DATAf(push, color->f[2]);724PUSH_DATAf(push, color->f[3]);725if (buffers & PIPE_CLEAR_COLOR0)726mode =727NVC0_3D_CLEAR_BUFFERS_R | NVC0_3D_CLEAR_BUFFERS_G |728NVC0_3D_CLEAR_BUFFERS_B | NVC0_3D_CLEAR_BUFFERS_A;729}730731if (buffers & PIPE_CLEAR_DEPTH) {732BEGIN_NVC0(push, NVC0_3D(CLEAR_DEPTH), 1);733PUSH_DATA (push, fui(depth));734mode |= NVC0_3D_CLEAR_BUFFERS_Z;735}736737if (buffers & PIPE_CLEAR_STENCIL) {738BEGIN_NVC0(push, NVC0_3D(CLEAR_STENCIL), 1);739PUSH_DATA (push, stencil & 0xff);740mode |= NVC0_3D_CLEAR_BUFFERS_S;741}742743if (mode) {744int zs_layers = 0, color0_layers = 0;745if (fb->cbufs[0] && (mode & 0x3c))746color0_layers = fb->cbufs[0]->u.tex.last_layer -747fb->cbufs[0]->u.tex.first_layer + 1;748if (fb->zsbuf && (mode & ~0x3c))749zs_layers = fb->zsbuf->u.tex.last_layer -750fb->zsbuf->u.tex.first_layer + 1;751752for (j = 0; j < MIN2(zs_layers, color0_layers); j++) {753BEGIN_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 1);754PUSH_DATA(push, mode | (j << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT));755}756for (k = j; k < zs_layers; k++) {757BEGIN_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 1);758PUSH_DATA(push, (mode & ~0x3c) | (k << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT));759}760for (k = j; k < color0_layers; k++) {761BEGIN_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 1);762PUSH_DATA(push, (mode & 0x3c) | (k << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT));763}764}765766for (i = 1; i < fb->nr_cbufs; i++) {767struct pipe_surface *sf = fb->cbufs[i];768if (!sf || !(buffers & (PIPE_CLEAR_COLOR0 << i)))769continue;770for (j = 0; j <= sf->u.tex.last_layer - sf->u.tex.first_layer; j++) {771BEGIN_NVC0(push, NVC0_3D(CLEAR_BUFFERS), 1);772PUSH_DATA (push, (i << 6) | 0x3c |773(j << NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT));774}775}776777/* restore screen scissor */778if (scissor_state) {779BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);780PUSH_DATA (push, fb->width << 16);781PUSH_DATA (push, fb->height << 16);782}783}784785static void786gm200_evaluate_depth_buffer(struct pipe_context *pipe)787{788struct nvc0_context *nvc0 = nvc0_context(pipe);789struct nouveau_pushbuf *push = nvc0->base.pushbuf;790791nvc0_state_validate_3d(nvc0, NVC0_NEW_3D_FRAMEBUFFER);792IMMED_NVC0(push, SUBC_3D(0x11fc), 1);793}794795796/* =============================== BLIT CODE ===================================797*/798799struct nvc0_blitter800{801struct nvc0_program *fp[NV50_BLIT_MAX_TEXTURE_TYPES][NV50_BLIT_MODES];802struct nvc0_program *vp;803804struct nv50_tsc_entry sampler[2]; /* nearest, bilinear */805806mtx_t mutex;807808struct nvc0_screen *screen;809};810811struct nvc0_blitctx812{813struct nvc0_context *nvc0;814struct nvc0_program *fp;815struct nvc0_program *vp;816uint8_t mode;817uint16_t color_mask;818uint8_t filter;819uint8_t render_condition_enable;820enum pipe_texture_target target;821struct {822struct pipe_framebuffer_state fb;823struct nvc0_window_rect_stateobj window_rect;824struct nvc0_rasterizer_stateobj *rast;825struct nvc0_program *vp;826struct nvc0_program *tcp;827struct nvc0_program *tep;828struct nvc0_program *gp;829struct nvc0_program *fp;830unsigned num_textures[5];831unsigned num_samplers[5];832struct pipe_sampler_view *texture[2];833struct nv50_tsc_entry *sampler[2];834unsigned min_samples;835uint32_t dirty_3d;836} saved;837struct nvc0_rasterizer_stateobj rast;838};839840static void *841nvc0_blitter_make_vp(struct pipe_context *pipe)842{843struct ureg_program *ureg;844struct ureg_src ipos, itex;845struct ureg_dst opos, otex;846847ureg = ureg_create(PIPE_SHADER_VERTEX);848if (!ureg)849return NULL;850851opos = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0);852ipos = ureg_DECL_vs_input(ureg, 0);853otex = ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, 0);854itex = ureg_DECL_vs_input(ureg, 1);855856ureg_MOV(ureg, ureg_writemask(opos, TGSI_WRITEMASK_XY ), ipos);857ureg_MOV(ureg, ureg_writemask(otex, TGSI_WRITEMASK_XYZ), itex);858ureg_END(ureg);859860return ureg_create_shader_and_destroy(ureg, pipe);861}862863static void864nvc0_blitter_make_sampler(struct nvc0_blitter *blit)865{866/* clamp to edge, min/max lod = 0, nearest filtering */867868blit->sampler[0].id = -1;869870blit->sampler[0].tsc[0] = G80_TSC_0_SRGB_CONVERSION |871(G80_TSC_WRAP_CLAMP_TO_EDGE << G80_TSC_0_ADDRESS_U__SHIFT) |872(G80_TSC_WRAP_CLAMP_TO_EDGE << G80_TSC_0_ADDRESS_V__SHIFT) |873(G80_TSC_WRAP_CLAMP_TO_EDGE << G80_TSC_0_ADDRESS_P__SHIFT);874blit->sampler[0].tsc[1] =875G80_TSC_1_MAG_FILTER_NEAREST |876G80_TSC_1_MIN_FILTER_NEAREST |877G80_TSC_1_MIP_FILTER_NONE;878879/* clamp to edge, min/max lod = 0, bilinear filtering */880881blit->sampler[1].id = -1;882883blit->sampler[1].tsc[0] = blit->sampler[0].tsc[0];884blit->sampler[1].tsc[1] =885G80_TSC_1_MAG_FILTER_LINEAR |886G80_TSC_1_MIN_FILTER_LINEAR |887G80_TSC_1_MIP_FILTER_NONE;888}889890static void891nvc0_blit_select_vp(struct nvc0_blitctx *ctx)892{893struct nvc0_blitter *blitter = ctx->nvc0->screen->blitter;894895if (!blitter->vp) {896mtx_lock(&blitter->mutex);897if (!blitter->vp)898blitter->vp = nvc0_blitter_make_vp(&ctx->nvc0->base.pipe);899mtx_unlock(&blitter->mutex);900}901ctx->vp = blitter->vp;902}903904static void905nvc0_blit_select_fp(struct nvc0_blitctx *ctx, const struct pipe_blit_info *info)906{907struct nvc0_blitter *blitter = ctx->nvc0->screen->blitter;908909const enum pipe_texture_target ptarg =910nv50_blit_reinterpret_pipe_texture_target(info->src.resource->target);911912const unsigned targ = nv50_blit_texture_type(ptarg);913const unsigned mode = ctx->mode;914915if (!blitter->fp[targ][mode]) {916mtx_lock(&blitter->mutex);917if (!blitter->fp[targ][mode])918blitter->fp[targ][mode] =919nv50_blitter_make_fp(&ctx->nvc0->base.pipe, mode, ptarg);920mtx_unlock(&blitter->mutex);921}922ctx->fp = blitter->fp[targ][mode];923}924925static void926nvc0_blit_set_dst(struct nvc0_blitctx *ctx,927struct pipe_resource *res, unsigned level, unsigned layer,928enum pipe_format format)929{930struct nvc0_context *nvc0 = ctx->nvc0;931struct pipe_context *pipe = &nvc0->base.pipe;932struct pipe_surface templ;933934if (util_format_is_depth_or_stencil(format))935templ.format = nv50_blit_zeta_to_colour_format(format);936else937templ.format = format;938939templ.u.tex.level = level;940templ.u.tex.first_layer = templ.u.tex.last_layer = layer;941942if (layer == -1) {943templ.u.tex.first_layer = 0;944templ.u.tex.last_layer =945(res->target == PIPE_TEXTURE_3D ? res->depth0 : res->array_size) - 1;946}947948nvc0->framebuffer.cbufs[0] = nvc0_miptree_surface_new(pipe, res, &templ);949nvc0->framebuffer.nr_cbufs = 1;950nvc0->framebuffer.zsbuf = NULL;951nvc0->framebuffer.width = nvc0->framebuffer.cbufs[0]->width;952nvc0->framebuffer.height = nvc0->framebuffer.cbufs[0]->height;953}954955static void956nvc0_blit_set_src(struct nvc0_blitctx *ctx,957struct pipe_resource *res, unsigned level, unsigned layer,958enum pipe_format format, const uint8_t filter)959{960struct nvc0_context *nvc0 = ctx->nvc0;961struct pipe_context *pipe = &nvc0->base.pipe;962struct pipe_sampler_view templ;963uint32_t flags;964unsigned s;965enum pipe_texture_target target;966967target = nv50_blit_reinterpret_pipe_texture_target(res->target);968969templ.target = target;970templ.format = format;971templ.u.tex.first_layer = templ.u.tex.last_layer = layer;972templ.u.tex.first_level = templ.u.tex.last_level = level;973templ.swizzle_r = PIPE_SWIZZLE_X;974templ.swizzle_g = PIPE_SWIZZLE_Y;975templ.swizzle_b = PIPE_SWIZZLE_Z;976templ.swizzle_a = PIPE_SWIZZLE_W;977978if (layer == -1) {979templ.u.tex.first_layer = 0;980templ.u.tex.last_layer =981(res->target == PIPE_TEXTURE_3D ? res->depth0 : res->array_size) - 1;982}983984flags = res->last_level ? 0 : NV50_TEXVIEW_SCALED_COORDS;985flags |= NV50_TEXVIEW_ACCESS_RESOLVE;986if (filter && res->nr_samples == 8)987flags |= NV50_TEXVIEW_FILTER_MSAA8;988989nvc0->textures[4][0] = nvc0_create_texture_view(990pipe, res, &templ, flags);991nvc0->textures[4][1] = NULL;992993for (s = 0; s <= 3; ++s)994nvc0->num_textures[s] = 0;995nvc0->num_textures[4] = 1;996997templ.format = nv50_zs_to_s_format(format);998if (templ.format != format) {999nvc0->textures[4][1] = nvc0_create_texture_view(1000pipe, res, &templ, flags);1001nvc0->num_textures[4] = 2;1002}1003}10041005static void1006nvc0_blitctx_prepare_state(struct nvc0_blitctx *blit)1007{1008struct nouveau_pushbuf *push = blit->nvc0->base.pushbuf;10091010/* TODO: maybe make this a MACRO (if we need more logic) ? */10111012if (blit->nvc0->cond_query && !blit->render_condition_enable)1013IMMED_NVC0(push, NVC0_3D(COND_MODE), NVC0_3D_COND_MODE_ALWAYS);10141015/* blend state */1016BEGIN_NVC0(push, NVC0_3D(COLOR_MASK(0)), 1);1017PUSH_DATA (push, blit->color_mask);1018IMMED_NVC0(push, NVC0_3D(BLEND_ENABLE(0)), 0);1019IMMED_NVC0(push, NVC0_3D(LOGIC_OP_ENABLE), 0);10201021/* rasterizer state */1022IMMED_NVC0(push, NVC0_3D(FRAG_COLOR_CLAMP_EN), 0);1023IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_ENABLE), 0);1024BEGIN_NVC0(push, NVC0_3D(MSAA_MASK(0)), 4);1025PUSH_DATA (push, 0xffff);1026PUSH_DATA (push, 0xffff);1027PUSH_DATA (push, 0xffff);1028PUSH_DATA (push, 0xffff);1029BEGIN_NVC0(push, NVC0_3D(MACRO_POLYGON_MODE_FRONT), 1);1030PUSH_DATA (push, NVC0_3D_MACRO_POLYGON_MODE_FRONT_FILL);1031BEGIN_NVC0(push, NVC0_3D(MACRO_POLYGON_MODE_BACK), 1);1032PUSH_DATA (push, NVC0_3D_MACRO_POLYGON_MODE_BACK_FILL);1033IMMED_NVC0(push, NVC0_3D(POLYGON_SMOOTH_ENABLE), 0);1034IMMED_NVC0(push, NVC0_3D(POLYGON_OFFSET_FILL_ENABLE), 0);1035IMMED_NVC0(push, NVC0_3D(POLYGON_STIPPLE_ENABLE), 0);1036IMMED_NVC0(push, NVC0_3D(CULL_FACE_ENABLE), 0);10371038/* zsa state */1039IMMED_NVC0(push, NVC0_3D(DEPTH_TEST_ENABLE), 0);1040IMMED_NVC0(push, NVC0_3D(DEPTH_BOUNDS_EN), 0);1041IMMED_NVC0(push, NVC0_3D(STENCIL_ENABLE), 0);1042IMMED_NVC0(push, NVC0_3D(ALPHA_TEST_ENABLE), 0);10431044/* disable transform feedback */1045IMMED_NVC0(push, NVC0_3D(TFB_ENABLE), 0);1046}10471048static void1049nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx,1050const struct pipe_blit_info *info)1051{1052struct nvc0_context *nvc0 = ctx->nvc0;1053struct nvc0_blitter *blitter = nvc0->screen->blitter;1054int s;10551056ctx->saved.fb.width = nvc0->framebuffer.width;1057ctx->saved.fb.height = nvc0->framebuffer.height;1058ctx->saved.fb.samples = nvc0->framebuffer.samples;1059ctx->saved.fb.layers = nvc0->framebuffer.layers;1060ctx->saved.fb.nr_cbufs = nvc0->framebuffer.nr_cbufs;1061ctx->saved.fb.cbufs[0] = nvc0->framebuffer.cbufs[0];1062ctx->saved.fb.zsbuf = nvc0->framebuffer.zsbuf;10631064ctx->saved.rast = nvc0->rast;10651066ctx->saved.vp = nvc0->vertprog;1067ctx->saved.tcp = nvc0->tctlprog;1068ctx->saved.tep = nvc0->tevlprog;1069ctx->saved.gp = nvc0->gmtyprog;1070ctx->saved.fp = nvc0->fragprog;10711072ctx->saved.min_samples = nvc0->min_samples;1073ctx->saved.window_rect = nvc0->window_rect;10741075nvc0->rast = &ctx->rast;10761077nvc0->vertprog = ctx->vp;1078nvc0->tctlprog = NULL;1079nvc0->tevlprog = NULL;1080nvc0->gmtyprog = NULL;1081nvc0->fragprog = ctx->fp;10821083nvc0->window_rect.rects =1084MIN2(info->num_window_rectangles, NVC0_MAX_WINDOW_RECTANGLES);1085nvc0->window_rect.inclusive = info->window_rectangle_include;1086if (nvc0->window_rect.rects)1087memcpy(nvc0->window_rect.rect, info->window_rectangles,1088sizeof(struct pipe_scissor_state) * nvc0->window_rect.rects);10891090for (s = 0; s <= 4; ++s) {1091ctx->saved.num_textures[s] = nvc0->num_textures[s];1092ctx->saved.num_samplers[s] = nvc0->num_samplers[s];1093nvc0->textures_dirty[s] = (1 << nvc0->num_textures[s]) - 1;1094nvc0->samplers_dirty[s] = (1 << nvc0->num_samplers[s]) - 1;1095}1096ctx->saved.texture[0] = nvc0->textures[4][0];1097ctx->saved.texture[1] = nvc0->textures[4][1];1098ctx->saved.sampler[0] = nvc0->samplers[4][0];1099ctx->saved.sampler[1] = nvc0->samplers[4][1];11001101nvc0->samplers[4][0] = &blitter->sampler[ctx->filter];1102nvc0->samplers[4][1] = &blitter->sampler[ctx->filter];11031104for (s = 0; s <= 3; ++s)1105nvc0->num_samplers[s] = 0;1106nvc0->num_samplers[4] = 2;11071108nvc0->min_samples = 1;11091110ctx->saved.dirty_3d = nvc0->dirty_3d;11111112nvc0->textures_dirty[4] |= 3;1113nvc0->samplers_dirty[4] |= 3;11141115nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);1116nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(4, 0));1117nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(4, 1));11181119nvc0->dirty_3d = NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_MIN_SAMPLES |1120NVC0_NEW_3D_VERTPROG | NVC0_NEW_3D_FRAGPROG |1121NVC0_NEW_3D_TCTLPROG | NVC0_NEW_3D_TEVLPROG | NVC0_NEW_3D_GMTYPROG |1122NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS | NVC0_NEW_3D_WINDOW_RECTS;1123}11241125static void1126nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)1127{1128struct nvc0_context *nvc0 = blit->nvc0;1129int s;11301131pipe_surface_reference(&nvc0->framebuffer.cbufs[0], NULL);11321133nvc0->framebuffer.width = blit->saved.fb.width;1134nvc0->framebuffer.height = blit->saved.fb.height;1135nvc0->framebuffer.samples = blit->saved.fb.samples;1136nvc0->framebuffer.layers = blit->saved.fb.layers;1137nvc0->framebuffer.nr_cbufs = blit->saved.fb.nr_cbufs;1138nvc0->framebuffer.cbufs[0] = blit->saved.fb.cbufs[0];1139nvc0->framebuffer.zsbuf = blit->saved.fb.zsbuf;11401141nvc0->rast = blit->saved.rast;11421143nvc0->vertprog = blit->saved.vp;1144nvc0->tctlprog = blit->saved.tcp;1145nvc0->tevlprog = blit->saved.tep;1146nvc0->gmtyprog = blit->saved.gp;1147nvc0->fragprog = blit->saved.fp;11481149nvc0->min_samples = blit->saved.min_samples;1150nvc0->window_rect = blit->saved.window_rect;11511152pipe_sampler_view_reference(&nvc0->textures[4][0], NULL);1153pipe_sampler_view_reference(&nvc0->textures[4][1], NULL);11541155for (s = 0; s <= 4; ++s) {1156nvc0->num_textures[s] = blit->saved.num_textures[s];1157nvc0->num_samplers[s] = blit->saved.num_samplers[s];1158nvc0->textures_dirty[s] = (1 << nvc0->num_textures[s]) - 1;1159nvc0->samplers_dirty[s] = (1 << nvc0->num_samplers[s]) - 1;1160}1161nvc0->textures[4][0] = blit->saved.texture[0];1162nvc0->textures[4][1] = blit->saved.texture[1];1163nvc0->samplers[4][0] = blit->saved.sampler[0];1164nvc0->samplers[4][1] = blit->saved.sampler[1];11651166nvc0->textures_dirty[4] |= 3;1167nvc0->samplers_dirty[4] |= 3;11681169if (nvc0->cond_query && !blit->render_condition_enable)1170nvc0->base.pipe.render_condition(&nvc0->base.pipe, nvc0->cond_query,1171nvc0->cond_cond, nvc0->cond_mode);11721173nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_VTX_TMP);1174nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEXT);1175nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB);1176nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(4, 0));1177nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_TEX(4, 1));1178nouveau_scratch_done(&nvc0->base);11791180nvc0->dirty_3d = blit->saved.dirty_3d |1181(NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_SCISSOR | NVC0_NEW_3D_SAMPLE_MASK |1182NVC0_NEW_3D_RASTERIZER | NVC0_NEW_3D_ZSA | NVC0_NEW_3D_BLEND |1183NVC0_NEW_3D_VIEWPORT | NVC0_NEW_3D_WINDOW_RECTS |1184NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS |1185NVC0_NEW_3D_VERTPROG | NVC0_NEW_3D_FRAGPROG |1186NVC0_NEW_3D_TCTLPROG | NVC0_NEW_3D_TEVLPROG | NVC0_NEW_3D_GMTYPROG |1187NVC0_NEW_3D_TFB_TARGETS | NVC0_NEW_3D_VERTEX | NVC0_NEW_3D_ARRAYS);1188nvc0->scissors_dirty |= 1;1189nvc0->viewports_dirty |= 1;11901191nvc0->base.pipe.set_min_samples(&nvc0->base.pipe, blit->saved.min_samples);1192}11931194static void1195nvc0_blit_3d(struct nvc0_context *nvc0, const struct pipe_blit_info *info)1196{1197struct nvc0_screen *screen = nvc0->screen;1198struct nvc0_blitctx *blit = nvc0->blit;1199struct nouveau_pushbuf *push = nvc0->base.pushbuf;1200struct pipe_resource *src = info->src.resource;1201struct pipe_resource *dst = info->dst.resource;1202struct nouveau_bo *vtxbuf_bo;1203uint32_t stride, length, *vbuf;1204uint64_t vtxbuf;1205int32_t minx, maxx, miny, maxy;1206int32_t i, n;1207float x0, x1, y0, y1, z;1208float dz;1209float x_range, y_range;12101211blit->mode = nv50_blit_select_mode(info);1212blit->color_mask = nv50_blit_derive_color_mask(info);1213blit->filter = nv50_blit_get_filter(info);1214blit->render_condition_enable = info->render_condition_enable;12151216nvc0_blit_select_vp(blit);1217nvc0_blit_select_fp(blit, info);1218nvc0_blitctx_pre_blit(blit, info);12191220nvc0_blit_set_dst(blit, dst, info->dst.level, -1, info->dst.format);1221nvc0_blit_set_src(blit, src, info->src.level, -1, info->src.format,1222blit->filter);12231224nvc0_blitctx_prepare_state(blit);12251226nvc0_state_validate_3d(nvc0, ~0);12271228x_range = (float)info->src.box.width / (float)info->dst.box.width;1229y_range = (float)info->src.box.height / (float)info->dst.box.height;12301231x0 = (float)info->src.box.x - x_range * (float)info->dst.box.x;1232y0 = (float)info->src.box.y - y_range * (float)info->dst.box.y;12331234x1 = x0 + 32768.0f * x_range;1235y1 = y0 + 32768.0f * y_range;12361237x0 *= (float)(1 << nv50_miptree(src)->ms_x);1238x1 *= (float)(1 << nv50_miptree(src)->ms_x);1239y0 *= (float)(1 << nv50_miptree(src)->ms_y);1240y1 *= (float)(1 << nv50_miptree(src)->ms_y);12411242dz = (float)info->src.box.depth / (float)info->dst.box.depth;1243z = (float)info->src.box.z;1244if (nv50_miptree(src)->layout_3d)1245z += 0.5f * dz;12461247if (src->last_level > 0) {1248/* If there are mip maps, GPU always assumes normalized coordinates. */1249const unsigned l = info->src.level;1250const float fh = u_minify(src->width0 << nv50_miptree(src)->ms_x, l);1251const float fv = u_minify(src->height0 << nv50_miptree(src)->ms_y, l);1252x0 /= fh;1253x1 /= fh;1254y0 /= fv;1255y1 /= fv;1256if (nv50_miptree(src)->layout_3d) {1257z /= u_minify(src->depth0, l);1258dz /= u_minify(src->depth0, l);1259}1260}12611262bool serialize = false;1263struct nv50_miptree *mt = nv50_miptree(dst);1264if (screen->eng3d->oclass >= TU102_3D_CLASS) {1265IMMED_NVC0(push, SUBC_3D(TU102_3D_SET_COLOR_RENDER_TO_ZETA_SURFACE),1266util_format_is_depth_or_stencil(info->dst.format));1267} else {1268/* When flipping a surface from zeta <-> color "mode", we have to wait for1269* the GPU to flush its current draws.1270*/1271serialize = util_format_is_depth_or_stencil(info->dst.format);1272if (serialize && mt->base.status & NOUVEAU_BUFFER_STATUS_GPU_WRITING) {1273IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);1274}1275}12761277IMMED_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 0);1278IMMED_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 0x2 |1279NVC0_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_RANGE_0_1);1280BEGIN_NVC0(push, NVC0_3D(VIEWPORT_HORIZ(0)), 2);1281PUSH_DATA (push, nvc0->framebuffer.width << 16);1282PUSH_DATA (push, nvc0->framebuffer.height << 16);12831284/* Draw a large triangle in screen coordinates covering the whole1285* render target, with scissors defining the destination region.1286* The vertex is supplied with non-normalized texture coordinates1287* arranged in a way to yield the desired offset and scale.1288*1289* Note that while the source texture is presented to the sampler as1290* non-MSAA (even if it is), the destination texture is treated as MSAA for1291* rendering. This means that1292* - destination coordinates shouldn't be scaled1293* - without per-sample rendering, the target will be a solid-fill for all1294* of the samples1295*1296* The last point implies that this process is very bad for 1:1 blits, as1297* well as scaled blits between MSAA surfaces. This works fine for1298* upscaling and downscaling though. The 1:1 blits should ideally be1299* handled by the 2d engine, which can do it perfectly.1300*/13011302minx = info->dst.box.x;1303maxx = info->dst.box.x + info->dst.box.width;1304miny = info->dst.box.y;1305maxy = info->dst.box.y + info->dst.box.height;1306if (info->scissor_enable) {1307minx = MAX2(minx, info->scissor.minx);1308maxx = MIN2(maxx, info->scissor.maxx);1309miny = MAX2(miny, info->scissor.miny);1310maxy = MIN2(maxy, info->scissor.maxy);1311}1312BEGIN_NVC0(push, NVC0_3D(SCISSOR_HORIZ(0)), 2);1313PUSH_DATA (push, (maxx << 16) | minx);1314PUSH_DATA (push, (maxy << 16) | miny);13151316stride = (3 + 2) * 4;1317length = stride * 3 * info->dst.box.depth;13181319vbuf = nouveau_scratch_get(&nvc0->base, length, &vtxbuf, &vtxbuf_bo);1320if (!vbuf) {1321assert(vbuf);1322return;1323}13241325BCTX_REFN_bo(nvc0->bufctx_3d, 3D_VTX_TMP,1326NOUVEAU_BO_GART | NOUVEAU_BO_RD, vtxbuf_bo);1327BCTX_REFN_bo(nvc0->bufctx_3d, 3D_TEXT,1328NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD, screen->text);1329nouveau_pushbuf_validate(push);13301331BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_FETCH(0)), 4);1332PUSH_DATA (push, NVC0_3D_VERTEX_ARRAY_FETCH_ENABLE | stride <<1333NVC0_3D_VERTEX_ARRAY_FETCH_STRIDE__SHIFT);1334PUSH_DATAh(push, vtxbuf);1335PUSH_DATA (push, vtxbuf);1336PUSH_DATA (push, 0);1337if (screen->eng3d->oclass < TU102_3D_CLASS)1338BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_LIMIT_HIGH(0)), 2);1339else1340BEGIN_NVC0(push, SUBC_3D(TU102_3D_VERTEX_ARRAY_LIMIT_HIGH(0)), 2);1341PUSH_DATAh(push, vtxbuf + length - 1);1342PUSH_DATA (push, vtxbuf + length - 1);13431344n = MAX2(2, nvc0->state.num_vtxelts);13451346BEGIN_NVC0(push, NVC0_3D(VERTEX_ATTRIB_FORMAT(0)), n);1347PUSH_DATA (push, NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT |1348NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32_32 | 0x00 <<1349NVC0_3D_VERTEX_ATTRIB_FORMAT_OFFSET__SHIFT);1350PUSH_DATA (push, NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT |1351NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32_32_32 | 0x08 <<1352NVC0_3D_VERTEX_ATTRIB_FORMAT_OFFSET__SHIFT);1353for (i = 2; i < n; i++) {1354PUSH_DATA(push, NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT |1355NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32 |1356NVC0_3D_VERTEX_ATTRIB_FORMAT_CONST);1357}1358for (i = 1; i < n; ++i)1359IMMED_NVC0(push, NVC0_3D(VERTEX_ARRAY_FETCH(i)), 0);1360if (nvc0->state.instance_elts) {1361nvc0->state.instance_elts = 0;1362BEGIN_NVC0(push, NVC0_3D(MACRO_VERTEX_ARRAY_PER_INSTANCE), 2);1363PUSH_DATA (push, n);1364PUSH_DATA (push, 0);1365}1366nvc0->state.num_vtxelts = 2;13671368if (nvc0->state.prim_restart) {1369IMMED_NVC0(push, NVC0_3D(PRIM_RESTART_ENABLE), 0);1370nvc0->state.prim_restart = 0;1371}13721373if (nvc0->state.index_bias) {1374IMMED_NVC0(push, NVC0_3D(VB_ELEMENT_BASE), 0);1375IMMED_NVC0(push, NVC0_3D(VERTEX_ID_BASE), 0);1376nvc0->state.index_bias = 0;1377}13781379for (i = 0; i < info->dst.box.depth; ++i, z += dz) {1380if (info->dst.box.z + i) {1381BEGIN_NVC0(push, NVC0_3D(LAYER), 1);1382PUSH_DATA (push, info->dst.box.z + i);1383}13841385*(vbuf++) = fui(0.0f);1386*(vbuf++) = fui(0.0f);1387*(vbuf++) = fui(x0);1388*(vbuf++) = fui(y0);1389*(vbuf++) = fui(z);13901391*(vbuf++) = fui(32768.0f);1392*(vbuf++) = fui(0.0f);1393*(vbuf++) = fui(x1);1394*(vbuf++) = fui(y0);1395*(vbuf++) = fui(z);13961397*(vbuf++) = fui(0.0f);1398*(vbuf++) = fui(32768.0f);1399*(vbuf++) = fui(x0);1400*(vbuf++) = fui(y1);1401*(vbuf++) = fui(z);14021403IMMED_NVC0(push, NVC0_3D(VERTEX_BEGIN_GL),1404NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_TRIANGLES);1405BEGIN_NVC0(push, NVC0_3D(VERTEX_BUFFER_FIRST), 2);1406PUSH_DATA (push, i * 3);1407PUSH_DATA (push, 3);1408IMMED_NVC0(push, NVC0_3D(VERTEX_END_GL), 0);1409}1410if (info->dst.box.z + info->dst.box.depth - 1)1411IMMED_NVC0(push, NVC0_3D(LAYER), 0);14121413nvc0_blitctx_post_blit(blit);14141415/* restore viewport transform */1416IMMED_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1);1417if (screen->eng3d->oclass >= TU102_3D_CLASS)1418IMMED_NVC0(push, SUBC_3D(TU102_3D_SET_COLOR_RENDER_TO_ZETA_SURFACE), 0);1419else if (serialize)1420/* mark the surface as reading, which will force a serialize next time1421* it's used for writing.1422*/1423mt->base.status |= NOUVEAU_BUFFER_STATUS_GPU_READING;1424}14251426static void1427nvc0_blit_eng2d(struct nvc0_context *nvc0, const struct pipe_blit_info *info)1428{1429struct nouveau_pushbuf *push = nvc0->base.pushbuf;1430struct nv50_miptree *dst = nv50_miptree(info->dst.resource);1431struct nv50_miptree *src = nv50_miptree(info->src.resource);1432const int32_t srcx_adj = info->src.box.width < 0 ? -1 : 0;1433const int32_t srcy_adj = info->src.box.height < 0 ? -1 : 0;1434const int dz = info->dst.box.z;1435const int sz = info->src.box.z;1436uint32_t dstw, dsth;1437int32_t dstx, dsty;1438int64_t srcx, srcy;1439int64_t du_dx, dv_dy;1440int i;1441uint32_t mode;1442uint32_t mask = nv50_blit_eng2d_get_mask(info);1443bool b;14441445mode = nv50_blit_get_filter(info) ?1446NV50_2D_BLIT_CONTROL_FILTER_BILINEAR :1447NV50_2D_BLIT_CONTROL_FILTER_POINT_SAMPLE;1448mode |= (src->base.base.nr_samples > dst->base.base.nr_samples) ?1449NV50_2D_BLIT_CONTROL_ORIGIN_CORNER : NV50_2D_BLIT_CONTROL_ORIGIN_CENTER;14501451du_dx = ((int64_t)info->src.box.width << 32) / info->dst.box.width;1452dv_dy = ((int64_t)info->src.box.height << 32) / info->dst.box.height;14531454b = info->dst.format == info->src.format;1455nvc0_2d_texture_set(push, 1, dst, info->dst.level, dz, info->dst.format, b);1456nvc0_2d_texture_set(push, 0, src, info->src.level, sz, info->src.format, b);14571458if (info->scissor_enable) {1459BEGIN_NVC0(push, NVC0_2D(CLIP_X), 5);1460PUSH_DATA (push, info->scissor.minx << dst->ms_x);1461PUSH_DATA (push, info->scissor.miny << dst->ms_y);1462PUSH_DATA (push, (info->scissor.maxx - info->scissor.minx) << dst->ms_x);1463PUSH_DATA (push, (info->scissor.maxy - info->scissor.miny) << dst->ms_y);1464PUSH_DATA (push, 1); /* enable */1465}14661467if (nvc0->cond_query && info->render_condition_enable)1468IMMED_NVC0(push, NVC0_2D(COND_MODE), nvc0->cond_condmode);14691470if (mask != 0xffffffff) {1471IMMED_NVC0(push, NVC0_2D(ROP), 0xca); /* DPSDxax */1472IMMED_NVC0(push, NVC0_2D(PATTERN_COLOR_FORMAT),1473NV50_2D_PATTERN_COLOR_FORMAT_A8R8G8B8);1474BEGIN_NVC0(push, NVC0_2D(PATTERN_BITMAP_COLOR(0)), 4);1475PUSH_DATA (push, 0x00000000);1476PUSH_DATA (push, mask);1477PUSH_DATA (push, 0xffffffff);1478PUSH_DATA (push, 0xffffffff);1479IMMED_NVC0(push, NVC0_2D(OPERATION), NV50_2D_OPERATION_ROP);1480} else1481if (info->src.format != info->dst.format) {1482if (info->src.format == PIPE_FORMAT_R8_UNORM ||1483info->src.format == PIPE_FORMAT_R8_SNORM ||1484info->src.format == PIPE_FORMAT_R16_UNORM ||1485info->src.format == PIPE_FORMAT_R16_SNORM ||1486info->src.format == PIPE_FORMAT_R16_FLOAT ||1487info->src.format == PIPE_FORMAT_R32_FLOAT) {1488mask = 0xffff0000; /* also makes condition for OPERATION reset true */1489BEGIN_NVC0(push, NVC0_2D(BETA4), 2);1490PUSH_DATA (push, mask);1491PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY_PREMULT);1492} else1493if (info->src.format == PIPE_FORMAT_A8_UNORM) {1494mask = 0xff000000;1495BEGIN_NVC0(push, NVC0_2D(BETA4), 2);1496PUSH_DATA (push, mask);1497PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY_PREMULT);1498}1499}15001501if (src->ms_x > dst->ms_x || src->ms_y > dst->ms_y) {1502/* ms_x is always >= ms_y */1503du_dx <<= src->ms_x - dst->ms_x;1504dv_dy <<= src->ms_y - dst->ms_y;1505} else {1506du_dx >>= dst->ms_x - src->ms_x;1507dv_dy >>= dst->ms_y - src->ms_y;1508}15091510srcx = (int64_t)(info->src.box.x + srcx_adj) << (src->ms_x + 32);1511srcy = (int64_t)(info->src.box.y + srcy_adj) << (src->ms_y + 32);15121513if (src->base.base.nr_samples > dst->base.base.nr_samples) {1514/* center src coorinates for proper MS resolve filtering */1515srcx += (int64_t)1 << (src->ms_x + 31);1516srcy += (int64_t)1 << (src->ms_y + 31);1517}15181519dstx = info->dst.box.x << dst->ms_x;1520dsty = info->dst.box.y << dst->ms_y;15211522dstw = info->dst.box.width << dst->ms_x;1523dsth = info->dst.box.height << dst->ms_y;15241525if (dstx < 0) {1526dstw += dstx;1527srcx -= du_dx * dstx;1528dstx = 0;1529}1530if (dsty < 0) {1531dsth += dsty;1532srcy -= dv_dy * dsty;1533dsty = 0;1534}15351536IMMED_NVC0(push, NVC0_2D(BLIT_CONTROL), mode);1537BEGIN_NVC0(push, NVC0_2D(BLIT_DST_X), 4);1538PUSH_DATA (push, dstx);1539PUSH_DATA (push, dsty);1540PUSH_DATA (push, dstw);1541PUSH_DATA (push, dsth);1542BEGIN_NVC0(push, NVC0_2D(BLIT_DU_DX_FRACT), 4);1543PUSH_DATA (push, du_dx);1544PUSH_DATA (push, du_dx >> 32);1545PUSH_DATA (push, dv_dy);1546PUSH_DATA (push, dv_dy >> 32);15471548BCTX_REFN(nvc0->bufctx, 2D, &dst->base, WR);1549BCTX_REFN(nvc0->bufctx, 2D, &src->base, RD);1550nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx);1551if (nouveau_pushbuf_validate(nvc0->base.pushbuf))1552return;15531554for (i = 0; i < info->dst.box.depth; ++i) {1555if (i > 0) {1556/* no scaling in z-direction possible for eng2d blits */1557if (dst->layout_3d) {1558BEGIN_NVC0(push, NVC0_2D(DST_LAYER), 1);1559PUSH_DATA (push, info->dst.box.z + i);1560} else {1561const unsigned z = info->dst.box.z + i;1562const uint64_t address = dst->base.address +1563dst->level[info->dst.level].offset +1564z * dst->layer_stride;1565BEGIN_NVC0(push, NVC0_2D(DST_ADDRESS_HIGH), 2);1566PUSH_DATAh(push, address);1567PUSH_DATA (push, address);1568}1569if (src->layout_3d) {1570/* not possible because of depth tiling */1571assert(0);1572} else {1573const unsigned z = info->src.box.z + i;1574const uint64_t address = src->base.address +1575src->level[info->src.level].offset +1576z * src->layer_stride;1577BEGIN_NVC0(push, NVC0_2D(SRC_ADDRESS_HIGH), 2);1578PUSH_DATAh(push, address);1579PUSH_DATA (push, address);1580}1581BEGIN_NVC0(push, NVC0_2D(BLIT_SRC_Y_INT), 1); /* trigger */1582PUSH_DATA (push, srcy >> 32);1583} else {1584BEGIN_NVC0(push, NVC0_2D(BLIT_SRC_X_FRACT), 4);1585PUSH_DATA (push, srcx);1586PUSH_DATA (push, srcx >> 32);1587PUSH_DATA (push, srcy);1588PUSH_DATA (push, srcy >> 32);1589}1590}1591nvc0_resource_validate(&dst->base, NOUVEAU_BO_WR);1592nvc0_resource_validate(&src->base, NOUVEAU_BO_RD);15931594nouveau_bufctx_reset(nvc0->bufctx, NVC0_BIND_2D);15951596if (info->scissor_enable)1597IMMED_NVC0(push, NVC0_2D(CLIP_ENABLE), 0);1598if (mask != 0xffffffff)1599IMMED_NVC0(push, NVC0_2D(OPERATION), NV50_2D_OPERATION_SRCCOPY);1600if (nvc0->cond_query && info->render_condition_enable)1601IMMED_NVC0(push, NVC0_2D(COND_MODE), NV50_2D_COND_MODE_ALWAYS);1602}16031604static void1605nvc0_blit(struct pipe_context *pipe, const struct pipe_blit_info *info)1606{1607struct nvc0_context *nvc0 = nvc0_context(pipe);1608struct nouveau_pushbuf *push = nvc0->base.pushbuf;1609bool eng3d = false;16101611if (info->src.box.width == 0 || info->src.box.height == 0 ||1612info->dst.box.width == 0 || info->dst.box.height == 0) {1613pipe_debug_message(&nvc0->base.debug, ERROR,1614"Blit with zero-size src or dst box");1615return;1616}16171618if (util_format_is_depth_or_stencil(info->dst.resource->format)) {1619if (!(info->mask & PIPE_MASK_ZS))1620return;1621if (info->dst.resource->format == PIPE_FORMAT_Z32_FLOAT ||1622info->dst.resource->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)1623eng3d = true;1624if (info->filter != PIPE_TEX_FILTER_NEAREST)1625eng3d = true;1626} else {1627if (!(info->mask & PIPE_MASK_RGBA))1628return;1629if (info->mask != PIPE_MASK_RGBA)1630eng3d = true;1631}16321633if (nv50_miptree(info->src.resource)->layout_3d) {1634eng3d = true;1635} else1636if (info->src.box.depth != info->dst.box.depth) {1637eng3d = true;1638debug_printf("blit: cannot filter array or cube textures in z direction");1639}16401641if (!eng3d && info->dst.format != info->src.format) {1642if (!nv50_2d_dst_format_faithful(info->dst.format)) {1643eng3d = true;1644} else1645if (!nv50_2d_src_format_faithful(info->src.format)) {1646if (!util_format_is_luminance(info->src.format)) {1647if (!nv50_2d_dst_format_ops_supported(info->dst.format))1648eng3d = true;1649else1650if (util_format_is_intensity(info->src.format))1651eng3d = info->src.format != PIPE_FORMAT_I8_UNORM;1652else1653if (util_format_is_alpha(info->src.format))1654eng3d = info->src.format != PIPE_FORMAT_A8_UNORM;1655else1656if (util_format_is_srgb(info->dst.format) &&1657util_format_get_nr_components(info->src.format) == 1)1658eng3d = true;1659else1660eng3d = !nv50_2d_format_supported(info->src.format);1661}1662} else1663if (util_format_is_luminance_alpha(info->src.format))1664eng3d = true;1665}16661667if (info->src.resource->nr_samples == 8 &&1668info->dst.resource->nr_samples <= 1)1669eng3d = true;1670#if 01671/* FIXME: can't make this work with eng2d anymore, at least not on nv50 */1672if (info->src.resource->nr_samples > 1 ||1673info->dst.resource->nr_samples > 1)1674eng3d = true;1675#endif1676/* FIXME: find correct src coordinates adjustments */1677if ((info->src.box.width != info->dst.box.width &&1678info->src.box.width != -info->dst.box.width) ||1679(info->src.box.height != info->dst.box.height &&1680info->src.box.height != -info->dst.box.height))1681eng3d = true;16821683if (info->num_window_rectangles > 0 || info->window_rectangle_include)1684eng3d = true;16851686if (nvc0->screen->num_occlusion_queries_active)1687IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 0);16881689if (!eng3d)1690nvc0_blit_eng2d(nvc0, info);1691else1692nvc0_blit_3d(nvc0, info);16931694if (nvc0->screen->num_occlusion_queries_active)1695IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 1);16961697NOUVEAU_DRV_STAT(&nvc0->screen->base, tex_blit_count, 1);1698}16991700static void1701nvc0_flush_resource(struct pipe_context *ctx,1702struct pipe_resource *resource)1703{1704}17051706bool1707nvc0_blitter_create(struct nvc0_screen *screen)1708{1709screen->blitter = CALLOC_STRUCT(nvc0_blitter);1710if (!screen->blitter) {1711NOUVEAU_ERR("failed to allocate blitter struct\n");1712return false;1713}1714screen->blitter->screen = screen;17151716(void) mtx_init(&screen->blitter->mutex, mtx_plain);17171718nvc0_blitter_make_sampler(screen->blitter);17191720return true;1721}17221723void1724nvc0_blitter_destroy(struct nvc0_screen *screen)1725{1726struct nvc0_blitter *blitter = screen->blitter;1727unsigned i, m;17281729for (i = 0; i < NV50_BLIT_MAX_TEXTURE_TYPES; ++i) {1730for (m = 0; m < NV50_BLIT_MODES; ++m) {1731struct nvc0_program *prog = blitter->fp[i][m];1732if (prog) {1733nvc0_program_destroy(NULL, prog);1734FREE((void *)prog->pipe.tokens);1735FREE(prog);1736}1737}1738}17391740mtx_destroy(&blitter->mutex);1741FREE(blitter);1742}17431744bool1745nvc0_blitctx_create(struct nvc0_context *nvc0)1746{1747nvc0->blit = CALLOC_STRUCT(nvc0_blitctx);1748if (!nvc0->blit) {1749NOUVEAU_ERR("failed to allocate blit context\n");1750return false;1751}17521753nvc0->blit->nvc0 = nvc0;17541755nvc0->blit->rast.pipe.half_pixel_center = 1;17561757return true;1758}17591760void1761nvc0_blitctx_destroy(struct nvc0_context *nvc0)1762{1763FREE(nvc0->blit);1764}17651766void1767nvc0_init_surface_functions(struct nvc0_context *nvc0)1768{1769struct pipe_context *pipe = &nvc0->base.pipe;17701771pipe->resource_copy_region = nvc0_resource_copy_region;1772pipe->blit = nvc0_blit;1773pipe->flush_resource = nvc0_flush_resource;1774pipe->clear_render_target = nvc0_clear_render_target;1775pipe->clear_depth_stencil = nvc0_clear_depth_stencil;1776pipe->clear_texture = nv50_clear_texture;1777pipe->clear_buffer = nvc0_clear_buffer;1778if (nvc0->screen->base.class_3d >= GM200_3D_CLASS)1779pipe->evaluate_depth_buffer = gm200_evaluate_depth_buffer;1780}178117821783