st/xorg: linear gradient shader
[mesa.git] / src / gallium / state_trackers / g3dvl / vl_r16snorm_mc_buf.c
index 2e790bb3af16d34809c73fc8da1cc71ffdd72208..23631adb69370f3b0fd477158e30443e79eb07d3 100644 (file)
@@ -2,7 +2,6 @@
 #include "vl_r16snorm_mc_buf.h"
 #include <assert.h>
 #include <pipe/p_context.h>
-#include <pipe/p_winsys.h>
 #include <pipe/p_screen.h>
 #include <pipe/p_state.h>
 #include <pipe/p_inlines.h>
@@ -67,7 +66,7 @@ struct vlR16SnormBufferedMC
        struct vlVertex2f                       zero_block[3];
        unsigned int                            num_macroblocks;
        struct vlMpeg2MacroBlock                *macroblocks;
-       struct pipe_surface                     *tex_surface[3];
+       struct pipe_transfer                    *tex_transfer[3];
        short                                   *texels[3];
 
        struct pipe_context                     *pipe;
@@ -188,7 +187,7 @@ static inline int vlGrabBlocks
        assert(mc);
        assert(blocks);
 
-       tex_pitch = mc->tex_surface[0]->stride / mc->tex_surface[0]->block.size;
+       tex_pitch = mc->tex_transfer[0]->stride / mc->tex_transfer[0]->block.size;
        texels = mc->texels[0] + mbpy * tex_pitch + mbpx;
 
        for (y = 0; y < 2; ++y)
@@ -236,7 +235,7 @@ static inline int vlGrabBlocks
 
        for (tb = 0; tb < 2; ++tb)
        {
-               tex_pitch = mc->tex_surface[tb + 1]->stride / mc->tex_surface[tb + 1]->block.size;
+               tex_pitch = mc->tex_transfer[tb + 1]->stride / mc->tex_transfer[tb + 1]->block.size;
                texels = mc->texels[tb + 1] + mbpy * tex_pitch + mbpx;
 
                if ((coded_block_pattern >> (1 - tb)) & 1)
@@ -297,6 +296,7 @@ static inline int vlGrabMacroBlock
 {
        assert(mc);
        assert(macroblock);
+       assert(mc->num_macroblocks < mc->macroblocks_per_picture);
 
        mc->macroblocks[mc->num_macroblocks].mbx = macroblock->mbx;
        mc->macroblocks[mc->num_macroblocks].mby = macroblock->mby;
@@ -330,6 +330,7 @@ static inline int vlGrabMacroBlock
 }
 
 #define SET_BLOCK(vb, cbp, mbx, mby, unitx, unity, ofsx, ofsy, hx, hy, lm, cbm, crm, zb)                                       \
+       do {                                                                                                                    \
        (vb)[0].pos.x = (mbx) * (unitx) + (ofsx);               (vb)[0].pos.y = (mby) * (unity) + (ofsy);                       \
        (vb)[1].pos.x = (mbx) * (unitx) + (ofsx);               (vb)[1].pos.y = (mby) * (unity) + (ofsy) + (hy);                \
        (vb)[2].pos.x = (mbx) * (unitx) + (ofsx) + (hx);        (vb)[2].pos.y = (mby) * (unity) + (ofsy);                       \
@@ -392,7 +393,8 @@ static inline int vlGrabMacroBlock
                (vb)[3].cr_tc.x = (zb)[2].x + (hx);     (vb)[3].cr_tc.y = (zb)[2].y;                                            \
                (vb)[4].cr_tc.x = (zb)[2].x;            (vb)[4].cr_tc.y = (zb)[2].y + (hy);                                     \
                (vb)[5].cr_tc.x = (zb)[2].x + (hx);     (vb)[5].cr_tc.y = (zb)[2].y + (hy);                                     \
-       }
+       }                                                                                                                       \
+       } while (0)
 
 static inline int vlGenMacroblockVerts
 (
@@ -409,6 +411,7 @@ static inline int vlGenMacroblockVerts
        assert(mc);
        assert(macroblock);
        assert(ycbcr_vb);
+       assert(pos < mc->macroblocks_per_picture);
 
        switch (macroblock->mb_type)
        {
@@ -581,6 +584,8 @@ static int vlFlush
        if (mc->num_macroblocks < mc->macroblocks_per_picture)
                return 0;
 
+       assert(mc->num_macroblocks <= mc->macroblocks_per_picture);
+
        pipe = mc->pipe;
 
        for (i = 0; i < mc->num_macroblocks; ++i)
@@ -599,17 +604,17 @@ static int vlFlush
                struct vlMacroBlockVertexStream0        *ycbcr_vb;
                struct vlVertex2f                       *ref_vb[2];
 
-               ycbcr_vb = (struct vlMacroBlockVertexStream0*)mc->pipe->winsys->buffer_map
+               ycbcr_vb = (struct vlMacroBlockVertexStream0*)pipe_buffer_map
                (
-                       mc->pipe->winsys,
+                       pipe->screen,
                        mc->vertex_bufs.ycbcr.buffer,
                        PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
                );
 
                for (i = 0; i < 2; ++i)
-                       ref_vb[i] = (struct vlVertex2f*)mc->pipe->winsys->buffer_map
+                       ref_vb[i] = (struct vlVertex2f*)pipe_buffer_map
                        (
-                               mc->pipe->winsys,
+                               pipe->screen,
                                mc->vertex_bufs.ref[i].buffer,
                                PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
                        );
@@ -623,15 +628,15 @@ static int vlFlush
                        offset[mb_type_ex]++;
                }
 
-               mc->pipe->winsys->buffer_unmap(mc->pipe->winsys, mc->vertex_bufs.ycbcr.buffer);
+               pipe_buffer_unmap(pipe->screen, mc->vertex_bufs.ycbcr.buffer);
                for (i = 0; i < 2; ++i)
-                       mc->pipe->winsys->buffer_unmap(mc->pipe->winsys, mc->vertex_bufs.ref[i].buffer);
+                       pipe_buffer_unmap(pipe->screen, mc->vertex_bufs.ref[i].buffer);
        }
 
        for (i = 0; i < 3; ++i)
        {
-               pipe_surface_unmap(mc->tex_surface[i]);
-               mc->pipe->screen->tex_surface_release(mc->pipe->screen, &mc->tex_surface[i]);
+               pipe->screen->transfer_unmap(pipe->screen, mc->tex_transfer[i]);
+               pipe->screen->tex_transfer_destroy(mc->tex_transfer[i]);
        }
 
        mc->render_target.cbufs[0] = pipe->screen->get_tex_surface
@@ -643,9 +648,9 @@ static int vlFlush
 
        pipe->set_framebuffer_state(pipe, &mc->render_target);
        pipe->set_viewport_state(pipe, &mc->viewport);
-       vs_consts = pipe->winsys->buffer_map
+       vs_consts = pipe_buffer_map
        (
-               pipe->winsys,
+               pipe->screen,
                mc->vs_const_buf.buffer,
                PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
        );
@@ -653,7 +658,7 @@ static int vlFlush
        vs_consts->denorm.x = mc->buffered_surface->texture->width[0];
        vs_consts->denorm.y = mc->buffered_surface->texture->height[0];
 
-       pipe->winsys->buffer_unmap(pipe->winsys, mc->vs_const_buf.buffer);
+       pipe_buffer_unmap(pipe->screen, mc->vs_const_buf.buffer);
        pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &mc->vs_const_buf);
        pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, &mc->fs_const_buf);
 
@@ -757,7 +762,7 @@ static int vlFlush
        }
 
        pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &mc->buffered_surface->render_fence);
-       pipe->screen->tex_surface_release(pipe->screen, &mc->render_target.cbufs[0]);
+       pipe_surface_reference(&mc->render_target.cbufs[0], NULL);
 
        for (i = 0; i < 3; ++i)
                mc->zero_block[i].x = -1.0f;
@@ -804,14 +809,16 @@ static int vlRenderMacroBlocksMpeg2R16SnormBuffered
 
                for (i = 0; i < 3; ++i)
                {
-                       mc->tex_surface[i] = mc->pipe->screen->get_tex_surface
+                       mc->tex_transfer[i] = mc->pipe->screen->get_tex_transfer
                        (
                                mc->pipe->screen,
                                mc->textures.all[i],
-                               0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
+                               0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0,
+                               surface->texture->width[0],
+                               surface->texture->height[0]
                        );
 
-                       mc->texels[i] = pipe_surface_map(mc->tex_surface[i], PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD);
+                       mc->texels[i] = mc->pipe->screen->transfer_map(mc->pipe->screen, mc->tex_transfer[i]);
                }
        }
 
@@ -849,11 +856,11 @@ static int vlDestroy
                pipe->delete_sampler_state(pipe, mc->samplers.all[i]);
 
        for (i = 0; i < 3; ++i)
-               pipe->winsys->buffer_destroy(pipe->winsys, mc->vertex_bufs.all[i].buffer);
+               pipe_buffer_reference(&mc->vertex_bufs.all[i].buffer, NULL);
 
        /* Textures 3 & 4 are not created directly, no need to release them here */
        for (i = 0; i < 3; ++i)
-               pipe_texture_release(&mc->textures.all[i]);
+               pipe_texture_reference(&mc->textures.all[i], NULL);
 
        pipe->delete_vs_state(pipe, mc->i_vs);
        pipe->delete_fs_state(pipe, mc->i_fs);
@@ -866,8 +873,8 @@ static int vlDestroy
                pipe->delete_fs_state(pipe, mc->b_fs[i]);
        }
 
-       pipe->winsys->buffer_destroy(pipe->winsys, mc->vs_const_buf.buffer);
-       pipe->winsys->buffer_destroy(pipe->winsys, mc->fs_const_buf.buffer);
+       pipe_buffer_reference(&mc->vs_const_buf.buffer, NULL);
+       pipe_buffer_reference(&mc->fs_const_buf.buffer, NULL);
 
        FREE(mc->macroblocks);
        FREE(mc);
@@ -906,12 +913,12 @@ static int vlCreateDataBufs
        mc->macroblocks_per_picture = mbw * mbh;
 
        /* Create our vertex buffers */
-       mc->vertex_bufs.ycbcr.pitch = sizeof(struct vlVertex2f) * 4;
+       mc->vertex_bufs.ycbcr.stride = sizeof(struct vlVertex2f) * 4;
        mc->vertex_bufs.ycbcr.max_index = 24 * mc->macroblocks_per_picture - 1;
        mc->vertex_bufs.ycbcr.buffer_offset = 0;
-       mc->vertex_bufs.ycbcr.buffer = pipe->winsys->buffer_create
+       mc->vertex_bufs.ycbcr.buffer = pipe_buffer_create
        (
-               pipe->winsys,
+               pipe->screen,
                DEFAULT_BUF_ALIGNMENT,
                PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_DISCARD,
                sizeof(struct vlVertex2f) * 4 * 24 * mc->macroblocks_per_picture
@@ -919,12 +926,12 @@ static int vlCreateDataBufs
 
        for (i = 1; i < 3; ++i)
        {
-               mc->vertex_bufs.all[i].pitch = sizeof(struct vlVertex2f) * 2;
+               mc->vertex_bufs.all[i].stride = sizeof(struct vlVertex2f) * 2;
                mc->vertex_bufs.all[i].max_index = 24 * mc->macroblocks_per_picture - 1;
                mc->vertex_bufs.all[i].buffer_offset = 0;
-               mc->vertex_bufs.all[i].buffer = pipe->winsys->buffer_create
+               mc->vertex_bufs.all[i].buffer = pipe_buffer_create
                (
-                       pipe->winsys,
+                       pipe->screen,
                        DEFAULT_BUF_ALIGNMENT,
                        PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_DISCARD,
                        sizeof(struct vlVertex2f) * 2 * 24 * mc->macroblocks_per_picture
@@ -980,32 +987,30 @@ static int vlCreateDataBufs
        mc->vertex_elems[7].src_format = PIPE_FORMAT_R32G32_FLOAT;
 
        /* Create our constant buffer */
-       mc->vs_const_buf.size = sizeof(struct vlVertexShaderConsts);
-       mc->vs_const_buf.buffer = pipe->winsys->buffer_create
+       mc->vs_const_buf.buffer = pipe_buffer_create
        (
-               pipe->winsys,
+               pipe->screen,
                DEFAULT_BUF_ALIGNMENT,
                PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD,
-               mc->vs_const_buf.size
+               sizeof(struct vlVertexShaderConsts)
        );
 
-       mc->fs_const_buf.size = sizeof(struct vlFragmentShaderConsts);
-       mc->fs_const_buf.buffer = pipe->winsys->buffer_create
+       mc->fs_const_buf.buffer = pipe_buffer_create
        (
-               pipe->winsys,
+               pipe->screen,
                DEFAULT_BUF_ALIGNMENT,
                PIPE_BUFFER_USAGE_CONSTANT,
-               mc->fs_const_buf.size
+               sizeof(struct vlFragmentShaderConsts)
        );
 
        memcpy
        (
-               pipe->winsys->buffer_map(pipe->winsys, mc->fs_const_buf.buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
+               pipe_buffer_map(pipe->screen, mc->fs_const_buf.buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
                &fs_consts,
                sizeof(struct vlFragmentShaderConsts)
        );
 
-       pipe->winsys->buffer_unmap(pipe->winsys, mc->fs_const_buf.buffer);
+       pipe_buffer_unmap(pipe->screen, mc->fs_const_buf.buffer);
 
        mc->macroblocks = MALLOC(sizeof(struct vlMpeg2MacroBlock) * mc->macroblocks_per_picture);
 
@@ -1046,7 +1051,7 @@ static int vlInit
 
        mc->render_target.width = vlRoundUpPOT(mc->picture_width);
        mc->render_target.height = vlRoundUpPOT(mc->picture_height);
-       mc->render_target.num_cbufs = 1;
+       mc->render_target.nr_cbufs = 1;
        /* FB for MC stage is a vlSurface created by the user, set at render time */
        mc->render_target.zsbuf = NULL;
 
@@ -1069,7 +1074,6 @@ static int vlInit
                sampler.compare_func = PIPE_FUNC_ALWAYS;
                sampler.normalized_coords = 1;
                /*sampler.prefilter = ;*/
-               /*sampler.shadow_ambient = ;*/
                /*sampler.lod_bias = ;*/
                sampler.min_lod = 0;
                /*sampler.max_lod = ;*/
@@ -1085,7 +1089,6 @@ static int vlInit
        template.width[0] = vlRoundUpPOT(mc->picture_width);
        template.height[0] = vlRoundUpPOT(mc->picture_height);
        template.depth[0] = 1;
-       template.compressed = 0;
        pf_get_block(template.format, &template.block);
        template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_DYNAMIC;