2 * Copyright 2010 Christoph Bumiller
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 shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "pipe/p_defines.h"
24 #include "util/u_inlines.h"
25 #include "util/u_transfer.h"
27 #include "tgsi/tgsi_parse.h"
29 #include "nv50_stateobj.h"
30 #include "nv50_context.h"
32 #include "nv50_3d.xml.h"
33 #include "nv50_texture.xml.h"
35 #include "nouveau/nouveau_gldefs.h"
37 static INLINE
uint32_t
38 nv50_colormask(unsigned mask
)
42 if (mask
& PIPE_MASK_R
)
44 if (mask
& PIPE_MASK_G
)
46 if (mask
& PIPE_MASK_B
)
48 if (mask
& PIPE_MASK_A
)
54 #define NV50_BLEND_FACTOR_CASE(a, b) \
55 case PIPE_BLENDFACTOR_##a: return NV50_3D_BLEND_FACTOR_##b
57 static INLINE
uint32_t
58 nv50_blend_fac(unsigned factor
)
61 NV50_BLEND_FACTOR_CASE(ONE
, ONE
);
62 NV50_BLEND_FACTOR_CASE(SRC_COLOR
, SRC_COLOR
);
63 NV50_BLEND_FACTOR_CASE(SRC_ALPHA
, SRC_ALPHA
);
64 NV50_BLEND_FACTOR_CASE(DST_ALPHA
, DST_ALPHA
);
65 NV50_BLEND_FACTOR_CASE(DST_COLOR
, DST_COLOR
);
66 NV50_BLEND_FACTOR_CASE(SRC_ALPHA_SATURATE
, SRC_ALPHA_SATURATE
);
67 NV50_BLEND_FACTOR_CASE(CONST_COLOR
, CONSTANT_COLOR
);
68 NV50_BLEND_FACTOR_CASE(CONST_ALPHA
, CONSTANT_ALPHA
);
69 NV50_BLEND_FACTOR_CASE(SRC1_COLOR
, SRC1_COLOR
);
70 NV50_BLEND_FACTOR_CASE(SRC1_ALPHA
, SRC1_ALPHA
);
71 NV50_BLEND_FACTOR_CASE(ZERO
, ZERO
);
72 NV50_BLEND_FACTOR_CASE(INV_SRC_COLOR
, ONE_MINUS_SRC_COLOR
);
73 NV50_BLEND_FACTOR_CASE(INV_SRC_ALPHA
, ONE_MINUS_SRC_ALPHA
);
74 NV50_BLEND_FACTOR_CASE(INV_DST_ALPHA
, ONE_MINUS_DST_ALPHA
);
75 NV50_BLEND_FACTOR_CASE(INV_DST_COLOR
, ONE_MINUS_DST_COLOR
);
76 NV50_BLEND_FACTOR_CASE(INV_CONST_COLOR
, ONE_MINUS_CONSTANT_COLOR
);
77 NV50_BLEND_FACTOR_CASE(INV_CONST_ALPHA
, ONE_MINUS_CONSTANT_ALPHA
);
78 NV50_BLEND_FACTOR_CASE(INV_SRC1_COLOR
, ONE_MINUS_SRC1_COLOR
);
79 NV50_BLEND_FACTOR_CASE(INV_SRC1_ALPHA
, ONE_MINUS_SRC1_ALPHA
);
81 return NV50_3D_BLEND_FACTOR_ZERO
;
86 nv50_blend_state_create(struct pipe_context
*pipe
,
87 const struct pipe_blend_state
*cso
)
89 struct nv50_blend_stateobj
*so
= CALLOC_STRUCT(nv50_blend_stateobj
);
91 boolean emit_common_func
= cso
->rt
[0].blend_enable
;
93 if (nv50_context(pipe
)->screen
->tesla
->grclass
>= NVA3_3D
) {
94 SB_BEGIN_3D(so
, BLEND_INDEPENDENT
, 1);
95 SB_DATA (so
, cso
->independent_blend_enable
);
100 SB_BEGIN_3D(so
, BLEND_ENABLE(0), 8);
101 if (cso
->independent_blend_enable
) {
102 for (i
= 0; i
< 8; ++i
) {
103 SB_DATA(so
, cso
->rt
[i
].blend_enable
);
104 if (cso
->rt
[i
].blend_enable
)
105 emit_common_func
= TRUE
;
108 if (nv50_context(pipe
)->screen
->tesla
->grclass
>= NVA3_3D
) {
109 emit_common_func
= FALSE
;
111 for (i
= 0; i
< 8; ++i
) {
112 if (!cso
->rt
[i
].blend_enable
)
114 SB_BEGIN_3D_(so
, NVA3_3D_IBLEND_EQUATION_RGB(i
), 6);
115 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[i
].rgb_func
));
116 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].rgb_src_factor
));
117 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].rgb_dst_factor
));
118 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[i
].alpha_func
));
119 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].alpha_src_factor
));
120 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].alpha_dst_factor
));
124 for (i
= 0; i
< 8; ++i
)
125 SB_DATA(so
, cso
->rt
[0].blend_enable
);
128 if (emit_common_func
) {
129 SB_BEGIN_3D(so
, BLEND_EQUATION_RGB
, 5);
130 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[0].rgb_func
));
131 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].rgb_src_factor
));
132 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].rgb_dst_factor
));
133 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[0].alpha_func
));
134 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].alpha_src_factor
));
135 SB_BEGIN_3D(so
, BLEND_FUNC_DST_ALPHA
, 1);
136 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].alpha_dst_factor
));
139 if (cso
->logicop_enable
) {
140 SB_BEGIN_3D(so
, LOGIC_OP_ENABLE
, 2);
142 SB_DATA (so
, nvgl_logicop_func(cso
->logicop_func
));
144 SB_BEGIN_3D(so
, LOGIC_OP_ENABLE
, 1);
148 SB_BEGIN_3D(so
, COLOR_MASK(0), 8);
149 if (cso
->independent_blend_enable
) {
150 for (i
= 0; i
< 8; ++i
)
151 SB_DATA(so
, nv50_colormask(cso
->rt
[i
].colormask
));
153 uint32_t cmask
= nv50_colormask(cso
->rt
[0].colormask
);
154 for (i
= 0; i
< 8; ++i
)
158 assert(so
->size
< (sizeof(so
->state
) / sizeof(so
->state
[0])));
163 nv50_blend_state_bind(struct pipe_context
*pipe
, void *hwcso
)
165 struct nv50_context
*nv50
= nv50_context(pipe
);
168 nv50
->dirty
|= NV50_NEW_BLEND
;
172 nv50_blend_state_delete(struct pipe_context
*pipe
, void *hwcso
)
178 nv50_rasterizer_state_create(struct pipe_context
*pipe
,
179 const struct pipe_rasterizer_state
*cso
)
181 struct nv50_rasterizer_stateobj
*so
;
183 so
= CALLOC_STRUCT(nv50_rasterizer_stateobj
);
188 #ifndef NV50_SCISSORS_CLIPPING
189 SB_BEGIN_3D(so
, SCISSOR_ENABLE(0), 1);
190 SB_DATA (so
, cso
->scissor
);
193 SB_BEGIN_3D(so
, SHADE_MODEL
, 1);
194 SB_DATA (so
, cso
->flatshade
? NV50_3D_SHADE_MODEL_FLAT
:
195 NV50_3D_SHADE_MODEL_SMOOTH
);
196 SB_BEGIN_3D(so
, PROVOKING_VERTEX_LAST
, 1);
197 SB_DATA (so
, !cso
->flatshade_first
);
198 SB_BEGIN_3D(so
, VERTEX_TWO_SIDE_ENABLE
, 1);
199 SB_DATA (so
, cso
->light_twoside
);
201 SB_BEGIN_3D(so
, LINE_WIDTH
, 1);
202 SB_DATA (so
, fui(cso
->line_width
));
203 SB_BEGIN_3D(so
, LINE_SMOOTH_ENABLE
, 1);
204 SB_DATA (so
, cso
->line_smooth
);
206 SB_BEGIN_3D(so
, LINE_STIPPLE_ENABLE
, 1);
207 if (cso
->line_stipple_enable
) {
209 SB_BEGIN_3D(so
, LINE_STIPPLE
, 1);
210 SB_DATA (so
, (cso
->line_stipple_pattern
<< 8) |
211 cso
->line_stipple_factor
);
216 if (!cso
->point_size_per_vertex
) {
217 SB_BEGIN_3D(so
, POINT_SIZE
, 1);
218 SB_DATA (so
, fui(cso
->point_size
));
220 SB_BEGIN_3D(so
, POINT_SPRITE_ENABLE
, 1);
221 SB_DATA (so
, cso
->point_quad_rasterization
);
222 SB_BEGIN_3D(so
, POINT_SMOOTH_ENABLE
, 1);
223 SB_DATA (so
, cso
->point_smooth
);
225 SB_BEGIN_3D(so
, POLYGON_MODE_FRONT
, 3);
226 SB_DATA (so
, nvgl_polygon_mode(cso
->fill_front
));
227 SB_DATA (so
, nvgl_polygon_mode(cso
->fill_back
));
228 SB_DATA (so
, cso
->poly_smooth
);
230 SB_BEGIN_3D(so
, CULL_FACE_ENABLE
, 3);
231 SB_DATA (so
, cso
->cull_face
!= PIPE_FACE_NONE
);
232 SB_DATA (so
, cso
->front_ccw
? NV50_3D_FRONT_FACE_CCW
:
233 NV50_3D_FRONT_FACE_CW
);
234 switch (cso
->cull_face
) {
235 case PIPE_FACE_FRONT_AND_BACK
:
236 SB_DATA(so
, NV50_3D_CULL_FACE_FRONT_AND_BACK
);
238 case PIPE_FACE_FRONT
:
239 SB_DATA(so
, NV50_3D_CULL_FACE_FRONT
);
243 SB_DATA(so
, NV50_3D_CULL_FACE_BACK
);
247 SB_BEGIN_3D(so
, POLYGON_STIPPLE_ENABLE
, 1);
248 SB_DATA (so
, cso
->poly_stipple_enable
);
249 SB_BEGIN_3D(so
, POLYGON_OFFSET_POINT_ENABLE
, 3);
250 SB_DATA (so
, cso
->offset_point
);
251 SB_DATA (so
, cso
->offset_line
);
252 SB_DATA (so
, cso
->offset_tri
);
254 if (cso
->offset_point
|| cso
->offset_line
|| cso
->offset_tri
) {
255 SB_BEGIN_3D(so
, POLYGON_OFFSET_FACTOR
, 1);
256 SB_DATA (so
, fui(cso
->offset_scale
));
257 SB_BEGIN_3D(so
, POLYGON_OFFSET_UNITS
, 1);
258 SB_DATA (so
, fui(cso
->offset_units
* 2.0f
));
261 assert(so
->size
< (sizeof(so
->state
) / sizeof(so
->state
[0])));
266 nv50_rasterizer_state_bind(struct pipe_context
*pipe
, void *hwcso
)
268 struct nv50_context
*nv50
= nv50_context(pipe
);
271 nv50
->dirty
|= NV50_NEW_RASTERIZER
;
275 nv50_rasterizer_state_delete(struct pipe_context
*pipe
, void *hwcso
)
281 nv50_zsa_state_create(struct pipe_context
*pipe
,
282 const struct pipe_depth_stencil_alpha_state
*cso
)
284 struct nv50_zsa_stateobj
*so
= CALLOC_STRUCT(nv50_zsa_stateobj
);
288 SB_BEGIN_3D(so
, DEPTH_WRITE_ENABLE
, 1);
289 SB_DATA (so
, cso
->depth
.writemask
);
290 SB_BEGIN_3D(so
, DEPTH_TEST_ENABLE
, 1);
291 if (cso
->depth
.enabled
) {
293 SB_BEGIN_3D(so
, DEPTH_TEST_FUNC
, 1);
294 SB_DATA (so
, nvgl_comparison_op(cso
->depth
.func
));
299 if (cso
->stencil
[0].enabled
) {
300 SB_BEGIN_3D(so
, STENCIL_ENABLE
, 5);
302 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].fail_op
));
303 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].zfail_op
));
304 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].zpass_op
));
305 SB_DATA (so
, nvgl_comparison_op(cso
->stencil
[0].func
));
306 SB_BEGIN_3D(so
, STENCIL_FRONT_MASK
, 2);
307 SB_DATA (so
, cso
->stencil
[0].writemask
);
308 SB_DATA (so
, cso
->stencil
[0].valuemask
);
310 SB_BEGIN_3D(so
, STENCIL_ENABLE
, 1);
314 if (cso
->stencil
[1].enabled
) {
315 assert(cso
->stencil
[0].enabled
);
316 SB_BEGIN_3D(so
, STENCIL_TWO_SIDE_ENABLE
, 5);
318 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].fail_op
));
319 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].zfail_op
));
320 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].zpass_op
));
321 SB_DATA (so
, nvgl_comparison_op(cso
->stencil
[1].func
));
322 SB_BEGIN_3D(so
, STENCIL_BACK_MASK
, 2);
323 SB_DATA (so
, cso
->stencil
[1].writemask
);
324 SB_DATA (so
, cso
->stencil
[1].valuemask
);
326 SB_BEGIN_3D(so
, STENCIL_TWO_SIDE_ENABLE
, 1);
330 SB_BEGIN_3D(so
, ALPHA_TEST_ENABLE
, 1);
331 if (cso
->alpha
.enabled
) {
333 SB_BEGIN_3D(so
, ALPHA_TEST_REF
, 2);
334 SB_DATA (so
, fui(cso
->alpha
.ref_value
));
335 SB_DATA (so
, nvgl_comparison_op(cso
->alpha
.func
));
340 assert(so
->size
< (sizeof(so
->state
) / sizeof(so
->state
[0])));
345 nv50_zsa_state_bind(struct pipe_context
*pipe
, void *hwcso
)
347 struct nv50_context
*nv50
= nv50_context(pipe
);
350 nv50
->dirty
|= NV50_NEW_ZSA
;
354 nv50_zsa_state_delete(struct pipe_context
*pipe
, void *hwcso
)
359 /* ====================== SAMPLERS AND TEXTURES ================================
362 #define NV50_TSC_WRAP_CASE(n) \
363 case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n
365 static INLINE
unsigned
366 nv50_tsc_wrap_mode(unsigned wrap
)
369 NV50_TSC_WRAP_CASE(REPEAT
);
370 NV50_TSC_WRAP_CASE(MIRROR_REPEAT
);
371 NV50_TSC_WRAP_CASE(CLAMP_TO_EDGE
);
372 NV50_TSC_WRAP_CASE(CLAMP_TO_BORDER
);
373 NV50_TSC_WRAP_CASE(CLAMP
);
374 NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_EDGE
);
375 NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_BORDER
);
376 NV50_TSC_WRAP_CASE(MIRROR_CLAMP
);
378 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap
);
379 return NV50_TSC_WRAP_REPEAT
;
384 nv50_sampler_state_create(struct pipe_context
*pipe
,
385 const struct pipe_sampler_state
*cso
)
387 struct nv50_tsc_entry
*so
= CALLOC_STRUCT(nv50_tsc_entry
);
392 so
->tsc
[0] = (0x00026000 |
393 (nv50_tsc_wrap_mode(cso
->wrap_s
) << 0) |
394 (nv50_tsc_wrap_mode(cso
->wrap_t
) << 3) |
395 (nv50_tsc_wrap_mode(cso
->wrap_r
) << 6));
397 switch (cso
->mag_img_filter
) {
398 case PIPE_TEX_FILTER_LINEAR
:
399 so
->tsc
[1] |= NV50_TSC_1_MAGF_LINEAR
;
401 case PIPE_TEX_FILTER_NEAREST
:
403 so
->tsc
[1] |= NV50_TSC_1_MAGF_NEAREST
;
407 switch (cso
->min_img_filter
) {
408 case PIPE_TEX_FILTER_LINEAR
:
409 so
->tsc
[1] |= NV50_TSC_1_MINF_LINEAR
;
411 case PIPE_TEX_FILTER_NEAREST
:
413 so
->tsc
[1] |= NV50_TSC_1_MINF_NEAREST
;
417 switch (cso
->min_mip_filter
) {
418 case PIPE_TEX_MIPFILTER_LINEAR
:
419 so
->tsc
[1] |= NV50_TSC_1_MIPF_LINEAR
;
421 case PIPE_TEX_MIPFILTER_NEAREST
:
422 so
->tsc
[1] |= NV50_TSC_1_MIPF_NEAREST
;
424 case PIPE_TEX_MIPFILTER_NONE
:
426 so
->tsc
[1] |= NV50_TSC_1_MIPF_NONE
;
430 if (cso
->max_anisotropy
>= 16)
431 so
->tsc
[0] |= (7 << 20);
433 if (cso
->max_anisotropy
>= 12)
434 so
->tsc
[0] |= (6 << 20);
436 so
->tsc
[0] |= (cso
->max_anisotropy
>> 1) << 20;
438 if (cso
->max_anisotropy
>= 4)
439 so
->tsc
[1] |= NV50_TSC_1_UNKN_ANISO_35
;
441 if (cso
->max_anisotropy
>= 2)
442 so
->tsc
[1] |= NV50_TSC_1_UNKN_ANISO_15
;
445 if (cso
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
) {
446 /* NOTE: must be deactivated for non-shadow textures */
447 so
->tsc
[0] |= (1 << 9);
448 so
->tsc
[0] |= (nvgl_comparison_op(cso
->compare_func
) & 0x7) << 10;
451 f
[0] = CLAMP(cso
->lod_bias
, -16.0f
, 15.0f
);
452 so
->tsc
[1] |= ((int)(f
[0] * 256.0f
) & 0x1fff) << 12;
454 f
[0] = CLAMP(cso
->min_lod
, 0.0f
, 15.0f
);
455 f
[1] = CLAMP(cso
->max_lod
, 0.0f
, 15.0f
);
457 (((int)(f
[1] * 256.0f
) & 0xfff) << 12) | ((int)(f
[0] * 256.0f
) & 0xfff);
459 so
->tsc
[4] = fui(cso
->border_color
[0]);
460 so
->tsc
[5] = fui(cso
->border_color
[1]);
461 so
->tsc
[6] = fui(cso
->border_color
[2]);
462 so
->tsc
[7] = fui(cso
->border_color
[3]);
468 nv50_sampler_state_delete(struct pipe_context
*pipe
, void *hwcso
)
472 for (s
= 0; s
< 5; ++s
)
473 for (i
= 0; i
< nv50_context(pipe
)->num_samplers
[s
]; ++i
)
474 if (nv50_context(pipe
)->samplers
[s
][i
] == hwcso
)
475 nv50_context(pipe
)->samplers
[s
][i
] = NULL
;
477 nv50_screen_tsc_free(nv50_context(pipe
)->screen
, nv50_tsc_entry(hwcso
));
483 nv50_stage_sampler_states_bind(struct nv50_context
*nv50
, int s
,
484 unsigned nr
, void **hwcso
)
488 for (i
= 0; i
< nr
; ++i
) {
489 struct nv50_tsc_entry
*old
= nv50
->samplers
[s
][i
];
491 nv50
->samplers
[s
][i
] = nv50_tsc_entry(hwcso
[i
]);
493 nv50_screen_tsc_unlock(nv50
->screen
, old
);
495 for (; i
< nv50
->num_samplers
[s
]; ++i
)
496 if (nv50
->samplers
[s
][i
])
497 nv50_screen_tsc_unlock(nv50
->screen
, nv50
->samplers
[s
][i
]);
499 nv50
->num_samplers
[s
] = nr
;
501 nv50
->dirty
|= NV50_NEW_SAMPLERS
;
505 nv50_vp_sampler_states_bind(struct pipe_context
*pipe
, unsigned nr
, void **s
)
507 nv50_stage_sampler_states_bind(nv50_context(pipe
), 0, nr
, s
);
511 nv50_fp_sampler_states_bind(struct pipe_context
*pipe
, unsigned nr
, void **s
)
513 nv50_stage_sampler_states_bind(nv50_context(pipe
), 2, nr
, s
);
517 nv50_gp_sampler_states_bind(struct pipe_context
*pipe
, unsigned nr
, void **s
)
519 nv50_stage_sampler_states_bind(nv50_context(pipe
), 1, nr
, s
);
522 /* NOTE: only called when not referenced anywhere, won't be bound */
524 nv50_sampler_view_destroy(struct pipe_context
*pipe
,
525 struct pipe_sampler_view
*view
)
527 pipe_resource_reference(&view
->texture
, NULL
);
529 nv50_screen_tic_free(nv50_context(pipe
)->screen
, nv50_tic_entry(view
));
531 FREE(nv50_tic_entry(view
));
535 nv50_stage_set_sampler_views(struct nv50_context
*nv50
, int s
,
537 struct pipe_sampler_view
**views
)
541 for (i
= 0; i
< nr
; ++i
) {
542 struct nv50_tic_entry
*old
= nv50_tic_entry(nv50
->textures
[s
][i
]);
544 nv50_screen_tic_unlock(nv50
->screen
, old
);
546 pipe_sampler_view_reference(&nv50
->textures
[s
][i
], views
[i
]);
549 for (i
= nr
; i
< nv50
->num_textures
[s
]; ++i
) {
550 struct nv50_tic_entry
*old
= nv50_tic_entry(nv50
->textures
[s
][i
]);
553 nv50_screen_tic_unlock(nv50
->screen
, old
);
555 pipe_sampler_view_reference(&nv50
->textures
[s
][i
], NULL
);
558 nv50
->num_textures
[s
] = nr
;
560 nv50_bufctx_reset(nv50
, NV50_BUFCTX_TEXTURES
);
562 nv50
->dirty
|= NV50_NEW_TEXTURES
;
566 nv50_vp_set_sampler_views(struct pipe_context
*pipe
,
568 struct pipe_sampler_view
**views
)
570 nv50_stage_set_sampler_views(nv50_context(pipe
), 0, nr
, views
);
574 nv50_fp_set_sampler_views(struct pipe_context
*pipe
,
576 struct pipe_sampler_view
**views
)
578 nv50_stage_set_sampler_views(nv50_context(pipe
), 2, nr
, views
);
582 nv50_gp_set_sampler_views(struct pipe_context
*pipe
,
584 struct pipe_sampler_view
**views
)
586 nv50_stage_set_sampler_views(nv50_context(pipe
), 1, nr
, views
);
589 /* ============================= SHADERS =======================================
593 nv50_sp_state_create(struct pipe_context
*pipe
,
594 const struct pipe_shader_state
*cso
, unsigned type
)
596 struct nv50_program
*prog
;
598 prog
= CALLOC_STRUCT(nv50_program
);
603 prog
->pipe
.tokens
= tgsi_dup_tokens(cso
->tokens
);
609 nv50_sp_state_delete(struct pipe_context
*pipe
, void *hwcso
)
611 struct nv50_program
*prog
= (struct nv50_program
*)hwcso
;
613 nv50_program_destroy(nv50_context(pipe
), prog
);
615 FREE((void *)prog
->pipe
.tokens
);
620 nv50_vp_state_create(struct pipe_context
*pipe
,
621 const struct pipe_shader_state
*cso
)
623 return nv50_sp_state_create(pipe
, cso
, PIPE_SHADER_VERTEX
);
627 nv50_vp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
629 struct nv50_context
*nv50
= nv50_context(pipe
);
631 nv50
->vertprog
= hwcso
;
632 nv50
->dirty
|= NV50_NEW_VERTPROG
;
636 nv50_fp_state_create(struct pipe_context
*pipe
,
637 const struct pipe_shader_state
*cso
)
639 return nv50_sp_state_create(pipe
, cso
, PIPE_SHADER_FRAGMENT
);
643 nv50_fp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
645 struct nv50_context
*nv50
= nv50_context(pipe
);
647 nv50
->fragprog
= hwcso
;
648 nv50
->dirty
|= NV50_NEW_FRAGPROG
;
652 nv50_gp_state_create(struct pipe_context
*pipe
,
653 const struct pipe_shader_state
*cso
)
655 return nv50_sp_state_create(pipe
, cso
, PIPE_SHADER_GEOMETRY
);
659 nv50_gp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
661 struct nv50_context
*nv50
= nv50_context(pipe
);
663 nv50
->gmtyprog
= hwcso
;
664 nv50
->dirty
|= NV50_NEW_GMTYPROG
;
668 nv50_set_constant_buffer(struct pipe_context
*pipe
, uint shader
, uint index
,
669 struct pipe_resource
*res
)
671 struct nv50_context
*nv50
= nv50_context(pipe
);
673 if (nv50
->constbuf
[shader
][index
])
674 nv50_bufctx_del_resident(nv50
, NV50_BUFCTX_CONSTANT
,
675 nv04_resource(nv50
->constbuf
[shader
][index
]));
677 pipe_resource_reference(&nv50
->constbuf
[shader
][index
], res
);
679 nv50
->constbuf_dirty
[shader
] |= 1 << index
;
681 nv50
->dirty
|= NV50_NEW_CONSTBUF
;
684 /* =============================================================================
688 nv50_set_blend_color(struct pipe_context
*pipe
,
689 const struct pipe_blend_color
*bcol
)
691 struct nv50_context
*nv50
= nv50_context(pipe
);
693 nv50
->blend_colour
= *bcol
;
694 nv50
->dirty
|= NV50_NEW_BLEND_COLOUR
;
698 nv50_set_stencil_ref(struct pipe_context
*pipe
,
699 const struct pipe_stencil_ref
*sr
)
701 struct nv50_context
*nv50
= nv50_context(pipe
);
703 nv50
->stencil_ref
= *sr
;
704 nv50
->dirty
|= NV50_NEW_STENCIL_REF
;
708 nv50_set_clip_state(struct pipe_context
*pipe
,
709 const struct pipe_clip_state
*clip
)
711 struct nv50_context
*nv50
= nv50_context(pipe
);
712 const unsigned size
= clip
->nr
* sizeof(clip
->ucp
[0]);
714 memcpy(&nv50
->clip
.ucp
[0][0], &clip
->ucp
[0][0], size
);
715 nv50
->clip
.nr
= clip
->nr
;
717 nv50
->clip
.depth_clamp
= clip
->depth_clamp
;
719 nv50
->dirty
|= NV50_NEW_CLIP
;
723 nv50_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
725 struct nv50_context
*nv50
= nv50_context(pipe
);
727 nv50
->sample_mask
= sample_mask
;
728 nv50
->dirty
|= NV50_NEW_SAMPLE_MASK
;
733 nv50_set_framebuffer_state(struct pipe_context
*pipe
,
734 const struct pipe_framebuffer_state
*fb
)
736 struct nv50_context
*nv50
= nv50_context(pipe
);
738 nv50
->framebuffer
= *fb
;
739 nv50
->dirty
|= NV50_NEW_FRAMEBUFFER
;
743 nv50_set_polygon_stipple(struct pipe_context
*pipe
,
744 const struct pipe_poly_stipple
*stipple
)
746 struct nv50_context
*nv50
= nv50_context(pipe
);
748 nv50
->stipple
= *stipple
;
749 nv50
->dirty
|= NV50_NEW_STIPPLE
;
753 nv50_set_scissor_state(struct pipe_context
*pipe
,
754 const struct pipe_scissor_state
*scissor
)
756 struct nv50_context
*nv50
= nv50_context(pipe
);
758 nv50
->scissor
= *scissor
;
759 nv50
->dirty
|= NV50_NEW_SCISSOR
;
763 nv50_set_viewport_state(struct pipe_context
*pipe
,
764 const struct pipe_viewport_state
*vpt
)
766 struct nv50_context
*nv50
= nv50_context(pipe
);
768 nv50
->viewport
= *vpt
;
769 nv50
->dirty
|= NV50_NEW_VIEWPORT
;
773 nv50_set_vertex_buffers(struct pipe_context
*pipe
,
775 const struct pipe_vertex_buffer
*vb
)
777 struct nv50_context
*nv50
= nv50_context(pipe
);
780 for (i
= 0; i
< count
; ++i
)
781 pipe_resource_reference(&nv50
->vtxbuf
[i
].buffer
, vb
[i
].buffer
);
782 for (; i
< nv50
->num_vtxbufs
; ++i
)
783 pipe_resource_reference(&nv50
->vtxbuf
[i
].buffer
, NULL
);
785 memcpy(nv50
->vtxbuf
, vb
, sizeof(*vb
) * count
);
786 nv50
->num_vtxbufs
= count
;
788 nv50_bufctx_reset(nv50
, NV50_BUFCTX_VERTEX
);
790 nv50
->dirty
|= NV50_NEW_ARRAYS
;
794 nv50_set_index_buffer(struct pipe_context
*pipe
,
795 const struct pipe_index_buffer
*ib
)
797 struct nv50_context
*nv50
= nv50_context(pipe
);
800 pipe_resource_reference(&nv50
->idxbuf
.buffer
, ib
->buffer
);
802 memcpy(&nv50
->idxbuf
, ib
, sizeof(nv50
->idxbuf
));
804 pipe_resource_reference(&nv50
->idxbuf
.buffer
, NULL
);
809 nv50_vertex_state_bind(struct pipe_context
*pipe
, void *hwcso
)
811 struct nv50_context
*nv50
= nv50_context(pipe
);
813 nv50
->vertex
= hwcso
;
814 nv50
->dirty
|= NV50_NEW_VERTEX
;
818 nv50_init_state_functions(struct nv50_context
*nv50
)
820 struct pipe_context
*pipe
= &nv50
->base
.pipe
;
822 pipe
->create_blend_state
= nv50_blend_state_create
;
823 pipe
->bind_blend_state
= nv50_blend_state_bind
;
824 pipe
->delete_blend_state
= nv50_blend_state_delete
;
826 pipe
->create_rasterizer_state
= nv50_rasterizer_state_create
;
827 pipe
->bind_rasterizer_state
= nv50_rasterizer_state_bind
;
828 pipe
->delete_rasterizer_state
= nv50_rasterizer_state_delete
;
830 pipe
->create_depth_stencil_alpha_state
= nv50_zsa_state_create
;
831 pipe
->bind_depth_stencil_alpha_state
= nv50_zsa_state_bind
;
832 pipe
->delete_depth_stencil_alpha_state
= nv50_zsa_state_delete
;
834 pipe
->create_sampler_state
= nv50_sampler_state_create
;
835 pipe
->delete_sampler_state
= nv50_sampler_state_delete
;
836 pipe
->bind_vertex_sampler_states
= nv50_vp_sampler_states_bind
;
837 pipe
->bind_fragment_sampler_states
= nv50_fp_sampler_states_bind
;
838 pipe
->bind_geometry_sampler_states
= nv50_gp_sampler_states_bind
;
840 pipe
->create_sampler_view
= nv50_create_sampler_view
;
841 pipe
->sampler_view_destroy
= nv50_sampler_view_destroy
;
842 pipe
->set_vertex_sampler_views
= nv50_vp_set_sampler_views
;
843 pipe
->set_fragment_sampler_views
= nv50_fp_set_sampler_views
;
844 pipe
->set_geometry_sampler_views
= nv50_gp_set_sampler_views
;
846 pipe
->create_vs_state
= nv50_vp_state_create
;
847 pipe
->create_fs_state
= nv50_fp_state_create
;
848 pipe
->create_gs_state
= nv50_gp_state_create
;
849 pipe
->bind_vs_state
= nv50_vp_state_bind
;
850 pipe
->bind_fs_state
= nv50_fp_state_bind
;
851 pipe
->bind_gs_state
= nv50_gp_state_bind
;
852 pipe
->delete_vs_state
= nv50_sp_state_delete
;
853 pipe
->delete_fs_state
= nv50_sp_state_delete
;
854 pipe
->delete_gs_state
= nv50_sp_state_delete
;
856 pipe
->set_blend_color
= nv50_set_blend_color
;
857 pipe
->set_stencil_ref
= nv50_set_stencil_ref
;
858 pipe
->set_clip_state
= nv50_set_clip_state
;
859 pipe
->set_sample_mask
= nv50_set_sample_mask
;
860 pipe
->set_constant_buffer
= nv50_set_constant_buffer
;
861 pipe
->set_framebuffer_state
= nv50_set_framebuffer_state
;
862 pipe
->set_polygon_stipple
= nv50_set_polygon_stipple
;
863 pipe
->set_scissor_state
= nv50_set_scissor_state
;
864 pipe
->set_viewport_state
= nv50_set_viewport_state
;
866 pipe
->create_vertex_elements_state
= nv50_vertex_state_create
;
867 pipe
->delete_vertex_elements_state
= nv50_vertex_state_delete
;
868 pipe
->bind_vertex_elements_state
= nv50_vertex_state_bind
;
870 pipe
->set_vertex_buffers
= nv50_set_vertex_buffers
;
871 pipe
->set_index_buffer
= nv50_set_index_buffer
;
873 pipe
->redefine_user_buffer
= u_default_redefine_user_buffer
;