shaders_cache.h revision e8ff3931f801dffdfd54832c298351e933688235
1/************************************************************************** 2 * 3 * Copyright 2009 VMware, Inc. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial portions 15 * of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 **************************************************************************/ 26 27#ifndef SHADERS_CACHE_H 28#define SHADERS_CACHE_H 29 30 31struct vg_context; 32struct pipe_context; 33struct tgsi_token; 34struct shaders_cache; 35 36#define _SHADERS_PAINT_BITS 3 37#define _SHADERS_IMAGE_BITS 2 38#define _SHADERS_COLOR_TRANSFORM_BITS 1 39#define _SHADERS_ALPHA_BITS 2 40#define _SHADERS_BLEND_BITS 3 41#define _SHADERS_MASK_BITS 1 42#define _SHADERS_PREMULTIPLY_BITS 2 43#define _SHADERS_BW_BITS 1 44 45#define SHADERS_PAINT_SHIFT (0) 46#define SHADERS_IMAGE_SHIFT (SHADERS_PAINT_SHIFT + _SHADERS_PAINT_BITS) 47#define SHADERS_COLOR_TRANSFORM_SHIFT (SHADERS_IMAGE_SHIFT + _SHADERS_IMAGE_BITS) 48#define SHADERS_ALPHA_SHIFT (SHADERS_COLOR_TRANSFORM_SHIFT + _SHADERS_COLOR_TRANSFORM_BITS) 49#define SHADERS_BLEND_SHIFT (SHADERS_ALPHA_SHIFT + _SHADERS_ALPHA_BITS) 50#define SHADERS_MASK_SHIFT (SHADERS_BLEND_SHIFT + _SHADERS_BLEND_BITS) 51#define SHADERS_PREMULTIPLY_SHIFT (SHADERS_MASK_SHIFT + _SHADERS_MASK_BITS) 52#define SHADERS_BW_SHIFT (SHADERS_PREMULTIPLY_SHIFT + _SHADERS_PREMULTIPLY_BITS) 53 54#define _SHADERS_GET_STAGE(stage, id) \ 55 ((id) & (((1 << _SHADERS_ ## stage ## _BITS) - 1) << SHADERS_ ## stage ## _SHIFT)) 56 57#define SHADERS_GET_PAINT_SHADER(id) _SHADERS_GET_STAGE(PAINT, id) 58#define SHADERS_GET_IMAGE_SHADER(id) _SHADERS_GET_STAGE(IMAGE, id) 59#define SHADERS_GET_COLOR_TRANSFORM_SHADER(id) _SHADERS_GET_STAGE(COLOR_TRANSFORM, id) 60#define SHADERS_GET_ALPHA_SHADER(id) _SHADERS_GET_STAGE(ALPHA, id) 61#define SHADERS_GET_BLEND_SHADER(id) _SHADERS_GET_STAGE(BLEND, id) 62#define SHADERS_GET_MASK_SHADER(id) _SHADERS_GET_STAGE(MASK, id) 63#define SHADERS_GET_PREMULTIPLY_SHADER(id) _SHADERS_GET_STAGE(PREMULTIPLY, id) 64#define SHADERS_GET_BW_SHADER(id) _SHADERS_GET_STAGE(BW, id) 65 66enum VegaShaderType { 67 VEGA_SOLID_FILL_SHADER = 1 << SHADERS_PAINT_SHIFT, 68 VEGA_LINEAR_GRADIENT_SHADER = 2 << SHADERS_PAINT_SHIFT, 69 VEGA_RADIAL_GRADIENT_SHADER = 3 << SHADERS_PAINT_SHIFT, 70 VEGA_PATTERN_SHADER = 4 << SHADERS_PAINT_SHIFT, 71 VEGA_PAINT_DEGENERATE_SHADER = 5 << SHADERS_PAINT_SHIFT, 72 73 VEGA_IMAGE_NORMAL_SHADER = 1 << SHADERS_IMAGE_SHIFT, 74 VEGA_IMAGE_MULTIPLY_SHADER = 2 << SHADERS_IMAGE_SHIFT, 75 VEGA_IMAGE_STENCIL_SHADER = 3 << SHADERS_IMAGE_SHIFT, 76 77 VEGA_COLOR_TRANSFORM_SHADER = 1 << SHADERS_COLOR_TRANSFORM_SHIFT, 78 79 VEGA_ALPHA_NORMAL_SHADER = 1 << SHADERS_ALPHA_SHIFT, 80 VEGA_ALPHA_PER_CHANNEL_SHADER = 2 << SHADERS_ALPHA_SHIFT, 81 82 VEGA_BLEND_MULTIPLY_SHADER = 1 << SHADERS_BLEND_SHIFT, 83 VEGA_BLEND_SCREEN_SHADER = 2 << SHADERS_BLEND_SHIFT, 84 VEGA_BLEND_DARKEN_SHADER = 3 << SHADERS_BLEND_SHIFT, 85 VEGA_BLEND_LIGHTEN_SHADER = 4 << SHADERS_BLEND_SHIFT, 86 87 VEGA_MASK_SHADER = 1 << SHADERS_MASK_SHIFT, 88 89 VEGA_PREMULTIPLY_SHADER = 1 << SHADERS_PREMULTIPLY_SHIFT, 90 VEGA_UNPREMULTIPLY_SHADER = 2 << SHADERS_PREMULTIPLY_SHIFT, 91 92 VEGA_BW_SHADER = 1 << SHADERS_BW_SHIFT 93}; 94 95struct vg_shader { 96 void *driver; 97 struct tgsi_token *tokens; 98 int type;/* PIPE_SHADER_VERTEX, PIPE_SHADER_FRAGMENT */ 99}; 100 101struct shaders_cache *shaders_cache_create(struct vg_context *pipe); 102void shaders_cache_destroy(struct shaders_cache *sc); 103void *shaders_cache_fill(struct shaders_cache *sc, 104 int shader_key); 105 106struct vg_shader *shader_create_from_text(struct pipe_context *pipe, 107 const char *txt, int num_tokens, 108 int type); 109 110void vg_shader_destroy(struct vg_context *ctx, struct vg_shader *shader); 111 112 113 114#endif 115