r600g: add stencil op/func translation
[mesa.git] / src / gallium / drivers / r600 / r600_state_inlines.h
1 /*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef R600_STATE_INLINES_H
24 #define R600_STATE_INLINES_H
25
26 #include "r600_reg.h"
27
28 static INLINE uint32_t r600_translate_blend_function(int blend_func)
29 {
30 switch (blend_func) {
31 case PIPE_BLEND_ADD:
32 return R600_BLEND_FCN_ADD;
33 case PIPE_BLEND_SUBTRACT:
34 return R600_BLEND_FCN_SUBTRACT;
35 case PIPE_BLEND_REVERSE_SUBTRACT:
36 return R600_BLEND_FCN_RSUB;
37 case PIPE_BLEND_MIN:
38 return R600_BLEND_FCN_MIN;
39 case PIPE_BLEND_MAX:
40 return R600_BLEND_FCN_MAX;
41 default:
42 fprintf(stderr, "r600: Unknown blend function %d\n", blend_func);
43 assert(0);
44 break;
45 }
46 return 0;
47 }
48
49 static INLINE uint32_t r600_translate_blend_factor(int blend_fact)
50 {
51 switch (blend_fact) {
52 case PIPE_BLENDFACTOR_ONE:
53 return R600_BLEND_ZERO;
54 case PIPE_BLENDFACTOR_SRC_COLOR:
55 return R600_BLEND_SRC_COLOR;
56 case PIPE_BLENDFACTOR_SRC_ALPHA:
57 return R600_BLEND_SRC_ALPHA;
58 case PIPE_BLENDFACTOR_DST_ALPHA:
59 return R600_BLEND_DST_ALPHA;
60 case PIPE_BLENDFACTOR_DST_COLOR:
61 return R600_BLEND_DST_COLOR;
62 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
63 return R600_BLEND_SRC_ALPHA_SATURATE;
64 case PIPE_BLENDFACTOR_CONST_COLOR:
65 return R600_BLEND_CONST_COLOR;
66 case PIPE_BLENDFACTOR_CONST_ALPHA:
67 return R600_BLEND_CONST_ALPHA;
68 case PIPE_BLENDFACTOR_ZERO:
69 return R600_BLEND_ZERO;
70 case PIPE_BLENDFACTOR_INV_SRC_COLOR:
71 return R600_BLEND_ONE_MINUS_SRC_COLOR;
72 case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
73 return R600_BLEND_ONE_MINUS_SRC_ALPHA;
74 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
75 return R600_BLEND_ONE_MINUS_DST_ALPHA;
76 case PIPE_BLENDFACTOR_INV_DST_COLOR:
77 return R600_BLEND_ONE_MINUS_DST_COLOR;
78 case PIPE_BLENDFACTOR_INV_CONST_COLOR:
79 return R600_BLEND_ONE_MINUS_CONST_COLOR;
80 case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
81 return R600_BLEND_ONE_MINUS_CONST_ALPHA;
82
83 case PIPE_BLENDFACTOR_SRC1_COLOR:
84 return R600_BLEND_SRC1_COLOR;
85 case PIPE_BLENDFACTOR_SRC1_ALPHA:
86 return R600_BLEND_SRC1_ALPHA;
87 case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
88 return R600_BLEND_INV_SRC1_COLOR;
89 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
90 return R600_BLEND_INV_SRC1_ALPHA;
91 default:
92 fprintf(stderr, "r600: Implementation error: "
93 "Bad blend factor %d not supported!\n", blend_fact);
94 assert(0);
95 break;
96 }
97 return 0;
98 }
99
100 static INLINE uint32_t r600_translate_stencil_op(int s_op)
101 {
102 switch (s_op) {
103 case PIPE_STENCIL_OP_KEEP:
104 return R600_ZS_KEEP;
105 case PIPE_STENCIL_OP_ZERO:
106 return R600_ZS_ZERO;
107 case PIPE_STENCIL_OP_REPLACE:
108 return R600_ZS_REPLACE;
109 case PIPE_STENCIL_OP_INCR:
110 return R600_ZS_INCR;
111 case PIPE_STENCIL_OP_DECR:
112 return R600_ZS_DECR;
113 case PIPE_STENCIL_OP_INCR_WRAP:
114 return R600_ZS_INCR_WRAP;
115 case PIPE_STENCIL_OP_DECR_WRAP:
116 return R600_ZS_DECR_WRAP;
117 case PIPE_STENCIL_OP_INVERT:
118 return R600_ZS_INVERT;
119 default:
120 fprintf(stderr, "r600: Unknown stencil op %d", s_op);
121 assert(0);
122 break;
123 }
124 return 0;
125 }
126
127 /* translates straight */
128 static INLINE uint32_t r600_translate_ds_func(int func)
129 {
130 return func;
131 }
132
133 #endif