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