1b8e80941Smrg/* 2b8e80941Smrg * Copyright © 2015 Broadcom 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21b8e80941Smrg * IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg 24b8e80941Smrg#include "util/u_format.h" 25b8e80941Smrg#include "util/u_surface.h" 26b8e80941Smrg#include "util/u_blitter.h" 27b8e80941Smrg#include "compiler/nir/nir_builder.h" 28b8e80941Smrg#include "vc4_context.h" 29b8e80941Smrg 30b8e80941Smrgstatic struct pipe_surface * 31b8e80941Smrgvc4_get_blit_surface(struct pipe_context *pctx, 32b8e80941Smrg struct pipe_resource *prsc, unsigned level) 33b8e80941Smrg{ 34b8e80941Smrg struct pipe_surface tmpl; 35b8e80941Smrg 36b8e80941Smrg memset(&tmpl, 0, sizeof(tmpl)); 37b8e80941Smrg tmpl.format = prsc->format; 38b8e80941Smrg tmpl.u.tex.level = level; 39b8e80941Smrg tmpl.u.tex.first_layer = 0; 40b8e80941Smrg tmpl.u.tex.last_layer = 0; 41b8e80941Smrg 42b8e80941Smrg return pctx->create_surface(pctx, prsc, &tmpl); 43b8e80941Smrg} 44b8e80941Smrg 45b8e80941Smrgstatic bool 46b8e80941Smrgis_tile_unaligned(unsigned size, unsigned tile_size) 47b8e80941Smrg{ 48b8e80941Smrg return size & (tile_size - 1); 49b8e80941Smrg} 50b8e80941Smrg 51b8e80941Smrgstatic bool 52b8e80941Smrgvc4_tile_blit(struct pipe_context *pctx, const struct pipe_blit_info *info) 53b8e80941Smrg{ 54b8e80941Smrg struct vc4_context *vc4 = vc4_context(pctx); 55b8e80941Smrg bool msaa = (info->src.resource->nr_samples > 1 || 56b8e80941Smrg info->dst.resource->nr_samples > 1); 57b8e80941Smrg int tile_width = msaa ? 32 : 64; 58b8e80941Smrg int tile_height = msaa ? 32 : 64; 59b8e80941Smrg 60b8e80941Smrg if (util_format_is_depth_or_stencil(info->dst.resource->format)) 61b8e80941Smrg return false; 62b8e80941Smrg 63b8e80941Smrg if (info->scissor_enable) 64b8e80941Smrg return false; 65b8e80941Smrg 66b8e80941Smrg if ((info->mask & PIPE_MASK_RGBA) == 0) 67b8e80941Smrg return false; 68b8e80941Smrg 69b8e80941Smrg if (info->dst.box.x != info->src.box.x || 70b8e80941Smrg info->dst.box.y != info->src.box.y || 71b8e80941Smrg info->dst.box.width != info->src.box.width || 72b8e80941Smrg info->dst.box.height != info->src.box.height) { 73b8e80941Smrg return false; 74b8e80941Smrg } 75b8e80941Smrg 76b8e80941Smrg int dst_surface_width = u_minify(info->dst.resource->width0, 77b8e80941Smrg info->dst.level); 78b8e80941Smrg int dst_surface_height = u_minify(info->dst.resource->height0, 79b8e80941Smrg info->dst.level); 80b8e80941Smrg if (is_tile_unaligned(info->dst.box.x, tile_width) || 81b8e80941Smrg is_tile_unaligned(info->dst.box.y, tile_height) || 82b8e80941Smrg (is_tile_unaligned(info->dst.box.width, tile_width) && 83b8e80941Smrg info->dst.box.x + info->dst.box.width != dst_surface_width) || 84b8e80941Smrg (is_tile_unaligned(info->dst.box.height, tile_height) && 85b8e80941Smrg info->dst.box.y + info->dst.box.height != dst_surface_height)) { 86b8e80941Smrg return false; 87b8e80941Smrg } 88b8e80941Smrg 89b8e80941Smrg /* VC4_PACKET_LOAD_TILE_BUFFER_GENERAL uses the 90b8e80941Smrg * VC4_PACKET_TILE_RENDERING_MODE_CONFIG's width (determined by our 91b8e80941Smrg * destination surface) to determine the stride. This may be wrong 92b8e80941Smrg * when reading from texture miplevels > 0, which are stored in 93b8e80941Smrg * POT-sized areas. For MSAA, the tile addresses are computed 94b8e80941Smrg * explicitly by the RCL, but still use the destination width to 95b8e80941Smrg * determine the stride (which could be fixed by explicitly supplying 96b8e80941Smrg * it in the ABI). 97b8e80941Smrg */ 98b8e80941Smrg struct vc4_resource *rsc = vc4_resource(info->src.resource); 99b8e80941Smrg 100b8e80941Smrg uint32_t stride; 101b8e80941Smrg 102b8e80941Smrg if (info->src.resource->nr_samples > 1) 103b8e80941Smrg stride = align(dst_surface_width, 32) * 4 * rsc->cpp; 104b8e80941Smrg else if (rsc->slices[info->src.level].tiling == VC4_TILING_FORMAT_T) 105b8e80941Smrg stride = align(dst_surface_width * rsc->cpp, 128); 106b8e80941Smrg else 107b8e80941Smrg stride = align(dst_surface_width * rsc->cpp, 16); 108b8e80941Smrg 109b8e80941Smrg if (stride != rsc->slices[info->src.level].stride) 110b8e80941Smrg return false; 111b8e80941Smrg 112b8e80941Smrg if (info->dst.resource->format != info->src.resource->format) 113b8e80941Smrg return false; 114b8e80941Smrg 115b8e80941Smrg if (false) { 116b8e80941Smrg fprintf(stderr, "RCL blit from %d,%d to %d,%d (%d,%d)\n", 117b8e80941Smrg info->src.box.x, 118b8e80941Smrg info->src.box.y, 119b8e80941Smrg info->dst.box.x, 120b8e80941Smrg info->dst.box.y, 121b8e80941Smrg info->dst.box.width, 122b8e80941Smrg info->dst.box.height); 123b8e80941Smrg } 124b8e80941Smrg 125b8e80941Smrg struct pipe_surface *dst_surf = 126b8e80941Smrg vc4_get_blit_surface(pctx, info->dst.resource, info->dst.level); 127b8e80941Smrg struct pipe_surface *src_surf = 128b8e80941Smrg vc4_get_blit_surface(pctx, info->src.resource, info->src.level); 129b8e80941Smrg 130b8e80941Smrg vc4_flush_jobs_reading_resource(vc4, info->src.resource); 131b8e80941Smrg 132b8e80941Smrg struct vc4_job *job = vc4_get_job(vc4, dst_surf, NULL); 133b8e80941Smrg pipe_surface_reference(&job->color_read, src_surf); 134b8e80941Smrg 135b8e80941Smrg /* If we're resolving from MSAA to single sample, we still need to run 136b8e80941Smrg * the engine in MSAA mode for the load. 137b8e80941Smrg */ 138b8e80941Smrg if (!job->msaa && info->src.resource->nr_samples > 1) { 139b8e80941Smrg job->msaa = true; 140b8e80941Smrg job->tile_width = 32; 141b8e80941Smrg job->tile_height = 32; 142b8e80941Smrg } 143b8e80941Smrg 144b8e80941Smrg job->draw_min_x = info->dst.box.x; 145b8e80941Smrg job->draw_min_y = info->dst.box.y; 146b8e80941Smrg job->draw_max_x = info->dst.box.x + info->dst.box.width; 147b8e80941Smrg job->draw_max_y = info->dst.box.y + info->dst.box.height; 148b8e80941Smrg job->draw_width = dst_surf->width; 149b8e80941Smrg job->draw_height = dst_surf->height; 150b8e80941Smrg 151b8e80941Smrg job->tile_width = tile_width; 152b8e80941Smrg job->tile_height = tile_height; 153b8e80941Smrg job->msaa = msaa; 154b8e80941Smrg job->needs_flush = true; 155b8e80941Smrg job->resolve |= PIPE_CLEAR_COLOR; 156b8e80941Smrg 157b8e80941Smrg vc4_job_submit(vc4, job); 158b8e80941Smrg 159b8e80941Smrg pipe_surface_reference(&dst_surf, NULL); 160b8e80941Smrg pipe_surface_reference(&src_surf, NULL); 161b8e80941Smrg 162b8e80941Smrg return true; 163b8e80941Smrg} 164b8e80941Smrg 165b8e80941Smrgvoid 166b8e80941Smrgvc4_blitter_save(struct vc4_context *vc4) 167b8e80941Smrg{ 168b8e80941Smrg util_blitter_save_vertex_buffer_slot(vc4->blitter, vc4->vertexbuf.vb); 169b8e80941Smrg util_blitter_save_vertex_elements(vc4->blitter, vc4->vtx); 170b8e80941Smrg util_blitter_save_vertex_shader(vc4->blitter, vc4->prog.bind_vs); 171b8e80941Smrg util_blitter_save_rasterizer(vc4->blitter, vc4->rasterizer); 172b8e80941Smrg util_blitter_save_viewport(vc4->blitter, &vc4->viewport); 173b8e80941Smrg util_blitter_save_scissor(vc4->blitter, &vc4->scissor); 174b8e80941Smrg util_blitter_save_fragment_shader(vc4->blitter, vc4->prog.bind_fs); 175b8e80941Smrg util_blitter_save_blend(vc4->blitter, vc4->blend); 176b8e80941Smrg util_blitter_save_depth_stencil_alpha(vc4->blitter, vc4->zsa); 177b8e80941Smrg util_blitter_save_stencil_ref(vc4->blitter, &vc4->stencil_ref); 178b8e80941Smrg util_blitter_save_sample_mask(vc4->blitter, vc4->sample_mask); 179b8e80941Smrg util_blitter_save_framebuffer(vc4->blitter, &vc4->framebuffer); 180b8e80941Smrg util_blitter_save_fragment_sampler_states(vc4->blitter, 181b8e80941Smrg vc4->fragtex.num_samplers, 182b8e80941Smrg (void **)vc4->fragtex.samplers); 183b8e80941Smrg util_blitter_save_fragment_sampler_views(vc4->blitter, 184b8e80941Smrg vc4->fragtex.num_textures, vc4->fragtex.textures); 185b8e80941Smrg} 186b8e80941Smrg 187b8e80941Smrgstatic void *vc4_get_yuv_vs(struct pipe_context *pctx) 188b8e80941Smrg{ 189b8e80941Smrg struct vc4_context *vc4 = vc4_context(pctx); 190b8e80941Smrg struct pipe_screen *pscreen = pctx->screen; 191b8e80941Smrg 192b8e80941Smrg if (vc4->yuv_linear_blit_vs) 193b8e80941Smrg return vc4->yuv_linear_blit_vs; 194b8e80941Smrg 195b8e80941Smrg const struct nir_shader_compiler_options *options = 196b8e80941Smrg pscreen->get_compiler_options(pscreen, 197b8e80941Smrg PIPE_SHADER_IR_NIR, 198b8e80941Smrg PIPE_SHADER_VERTEX); 199b8e80941Smrg 200b8e80941Smrg nir_builder b; 201b8e80941Smrg nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_VERTEX, options); 202b8e80941Smrg b.shader->info.name = ralloc_strdup(b.shader, "linear_blit_vs"); 203b8e80941Smrg 204b8e80941Smrg const struct glsl_type *vec4 = glsl_vec4_type(); 205b8e80941Smrg nir_variable *pos_in = nir_variable_create(b.shader, nir_var_shader_in, 206b8e80941Smrg vec4, "pos"); 207b8e80941Smrg 208b8e80941Smrg nir_variable *pos_out = nir_variable_create(b.shader, nir_var_shader_out, 209b8e80941Smrg vec4, "gl_Position"); 210b8e80941Smrg pos_out->data.location = VARYING_SLOT_POS; 211b8e80941Smrg 212b8e80941Smrg nir_store_var(&b, pos_out, nir_load_var(&b, pos_in), 0xf); 213b8e80941Smrg 214b8e80941Smrg struct pipe_shader_state shader_tmpl = { 215b8e80941Smrg .type = PIPE_SHADER_IR_NIR, 216b8e80941Smrg .ir.nir = b.shader, 217b8e80941Smrg }; 218b8e80941Smrg 219b8e80941Smrg vc4->yuv_linear_blit_vs = pctx->create_vs_state(pctx, &shader_tmpl); 220b8e80941Smrg 221b8e80941Smrg return vc4->yuv_linear_blit_vs; 222b8e80941Smrg} 223b8e80941Smrg 224b8e80941Smrgstatic void *vc4_get_yuv_fs(struct pipe_context *pctx, int cpp) 225b8e80941Smrg{ 226b8e80941Smrg struct vc4_context *vc4 = vc4_context(pctx); 227b8e80941Smrg struct pipe_screen *pscreen = pctx->screen; 228b8e80941Smrg struct pipe_shader_state **cached_shader; 229b8e80941Smrg const char *name; 230b8e80941Smrg 231b8e80941Smrg if (cpp == 1) { 232b8e80941Smrg cached_shader = &vc4->yuv_linear_blit_fs_8bit; 233b8e80941Smrg name = "linear_blit_8bit_fs"; 234b8e80941Smrg } else { 235b8e80941Smrg cached_shader = &vc4->yuv_linear_blit_fs_16bit; 236b8e80941Smrg name = "linear_blit_16bit_fs"; 237b8e80941Smrg } 238b8e80941Smrg 239b8e80941Smrg if (*cached_shader) 240b8e80941Smrg return *cached_shader; 241b8e80941Smrg 242b8e80941Smrg const struct nir_shader_compiler_options *options = 243b8e80941Smrg pscreen->get_compiler_options(pscreen, 244b8e80941Smrg PIPE_SHADER_IR_NIR, 245b8e80941Smrg PIPE_SHADER_FRAGMENT); 246b8e80941Smrg 247b8e80941Smrg nir_builder b; 248b8e80941Smrg nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, options); 249b8e80941Smrg b.shader->info.name = ralloc_strdup(b.shader, name); 250b8e80941Smrg 251b8e80941Smrg const struct glsl_type *vec4 = glsl_vec4_type(); 252b8e80941Smrg const struct glsl_type *glsl_int = glsl_int_type(); 253b8e80941Smrg 254b8e80941Smrg nir_variable *color_out = nir_variable_create(b.shader, nir_var_shader_out, 255b8e80941Smrg vec4, "f_color"); 256b8e80941Smrg color_out->data.location = FRAG_RESULT_COLOR; 257b8e80941Smrg 258b8e80941Smrg nir_variable *pos_in = nir_variable_create(b.shader, nir_var_shader_in, 259b8e80941Smrg vec4, "pos"); 260b8e80941Smrg pos_in->data.location = VARYING_SLOT_POS; 261b8e80941Smrg nir_ssa_def *pos = nir_load_var(&b, pos_in); 262b8e80941Smrg 263b8e80941Smrg nir_ssa_def *one = nir_imm_int(&b, 1); 264b8e80941Smrg nir_ssa_def *two = nir_imm_int(&b, 2); 265b8e80941Smrg 266b8e80941Smrg nir_ssa_def *x = nir_f2i32(&b, nir_channel(&b, pos, 0)); 267b8e80941Smrg nir_ssa_def *y = nir_f2i32(&b, nir_channel(&b, pos, 1)); 268b8e80941Smrg 269b8e80941Smrg nir_variable *stride_in = nir_variable_create(b.shader, nir_var_uniform, 270b8e80941Smrg glsl_int, "stride"); 271b8e80941Smrg nir_ssa_def *stride = nir_load_var(&b, stride_in); 272b8e80941Smrg 273b8e80941Smrg nir_ssa_def *x_offset; 274b8e80941Smrg nir_ssa_def *y_offset; 275b8e80941Smrg if (cpp == 1) { 276b8e80941Smrg nir_ssa_def *intra_utile_x_offset = 277b8e80941Smrg nir_ishl(&b, nir_iand(&b, x, one), two); 278b8e80941Smrg nir_ssa_def *inter_utile_x_offset = 279b8e80941Smrg nir_ishl(&b, nir_iand(&b, x, nir_imm_int(&b, ~3)), one); 280b8e80941Smrg 281b8e80941Smrg x_offset = nir_iadd(&b, 282b8e80941Smrg intra_utile_x_offset, 283b8e80941Smrg inter_utile_x_offset); 284b8e80941Smrg y_offset = nir_imul(&b, 285b8e80941Smrg nir_iadd(&b, 286b8e80941Smrg nir_ishl(&b, y, one), 287b8e80941Smrg nir_ushr(&b, nir_iand(&b, x, two), one)), 288b8e80941Smrg stride); 289b8e80941Smrg } else { 290b8e80941Smrg x_offset = nir_ishl(&b, x, two); 291b8e80941Smrg y_offset = nir_imul(&b, y, stride); 292b8e80941Smrg } 293b8e80941Smrg 294b8e80941Smrg nir_intrinsic_instr *load = 295b8e80941Smrg nir_intrinsic_instr_create(b.shader, nir_intrinsic_load_ubo); 296b8e80941Smrg load->num_components = 1; 297b8e80941Smrg nir_ssa_dest_init(&load->instr, &load->dest, load->num_components, 32, NULL); 298b8e80941Smrg load->src[0] = nir_src_for_ssa(one); 299b8e80941Smrg load->src[1] = nir_src_for_ssa(nir_iadd(&b, x_offset, y_offset)); 300b8e80941Smrg nir_builder_instr_insert(&b, &load->instr); 301b8e80941Smrg 302b8e80941Smrg nir_store_var(&b, color_out, 303b8e80941Smrg nir_unpack_unorm_4x8(&b, &load->dest.ssa), 304b8e80941Smrg 0xf); 305b8e80941Smrg 306b8e80941Smrg struct pipe_shader_state shader_tmpl = { 307b8e80941Smrg .type = PIPE_SHADER_IR_NIR, 308b8e80941Smrg .ir.nir = b.shader, 309b8e80941Smrg }; 310b8e80941Smrg 311b8e80941Smrg *cached_shader = pctx->create_fs_state(pctx, &shader_tmpl); 312b8e80941Smrg 313b8e80941Smrg return *cached_shader; 314b8e80941Smrg} 315b8e80941Smrg 316b8e80941Smrgstatic bool 317b8e80941Smrgvc4_yuv_blit(struct pipe_context *pctx, const struct pipe_blit_info *info) 318b8e80941Smrg{ 319b8e80941Smrg struct vc4_context *vc4 = vc4_context(pctx); 320b8e80941Smrg struct vc4_resource *src = vc4_resource(info->src.resource); 321b8e80941Smrg struct vc4_resource *dst = vc4_resource(info->dst.resource); 322b8e80941Smrg bool ok; 323b8e80941Smrg 324b8e80941Smrg if (src->tiled) 325b8e80941Smrg return false; 326b8e80941Smrg if (src->base.format != PIPE_FORMAT_R8_UNORM && 327b8e80941Smrg src->base.format != PIPE_FORMAT_R8G8_UNORM) 328b8e80941Smrg return false; 329b8e80941Smrg 330b8e80941Smrg /* YUV blits always turn raster-order to tiled */ 331b8e80941Smrg assert(dst->base.format == src->base.format); 332b8e80941Smrg assert(dst->tiled); 333b8e80941Smrg 334b8e80941Smrg /* Always 1:1 and at the origin */ 335b8e80941Smrg assert(info->src.box.x == 0 && info->dst.box.x == 0); 336b8e80941Smrg assert(info->src.box.y == 0 && info->dst.box.y == 0); 337b8e80941Smrg assert(info->src.box.width == info->dst.box.width); 338b8e80941Smrg assert(info->src.box.height == info->dst.box.height); 339b8e80941Smrg 340b8e80941Smrg if ((src->slices[info->src.level].offset & 3) || 341b8e80941Smrg (src->slices[info->src.level].stride & 3)) { 342b8e80941Smrg perf_debug("YUV-blit src texture offset/stride misaligned: 0x%08x/%d\n", 343b8e80941Smrg src->slices[info->src.level].offset, 344b8e80941Smrg src->slices[info->src.level].stride); 345b8e80941Smrg goto fallback; 346b8e80941Smrg } 347b8e80941Smrg 348b8e80941Smrg vc4_blitter_save(vc4); 349b8e80941Smrg 350b8e80941Smrg /* Create a renderable surface mapping the T-tiled shadow buffer. 351b8e80941Smrg */ 352b8e80941Smrg struct pipe_surface dst_tmpl; 353b8e80941Smrg util_blitter_default_dst_texture(&dst_tmpl, info->dst.resource, 354b8e80941Smrg info->dst.level, info->dst.box.z); 355b8e80941Smrg dst_tmpl.format = PIPE_FORMAT_RGBA8888_UNORM; 356b8e80941Smrg struct pipe_surface *dst_surf = 357b8e80941Smrg pctx->create_surface(pctx, info->dst.resource, &dst_tmpl); 358b8e80941Smrg if (!dst_surf) { 359b8e80941Smrg fprintf(stderr, "Failed to create YUV dst surface\n"); 360b8e80941Smrg util_blitter_unset_running_flag(vc4->blitter); 361b8e80941Smrg return false; 362b8e80941Smrg } 363b8e80941Smrg dst_surf->width /= 2; 364b8e80941Smrg if (dst->cpp == 1) 365b8e80941Smrg dst_surf->height /= 2; 366b8e80941Smrg 367b8e80941Smrg /* Set the constant buffer. */ 368b8e80941Smrg uint32_t stride = src->slices[info->src.level].stride; 369b8e80941Smrg struct pipe_constant_buffer cb_uniforms = { 370b8e80941Smrg .user_buffer = &stride, 371b8e80941Smrg .buffer_size = sizeof(stride), 372b8e80941Smrg }; 373b8e80941Smrg pctx->set_constant_buffer(pctx, PIPE_SHADER_FRAGMENT, 0, &cb_uniforms); 374b8e80941Smrg struct pipe_constant_buffer cb_src = { 375b8e80941Smrg .buffer = info->src.resource, 376b8e80941Smrg .buffer_offset = src->slices[info->src.level].offset, 377b8e80941Smrg .buffer_size = (src->bo->size - 378b8e80941Smrg src->slices[info->src.level].offset), 379b8e80941Smrg }; 380b8e80941Smrg pctx->set_constant_buffer(pctx, PIPE_SHADER_FRAGMENT, 1, &cb_src); 381b8e80941Smrg 382b8e80941Smrg /* Unbind the textures, to make sure we don't try to recurse into the 383b8e80941Smrg * shadow blit. 384b8e80941Smrg */ 385b8e80941Smrg pctx->set_sampler_views(pctx, PIPE_SHADER_FRAGMENT, 0, 0, NULL); 386b8e80941Smrg pctx->bind_sampler_states(pctx, PIPE_SHADER_FRAGMENT, 0, 0, NULL); 387b8e80941Smrg 388b8e80941Smrg util_blitter_custom_shader(vc4->blitter, dst_surf, 389b8e80941Smrg vc4_get_yuv_vs(pctx), 390b8e80941Smrg vc4_get_yuv_fs(pctx, src->cpp)); 391b8e80941Smrg 392b8e80941Smrg util_blitter_restore_textures(vc4->blitter); 393b8e80941Smrg util_blitter_restore_constant_buffer_state(vc4->blitter); 394b8e80941Smrg /* Restore cb1 (util_blitter doesn't handle this one). */ 395b8e80941Smrg struct pipe_constant_buffer cb_disabled = { 0 }; 396b8e80941Smrg pctx->set_constant_buffer(pctx, PIPE_SHADER_FRAGMENT, 1, &cb_disabled); 397b8e80941Smrg 398b8e80941Smrg pipe_surface_reference(&dst_surf, NULL); 399b8e80941Smrg 400b8e80941Smrg return true; 401b8e80941Smrg 402b8e80941Smrgfallback: 403b8e80941Smrg /* Do an immediate SW fallback, since the render blit path 404b8e80941Smrg * would just recurse. 405b8e80941Smrg */ 406b8e80941Smrg ok = util_try_blit_via_copy_region(pctx, info); 407b8e80941Smrg assert(ok); (void)ok; 408b8e80941Smrg 409b8e80941Smrg return true; 410b8e80941Smrg} 411b8e80941Smrg 412b8e80941Smrgstatic bool 413b8e80941Smrgvc4_render_blit(struct pipe_context *ctx, struct pipe_blit_info *info) 414b8e80941Smrg{ 415b8e80941Smrg struct vc4_context *vc4 = vc4_context(ctx); 416b8e80941Smrg 417b8e80941Smrg if (!util_blitter_is_blit_supported(vc4->blitter, info)) { 418b8e80941Smrg fprintf(stderr, "blit unsupported %s -> %s\n", 419b8e80941Smrg util_format_short_name(info->src.resource->format), 420b8e80941Smrg util_format_short_name(info->dst.resource->format)); 421b8e80941Smrg return false; 422b8e80941Smrg } 423b8e80941Smrg 424b8e80941Smrg /* Enable the scissor, so we get a minimal set of tiles rendered. */ 425b8e80941Smrg if (!info->scissor_enable) { 426b8e80941Smrg info->scissor_enable = true; 427b8e80941Smrg info->scissor.minx = info->dst.box.x; 428b8e80941Smrg info->scissor.miny = info->dst.box.y; 429b8e80941Smrg info->scissor.maxx = info->dst.box.x + info->dst.box.width; 430b8e80941Smrg info->scissor.maxy = info->dst.box.y + info->dst.box.height; 431b8e80941Smrg } 432b8e80941Smrg 433b8e80941Smrg vc4_blitter_save(vc4); 434b8e80941Smrg util_blitter_blit(vc4->blitter, info); 435b8e80941Smrg 436b8e80941Smrg return true; 437b8e80941Smrg} 438b8e80941Smrg 439b8e80941Smrg/* Optimal hardware path for blitting pixels. 440b8e80941Smrg * Scaling, format conversion, up- and downsampling (resolve) are allowed. 441b8e80941Smrg */ 442b8e80941Smrgvoid 443b8e80941Smrgvc4_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info) 444b8e80941Smrg{ 445b8e80941Smrg struct pipe_blit_info info = *blit_info; 446b8e80941Smrg 447b8e80941Smrg if (vc4_yuv_blit(pctx, blit_info)) 448b8e80941Smrg return; 449b8e80941Smrg 450b8e80941Smrg if (vc4_tile_blit(pctx, blit_info)) 451b8e80941Smrg return; 452b8e80941Smrg 453b8e80941Smrg if (info.mask & PIPE_MASK_S) { 454b8e80941Smrg if (util_try_blit_via_copy_region(pctx, &info)) 455b8e80941Smrg return; 456b8e80941Smrg 457b8e80941Smrg info.mask &= ~PIPE_MASK_S; 458b8e80941Smrg fprintf(stderr, "cannot blit stencil, skipping\n"); 459b8e80941Smrg } 460b8e80941Smrg 461b8e80941Smrg if (vc4_render_blit(pctx, &info)) 462b8e80941Smrg return; 463b8e80941Smrg 464b8e80941Smrg fprintf(stderr, "Unsupported blit\n"); 465b8e80941Smrg} 466