1af69d88dSmrg/**************************************************************************
2af69d88dSmrg *
3af69d88dSmrg * Copyright 2010 Jakob Bornecrantz
4af69d88dSmrg * Copyright 2011 Lauri Kasanen
5af69d88dSmrg * All Rights Reserved.
6af69d88dSmrg *
7af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a
8af69d88dSmrg * copy of this software and associated documentation files (the
9af69d88dSmrg * "Software"), to deal in the Software without restriction, including
10af69d88dSmrg * without limitation the rights to use, copy, modify, merge, publish,
11af69d88dSmrg * distribute, sub license, and/or sell copies of the Software, and to
12af69d88dSmrg * permit persons to whom the Software is furnished to do so, subject to
13af69d88dSmrg * the following conditions:
14af69d88dSmrg *
15af69d88dSmrg * The above copyright notice and this permission notice (including the
16af69d88dSmrg * next paragraph) shall be included in all copies or substantial portions
17af69d88dSmrg * of the Software.
18af69d88dSmrg *
19af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22af69d88dSmrg * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
23af69d88dSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24af69d88dSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25af69d88dSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26af69d88dSmrg *
27af69d88dSmrg **************************************************************************/
28af69d88dSmrg
29af69d88dSmrg#include "postprocess/postprocess.h"
30af69d88dSmrg#include "postprocess/pp_private.h"
31af69d88dSmrg
32af69d88dSmrg#include "cso_cache/cso_context.h"
33af69d88dSmrg#include "pipe/p_screen.h"
34af69d88dSmrg#include "pipe/p_context.h"
35af69d88dSmrg#include "pipe/p_state.h"
36af69d88dSmrg#include "pipe/p_shader_tokens.h"
37af69d88dSmrg#include "util/u_inlines.h"
38af69d88dSmrg#include "util/u_simple_shaders.h"
39af69d88dSmrg#include "util/u_memory.h"
40af69d88dSmrg
41af69d88dSmrg/** Initialize the internal details */
42af69d88dSmrgstruct pp_program *
43af69d88dSmrgpp_init_prog(struct pp_queue_t *ppq, struct pipe_context *pipe,
447ec681f3Smrg             struct cso_context *cso, struct st_context_iface *st)
45af69d88dSmrg{
46af69d88dSmrg   struct pp_program *p;
47af69d88dSmrg
48af69d88dSmrg   pp_debug("Initializing program\n");
49af69d88dSmrg   if (!pipe)
50af69d88dSmrg      return NULL;
51af69d88dSmrg
52af69d88dSmrg   p = CALLOC(1, sizeof(struct pp_program));
53af69d88dSmrg   if (!p)
54af69d88dSmrg      return NULL;
55af69d88dSmrg
56af69d88dSmrg   p->screen = pipe->screen;
57af69d88dSmrg   p->pipe = pipe;
58af69d88dSmrg   p->cso = cso;
597ec681f3Smrg   p->st = st;
60af69d88dSmrg
61af69d88dSmrg   {
62af69d88dSmrg      static const float verts[4][2][4] = {
63af69d88dSmrg         {
64af69d88dSmrg          {1.0f, 1.0f, 0.0f, 1.0f},
65af69d88dSmrg          {1.0f, 1.0f, 0.0f, 1.0f}
66af69d88dSmrg          },
67af69d88dSmrg         {
68af69d88dSmrg          {-1.0f, 1.0f, 0.0f, 1.0f},
69af69d88dSmrg          {0.0f, 1.0f, 0.0f, 1.0f}
70af69d88dSmrg          },
71af69d88dSmrg         {
72af69d88dSmrg          {-1.0f, -1.0f, 0.0f, 1.0f},
73af69d88dSmrg          {0.0f, 0.0f, 0.0f, 1.0f}
74af69d88dSmrg          },
75af69d88dSmrg         {
76af69d88dSmrg          {1.0f, -1.0f, 0.0f, 1.0f},
77af69d88dSmrg          {1.0f, 0.0f, 0.0f, 1.0f}
78af69d88dSmrg          }
79af69d88dSmrg      };
80af69d88dSmrg
81af69d88dSmrg      p->vbuf = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
82af69d88dSmrg                                   PIPE_USAGE_DEFAULT, sizeof(verts));
83af69d88dSmrg      pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(verts), verts);
84af69d88dSmrg   }
85af69d88dSmrg
86af69d88dSmrg   p->blend.rt[0].colormask = PIPE_MASK_RGBA;
87af69d88dSmrg   p->blend.rt[0].rgb_src_factor = p->blend.rt[0].alpha_src_factor =
88af69d88dSmrg      PIPE_BLENDFACTOR_SRC_ALPHA;
89af69d88dSmrg   p->blend.rt[0].rgb_dst_factor = p->blend.rt[0].alpha_dst_factor =
90af69d88dSmrg      PIPE_BLENDFACTOR_INV_SRC_ALPHA;
91af69d88dSmrg
92af69d88dSmrg   p->rasterizer.cull_face = PIPE_FACE_NONE;
93af69d88dSmrg   p->rasterizer.half_pixel_center = 1;
94af69d88dSmrg   p->rasterizer.bottom_edge_rule = 1;
9501e04c3fSmrg   p->rasterizer.depth_clip_near = 1;
9601e04c3fSmrg   p->rasterizer.depth_clip_far = 1;
97af69d88dSmrg
98af69d88dSmrg   p->sampler.wrap_s = p->sampler.wrap_t = p->sampler.wrap_r =
99af69d88dSmrg      PIPE_TEX_WRAP_CLAMP_TO_EDGE;
100af69d88dSmrg
101af69d88dSmrg   p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
102af69d88dSmrg   p->sampler.min_img_filter = p->sampler.mag_img_filter =
103af69d88dSmrg      PIPE_TEX_FILTER_LINEAR;
104af69d88dSmrg   p->sampler.normalized_coords = 1;
105af69d88dSmrg
106af69d88dSmrg   p->sampler_point.wrap_s = p->sampler_point.wrap_t =
107af69d88dSmrg      p->sampler_point.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
108af69d88dSmrg   p->sampler_point.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
109af69d88dSmrg   p->sampler_point.min_img_filter = p->sampler_point.mag_img_filter =
110af69d88dSmrg      PIPE_TEX_FILTER_NEAREST;
111af69d88dSmrg   p->sampler_point.normalized_coords = 1;
112af69d88dSmrg
1137ec681f3Smrg   p->velem.count = 2;
1147ec681f3Smrg   p->velem.velems[0].src_offset = 0;
1157ec681f3Smrg   p->velem.velems[0].instance_divisor = 0;
1167ec681f3Smrg   p->velem.velems[0].vertex_buffer_index = 0;
1177ec681f3Smrg   p->velem.velems[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
1187ec681f3Smrg   p->velem.velems[1].src_offset = 1 * 4 * sizeof(float);
1197ec681f3Smrg   p->velem.velems[1].instance_divisor = 0;
1207ec681f3Smrg   p->velem.velems[1].vertex_buffer_index = 0;
1217ec681f3Smrg   p->velem.velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
122af69d88dSmrg
123af69d88dSmrg   if (!p->screen->is_format_supported(p->screen,
124af69d88dSmrg                                       PIPE_FORMAT_R32G32B32A32_FLOAT,
12501e04c3fSmrg                                       PIPE_BUFFER, 1, 1,
126af69d88dSmrg                                       PIPE_BIND_VERTEX_BUFFER))
127af69d88dSmrg      pp_debug("Vertex buf format fail\n");
128af69d88dSmrg
129af69d88dSmrg
130af69d88dSmrg   {
1317ec681f3Smrg      const enum tgsi_semantic semantic_names[] = { TGSI_SEMANTIC_POSITION,
132af69d88dSmrg         TGSI_SEMANTIC_GENERIC
133af69d88dSmrg      };
134af69d88dSmrg      const uint semantic_indexes[] = { 0, 0 };
135af69d88dSmrg      p->passvs = util_make_vertex_passthrough_shader(p->pipe, 2,
136af69d88dSmrg                                                      semantic_names,
13701e04c3fSmrg                                                      semantic_indexes, FALSE);
138af69d88dSmrg   }
139af69d88dSmrg
140af69d88dSmrg   p->framebuffer.nr_cbufs = 1;
141af69d88dSmrg
142af69d88dSmrg   p->surf.format = PIPE_FORMAT_B8G8R8A8_UNORM;
143af69d88dSmrg
144af69d88dSmrg   return p;
145af69d88dSmrg}
146