gallium: remove deprecated PIPE_TRANSFER_DISCARD
[mesa.git] / src / gallium / auxiliary / vl / vl_zscan.c
index 58cee0070d8054c8bb5a9f151c2b6d032112d3b5..730074c0c57bf46b04293566a5911e0e463ef476 100644 (file)
 
 #include <assert.h>
 
-#include <pipe/p_screen.h>
-#include <pipe/p_context.h>
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
 
-#include <util/u_draw.h>
-#include <util/u_sampler.h>
-#include <util/u_inlines.h>
+#include "util/u_draw.h"
+#include "util/u_sampler.h"
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
 
-#include <tgsi/tgsi_ureg.h>
+#include "tgsi/tgsi_ureg.h"
 
-#include <vl/vl_defines.h>
-#include <vl/vl_types.h>
+#include "vl_defines.h"
+#include "vl_types.h"
 
 #include "vl_zscan.h"
 #include "vl_vertex_buffers.h"
@@ -96,7 +97,8 @@ create_vert_shader(struct vl_zscan *zscan)
    struct ureg_src vrect, vpos, block_num;
 
    struct ureg_dst tmp;
-   struct ureg_dst o_vpos, o_vtex[zscan->num_channels];
+   struct ureg_dst o_vpos;
+   struct ureg_dst *o_vtex;
 
    signed i;
 
@@ -104,6 +106,8 @@ create_vert_shader(struct vl_zscan *zscan)
    if (!shader)
       return NULL;
 
+   o_vtex = MALLOC(zscan->num_channels * sizeof(struct ureg_dst));
+
    scale = ureg_imm2f(shader,
       (float)BLOCK_WIDTH / zscan->buffer_width,
       (float)BLOCK_HEIGHT / zscan->buffer_height);
@@ -156,6 +160,8 @@ create_vert_shader(struct vl_zscan *zscan)
    ureg_release_temporary(shader, tmp);
    ureg_END(shader);
 
+   FREE(o_vtex);
+
    return ureg_create_shader_and_destroy(shader, zscan->pipe);
 }
 
@@ -163,11 +169,11 @@ static void *
 create_frag_shader(struct vl_zscan *zscan)
 {
    struct ureg_program *shader;
-   struct ureg_src vtex[zscan->num_channels];
+   struct ureg_src *vtex;
 
    struct ureg_src samp_src, samp_scan, samp_quant;
 
-   struct ureg_dst tmp[zscan->num_channels];
+   struct ureg_dst *tmp;
    struct ureg_dst quant, fragment;
 
    unsigned i;
@@ -176,6 +182,9 @@ create_frag_shader(struct vl_zscan *zscan)
    if (!shader)
       return NULL;
 
+   vtex = MALLOC(zscan->num_channels * sizeof(struct ureg_src));
+   tmp = MALLOC(zscan->num_channels * sizeof(struct ureg_dst));
+
    for (i = 0; i < zscan->num_channels; ++i)
       vtex[i] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_VTEX + i, TGSI_INTERPOLATE_LINEAR);
 
@@ -212,6 +221,9 @@ create_frag_shader(struct vl_zscan *zscan)
       ureg_release_temporary(shader, tmp[i]);
    ureg_END(shader);
 
+   FREE(vtex);
+   FREE(tmp);
+
    return ureg_create_shader_and_destroy(shader, zscan->pipe);
 }
 
@@ -370,7 +382,7 @@ vl_zscan_layout(struct pipe_context *pipe, const int layout[64], unsigned blocks
    buf_transfer = pipe->get_transfer
    (
       pipe, res,
-      0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
+      0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
       &rect
    );
    if (!buf_transfer)
@@ -461,8 +473,6 @@ vl_zscan_init_buffer(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
 
    memset(buffer, 0, sizeof(struct vl_zscan_buffer));
 
-   buffer->zscan = zscan;
-
    pipe_sampler_view_reference(&buffer->src, src);
 
    buffer->viewport.scale[0] = dst->width;
@@ -525,35 +535,33 @@ vl_zscan_set_layout(struct vl_zscan_buffer *buffer, struct pipe_sampler_view *la
 }
 
 void
-vl_zscan_upload_quant(struct vl_zscan_buffer *buffer,
-                      const uint8_t intra_matrix[64],
-                      const uint8_t non_intra_matrix[64])
+vl_zscan_upload_quant(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
+                      const uint8_t matrix[64], bool intra)
 {
    struct pipe_context *pipe;
    struct pipe_transfer *buf_transfer;
    unsigned x, y, i, pitch;
-   uint8_t *intra, *non_intra;
+   uint8_t *data;
 
    struct pipe_box rect =
    {
-      0, 0, 0,
+      0, 0, intra ? 1 : 0,
       BLOCK_WIDTH,
       BLOCK_HEIGHT,
-      2
+      1
    };
 
    assert(buffer);
-   assert(intra_matrix);
-   assert(non_intra_matrix);
+   assert(matrix);
 
-   pipe = buffer->zscan->pipe;
+   pipe = zscan->pipe;
 
-   rect.width *= buffer->zscan->blocks_per_line;
+   rect.width *= zscan->blocks_per_line;
 
    buf_transfer = pipe->get_transfer
    (
       pipe, buffer->quant->texture,
-      0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
+      0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
       &rect
    );
    if (!buf_transfer)
@@ -561,18 +569,14 @@ vl_zscan_upload_quant(struct vl_zscan_buffer *buffer,
 
    pitch = buf_transfer->stride;
 
-   non_intra = pipe->transfer_map(pipe, buf_transfer);
-   if (!non_intra)
+   data = pipe->transfer_map(pipe, buf_transfer);
+   if (!data)
       goto error_map;
 
-   intra = non_intra + BLOCK_HEIGHT * pitch;
-
-   for (i = 0; i < buffer->zscan->blocks_per_line; ++i)
+   for (i = 0; i < zscan->blocks_per_line; ++i)
       for (y = 0; y < BLOCK_HEIGHT; ++y)
-         for (x = 0; x < BLOCK_WIDTH; ++x) {
-            intra[i * BLOCK_WIDTH + y * pitch + x] = intra_matrix[x + y * BLOCK_WIDTH];
-            non_intra[i * BLOCK_WIDTH + y * pitch + x] = non_intra_matrix[x + y * BLOCK_WIDTH];
-         }
+         for (x = 0; x < BLOCK_WIDTH; ++x)
+            data[i * BLOCK_WIDTH + y * pitch + x] = matrix[x + y * BLOCK_WIDTH];
 
    pipe->transfer_unmap(pipe, buf_transfer);
 
@@ -584,14 +588,10 @@ error_transfer:
 }
 
 void
-vl_zscan_render(struct vl_zscan_buffer *buffer, unsigned num_instances)
+vl_zscan_render(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer, unsigned num_instances)
 {
-   struct vl_zscan *zscan;
-
    assert(buffer);
 
-   zscan = buffer->zscan;
-
    zscan->pipe->bind_rasterizer_state(zscan->pipe, zscan->rs_state);
    zscan->pipe->bind_blend_state(zscan->pipe, zscan->blend);
    zscan->pipe->bind_fragment_sampler_states(zscan->pipe, 3, zscan->samplers);