The code to create and add the list of tgsi instructions is now in lp_bld_tgsi.c. --- src/gallium/auxiliary/Makefile.sources | 1 + src/gallium/auxiliary/gallivm/lp_bld_tgsi.c | 71 +++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 19 +++++- src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c | 36 ++---------- src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 37 ++---------- 5 files changed, 99 insertions(+), 65 deletions(-) create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_tgsi.c
diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources index d40b954..eb4f2d5 100644 --- a/src/gallium/auxiliary/Makefile.sources +++ b/src/gallium/auxiliary/Makefile.sources @@ -175,6 +175,7 @@ GALLIVM_SOURCES := \ gallivm/lp_bld_sample_soa.c \ gallivm/lp_bld_struct.c \ gallivm/lp_bld_swizzle.c \ + gallivm/lp_bld_tgsi.c \ gallivm/lp_bld_tgsi_aos.c \ gallivm/lp_bld_tgsi_info.c \ gallivm/lp_bld_tgsi_soa.c \ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c new file mode 100644 index 0000000..5a7c5ac --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.c @@ -0,0 +1,71 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * Copyright 2009 VMware, Inc. + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "gallivm/lp_bld_tgsi.h" +#include "tgsi/tgsi_parse.h" +#include "util/u_memory.h" + +/* The user is responsible for freeing list->instructions */ +unsigned lp_bld_tgsi_list_init(struct lp_build_tgsi_inst_list * list) +{ + list->instructions = (struct tgsi_full_instruction *) + MALLOC( LP_MAX_INSTRUCTIONS * sizeof(struct tgsi_full_instruction) ); + if (!list->instructions) { + return 0; + } + list->max_instructions = LP_MAX_INSTRUCTIONS; + return 1; +} + + +unsigned lp_bld_tgsi_add_instruction( + struct lp_build_tgsi_inst_list * list, + struct tgsi_full_instruction *inst_to_add) +{ + + if (list->num_instructions == list->max_instructions) { + struct tgsi_full_instruction *instructions; + instructions = REALLOC(list->instructions, list->max_instructions + * sizeof(struct tgsi_full_instruction), + (list->max_instructions + LP_MAX_INSTRUCTIONS) + * sizeof(struct tgsi_full_instruction)); + if (!instructions) { + return 0; + } + list->instructions = instructions; + list->max_instructions += LP_MAX_INSTRUCTIONS; + } + memcpy(list->instructions + list->num_instructions, inst_to_add, + sizeof(list->instructions[0])); + + list->num_instructions++; + + return 1; +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index e8b73e5..ec366ca 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -253,6 +253,19 @@ struct lp_exec_mask { LLVMValueRef exec_mask; }; +struct lp_build_tgsi_inst_list +{ + struct tgsi_full_instruction *instructions; + uint max_instructions; + uint num_instructions; +}; + +unsigned lp_bld_tgsi_list_init(struct lp_build_tgsi_inst_list * list); + + +unsigned lp_bld_tgsi_add_instruction( + struct lp_build_tgsi_inst_list * list, + struct tgsi_full_instruction *inst_to_add); struct lp_build_tgsi_soa_context { @@ -303,8 +316,7 @@ struct lp_build_tgsi_soa_context struct lp_build_mask_context *mask; struct lp_exec_mask exec_mask; - struct tgsi_full_instruction *instructions; - uint max_instructions; + struct lp_build_tgsi_inst_list inst_list; /* Allow the user to store data in this structure rather than passing it * to every function. */ @@ -390,8 +402,7 @@ struct lp_build_tgsi_aos_context /** bitmask indicating which register files are accessed indirectly */ unsigned indirect_files; - struct tgsi_full_instruction *instructions; - uint max_instructions; + struct lp_build_tgsi_inst_list inst_list; /* Allow the user to store data in this structure rather than passing it * to every function. */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c index bf623ca..5f88eca 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c @@ -1016,7 +1016,6 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm, struct lp_build_tgsi_aos_context bld; struct tgsi_parse_context parse; uint num_immediates = 0; - uint num_instructions = 0; unsigned chan; int pc = 0; @@ -1036,12 +1035,9 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm, bld.sampler = sampler; bld.indirect_files = info->indirect_files; bld.emit_fetch_switch_file_fn = emit_fetch_switch_file; - bld.instructions = (struct tgsi_full_instruction *) - MALLOC(LP_MAX_INSTRUCTIONS * sizeof(struct tgsi_full_instruction)); - bld.max_instructions = LP_MAX_INSTRUCTIONS; bld.emit_swizzle = swizzle_aos; - if (!bld.instructions) { + if (!lp_bld_tgsi_list_init(&bld.inst_list)) { return; } @@ -1057,29 +1053,9 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm, break; case TGSI_TOKEN_TYPE_INSTRUCTION: - { - /* save expanded instruction */ - if (num_instructions == bld.max_instructions) { - struct tgsi_full_instruction *instructions; - instructions = REALLOC(bld.instructions, - bld.max_instructions - * sizeof(struct tgsi_full_instruction), - (bld.max_instructions + LP_MAX_INSTRUCTIONS) - * sizeof(struct tgsi_full_instruction)); - if (!instructions) { - break; - } - bld.instructions = instructions; - bld.max_instructions += LP_MAX_INSTRUCTIONS; - } - - memcpy(bld.instructions + num_instructions, - &parse.FullToken.FullInstruction, - sizeof(bld.instructions[0])); - - num_instructions++; - } - + /* save expanded instruction */ + lp_bld_tgsi_add_instruction(&bld.inst_list, + &parse.FullToken.FullInstruction); break; case TGSI_TOKEN_TYPE_IMMEDIATE: @@ -1113,7 +1089,7 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm, } while (pc != -1) { - struct tgsi_full_instruction *instr = bld.instructions + pc; + struct tgsi_full_instruction *instr = bld.inst_list.instructions + pc; const struct tgsi_opcode_info *opcode_info = tgsi_get_opcode_info(instr->Instruction.Opcode); if (!lp_emit_instruction_aos(&bld, instr, opcode_info, &pc)) @@ -1137,6 +1113,6 @@ lp_build_tgsi_aos(struct gallivm_state *gallivm, LLVMDumpModule(module); } - FREE(bld.instructions); + FREE(bld.inst_list.instructions); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index f504fed..93968e7 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -1080,7 +1080,7 @@ near_end_of_shader(struct lp_build_tgsi_soa_context *bld, if (pc + i >= bld->info->num_instructions) return TRUE; - opcode = bld->instructions[pc + i].Instruction.Opcode; + opcode = bld->inst_list.instructions[pc + i].Instruction.Opcode; if (opcode == TGSI_OPCODE_END) return TRUE; @@ -2266,7 +2266,6 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, struct lp_build_tgsi_soa_context bld; struct tgsi_parse_context parse; uint num_immediates = 0; - uint num_instructions = 0; unsigned i; int pc = 0; @@ -2292,11 +2291,8 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, bld.info = info; bld.indirect_files = info->indirect_files; bld.emit_fetch_switch_file_fn = emit_fetch_switch_file; - bld.instructions = (struct tgsi_full_instruction *) - MALLOC( LP_MAX_INSTRUCTIONS * sizeof(struct tgsi_full_instruction) ); - bld.max_instructions = LP_MAX_INSTRUCTIONS; - if (!bld.instructions) { + if (!lp_bld_tgsi_list_init(&bld.inst_list)) { return; } @@ -2361,29 +2357,8 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, break; case TGSI_TOKEN_TYPE_INSTRUCTION: - { - /* save expanded instruction */ - if (num_instructions == bld.max_instructions) { - struct tgsi_full_instruction *instructions; - instructions = REALLOC(bld.instructions, - bld.max_instructions - * sizeof(struct tgsi_full_instruction), - (bld.max_instructions + LP_MAX_INSTRUCTIONS) - * sizeof(struct tgsi_full_instruction)); - if (!instructions) { - break; - } - bld.instructions = instructions; - bld.max_instructions += LP_MAX_INSTRUCTIONS; - } - - memcpy(bld.instructions + num_instructions, - &parse.FullToken.FullInstruction, - sizeof(bld.instructions[0])); - - num_instructions++; - } - + lp_bld_tgsi_add_instruction(&bld.inst_list, + &parse.FullToken.FullInstruction); break; case TGSI_TOKEN_TYPE_IMMEDIATE: @@ -2410,7 +2385,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, } while (pc != -1) { - struct tgsi_full_instruction *instr = bld.instructions + pc; + struct tgsi_full_instruction *instr = bld.inst_list.instructions + pc; const struct tgsi_opcode_info *opcode_info = tgsi_get_opcode_info(instr->Instruction.Opcode); if (!lp_emit_instruction_soa( &bld, instr, opcode_info, &pc )) @@ -2447,7 +2422,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, } - FREE( bld.instructions ); + FREE( bld.inst_list.instructions ); } -- 1.7.6.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev