vc4_nir_lower_blend.c revision bf3c50fba221f216e38d3f60f89161ced4c684c0
1bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt/* 2bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * Copyright © 2015 Broadcom 3bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * 4bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a 5bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * copy of this software and associated documentation files (the "Software"), 6bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * to deal in the Software without restriction, including without limitation 7bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * and/or sell copies of the Software, and to permit persons to whom the 9bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * Software is furnished to do so, subject to the following conditions: 10bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * 11bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * The above copyright notice and this permission notice (including the next 12bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * paragraph) shall be included in all copies or substantial portions of the 13bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * Software. 14bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * 15bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * IN THE SOFTWARE. 22bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt */ 23bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 24bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt/** 25bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * Implements most of the fixed function fragment pipeline in shader code. 26bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * 27bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * VC4 doesn't have any hardware support for blending, alpha test, logic ops, 28bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * or color mask. Instead, you read the current contents of the destination 29bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * from the tile buffer after having waited for the scoreboard (which is 30bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * handled by vc4_qpu_emit.c), then do math using your output color and that 31bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * destination value, and update the output color appropriately. 32bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt */ 33bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 34bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt/** 35bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * Lowers fixed-function blending to a load of the destination color and a 36bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * series of ALU operations before the store of the output. 37bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt */ 38bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt#include "util/u_format.h" 39bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt#include "vc4_qir.h" 40bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt#include "glsl/nir/nir_builder.h" 41bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt#include "vc4_context.h" 42bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 43bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt/** Emits a load of the previous fragment color from the tile buffer. */ 44bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 45bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_get_dst_color(nir_builder *b) 46bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 47bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_instr *load = 48bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_instr_create(b->shader, 49bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_load_input); 50bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt load->num_components = 1; 51bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt load->const_index[0] = VC4_NIR_TLB_COLOR_READ_INPUT; 52bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_dest_init(&load->instr, &load->dest, 1, NULL); 53bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_builder_instr_insert(b, &load->instr); 54bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return &load->dest.ssa; 55bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 56bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 57bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 58bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_srgb_decode(nir_builder *b, nir_ssa_def *srgb) 59bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 60bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *is_low = nir_flt(b, srgb, nir_imm_float(b, 0.04045)); 61bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *low = nir_fmul(b, srgb, nir_imm_float(b, 1.0 / 12.92)); 62bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *high = nir_fpow(b, 63bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_fmul(b, 64bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_fadd(b, srgb, 65bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 0.055)), 66bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 1.0 / 1.055)), 67bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 2.4)); 68bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 69bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_bcsel(b, is_low, low, high); 70bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 71bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 72bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 73bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_srgb_encode(nir_builder *b, nir_ssa_def *linear) 74bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 75bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *is_low = nir_flt(b, linear, nir_imm_float(b, 0.0031308)); 76bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *low = nir_fmul(b, linear, nir_imm_float(b, 12.92)); 77bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *high = nir_fsub(b, 78bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_fmul(b, 79bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 1.055), 80bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_fpow(b, 81bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt linear, 82bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 0.41666))), 83bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 0.055)); 84bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 85bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_bcsel(b, is_low, low, high); 86bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 87bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 88bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 89bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_blend_channel(nir_builder *b, 90bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def **src, 91bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def **dst, 92bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt unsigned factor, 93bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt int channel) 94bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 95bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt switch(factor) { 96bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_ONE: 97bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_float(b, 1.0); 98bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_SRC_COLOR: 99bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return src[channel]; 100bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_SRC_ALPHA: 101bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return src[3]; 102bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_DST_ALPHA: 103bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return dst[3]; 104bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_DST_COLOR: 105bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return dst[channel]; 106bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 107bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (channel != 3) { 108bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fmin(b, 109bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src[3], 110bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_fsub(b, 111bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_float(b, 1.0), 112bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt dst[3])); 113bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } else { 114bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_float(b, 1.0); 115bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 116bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_CONST_COLOR: 117bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return vc4_nir_get_state_uniform(b, QUNIFORM_BLEND_CONST_COLOR_X + channel); 118bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_CONST_ALPHA: 119bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return vc4_nir_get_state_uniform(b, QUNIFORM_BLEND_CONST_COLOR_W); 120bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_ZERO: 121bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_float(b, 0.0); 122bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_SRC_COLOR: 123bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, nir_imm_float(b, 1.0), src[channel]); 124bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 125bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, nir_imm_float(b, 1.0), src[3]); 126bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_DST_ALPHA: 127bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, nir_imm_float(b, 1.0), dst[3]); 128bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_DST_COLOR: 129bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, nir_imm_float(b, 1.0), dst[channel]); 130bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_CONST_COLOR: 131bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, nir_imm_float(b, 1.0), 132bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_get_state_uniform(b, QUNIFORM_BLEND_CONST_COLOR_X + channel)); 133bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 134bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, nir_imm_float(b, 1.0), 135bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_get_state_uniform(b, QUNIFORM_BLEND_CONST_COLOR_W)); 136bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 137bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt default: 138bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_SRC1_COLOR: 139bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_SRC1_ALPHA: 140bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_SRC1_COLOR: 141bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: 142bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Unsupported. */ 143bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt fprintf(stderr, "Unknown blend factor %d\n", factor); 144bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_float(b, 1.0); 145bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 146bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 147bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 148bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 149bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_blend_func(nir_builder *b, nir_ssa_def *src, nir_ssa_def *dst, 150bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt unsigned func) 151bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 152bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt switch (func) { 153bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLEND_ADD: 154bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fadd(b, src, dst); 155bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLEND_SUBTRACT: 156bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, src, dst); 157bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLEND_REVERSE_SUBTRACT: 158bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fsub(b, dst, src); 159bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLEND_MIN: 160bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fmin(b, src, dst); 161bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_BLEND_MAX: 162bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fmax(b, src, dst); 163bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 164bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt default: 165bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Unsupported. */ 166bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt fprintf(stderr, "Unknown blend func %d\n", func); 167bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return src; 168bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 169bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 170bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 171bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 172bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic void 173bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_do_blending(struct vc4_compile *c, nir_builder *b, nir_ssa_def **result, 174bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def **src_color, nir_ssa_def **dst_color) 175bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 176bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt struct pipe_rt_blend_state *blend = &c->fs_key->blend; 177bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 178bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (!blend->blend_enable) { 179bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 4; i++) 180bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt result[i] = src_color[i]; 181bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return; 182bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 183bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 184bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Clamp the src color to [0, 1]. Dest is already clamped. */ 185bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 4; i++) 186bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src_color[i] = nir_fsat(b, src_color[i]); 187bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 188bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *src_blend[4], *dst_blend[4]; 189bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 4; i++) { 190bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt int src_factor = ((i != 3) ? blend->rgb_src_factor : 191bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt blend->alpha_src_factor); 192bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt int dst_factor = ((i != 3) ? blend->rgb_dst_factor : 193bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt blend->alpha_dst_factor); 194bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src_blend[i] = nir_fmul(b, src_color[i], 195bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_blend_channel(b, 196bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src_color, dst_color, 197bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src_factor, i)); 198bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt dst_blend[i] = nir_fmul(b, dst_color[i], 199bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_blend_channel(b, 200bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src_color, dst_color, 201bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt dst_factor, i)); 202bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 203bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 204bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 4; i++) { 205bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt result[i] = vc4_blend_func(b, src_blend[i], dst_blend[i], 206bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt ((i != 3) ? blend->rgb_func : 207bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt blend->alpha_func)); 208bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 209bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 210bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 211bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 212bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_logicop(nir_builder *b, int logicop_func, 213bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *src, nir_ssa_def *dst) 214bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 215bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt switch (logicop_func) { 216bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_CLEAR: 217bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_int(b, 0); 218bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_NOR: 219bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_inot(b, nir_ior(b, src, dst)); 220bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_AND_INVERTED: 221bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_iand(b, nir_inot(b, src), dst); 222bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_COPY_INVERTED: 223bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_inot(b, src); 224bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_AND_REVERSE: 225bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_iand(b, src, nir_inot(b, dst)); 226bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_INVERT: 227bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_inot(b, dst); 228bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_XOR: 229bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_ixor(b, src, dst); 230bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_NAND: 231bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_inot(b, nir_iand(b, src, dst)); 232bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_AND: 233bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_iand(b, src, dst); 234bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_EQUIV: 235bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_inot(b, nir_ixor(b, src, dst)); 236bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_NOOP: 237bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return dst; 238bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_OR_INVERTED: 239bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_ior(b, nir_inot(b, src), dst); 240bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_OR_REVERSE: 241bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_ior(b, src, nir_inot(b, dst)); 242bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_OR: 243bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_ior(b, src, dst); 244bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_SET: 245bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_int(b, ~0); 246bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt default: 247bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt fprintf(stderr, "Unknown logic op %d\n", logicop_func); 248bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* FALLTHROUGH */ 249bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_LOGICOP_COPY: 250bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return src; 251bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 252bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 253bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 254bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic nir_ssa_def * 255bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_pipe_compare_func(nir_builder *b, int func, 256bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *src0, nir_ssa_def *src1) 257bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 258bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt switch (func) { 259bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt default: 260bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt fprintf(stderr, "Unknown compare func %d\n", func); 261bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* FALLTHROUGH */ 262bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_NEVER: 263bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_int(b, 0); 264bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_ALWAYS: 265bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_imm_int(b, ~0); 266bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_EQUAL: 267bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_feq(b, src0, src1); 268bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_NOTEQUAL: 269bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fne(b, src0, src1); 270bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_GREATER: 271bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_flt(b, src1, src0); 272bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_GEQUAL: 273bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fge(b, src0, src1); 274bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_LESS: 275bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_flt(b, src0, src1); 276bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt case PIPE_FUNC_LEQUAL: 277bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return nir_fge(b, src1, src0); 278bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 279bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 280bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 281bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic void 282bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_emit_alpha_test_discard(struct vc4_compile *c, nir_builder *b, 283bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *alpha) 284bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 285bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (!c->fs_key->alpha_test) 286bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return; 287bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 288bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *alpha_ref = 289bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_get_state_uniform(b, QUNIFORM_ALPHA_REF); 290bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *condition = 291bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_pipe_compare_func(b, c->fs_key->alpha_test_func, 292bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt alpha, alpha_ref); 293bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 294bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_instr *discard = 295bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_instr_create(b->shader, 296bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_discard_if); 297bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt discard->num_components = 1; 298bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt discard->src[0] = nir_src_for_ssa(nir_inot(b, condition)); 299bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_builder_instr_insert(b, &discard->instr); 300bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 301bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 302bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic void 303bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_lower_blend_instr(struct vc4_compile *c, nir_builder *b, 304bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_instr *intr) 305bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 306bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt enum pipe_format color_format = c->fs_key->color_format; 307bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt const uint8_t *format_swiz = vc4_get_format_swizzle(color_format); 308bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 309bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Pull out the float src/dst color components. */ 310bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *packed_dst_color = vc4_nir_get_dst_color(b); 311bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *dst_vec4 = nir_unpack_unorm_4x8(b, packed_dst_color); 312bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *src_color[4], *unpacked_dst_color[4]; 313bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (unsigned i = 0; i < 4; i++) { 314bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt src_color[i] = nir_swizzle(b, intr->src[0].ssa, &i, 1, false); 315bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt unpacked_dst_color[i] = nir_swizzle(b, dst_vec4, &i, 1, false); 316bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 317bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 318bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Unswizzle the destination color. */ 319bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *dst_color[4]; 320bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (unsigned i = 0; i < 4; i++) { 321bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt dst_color[i] = vc4_nir_get_swizzled_channel(b, 322bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt unpacked_dst_color, 323bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt format_swiz[i]); 324bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 325bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 326bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_emit_alpha_test_discard(c, b, src_color[3]); 327bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 328bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Turn dst color to linear. */ 329bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (util_format_is_srgb(color_format)) { 330bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 3; i++) 331bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt dst_color[i] = vc4_nir_srgb_decode(b, dst_color[i]); 332bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 333bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 334bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *blend_color[4]; 335bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_do_blending(c, b, blend_color, src_color, dst_color); 336bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 337bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* sRGB encode the output color */ 338bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (util_format_is_srgb(color_format)) { 339bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 3; i++) 340bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt blend_color[i] = vc4_nir_srgb_encode(b, blend_color[i]); 341bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 342bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 343bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *swizzled_outputs[4]; 344bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 4; i++) { 345bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt swizzled_outputs[i] = 346bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_get_swizzled_channel(b, blend_color, 347bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt format_swiz[i]); 348bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 349bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 350bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_ssa_def *packed_color = 351bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_pack_unorm_4x8(b, 352bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_vec4(b, 353bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt swizzled_outputs[0], 354bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt swizzled_outputs[1], 355bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt swizzled_outputs[2], 356bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt swizzled_outputs[3])); 357bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 358bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt packed_color = vc4_logicop(b, c->fs_key->logicop_func, 359bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt packed_color, packed_dst_color); 360bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 361bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* If the bit isn't set in the color mask, then just return the 362bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt * original dst color, instead. 363bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt */ 364bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt uint32_t colormask = 0xffffffff; 365bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt for (int i = 0; i < 4; i++) { 366bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (format_swiz[i] < 4 && 367bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt !(c->fs_key->blend.colormask & (1 << format_swiz[i]))) { 368bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt colormask &= ~(0xff << (i * 8)); 369bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 370bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 371bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt packed_color = nir_ior(b, 372bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_iand(b, packed_color, 373bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_int(b, colormask)), 374bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_iand(b, packed_dst_color, 375bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_imm_int(b, ~colormask))); 376bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 377bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt /* Turn the old vec4 output into a store of the packed color. */ 378bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_instr_rewrite_src(&intr->instr, &intr->src[0], 379bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_src_for_ssa(packed_color)); 380bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt intr->num_components = 1; 381bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 382bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 383bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtstatic bool 384bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_lower_blend_block(nir_block *block, void *state) 385bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 386bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt struct vc4_compile *c = state; 387bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 388bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_foreach_instr(block, instr) { 389bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (instr->type != nir_instr_type_intrinsic) 390bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt continue; 391bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr); 392bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (intr->intrinsic != nir_intrinsic_store_output) 393bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt continue; 394bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 395bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_variable *output_var = NULL; 396bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt foreach_list_typed(nir_variable, var, node, &c->s->outputs) { 397bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (var->data.driver_location == intr->const_index[0]) { 398bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt output_var = var; 399bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt break; 400bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 401bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 402bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt assert(output_var); 403bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt unsigned semantic_name = output_var->data.location; 404bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 405bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (semantic_name != TGSI_SEMANTIC_COLOR) 406bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt continue; 407bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 408bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_function_impl *impl = 409bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_cf_node_get_function(&block->cf_node); 410bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_builder b; 411bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_builder_init(&b, impl); 412bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_builder_insert_before_instr(&b, &intr->instr); 413bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_lower_blend_instr(c, &b, intr); 414bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 415bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt return true; 416bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 417bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 418bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvoid 419bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholtvc4_nir_lower_blend(struct vc4_compile *c) 420bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt{ 421bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_foreach_overload(c->s, overload) { 422bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt if (overload->impl) { 423bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_foreach_block(overload->impl, 424bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt vc4_nir_lower_blend_block, c); 425bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt 426bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_metadata_preserve(overload->impl, 427bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_metadata_block_index | 428bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt nir_metadata_dominance); 429bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 430bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt } 431bf3c50fba221f216e38d3f60f89161ced4c684c0Eric Anholt} 432