Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-25 Thread Marek Olšák
On Thu, Feb 25, 2016 at 4:18 PM, Miklós Máté  wrote:
> On 02/25/2016 11:40 AM, Marek Olšák wrote:
>>
>> On Thu, Feb 25, 2016 at 12:35 AM, Miklós Máté  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é 
>>> ---
>>>   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 = 
>>> +   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 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-25 Thread Brian Paul

On 02/25/2016 08:20 AM, Miklós Máté wrote:

On 02/25/2016 02:37 AM, Brian Paul wrote:



+   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);
+  unsigned target = translate_texture_target(index);


So, the result of compiling the shader happens to depend upon the
currently active texture for unit 'r'?  That seems funny/fragile.

I've never really looked too closely at ATI_fragment_shader so I don't
know.

Yes, the shader code doesn't supply the texture target, it has to be
deduced in the draw call, and a separate variant has to be created if
the shader is re-used with different texture targets. AFAICT the r200
driver avoids this by translating the shader on every draw call.


That would be good info to have in a comment somewhere, if it's not 
already stated somewhere else.


-Brian

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-25 Thread Miklós Máté

On 02/25/2016 02:37 AM, Brian Paul wrote:

I think this patch could be broken up a bit...
Yes, I agree that this is very long, but I couldn't decide on how to 
split it up.




On 02/24/2016 04:35 PM, Miklós Máté 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é 
---
  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

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index a6c12c6..54601a9 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -395,6 +395,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/main/atifragshader.h 
b/src/mesa/main/atifragshader.h

index 5901134..0e32795 100644
--- a/src/mesa/main/atifragshader.h
+++ b/src/mesa/main/atifragshader.h
@@ -16,6 +16,7 @@ struct gl_context;
  #define MAX_NUM_INSTRUCTIONS_PER_PASS_ATI 8
  #define MAX_NUM_PASSES_ATI2
  #define MAX_NUM_FRAGMENT_REGISTERS_ATI6
+#define MAX_NUM_FRAGMENT_CONSTANTS_ATI8

  struct ati_fs_opcode_st
  {
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 9ee5c69..1f7aa4a 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -57,6 +57,24 @@ static const struct gl_tex_env_combine_state 
default_combine_state = {

  };


+/**
+ * Return the the currently active target index of the given texture 
unit,

+ * fall back to 2D if nothing is current.
+ */
+gl_texture_index
+_mesa_get_texture_target_index(struct gl_context *ctx, const 
unsigned unit)

+{
+   struct gl_texture_object *texObj = _mesa_get_tex_unit(ctx, 
unit)->_Current;

+
+   if (texObj) {
+  return _mesa_tex_target_to_index(ctx, texObj->Target);
+   } else {
+  /* fallback for missing texture */
+  return TEXTURE_2D_INDEX;
+   }
+


Extraneous blank line.



+}
+

  /**
   * Used by glXCopyContext to copy texture state from one context to 
another.

diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
index 52fe602..f7100bf 100644
--- a/src/mesa/main/texstate.h
+++ b/src/mesa/main/texstate.h
@@ -63,6 +63,9 @@ _mesa_max_tex_unit(struct gl_context *ctx)
 ctx->Const.MaxTextureCoordUnits);
  }

+gl_texture_index
+_mesa_get_texture_target_index(struct gl_context *ctx, const 
unsigned unit);

+

  extern void
  _mesa_copy_texture_state( const struct gl_context *src, struct 
gl_context *dst );



Adding this new _mesa_get_texture_target_index() function could be a 
separate patch (if it's needed, see below).
OK, I'll put it into a separate patch. BTW is this function in the right 
place?






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:


That could be separate too.

OK.




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 000..6c2d2f2
--- /dev/null
+++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
@@ -0,0 +1,726 @@
+/*
+ * 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 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-25 Thread Miklós Máté

On 02/25/2016 11:40 AM, Marek Olšák wrote:

On Thu, Feb 25, 2016 at 12:35 AM, Miklós Máté  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é 
---
  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 = 
+   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 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-25 Thread Marek Olšák
On Thu, Feb 25, 2016 at 12:35 AM, Miklós Máté  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é 
> ---
>  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
>
> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
> index a6c12c6..54601a9 100644
> --- a/src/mesa/Makefile.sources
> +++ b/src/mesa/Makefile.sources
> @@ -395,6 +395,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/main/atifragshader.h b/src/mesa/main/atifragshader.h
> index 5901134..0e32795 100644
> --- a/src/mesa/main/atifragshader.h
> +++ b/src/mesa/main/atifragshader.h
> @@ -16,6 +16,7 @@ struct gl_context;
>  #define MAX_NUM_INSTRUCTIONS_PER_PASS_ATI 8
>  #define MAX_NUM_PASSES_ATI2
>  #define MAX_NUM_FRAGMENT_REGISTERS_ATI6
> +#define MAX_NUM_FRAGMENT_CONSTANTS_ATI8
>
>  struct ati_fs_opcode_st
>  {
> diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
> index 9ee5c69..1f7aa4a 100644
> --- a/src/mesa/main/texstate.c
> +++ b/src/mesa/main/texstate.c
> @@ -57,6 +57,24 @@ static const struct gl_tex_env_combine_state 
> default_combine_state = {
>  };
>
>
> +/**
> + * Return the the currently active target index of the given texture unit,
> + * fall back to 2D if nothing is current.
> + */
> +gl_texture_index
> +_mesa_get_texture_target_index(struct gl_context *ctx, const unsigned unit)
> +{
> +   struct gl_texture_object *texObj = _mesa_get_tex_unit(ctx, 
> unit)->_Current;
> +
> +   if (texObj) {
> +  return _mesa_tex_target_to_index(ctx, texObj->Target);
> +   } else {
> +  /* fallback for missing texture */
> +  return TEXTURE_2D_INDEX;
> +   }
> +
> +}
> +
>
>  /**
>   * Used by glXCopyContext to copy texture state from one context to another.
> diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
> index 52fe602..f7100bf 100644
> --- a/src/mesa/main/texstate.h
> +++ b/src/mesa/main/texstate.h
> @@ -63,6 +63,9 @@ _mesa_max_tex_unit(struct gl_context *ctx)
> ctx->Const.MaxTextureCoordUnits);
>  }
>
> +gl_texture_index
> +_mesa_get_texture_target_index(struct gl_context *ctx, const unsigned unit);
> +
>
>  extern void
>  _mesa_copy_texture_state( const struct gl_context *src, struct gl_context 
> *dst );
> 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 000..6c2d2f2
> --- /dev/null
> +++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
> @@ -0,0 +1,726 @@
> +/*
> + * 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", 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-24 Thread Brian Paul

I think this patch could be broken up a bit...

On 02/24/2016 04:35 PM, Miklós Máté 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é 
---
  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

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index a6c12c6..54601a9 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -395,6 +395,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/main/atifragshader.h b/src/mesa/main/atifragshader.h
index 5901134..0e32795 100644
--- a/src/mesa/main/atifragshader.h
+++ b/src/mesa/main/atifragshader.h
@@ -16,6 +16,7 @@ struct gl_context;
  #define MAX_NUM_INSTRUCTIONS_PER_PASS_ATI 8
  #define MAX_NUM_PASSES_ATI2
  #define MAX_NUM_FRAGMENT_REGISTERS_ATI6
+#define MAX_NUM_FRAGMENT_CONSTANTS_ATI8

  struct ati_fs_opcode_st
  {
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 9ee5c69..1f7aa4a 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -57,6 +57,24 @@ static const struct gl_tex_env_combine_state 
default_combine_state = {
  };


+/**
+ * Return the the currently active target index of the given texture unit,
+ * fall back to 2D if nothing is current.
+ */
+gl_texture_index
+_mesa_get_texture_target_index(struct gl_context *ctx, const unsigned unit)
+{
+   struct gl_texture_object *texObj = _mesa_get_tex_unit(ctx, unit)->_Current;
+
+   if (texObj) {
+  return _mesa_tex_target_to_index(ctx, texObj->Target);
+   } else {
+  /* fallback for missing texture */
+  return TEXTURE_2D_INDEX;
+   }
+


Extraneous blank line.



+}
+

  /**
   * Used by glXCopyContext to copy texture state from one context to another.
diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
index 52fe602..f7100bf 100644
--- a/src/mesa/main/texstate.h
+++ b/src/mesa/main/texstate.h
@@ -63,6 +63,9 @@ _mesa_max_tex_unit(struct gl_context *ctx)
 ctx->Const.MaxTextureCoordUnits);
  }

+gl_texture_index
+_mesa_get_texture_target_index(struct gl_context *ctx, const unsigned unit);
+

  extern void
  _mesa_copy_texture_state( const struct gl_context *src, struct gl_context 
*dst );



Adding this new _mesa_get_texture_target_index() function could be a 
separate patch (if it's needed, see below).




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:


That could be separate too.



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 000..6c2d2f2
--- /dev/null
+++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
@@ -0,0 +1,726 @@
+/*
+ * 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 

[Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-24 Thread Miklós Máté
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é 
---
 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

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index a6c12c6..54601a9 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -395,6 +395,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/main/atifragshader.h b/src/mesa/main/atifragshader.h
index 5901134..0e32795 100644
--- a/src/mesa/main/atifragshader.h
+++ b/src/mesa/main/atifragshader.h
@@ -16,6 +16,7 @@ struct gl_context;
 #define MAX_NUM_INSTRUCTIONS_PER_PASS_ATI 8
 #define MAX_NUM_PASSES_ATI2
 #define MAX_NUM_FRAGMENT_REGISTERS_ATI6
+#define MAX_NUM_FRAGMENT_CONSTANTS_ATI8
 
 struct ati_fs_opcode_st
 {
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 9ee5c69..1f7aa4a 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -57,6 +57,24 @@ static const struct gl_tex_env_combine_state 
default_combine_state = {
 };
 
 
+/**
+ * Return the the currently active target index of the given texture unit,
+ * fall back to 2D if nothing is current.
+ */
+gl_texture_index
+_mesa_get_texture_target_index(struct gl_context *ctx, const unsigned unit)
+{
+   struct gl_texture_object *texObj = _mesa_get_tex_unit(ctx, unit)->_Current;
+
+   if (texObj) {
+  return _mesa_tex_target_to_index(ctx, texObj->Target);
+   } else {
+  /* fallback for missing texture */
+  return TEXTURE_2D_INDEX;
+   }
+
+}
+
 
 /**
  * Used by glXCopyContext to copy texture state from one context to another.
diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
index 52fe602..f7100bf 100644
--- a/src/mesa/main/texstate.h
+++ b/src/mesa/main/texstate.h
@@ -63,6 +63,9 @@ _mesa_max_tex_unit(struct gl_context *ctx)
ctx->Const.MaxTextureCoordUnits);
 }
 
+gl_texture_index
+_mesa_get_texture_target_index(struct gl_context *ctx, const unsigned unit);
+
 
 extern void
 _mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst 
);
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 000..6c2d2f2
--- /dev/null
+++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
@@ -0,0 +1,726 @@
+/*
+ * 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, 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-08 Thread Marek Olšák
I see that the shader doesn't specify texture target types and they
must be obtained from the current GL states. That means texture
targets have to be properly listed in the shader key. The shader
compilation *must not* read any states from the current context. The
shader key is the only place from which the compilation can read
states.

Right now, if an ATI fragment shader is used with a different texture
target than it has been compiled for, the texturing won't work.

Marek

On Fri, Feb 5, 2016 at 10:11 PM, Miklós Máté  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 000..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 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-05 Thread Matt Turner
On Fri, Feb 5, 2016 at 1:11 PM, Miklós Máté  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 000..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[] = {

const

> +   {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, 

[Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-05 Thread Miklós Máté
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 000..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 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-05 Thread Ilia Mirkin
On Fri, Feb 5, 2016 at 4:11 PM, Miklós Máté  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 000..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, 

Re: [Mesa-dev] [PATCH 2/7] st/mesa: implement GL_ATI_fragment_shader

2016-02-05 Thread Ian Romanick
On 02/05/2016 01:11 PM, Miklós Máté 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 000..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,