1 #include "xorg_exa_tgsi.h"
3 /*### stupidity defined in X11/extensions/XI.h */
6 #include "pipe/p_format.h"
7 #include "pipe/p_context.h"
8 #include "pipe/p_state.h"
9 #include "pipe/p_inlines.h"
10 #include "pipe/p_shader_tokens.h"
12 #include "util/u_memory.h"
13 #include "util/u_simple_shaders.h"
15 #include "tgsi/tgsi_ureg.h"
17 #include "cso_cache/cso_context.h"
18 #include "cso_cache/cso_hash.h"
22 * IN[1] = src tex coord | solid fill color
23 * IN[2] = mask tex coord
24 * IN[3] = dst tex coord
25 * CONST[0] = (2/dst_width, 2/dst_height, 1, 1)
26 * CONST[1] = (-1, -1, 0, 0)
29 * OUT[1] = src tex coord | solid fill color
30 * OUT[2] = mask tex coord
31 * OUT[3] = dst tex coord
38 * IN[0] = pos src | solid fill color
41 * CONST[0] = (0, 0, 0, 1)
47 print_fs_traits(int fs_traits
)
49 const char *strings
[] = {
50 "FS_COMPOSITE", /* = 1 << 0 */
51 "FS_MASK", /* = 1 << 1 */
52 "FS_SOLID_FILL", /* = 1 << 2 */
53 "FS_LINGRAD_FILL", /* = 1 << 3 */
54 "FS_RADGRAD_FILL", /* = 1 << 4 */
55 "FS_CA_FULL", /* = 1 << 5 - src.rgba * mask.rgba */
56 "FS_CA_SRCALPHA", /* = 1 << 6 - src.aaaa * mask.rgba */
57 "FS_YUV", /* = 1 << 7 */
58 "FS_SRC_REPEAT_NONE", /* = 1 << 8 */
59 "FS_MASK_REPEAT_NONE",/* = 1 << 9 */
60 "FS_SRC_SWIZZLE_RGB", /* = 1 << 10 */
61 "FS_MASK_SWIZZLE_RGB",/* = 1 << 11 */
62 "FS_SRC_SET_ALPHA", /* = 1 << 12 */
63 "FS_MASK_SET_ALPHA", /* = 1 << 13 */
64 "FS_SRC_LUMINANCE", /* = 1 << 14 */
65 "FS_MASK_LUMINANCE", /* = 1 << 15 */
68 debug_printf("%s: ", __func__
);
70 for (i
= 0, k
= 1; k
< (1 << 16); i
++, k
<<= 1) {
72 debug_printf("%s, ", strings
[i
]);
79 struct xorg_renderer
*r
;
81 struct cso_hash
*vs_hash
;
82 struct cso_hash
*fs_hash
;
86 src_in_mask(struct ureg_program
*ureg
,
90 unsigned component_alpha
,
91 unsigned mask_luminance
)
93 if (component_alpha
== FS_CA_FULL
) {
94 ureg_MUL(ureg
, dst
, src
, mask
);
95 } else if (component_alpha
== FS_CA_SRCALPHA
) {
97 ureg_scalar(src
, TGSI_SWIZZLE_W
), mask
);
101 ureg_MUL(ureg
, dst
, src
,
102 ureg_scalar(mask
, TGSI_SWIZZLE_X
));
104 ureg_MUL(ureg
, dst
, src
,
105 ureg_scalar(mask
, TGSI_SWIZZLE_W
));
109 static struct ureg_src
110 vs_normalize_coords(struct ureg_program
*ureg
, struct ureg_src coords
,
111 struct ureg_src const0
, struct ureg_src const1
)
113 struct ureg_dst tmp
= ureg_DECL_temporary(ureg
);
115 ureg_MAD(ureg
, tmp
, coords
, const0
, const1
);
117 ureg_release_temporary(ureg
, tmp
);
122 linear_gradient(struct ureg_program
*ureg
,
125 struct ureg_src sampler
,
126 struct ureg_src coords
,
127 struct ureg_src const0124
,
128 struct ureg_src matrow0
,
129 struct ureg_src matrow1
,
130 struct ureg_src matrow2
)
132 struct ureg_dst temp0
= ureg_DECL_temporary(ureg
);
133 struct ureg_dst temp1
= ureg_DECL_temporary(ureg
);
134 struct ureg_dst temp2
= ureg_DECL_temporary(ureg
);
135 struct ureg_dst temp3
= ureg_DECL_temporary(ureg
);
136 struct ureg_dst temp4
= ureg_DECL_temporary(ureg
);
137 struct ureg_dst temp5
= ureg_DECL_temporary(ureg
);
140 ureg_writemask(temp0
, TGSI_WRITEMASK_XY
), pos
);
142 ureg_writemask(temp0
, TGSI_WRITEMASK_Z
),
143 ureg_scalar(const0124
, TGSI_SWIZZLE_Y
));
145 ureg_DP3(ureg
, temp1
, matrow0
, ureg_src(temp0
));
146 ureg_DP3(ureg
, temp2
, matrow1
, ureg_src(temp0
));
147 ureg_DP3(ureg
, temp3
, matrow2
, ureg_src(temp0
));
148 ureg_RCP(ureg
, temp3
, ureg_src(temp3
));
149 ureg_MUL(ureg
, temp1
, ureg_src(temp1
), ureg_src(temp3
));
150 ureg_MUL(ureg
, temp2
, ureg_src(temp2
), ureg_src(temp3
));
152 ureg_MOV(ureg
, ureg_writemask(temp4
, TGSI_WRITEMASK_X
),
154 ureg_MOV(ureg
, ureg_writemask(temp4
, TGSI_WRITEMASK_Y
),
157 ureg_MUL(ureg
, temp0
,
158 ureg_scalar(coords
, TGSI_SWIZZLE_Y
),
159 ureg_scalar(ureg_src(temp4
), TGSI_SWIZZLE_Y
));
160 ureg_MAD(ureg
, temp1
,
161 ureg_scalar(coords
, TGSI_SWIZZLE_X
),
162 ureg_scalar(ureg_src(temp4
), TGSI_SWIZZLE_X
),
165 ureg_MUL(ureg
, temp2
,
167 ureg_scalar(coords
, TGSI_SWIZZLE_Z
));
170 TGSI_TEXTURE_1D
, ureg_src(temp2
), sampler
);
172 ureg_release_temporary(ureg
, temp0
);
173 ureg_release_temporary(ureg
, temp1
);
174 ureg_release_temporary(ureg
, temp2
);
175 ureg_release_temporary(ureg
, temp3
);
176 ureg_release_temporary(ureg
, temp4
);
177 ureg_release_temporary(ureg
, temp5
);
182 radial_gradient(struct ureg_program
*ureg
,
185 struct ureg_src sampler
,
186 struct ureg_src coords
,
187 struct ureg_src const0124
,
188 struct ureg_src matrow0
,
189 struct ureg_src matrow1
,
190 struct ureg_src matrow2
)
192 struct ureg_dst temp0
= ureg_DECL_temporary(ureg
);
193 struct ureg_dst temp1
= ureg_DECL_temporary(ureg
);
194 struct ureg_dst temp2
= ureg_DECL_temporary(ureg
);
195 struct ureg_dst temp3
= ureg_DECL_temporary(ureg
);
196 struct ureg_dst temp4
= ureg_DECL_temporary(ureg
);
197 struct ureg_dst temp5
= ureg_DECL_temporary(ureg
);
200 ureg_writemask(temp0
, TGSI_WRITEMASK_XY
),
203 ureg_writemask(temp0
, TGSI_WRITEMASK_Z
),
204 ureg_scalar(const0124
, TGSI_SWIZZLE_Y
));
206 ureg_DP3(ureg
, temp1
, matrow0
, ureg_src(temp0
));
207 ureg_DP3(ureg
, temp2
, matrow1
, ureg_src(temp0
));
208 ureg_DP3(ureg
, temp3
, matrow2
, ureg_src(temp0
));
209 ureg_RCP(ureg
, temp3
, ureg_src(temp3
));
210 ureg_MUL(ureg
, temp1
, ureg_src(temp1
), ureg_src(temp3
));
211 ureg_MUL(ureg
, temp2
, ureg_src(temp2
), ureg_src(temp3
));
213 ureg_MOV(ureg
, ureg_writemask(temp5
, TGSI_WRITEMASK_X
),
215 ureg_MOV(ureg
, ureg_writemask(temp5
, TGSI_WRITEMASK_Y
),
218 ureg_MUL(ureg
, temp0
, ureg_scalar(coords
, TGSI_SWIZZLE_Y
),
219 ureg_scalar(ureg_src(temp5
), TGSI_SWIZZLE_Y
));
220 ureg_MAD(ureg
, temp1
,
221 ureg_scalar(coords
, TGSI_SWIZZLE_X
),
222 ureg_scalar(ureg_src(temp5
), TGSI_SWIZZLE_X
),
224 ureg_ADD(ureg
, temp1
,
225 ureg_src(temp1
), ureg_src(temp1
));
226 ureg_MUL(ureg
, temp3
,
227 ureg_scalar(ureg_src(temp5
), TGSI_SWIZZLE_Y
),
228 ureg_scalar(ureg_src(temp5
), TGSI_SWIZZLE_Y
));
229 ureg_MAD(ureg
, temp4
,
230 ureg_scalar(ureg_src(temp5
), TGSI_SWIZZLE_X
),
231 ureg_scalar(ureg_src(temp5
), TGSI_SWIZZLE_X
),
233 ureg_MOV(ureg
, temp4
, ureg_negate(ureg_src(temp4
)));
234 ureg_MUL(ureg
, temp2
,
235 ureg_scalar(coords
, TGSI_SWIZZLE_Z
),
237 ureg_MUL(ureg
, temp0
,
238 ureg_scalar(const0124
, TGSI_SWIZZLE_W
),
240 ureg_MUL(ureg
, temp3
,
241 ureg_src(temp1
), ureg_src(temp1
));
242 ureg_SUB(ureg
, temp2
,
243 ureg_src(temp3
), ureg_src(temp0
));
244 ureg_RSQ(ureg
, temp2
, ureg_abs(ureg_src(temp2
)));
245 ureg_RCP(ureg
, temp2
, ureg_src(temp2
));
246 ureg_SUB(ureg
, temp1
,
247 ureg_src(temp2
), ureg_src(temp1
));
248 ureg_ADD(ureg
, temp0
,
249 ureg_scalar(coords
, TGSI_SWIZZLE_Z
),
250 ureg_scalar(coords
, TGSI_SWIZZLE_Z
));
251 ureg_RCP(ureg
, temp0
, ureg_src(temp0
));
252 ureg_MUL(ureg
, temp2
,
253 ureg_src(temp1
), ureg_src(temp0
));
254 ureg_TEX(ureg
, out
, TGSI_TEXTURE_1D
,
255 ureg_src(temp2
), sampler
);
257 ureg_release_temporary(ureg
, temp0
);
258 ureg_release_temporary(ureg
, temp1
);
259 ureg_release_temporary(ureg
, temp2
);
260 ureg_release_temporary(ureg
, temp3
);
261 ureg_release_temporary(ureg
, temp4
);
262 ureg_release_temporary(ureg
, temp5
);
266 create_vs(struct pipe_context
*pipe
,
269 struct ureg_program
*ureg
;
272 struct ureg_src const0
, const1
;
273 boolean is_fill
= (vs_traits
& VS_FILL
) != 0;
274 boolean is_composite
= (vs_traits
& VS_COMPOSITE
) != 0;
275 boolean has_mask
= (vs_traits
& VS_MASK
) != 0;
276 boolean is_yuv
= (vs_traits
& VS_YUV
) != 0;
277 unsigned input_slot
= 0;
279 ureg
= ureg_create(TGSI_PROCESSOR_VERTEX
);
283 const0
= ureg_DECL_constant(ureg
, 0);
284 const1
= ureg_DECL_constant(ureg
, 1);
286 /* it has to be either a fill or a composite op */
287 debug_assert((is_fill
^ is_composite
) ^ is_yuv
);
289 src
= ureg_DECL_vs_input(ureg
, input_slot
++);
290 dst
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_POSITION
, 0);
291 src
= vs_normalize_coords(ureg
, src
,
293 ureg_MOV(ureg
, dst
, src
);
296 src
= ureg_DECL_vs_input(ureg
, input_slot
++);
297 dst
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 0);
298 ureg_MOV(ureg
, dst
, src
);
302 src
= ureg_DECL_vs_input(ureg
, input_slot
++);
303 dst
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 0);
304 ureg_MOV(ureg
, dst
, src
);
308 src
= ureg_DECL_vs_input(ureg
, input_slot
++);
309 dst
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_COLOR
, 0);
310 ureg_MOV(ureg
, dst
, src
);
314 src
= ureg_DECL_vs_input(ureg
, input_slot
++);
315 dst
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_GENERIC
, 1);
316 ureg_MOV(ureg
, dst
, src
);
321 return ureg_create_shader_and_destroy(ureg
, pipe
);
325 create_yuv_shader(struct pipe_context
*pipe
, struct ureg_program
*ureg
)
327 struct ureg_src y_sampler
, u_sampler
, v_sampler
;
329 struct ureg_src matrow0
, matrow1
, matrow2
;
330 struct ureg_dst y
, u
, v
, rgb
;
331 struct ureg_dst out
= ureg_DECL_output(ureg
,
335 pos
= ureg_DECL_fs_input(ureg
,
336 TGSI_SEMANTIC_GENERIC
,
338 TGSI_INTERPOLATE_PERSPECTIVE
);
340 rgb
= ureg_DECL_temporary(ureg
);
341 y
= ureg_DECL_temporary(ureg
);
342 u
= ureg_DECL_temporary(ureg
);
343 v
= ureg_DECL_temporary(ureg
);
345 y_sampler
= ureg_DECL_sampler(ureg
, 0);
346 u_sampler
= ureg_DECL_sampler(ureg
, 1);
347 v_sampler
= ureg_DECL_sampler(ureg
, 2);
349 matrow0
= ureg_DECL_constant(ureg
, 0);
350 matrow1
= ureg_DECL_constant(ureg
, 1);
351 matrow2
= ureg_DECL_constant(ureg
, 2);
354 TGSI_TEXTURE_2D
, pos
, y_sampler
);
356 TGSI_TEXTURE_2D
, pos
, u_sampler
);
358 TGSI_TEXTURE_2D
, pos
, v_sampler
);
360 ureg_SUB(ureg
, u
, ureg_src(u
),
361 ureg_scalar(matrow0
, TGSI_SWIZZLE_W
));
362 ureg_SUB(ureg
, v
, ureg_src(v
),
363 ureg_scalar(matrow0
, TGSI_SWIZZLE_W
));
366 ureg_scalar(ureg_src(y
), TGSI_SWIZZLE_X
),
369 ureg_scalar(ureg_src(u
), TGSI_SWIZZLE_X
),
373 ureg_scalar(ureg_src(v
), TGSI_SWIZZLE_X
),
378 ureg_MOV(ureg
, ureg_writemask(rgb
, TGSI_WRITEMASK_W
),
379 ureg_scalar(matrow0
, TGSI_SWIZZLE_X
));
381 ureg_MOV(ureg
, out
, ureg_src(rgb
));
383 ureg_release_temporary(ureg
, rgb
);
384 ureg_release_temporary(ureg
, y
);
385 ureg_release_temporary(ureg
, u
);
386 ureg_release_temporary(ureg
, v
);
390 return ureg_create_shader_and_destroy(ureg
, pipe
);
395 xrender_tex(struct ureg_program
*ureg
,
397 struct ureg_src coords
,
398 struct ureg_src sampler
,
399 struct ureg_src imm0
,
405 struct ureg_dst tmp0
= ureg_DECL_temporary(ureg
);
406 struct ureg_dst tmp1
= ureg_DECL_temporary(ureg
);
407 ureg_SGT(ureg
, tmp1
, ureg_swizzle(coords
,
412 ureg_scalar(imm0
, TGSI_SWIZZLE_X
));
413 ureg_SLT(ureg
, tmp0
, ureg_swizzle(coords
,
418 ureg_scalar(imm0
, TGSI_SWIZZLE_W
));
419 ureg_MIN(ureg
, tmp0
, ureg_src(tmp0
), ureg_src(tmp1
));
420 ureg_MIN(ureg
, tmp0
, ureg_scalar(ureg_src(tmp0
), TGSI_SWIZZLE_X
),
421 ureg_scalar(ureg_src(tmp0
), TGSI_SWIZZLE_Y
));
422 ureg_TEX(ureg
, tmp1
, TGSI_TEXTURE_2D
, coords
, sampler
);
424 ureg_MOV(ureg
, tmp1
, ureg_swizzle(ureg_src(tmp1
),
431 ureg_writemask(tmp1
, TGSI_WRITEMASK_W
),
432 ureg_scalar(imm0
, TGSI_SWIZZLE_W
));
433 ureg_MUL(ureg
, dst
, ureg_src(tmp1
), ureg_src(tmp0
));
434 ureg_release_temporary(ureg
, tmp0
);
435 ureg_release_temporary(ureg
, tmp1
);
438 struct ureg_dst tmp
= ureg_DECL_temporary(ureg
);
439 ureg_TEX(ureg
, tmp
, TGSI_TEXTURE_2D
, coords
, sampler
);
440 ureg_MOV(ureg
, dst
, ureg_swizzle(ureg_src(tmp
),
445 ureg_release_temporary(ureg
, tmp
);
447 ureg_TEX(ureg
, dst
, TGSI_TEXTURE_2D
, coords
, sampler
);
451 ureg_writemask(dst
, TGSI_WRITEMASK_W
),
452 ureg_scalar(imm0
, TGSI_SWIZZLE_W
));
457 create_fs(struct pipe_context
*pipe
,
460 struct ureg_program
*ureg
;
461 struct ureg_src
/*dst_sampler,*/ src_sampler
, mask_sampler
;
462 struct ureg_src
/*dst_pos,*/ src_input
, mask_pos
;
463 struct ureg_dst src
, mask
;
465 struct ureg_src imm0
= { 0 };
466 unsigned has_mask
= (fs_traits
& FS_MASK
) != 0;
467 unsigned is_fill
= (fs_traits
& FS_FILL
) != 0;
468 unsigned is_composite
= (fs_traits
& FS_COMPOSITE
) != 0;
469 unsigned is_solid
= (fs_traits
& FS_SOLID_FILL
) != 0;
470 unsigned is_lingrad
= (fs_traits
& FS_LINGRAD_FILL
) != 0;
471 unsigned is_radgrad
= (fs_traits
& FS_RADGRAD_FILL
) != 0;
472 unsigned comp_alpha_mask
= fs_traits
& FS_COMPONENT_ALPHA
;
473 unsigned is_yuv
= (fs_traits
& FS_YUV
) != 0;
474 unsigned src_repeat_none
= (fs_traits
& FS_SRC_REPEAT_NONE
) != 0;
475 unsigned mask_repeat_none
= (fs_traits
& FS_MASK_REPEAT_NONE
) != 0;
476 unsigned src_swizzle
= (fs_traits
& FS_SRC_SWIZZLE_RGB
) != 0;
477 unsigned mask_swizzle
= (fs_traits
& FS_MASK_SWIZZLE_RGB
) != 0;
478 unsigned src_set_alpha
= (fs_traits
& FS_SRC_SET_ALPHA
) != 0;
479 unsigned mask_set_alpha
= (fs_traits
& FS_MASK_SET_ALPHA
) != 0;
480 unsigned src_luminance
= (fs_traits
& FS_SRC_LUMINANCE
) != 0;
481 unsigned mask_luminance
= (fs_traits
& FS_MASK_LUMINANCE
) != 0;
484 print_fs_traits(fs_traits
);
486 (void)print_fs_traits
;
489 ureg
= ureg_create(TGSI_PROCESSOR_FRAGMENT
);
493 /* it has to be either a fill, a composite op or a yuv conversion */
494 debug_assert((is_fill
^ is_composite
) ^ is_yuv
);
496 out
= ureg_DECL_output(ureg
,
500 if (src_repeat_none
|| mask_repeat_none
||
501 src_set_alpha
|| mask_set_alpha
||
503 imm0
= ureg_imm4f(ureg
, 0, 0, 0, 1);
506 src_sampler
= ureg_DECL_sampler(ureg
, 0);
507 src_input
= ureg_DECL_fs_input(ureg
,
508 TGSI_SEMANTIC_GENERIC
,
510 TGSI_INTERPOLATE_PERSPECTIVE
);
511 } else if (is_fill
) {
513 src_input
= ureg_DECL_fs_input(ureg
,
516 TGSI_INTERPOLATE_PERSPECTIVE
);
518 src_input
= ureg_DECL_fs_input(ureg
,
519 TGSI_SEMANTIC_POSITION
,
521 TGSI_INTERPOLATE_PERSPECTIVE
);
523 debug_assert(is_yuv
);
524 return create_yuv_shader(pipe
, ureg
);
528 mask_sampler
= ureg_DECL_sampler(ureg
, 1);
529 mask_pos
= ureg_DECL_fs_input(ureg
,
530 TGSI_SEMANTIC_GENERIC
,
532 TGSI_INTERPOLATE_PERSPECTIVE
);
535 #if 0 /* unused right now */
536 dst_sampler
= ureg_DECL_sampler(ureg
, 2);
537 dst_pos
= ureg_DECL_fs_input(ureg
,
538 TGSI_SEMANTIC_POSITION
,
540 TGSI_INTERPOLATE_PERSPECTIVE
);
545 if (has_mask
|| src_luminance
)
546 src
= ureg_DECL_temporary(ureg
);
549 xrender_tex(ureg
, src
, src_input
, src_sampler
, imm0
,
550 src_repeat_none
, src_swizzle
, src_set_alpha
);
551 } else if (is_fill
) {
553 if (has_mask
|| src_luminance
)
554 src
= ureg_dst(src_input
);
556 ureg_MOV(ureg
, out
, src_input
);
557 } else if (is_lingrad
|| is_radgrad
) {
558 struct ureg_src coords
, const0124
,
559 matrow0
, matrow1
, matrow2
;
561 if (has_mask
|| src_luminance
)
562 src
= ureg_DECL_temporary(ureg
);
566 coords
= ureg_DECL_constant(ureg
, 0);
567 const0124
= ureg_DECL_constant(ureg
, 1);
568 matrow0
= ureg_DECL_constant(ureg
, 2);
569 matrow1
= ureg_DECL_constant(ureg
, 3);
570 matrow2
= ureg_DECL_constant(ureg
, 4);
573 linear_gradient(ureg
, src
,
574 src_input
, src_sampler
,
576 matrow0
, matrow1
, matrow2
);
577 } else if (is_radgrad
) {
578 radial_gradient(ureg
, src
,
579 src_input
, src_sampler
,
581 matrow0
, matrow1
, matrow2
);
584 debug_assert(!"Unknown fill type!");
588 ureg_scalar(ureg_src(src
), TGSI_SWIZZLE_X
));
589 ureg_MOV(ureg
, ureg_writemask(src
, TGSI_WRITEMASK_XYZ
),
590 ureg_scalar(imm0
, TGSI_SWIZZLE_X
));
592 ureg_MOV(ureg
, out
, ureg_src(src
));
596 mask
= ureg_DECL_temporary(ureg
);
597 xrender_tex(ureg
, mask
, mask_pos
, mask_sampler
, imm0
,
598 mask_repeat_none
, mask_swizzle
, mask_set_alpha
);
600 src_in_mask(ureg
, out
, ureg_src(src
), ureg_src(mask
),
601 comp_alpha_mask
, mask_luminance
);
602 ureg_release_temporary(ureg
, mask
);
607 return ureg_create_shader_and_destroy(ureg
, pipe
);
610 struct xorg_shaders
* xorg_shaders_create(struct xorg_renderer
*r
)
612 struct xorg_shaders
*sc
= CALLOC_STRUCT(xorg_shaders
);
615 sc
->vs_hash
= cso_hash_create();
616 sc
->fs_hash
= cso_hash_create();
622 cache_destroy(struct cso_context
*cso
,
623 struct cso_hash
*hash
,
626 struct cso_hash_iter iter
= cso_hash_first_node(hash
);
627 while (!cso_hash_iter_is_null(iter
)) {
628 void *shader
= (void *)cso_hash_iter_data(iter
);
629 if (processor
== PIPE_SHADER_FRAGMENT
) {
630 cso_delete_fragment_shader(cso
, shader
);
631 } else if (processor
== PIPE_SHADER_VERTEX
) {
632 cso_delete_vertex_shader(cso
, shader
);
634 iter
= cso_hash_erase(hash
, iter
);
636 cso_hash_delete(hash
);
639 void xorg_shaders_destroy(struct xorg_shaders
*sc
)
641 cache_destroy(sc
->r
->cso
, sc
->vs_hash
,
643 cache_destroy(sc
->r
->cso
, sc
->fs_hash
,
644 PIPE_SHADER_FRAGMENT
);
650 shader_from_cache(struct pipe_context
*pipe
,
652 struct cso_hash
*hash
,
657 struct cso_hash_iter iter
= cso_hash_find(hash
, key
);
659 if (cso_hash_iter_is_null(iter
)) {
660 if (type
== PIPE_SHADER_VERTEX
)
661 shader
= create_vs(pipe
, key
);
663 shader
= create_fs(pipe
, key
);
664 cso_hash_insert(hash
, key
, shader
);
666 shader
= (void *)cso_hash_iter_data(iter
);
671 struct xorg_shader
xorg_shaders_get(struct xorg_shaders
*sc
,
675 struct xorg_shader shader
= { NULL
, NULL
};
678 vs
= shader_from_cache(sc
->r
->pipe
, PIPE_SHADER_VERTEX
,
679 sc
->vs_hash
, vs_traits
);
680 fs
= shader_from_cache(sc
->r
->pipe
, PIPE_SHADER_FRAGMENT
,
681 sc
->fs_hash
, fs_traits
);
683 debug_assert(vs
&& fs
);