asm_fill.h revision 544dd4b11f7be76bb00fe29a60eaf2772dcc69ca
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 ASM_FILL_H 28#define ASM_FILL_H 29 30static const char solid_fill_asm[] = 31 "MOV %s, CONST[0]\n"; 32 33 34static const char linear_grad_asm[] = 35 "MOV TEMP[0].xy, IN[0]\n" 36 "MOV TEMP[0].z, CONST[1].yyyy\n" 37 "DP3 TEMP[1], CONST[2], TEMP[0]\n" 38 "DP3 TEMP[2], CONST[3], TEMP[0]\n" 39 "DP3 TEMP[3], CONST[4], TEMP[0]\n" 40 "RCP TEMP[3], TEMP[3]\n" 41 "MUL TEMP[1], TEMP[1], TEMP[3]\n" 42 "MUL TEMP[2], TEMP[2], TEMP[3]\n" 43 "MOV TEMP[4].x, TEMP[1]\n" 44 "MOV TEMP[4].y, TEMP[2]\n" 45 "MUL TEMP[0], CONST[0].yyyy, TEMP[4].yyyy\n" 46 "MAD TEMP[1], CONST[0].xxxx, TEMP[4].xxxx, TEMP[0]\n" 47 "MUL TEMP[2], TEMP[1], CONST[0].zzzz\n" 48 "TEX %s, TEMP[2], SAMP[0], 1D\n"; 49 50static const char radial_grad_asm[] = 51 "MOV TEMP[0].xy, IN[0]\n" 52 "MOV TEMP[0].z, CONST[1].yyyy\n" 53 "DP3 TEMP[1], CONST[2], TEMP[0]\n" 54 "DP3 TEMP[2], CONST[3], TEMP[0]\n" 55 "DP3 TEMP[3], CONST[4], TEMP[0]\n" 56 "RCP TEMP[3], TEMP[3]\n" 57 "MUL TEMP[1], TEMP[1], TEMP[3]\n" 58 "MUL TEMP[2], TEMP[2], TEMP[3]\n" 59 "MOV TEMP[5].x, TEMP[1]\n" 60 "MOV TEMP[5].y, TEMP[2]\n" 61 "MUL TEMP[0], CONST[0].yyyy, TEMP[5].yyyy\n" 62 "MAD TEMP[1], CONST[0].xxxx, TEMP[5].xxxx, TEMP[0]\n" 63 "ADD TEMP[1], TEMP[1], TEMP[1]\n" 64 "MUL TEMP[3], TEMP[5].yyyy, TEMP[5].yyyy\n" 65 "MAD TEMP[4], TEMP[5].xxxx, TEMP[5].xxxx, TEMP[3]\n" 66 "MOV TEMP[4], -TEMP[4]\n" 67 "MUL TEMP[2], CONST[0].zzzz, TEMP[4]\n" 68 "MUL TEMP[0], CONST[1].wwww, TEMP[2]\n" 69 "MUL TEMP[3], TEMP[1], TEMP[1]\n" 70 "SUB TEMP[2], TEMP[3], TEMP[0]\n" 71 "RSQ TEMP[2], |TEMP[2]|\n" 72 "RCP TEMP[2], TEMP[2]\n" 73 "SUB TEMP[1], TEMP[2], TEMP[1]\n" 74 "ADD TEMP[0], CONST[0].zzzz, CONST[0].zzzz\n" 75 "RCP TEMP[0], TEMP[0]\n" 76 "MUL TEMP[2], TEMP[1], TEMP[0]\n" 77 "TEX %s, TEMP[2], SAMP[0], 1D\n"; 78 79static const char pattern_asm[] = 80 "MOV TEMP[0].xy, IN[0]\n" 81 "MOV TEMP[0].z, CONST[1].yyyy\n" 82 "DP3 TEMP[1], CONST[2], TEMP[0]\n" 83 "DP3 TEMP[2], CONST[3], TEMP[0]\n" 84 "DP3 TEMP[3], CONST[4], TEMP[0]\n" 85 "RCP TEMP[3], TEMP[3]\n" 86 "MUL TEMP[1], TEMP[1], TEMP[3]\n" 87 "MUL TEMP[2], TEMP[2], TEMP[3]\n" 88 "MOV TEMP[4].x, TEMP[1]\n" 89 "MOV TEMP[4].y, TEMP[2]\n" 90 "RCP TEMP[0], CONST[1].zwzw\n" 91 "MOV TEMP[1], TEMP[4]\n" 92 "MUL TEMP[1].x, TEMP[1], TEMP[0]\n" 93 "MUL TEMP[1].y, TEMP[1], TEMP[0]\n" 94 "TEX %s, TEMP[1], SAMP[0], 2D\n"; 95 96 97static const char mask_asm[] = 98 "TEX TEMP[1], IN[0], SAMP[1], 2D\n" 99 "MUL TEMP[0].w, TEMP[0].wwww, TEMP[1].wwww\n" 100 "MOV %s, TEMP[0]\n"; 101 102 103static const char image_normal_asm[] = 104 "TEX %s, IN[1], SAMP[3], 2D\n"; 105 106static const char image_multiply_asm[] = 107 "TEX TEMP[1], IN[1], SAMP[3], 2D\n" 108 "MUL %s, TEMP[0], TEMP[1]\n"; 109 110static const char image_stencil_asm[] = 111 "TEX TEMP[1], IN[1], SAMP[3], 2D\n" 112 "MUL %s, TEMP[0], TEMP[1]\n"; 113 114 115#define EXTENDED_BLEND_OVER \ 116 "SUB TEMP[3], CONST[1].yyyy, TEMP[1].wwww\n" \ 117 "SUB TEMP[4], CONST[1].yyyy, TEMP[0].wwww\n" \ 118 "MUL TEMP[3], TEMP[0], TEMP[3]\n" \ 119 "MUL TEMP[4], TEMP[1], TEMP[4]\n" \ 120 "ADD TEMP[3], TEMP[3], TEMP[4]\n" 121 122static const char blend_multiply_asm[] = 123 "TEX TEMP[1], IN[0], SAMP[2], 2D\n" 124 EXTENDED_BLEND_OVER 125 "MUL TEMP[4], TEMP[0], TEMP[1]\n" 126 "ADD TEMP[1], TEMP[4], TEMP[3]\n"/*result.rgb*/ 127 "MUL TEMP[2], TEMP[0].wwww, TEMP[1].wwww\n" 128 "ADD TEMP[3], TEMP[0].wwww, TEMP[1].wwww\n" 129 "SUB TEMP[1].w, TEMP[3], TEMP[2]\n" 130 "MOV %s, TEMP[1]\n"; 131#if 1 132static const char blend_screen_asm[] = 133 "TEX TEMP[1], IN[0], SAMP[2], 2D\n" 134 "ADD TEMP[3], TEMP[0], TEMP[1]\n" 135 "MUL TEMP[2], TEMP[0], TEMP[1]\n" 136 "SUB %s, TEMP[3], TEMP[2]\n"; 137#else 138static const char blend_screen_asm[] = 139 "TEX TEMP[1], IN[0], SAMP[2], 2D\n" 140 "MOV %s, TEMP[1]\n"; 141#endif 142 143static const char blend_darken_asm[] = 144 "TEX TEMP[1], IN[0], SAMP[2], 2D\n" 145 EXTENDED_BLEND_OVER 146 "MUL TEMP[4], TEMP[0], TEMP[1].wwww\n" 147 "MUL TEMP[5], TEMP[1], TEMP[0].wwww\n" 148 "MIN TEMP[4], TEMP[4], TEMP[5]\n" 149 "ADD TEMP[1], TEMP[3], TEMP[4]\n" 150 "MUL TEMP[2], TEMP[0].wwww, TEMP[1].wwww\n" 151 "ADD TEMP[3], TEMP[0].wwww, TEMP[1].wwww\n" 152 "SUB TEMP[1].w, TEMP[3], TEMP[2]\n" 153 "MOV %s, TEMP[1]\n"; 154 155static const char blend_lighten_asm[] = 156 "TEX TEMP[1], IN[0], SAMP[2], 2D\n" 157 EXTENDED_BLEND_OVER 158 "MUL TEMP[4], TEMP[0], TEMP[1].wwww\n" 159 "MUL TEMP[5], TEMP[1], TEMP[0].wwww\n" 160 "MAX TEMP[4], TEMP[4], TEMP[5]\n" 161 "ADD TEMP[1], TEMP[3], TEMP[4]\n" 162 "MUL TEMP[2], TEMP[0].wwww, TEMP[1].wwww\n" 163 "ADD TEMP[3], TEMP[0].wwww, TEMP[1].wwww\n" 164 "SUB TEMP[1].w, TEMP[3], TEMP[2]\n" 165 "MOV %s, TEMP[1]\n"; 166 167 168static const char premultiply_asm[] = 169 "MUL TEMP[0].xyz, TEMP[0], TEMP[0].wwww\n"; 170 171static const char unpremultiply_asm[] = 172 "TEX TEMP[0], IN[0], SAMP[1], 2D\n"; 173 174 175static const char color_bw_asm[] = 176 "ADD TEMP[1], CONST[1].yyyy, CONST[1].yyyy\n" 177 "RCP TEMP[2], TEMP[1]\n" 178 "ADD TEMP[1], CONST[1].yyyy, TEMP[2]\n" 179 "ADD TEMP[2].x, TEMP[0].xxxx, TEMP[0].yyyy\n" 180 "ADD TEMP[2].x, TEMP[0].zzzz, TEMP[0].xxxx\n" 181 "SGE TEMP[0].xyz, TEMP[2].xxxx, TEMP[1]\n" 182 "SGE TEMP[0].w, TEMP[0].wwww, TEMP[2].yyyy\n" 183 "MOV %s, TEMP[0]\n"; 184 185 186struct shader_asm_info { 187 VGint id; 188 VGint num_tokens; 189 const char * txt; 190 191 VGboolean needs_position; 192 193 VGint start_const; 194 VGint num_consts; 195 196 VGint start_sampler; 197 VGint num_samplers; 198 199 VGint start_temp; 200 VGint num_temps; 201}; 202 203 204static const struct shader_asm_info shaders_asm[] = { 205 /* fills */ 206 {VEGA_SOLID_FILL_SHADER, 40, solid_fill_asm, 207 VG_FALSE, 0, 1, 0, 0, 0, 0}, 208 {VEGA_LINEAR_GRADIENT_SHADER, 200, linear_grad_asm, 209 VG_TRUE, 0, 5, 0, 1, 0, 5}, 210 {VEGA_RADIAL_GRADIENT_SHADER, 200, radial_grad_asm, 211 VG_TRUE, 0, 5, 0, 1, 0, 6}, 212 {VEGA_PATTERN_SHADER, 100, pattern_asm, 213 VG_TRUE, 1, 4, 0, 1, 0, 5}, 214 215 /* image draw modes */ 216 {VEGA_IMAGE_NORMAL_SHADER, 200, image_normal_asm, 217 VG_TRUE, 0, 0, 3, 1, 0, 0}, 218 {VEGA_IMAGE_MULTIPLY_SHADER, 200, image_multiply_asm, 219 VG_TRUE, 0, 0, 3, 1, 0, 2}, 220 {VEGA_IMAGE_STENCIL_SHADER, 200, image_stencil_asm, 221 VG_TRUE, 0, 0, 3, 1, 0, 2}, 222 223 {VEGA_MASK_SHADER, 100, mask_asm, 224 VG_TRUE, 0, 0, 1, 1, 0, 2}, 225 226 /* extra blend modes */ 227 {VEGA_BLEND_MULTIPLY_SHADER, 200, blend_multiply_asm, 228 VG_TRUE, 1, 1, 2, 1, 0, 5}, 229 {VEGA_BLEND_SCREEN_SHADER, 200, blend_screen_asm, 230 VG_TRUE, 0, 0, 2, 1, 0, 4}, 231 {VEGA_BLEND_DARKEN_SHADER, 200, blend_darken_asm, 232 VG_TRUE, 1, 1, 2, 1, 0, 6}, 233 {VEGA_BLEND_LIGHTEN_SHADER, 200, blend_lighten_asm, 234 VG_TRUE, 1, 1, 2, 1, 0, 6}, 235 236 /* premultiply */ 237 {VEGA_PREMULTIPLY_SHADER, 100, premultiply_asm, 238 VG_FALSE, 0, 0, 0, 0, 0, 1}, 239 {VEGA_UNPREMULTIPLY_SHADER, 100, unpremultiply_asm, 240 VG_FALSE, 0, 0, 0, 0, 0, 1}, 241 242 /* color transform to black and white */ 243 {VEGA_BW_SHADER, 150, color_bw_asm, 244 VG_FALSE, 1, 1, 0, 0, 0, 3}, 245}; 246#endif 247