On Fri, Feb 5, 2016 at 4:11 PM, Miklós Máté <[email protected]> wrote: > v2: fix arithmetic for special opcodes > (based on comments from Marek and Ilia), > fix fog state, cleanup > --- > src/mesa/Makefile.sources | 1 + > src/mesa/program/program.h | 2 + > src/mesa/state_tracker/st_atifs_to_tgsi.c | 734 > ++++++++++++++++++++++++++++++ > src/mesa/state_tracker/st_atifs_to_tgsi.h | 65 +++ > src/mesa/state_tracker/st_atom_constbuf.c | 14 + > src/mesa/state_tracker/st_atom_shader.c | 5 +- > src/mesa/state_tracker/st_cb_drawpixels.c | 1 + > src/mesa/state_tracker/st_cb_program.c | 36 +- > src/mesa/state_tracker/st_program.c | 30 +- > src/mesa/state_tracker/st_program.h | 4 + > 10 files changed, 889 insertions(+), 3 deletions(-) > create mode 100644 src/mesa/state_tracker/st_atifs_to_tgsi.c > create mode 100644 src/mesa/state_tracker/st_atifs_to_tgsi.h > > diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources > index ffe560f..23fe42a 100644 > --- a/src/mesa/Makefile.sources > +++ b/src/mesa/Makefile.sources > @@ -393,6 +393,7 @@ VBO_FILES = \ > vbo/vbo_split_inplace.c > > STATETRACKER_FILES = \ > + state_tracker/st_atifs_to_tgsi.c \ > state_tracker/st_atom_array.c \ > state_tracker/st_atom_atomicbuf.c \ > state_tracker/st_atom_blend.c \ > diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h > index 24e0597..09e6928 100644 > --- a/src/mesa/program/program.h > +++ b/src/mesa/program/program.h > @@ -172,6 +172,8 @@ _mesa_program_enum_to_shader_stage(GLenum v) > return MESA_SHADER_VERTEX; > case GL_FRAGMENT_PROGRAM_ARB: > return MESA_SHADER_FRAGMENT; > + case GL_FRAGMENT_SHADER_ATI: > + return MESA_SHADER_FRAGMENT; > case GL_GEOMETRY_PROGRAM_NV: > return MESA_SHADER_GEOMETRY; > case GL_TESS_CONTROL_PROGRAM_NV: > diff --git a/src/mesa/state_tracker/st_atifs_to_tgsi.c > b/src/mesa/state_tracker/st_atifs_to_tgsi.c > new file mode 100644 > index 0000000..fe303f6 > --- /dev/null > +++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c > @@ -0,0 +1,734 @@ > +/* > + * Copyright (C) 2016 Miklós Máté > + * > + * 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 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. > + */ > + > +#include "main/mtypes.h" > +#include "main/atifragshader.h" > +#include "main/texobj.h" > +#include "main/errors.h" > +#include "program/prog_parameter.h" > + > +#include "tgsi/tgsi_transform.h" > +#include "tgsi/tgsi_ureg.h" > +#include "util/u_math.h" > +#include "util/u_memory.h" > + > +#include "st_program.h" > +#include "st_atifs_to_tgsi.h" > + > +/** > + * Intermediate state used during shader translation. > + */ > +struct st_translate { > + struct ureg_program *ureg; > + struct gl_context *ctx; > + struct ati_fragment_shader *atifs; > + > + struct ureg_dst temps[MAX_PROGRAM_TEMPS]; > + struct ureg_src *constants; > + struct ureg_dst outputs[PIPE_MAX_SHADER_OUTPUTS]; > + struct ureg_src inputs[PIPE_MAX_SHADER_INPUTS]; > + struct ureg_src samplers[PIPE_MAX_SAMPLERS]; > + > + const GLuint *inputMapping; > + const GLuint *outputMapping; > + > + unsigned current_pass; > + > + bool regs_written[MAX_NUM_PASSES_ATI][MAX_NUM_FRAGMENT_REGISTERS_ATI]; > + > + boolean error; > +}; > + > +struct instruction_desc { > + unsigned TGSI_opcode; > + const char *name; > + unsigned char arg_count; > + unsigned char special; /* no 1:1 corresponding TGSI instruction */ > +}; > + > +static struct instruction_desc inst_desc[] = { > + {TGSI_OPCODE_MOV, "MOV", 1, 0}, > + {TGSI_OPCODE_NOP, "UND", 0, 0}, /* unused */ > + {TGSI_OPCODE_ADD, "ADD", 2, 0}, > + {TGSI_OPCODE_MUL, "MUL", 2, 0}, > + {TGSI_OPCODE_SUB, "SUB", 2, 0}, > + {TGSI_OPCODE_DP3, "DOT3", 2, 0}, > + {TGSI_OPCODE_DP4, "DOT4", 2, 0}, > + {TGSI_OPCODE_MAD, "MAD", 3, 0}, > + {TGSI_OPCODE_LRP, "LERP", 3, 0}, > + {TGSI_OPCODE_NOP, "CND", 3, 1}, > + {TGSI_OPCODE_NOP, "CND0", 3, 2}, > + {TGSI_OPCODE_NOP, "DOT2_ADD", 3, 3} > +}; > + > +static struct ureg_dst get_temp(struct st_translate *t, unsigned index) > +{ > + if (ureg_dst_is_undef(t->temps[index])) > + t->temps[index] = ureg_DECL_temporary(t->ureg); > + return t->temps[index]; > +} > + > +static struct ureg_src apply_swizzle(struct st_translate *t, > + struct ureg_src src, GLuint swizzle) > +{ > + if (swizzle == GL_SWIZZLE_STR_ATI) { > + return src; > + } else if (swizzle == GL_SWIZZLE_STQ_ATI) { > + return ureg_swizzle(src, > + TGSI_SWIZZLE_X, TGSI_SWIZZLE_Y, TGSI_SWIZZLE_W, TGSI_SWIZZLE_Z); > + } else { > + struct ureg_dst tmp[2]; > + struct ureg_src imm[3]; > + > + tmp[0] = get_temp(t, MAX_NUM_FRAGMENT_REGISTERS_ATI); > + tmp[1] = get_temp(t, MAX_NUM_FRAGMENT_REGISTERS_ATI+1); > + imm[0] = src; > + imm[1] = ureg_imm4f(t->ureg, 1.0, 1.0, 0.0, 0.0); > + imm[2] = ureg_imm4f(t->ureg, 0.0, 0.0, 1.0, 1.0); > + ureg_insn(t->ureg, TGSI_OPCODE_MAD, &tmp[0], 1, imm, 3); > + > + if (swizzle == GL_SWIZZLE_STR_DR_ATI) > + imm[0] = ureg_swizzle(src, > + TGSI_SWIZZLE_Z, TGSI_SWIZZLE_Z, TGSI_SWIZZLE_Z, > TGSI_SWIZZLE_Z);
Both here and elsewhere, you may find it more compact to write ureg_scalar(src, TGSI_SWIZZLE_Z); _______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
