1bf215546Sopenharmony_ci 2bf215546Sopenharmony_ci#ifndef __NV50_BLIT_H__ 3bf215546Sopenharmony_ci#define __NV50_BLIT_H__ 4bf215546Sopenharmony_ci 5bf215546Sopenharmony_ci#include "util/u_inlines.h" 6bf215546Sopenharmony_ci#include "util/format/u_format.h" 7bf215546Sopenharmony_ci 8bf215546Sopenharmony_civoid * 9bf215546Sopenharmony_cinv50_blitter_make_fp(struct pipe_context *, 10bf215546Sopenharmony_ci unsigned mode, 11bf215546Sopenharmony_ci enum pipe_texture_target); 12bf215546Sopenharmony_ci 13bf215546Sopenharmony_ciunsigned 14bf215546Sopenharmony_cinv50_blit_select_mode(const struct pipe_blit_info *); 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_ci/* Converted to a pipe->blit. */ 17bf215546Sopenharmony_civoid 18bf215546Sopenharmony_cinv50_resource_resolve(struct pipe_context *, const struct pipe_resolve_info *); 19bf215546Sopenharmony_ci 20bf215546Sopenharmony_ci#define NV50_BLIT_MODE_PASS 0 /* pass through TEX $t0/$s0 output */ 21bf215546Sopenharmony_ci#define NV50_BLIT_MODE_Z24S8 1 /* encode ZS values for RGBA unorm8 */ 22bf215546Sopenharmony_ci#define NV50_BLIT_MODE_S8Z24 2 23bf215546Sopenharmony_ci#define NV50_BLIT_MODE_X24S8 3 24bf215546Sopenharmony_ci#define NV50_BLIT_MODE_S8X24 4 25bf215546Sopenharmony_ci#define NV50_BLIT_MODE_Z24X8 5 26bf215546Sopenharmony_ci#define NV50_BLIT_MODE_X8Z24 6 27bf215546Sopenharmony_ci#define NV50_BLIT_MODE_ZS 7 /* put $t0/$s0 into R, $t1/$s1 into G */ 28bf215546Sopenharmony_ci#define NV50_BLIT_MODE_XS 8 /* put $t1/$s1 into G */ 29bf215546Sopenharmony_ci#define NV50_BLIT_MODE_INT_CLAMP 9 /* unsigned to signed integer conversion */ 30bf215546Sopenharmony_ci#define NV50_BLIT_MODES 10 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci/* CUBE and RECT textures are reinterpreted as 2D(_ARRAY) */ 33bf215546Sopenharmony_ci#define NV50_BLIT_TEXTURE_BUFFER 0 34bf215546Sopenharmony_ci#define NV50_BLIT_TEXTURE_1D 1 35bf215546Sopenharmony_ci#define NV50_BLIT_TEXTURE_2D 2 36bf215546Sopenharmony_ci#define NV50_BLIT_TEXTURE_3D 3 37bf215546Sopenharmony_ci#define NV50_BLIT_TEXTURE_1D_ARRAY 4 38bf215546Sopenharmony_ci#define NV50_BLIT_TEXTURE_2D_ARRAY 5 39bf215546Sopenharmony_ci#define NV50_BLIT_MAX_TEXTURE_TYPES 6 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cistatic inline unsigned 42bf215546Sopenharmony_cinv50_blit_texture_type(enum pipe_texture_target target) 43bf215546Sopenharmony_ci{ 44bf215546Sopenharmony_ci switch (target) { 45bf215546Sopenharmony_ci case PIPE_TEXTURE_1D: return NV50_BLIT_TEXTURE_1D; 46bf215546Sopenharmony_ci case PIPE_TEXTURE_2D: return NV50_BLIT_TEXTURE_2D; 47bf215546Sopenharmony_ci case PIPE_TEXTURE_3D: return NV50_BLIT_TEXTURE_3D; 48bf215546Sopenharmony_ci case PIPE_TEXTURE_1D_ARRAY: return NV50_BLIT_TEXTURE_1D_ARRAY; 49bf215546Sopenharmony_ci case PIPE_TEXTURE_2D_ARRAY: return NV50_BLIT_TEXTURE_2D_ARRAY; 50bf215546Sopenharmony_ci default: 51bf215546Sopenharmony_ci assert(target == PIPE_BUFFER); 52bf215546Sopenharmony_ci return NV50_BLIT_TEXTURE_BUFFER; 53bf215546Sopenharmony_ci } 54bf215546Sopenharmony_ci} 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_cistatic inline unsigned 57bf215546Sopenharmony_cinv50_blit_get_tgsi_texture_target(enum pipe_texture_target target) 58bf215546Sopenharmony_ci{ 59bf215546Sopenharmony_ci switch (target) { 60bf215546Sopenharmony_ci case PIPE_TEXTURE_1D: return TGSI_TEXTURE_1D; 61bf215546Sopenharmony_ci case PIPE_TEXTURE_2D: return TGSI_TEXTURE_2D; 62bf215546Sopenharmony_ci case PIPE_TEXTURE_3D: return TGSI_TEXTURE_3D; 63bf215546Sopenharmony_ci case PIPE_TEXTURE_1D_ARRAY: return TGSI_TEXTURE_1D_ARRAY; 64bf215546Sopenharmony_ci case PIPE_TEXTURE_2D_ARRAY: return TGSI_TEXTURE_2D_ARRAY; 65bf215546Sopenharmony_ci default: 66bf215546Sopenharmony_ci assert(target == PIPE_BUFFER); 67bf215546Sopenharmony_ci return TGSI_TEXTURE_BUFFER; 68bf215546Sopenharmony_ci } 69bf215546Sopenharmony_ci} 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_cistatic inline enum pipe_texture_target 72bf215546Sopenharmony_cinv50_blit_reinterpret_pipe_texture_target(enum pipe_texture_target target) 73bf215546Sopenharmony_ci{ 74bf215546Sopenharmony_ci switch (target) { 75bf215546Sopenharmony_ci case PIPE_TEXTURE_CUBE: 76bf215546Sopenharmony_ci case PIPE_TEXTURE_CUBE_ARRAY: 77bf215546Sopenharmony_ci return PIPE_TEXTURE_2D_ARRAY; 78bf215546Sopenharmony_ci case PIPE_TEXTURE_RECT: 79bf215546Sopenharmony_ci return PIPE_TEXTURE_2D; 80bf215546Sopenharmony_ci default: 81bf215546Sopenharmony_ci return target; 82bf215546Sopenharmony_ci } 83bf215546Sopenharmony_ci} 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_cistatic inline unsigned 86bf215546Sopenharmony_cinv50_blit_get_filter(const struct pipe_blit_info *info) 87bf215546Sopenharmony_ci{ 88bf215546Sopenharmony_ci if (info->dst.resource->nr_samples < info->src.resource->nr_samples) 89bf215546Sopenharmony_ci return (util_format_is_depth_or_stencil(info->src.format) || 90bf215546Sopenharmony_ci util_format_is_pure_integer(info->src.format)) ? 0 : 1; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci if (info->filter != PIPE_TEX_FILTER_LINEAR) 93bf215546Sopenharmony_ci return 0; 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci if ((info->dst.box.width == info->src.box.width || 96bf215546Sopenharmony_ci info->dst.box.width == -info->src.box.width) && 97bf215546Sopenharmony_ci (info->dst.box.height == info->src.box.height || 98bf215546Sopenharmony_ci info->dst.box.height == -info->src.box.height)) 99bf215546Sopenharmony_ci return 0; 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci return 1; 102bf215546Sopenharmony_ci} 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci/* Since shaders cannot export stencil, we cannot copy stencil values when 105bf215546Sopenharmony_ci * rendering to ZETA, so we attach the ZS surface to a colour render target. 106bf215546Sopenharmony_ci */ 107bf215546Sopenharmony_cistatic inline enum pipe_format 108bf215546Sopenharmony_cinv50_blit_zeta_to_colour_format(enum pipe_format format) 109bf215546Sopenharmony_ci{ 110bf215546Sopenharmony_ci switch (format) { 111bf215546Sopenharmony_ci case PIPE_FORMAT_Z16_UNORM: 112bf215546Sopenharmony_ci return PIPE_FORMAT_R16_UNORM; 113bf215546Sopenharmony_ci case PIPE_FORMAT_Z24_UNORM_S8_UINT: 114bf215546Sopenharmony_ci case PIPE_FORMAT_S8_UINT_Z24_UNORM: 115bf215546Sopenharmony_ci case PIPE_FORMAT_Z24X8_UNORM: 116bf215546Sopenharmony_ci case PIPE_FORMAT_X8Z24_UNORM: 117bf215546Sopenharmony_ci case PIPE_FORMAT_X24S8_UINT: 118bf215546Sopenharmony_ci case PIPE_FORMAT_S8X24_UINT: 119bf215546Sopenharmony_ci return PIPE_FORMAT_R8G8B8A8_UNORM; 120bf215546Sopenharmony_ci case PIPE_FORMAT_Z32_FLOAT: 121bf215546Sopenharmony_ci return PIPE_FORMAT_R32_FLOAT; 122bf215546Sopenharmony_ci case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: 123bf215546Sopenharmony_ci case PIPE_FORMAT_X32_S8X24_UINT: 124bf215546Sopenharmony_ci return PIPE_FORMAT_R32G32_FLOAT; 125bf215546Sopenharmony_ci default: 126bf215546Sopenharmony_ci assert(0); 127bf215546Sopenharmony_ci return PIPE_FORMAT_NONE; 128bf215546Sopenharmony_ci } 129bf215546Sopenharmony_ci} 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_cistatic inline uint16_t 133bf215546Sopenharmony_cinv50_blit_derive_color_mask(const struct pipe_blit_info *info) 134bf215546Sopenharmony_ci{ 135bf215546Sopenharmony_ci const unsigned mask = info->mask; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci uint16_t color_mask = 0; 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci switch (info->dst.format) { 140bf215546Sopenharmony_ci case PIPE_FORMAT_Z24X8_UNORM: 141bf215546Sopenharmony_ci case PIPE_FORMAT_X24S8_UINT: 142bf215546Sopenharmony_ci case PIPE_FORMAT_Z24_UNORM_S8_UINT: 143bf215546Sopenharmony_ci if (mask & PIPE_MASK_S) 144bf215546Sopenharmony_ci color_mask |= 0x1000; 145bf215546Sopenharmony_ci if (mask & PIPE_MASK_Z) 146bf215546Sopenharmony_ci color_mask |= 0x0111; 147bf215546Sopenharmony_ci break; 148bf215546Sopenharmony_ci case PIPE_FORMAT_X8Z24_UNORM: 149bf215546Sopenharmony_ci case PIPE_FORMAT_S8X24_UINT: 150bf215546Sopenharmony_ci case PIPE_FORMAT_S8_UINT_Z24_UNORM: 151bf215546Sopenharmony_ci if (mask & PIPE_MASK_S) 152bf215546Sopenharmony_ci color_mask |= 0x0001; 153bf215546Sopenharmony_ci if (mask & PIPE_MASK_Z) 154bf215546Sopenharmony_ci color_mask |= 0x1110; 155bf215546Sopenharmony_ci break; 156bf215546Sopenharmony_ci default: 157bf215546Sopenharmony_ci if (mask & (PIPE_MASK_R | PIPE_MASK_Z)) color_mask |= 0x0001; 158bf215546Sopenharmony_ci if (mask & (PIPE_MASK_G | PIPE_MASK_S)) color_mask |= 0x0010; 159bf215546Sopenharmony_ci if (mask & PIPE_MASK_B) color_mask |= 0x0100; 160bf215546Sopenharmony_ci if (mask & PIPE_MASK_A) color_mask |= 0x1000; 161bf215546Sopenharmony_ci break; 162bf215546Sopenharmony_ci } 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci return color_mask; 165bf215546Sopenharmony_ci} 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_cistatic inline uint32_t 168bf215546Sopenharmony_cinv50_blit_eng2d_get_mask(const struct pipe_blit_info *info) 169bf215546Sopenharmony_ci{ 170bf215546Sopenharmony_ci uint32_t mask = 0; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci switch (info->dst.format) { 173bf215546Sopenharmony_ci case PIPE_FORMAT_Z24X8_UNORM: 174bf215546Sopenharmony_ci case PIPE_FORMAT_X24S8_UINT: 175bf215546Sopenharmony_ci case PIPE_FORMAT_Z24_UNORM_S8_UINT: 176bf215546Sopenharmony_ci if (info->mask & PIPE_MASK_Z) mask |= 0x00ffffff; 177bf215546Sopenharmony_ci if (info->mask & PIPE_MASK_S) mask |= 0xff000000; 178bf215546Sopenharmony_ci break; 179bf215546Sopenharmony_ci case PIPE_FORMAT_X8Z24_UNORM: 180bf215546Sopenharmony_ci case PIPE_FORMAT_S8X24_UINT: 181bf215546Sopenharmony_ci case PIPE_FORMAT_S8_UINT_Z24_UNORM: 182bf215546Sopenharmony_ci if (info->mask & PIPE_MASK_Z) mask |= 0xffffff00; 183bf215546Sopenharmony_ci if (info->mask & PIPE_MASK_S) mask |= 0x000000ff; 184bf215546Sopenharmony_ci break; 185bf215546Sopenharmony_ci default: 186bf215546Sopenharmony_ci mask = 0xffffffff; 187bf215546Sopenharmony_ci break; 188bf215546Sopenharmony_ci } 189bf215546Sopenharmony_ci return mask; 190bf215546Sopenharmony_ci} 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_ci#if NOUVEAU_DRIVER == 0xc0 193bf215546Sopenharmony_ci# define nv50_format_table nvc0_format_table 194bf215546Sopenharmony_ci#endif 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci/* return true for formats that can be converted among each other by NVC0_2D */ 197bf215546Sopenharmony_cistatic inline bool 198bf215546Sopenharmony_cinv50_2d_dst_format_faithful(enum pipe_format format) 199bf215546Sopenharmony_ci{ 200bf215546Sopenharmony_ci const uint64_t mask = 201bf215546Sopenharmony_ci NV50_ENG2D_SUPPORTED_FORMATS & 202bf215546Sopenharmony_ci ~NV50_ENG2D_NOCONVERT_FORMATS; 203bf215546Sopenharmony_ci uint8_t id = nv50_format_table[format].rt; 204bf215546Sopenharmony_ci return (id >= 0xc0) && (mask & (1ULL << (id - 0xc0))); 205bf215546Sopenharmony_ci} 206bf215546Sopenharmony_cistatic inline bool 207bf215546Sopenharmony_cinv50_2d_src_format_faithful(enum pipe_format format) 208bf215546Sopenharmony_ci{ 209bf215546Sopenharmony_ci const uint64_t mask = 210bf215546Sopenharmony_ci NV50_ENG2D_SUPPORTED_FORMATS & 211bf215546Sopenharmony_ci ~(NV50_ENG2D_LUMINANCE_FORMATS | NV50_ENG2D_INTENSITY_FORMATS); 212bf215546Sopenharmony_ci uint8_t id = nv50_format_table[format].rt; 213bf215546Sopenharmony_ci return (id >= 0xc0) && (mask & (1ULL << (id - 0xc0))); 214bf215546Sopenharmony_ci} 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_cistatic inline bool 217bf215546Sopenharmony_cinv50_2d_format_supported(enum pipe_format format) 218bf215546Sopenharmony_ci{ 219bf215546Sopenharmony_ci uint8_t id = nv50_format_table[format].rt; 220bf215546Sopenharmony_ci return (id >= 0xc0) && 221bf215546Sopenharmony_ci (NV50_ENG2D_SUPPORTED_FORMATS & (1ULL << (id - 0xc0))); 222bf215546Sopenharmony_ci} 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_cistatic inline bool 225bf215546Sopenharmony_cinv50_2d_dst_format_ops_supported(enum pipe_format format) 226bf215546Sopenharmony_ci{ 227bf215546Sopenharmony_ci uint8_t id = nv50_format_table[format].rt; 228bf215546Sopenharmony_ci return (id >= 0xc0) && 229bf215546Sopenharmony_ci (NV50_ENG2D_OPERATION_FORMATS & (1ULL << (id - 0xc0))); 230bf215546Sopenharmony_ci} 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_ci#endif /* __NV50_BLIT_H__ */ 233