1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2010 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "util/u_math.h" 29bf215546Sopenharmony_ci#include "util/u_memory.h" 30bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h" 31bf215546Sopenharmony_ci#include "pipe/p_screen.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include "draw_private.h" 34bf215546Sopenharmony_ci#include "draw_context.h" 35bf215546Sopenharmony_ci#include "draw_vs.h" 36bf215546Sopenharmony_ci#include "draw_llvm.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci#include "tgsi/tgsi_parse.h" 39bf215546Sopenharmony_ci#include "tgsi/tgsi_scan.h" 40bf215546Sopenharmony_ci#include "nir/nir_to_tgsi_info.h" 41bf215546Sopenharmony_ci#include "nir.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_cistatic void 44bf215546Sopenharmony_civs_llvm_prepare(struct draw_vertex_shader *shader, 45bf215546Sopenharmony_ci struct draw_context *draw) 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci /*struct llvm_vertex_shader *evs = llvm_vertex_shader(shader);*/ 48bf215546Sopenharmony_ci} 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cistatic void 51bf215546Sopenharmony_civs_llvm_run_linear( struct draw_vertex_shader *shader, 52bf215546Sopenharmony_ci const float (*input)[4], 53bf215546Sopenharmony_ci float (*output)[4], 54bf215546Sopenharmony_ci const void *constants[PIPE_MAX_CONSTANT_BUFFERS], 55bf215546Sopenharmony_ci const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS], 56bf215546Sopenharmony_ci unsigned count, 57bf215546Sopenharmony_ci unsigned input_stride, 58bf215546Sopenharmony_ci unsigned output_stride, 59bf215546Sopenharmony_ci const unsigned *elts) 60bf215546Sopenharmony_ci{ 61bf215546Sopenharmony_ci /* we should never get here since the entire pipeline is 62bf215546Sopenharmony_ci * generated in draw_pt_fetch_shade_pipeline_llvm.c */ 63bf215546Sopenharmony_ci assert(0); 64bf215546Sopenharmony_ci} 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_cistatic void 68bf215546Sopenharmony_civs_llvm_delete( struct draw_vertex_shader *dvs ) 69bf215546Sopenharmony_ci{ 70bf215546Sopenharmony_ci struct llvm_vertex_shader *shader = llvm_vertex_shader(dvs); 71bf215546Sopenharmony_ci struct draw_llvm_variant_list_item *li, *next; 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci LIST_FOR_EACH_ENTRY_SAFE(li, next, &shader->variants.list, list) { 74bf215546Sopenharmony_ci draw_llvm_destroy_variant(li->base); 75bf215546Sopenharmony_ci } 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci assert(shader->variants_cached == 0); 78bf215546Sopenharmony_ci if (dvs->state.ir.nir) 79bf215546Sopenharmony_ci ralloc_free(dvs->state.ir.nir); 80bf215546Sopenharmony_ci FREE((void*) dvs->state.tokens); 81bf215546Sopenharmony_ci FREE( dvs ); 82bf215546Sopenharmony_ci} 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_cistruct draw_vertex_shader * 86bf215546Sopenharmony_cidraw_create_vs_llvm(struct draw_context *draw, 87bf215546Sopenharmony_ci const struct pipe_shader_state *state) 88bf215546Sopenharmony_ci{ 89bf215546Sopenharmony_ci struct llvm_vertex_shader *vs = CALLOC_STRUCT( llvm_vertex_shader ); 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci if (!vs) 92bf215546Sopenharmony_ci return NULL; 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci if (state->type == PIPE_SHADER_IR_NIR) { 95bf215546Sopenharmony_ci vs->base.state.ir.nir = state->ir.nir; 96bf215546Sopenharmony_ci nir_shader *nir = (nir_shader *)state->ir.nir; 97bf215546Sopenharmony_ci if (!nir->options->lower_uniforms_to_ubo) 98bf215546Sopenharmony_ci NIR_PASS_V(state->ir.nir, nir_lower_uniforms_to_ubo, false, false); 99bf215546Sopenharmony_ci nir_tgsi_scan_shader(state->ir.nir, &vs->base.info, true); 100bf215546Sopenharmony_ci } else { 101bf215546Sopenharmony_ci /* we make a private copy of the tokens */ 102bf215546Sopenharmony_ci vs->base.state.tokens = tgsi_dup_tokens(state->tokens); 103bf215546Sopenharmony_ci if (!vs->base.state.tokens) { 104bf215546Sopenharmony_ci FREE(vs); 105bf215546Sopenharmony_ci return NULL; 106bf215546Sopenharmony_ci } 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci tgsi_scan_shader(state->tokens, &vs->base.info); 109bf215546Sopenharmony_ci } 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci vs->variant_key_size = 112bf215546Sopenharmony_ci draw_llvm_variant_key_size( 113bf215546Sopenharmony_ci vs->base.info.file_max[TGSI_FILE_INPUT]+1, 114bf215546Sopenharmony_ci vs->base.info.file_max[TGSI_FILE_SAMPLER]+1, 115bf215546Sopenharmony_ci vs->base.info.file_max[TGSI_FILE_SAMPLER_VIEW]+1, 116bf215546Sopenharmony_ci vs->base.info.file_max[TGSI_FILE_IMAGE]+1); 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci vs->base.state.type = state->type; 119bf215546Sopenharmony_ci vs->base.state.stream_output = state->stream_output; 120bf215546Sopenharmony_ci vs->base.draw = draw; 121bf215546Sopenharmony_ci vs->base.prepare = vs_llvm_prepare; 122bf215546Sopenharmony_ci vs->base.run_linear = vs_llvm_run_linear; 123bf215546Sopenharmony_ci vs->base.delete = vs_llvm_delete; 124bf215546Sopenharmony_ci vs->base.create_variant = draw_vs_create_variant_generic; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci list_inithead(&vs->variants.list); 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci return &vs->base; 129bf215546Sopenharmony_ci} 130