On 02/25/2016 11:40 AM, Marek Olšák wrote:
On Thu, Feb 25, 2016 at 12:35 AM, Miklós Máté <mtm...@gmail.com> wrote:
v2: fix arithmetic for special opcodes,
fix fog state, cleanup
v3: simplify handling of special opcodes,
fix rebinding with different textargets or fog equation,
lots of formatting fixes
Signed-off-by: Miklós Máté <mtm...@gmail.com>
---
src/mesa/Makefile.sources | 1 +
src/mesa/main/atifragshader.h | 1 +
src/mesa/main/texstate.c | 18 +
src/mesa/main/texstate.h | 3 +
src/mesa/program/program.h | 2 +
src/mesa/state_tracker/st_atifs_to_tgsi.c | 726 ++++++++++++++++++++++++++++++
src/mesa/state_tracker/st_atifs_to_tgsi.h | 65 +++
src/mesa/state_tracker/st_atom_constbuf.c | 16 +
src/mesa/state_tracker/st_atom_shader.c | 27 +-
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 | 7 +
13 files changed, 930 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
[snip]
+ if (texinst->Opcode == ATI_FRAGMENT_SHADER_SAMPLE_OP) {
+ /* use the current texture target for the sample operation
+ * note: this implementation doesn't support re-using an ATI_fs
+ * with different texture targets
+ */
+ gl_texture_index index = _mesa_get_texture_target_index(t->ctx, r);
Please use value from the shader key here, not the context function.
+ unsigned target = translate_texture_target(index);
+
+ /* by default texture and sampler indexes are the same */
+ src[1] = t->samplers[r];
+ ureg_tex_insn(t->ureg, TGSI_OPCODE_TEX, dst, 1, target,
+ NULL, 0, src, 2);
+ } else if (texinst->Opcode == ATI_FRAGMENT_SHADER_PASS_OP) {
+ ureg_insn(t->ureg, TGSI_OPCODE_MOV, dst, 1, src, 1);
+ }
+
[snip]
+/**
+ * Called when a new variant is needed, we need to translate
+ * the ATI fragment shader to TGSI
+ */
+enum pipe_error
+st_translate_atifs_program(
+ struct gl_context *ctx,
+ struct ureg_program *ureg,
+ struct ati_fragment_shader *atifs,
+ struct gl_program *program,
+ GLuint numInputs,
+ const GLuint inputMapping[],
+ const ubyte inputSemanticName[],
+ const ubyte inputSemanticIndex[],
+ const GLuint interpMode[],
+ GLuint numOutputs,
+ const GLuint outputMapping[],
+ const ubyte outputSemanticName[],
+ const ubyte outputSemanticIndex[])
+{
+ enum pipe_error ret = PIPE_OK;
+
+ unsigned pass, i, r;
+
+ struct st_translate translate, *t;
+ t = &translate;
+ memset(t, 0, sizeof *t);
+
+ t->inputMapping = inputMapping;
+ t->outputMapping = outputMapping;
+ t->ureg = ureg;
+ t->ctx = ctx;
+ t->atifs = atifs;
+
+ /*
+ * Declare input attributes.
+ */
+ for (i = 0; i < numInputs; i++) {
+ t->inputs[i] = ureg_DECL_fs_input(ureg,
+ inputSemanticName[i],
+ inputSemanticIndex[i],
+ interpMode[i]);
+ }
+
+ /*
+ * Declare output attributes:
+ * we always have numOutputs=1 and it's FRAG_RESULT_COLOR
+ */
+ t->outputs[0] = ureg_DECL_output( ureg,
+ TGSI_SEMANTIC_COLOR,
+ outputSemanticIndex[0] );
+
+ /* Emit constants and immediates. Mesa uses a single index space
+ * for these, so we put all the translated regs in t->constants.
+ */
+ if (program->Parameters) {
+ t->constants = calloc( program->Parameters->NumParameters,
+ sizeof t->constants[0] );
+ if (t->constants == NULL) {
+ ret = PIPE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ for (i = 0; i < program->Parameters->NumParameters; i++) {
+ switch (program->Parameters->Parameters[i].Type) {
+ case PROGRAM_STATE_VAR:
+ case PROGRAM_UNIFORM:
+ t->constants[i] = ureg_DECL_constant( ureg, i );
+ break;
+
+ case PROGRAM_CONSTANT:
+ t->constants[i] =
+ ureg_DECL_immediate( ureg,
+ (const
float*)program->Parameters->ParameterValues[i],
+ 4 );
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ /* texture samplers */
+ for (i = 0; i <
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; i++) {
+ if (program->SamplersUsed & (1 << i)) {
+ t->samplers[i] = ureg_DECL_sampler( ureg, i );
+
+ /* fix texture targets that are not 2D * /
+ / * note: this implementation doesn't support re-using an ATI_fs
+ * with different texture targets
+ */
+ gl_texture_index index = _mesa_get_texture_target_index(ctx, i);
Same here - please use the shader key. Also, the comment above that
looks obsolete now.
Marek
I'd love to, but this is called from st_translate_fragment_program(),
which doesn't have the key.
Moreover, st_translate_fragment_program() is usually called from
st_program_string_notify(), where
there is no shader key at all.
The comment is indeed obsolete now, I now removed it.
MM
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev