1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2010 Christian König
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg#ifndef vl_idct_h
29848b8605Smrg#define vl_idct_h
30848b8605Smrg
31848b8605Smrg#include "pipe/p_state.h"
32848b8605Smrg
33848b8605Smrg#include "tgsi/tgsi_ureg.h"
34848b8605Smrg
35848b8605Smrg/* shader based inverse distinct cosinus transformation
36848b8605Smrg * expect usage of vl_vertex_buffers as a todo list
37848b8605Smrg */
38848b8605Smrgstruct vl_idct
39848b8605Smrg{
40848b8605Smrg   struct pipe_context *pipe;
41848b8605Smrg
42848b8605Smrg   unsigned buffer_width;
43848b8605Smrg   unsigned buffer_height;
44848b8605Smrg   unsigned nr_of_render_targets;
45848b8605Smrg
46848b8605Smrg   void *rs_state;
47848b8605Smrg   void *blend;
48848b8605Smrg
49848b8605Smrg   void *samplers[2];
50848b8605Smrg
51848b8605Smrg   void *vs_mismatch, *fs_mismatch;
52848b8605Smrg   void *vs, *fs;
53848b8605Smrg
54848b8605Smrg   struct pipe_sampler_view *matrix;
55848b8605Smrg   struct pipe_sampler_view *transpose;
56848b8605Smrg};
57848b8605Smrg
58848b8605Smrg/* a set of buffers to work with */
59848b8605Smrgstruct vl_idct_buffer
60848b8605Smrg{
61848b8605Smrg   struct pipe_viewport_state viewport_mismatch;
62848b8605Smrg   struct pipe_viewport_state viewport;
63848b8605Smrg
64848b8605Smrg   struct pipe_framebuffer_state fb_state_mismatch;
65848b8605Smrg   struct pipe_framebuffer_state fb_state;
66848b8605Smrg
67848b8605Smrg   union
68848b8605Smrg   {
69848b8605Smrg      struct pipe_sampler_view *all[4];
70848b8605Smrg      struct pipe_sampler_view *stage[2][2];
71848b8605Smrg      struct {
72848b8605Smrg         struct pipe_sampler_view *source, *matrix;
73848b8605Smrg         struct pipe_sampler_view *intermediate, *transpose;
74848b8605Smrg      } individual;
75848b8605Smrg   } sampler_views;
76848b8605Smrg};
77848b8605Smrg
78848b8605Smrg/* upload the idct matrix, which can be shared by all idct instances of a pipe */
79848b8605Smrgstruct pipe_sampler_view *
80848b8605Smrgvl_idct_upload_matrix(struct pipe_context *pipe, float scale);
81848b8605Smrg
82848b8605Smrgvoid
83848b8605Smrgvl_idct_stage2_vert_shader(struct vl_idct *idct, struct ureg_program *shader,
84848b8605Smrg                           unsigned first_output, struct ureg_dst tex);
85848b8605Smrg
86848b8605Smrgvoid
87848b8605Smrgvl_idct_stage2_frag_shader(struct vl_idct *idct, struct ureg_program *shader,
88848b8605Smrg                           unsigned first_input, struct ureg_dst fragment);
89848b8605Smrg
90848b8605Smrg/* init an idct instance */
91848b8605Smrgbool
92848b8605Smrgvl_idct_init(struct vl_idct *idct, struct pipe_context *pipe,
93848b8605Smrg             unsigned buffer_width, unsigned buffer_height,
94848b8605Smrg             unsigned nr_of_render_targets,
95848b8605Smrg             struct pipe_sampler_view *matrix,
96848b8605Smrg             struct pipe_sampler_view *transpose);
97848b8605Smrg
98848b8605Smrg/* destroy an idct instance */
99848b8605Smrgvoid
100848b8605Smrgvl_idct_cleanup(struct vl_idct *idct);
101848b8605Smrg
102848b8605Smrg/* init a buffer assosiated with agiven idct instance */
103848b8605Smrgbool
104848b8605Smrgvl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer,
105848b8605Smrg                    struct pipe_sampler_view *source,
106848b8605Smrg                    struct pipe_sampler_view *intermediate);
107848b8605Smrg
108848b8605Smrg/* cleanup a buffer of an idct instance */
109848b8605Smrgvoid
110848b8605Smrgvl_idct_cleanup_buffer(struct vl_idct_buffer *buffer);
111848b8605Smrg
112848b8605Smrg/* flush the buffer and start rendering, vertex buffers needs to be setup before calling this */
113848b8605Smrgvoid
114848b8605Smrgvl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer, unsigned num_verts);
115848b8605Smrg
116848b8605Smrgvoid
117848b8605Smrgvl_idct_prepare_stage2(struct vl_idct *idct, struct vl_idct_buffer *buffer);
118848b8605Smrg
119848b8605Smrg#endif
120