Path: blob/21.2-virgl/src/gallium/auxiliary/postprocess/pp_program.c
4561 views
/**************************************************************************1*2* Copyright 2010 Jakob Bornecrantz3* Copyright 2011 Lauri Kasanen4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* The above copyright notice and this permission notice (including the15* next paragraph) shall be included in all copies or substantial portions16* of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS19* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF20* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.21* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR22* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,23* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE24* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.25*26**************************************************************************/2728#include "postprocess/postprocess.h"29#include "postprocess/pp_private.h"3031#include "cso_cache/cso_context.h"32#include "pipe/p_screen.h"33#include "pipe/p_context.h"34#include "pipe/p_state.h"35#include "pipe/p_shader_tokens.h"36#include "util/u_inlines.h"37#include "util/u_simple_shaders.h"38#include "util/u_memory.h"3940/** Initialize the internal details */41struct pp_program *42pp_init_prog(struct pp_queue_t *ppq, struct pipe_context *pipe,43struct cso_context *cso, struct st_context_iface *st)44{45struct pp_program *p;4647pp_debug("Initializing program\n");48if (!pipe)49return NULL;5051p = CALLOC(1, sizeof(struct pp_program));52if (!p)53return NULL;5455p->screen = pipe->screen;56p->pipe = pipe;57p->cso = cso;58p->st = st;5960{61static const float verts[4][2][4] = {62{63{1.0f, 1.0f, 0.0f, 1.0f},64{1.0f, 1.0f, 0.0f, 1.0f}65},66{67{-1.0f, 1.0f, 0.0f, 1.0f},68{0.0f, 1.0f, 0.0f, 1.0f}69},70{71{-1.0f, -1.0f, 0.0f, 1.0f},72{0.0f, 0.0f, 0.0f, 1.0f}73},74{75{1.0f, -1.0f, 0.0f, 1.0f},76{1.0f, 0.0f, 0.0f, 1.0f}77}78};7980p->vbuf = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,81PIPE_USAGE_DEFAULT, sizeof(verts));82pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(verts), verts);83}8485p->blend.rt[0].colormask = PIPE_MASK_RGBA;86p->blend.rt[0].rgb_src_factor = p->blend.rt[0].alpha_src_factor =87PIPE_BLENDFACTOR_SRC_ALPHA;88p->blend.rt[0].rgb_dst_factor = p->blend.rt[0].alpha_dst_factor =89PIPE_BLENDFACTOR_INV_SRC_ALPHA;9091p->rasterizer.cull_face = PIPE_FACE_NONE;92p->rasterizer.half_pixel_center = 1;93p->rasterizer.bottom_edge_rule = 1;94p->rasterizer.depth_clip_near = 1;95p->rasterizer.depth_clip_far = 1;9697p->sampler.wrap_s = p->sampler.wrap_t = p->sampler.wrap_r =98PIPE_TEX_WRAP_CLAMP_TO_EDGE;99100p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;101p->sampler.min_img_filter = p->sampler.mag_img_filter =102PIPE_TEX_FILTER_LINEAR;103p->sampler.normalized_coords = 1;104105p->sampler_point.wrap_s = p->sampler_point.wrap_t =106p->sampler_point.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;107p->sampler_point.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;108p->sampler_point.min_img_filter = p->sampler_point.mag_img_filter =109PIPE_TEX_FILTER_NEAREST;110p->sampler_point.normalized_coords = 1;111112p->velem.count = 2;113p->velem.velems[0].src_offset = 0;114p->velem.velems[0].instance_divisor = 0;115p->velem.velems[0].vertex_buffer_index = 0;116p->velem.velems[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;117p->velem.velems[1].src_offset = 1 * 4 * sizeof(float);118p->velem.velems[1].instance_divisor = 0;119p->velem.velems[1].vertex_buffer_index = 0;120p->velem.velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;121122if (!p->screen->is_format_supported(p->screen,123PIPE_FORMAT_R32G32B32A32_FLOAT,124PIPE_BUFFER, 1, 1,125PIPE_BIND_VERTEX_BUFFER))126pp_debug("Vertex buf format fail\n");127128129{130const enum tgsi_semantic semantic_names[] = { TGSI_SEMANTIC_POSITION,131TGSI_SEMANTIC_GENERIC132};133const uint semantic_indexes[] = { 0, 0 };134p->passvs = util_make_vertex_passthrough_shader(p->pipe, 2,135semantic_names,136semantic_indexes, FALSE);137}138139p->framebuffer.nr_cbufs = 1;140141p->surf.format = PIPE_FORMAT_B8G8R8A8_UNORM;142143return p;144}145146147