1 /****************************************************************************
2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 ***************************************************************************/
24 // llvm redefines DEBUG
25 #pragma push_macro("DEBUG")
27 #include "JitManager.h"
28 #pragma pop_macro("DEBUG")
30 #include "common/os.h"
32 #include "gen_state_llvm.h"
33 #include "core/multisample.h"
35 #include "gallivm/lp_bld_tgsi.h"
36 #include "util/u_format.h"
38 #include "util/u_memory.h"
39 #include "util/u_inlines.h"
40 #include "util/u_helpers.h"
41 #include "util/u_framebuffer.h"
42 #include "util/u_viewport.h"
43 #include "util/u_prim.h"
45 #include "swr_state.h"
46 #include "swr_context.h"
47 #include "gen_swr_context_llvm.h"
48 #include "swr_screen.h"
49 #include "swr_resource.h"
50 #include "swr_tex_sample.h"
51 #include "swr_scratch.h"
52 #include "swr_shader.h"
53 #include "swr_fence.h"
55 /* These should be pulled out into separate files as necessary
56 * Just initializing everything here to get going. */
59 swr_create_blend_state(struct pipe_context
*pipe
,
60 const struct pipe_blend_state
*blend
)
62 struct swr_blend_state
*state
= CALLOC_STRUCT(swr_blend_state
);
64 memcpy(&state
->pipe
, blend
, sizeof(*blend
));
66 struct pipe_blend_state
*pipe_blend
= &state
->pipe
;
69 target
< std::min(SWR_NUM_RENDERTARGETS
, PIPE_MAX_COLOR_BUFS
);
72 struct pipe_rt_blend_state
*rt_blend
= &pipe_blend
->rt
[target
];
73 SWR_RENDER_TARGET_BLEND_STATE
&blendState
=
74 state
->blendState
.renderTarget
[target
];
75 RENDER_TARGET_BLEND_COMPILE_STATE
&compileState
=
76 state
->compileState
[target
];
78 if (target
!= 0 && !pipe_blend
->independent_blend_enable
) {
80 &state
->compileState
[0],
81 sizeof(RENDER_TARGET_BLEND_COMPILE_STATE
));
85 compileState
.blendEnable
= rt_blend
->blend_enable
;
86 if (compileState
.blendEnable
) {
87 compileState
.sourceAlphaBlendFactor
=
88 swr_convert_blend_factor(rt_blend
->alpha_src_factor
);
89 compileState
.destAlphaBlendFactor
=
90 swr_convert_blend_factor(rt_blend
->alpha_dst_factor
);
91 compileState
.sourceBlendFactor
=
92 swr_convert_blend_factor(rt_blend
->rgb_src_factor
);
93 compileState
.destBlendFactor
=
94 swr_convert_blend_factor(rt_blend
->rgb_dst_factor
);
96 compileState
.colorBlendFunc
=
97 swr_convert_blend_func(rt_blend
->rgb_func
);
98 compileState
.alphaBlendFunc
=
99 swr_convert_blend_func(rt_blend
->alpha_func
);
101 compileState
.logicOpEnable
= state
->pipe
.logicop_enable
;
102 if (compileState
.logicOpEnable
) {
103 compileState
.logicOpFunc
=
104 swr_convert_logic_op(state
->pipe
.logicop_func
);
107 blendState
.writeDisableRed
=
108 (rt_blend
->colormask
& PIPE_MASK_R
) ? 0 : 1;
109 blendState
.writeDisableGreen
=
110 (rt_blend
->colormask
& PIPE_MASK_G
) ? 0 : 1;
111 blendState
.writeDisableBlue
=
112 (rt_blend
->colormask
& PIPE_MASK_B
) ? 0 : 1;
113 blendState
.writeDisableAlpha
=
114 (rt_blend
->colormask
& PIPE_MASK_A
) ? 0 : 1;
116 if (rt_blend
->colormask
== 0)
117 compileState
.blendEnable
= false;
124 swr_bind_blend_state(struct pipe_context
*pipe
, void *blend
)
126 struct swr_context
*ctx
= swr_context(pipe
);
128 if (ctx
->blend
== blend
)
131 ctx
->blend
= (swr_blend_state
*)blend
;
133 ctx
->dirty
|= SWR_NEW_BLEND
;
137 swr_delete_blend_state(struct pipe_context
*pipe
, void *blend
)
143 swr_set_blend_color(struct pipe_context
*pipe
,
144 const struct pipe_blend_color
*color
)
146 struct swr_context
*ctx
= swr_context(pipe
);
148 ctx
->blend_color
= *color
;
150 ctx
->dirty
|= SWR_NEW_BLEND
;
154 swr_set_stencil_ref(struct pipe_context
*pipe
,
155 const struct pipe_stencil_ref
*ref
)
157 struct swr_context
*ctx
= swr_context(pipe
);
159 ctx
->stencil_ref
= *ref
;
161 ctx
->dirty
|= SWR_NEW_DEPTH_STENCIL_ALPHA
;
165 swr_create_depth_stencil_state(
166 struct pipe_context
*pipe
,
167 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
169 struct pipe_depth_stencil_alpha_state
*state
;
171 state
= (pipe_depth_stencil_alpha_state
*)mem_dup(depth_stencil
,
172 sizeof *depth_stencil
);
178 swr_bind_depth_stencil_state(struct pipe_context
*pipe
, void *depth_stencil
)
180 struct swr_context
*ctx
= swr_context(pipe
);
182 if (ctx
->depth_stencil
== (pipe_depth_stencil_alpha_state
*)depth_stencil
)
185 ctx
->depth_stencil
= (pipe_depth_stencil_alpha_state
*)depth_stencil
;
187 ctx
->dirty
|= SWR_NEW_DEPTH_STENCIL_ALPHA
;
191 swr_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
198 swr_create_rasterizer_state(struct pipe_context
*pipe
,
199 const struct pipe_rasterizer_state
*rast
)
201 struct pipe_rasterizer_state
*state
;
202 state
= (pipe_rasterizer_state
*)mem_dup(rast
, sizeof *rast
);
208 swr_bind_rasterizer_state(struct pipe_context
*pipe
, void *handle
)
210 struct swr_context
*ctx
= swr_context(pipe
);
211 const struct pipe_rasterizer_state
*rasterizer
=
212 (const struct pipe_rasterizer_state
*)handle
;
214 if (ctx
->rasterizer
== (pipe_rasterizer_state
*)rasterizer
)
217 ctx
->rasterizer
= (pipe_rasterizer_state
*)rasterizer
;
219 ctx
->dirty
|= SWR_NEW_RASTERIZER
;
223 swr_delete_rasterizer_state(struct pipe_context
*pipe
, void *rasterizer
)
230 swr_create_sampler_state(struct pipe_context
*pipe
,
231 const struct pipe_sampler_state
*sampler
)
233 struct pipe_sampler_state
*state
=
234 (pipe_sampler_state
*)mem_dup(sampler
, sizeof *sampler
);
240 swr_bind_sampler_states(struct pipe_context
*pipe
,
241 enum pipe_shader_type shader
,
246 struct swr_context
*ctx
= swr_context(pipe
);
249 assert(shader
< PIPE_SHADER_TYPES
);
250 assert(start
+ num
<= ARRAY_SIZE(ctx
->samplers
[shader
]));
252 /* set the new samplers */
253 ctx
->num_samplers
[shader
] = num
;
254 for (i
= 0; i
< num
; i
++) {
255 ctx
->samplers
[shader
][start
+ i
] = (pipe_sampler_state
*)samplers
[i
];
258 ctx
->dirty
|= SWR_NEW_SAMPLER
;
262 swr_delete_sampler_state(struct pipe_context
*pipe
, void *sampler
)
268 static struct pipe_sampler_view
*
269 swr_create_sampler_view(struct pipe_context
*pipe
,
270 struct pipe_resource
*texture
,
271 const struct pipe_sampler_view
*templ
)
273 struct pipe_sampler_view
*view
= CALLOC_STRUCT(pipe_sampler_view
);
277 view
->reference
.count
= 1;
278 view
->texture
= NULL
;
279 pipe_resource_reference(&view
->texture
, texture
);
280 view
->context
= pipe
;
287 swr_set_sampler_views(struct pipe_context
*pipe
,
288 enum pipe_shader_type shader
,
291 struct pipe_sampler_view
**views
)
293 struct swr_context
*ctx
= swr_context(pipe
);
296 assert(num
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
298 assert(shader
< PIPE_SHADER_TYPES
);
299 assert(start
+ num
<= ARRAY_SIZE(ctx
->sampler_views
[shader
]));
301 /* set the new sampler views */
302 ctx
->num_sampler_views
[shader
] = num
;
303 for (i
= 0; i
< num
; i
++) {
304 /* Note: we're using pipe_sampler_view_release() here to work around
305 * a possible crash when the old view belongs to another context that
306 * was already destroyed.
308 pipe_sampler_view_release(pipe
, &ctx
->sampler_views
[shader
][start
+ i
]);
309 pipe_sampler_view_reference(&ctx
->sampler_views
[shader
][start
+ i
],
313 ctx
->dirty
|= SWR_NEW_SAMPLER_VIEW
;
317 swr_sampler_view_destroy(struct pipe_context
*pipe
,
318 struct pipe_sampler_view
*view
)
320 pipe_resource_reference(&view
->texture
, NULL
);
325 swr_create_vs_state(struct pipe_context
*pipe
,
326 const struct pipe_shader_state
*vs
)
328 struct swr_vertex_shader
*swr_vs
= new swr_vertex_shader
;
332 swr_vs
->pipe
.tokens
= tgsi_dup_tokens(vs
->tokens
);
333 swr_vs
->pipe
.stream_output
= vs
->stream_output
;
335 lp_build_tgsi_info(vs
->tokens
, &swr_vs
->info
);
337 swr_vs
->soState
= {0};
339 if (swr_vs
->pipe
.stream_output
.num_outputs
) {
340 pipe_stream_output_info
*stream_output
= &swr_vs
->pipe
.stream_output
;
342 swr_vs
->soState
.soEnable
= true;
343 // soState.rasterizerDisable set on state dirty
344 // soState.streamToRasterizer not used
346 for (uint32_t i
= 0; i
< stream_output
->num_outputs
; i
++) {
347 swr_vs
->soState
.streamMasks
[stream_output
->output
[i
].stream
] |=
348 1 << (stream_output
->output
[i
].register_index
- 1);
350 for (uint32_t i
= 0; i
< MAX_SO_STREAMS
; i
++) {
351 swr_vs
->soState
.streamNumEntries
[i
] =
352 _mm_popcnt_u32(swr_vs
->soState
.streamMasks
[i
]);
360 swr_bind_vs_state(struct pipe_context
*pipe
, void *vs
)
362 struct swr_context
*ctx
= swr_context(pipe
);
367 ctx
->vs
= (swr_vertex_shader
*)vs
;
368 ctx
->dirty
|= SWR_NEW_VS
;
372 swr_delete_vs_state(struct pipe_context
*pipe
, void *vs
)
374 struct swr_vertex_shader
*swr_vs
= (swr_vertex_shader
*)vs
;
375 FREE((void *)swr_vs
->pipe
.tokens
);
376 struct swr_screen
*screen
= swr_screen(pipe
->screen
);
378 /* Defer deletion of vs state */
379 swr_fence_work_delete_vs(screen
->flush_fence
, swr_vs
);
383 swr_create_fs_state(struct pipe_context
*pipe
,
384 const struct pipe_shader_state
*fs
)
386 struct swr_fragment_shader
*swr_fs
= new swr_fragment_shader
;
390 swr_fs
->pipe
.tokens
= tgsi_dup_tokens(fs
->tokens
);
392 lp_build_tgsi_info(fs
->tokens
, &swr_fs
->info
);
399 swr_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
401 struct swr_context
*ctx
= swr_context(pipe
);
406 ctx
->fs
= (swr_fragment_shader
*)fs
;
407 ctx
->dirty
|= SWR_NEW_FS
;
411 swr_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
413 struct swr_fragment_shader
*swr_fs
= (swr_fragment_shader
*)fs
;
414 FREE((void *)swr_fs
->pipe
.tokens
);
415 struct swr_screen
*screen
= swr_screen(pipe
->screen
);
417 /* Defer deleton of fs state */
418 swr_fence_work_delete_fs(screen
->flush_fence
, swr_fs
);
422 swr_create_gs_state(struct pipe_context
*pipe
,
423 const struct pipe_shader_state
*gs
)
425 struct swr_geometry_shader
*swr_gs
= new swr_geometry_shader
;
429 swr_gs
->pipe
.tokens
= tgsi_dup_tokens(gs
->tokens
);
431 lp_build_tgsi_info(gs
->tokens
, &swr_gs
->info
);
438 swr_bind_gs_state(struct pipe_context
*pipe
, void *gs
)
440 struct swr_context
*ctx
= swr_context(pipe
);
445 ctx
->gs
= (swr_geometry_shader
*)gs
;
446 ctx
->dirty
|= SWR_NEW_GS
;
450 swr_delete_gs_state(struct pipe_context
*pipe
, void *gs
)
452 struct swr_geometry_shader
*swr_gs
= (swr_geometry_shader
*)gs
;
453 FREE((void *)swr_gs
->pipe
.tokens
);
454 struct swr_screen
*screen
= swr_screen(pipe
->screen
);
456 /* Defer deleton of fs state */
457 swr_fence_work_delete_gs(screen
->flush_fence
, swr_gs
);
461 swr_set_constant_buffer(struct pipe_context
*pipe
,
462 enum pipe_shader_type shader
,
464 const struct pipe_constant_buffer
*cb
)
466 struct swr_context
*ctx
= swr_context(pipe
);
467 struct pipe_resource
*constants
= cb
? cb
->buffer
: NULL
;
469 assert(shader
< PIPE_SHADER_TYPES
);
470 assert(index
< ARRAY_SIZE(ctx
->constants
[shader
]));
472 /* note: reference counting */
473 util_copy_constant_buffer(&ctx
->constants
[shader
][index
], cb
);
475 if (shader
== PIPE_SHADER_VERTEX
) {
476 ctx
->dirty
|= SWR_NEW_VSCONSTANTS
;
477 } else if (shader
== PIPE_SHADER_FRAGMENT
) {
478 ctx
->dirty
|= SWR_NEW_FSCONSTANTS
;
479 } else if (shader
== PIPE_SHADER_GEOMETRY
) {
480 ctx
->dirty
|= SWR_NEW_GSCONSTANTS
;
483 if (cb
&& cb
->user_buffer
) {
484 pipe_resource_reference(&constants
, NULL
);
490 swr_create_vertex_elements_state(struct pipe_context
*pipe
,
491 unsigned num_elements
,
492 const struct pipe_vertex_element
*attribs
)
494 struct swr_vertex_element_state
*velems
;
495 assert(num_elements
<= PIPE_MAX_ATTRIBS
);
496 velems
= new swr_vertex_element_state
;
498 velems
->fsState
.bVertexIDOffsetEnable
= true;
499 velems
->fsState
.numAttribs
= num_elements
;
500 for (unsigned i
= 0; i
< num_elements
; i
++) {
501 // XXX: we should do this keyed on the VS usage info
503 const struct util_format_description
*desc
=
504 util_format_description(attribs
[i
].src_format
);
506 velems
->fsState
.layout
[i
].AlignedByteOffset
= attribs
[i
].src_offset
;
507 velems
->fsState
.layout
[i
].Format
=
508 mesa_to_swr_format(attribs
[i
].src_format
);
509 velems
->fsState
.layout
[i
].StreamIndex
=
510 attribs
[i
].vertex_buffer_index
;
511 velems
->fsState
.layout
[i
].InstanceEnable
=
512 attribs
[i
].instance_divisor
!= 0;
513 velems
->fsState
.layout
[i
].ComponentControl0
=
514 desc
->channel
[0].type
!= UTIL_FORMAT_TYPE_VOID
515 ? ComponentControl::StoreSrc
516 : ComponentControl::Store0
;
517 velems
->fsState
.layout
[i
].ComponentControl1
=
518 desc
->channel
[1].type
!= UTIL_FORMAT_TYPE_VOID
519 ? ComponentControl::StoreSrc
520 : ComponentControl::Store0
;
521 velems
->fsState
.layout
[i
].ComponentControl2
=
522 desc
->channel
[2].type
!= UTIL_FORMAT_TYPE_VOID
523 ? ComponentControl::StoreSrc
524 : ComponentControl::Store0
;
525 velems
->fsState
.layout
[i
].ComponentControl3
=
526 desc
->channel
[3].type
!= UTIL_FORMAT_TYPE_VOID
527 ? ComponentControl::StoreSrc
528 : ComponentControl::Store1Fp
;
529 velems
->fsState
.layout
[i
].ComponentPacking
= ComponentEnable::XYZW
;
530 velems
->fsState
.layout
[i
].InstanceDataStepRate
=
531 attribs
[i
].instance_divisor
;
533 /* Calculate the pitch of each stream */
534 const SWR_FORMAT_INFO
&swr_desc
= GetFormatInfo(
535 mesa_to_swr_format(attribs
[i
].src_format
));
536 velems
->stream_pitch
[attribs
[i
].vertex_buffer_index
] += swr_desc
.Bpp
;
538 if (attribs
[i
].instance_divisor
!= 0) {
539 velems
->instanced_bufs
|= 1U << attribs
[i
].vertex_buffer_index
;
540 uint32_t *min_instance_div
=
541 &velems
->min_instance_div
[attribs
[i
].vertex_buffer_index
];
542 if (!*min_instance_div
||
543 attribs
[i
].instance_divisor
< *min_instance_div
)
544 *min_instance_div
= attribs
[i
].instance_divisor
;
553 swr_bind_vertex_elements_state(struct pipe_context
*pipe
, void *velems
)
555 struct swr_context
*ctx
= swr_context(pipe
);
556 struct swr_vertex_element_state
*swr_velems
=
557 (struct swr_vertex_element_state
*)velems
;
559 ctx
->velems
= swr_velems
;
560 ctx
->dirty
|= SWR_NEW_VERTEX
;
564 swr_delete_vertex_elements_state(struct pipe_context
*pipe
, void *velems
)
566 struct swr_vertex_element_state
*swr_velems
=
567 (struct swr_vertex_element_state
*) velems
;
568 /* XXX Need to destroy fetch shader? */
574 swr_set_vertex_buffers(struct pipe_context
*pipe
,
576 unsigned num_elements
,
577 const struct pipe_vertex_buffer
*buffers
)
579 struct swr_context
*ctx
= swr_context(pipe
);
581 assert(num_elements
<= PIPE_MAX_ATTRIBS
);
583 util_set_vertex_buffers_count(ctx
->vertex_buffer
,
584 &ctx
->num_vertex_buffers
,
589 ctx
->dirty
|= SWR_NEW_VERTEX
;
594 swr_set_polygon_stipple(struct pipe_context
*pipe
,
595 const struct pipe_poly_stipple
*stipple
)
597 struct swr_context
*ctx
= swr_context(pipe
);
599 ctx
->poly_stipple
.pipe
= *stipple
; /* struct copy */
600 ctx
->dirty
|= SWR_NEW_STIPPLE
;
604 swr_set_clip_state(struct pipe_context
*pipe
,
605 const struct pipe_clip_state
*clip
)
607 struct swr_context
*ctx
= swr_context(pipe
);
610 /* XXX Unimplemented, but prevents crash */
612 ctx
->dirty
|= SWR_NEW_CLIP
;
617 swr_set_scissor_states(struct pipe_context
*pipe
,
619 unsigned num_viewports
,
620 const struct pipe_scissor_state
*scissor
)
622 struct swr_context
*ctx
= swr_context(pipe
);
624 ctx
->scissor
= *scissor
;
625 ctx
->swr_scissor
.xmin
= scissor
->minx
;
626 ctx
->swr_scissor
.xmax
= scissor
->maxx
;
627 ctx
->swr_scissor
.ymin
= scissor
->miny
;
628 ctx
->swr_scissor
.ymax
= scissor
->maxy
;
629 ctx
->dirty
|= SWR_NEW_SCISSOR
;
633 swr_set_viewport_states(struct pipe_context
*pipe
,
635 unsigned num_viewports
,
636 const struct pipe_viewport_state
*vpt
)
638 struct swr_context
*ctx
= swr_context(pipe
);
640 ctx
->viewport
= *vpt
;
641 ctx
->dirty
|= SWR_NEW_VIEWPORT
;
646 swr_set_framebuffer_state(struct pipe_context
*pipe
,
647 const struct pipe_framebuffer_state
*fb
)
649 struct swr_context
*ctx
= swr_context(pipe
);
651 boolean changed
= !util_framebuffer_state_equal(&ctx
->framebuffer
, fb
);
653 assert(fb
->width
<= KNOB_GUARDBAND_WIDTH
);
654 assert(fb
->height
<= KNOB_GUARDBAND_HEIGHT
);
657 util_copy_framebuffer_state(&ctx
->framebuffer
, fb
);
659 /* 0 and 1 both indicate no msaa. Core doesn't understand 0 samples */
660 ctx
->framebuffer
.samples
= std::max((ubyte
)1, ctx
->framebuffer
.samples
);
662 ctx
->dirty
|= SWR_NEW_FRAMEBUFFER
;
668 swr_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
670 struct swr_context
*ctx
= swr_context(pipe
);
672 if (sample_mask
!= ctx
->sample_mask
) {
673 ctx
->sample_mask
= sample_mask
;
674 ctx
->dirty
|= SWR_NEW_RASTERIZER
;
679 * MSAA fixed sample position table
680 * used by update_derived and get_sample_position
681 * (integer locations on a 16x16 grid)
683 static const uint8_t swr_sample_positions
[][2] =
685 /* 2x*/ {12,12},{ 4, 4},
686 /* 4x*/ { 6, 2},{14, 6},{ 2,10},{10,14},
687 /* 8x*/ { 9, 5},{ 7,11},{13, 9},{ 5, 3},
688 { 3,13},{ 1, 7},{11,15},{15, 1},
689 /*16x*/ { 9, 9},{ 7, 5},{ 5,10},{12, 7},
690 { 3, 6},{10,13},{13,11},{11, 3},
691 { 6,14},{ 8, 1},{ 4, 2},{ 2,12},
692 { 0, 8},{15, 4},{14,15},{ 1, 0} };
695 swr_get_sample_position(struct pipe_context
*pipe
,
696 unsigned sample_count
, unsigned sample_index
,
699 /* validate sample_count */
700 sample_count
= GetNumSamples(GetSampleCount(sample_count
));
702 const uint8_t *sample
= swr_sample_positions
[sample_count
-1 + sample_index
];
703 out_value
[0] = sample
[0] / 16.0f
;
704 out_value
[1] = sample
[1] / 16.0f
;
709 * Update resource in-use status
710 * All resources bound to color or depth targets marked as WRITE resources.
711 * VBO Vertex/index buffers and texture views marked as READ resources.
714 swr_update_resource_status(struct pipe_context
*pipe
,
715 const struct pipe_draw_info
*p_draw_info
)
717 struct swr_context
*ctx
= swr_context(pipe
);
718 struct pipe_framebuffer_state
*fb
= &ctx
->framebuffer
;
720 /* colorbuffer targets */
722 for (uint32_t i
= 0; i
< fb
->nr_cbufs
; ++i
)
724 swr_resource_write(fb
->cbufs
[i
]->texture
);
726 /* depth/stencil target */
728 swr_resource_write(fb
->zsbuf
->texture
);
730 /* VBO vertex buffers */
731 for (uint32_t i
= 0; i
< ctx
->num_vertex_buffers
; i
++) {
732 struct pipe_vertex_buffer
*vb
= &ctx
->vertex_buffer
[i
];
733 if (!vb
->is_user_buffer
)
734 swr_resource_read(vb
->buffer
.resource
);
737 /* VBO index buffer */
738 if (p_draw_info
&& p_draw_info
->index_size
) {
739 if (!p_draw_info
->has_user_indices
)
740 swr_resource_read(p_draw_info
->index
.resource
);
743 /* transform feedback buffers */
744 for (uint32_t i
= 0; i
< ctx
->num_so_targets
; i
++) {
745 struct pipe_stream_output_target
*target
= ctx
->so_targets
[i
];
746 if (target
&& target
->buffer
)
747 swr_resource_write(target
->buffer
);
750 /* texture sampler views */
751 for (uint32_t j
: {PIPE_SHADER_VERTEX
, PIPE_SHADER_FRAGMENT
}) {
752 for (uint32_t i
= 0; i
< ctx
->num_sampler_views
[j
]; i
++) {
753 struct pipe_sampler_view
*view
= ctx
->sampler_views
[j
][i
];
755 swr_resource_read(view
->texture
);
759 /* constant buffers */
760 for (uint32_t j
: {PIPE_SHADER_VERTEX
, PIPE_SHADER_FRAGMENT
}) {
761 for (uint32_t i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
762 struct pipe_constant_buffer
*cb
= &ctx
->constants
[j
][i
];
764 swr_resource_read(cb
->buffer
);
770 swr_update_texture_state(struct swr_context
*ctx
,
771 enum pipe_shader_type shader_type
,
772 unsigned num_sampler_views
,
773 swr_jit_texture
*textures
)
775 for (unsigned i
= 0; i
< num_sampler_views
; i
++) {
776 struct pipe_sampler_view
*view
=
777 ctx
->sampler_views
[shader_type
][i
];
778 struct swr_jit_texture
*jit_tex
= &textures
[i
];
780 memset(jit_tex
, 0, sizeof(*jit_tex
));
782 struct pipe_resource
*res
= view
->texture
;
783 struct swr_resource
*swr_res
= swr_resource(res
);
784 SWR_SURFACE_STATE
*swr
= &swr_res
->swr
;
785 size_t *mip_offsets
= swr_res
->mip_offsets
;
786 if (swr_res
->has_depth
&& swr_res
->has_stencil
&&
787 !util_format_has_depth(util_format_description(view
->format
))) {
788 swr
= &swr_res
->secondary
;
789 mip_offsets
= swr_res
->secondary_mip_offsets
;
792 jit_tex
->width
= res
->width0
;
793 jit_tex
->height
= res
->height0
;
794 jit_tex
->base_ptr
= swr
->pBaseAddress
;
795 if (view
->target
!= PIPE_BUFFER
) {
796 jit_tex
->first_level
= view
->u
.tex
.first_level
;
797 jit_tex
->last_level
= view
->u
.tex
.last_level
;
798 if (view
->target
== PIPE_TEXTURE_3D
)
799 jit_tex
->depth
= res
->depth0
;
802 view
->u
.tex
.last_layer
- view
->u
.tex
.first_layer
+ 1;
803 jit_tex
->base_ptr
+= view
->u
.tex
.first_layer
*
804 swr
->qpitch
* swr
->pitch
;
806 unsigned view_blocksize
= util_format_get_blocksize(view
->format
);
807 jit_tex
->base_ptr
+= view
->u
.buf
.offset
;
808 jit_tex
->width
= view
->u
.buf
.size
/ view_blocksize
;
812 for (unsigned level
= jit_tex
->first_level
;
813 level
<= jit_tex
->last_level
;
815 jit_tex
->row_stride
[level
] = swr
->pitch
;
816 jit_tex
->img_stride
[level
] = swr
->qpitch
* swr
->pitch
;
817 jit_tex
->mip_offsets
[level
] = mip_offsets
[level
];
824 swr_update_sampler_state(struct swr_context
*ctx
,
825 enum pipe_shader_type shader_type
,
826 unsigned num_samplers
,
827 swr_jit_sampler
*samplers
)
829 for (unsigned i
= 0; i
< num_samplers
; i
++) {
830 const struct pipe_sampler_state
*sampler
=
831 ctx
->samplers
[shader_type
][i
];
834 samplers
[i
].min_lod
= sampler
->min_lod
;
835 samplers
[i
].max_lod
= sampler
->max_lod
;
836 samplers
[i
].lod_bias
= sampler
->lod_bias
;
837 COPY_4V(samplers
[i
].border_color
, sampler
->border_color
.f
);
843 swr_update_constants(struct swr_context
*ctx
, enum pipe_shader_type shaderType
)
845 swr_draw_context
*pDC
= &ctx
->swrDC
;
847 const float **constant
;
848 uint32_t *num_constants
;
849 struct swr_scratch_space
*scratch
;
851 switch (shaderType
) {
852 case PIPE_SHADER_VERTEX
:
853 constant
= pDC
->constantVS
;
854 num_constants
= pDC
->num_constantsVS
;
855 scratch
= &ctx
->scratch
->vs_constants
;
857 case PIPE_SHADER_FRAGMENT
:
858 constant
= pDC
->constantFS
;
859 num_constants
= pDC
->num_constantsFS
;
860 scratch
= &ctx
->scratch
->fs_constants
;
862 case PIPE_SHADER_GEOMETRY
:
863 constant
= pDC
->constantGS
;
864 num_constants
= pDC
->num_constantsGS
;
865 scratch
= &ctx
->scratch
->gs_constants
;
868 debug_printf("Unsupported shader type constants\n");
872 for (UINT i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
873 const pipe_constant_buffer
*cb
= &ctx
->constants
[shaderType
][i
];
874 num_constants
[i
] = cb
->buffer_size
;
877 (const float *)(swr_resource_data(cb
->buffer
) +
880 /* Need to copy these constants to scratch space */
881 if (cb
->user_buffer
&& cb
->buffer_size
) {
883 ((const uint8_t *)cb
->user_buffer
+ cb
->buffer_offset
);
884 uint32_t size
= AlignUp(cb
->buffer_size
, 4);
885 ptr
= swr_copy_to_scratch_space(ctx
, scratch
, ptr
, size
);
886 constant
[i
] = (const float *)ptr
;
893 swr_change_rt(struct swr_context
*ctx
,
895 const struct pipe_surface
*sf
)
897 swr_draw_context
*pDC
= &ctx
->swrDC
;
898 struct SWR_SURFACE_STATE
*rt
= &pDC
->renderTargets
[attachment
];
900 /* Do nothing if the render target hasn't changed */
901 if ((!sf
|| !sf
->texture
) && rt
->pBaseAddress
== nullptr)
904 /* Deal with disabling RT up front */
905 if (!sf
|| !sf
->texture
) {
906 /* If detaching attachment, mark tiles as RESOLVED so core
907 * won't try to load from non-existent target. */
908 swr_store_render_target(&ctx
->pipe
, attachment
, SWR_TILE_RESOLVED
);
913 const struct swr_resource
*swr
= swr_resource(sf
->texture
);
914 const SWR_SURFACE_STATE
*swr_surface
= &swr
->swr
;
915 SWR_FORMAT fmt
= mesa_to_swr_format(sf
->format
);
917 if (attachment
== SWR_ATTACHMENT_STENCIL
&& swr
->secondary
.pBaseAddress
) {
918 swr_surface
= &swr
->secondary
;
919 fmt
= swr_surface
->format
;
922 if (rt
->pBaseAddress
== swr_surface
->pBaseAddress
&&
924 rt
->lod
== sf
->u
.tex
.level
&&
925 rt
->arrayIndex
== sf
->u
.tex
.first_layer
)
928 bool need_fence
= false;
930 /* StoreTile for changed target */
931 if (rt
->pBaseAddress
) {
932 /* If changing attachment to a new target, mark tiles as
933 * INVALID so they are reloaded from surface. */
934 swr_store_render_target(&ctx
->pipe
, attachment
, SWR_TILE_INVALID
);
938 /* Make new attachment */
941 rt
->lod
= sf
->u
.tex
.level
;
942 rt
->arrayIndex
= sf
->u
.tex
.first_layer
;
948 swr_user_vbuf_range(const struct pipe_draw_info
*info
,
949 const struct swr_vertex_element_state
*velems
,
950 const struct pipe_vertex_buffer
*vb
,
956 /* FIXME: The size is too large - we don't access the full extra stride. */
958 if (velems
->instanced_bufs
& (1U << i
)) {
959 elems
= info
->instance_count
/ velems
->min_instance_div
[i
] + 1;
960 *totelems
= info
->start_instance
+ elems
;
961 *base
= info
->start_instance
* vb
->stride
;
962 *size
= elems
* vb
->stride
;
963 } else if (vb
->stride
) {
964 elems
= info
->max_index
- info
->min_index
+ 1;
965 *totelems
= info
->max_index
+ 1;
966 *base
= info
->min_index
* vb
->stride
;
967 *size
= elems
* vb
->stride
;
971 *size
= velems
->stream_pitch
[i
];
976 swr_update_poly_stipple(struct swr_context
*ctx
)
978 struct swr_draw_context
*pDC
= &ctx
->swrDC
;
980 assert(sizeof(ctx
->poly_stipple
.pipe
.stipple
) == sizeof(pDC
->polyStipple
));
981 memcpy(pDC
->polyStipple
,
982 ctx
->poly_stipple
.pipe
.stipple
,
983 sizeof(ctx
->poly_stipple
.pipe
.stipple
));
987 swr_update_derived(struct pipe_context
*pipe
,
988 const struct pipe_draw_info
*p_draw_info
)
990 struct swr_context
*ctx
= swr_context(pipe
);
991 struct swr_screen
*screen
= swr_screen(pipe
->screen
);
993 /* When called from swr_clear (p_draw_info = null), set any null
994 * state-objects to the dummy state objects to prevent nullptr dereference
995 * in validation below.
997 * Important that this remains static for zero initialization. These
998 * aren't meant to be proper state objects, just empty structs. They will
1001 * Shaders can't be part of the union since they contain std::unordered_map
1005 struct pipe_rasterizer_state rasterizer
;
1006 struct pipe_depth_stencil_alpha_state depth_stencil
;
1007 struct swr_blend_state blend
;
1009 struct swr_vertex_shader vs
;
1010 struct swr_fragment_shader fs
;
1014 if (!ctx
->rasterizer
)
1015 ctx
->rasterizer
= &swr_dummy
.state
.rasterizer
;
1016 if (!ctx
->depth_stencil
)
1017 ctx
->depth_stencil
= &swr_dummy
.state
.depth_stencil
;
1019 ctx
->blend
= &swr_dummy
.state
.blend
;
1021 ctx
->vs
= &swr_dummy
.vs
;
1023 ctx
->fs
= &swr_dummy
.fs
;
1026 /* Update screen->pipe to current pipe context. */
1027 if (screen
->pipe
!= pipe
)
1028 screen
->pipe
= pipe
;
1030 /* Any state that requires dirty flags to be re-triggered sets this mask */
1031 /* For example, user_buffer vertex and index buffers. */
1032 unsigned post_update_dirty_flags
= 0;
1034 /* Render Targets */
1035 if (ctx
->dirty
& SWR_NEW_FRAMEBUFFER
) {
1036 struct pipe_framebuffer_state
*fb
= &ctx
->framebuffer
;
1037 const struct util_format_description
*desc
= NULL
;
1038 bool need_fence
= false;
1040 /* colorbuffer targets */
1042 for (unsigned i
= 0; i
< fb
->nr_cbufs
; ++i
)
1043 need_fence
|= swr_change_rt(
1044 ctx
, SWR_ATTACHMENT_COLOR0
+ i
, fb
->cbufs
[i
]);
1046 for (unsigned i
= fb
->nr_cbufs
; i
< SWR_NUM_RENDERTARGETS
; ++i
)
1047 need_fence
|= swr_change_rt(ctx
, SWR_ATTACHMENT_COLOR0
+ i
, NULL
);
1049 /* depth/stencil target */
1051 desc
= util_format_description(fb
->zsbuf
->format
);
1052 if (fb
->zsbuf
&& util_format_has_depth(desc
))
1053 need_fence
|= swr_change_rt(ctx
, SWR_ATTACHMENT_DEPTH
, fb
->zsbuf
);
1055 need_fence
|= swr_change_rt(ctx
, SWR_ATTACHMENT_DEPTH
, NULL
);
1057 if (fb
->zsbuf
&& util_format_has_stencil(desc
))
1058 need_fence
|= swr_change_rt(ctx
, SWR_ATTACHMENT_STENCIL
, fb
->zsbuf
);
1060 need_fence
|= swr_change_rt(ctx
, SWR_ATTACHMENT_STENCIL
, NULL
);
1062 /* This fence ensures any attachment changes are resolved before the
1065 swr_fence_submit(ctx
, screen
->flush_fence
);
1069 if (ctx
->dirty
& (SWR_NEW_RASTERIZER
|
1070 SWR_NEW_VS
| // clipping
1071 SWR_NEW_FRAMEBUFFER
)) {
1072 pipe_rasterizer_state
*rasterizer
= ctx
->rasterizer
;
1073 pipe_framebuffer_state
*fb
= &ctx
->framebuffer
;
1075 SWR_RASTSTATE
*rastState
= &ctx
->derived
.rastState
;
1076 rastState
->cullMode
= swr_convert_cull_mode(rasterizer
->cull_face
);
1077 rastState
->frontWinding
= rasterizer
->front_ccw
1078 ? SWR_FRONTWINDING_CCW
1079 : SWR_FRONTWINDING_CW
;
1080 rastState
->scissorEnable
= rasterizer
->scissor
;
1081 rastState
->pointSize
= rasterizer
->point_size
> 0.0f
1082 ? rasterizer
->point_size
1084 rastState
->lineWidth
= rasterizer
->line_width
> 0.0f
1085 ? rasterizer
->line_width
1088 rastState
->pointParam
= rasterizer
->point_size_per_vertex
;
1090 rastState
->pointSpriteEnable
= rasterizer
->sprite_coord_enable
;
1091 rastState
->pointSpriteTopOrigin
=
1092 rasterizer
->sprite_coord_mode
== PIPE_SPRITE_COORD_UPPER_LEFT
;
1094 /* If SWR_MSAA_FORCE_ENABLE is set, turn msaa on */
1095 if (screen
->msaa_force_enable
&& !rasterizer
->multisample
) {
1096 /* Force enable and use the value the surface was created with */
1097 rasterizer
->multisample
= true;
1098 fb
->samples
= swr_resource(fb
->cbufs
[0]->texture
)->swr
.numSamples
;
1099 fprintf(stderr
,"msaa force enable: %d samples\n", fb
->samples
);
1102 rastState
->sampleCount
= GetSampleCount(fb
->samples
);
1103 rastState
->forcedSampleCount
= false;
1104 rastState
->bIsCenterPattern
= !rasterizer
->multisample
;
1105 rastState
->pixelLocation
= SWR_PIXEL_LOCATION_CENTER
;
1107 /* Only initialize sample positions if msaa is enabled */
1108 if (rasterizer
->multisample
) {
1109 for (uint32_t i
= 0; i
< fb
->samples
; i
++) {
1110 const uint8_t *sample
= swr_sample_positions
[fb
->samples
-1 + i
];
1111 rastState
->samplePositions
.SetXi(i
, sample
[0] << 4);
1112 rastState
->samplePositions
.SetYi(i
, sample
[1] << 4);
1113 rastState
->samplePositions
.SetX (i
, sample
[0] / 16.0f
);
1114 rastState
->samplePositions
.SetY (i
, sample
[1] / 16.0f
);
1116 rastState
->samplePositions
.PrecalcSampleData(fb
->samples
);
1119 bool do_offset
= false;
1120 switch (rasterizer
->fill_front
) {
1121 case PIPE_POLYGON_MODE_FILL
:
1122 do_offset
= rasterizer
->offset_tri
;
1124 case PIPE_POLYGON_MODE_LINE
:
1125 do_offset
= rasterizer
->offset_line
;
1127 case PIPE_POLYGON_MODE_POINT
:
1128 do_offset
= rasterizer
->offset_point
;
1133 rastState
->depthBias
= rasterizer
->offset_units
;
1134 rastState
->slopeScaledDepthBias
= rasterizer
->offset_scale
;
1135 rastState
->depthBiasClamp
= rasterizer
->offset_clamp
;
1137 rastState
->depthBias
= 0;
1138 rastState
->slopeScaledDepthBias
= 0;
1139 rastState
->depthBiasClamp
= 0;
1142 /* translate polygon mode, at least for the front==back case */
1143 rastState
->fillMode
= swr_convert_fill_mode(rasterizer
->fill_front
);
1145 struct pipe_surface
*zb
= fb
->zsbuf
;
1146 if (zb
&& swr_resource(zb
->texture
)->has_depth
)
1147 rastState
->depthFormat
= swr_resource(zb
->texture
)->swr
.format
;
1149 rastState
->depthClipEnable
= rasterizer
->depth_clip
;
1150 rastState
->clipHalfZ
= rasterizer
->clip_halfz
;
1152 rastState
->clipDistanceMask
=
1153 ctx
->vs
->info
.base
.num_written_clipdistance
?
1154 ctx
->vs
->info
.base
.clipdist_writemask
& rasterizer
->clip_plane_enable
:
1155 rasterizer
->clip_plane_enable
;
1157 rastState
->cullDistanceMask
=
1158 ctx
->vs
->info
.base
.culldist_writemask
<< ctx
->vs
->info
.base
.num_written_clipdistance
;
1160 SwrSetRastState(ctx
->swrContext
, rastState
);
1164 if (ctx
->dirty
& SWR_NEW_SCISSOR
) {
1165 SwrSetScissorRects(ctx
->swrContext
, 1, &ctx
->swr_scissor
);
1169 if (ctx
->dirty
& (SWR_NEW_VIEWPORT
| SWR_NEW_FRAMEBUFFER
1170 | SWR_NEW_RASTERIZER
)) {
1171 pipe_viewport_state
*state
= &ctx
->viewport
;
1172 pipe_framebuffer_state
*fb
= &ctx
->framebuffer
;
1173 pipe_rasterizer_state
*rasterizer
= ctx
->rasterizer
;
1175 SWR_VIEWPORT
*vp
= &ctx
->derived
.vp
;
1176 SWR_VIEWPORT_MATRICES
*vpm
= &ctx
->derived
.vpm
;
1178 vp
->x
= state
->translate
[0] - state
->scale
[0];
1179 vp
->width
= 2 * state
->scale
[0];
1180 vp
->y
= state
->translate
[1] - fabs(state
->scale
[1]);
1181 vp
->height
= 2 * fabs(state
->scale
[1]);
1182 util_viewport_zmin_zmax(state
, rasterizer
->clip_halfz
,
1183 &vp
->minZ
, &vp
->maxZ
);
1185 vpm
->m00
[0] = state
->scale
[0];
1186 vpm
->m11
[0] = state
->scale
[1];
1187 vpm
->m22
[0] = state
->scale
[2];
1188 vpm
->m30
[0] = state
->translate
[0];
1189 vpm
->m31
[0] = state
->translate
[1];
1190 vpm
->m32
[0] = state
->translate
[2];
1192 /* Now that the matrix is calculated, clip the view coords to screen
1193 * size. OpenGL allows for -ve x,y in the viewport. */
1199 vp
->height
+= vp
->y
;
1202 vp
->width
= std::min(vp
->width
, (float)fb
->width
- vp
->x
);
1203 vp
->height
= std::min(vp
->height
, (float)fb
->height
- vp
->y
);
1205 SwrSetViewports(ctx
->swrContext
, 1, vp
, vpm
);
1208 /* Set vertex & index buffers */
1209 /* (using draw info if called by swr_draw_vbo) */
1210 /* TODO: This is always true, because the index buffer comes from
1213 if (1 || ctx
->dirty
& SWR_NEW_VERTEX
) {
1214 uint32_t scratch_total
;
1215 uint8_t *scratch
= NULL
;
1217 /* If being called by swr_draw_vbo, copy draw details */
1218 struct pipe_draw_info info
= {0};
1220 info
= *p_draw_info
;
1222 /* We must get all the scratch space in one go */
1224 for (UINT i
= 0; i
< ctx
->num_vertex_buffers
; i
++) {
1225 struct pipe_vertex_buffer
*vb
= &ctx
->vertex_buffer
[i
];
1227 if (!vb
->is_user_buffer
)
1230 uint32_t elems
, base
, size
;
1231 swr_user_vbuf_range(&info
, ctx
->velems
, vb
, i
, &elems
, &base
, &size
);
1232 scratch_total
+= AlignUp(size
, 4);
1235 if (scratch_total
) {
1236 scratch
= (uint8_t *)swr_copy_to_scratch_space(
1237 ctx
, &ctx
->scratch
->vertex_buffer
, NULL
, scratch_total
);
1240 /* vertex buffers */
1241 SWR_VERTEX_BUFFER_STATE swrVertexBuffers
[PIPE_MAX_ATTRIBS
];
1242 for (UINT i
= 0; i
< ctx
->num_vertex_buffers
; i
++) {
1243 uint32_t size
, pitch
, elems
, partial_inbounds
;
1244 uint32_t min_vertex_index
;
1245 const uint8_t *p_data
;
1246 struct pipe_vertex_buffer
*vb
= &ctx
->vertex_buffer
[i
];
1249 if (!vb
->is_user_buffer
) {
1251 * size is based on buffer->width0 rather than info.max_index
1252 * to prevent having to validate VBO on each draw */
1253 size
= vb
->buffer
.resource
->width0
;
1254 elems
= size
/ pitch
;
1255 partial_inbounds
= size
% pitch
;
1256 min_vertex_index
= 0;
1258 p_data
= swr_resource_data(vb
->buffer
.resource
) + vb
->buffer_offset
;
1261 * client memory is one-time use, re-trigger SWR_NEW_VERTEX to
1262 * revalidate on each draw */
1263 post_update_dirty_flags
|= SWR_NEW_VERTEX
;
1266 swr_user_vbuf_range(&info
, ctx
->velems
, vb
, i
, &elems
, &base
, &size
);
1267 partial_inbounds
= 0;
1268 min_vertex_index
= info
.min_index
;
1270 /* Copy only needed vertices to scratch space */
1271 size
= AlignUp(size
, 4);
1272 const void *ptr
= (const uint8_t *) vb
->buffer
.user
+ base
;
1273 memcpy(scratch
, ptr
, size
);
1276 p_data
= (const uint8_t *)ptr
- base
;
1279 swrVertexBuffers
[i
] = {0};
1280 swrVertexBuffers
[i
].index
= i
;
1281 swrVertexBuffers
[i
].pitch
= pitch
;
1282 swrVertexBuffers
[i
].pData
= p_data
;
1283 swrVertexBuffers
[i
].size
= size
;
1284 swrVertexBuffers
[i
].minVertex
= min_vertex_index
;
1285 swrVertexBuffers
[i
].maxVertex
= elems
;
1286 swrVertexBuffers
[i
].partialInboundsSize
= partial_inbounds
;
1289 SwrSetVertexBuffers(
1290 ctx
->swrContext
, ctx
->num_vertex_buffers
, swrVertexBuffers
);
1292 /* index buffer, if required (info passed in by swr_draw_vbo) */
1293 SWR_FORMAT index_type
= R32_UINT
; /* Default for non-indexed draws */
1294 if (info
.index_size
) {
1295 const uint8_t *p_data
;
1296 uint32_t size
, pitch
;
1298 pitch
= p_draw_info
->index_size
? p_draw_info
->index_size
: sizeof(uint32_t);
1299 index_type
= swr_convert_index_type(pitch
);
1301 if (!info
.has_user_indices
) {
1303 * size is based on buffer->width0 rather than info.count
1304 * to prevent having to validate VBO on each draw */
1305 size
= info
.index
.resource
->width0
;
1306 p_data
= swr_resource_data(info
.index
.resource
);
1309 * client memory is one-time use, re-trigger SWR_NEW_VERTEX to
1310 * revalidate on each draw */
1311 post_update_dirty_flags
|= SWR_NEW_VERTEX
;
1313 size
= info
.count
* pitch
;
1314 size
= AlignUp(size
, 4);
1316 /* Copy indices to scratch space */
1317 const void *ptr
= info
.index
.user
;
1318 ptr
= swr_copy_to_scratch_space(
1319 ctx
, &ctx
->scratch
->index_buffer
, ptr
, size
);
1320 p_data
= (const uint8_t *)ptr
;
1323 SWR_INDEX_BUFFER_STATE swrIndexBuffer
;
1324 swrIndexBuffer
.format
= swr_convert_index_type(p_draw_info
->index_size
);
1325 swrIndexBuffer
.pIndices
= p_data
;
1326 swrIndexBuffer
.size
= size
;
1328 SwrSetIndexBuffer(ctx
->swrContext
, &swrIndexBuffer
);
1331 struct swr_vertex_element_state
*velems
= ctx
->velems
;
1332 if (velems
&& velems
->fsState
.indexType
!= index_type
) {
1333 velems
->fsFunc
= NULL
;
1334 velems
->fsState
.indexType
= index_type
;
1338 /* GeometryShader */
1339 if (ctx
->dirty
& (SWR_NEW_GS
|
1342 SWR_NEW_SAMPLER_VIEW
)) {
1345 swr_generate_gs_key(key
, ctx
, ctx
->gs
);
1346 auto search
= ctx
->gs
->map
.find(key
);
1348 if (search
!= ctx
->gs
->map
.end()) {
1349 func
= search
->second
->shader
;
1351 func
= swr_compile_gs(ctx
, key
);
1353 SwrSetGsFunc(ctx
->swrContext
, func
);
1355 /* JIT sampler state */
1356 if (ctx
->dirty
& SWR_NEW_SAMPLER
) {
1357 swr_update_sampler_state(ctx
,
1358 PIPE_SHADER_GEOMETRY
,
1360 ctx
->swrDC
.samplersGS
);
1363 /* JIT sampler view state */
1364 if (ctx
->dirty
& (SWR_NEW_SAMPLER_VIEW
| SWR_NEW_FRAMEBUFFER
)) {
1365 swr_update_texture_state(ctx
,
1366 PIPE_SHADER_GEOMETRY
,
1367 key
.nr_sampler_views
,
1368 ctx
->swrDC
.texturesGS
);
1371 SwrSetGsState(ctx
->swrContext
, &ctx
->gs
->gsState
);
1373 SWR_GS_STATE state
= { 0 };
1374 SwrSetGsState(ctx
->swrContext
, &state
);
1375 SwrSetGsFunc(ctx
->swrContext
, NULL
);
1380 if (ctx
->dirty
& (SWR_NEW_VS
|
1381 SWR_NEW_RASTERIZER
| // for clip planes
1383 SWR_NEW_SAMPLER_VIEW
|
1384 SWR_NEW_FRAMEBUFFER
)) {
1386 swr_generate_vs_key(key
, ctx
, ctx
->vs
);
1387 auto search
= ctx
->vs
->map
.find(key
);
1388 PFN_VERTEX_FUNC func
;
1389 if (search
!= ctx
->vs
->map
.end()) {
1390 func
= search
->second
->shader
;
1392 func
= swr_compile_vs(ctx
, key
);
1394 SwrSetVertexFunc(ctx
->swrContext
, func
);
1396 /* JIT sampler state */
1397 if (ctx
->dirty
& SWR_NEW_SAMPLER
) {
1398 swr_update_sampler_state(ctx
,
1401 ctx
->swrDC
.samplersVS
);
1404 /* JIT sampler view state */
1405 if (ctx
->dirty
& (SWR_NEW_SAMPLER_VIEW
| SWR_NEW_FRAMEBUFFER
)) {
1406 swr_update_texture_state(ctx
,
1408 key
.nr_sampler_views
,
1409 ctx
->swrDC
.texturesVS
);
1413 /* work around the fact that poly stipple also affects lines */
1414 /* and points, since we rasterize them as triangles, too */
1415 /* Has to be before fragment shader, since it sets SWR_NEW_FS */
1417 bool new_prim_is_poly
=
1418 (u_reduced_prim(p_draw_info
->mode
) == PIPE_PRIM_TRIANGLES
) &&
1419 (ctx
->derived
.rastState
.fillMode
== SWR_FILLMODE_SOLID
);
1420 if (new_prim_is_poly
!= ctx
->poly_stipple
.prim_is_poly
) {
1421 ctx
->dirty
|= SWR_NEW_FS
;
1422 ctx
->poly_stipple
.prim_is_poly
= new_prim_is_poly
;
1426 /* FragmentShader */
1427 if (ctx
->dirty
& (SWR_NEW_FS
|
1430 SWR_NEW_RASTERIZER
|
1432 SWR_NEW_SAMPLER_VIEW
|
1433 SWR_NEW_FRAMEBUFFER
)) {
1435 swr_generate_fs_key(key
, ctx
, ctx
->fs
);
1436 auto search
= ctx
->fs
->map
.find(key
);
1437 PFN_PIXEL_KERNEL func
;
1438 if (search
!= ctx
->fs
->map
.end()) {
1439 func
= search
->second
->shader
;
1441 func
= swr_compile_fs(ctx
, key
);
1443 SWR_PS_STATE psState
= {0};
1444 psState
.pfnPixelShader
= func
;
1445 psState
.killsPixel
= ctx
->fs
->info
.base
.uses_kill
;
1446 psState
.inputCoverage
= SWR_INPUT_COVERAGE_NORMAL
;
1447 psState
.writesODepth
= ctx
->fs
->info
.base
.writes_z
;
1448 psState
.usesSourceDepth
= ctx
->fs
->info
.base
.reads_z
;
1449 psState
.shadingRate
= SWR_SHADING_RATE_PIXEL
;
1450 psState
.numRenderTargets
= ctx
->framebuffer
.nr_cbufs
;
1451 psState
.posOffset
= SWR_PS_POSITION_SAMPLE_NONE
;
1452 uint32_t barycentricsMask
= 0;
1454 // when we switch to mesa-master
1455 if (ctx
->fs
->info
.base
.uses_persp_center
||
1456 ctx
->fs
->info
.base
.uses_linear_center
)
1457 barycentricsMask
|= SWR_BARYCENTRIC_PER_PIXEL_MASK
;
1458 if (ctx
->fs
->info
.base
.uses_persp_centroid
||
1459 ctx
->fs
->info
.base
.uses_linear_centroid
)
1460 barycentricsMask
|= SWR_BARYCENTRIC_CENTROID_MASK
;
1461 if (ctx
->fs
->info
.base
.uses_persp_sample
||
1462 ctx
->fs
->info
.base
.uses_linear_sample
)
1463 barycentricsMask
|= SWR_BARYCENTRIC_PER_SAMPLE_MASK
;
1465 for (unsigned i
= 0; i
< ctx
->fs
->info
.base
.num_inputs
; i
++) {
1466 switch (ctx
->fs
->info
.base
.input_interpolate_loc
[i
]) {
1467 case TGSI_INTERPOLATE_LOC_CENTER
:
1468 barycentricsMask
|= SWR_BARYCENTRIC_PER_PIXEL_MASK
;
1470 case TGSI_INTERPOLATE_LOC_CENTROID
:
1471 barycentricsMask
|= SWR_BARYCENTRIC_CENTROID_MASK
;
1473 case TGSI_INTERPOLATE_LOC_SAMPLE
:
1474 barycentricsMask
|= SWR_BARYCENTRIC_PER_SAMPLE_MASK
;
1479 psState
.barycentricsMask
= barycentricsMask
;
1480 psState
.usesUAV
= false; // XXX
1481 psState
.forceEarlyZ
= false;
1482 SwrSetPixelShaderState(ctx
->swrContext
, &psState
);
1484 /* JIT sampler state */
1485 if (ctx
->dirty
& (SWR_NEW_SAMPLER
|
1487 swr_update_sampler_state(ctx
,
1488 PIPE_SHADER_FRAGMENT
,
1490 ctx
->swrDC
.samplersFS
);
1493 /* JIT sampler view state */
1494 if (ctx
->dirty
& (SWR_NEW_SAMPLER_VIEW
|
1495 SWR_NEW_FRAMEBUFFER
|
1497 swr_update_texture_state(ctx
,
1498 PIPE_SHADER_FRAGMENT
,
1499 key
.nr_sampler_views
,
1500 ctx
->swrDC
.texturesFS
);
1505 /* VertexShader Constants */
1506 if (ctx
->dirty
& SWR_NEW_VSCONSTANTS
) {
1507 swr_update_constants(ctx
, PIPE_SHADER_VERTEX
);
1510 /* FragmentShader Constants */
1511 if (ctx
->dirty
& SWR_NEW_FSCONSTANTS
) {
1512 swr_update_constants(ctx
, PIPE_SHADER_FRAGMENT
);
1515 /* GeometryShader Constants */
1516 if (ctx
->dirty
& SWR_NEW_GSCONSTANTS
) {
1517 swr_update_constants(ctx
, PIPE_SHADER_GEOMETRY
);
1520 /* Depth/stencil state */
1521 if (ctx
->dirty
& (SWR_NEW_DEPTH_STENCIL_ALPHA
| SWR_NEW_FRAMEBUFFER
)) {
1522 struct pipe_depth_state
*depth
= &(ctx
->depth_stencil
->depth
);
1523 struct pipe_stencil_state
*stencil
= ctx
->depth_stencil
->stencil
;
1524 SWR_DEPTH_STENCIL_STATE depthStencilState
= {{0}};
1525 SWR_DEPTH_BOUNDS_STATE depthBoundsState
= {0};
1527 /* XXX, incomplete. Need to flesh out stencil & alpha test state
1528 struct pipe_stencil_state *front_stencil =
1529 ctx->depth_stencil.stencil[0];
1530 struct pipe_stencil_state *back_stencil = ctx->depth_stencil.stencil[1];
1531 struct pipe_alpha_state alpha;
1533 if (stencil
[0].enabled
) {
1534 depthStencilState
.stencilWriteEnable
= 1;
1535 depthStencilState
.stencilTestEnable
= 1;
1536 depthStencilState
.stencilTestFunc
=
1537 swr_convert_depth_func(stencil
[0].func
);
1539 depthStencilState
.stencilPassDepthPassOp
=
1540 swr_convert_stencil_op(stencil
[0].zpass_op
);
1541 depthStencilState
.stencilPassDepthFailOp
=
1542 swr_convert_stencil_op(stencil
[0].zfail_op
);
1543 depthStencilState
.stencilFailOp
=
1544 swr_convert_stencil_op(stencil
[0].fail_op
);
1545 depthStencilState
.stencilWriteMask
= stencil
[0].writemask
;
1546 depthStencilState
.stencilTestMask
= stencil
[0].valuemask
;
1547 depthStencilState
.stencilRefValue
= ctx
->stencil_ref
.ref_value
[0];
1549 if (stencil
[1].enabled
) {
1550 depthStencilState
.doubleSidedStencilTestEnable
= 1;
1552 depthStencilState
.backfaceStencilTestFunc
=
1553 swr_convert_depth_func(stencil
[1].func
);
1555 depthStencilState
.backfaceStencilPassDepthPassOp
=
1556 swr_convert_stencil_op(stencil
[1].zpass_op
);
1557 depthStencilState
.backfaceStencilPassDepthFailOp
=
1558 swr_convert_stencil_op(stencil
[1].zfail_op
);
1559 depthStencilState
.backfaceStencilFailOp
=
1560 swr_convert_stencil_op(stencil
[1].fail_op
);
1561 depthStencilState
.backfaceStencilWriteMask
= stencil
[1].writemask
;
1562 depthStencilState
.backfaceStencilTestMask
= stencil
[1].valuemask
;
1564 depthStencilState
.backfaceStencilRefValue
=
1565 ctx
->stencil_ref
.ref_value
[1];
1568 depthStencilState
.depthTestEnable
= depth
->enabled
;
1569 depthStencilState
.depthTestFunc
= swr_convert_depth_func(depth
->func
);
1570 depthStencilState
.depthWriteEnable
= depth
->writemask
;
1571 SwrSetDepthStencilState(ctx
->swrContext
, &depthStencilState
);
1573 depthBoundsState
.depthBoundsTestEnable
= depth
->bounds_test
;
1574 depthBoundsState
.depthBoundsTestMinValue
= depth
->bounds_min
;
1575 depthBoundsState
.depthBoundsTestMaxValue
= depth
->bounds_max
;
1576 SwrSetDepthBoundsState(ctx
->swrContext
, &depthBoundsState
);
1580 if (ctx
->dirty
& (SWR_NEW_BLEND
|
1581 SWR_NEW_RASTERIZER
|
1582 SWR_NEW_FRAMEBUFFER
|
1583 SWR_NEW_DEPTH_STENCIL_ALPHA
)) {
1584 struct pipe_framebuffer_state
*fb
= &ctx
->framebuffer
;
1586 SWR_BLEND_STATE blendState
;
1587 memcpy(&blendState
, &ctx
->blend
->blendState
, sizeof(blendState
));
1588 blendState
.constantColor
[0] = ctx
->blend_color
.color
[0];
1589 blendState
.constantColor
[1] = ctx
->blend_color
.color
[1];
1590 blendState
.constantColor
[2] = ctx
->blend_color
.color
[2];
1591 blendState
.constantColor
[3] = ctx
->blend_color
.color
[3];
1592 blendState
.alphaTestReference
=
1593 *((uint32_t*)&ctx
->depth_stencil
->alpha
.ref_value
);
1595 blendState
.sampleMask
= ctx
->sample_mask
;
1596 blendState
.sampleCount
= GetSampleCount(fb
->samples
);
1598 /* If there are no color buffers bound, disable writes on RT0
1600 if (fb
->nr_cbufs
== 0) {
1601 blendState
.renderTarget
[0].writeDisableRed
= 1;
1602 blendState
.renderTarget
[0].writeDisableGreen
= 1;
1603 blendState
.renderTarget
[0].writeDisableBlue
= 1;
1604 blendState
.renderTarget
[0].writeDisableAlpha
= 1;
1605 SwrSetBlendFunc(ctx
->swrContext
, 0, NULL
);
1608 for (int target
= 0;
1609 target
< std::min(SWR_NUM_RENDERTARGETS
,
1610 PIPE_MAX_COLOR_BUFS
);
1612 if (!fb
->cbufs
[target
])
1615 struct swr_resource
*colorBuffer
=
1616 swr_resource(fb
->cbufs
[target
]->texture
);
1618 BLEND_COMPILE_STATE compileState
;
1619 memset(&compileState
, 0, sizeof(compileState
));
1620 compileState
.format
= colorBuffer
->swr
.format
;
1621 memcpy(&compileState
.blendState
,
1622 &ctx
->blend
->compileState
[target
],
1623 sizeof(compileState
.blendState
));
1625 const SWR_FORMAT_INFO
& info
= GetFormatInfo(compileState
.format
);
1626 if (compileState
.blendState
.logicOpEnable
&&
1627 ((info
.type
[0] == SWR_TYPE_FLOAT
) || info
.isSRGB
)) {
1628 compileState
.blendState
.logicOpEnable
= false;
1631 if (info
.type
[0] == SWR_TYPE_SINT
|| info
.type
[0] == SWR_TYPE_UINT
)
1632 compileState
.blendState
.blendEnable
= false;
1634 if (compileState
.blendState
.blendEnable
== false &&
1635 compileState
.blendState
.logicOpEnable
== false &&
1636 ctx
->depth_stencil
->alpha
.enabled
== 0) {
1637 SwrSetBlendFunc(ctx
->swrContext
, target
, NULL
);
1641 compileState
.desc
.alphaTestEnable
=
1642 ctx
->depth_stencil
->alpha
.enabled
;
1643 compileState
.desc
.independentAlphaBlendEnable
=
1644 (compileState
.blendState
.sourceBlendFactor
!=
1645 compileState
.blendState
.sourceAlphaBlendFactor
) ||
1646 (compileState
.blendState
.destBlendFactor
!=
1647 compileState
.blendState
.destAlphaBlendFactor
) ||
1648 (compileState
.blendState
.colorBlendFunc
!=
1649 compileState
.blendState
.alphaBlendFunc
);
1650 compileState
.desc
.alphaToCoverageEnable
=
1651 ctx
->blend
->pipe
.alpha_to_coverage
;
1652 compileState
.desc
.sampleMaskEnable
= (blendState
.sampleMask
!= 0);
1653 compileState
.desc
.numSamples
= fb
->samples
;
1655 compileState
.alphaTestFunction
=
1656 swr_convert_depth_func(ctx
->depth_stencil
->alpha
.func
);
1657 compileState
.alphaTestFormat
= ALPHA_TEST_FLOAT32
; // xxx
1659 compileState
.Canonicalize();
1661 PFN_BLEND_JIT_FUNC func
= NULL
;
1662 auto search
= ctx
->blendJIT
->find(compileState
);
1663 if (search
!= ctx
->blendJIT
->end()) {
1664 func
= search
->second
;
1666 HANDLE hJitMgr
= screen
->hJitMgr
;
1667 func
= JitCompileBlend(hJitMgr
, compileState
);
1668 debug_printf("BLEND shader %p\n", func
);
1669 assert(func
&& "Error: BlendShader = NULL");
1671 ctx
->blendJIT
->insert(std::make_pair(compileState
, func
));
1673 SwrSetBlendFunc(ctx
->swrContext
, target
, func
);
1676 SwrSetBlendState(ctx
->swrContext
, &blendState
);
1679 if (ctx
->dirty
& SWR_NEW_STIPPLE
) {
1680 swr_update_poly_stipple(ctx
);
1683 if (ctx
->dirty
& (SWR_NEW_VS
| SWR_NEW_SO
| SWR_NEW_RASTERIZER
)) {
1684 ctx
->vs
->soState
.rasterizerDisable
=
1685 ctx
->rasterizer
->rasterizer_discard
;
1686 SwrSetSoState(ctx
->swrContext
, &ctx
->vs
->soState
);
1688 pipe_stream_output_info
*stream_output
= &ctx
->vs
->pipe
.stream_output
;
1690 for (uint32_t i
= 0; i
< ctx
->num_so_targets
; i
++) {
1691 SWR_STREAMOUT_BUFFER buffer
= {0};
1692 if (!ctx
->so_targets
[i
])
1694 buffer
.enable
= true;
1696 (uint32_t *)(swr_resource_data(ctx
->so_targets
[i
]->buffer
) +
1697 ctx
->so_targets
[i
]->buffer_offset
);
1698 buffer
.bufferSize
= ctx
->so_targets
[i
]->buffer_size
>> 2;
1699 buffer
.pitch
= stream_output
->stride
[i
];
1700 buffer
.streamOffset
= 0;
1702 SwrSetSoBuffers(ctx
->swrContext
, &buffer
, i
);
1706 if (ctx
->dirty
& (SWR_NEW_CLIP
| SWR_NEW_RASTERIZER
| SWR_NEW_VS
)) {
1707 // shader exporting clip distances overrides all user clip planes
1708 if (ctx
->rasterizer
->clip_plane_enable
&&
1709 !ctx
->vs
->info
.base
.num_written_clipdistance
)
1711 swr_draw_context
*pDC
= &ctx
->swrDC
;
1712 memcpy(pDC
->userClipPlanes
,
1714 sizeof(pDC
->userClipPlanes
));
1718 // set up backend state
1719 SWR_BACKEND_STATE backendState
= {0};
1720 backendState
.numAttributes
=
1721 ((ctx
->gs
? ctx
->gs
->info
.base
.num_outputs
: ctx
->vs
->info
.base
.num_outputs
) - 1) +
1722 (ctx
->rasterizer
->sprite_coord_enable
? 1 : 0);
1723 backendState
.numAttributes
= std::min((size_t)backendState
.numAttributes
,
1724 sizeof(backendState
.numComponents
));
1725 for (unsigned i
= 0; i
< backendState
.numAttributes
; i
++)
1726 backendState
.numComponents
[i
] = 4;
1727 backendState
.constantInterpolationMask
= ctx
->fs
->constantMask
|
1728 (ctx
->rasterizer
->flatshade
? ctx
->fs
->flatConstantMask
: 0);
1729 backendState
.pointSpriteTexCoordMask
= ctx
->fs
->pointSpriteMask
;
1731 SwrSetBackendState(ctx
->swrContext
, &backendState
);
1733 /* Ensure that any in-progress attachment change StoreTiles finish */
1734 if (swr_is_fence_pending(screen
->flush_fence
))
1735 swr_fence_finish(pipe
->screen
, NULL
, screen
->flush_fence
, 0);
1737 /* Finally, update the in-use status of all resources involved in draw */
1738 swr_update_resource_status(pipe
, p_draw_info
);
1740 ctx
->dirty
= post_update_dirty_flags
;
1744 static struct pipe_stream_output_target
*
1745 swr_create_so_target(struct pipe_context
*pipe
,
1746 struct pipe_resource
*buffer
,
1747 unsigned buffer_offset
,
1748 unsigned buffer_size
)
1750 struct pipe_stream_output_target
*target
;
1752 target
= CALLOC_STRUCT(pipe_stream_output_target
);
1756 target
->context
= pipe
;
1757 target
->reference
.count
= 1;
1758 pipe_resource_reference(&target
->buffer
, buffer
);
1759 target
->buffer_offset
= buffer_offset
;
1760 target
->buffer_size
= buffer_size
;
1765 swr_destroy_so_target(struct pipe_context
*pipe
,
1766 struct pipe_stream_output_target
*target
)
1768 pipe_resource_reference(&target
->buffer
, NULL
);
1773 swr_set_so_targets(struct pipe_context
*pipe
,
1774 unsigned num_targets
,
1775 struct pipe_stream_output_target
**targets
,
1776 const unsigned *offsets
)
1778 struct swr_context
*swr
= swr_context(pipe
);
1781 assert(num_targets
<= MAX_SO_STREAMS
);
1783 for (i
= 0; i
< num_targets
; i
++) {
1784 pipe_so_target_reference(
1785 (struct pipe_stream_output_target
**)&swr
->so_targets
[i
],
1789 for (/* fall-through */; i
< swr
->num_so_targets
; i
++) {
1790 pipe_so_target_reference(
1791 (struct pipe_stream_output_target
**)&swr
->so_targets
[i
], NULL
);
1794 swr
->num_so_targets
= num_targets
;
1796 swr
->dirty
|= SWR_NEW_SO
;
1801 swr_state_init(struct pipe_context
*pipe
)
1803 pipe
->create_blend_state
= swr_create_blend_state
;
1804 pipe
->bind_blend_state
= swr_bind_blend_state
;
1805 pipe
->delete_blend_state
= swr_delete_blend_state
;
1807 pipe
->create_depth_stencil_alpha_state
= swr_create_depth_stencil_state
;
1808 pipe
->bind_depth_stencil_alpha_state
= swr_bind_depth_stencil_state
;
1809 pipe
->delete_depth_stencil_alpha_state
= swr_delete_depth_stencil_state
;
1811 pipe
->create_rasterizer_state
= swr_create_rasterizer_state
;
1812 pipe
->bind_rasterizer_state
= swr_bind_rasterizer_state
;
1813 pipe
->delete_rasterizer_state
= swr_delete_rasterizer_state
;
1815 pipe
->create_sampler_state
= swr_create_sampler_state
;
1816 pipe
->bind_sampler_states
= swr_bind_sampler_states
;
1817 pipe
->delete_sampler_state
= swr_delete_sampler_state
;
1819 pipe
->create_sampler_view
= swr_create_sampler_view
;
1820 pipe
->set_sampler_views
= swr_set_sampler_views
;
1821 pipe
->sampler_view_destroy
= swr_sampler_view_destroy
;
1823 pipe
->create_vs_state
= swr_create_vs_state
;
1824 pipe
->bind_vs_state
= swr_bind_vs_state
;
1825 pipe
->delete_vs_state
= swr_delete_vs_state
;
1827 pipe
->create_fs_state
= swr_create_fs_state
;
1828 pipe
->bind_fs_state
= swr_bind_fs_state
;
1829 pipe
->delete_fs_state
= swr_delete_fs_state
;
1831 pipe
->create_gs_state
= swr_create_gs_state
;
1832 pipe
->bind_gs_state
= swr_bind_gs_state
;
1833 pipe
->delete_gs_state
= swr_delete_gs_state
;
1835 pipe
->set_constant_buffer
= swr_set_constant_buffer
;
1837 pipe
->create_vertex_elements_state
= swr_create_vertex_elements_state
;
1838 pipe
->bind_vertex_elements_state
= swr_bind_vertex_elements_state
;
1839 pipe
->delete_vertex_elements_state
= swr_delete_vertex_elements_state
;
1841 pipe
->set_vertex_buffers
= swr_set_vertex_buffers
;
1843 pipe
->set_polygon_stipple
= swr_set_polygon_stipple
;
1844 pipe
->set_clip_state
= swr_set_clip_state
;
1845 pipe
->set_scissor_states
= swr_set_scissor_states
;
1846 pipe
->set_viewport_states
= swr_set_viewport_states
;
1848 pipe
->set_framebuffer_state
= swr_set_framebuffer_state
;
1850 pipe
->set_blend_color
= swr_set_blend_color
;
1851 pipe
->set_stencil_ref
= swr_set_stencil_ref
;
1853 pipe
->set_sample_mask
= swr_set_sample_mask
;
1854 pipe
->get_sample_position
= swr_get_sample_position
;
1856 pipe
->create_stream_output_target
= swr_create_so_target
;
1857 pipe
->stream_output_target_destroy
= swr_destroy_so_target
;
1858 pipe
->set_stream_output_targets
= swr_set_so_targets
;