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