vc4: Make a helper function for getting the current offset in the CL.
[mesa.git] / src / mesa / state_tracker / st_atom_pixeltransfer.c
index 6be03376d0177966e4bf06cc110bf8e23757c78c..a04163cc137a8fec8e00d8442e6715f589a9db49 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
@@ -84,26 +84,6 @@ make_state_key(struct gl_context *ctx,  struct state_key *key)
 }
 
 
-static struct pipe_resource *
-create_color_map_texture(struct gl_context *ctx)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct pipe_resource *pt;
-   enum pipe_format format;
-   const uint texSize = 256; /* simple, and usually perfect */
-
-   /* find an RGBA texture format */
-   format = st_choose_format(pipe->screen, GL_RGBA,
-                             PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
-
-   /* create texture for color map/table */
-   pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
-                          texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW);
-   return pt;
-}
-
-
 /**
  * Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
  */
@@ -121,10 +101,9 @@ load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt)
    uint *dest;
    uint i, j;
 
-   transfer = pipe_get_transfer(st_context(ctx)->pipe,
-                                            pt, 0, 0, 0, PIPE_TRANSFER_WRITE,
-                                            0, 0, texSize, texSize);
-   dest = (uint *) pipe_transfer_map(pipe, transfer);
+   dest = (uint *) pipe_transfer_map(pipe,
+                                     pt, 0, 0, PIPE_TRANSFER_WRITE,
+                                     0, 0, texSize, texSize, &transfer);
 
    /* Pack four 1D maps into a 2D texture:
     * R map is placed horizontally, indexed by S, in channel 0
@@ -136,17 +115,17 @@ load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt)
       for (j = 0; j < texSize; j++) {
          union util_color uc;
          int k = (i * texSize + j);
-         ubyte r = ctx->PixelMaps.RtoR.Map8[j * rSize / texSize];
-         ubyte g = ctx->PixelMaps.GtoG.Map8[i * gSize / texSize];
-         ubyte b = ctx->PixelMaps.BtoB.Map8[j * bSize / texSize];
-         ubyte a = ctx->PixelMaps.AtoA.Map8[i * aSize / texSize];
-         util_pack_color_ub(r, g, b, a, pt->format, &uc);
-         *(dest + k) = uc.ui;
+         float rgba[4];
+         rgba[0] = ctx->PixelMaps.RtoR.Map[j * rSize / texSize];
+         rgba[1] = ctx->PixelMaps.GtoG.Map[i * gSize / texSize];
+         rgba[2] = ctx->PixelMaps.BtoB.Map[j * bSize / texSize];
+         rgba[3] = ctx->PixelMaps.AtoA.Map[i * aSize / texSize];
+         util_pack_color(rgba, pt->format, &uc);
+         *(dest + k) = uc.ui[0];
       }
    }
 
    pipe_transfer_unmap(pipe, transfer);
-   pipe->transfer_destroy(pipe, transfer);
 }
 
 
@@ -182,12 +161,12 @@ get_pixel_transfer_program(struct gl_context *ctx, const struct state_key *key)
    inst[ic].DstReg.File = PROGRAM_TEMPORARY;
    inst[ic].DstReg.Index = colorTemp;
    inst[ic].SrcReg[0].File = PROGRAM_INPUT;
-   inst[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0;
+   inst[ic].SrcReg[0].Index = VARYING_SLOT_TEX0;
    inst[ic].TexSrcUnit = 0;
    inst[ic].TexSrcTarget = TEXTURE_2D_INDEX;
    ic++;
-   fp->Base.InputsRead = (1 << FRAG_ATTRIB_TEX0);
-   fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLOR);
+   fp->Base.InputsRead = BITFIELD64_BIT(VARYING_SLOT_TEX0);
+   fp->Base.OutputsWritten = BITFIELD64_BIT(FRAG_RESULT_COLOR);
    fp->Base.SamplersUsed = 0x1;  /* sampler 0 (bit 0) is used */
 
    if (key->scaleAndBias) {
@@ -195,18 +174,8 @@ get_pixel_transfer_program(struct gl_context *ctx, const struct state_key *key)
          { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 };
       static const gl_state_index bias_state[STATE_LENGTH] =
          { STATE_INTERNAL, STATE_PT_BIAS, 0, 0, 0 };
-      GLfloat scale[4], bias[4];
       GLint scale_p, bias_p;
 
-      scale[0] = ctx->Pixel.RedScale;
-      scale[1] = ctx->Pixel.GreenScale;
-      scale[2] = ctx->Pixel.BlueScale;
-      scale[3] = ctx->Pixel.AlphaScale;
-      bias[0] = ctx->Pixel.RedBias;
-      bias[1] = ctx->Pixel.GreenBias;
-      bias[2] = ctx->Pixel.BlueBias;
-      bias[3] = ctx->Pixel.AlphaBias;
-
       scale_p = _mesa_add_state_reference(params, scale_state);
       bias_p = _mesa_add_state_reference(params, bias_state);
 
@@ -229,7 +198,7 @@ get_pixel_transfer_program(struct gl_context *ctx, const struct state_key *key)
 
       /* create the colormap/texture now if not already done */
       if (!st->pixel_xfer.pixelmap_texture) {
-         st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
+         st->pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx);
          st->pixel_xfer.pixelmap_sampler_view =
             st_create_texture_sampler_view(st->pipe,
                                            st->pixel_xfer.pixelmap_texture);
@@ -296,6 +265,7 @@ get_pixel_transfer_program(struct gl_context *ctx, const struct state_key *key)
    if (!fp->Base.Instructions) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY,
                   "generating pixel transfer program");
+      _mesa_free_parameter_list(params);
       return NULL;
    }