Path: blob/21.2-virgl/src/gallium/drivers/panfrost/pan_assemble.c
4570 views
/*1* © Copyright 2018 Alyssa Rosenzweig2* Copyright (C) 2019-2020 Collabora, Ltd.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23*/2425#include <stdio.h>26#include <stdlib.h>27#include <string.h>28#include "pan_bo.h"29#include "pan_context.h"30#include "pan_shader.h"31#include "pan_util.h"32#include "panfrost-quirks.h"3334#include "compiler/nir/nir.h"35#include "nir/tgsi_to_nir.h"36#include "util/u_dynarray.h"37#include "util/u_upload_mgr.h"3839#include "tgsi/tgsi_dump.h"4041void42panfrost_shader_compile(struct pipe_screen *pscreen,43struct panfrost_pool *shader_pool,44struct panfrost_pool *desc_pool,45enum pipe_shader_ir ir_type,46const void *ir,47gl_shader_stage stage,48struct panfrost_shader_state *state)49{50struct panfrost_screen *screen = pan_screen(pscreen);51struct panfrost_device *dev = pan_device(pscreen);5253nir_shader *s;5455if (ir_type == PIPE_SHADER_IR_NIR) {56s = nir_shader_clone(NULL, ir);57} else {58assert (ir_type == PIPE_SHADER_IR_TGSI);59s = tgsi_to_nir(ir, pscreen, false);60}6162/* Lower this early so the backends don't have to worry about it */63if (stage == MESA_SHADER_FRAGMENT)64NIR_PASS_V(s, nir_lower_fragcolor, state->nr_cbufs);6566s->info.stage = stage;6768/* Call out to Midgard compiler given the above NIR */69struct panfrost_compile_inputs inputs = {70.gpu_id = dev->gpu_id,71.shaderdb = !!(dev->debug & PAN_DBG_PRECOMPILE),72};7374memcpy(inputs.rt_formats, state->rt_formats, sizeof(inputs.rt_formats));7576struct util_dynarray binary;7778util_dynarray_init(&binary, NULL);79pan_shader_compile(dev, s, &inputs, &binary, &state->info);8081if (binary.size) {82state->bin = panfrost_pool_take_ref(shader_pool,83pan_pool_upload_aligned(&shader_pool->base,84binary.data, binary.size, 128));85}868788/* Don't upload RSD for fragment shaders since they need draw-time89* merging for e.g. depth/stencil/alpha */90bool upload = stage != MESA_SHADER_FRAGMENT;91screen->vtbl.prepare_rsd(dev, state, desc_pool, upload);9293panfrost_analyze_sysvals(state);9495util_dynarray_fini(&binary);9697/* In both clone and tgsi_to_nir paths, the shader is ralloc'd against98* a NULL context */99ralloc_free(s);100}101102103