1/* 2 * Copyright (c) 2020 Etnaviv Project 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sub license, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the 12 * next paragraph) shall be included in all copies or substantial portions 13 * of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Christian Gmeiner <christian.gmeiner@gmail.com> 25 */ 26 27#include "etnaviv_compiler.h" 28#include "etnaviv_compiler_nir.h" 29#include "etnaviv_debug.h" 30#include "etnaviv_disk_cache.h" 31#include "util/ralloc.h" 32 33struct etna_compiler * 34etna_compiler_create(const char *renderer, const struct etna_specs *specs) 35{ 36 struct etna_compiler *compiler = rzalloc(NULL, struct etna_compiler); 37 38 compiler->options = (nir_shader_compiler_options) { 39 .lower_fpow = true, 40 .lower_ftrunc = true, 41 .fuse_ffma16 = true, 42 .fuse_ffma32 = true, 43 .fuse_ffma64 = true, 44 .lower_bitops = true, 45 .lower_all_io_to_temps = true, 46 .vertex_id_zero_based = true, 47 .lower_flrp32 = true, 48 .lower_fmod = true, 49 .lower_vector_cmp = true, 50 .lower_fdph = true, 51 .lower_insert_byte = true, 52 .lower_insert_word = true, 53 .lower_fdiv = true, /* !specs->has_new_transcendentals */ 54 .lower_fsign = !specs->has_sign_floor_ceil, 55 .lower_ffloor = !specs->has_sign_floor_ceil, 56 .lower_fceil = !specs->has_sign_floor_ceil, 57 .lower_fsqrt = !specs->has_sin_cos_sqrt, 58 .lower_sincos = !specs->has_sin_cos_sqrt, 59 .lower_uniforms_to_ubo = specs->halti >= 2, 60 .force_indirect_unrolling = nir_var_all, 61 .max_unroll_iterations = 32, 62 .vectorize_io = true, 63 }; 64 65 compiler->regs = etna_ra_setup(compiler); 66 if (!compiler->regs) { 67 ralloc_free((void *)compiler); 68 compiler = NULL; 69 } 70 71 etna_disk_cache_init(compiler, renderer); 72 73 return compiler; 74} 75 76void 77etna_compiler_destroy(const struct etna_compiler *compiler) 78{ 79 ralloc_free((void *)compiler); 80} 81 82const nir_shader_compiler_options * 83etna_compiler_get_options(struct etna_compiler *compiler) 84{ 85 return &compiler->options; 86} 87