1af69d88dSmrg/**************************************************************************
2af69d88dSmrg *
3af69d88dSmrg * Copyright 2010 Christian König
4af69d88dSmrg * All Rights Reserved.
5af69d88dSmrg *
6af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a
7af69d88dSmrg * copy of this software and associated documentation files (the
8af69d88dSmrg * "Software"), to deal in the Software without restriction, including
9af69d88dSmrg * without limitation the rights to use, copy, modify, merge, publish,
10af69d88dSmrg * distribute, sub license, and/or sell copies of the Software, and to
11af69d88dSmrg * permit persons to whom the Software is furnished to do so, subject to
12af69d88dSmrg * the following conditions:
13af69d88dSmrg *
14af69d88dSmrg * The above copyright notice and this permission notice (including the
15af69d88dSmrg * next paragraph) shall be included in all copies or substantial portions
16af69d88dSmrg * of the Software.
17af69d88dSmrg *
18af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22af69d88dSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23af69d88dSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24af69d88dSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25af69d88dSmrg *
26af69d88dSmrg **************************************************************************/
27af69d88dSmrg
28af69d88dSmrg#ifndef vl_idct_h
29af69d88dSmrg#define vl_idct_h
30af69d88dSmrg
31af69d88dSmrg#include "pipe/p_state.h"
32af69d88dSmrg
33af69d88dSmrg#include "tgsi/tgsi_ureg.h"
34af69d88dSmrg
35af69d88dSmrg/* shader based inverse distinct cosinus transformation
36af69d88dSmrg * expect usage of vl_vertex_buffers as a todo list
37af69d88dSmrg */
38af69d88dSmrgstruct vl_idct
39af69d88dSmrg{
40af69d88dSmrg   struct pipe_context *pipe;
41af69d88dSmrg
42af69d88dSmrg   unsigned buffer_width;
43af69d88dSmrg   unsigned buffer_height;
44af69d88dSmrg   unsigned nr_of_render_targets;
45af69d88dSmrg
46af69d88dSmrg   void *rs_state;
47af69d88dSmrg   void *blend;
48af69d88dSmrg
49af69d88dSmrg   void *samplers[2];
50af69d88dSmrg
51af69d88dSmrg   void *vs_mismatch, *fs_mismatch;
52af69d88dSmrg   void *vs, *fs;
53af69d88dSmrg
54af69d88dSmrg   struct pipe_sampler_view *matrix;
55af69d88dSmrg   struct pipe_sampler_view *transpose;
56af69d88dSmrg};
57af69d88dSmrg
58af69d88dSmrg/* a set of buffers to work with */
59af69d88dSmrgstruct vl_idct_buffer
60af69d88dSmrg{
61af69d88dSmrg   struct pipe_viewport_state viewport_mismatch;
62af69d88dSmrg   struct pipe_viewport_state viewport;
63af69d88dSmrg
64af69d88dSmrg   struct pipe_framebuffer_state fb_state_mismatch;
65af69d88dSmrg   struct pipe_framebuffer_state fb_state;
66af69d88dSmrg
67af69d88dSmrg   union
68af69d88dSmrg   {
69af69d88dSmrg      struct pipe_sampler_view *all[4];
70af69d88dSmrg      struct pipe_sampler_view *stage[2][2];
71af69d88dSmrg      struct {
72af69d88dSmrg         struct pipe_sampler_view *source, *matrix;
73af69d88dSmrg         struct pipe_sampler_view *intermediate, *transpose;
74af69d88dSmrg      } individual;
75af69d88dSmrg   } sampler_views;
76af69d88dSmrg};
77af69d88dSmrg
78af69d88dSmrg/* upload the idct matrix, which can be shared by all idct instances of a pipe */
79af69d88dSmrgstruct pipe_sampler_view *
80af69d88dSmrgvl_idct_upload_matrix(struct pipe_context *pipe, float scale);
81af69d88dSmrg
82af69d88dSmrgvoid
83af69d88dSmrgvl_idct_stage2_vert_shader(struct vl_idct *idct, struct ureg_program *shader,
84af69d88dSmrg                           unsigned first_output, struct ureg_dst tex);
85af69d88dSmrg
86af69d88dSmrgvoid
87af69d88dSmrgvl_idct_stage2_frag_shader(struct vl_idct *idct, struct ureg_program *shader,
88af69d88dSmrg                           unsigned first_input, struct ureg_dst fragment);
89af69d88dSmrg
90af69d88dSmrg/* init an idct instance */
91af69d88dSmrgbool
92af69d88dSmrgvl_idct_init(struct vl_idct *idct, struct pipe_context *pipe,
93af69d88dSmrg             unsigned buffer_width, unsigned buffer_height,
94af69d88dSmrg             unsigned nr_of_render_targets,
95af69d88dSmrg             struct pipe_sampler_view *matrix,
96af69d88dSmrg             struct pipe_sampler_view *transpose);
97af69d88dSmrg
98af69d88dSmrg/* destroy an idct instance */
99af69d88dSmrgvoid
100af69d88dSmrgvl_idct_cleanup(struct vl_idct *idct);
101af69d88dSmrg
102af69d88dSmrg/* init a buffer assosiated with agiven idct instance */
103af69d88dSmrgbool
104af69d88dSmrgvl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer,
105af69d88dSmrg                    struct pipe_sampler_view *source,
106af69d88dSmrg                    struct pipe_sampler_view *intermediate);
107af69d88dSmrg
108af69d88dSmrg/* cleanup a buffer of an idct instance */
109af69d88dSmrgvoid
110af69d88dSmrgvl_idct_cleanup_buffer(struct vl_idct_buffer *buffer);
111af69d88dSmrg
112af69d88dSmrg/* flush the buffer and start rendering, vertex buffers needs to be setup before calling this */
113af69d88dSmrgvoid
114af69d88dSmrgvl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer, unsigned num_verts);
115af69d88dSmrg
116af69d88dSmrgvoid
117af69d88dSmrgvl_idct_prepare_stage2(struct vl_idct *idct, struct vl_idct_buffer *buffer);
118af69d88dSmrg
119af69d88dSmrg#endif
120