From 770cebbc29863ae944a31463ee4bdeb789105aba Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 20 Jul 2009 17:44:36 -0700 Subject: ARB_fp/vp: Initial import of new ARB vp/fp assembler This still needs quite a bit of work, but a bunch of the programs in progs/vp produce correct results. --- src/mesa/shader/prog_parameter_layout.c | 205 ++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 src/mesa/shader/prog_parameter_layout.c (limited to 'src/mesa/shader/prog_parameter_layout.c') diff --git a/src/mesa/shader/prog_parameter_layout.c b/src/mesa/shader/prog_parameter_layout.c new file mode 100644 index 0000000000..f374636f11 --- /dev/null +++ b/src/mesa/shader/prog_parameter_layout.c @@ -0,0 +1,205 @@ +/* + * Copyright © 2009 Intel Corporation + * + * 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, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +/** + * \file prog_parameter_layout.c + * \brief Helper functions to layout storage for program parameters + * + * \author Ian Romanick + */ + +#include "main/mtypes.h" +#include "prog_parameter.h" +#include "prog_parameter_layout.h" +#include "prog_instruction.h" +#include "program_parser.h" + +unsigned +_mesa_combine_swizzles(unsigned base, unsigned applied) +{ + unsigned swiz = 0; + unsigned i; + + for (i = 0; i < 4; i++) { + const unsigned s = GET_SWZ(applied, i); + + swiz |= ((s <= SWIZZLE_W) ? GET_SWZ(base, s) : s) << (i * 3); + } + + return swiz; +} + + +/** + * Copy indirect access array from one parameter list to another + * + * \param src Parameter array copied from + * \param dst Parameter array copied to + * \param first Index of first element in \c src to copy + * \param count Number of elements to copy + * + * \return + * The location in \c dst of the first element copied from \c src on + * success. -1 on failure. + * + * \warning + * This function assumes that there is already enough space available in + * \c dst to hold all of the elements that will be copied over. + */ +static int +copy_indirect_accessed_array(struct gl_program_parameter_list *src, + struct gl_program_parameter_list *dst, + unsigned first, unsigned count) +{ + const int base = dst->NumParameters; + unsigned i; + unsigned j; + + + for (i = first; i < (first + count); i++) { + struct gl_program_parameter *curr = & src->Parameters[i]; + + + if (curr->Type == PROGRAM_CONSTANT) { + j = dst->NumParameters; + } else { + for (j = 0; j < dst->NumParameters; j++) { + if (memcmp(dst->Parameters[j].StateIndexes, curr->StateIndexes, + sizeof(curr->StateIndexes)) == 0) { + return -1; + } + } + } + + assert(j == dst->NumParameters); + + memcpy(& dst->Parameters[j], curr, + sizeof(dst->Parameters[j])); + memcpy(dst->ParameterValues[j], src->ParameterValues[i], + sizeof(GLfloat) * 4); + curr->Name = NULL; + + dst->NumParameters++; + } + + return base; +} + + +int +_mesa_layout_parameters(struct asm_parser_state *state) +{ + struct gl_program_parameter_list *layout; + struct asm_instruction *inst; + unsigned i; + + + layout = + _mesa_new_parameter_list_sized(state->prog->Parameters->NumParameters); + + + /* PASS 1: Move any parameters that are accessed indirectly from the + * original parameter list to the new parameter list. + */ + for (inst = state->inst_head; inst != NULL; inst = inst->next) { + for (i = 0; i < 3; i++) { + if (inst->SrcReg[i].Base.RelAddr) { + /* Only attempt to add the to the new parameter list once. + */ + if (!inst->SrcReg[i].Symbol->pass1_done) { + const int new_begin = + copy_indirect_accessed_array(state->prog->Parameters, layout, + inst->SrcReg[i].Symbol->param_binding_begin, + inst->SrcReg[i].Symbol->param_binding_length); + + if (new_begin < 0) { + return 0; + } + + inst->SrcReg[i].Symbol->param_binding_begin = new_begin; + inst->SrcReg[i].Symbol->pass1_done = 1; + } + + /* Previously the Index was just the offset from the parameter + * array. Now that the base of the parameter array is known, the + * index can be updated to its actual value. + */ + inst->Base.SrcReg[i] = inst->SrcReg[i].Base; + inst->Base.SrcReg[i].Index += + inst->SrcReg[i].Symbol->param_binding_begin; + } + } + } + + + /* PASS 2: Move any parameters that are not accessed indirectly from the + * original parameter list to the new parameter list. + */ + for (inst = state->inst_head; inst != NULL; inst = inst->next) { + for (i = 0; i < 3; i++) { + const struct gl_program_parameter *p; + const int idx = inst->SrcReg[i].Base.Index; + unsigned swizzle = SWIZZLE_NOOP; + + + /* All relative addressed operands were processed on the first + * pass. Just skip them here. + */ + if (inst->SrcReg[i].Base.RelAddr) { + continue; + } + + + inst->Base.SrcReg[i] = inst->SrcReg[i].Base; + p = & state->prog->Parameters->Parameters[idx]; + + switch (inst->SrcReg[i].Base.File) { + case PROGRAM_CONSTANT: { + const float *const v = + state->prog->Parameters->ParameterValues[idx]; + + inst->Base.SrcReg[i].Index = + _mesa_add_unnamed_constant(layout, v, p->Size, & swizzle); + + inst->Base.SrcReg[i].Swizzle = + _mesa_combine_swizzles(inst->Base.SrcReg[i].Swizzle, swizzle); + break; + } + + case PROGRAM_STATE_VAR: + inst->Base.SrcReg[i].Index = + _mesa_add_state_reference(layout, p->StateIndexes); + break; + + default: + break; + } + } + } + + + _mesa_free_parameter_list(state->prog->Parameters); + state->prog->Parameters = layout; + + return 1; +} -- cgit v1.2.3 From 258f640edab9ca9e71ee255ebe5ddae4b9d0d871 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 24 Jul 2009 18:14:47 -0700 Subject: ARB prog: Layout parameters from parameter type, not src type Use the type stored in the Parameters array to determine the layout instead of the type in the instruction register field. Also, update the instruction register field based on the parameter type. This makes Google Earth work exactly like with Mesa master. --- src/mesa/shader/prog_parameter_layout.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/mesa/shader/prog_parameter_layout.c') diff --git a/src/mesa/shader/prog_parameter_layout.c b/src/mesa/shader/prog_parameter_layout.c index f374636f11..4d67eca902 100644 --- a/src/mesa/shader/prog_parameter_layout.c +++ b/src/mesa/shader/prog_parameter_layout.c @@ -170,10 +170,15 @@ _mesa_layout_parameters(struct asm_parser_state *state) } + if ((inst->SrcReg[i].Base.File <= PROGRAM_VARYING ) + || (inst->SrcReg[i].Base.File >= PROGRAM_WRITE_ONLY)) { + continue; + } + inst->Base.SrcReg[i] = inst->SrcReg[i].Base; p = & state->prog->Parameters->Parameters[idx]; - switch (inst->SrcReg[i].Base.File) { + switch (p->Type) { case PROGRAM_CONSTANT: { const float *const v = state->prog->Parameters->ParameterValues[idx]; @@ -194,6 +199,9 @@ _mesa_layout_parameters(struct asm_parser_state *state) default: break; } + + inst->SrcReg[i].Base.File = p->Type; + inst->Base.SrcReg[i].File = p->Type; } } -- cgit v1.2.3 From e511633985ebdb423d1addefa1267a03a76da33b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 29 Jul 2009 20:07:59 -0700 Subject: ARB prog: Fix the order of swizzle application The swizzle used to generate the "original" value from the value stored in the parameter array happens before the swizzle specified in the instruction. This fixes problems seen in progs/vp/vp-tris with arl-*.txt. --- src/mesa/shader/prog_parameter_layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/shader/prog_parameter_layout.c') diff --git a/src/mesa/shader/prog_parameter_layout.c b/src/mesa/shader/prog_parameter_layout.c index 4d67eca902..8f2b306220 100644 --- a/src/mesa/shader/prog_parameter_layout.c +++ b/src/mesa/shader/prog_parameter_layout.c @@ -187,7 +187,7 @@ _mesa_layout_parameters(struct asm_parser_state *state) _mesa_add_unnamed_constant(layout, v, p->Size, & swizzle); inst->Base.SrcReg[i].Swizzle = - _mesa_combine_swizzles(inst->Base.SrcReg[i].Swizzle, swizzle); + _mesa_combine_swizzles(swizzle, inst->Base.SrcReg[i].Swizzle); break; } -- cgit v1.2.3 From 53db19b57d41a5e6beea5cb5dff4f7f638ca7b50 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 24 Aug 2009 10:50:07 -0600 Subject: mesa: _mesa_layout_parameters() returns a boolean value --- src/mesa/shader/prog_parameter_layout.c | 12 ++++++++---- src/mesa/shader/prog_parameter_layout.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/mesa/shader/prog_parameter_layout.c') diff --git a/src/mesa/shader/prog_parameter_layout.c b/src/mesa/shader/prog_parameter_layout.c index 8f2b306220..1c37b3a7a5 100644 --- a/src/mesa/shader/prog_parameter_layout.c +++ b/src/mesa/shader/prog_parameter_layout.c @@ -106,7 +106,11 @@ copy_indirect_accessed_array(struct gl_program_parameter_list *src, } -int +/** + * XXX description??? + * \return GL_TRUE for success, GL_FALSE for failure + */ +GLboolean _mesa_layout_parameters(struct asm_parser_state *state) { struct gl_program_parameter_list *layout; @@ -128,12 +132,12 @@ _mesa_layout_parameters(struct asm_parser_state *state) */ if (!inst->SrcReg[i].Symbol->pass1_done) { const int new_begin = - copy_indirect_accessed_array(state->prog->Parameters, layout, + copy_indirect_accessed_array(state->prog->Parameters, layout, inst->SrcReg[i].Symbol->param_binding_begin, inst->SrcReg[i].Symbol->param_binding_length); if (new_begin < 0) { - return 0; + return GL_FALSE; } inst->SrcReg[i].Symbol->param_binding_begin = new_begin; @@ -209,5 +213,5 @@ _mesa_layout_parameters(struct asm_parser_state *state) _mesa_free_parameter_list(state->prog->Parameters); state->prog->Parameters = layout; - return 1; + return GL_TRUE; } diff --git a/src/mesa/shader/prog_parameter_layout.h b/src/mesa/shader/prog_parameter_layout.h index 1686170bab..99a7b6c726 100644 --- a/src/mesa/shader/prog_parameter_layout.h +++ b/src/mesa/shader/prog_parameter_layout.h @@ -36,6 +36,7 @@ extern unsigned _mesa_combine_swizzles(unsigned base, unsigned applied); struct asm_parser_state; -extern int _mesa_layout_parameters(struct asm_parser_state *state); + +extern GLboolean _mesa_layout_parameters(struct asm_parser_state *state); #endif /* PROG_PARAMETER_LAYOUT_H */ -- cgit v1.2.3