vc4: Use Newton-Raphson on the 1/W write to fix glmark2 terrain.
[mesa.git] / src / mesa / state_tracker / st_program.c
index 7a4ac26066b87f27005bf9540845b4e8148f154a..0822509c4e582585e5306400361bb41d6389a368 100644 (file)
@@ -250,11 +250,12 @@ st_translate_vertex_program(struct st_context *st,
     * and TGSI generic input indexes, plus input attrib semantic info.
     */
    for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
-      if ((stvp->Base.InputsRead & BITFIELD64_BIT(attr)) != 0) {
+      if ((stvp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
          input_to_index[attr] = stvp->num_inputs;
          stvp->index_to_input[stvp->num_inputs] = attr;
          stvp->num_inputs++;
-         if ((stvp->Base.DoubleInputsRead & BITFIELD64_BIT(attr)) != 0) {
+         if ((stvp->Base.info.double_inputs_read &
+              BITFIELD64_BIT(attr)) != 0) {
             /* add placeholder for second part of a double attribute */
             stvp->index_to_input[stvp->num_inputs] = ST_DOUBLE_ATTRIB_PLACEHOLDER;
             stvp->num_inputs++;
@@ -268,7 +269,7 @@ st_translate_vertex_program(struct st_context *st,
    /* Compute mapping of vertex program outputs to slots.
     */
    for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
-      if ((stvp->Base.OutputsWritten & BITFIELD64_BIT(attr)) == 0) {
+      if ((stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) == 0) {
          stvp->result_to_output[attr] = ~0;
       }
       else {
@@ -586,9 +587,9 @@ st_translate_fragment_program(struct st_context *st,
 
    /* Non-GLSL programs: */
    if (!stfp->glsl_to_tgsi && !stfp->shader_program) {
-      _mesa_remove_output_reads(&stfp->Base.Base, PROGRAM_OUTPUT);
+      _mesa_remove_output_reads(&stfp->Base, PROGRAM_OUTPUT);
       if (st->ctx->Const.GLSLFragCoordIsSysVal)
-         _mesa_program_fragment_position_to_sysval(&stfp->Base.Base);
+         _mesa_program_fragment_position_to_sysval(&stfp->Base);
 
       /* This determines which states will be updated when the assembly
        * shader is bound.
@@ -605,7 +606,7 @@ st_translate_fragment_program(struct st_context *st,
                                   ST_NEW_RENDER_SAMPLERS;
       } else {
          /* ARB_fp */
-         if (stfp->Base.Base.SamplersUsed)
+         if (stfp->Base.SamplersUsed)
             stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
                                      ST_NEW_RENDER_SAMPLERS;
       }
@@ -614,7 +615,7 @@ st_translate_fragment_program(struct st_context *st,
    /*
     * Convert Mesa program inputs to TGSI input register semantics.
     */
-   inputsRead = stfp->Base.Base.InputsRead;
+   inputsRead = stfp->Base.info.inputs_read;
    for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
       if ((inputsRead & BITFIELD64_BIT(attr)) != 0) {
          const GLuint slot = fs_num_inputs++;
@@ -753,7 +754,7 @@ st_translate_fragment_program(struct st_context *st,
     * Semantics and mapping for outputs
     */
    {
-      GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
+      GLbitfield64 outputsWritten = stfp->Base.info.outputs_written;
 
       /* if z is written, emit that first */
       if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
@@ -783,7 +784,7 @@ st_translate_fragment_program(struct st_context *st,
       /* handle remaining outputs (color) */
       for (attr = 0; attr < ARRAY_SIZE(outputMapping); attr++) {
          const GLbitfield64 written = attr < FRAG_RESULT_MAX ? outputsWritten :
-            stfp->Base.Base.SecondaryOutputsWritten;
+            stfp->Base.SecondaryOutputsWritten;
          const unsigned loc = attr % FRAG_RESULT_MAX;
 
          if (written & BITFIELD64_BIT(loc)) {
@@ -822,8 +823,7 @@ st_translate_fragment_program(struct st_context *st,
    }
 
    if (stfp->shader_program) {
-      nir_shader *nir = st_glsl_to_nir(st, &stfp->Base.Base,
-                                       stfp->shader_program,
+      nir_shader *nir = st_glsl_to_nir(st, &stfp->Base, stfp->shader_program,
                                        MESA_SHADER_FRAGMENT);
 
       stfp->tgsi.type = PIPE_SHADER_IR_NIR;
@@ -837,15 +837,15 @@ st_translate_fragment_program(struct st_context *st,
       return false;
 
    if (ST_DEBUG & DEBUG_MESA) {
-      _mesa_print_program(&stfp->Base.Base);
-      _mesa_print_program_parameters(st->ctx, &stfp->Base.Base);
+      _mesa_print_program(&stfp->Base);
+      _mesa_print_program_parameters(st->ctx, &stfp->Base);
       debug_printf("\n");
    }
    if (write_all == GL_TRUE)
       ureg_property(ureg, TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS, 1);
 
-   if (stfp->Base.FragDepthLayout != FRAG_DEPTH_LAYOUT_NONE) {
-      switch (stfp->Base.FragDepthLayout) {
+   if (stfp->Base.info.fs.depth_layout != FRAG_DEPTH_LAYOUT_NONE) {
+      switch (stfp->Base.info.fs.depth_layout) {
       case FRAG_DEPTH_LAYOUT_ANY:
          ureg_property(ureg, TGSI_PROPERTY_FS_DEPTH_LAYOUT,
                        TGSI_FS_DEPTH_LAYOUT_ANY);
@@ -872,7 +872,7 @@ st_translate_fragment_program(struct st_context *st,
                            PIPE_SHADER_FRAGMENT,
                            ureg,
                            stfp->glsl_to_tgsi,
-                           &stfp->Base.Base,
+                           &stfp->Base,
                            /* inputs */
                            fs_num_inputs,
                            inputMapping,
@@ -892,7 +892,7 @@ st_translate_fragment_program(struct st_context *st,
    } else if (stfp->ati_fs)
       st_translate_atifs_program(ureg,
                                  stfp->ati_fs,
-                                 &stfp->Base.Base,
+                                 &stfp->Base,
                                  /* inputs */
                                  fs_num_inputs,
                                  inputMapping,
@@ -908,7 +908,7 @@ st_translate_fragment_program(struct st_context *st,
       st_translate_mesa_program(st->ctx,
                                 PIPE_SHADER_FRAGMENT,
                                 ureg,
-                                &stfp->Base.Base,
+                                &stfp->Base,
                                 /* inputs */
                                 fs_num_inputs,
                                 inputMapping,
@@ -934,7 +934,7 @@ st_create_fp_variant(struct st_context *st,
    struct pipe_context *pipe = st->pipe;
    struct st_fp_variant *variant = CALLOC_STRUCT(st_fp_variant);
    struct pipe_shader_state tgsi = {0};
-   struct gl_program_parameter_list *params = stfp->Base.Base.Parameters;
+   struct gl_program_parameter_list *params = stfp->Base.Parameters;
    static const gl_state_index texcoord_state[STATE_LENGTH] =
       { STATE_INTERNAL, STATE_CURRENT_ATTRIB, VERT_ATTRIB_TEX0 };
    static const gl_state_index scale_state[STATE_LENGTH] =
@@ -964,7 +964,7 @@ st_create_fp_variant(struct st_context *st,
       if (key->bitmap) {
          nir_lower_bitmap_options options = {0};
 
-         variant->bitmap_sampler = ffs(~stfp->Base.Base.SamplersUsed) - 1;
+         variant->bitmap_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
          options.sampler = variant->bitmap_sampler;
          options.swizzle_xxxx = (st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM);
 
@@ -974,7 +974,7 @@ st_create_fp_variant(struct st_context *st,
       /* glDrawPixels (color only) */
       if (key->drawpixels) {
          nir_lower_drawpixels_options options = {{0}};
-         unsigned samplers_used = stfp->Base.Base.SamplersUsed;
+         unsigned samplers_used = stfp->Base.SamplersUsed;
 
          /* Find the first unused slot. */
          variant->drawpix_sampler = ffs(~samplers_used) - 1;
@@ -1011,12 +1011,12 @@ st_create_fp_variant(struct st_context *st,
          NIR_PASS_V(tgsi.ir.nir, nir_lower_tex, &options);
       }
 
-      st_finalize_nir(st, &stfp->Base.Base, tgsi.ir.nir);
+      st_finalize_nir(st, &stfp->Base, tgsi.ir.nir);
 
       if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
          /* This pass needs to happen *after* nir_lower_sampler */
          NIR_PASS_V(tgsi.ir.nir, st_nir_lower_tex_src_plane,
-                    ~stfp->Base.Base.SamplersUsed,
+                    ~stfp->Base.SamplersUsed,
                     key->external.lower_nv12,
                     key->external.lower_iyuv);
       }
@@ -1062,7 +1062,7 @@ st_create_fp_variant(struct st_context *st,
    if (key->bitmap) {
       const struct tgsi_token *tokens;
 
-      variant->bitmap_sampler = ffs(~stfp->Base.Base.SamplersUsed) - 1;
+      variant->bitmap_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
 
       tokens = st_get_bitmap_shader(tgsi.tokens,
                                     st->internal_target,
@@ -1085,10 +1085,10 @@ st_create_fp_variant(struct st_context *st,
       unsigned scale_const = 0, bias_const = 0, texcoord_const = 0;
 
       /* Find the first unused slot. */
-      variant->drawpix_sampler = ffs(~stfp->Base.Base.SamplersUsed) - 1;
+      variant->drawpix_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
 
       if (key->pixelMaps) {
-         unsigned samplers_used = stfp->Base.Base.SamplersUsed |
+         unsigned samplers_used = stfp->Base.SamplersUsed |
                                   (1 << variant->drawpix_sampler);
 
          variant->pixelmap_sampler = ffs(~samplers_used) - 1;
@@ -1124,7 +1124,7 @@ st_create_fp_variant(struct st_context *st,
       assert(!(key->bitmap || key->drawpixels));
 
       tokens = st_tgsi_lower_yuv(tgsi.tokens,
-                                 ~stfp->Base.Base.SamplersUsed,
+                                 ~stfp->Base.SamplersUsed,
                                  key->external.lower_nv12,
                                  key->external.lower_iyuv);
       if (tokens) {
@@ -1226,7 +1226,7 @@ st_translate_program_common(struct st_context *st,
     * Convert Mesa program inputs to TGSI input register semantics.
     */
    for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
-      if ((prog->InputsRead & BITFIELD64_BIT(attr)) != 0) {
+      if ((prog->info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
          const GLuint slot = num_inputs++;
 
          inputMapping[attr] = slot;
@@ -1303,7 +1303,7 @@ st_translate_program_common(struct st_context *st,
 
    /* Also add patch inputs. */
    for (attr = 0; attr < 32; attr++) {
-      if (prog->PatchInputsRead & (1u << attr)) {
+      if (prog->info.patch_inputs_read & (1u << attr)) {
          GLuint slot = num_inputs++;
          GLuint patch_attr = VARYING_SLOT_PATCH0 + attr;
 
@@ -1325,7 +1325,7 @@ st_translate_program_common(struct st_context *st,
     * mapping and the semantic information for each output.
     */
    for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
-      if (prog->OutputsWritten & BITFIELD64_BIT(attr)) {
+      if (prog->info.outputs_written & BITFIELD64_BIT(attr)) {
          GLuint slot = num_outputs++;
 
          outputMapping[attr] = slot;
@@ -1427,7 +1427,7 @@ st_translate_program_common(struct st_context *st,
 
    /* Also add patch outputs. */
    for (attr = 0; attr < 32; attr++) {
-      if (prog->PatchOutputsWritten & (1u << attr)) {
+      if (prog->info.patch_outputs_written & (1u << attr)) {
          GLuint slot = num_outputs++;
          GLuint patch_attr = VARYING_SLOT_PATCH0 + attr;