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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include "pipe/p_defines.h"
24 #include "util/u_helpers.h"
25 #include "util/u_inlines.h"
26 #include "util/u_transfer.h"
27 #include "util/format_srgb.h"
29 #include "tgsi/tgsi_parse.h"
31 #include "nv50/nv50_stateobj.h"
32 #include "nv50/nv50_context.h"
33 #include "nv50/nv50_query_hw.h"
35 #include "nv50/nv50_3d.xml.h"
36 #include "nv50/nv50_texture.xml.h"
38 #include "nouveau_gldefs.h"
41 * ! pipe_sampler_state.normalized_coords is ignored - rectangle textures will
42 * use non-normalized coordinates, everything else won't
43 * (The relevant bit is in the TIC entry and not the TSC entry.)
45 * ! pipe_sampler_state.seamless_cube_map is ignored - seamless filtering is
46 * always activated on NVA0 +
47 * (Give me the global bit, otherwise it's not worth the CPU work.)
49 * ! pipe_sampler_state.border_color is not swizzled according to the texture
50 * swizzle in pipe_sampler_view
51 * (This will be ugly with indirect independent texture/sampler access,
52 * we'd have to emulate the logic in the shader. GL doesn't have that,
53 * D3D doesn't have swizzle, if we knew what we were implementing we'd be
56 * ! pipe_rasterizer_state.line_last_pixel is ignored - it is never drawn
58 * ! pipe_rasterizer_state.flatshade_first also applies to QUADS
59 * (There's a GL query for that, forcing an exception is just ridiculous.)
61 * ! pipe_rasterizer_state.sprite_coord_enable is masked with 0xff on NVC0
62 * (The hardware only has 8 slots meant for TexCoord and we have to assign
63 * in advance to maintain elegant separate shader objects.)
66 static inline uint32_t
67 nv50_colormask(unsigned mask
)
71 if (mask
& PIPE_MASK_R
)
73 if (mask
& PIPE_MASK_G
)
75 if (mask
& PIPE_MASK_B
)
77 if (mask
& PIPE_MASK_A
)
83 #define NV50_BLEND_FACTOR_CASE(a, b) \
84 case PIPE_BLENDFACTOR_##a: return NV50_BLEND_FACTOR_##b
86 static inline uint32_t
87 nv50_blend_fac(unsigned factor
)
90 NV50_BLEND_FACTOR_CASE(ONE
, ONE
);
91 NV50_BLEND_FACTOR_CASE(SRC_COLOR
, SRC_COLOR
);
92 NV50_BLEND_FACTOR_CASE(SRC_ALPHA
, SRC_ALPHA
);
93 NV50_BLEND_FACTOR_CASE(DST_ALPHA
, DST_ALPHA
);
94 NV50_BLEND_FACTOR_CASE(DST_COLOR
, DST_COLOR
);
95 NV50_BLEND_FACTOR_CASE(SRC_ALPHA_SATURATE
, SRC_ALPHA_SATURATE
);
96 NV50_BLEND_FACTOR_CASE(CONST_COLOR
, CONSTANT_COLOR
);
97 NV50_BLEND_FACTOR_CASE(CONST_ALPHA
, CONSTANT_ALPHA
);
98 NV50_BLEND_FACTOR_CASE(SRC1_COLOR
, SRC1_COLOR
);
99 NV50_BLEND_FACTOR_CASE(SRC1_ALPHA
, SRC1_ALPHA
);
100 NV50_BLEND_FACTOR_CASE(ZERO
, ZERO
);
101 NV50_BLEND_FACTOR_CASE(INV_SRC_COLOR
, ONE_MINUS_SRC_COLOR
);
102 NV50_BLEND_FACTOR_CASE(INV_SRC_ALPHA
, ONE_MINUS_SRC_ALPHA
);
103 NV50_BLEND_FACTOR_CASE(INV_DST_ALPHA
, ONE_MINUS_DST_ALPHA
);
104 NV50_BLEND_FACTOR_CASE(INV_DST_COLOR
, ONE_MINUS_DST_COLOR
);
105 NV50_BLEND_FACTOR_CASE(INV_CONST_COLOR
, ONE_MINUS_CONSTANT_COLOR
);
106 NV50_BLEND_FACTOR_CASE(INV_CONST_ALPHA
, ONE_MINUS_CONSTANT_ALPHA
);
107 NV50_BLEND_FACTOR_CASE(INV_SRC1_COLOR
, ONE_MINUS_SRC1_COLOR
);
108 NV50_BLEND_FACTOR_CASE(INV_SRC1_ALPHA
, ONE_MINUS_SRC1_ALPHA
);
110 return NV50_BLEND_FACTOR_ZERO
;
115 nv50_blend_state_create(struct pipe_context
*pipe
,
116 const struct pipe_blend_state
*cso
)
118 struct nv50_blend_stateobj
*so
= CALLOC_STRUCT(nv50_blend_stateobj
);
120 bool emit_common_func
= cso
->rt
[0].blend_enable
;
122 if (nv50_context(pipe
)->screen
->tesla
->oclass
>= NVA3_3D_CLASS
) {
123 SB_BEGIN_3D(so
, BLEND_INDEPENDENT
, 1);
124 SB_DATA (so
, cso
->independent_blend_enable
);
129 SB_BEGIN_3D(so
, COLOR_MASK_COMMON
, 1);
130 SB_DATA (so
, !cso
->independent_blend_enable
);
132 SB_BEGIN_3D(so
, BLEND_ENABLE_COMMON
, 1);
133 SB_DATA (so
, !cso
->independent_blend_enable
);
135 if (cso
->independent_blend_enable
) {
136 SB_BEGIN_3D(so
, BLEND_ENABLE(0), 8);
137 for (i
= 0; i
< 8; ++i
) {
138 SB_DATA(so
, cso
->rt
[i
].blend_enable
);
139 if (cso
->rt
[i
].blend_enable
)
140 emit_common_func
= true;
143 if (nv50_context(pipe
)->screen
->tesla
->oclass
>= NVA3_3D_CLASS
) {
144 emit_common_func
= false;
146 for (i
= 0; i
< 8; ++i
) {
147 if (!cso
->rt
[i
].blend_enable
)
149 SB_BEGIN_3D_(so
, NVA3_3D_IBLEND_EQUATION_RGB(i
), 6);
150 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[i
].rgb_func
));
151 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].rgb_src_factor
));
152 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].rgb_dst_factor
));
153 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[i
].alpha_func
));
154 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].alpha_src_factor
));
155 SB_DATA (so
, nv50_blend_fac(cso
->rt
[i
].alpha_dst_factor
));
159 SB_BEGIN_3D(so
, BLEND_ENABLE(0), 1);
160 SB_DATA (so
, cso
->rt
[0].blend_enable
);
163 if (emit_common_func
) {
164 SB_BEGIN_3D(so
, BLEND_EQUATION_RGB
, 5);
165 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[0].rgb_func
));
166 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].rgb_src_factor
));
167 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].rgb_dst_factor
));
168 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[0].alpha_func
));
169 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].alpha_src_factor
));
170 SB_BEGIN_3D(so
, BLEND_FUNC_DST_ALPHA
, 1);
171 SB_DATA (so
, nv50_blend_fac(cso
->rt
[0].alpha_dst_factor
));
174 if (cso
->logicop_enable
) {
175 SB_BEGIN_3D(so
, LOGIC_OP_ENABLE
, 2);
177 SB_DATA (so
, nvgl_logicop_func(cso
->logicop_func
));
179 SB_BEGIN_3D(so
, LOGIC_OP_ENABLE
, 1);
183 if (cso
->independent_blend_enable
) {
184 SB_BEGIN_3D(so
, COLOR_MASK(0), 8);
185 for (i
= 0; i
< 8; ++i
)
186 SB_DATA(so
, nv50_colormask(cso
->rt
[i
].colormask
));
188 SB_BEGIN_3D(so
, COLOR_MASK(0), 1);
189 SB_DATA (so
, nv50_colormask(cso
->rt
[0].colormask
));
192 assert(so
->size
<= ARRAY_SIZE(so
->state
));
197 nv50_blend_state_bind(struct pipe_context
*pipe
, void *hwcso
)
199 struct nv50_context
*nv50
= nv50_context(pipe
);
202 nv50
->dirty
|= NV50_NEW_BLEND
;
206 nv50_blend_state_delete(struct pipe_context
*pipe
, void *hwcso
)
211 /* NOTE: ignoring line_last_pixel */
213 nv50_rasterizer_state_create(struct pipe_context
*pipe
,
214 const struct pipe_rasterizer_state
*cso
)
216 struct nv50_rasterizer_stateobj
*so
;
219 so
= CALLOC_STRUCT(nv50_rasterizer_stateobj
);
224 #ifndef NV50_SCISSORS_CLIPPING
225 for (int i
= 0; i
< NV50_MAX_VIEWPORTS
; i
++) {
226 SB_BEGIN_3D(so
, SCISSOR_ENABLE(i
), 1);
227 SB_DATA (so
, cso
->scissor
);
231 SB_BEGIN_3D(so
, SHADE_MODEL
, 1);
232 SB_DATA (so
, cso
->flatshade
? NV50_3D_SHADE_MODEL_FLAT
:
233 NV50_3D_SHADE_MODEL_SMOOTH
);
234 SB_BEGIN_3D(so
, PROVOKING_VERTEX_LAST
, 1);
235 SB_DATA (so
, !cso
->flatshade_first
);
236 SB_BEGIN_3D(so
, VERTEX_TWO_SIDE_ENABLE
, 1);
237 SB_DATA (so
, cso
->light_twoside
);
239 SB_BEGIN_3D(so
, FRAG_COLOR_CLAMP_EN
, 1);
240 SB_DATA (so
, cso
->clamp_fragment_color
? 0x11111111 : 0x00000000);
242 SB_BEGIN_3D(so
, MULTISAMPLE_ENABLE
, 1);
243 SB_DATA (so
, cso
->multisample
);
245 SB_BEGIN_3D(so
, LINE_WIDTH
, 1);
246 SB_DATA (so
, fui(cso
->line_width
));
247 SB_BEGIN_3D(so
, LINE_SMOOTH_ENABLE
, 1);
248 SB_DATA (so
, cso
->line_smooth
);
250 SB_BEGIN_3D(so
, LINE_STIPPLE_ENABLE
, 1);
251 if (cso
->line_stipple_enable
) {
253 SB_BEGIN_3D(so
, LINE_STIPPLE
, 1);
254 SB_DATA (so
, (cso
->line_stipple_pattern
<< 8) |
255 cso
->line_stipple_factor
);
260 if (!cso
->point_size_per_vertex
) {
261 SB_BEGIN_3D(so
, POINT_SIZE
, 1);
262 SB_DATA (so
, fui(cso
->point_size
));
264 SB_BEGIN_3D(so
, POINT_SPRITE_ENABLE
, 1);
265 SB_DATA (so
, cso
->point_quad_rasterization
);
266 SB_BEGIN_3D(so
, POINT_SMOOTH_ENABLE
, 1);
267 SB_DATA (so
, cso
->point_smooth
);
269 SB_BEGIN_3D(so
, POLYGON_MODE_FRONT
, 3);
270 SB_DATA (so
, nvgl_polygon_mode(cso
->fill_front
));
271 SB_DATA (so
, nvgl_polygon_mode(cso
->fill_back
));
272 SB_DATA (so
, cso
->poly_smooth
);
274 SB_BEGIN_3D(so
, CULL_FACE_ENABLE
, 3);
275 SB_DATA (so
, cso
->cull_face
!= PIPE_FACE_NONE
);
276 SB_DATA (so
, cso
->front_ccw
? NV50_3D_FRONT_FACE_CCW
:
277 NV50_3D_FRONT_FACE_CW
);
278 switch (cso
->cull_face
) {
279 case PIPE_FACE_FRONT_AND_BACK
:
280 SB_DATA(so
, NV50_3D_CULL_FACE_FRONT_AND_BACK
);
282 case PIPE_FACE_FRONT
:
283 SB_DATA(so
, NV50_3D_CULL_FACE_FRONT
);
287 SB_DATA(so
, NV50_3D_CULL_FACE_BACK
);
291 SB_BEGIN_3D(so
, POLYGON_STIPPLE_ENABLE
, 1);
292 SB_DATA (so
, cso
->poly_stipple_enable
);
293 SB_BEGIN_3D(so
, POLYGON_OFFSET_POINT_ENABLE
, 3);
294 SB_DATA (so
, cso
->offset_point
);
295 SB_DATA (so
, cso
->offset_line
);
296 SB_DATA (so
, cso
->offset_tri
);
298 if (cso
->offset_point
|| cso
->offset_line
|| cso
->offset_tri
) {
299 SB_BEGIN_3D(so
, POLYGON_OFFSET_FACTOR
, 1);
300 SB_DATA (so
, fui(cso
->offset_scale
));
301 SB_BEGIN_3D(so
, POLYGON_OFFSET_UNITS
, 1);
302 SB_DATA (so
, fui(cso
->offset_units
* 2.0f
));
303 SB_BEGIN_3D(so
, POLYGON_OFFSET_CLAMP
, 1);
304 SB_DATA (so
, fui(cso
->offset_clamp
));
307 if (cso
->depth_clip
) {
311 NV50_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_NEAR
|
312 NV50_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_FAR
|
313 NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK1
;
315 #ifndef NV50_SCISSORS_CLIPPING
317 NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK7
|
318 NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK1
;
320 SB_BEGIN_3D(so
, VIEW_VOLUME_CLIP_CTRL
, 1);
323 SB_BEGIN_3D(so
, DEPTH_CLIP_NEGATIVE_Z
, 1);
324 SB_DATA (so
, cso
->clip_halfz
);
326 SB_BEGIN_3D(so
, PIXEL_CENTER_INTEGER
, 1);
327 SB_DATA (so
, !cso
->half_pixel_center
);
329 assert(so
->size
<= ARRAY_SIZE(so
->state
));
334 nv50_rasterizer_state_bind(struct pipe_context
*pipe
, void *hwcso
)
336 struct nv50_context
*nv50
= nv50_context(pipe
);
339 nv50
->dirty
|= NV50_NEW_RASTERIZER
;
343 nv50_rasterizer_state_delete(struct pipe_context
*pipe
, void *hwcso
)
349 nv50_zsa_state_create(struct pipe_context
*pipe
,
350 const struct pipe_depth_stencil_alpha_state
*cso
)
352 struct nv50_zsa_stateobj
*so
= CALLOC_STRUCT(nv50_zsa_stateobj
);
356 SB_BEGIN_3D(so
, DEPTH_WRITE_ENABLE
, 1);
357 SB_DATA (so
, cso
->depth
.writemask
);
358 SB_BEGIN_3D(so
, DEPTH_TEST_ENABLE
, 1);
359 if (cso
->depth
.enabled
) {
361 SB_BEGIN_3D(so
, DEPTH_TEST_FUNC
, 1);
362 SB_DATA (so
, nvgl_comparison_op(cso
->depth
.func
));
367 SB_BEGIN_3D(so
, DEPTH_BOUNDS_EN
, 1);
368 if (cso
->depth
.bounds_test
) {
370 SB_BEGIN_3D(so
, DEPTH_BOUNDS(0), 2);
371 SB_DATA (so
, fui(cso
->depth
.bounds_min
));
372 SB_DATA (so
, fui(cso
->depth
.bounds_max
));
377 if (cso
->stencil
[0].enabled
) {
378 SB_BEGIN_3D(so
, STENCIL_ENABLE
, 5);
380 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].fail_op
));
381 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].zfail_op
));
382 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].zpass_op
));
383 SB_DATA (so
, nvgl_comparison_op(cso
->stencil
[0].func
));
384 SB_BEGIN_3D(so
, STENCIL_FRONT_MASK
, 2);
385 SB_DATA (so
, cso
->stencil
[0].writemask
);
386 SB_DATA (so
, cso
->stencil
[0].valuemask
);
388 SB_BEGIN_3D(so
, STENCIL_ENABLE
, 1);
392 if (cso
->stencil
[1].enabled
) {
393 assert(cso
->stencil
[0].enabled
);
394 SB_BEGIN_3D(so
, STENCIL_TWO_SIDE_ENABLE
, 5);
396 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].fail_op
));
397 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].zfail_op
));
398 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].zpass_op
));
399 SB_DATA (so
, nvgl_comparison_op(cso
->stencil
[1].func
));
400 SB_BEGIN_3D(so
, STENCIL_BACK_MASK
, 2);
401 SB_DATA (so
, cso
->stencil
[1].writemask
);
402 SB_DATA (so
, cso
->stencil
[1].valuemask
);
404 SB_BEGIN_3D(so
, STENCIL_TWO_SIDE_ENABLE
, 1);
408 SB_BEGIN_3D(so
, ALPHA_TEST_ENABLE
, 1);
409 if (cso
->alpha
.enabled
) {
411 SB_BEGIN_3D(so
, ALPHA_TEST_REF
, 2);
412 SB_DATA (so
, fui(cso
->alpha
.ref_value
));
413 SB_DATA (so
, nvgl_comparison_op(cso
->alpha
.func
));
418 assert(so
->size
<= ARRAY_SIZE(so
->state
));
423 nv50_zsa_state_bind(struct pipe_context
*pipe
, void *hwcso
)
425 struct nv50_context
*nv50
= nv50_context(pipe
);
428 nv50
->dirty
|= NV50_NEW_ZSA
;
432 nv50_zsa_state_delete(struct pipe_context
*pipe
, void *hwcso
)
437 /* ====================== SAMPLERS AND TEXTURES ================================
440 #define NV50_TSC_WRAP_CASE(n) \
441 case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n
443 static inline unsigned
444 nv50_tsc_wrap_mode(unsigned wrap
)
447 NV50_TSC_WRAP_CASE(REPEAT
);
448 NV50_TSC_WRAP_CASE(MIRROR_REPEAT
);
449 NV50_TSC_WRAP_CASE(CLAMP_TO_EDGE
);
450 NV50_TSC_WRAP_CASE(CLAMP_TO_BORDER
);
451 NV50_TSC_WRAP_CASE(CLAMP
);
452 NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_EDGE
);
453 NV50_TSC_WRAP_CASE(MIRROR_CLAMP_TO_BORDER
);
454 NV50_TSC_WRAP_CASE(MIRROR_CLAMP
);
456 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap
);
457 return NV50_TSC_WRAP_REPEAT
;
462 nv50_sampler_state_create(struct pipe_context
*pipe
,
463 const struct pipe_sampler_state
*cso
)
465 struct nv50_tsc_entry
*so
= MALLOC_STRUCT(nv50_tsc_entry
);
470 so
->tsc
[0] = (0x00026000 |
471 (nv50_tsc_wrap_mode(cso
->wrap_s
) << 0) |
472 (nv50_tsc_wrap_mode(cso
->wrap_t
) << 3) |
473 (nv50_tsc_wrap_mode(cso
->wrap_r
) << 6));
475 switch (cso
->mag_img_filter
) {
476 case PIPE_TEX_FILTER_LINEAR
:
477 so
->tsc
[1] = NV50_TSC_1_MAGF_LINEAR
;
479 case PIPE_TEX_FILTER_NEAREST
:
481 so
->tsc
[1] = NV50_TSC_1_MAGF_NEAREST
;
485 switch (cso
->min_img_filter
) {
486 case PIPE_TEX_FILTER_LINEAR
:
487 so
->tsc
[1] |= NV50_TSC_1_MINF_LINEAR
;
489 case PIPE_TEX_FILTER_NEAREST
:
491 so
->tsc
[1] |= NV50_TSC_1_MINF_NEAREST
;
495 switch (cso
->min_mip_filter
) {
496 case PIPE_TEX_MIPFILTER_LINEAR
:
497 so
->tsc
[1] |= NV50_TSC_1_MIPF_LINEAR
;
499 case PIPE_TEX_MIPFILTER_NEAREST
:
500 so
->tsc
[1] |= NV50_TSC_1_MIPF_NEAREST
;
502 case PIPE_TEX_MIPFILTER_NONE
:
504 so
->tsc
[1] |= NV50_TSC_1_MIPF_NONE
;
508 if (nouveau_screen(pipe
->screen
)->class_3d
>= NVE4_3D_CLASS
) {
509 if (cso
->seamless_cube_map
)
510 so
->tsc
[1] |= NVE4_TSC_1_CUBE_SEAMLESS
;
511 if (!cso
->normalized_coords
)
512 so
->tsc
[1] |= NVE4_TSC_1_FORCE_NONNORMALIZED_COORDS
;
515 if (cso
->max_anisotropy
>= 16)
516 so
->tsc
[0] |= (7 << 20);
518 if (cso
->max_anisotropy
>= 12)
519 so
->tsc
[0] |= (6 << 20);
521 so
->tsc
[0] |= (cso
->max_anisotropy
>> 1) << 20;
523 if (cso
->max_anisotropy
>= 4)
524 so
->tsc
[1] |= NV50_TSC_1_UNKN_ANISO_35
;
526 if (cso
->max_anisotropy
>= 2)
527 so
->tsc
[1] |= NV50_TSC_1_UNKN_ANISO_15
;
530 if (cso
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
) {
531 /* NOTE: must be deactivated for non-shadow textures */
532 so
->tsc
[0] |= (1 << 9);
533 so
->tsc
[0] |= (nvgl_comparison_op(cso
->compare_func
) & 0x7) << 10;
536 f
[0] = CLAMP(cso
->lod_bias
, -16.0f
, 15.0f
);
537 so
->tsc
[1] |= ((int)(f
[0] * 256.0f
) & 0x1fff) << 12;
539 f
[0] = CLAMP(cso
->min_lod
, 0.0f
, 15.0f
);
540 f
[1] = CLAMP(cso
->max_lod
, 0.0f
, 15.0f
);
542 (((int)(f
[1] * 256.0f
) & 0xfff) << 12) | ((int)(f
[0] * 256.0f
) & 0xfff);
545 util_format_linear_float_to_srgb_8unorm(cso
->border_color
.f
[0]) << 24;
547 util_format_linear_float_to_srgb_8unorm(cso
->border_color
.f
[1]) << 12;
549 util_format_linear_float_to_srgb_8unorm(cso
->border_color
.f
[2]) << 20;
551 so
->tsc
[4] = fui(cso
->border_color
.f
[0]);
552 so
->tsc
[5] = fui(cso
->border_color
.f
[1]);
553 so
->tsc
[6] = fui(cso
->border_color
.f
[2]);
554 so
->tsc
[7] = fui(cso
->border_color
.f
[3]);
560 nv50_sampler_state_delete(struct pipe_context
*pipe
, void *hwcso
)
564 for (s
= 0; s
< 3; ++s
) {
565 assert(nv50_context(pipe
)->num_samplers
[s
] <= PIPE_MAX_SAMPLERS
);
566 for (i
= 0; i
< nv50_context(pipe
)->num_samplers
[s
]; ++i
)
567 if (nv50_context(pipe
)->samplers
[s
][i
] == hwcso
)
568 nv50_context(pipe
)->samplers
[s
][i
] = NULL
;
571 nv50_screen_tsc_free(nv50_context(pipe
)->screen
, nv50_tsc_entry(hwcso
));
577 nv50_stage_sampler_states_bind(struct nv50_context
*nv50
, int s
,
578 unsigned nr
, void **hwcso
)
582 assert(nr
<= PIPE_MAX_SAMPLERS
);
583 for (i
= 0; i
< nr
; ++i
) {
584 struct nv50_tsc_entry
*old
= nv50
->samplers
[s
][i
];
586 nv50
->samplers
[s
][i
] = nv50_tsc_entry(hwcso
[i
]);
588 nv50_screen_tsc_unlock(nv50
->screen
, old
);
590 assert(nv50
->num_samplers
[s
] <= PIPE_MAX_SAMPLERS
);
591 for (; i
< nv50
->num_samplers
[s
]; ++i
) {
592 if (nv50
->samplers
[s
][i
]) {
593 nv50_screen_tsc_unlock(nv50
->screen
, nv50
->samplers
[s
][i
]);
594 nv50
->samplers
[s
][i
] = NULL
;
598 nv50
->num_samplers
[s
] = nr
;
600 nv50
->dirty
|= NV50_NEW_SAMPLERS
;
604 nv50_vp_sampler_states_bind(struct pipe_context
*pipe
, unsigned nr
, void **s
)
606 nv50_stage_sampler_states_bind(nv50_context(pipe
), 0, nr
, s
);
610 nv50_fp_sampler_states_bind(struct pipe_context
*pipe
, unsigned nr
, void **s
)
612 nv50_stage_sampler_states_bind(nv50_context(pipe
), 2, nr
, s
);
616 nv50_gp_sampler_states_bind(struct pipe_context
*pipe
, unsigned nr
, void **s
)
618 nv50_stage_sampler_states_bind(nv50_context(pipe
), 1, nr
, s
);
622 nv50_bind_sampler_states(struct pipe_context
*pipe
,
623 unsigned shader
, unsigned start
,
624 unsigned num_samplers
, void **samplers
)
628 case PIPE_SHADER_VERTEX
:
629 nv50_vp_sampler_states_bind(pipe
, num_samplers
, samplers
);
631 case PIPE_SHADER_GEOMETRY
:
632 nv50_gp_sampler_states_bind(pipe
, num_samplers
, samplers
);
634 case PIPE_SHADER_FRAGMENT
:
635 nv50_fp_sampler_states_bind(pipe
, num_samplers
, samplers
);
642 /* NOTE: only called when not referenced anywhere, won't be bound */
644 nv50_sampler_view_destroy(struct pipe_context
*pipe
,
645 struct pipe_sampler_view
*view
)
647 pipe_resource_reference(&view
->texture
, NULL
);
649 nv50_screen_tic_free(nv50_context(pipe
)->screen
, nv50_tic_entry(view
));
651 FREE(nv50_tic_entry(view
));
655 nv50_stage_set_sampler_views(struct nv50_context
*nv50
, int s
,
657 struct pipe_sampler_view
**views
)
661 assert(nr
<= PIPE_MAX_SAMPLERS
);
662 for (i
= 0; i
< nr
; ++i
) {
663 struct nv50_tic_entry
*old
= nv50_tic_entry(nv50
->textures
[s
][i
]);
665 nv50_screen_tic_unlock(nv50
->screen
, old
);
667 if (views
[i
] && views
[i
]->texture
) {
668 struct pipe_resource
*res
= views
[i
]->texture
;
669 if (res
->target
== PIPE_BUFFER
&&
670 (res
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
))
671 nv50
->textures_coherent
[s
] |= 1 << i
;
673 nv50
->textures_coherent
[s
] &= ~(1 << i
);
675 nv50
->textures_coherent
[s
] &= ~(1 << i
);
678 pipe_sampler_view_reference(&nv50
->textures
[s
][i
], views
[i
]);
681 assert(nv50
->num_textures
[s
] <= PIPE_MAX_SAMPLERS
);
682 for (i
= nr
; i
< nv50
->num_textures
[s
]; ++i
) {
683 struct nv50_tic_entry
*old
= nv50_tic_entry(nv50
->textures
[s
][i
]);
686 nv50_screen_tic_unlock(nv50
->screen
, old
);
688 pipe_sampler_view_reference(&nv50
->textures
[s
][i
], NULL
);
691 nv50
->num_textures
[s
] = nr
;
693 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_TEXTURES
);
695 nv50
->dirty
|= NV50_NEW_TEXTURES
;
699 nv50_set_sampler_views(struct pipe_context
*pipe
, unsigned shader
,
700 unsigned start
, unsigned nr
,
701 struct pipe_sampler_view
**views
)
705 case PIPE_SHADER_VERTEX
:
706 nv50_stage_set_sampler_views(nv50_context(pipe
), 0, nr
, views
);
708 case PIPE_SHADER_GEOMETRY
:
709 nv50_stage_set_sampler_views(nv50_context(pipe
), 1, nr
, views
);
711 case PIPE_SHADER_FRAGMENT
:
712 nv50_stage_set_sampler_views(nv50_context(pipe
), 2, nr
, views
);
721 /* ============================= SHADERS =======================================
725 nv50_sp_state_create(struct pipe_context
*pipe
,
726 const struct pipe_shader_state
*cso
, unsigned type
)
728 struct nv50_program
*prog
;
730 prog
= CALLOC_STRUCT(nv50_program
);
735 prog
->pipe
.tokens
= tgsi_dup_tokens(cso
->tokens
);
737 if (cso
->stream_output
.num_outputs
)
738 prog
->pipe
.stream_output
= cso
->stream_output
;
740 prog
->translated
= nv50_program_translate(
741 prog
, nv50_context(pipe
)->screen
->base
.device
->chipset
,
742 &nouveau_context(pipe
)->debug
);
748 nv50_sp_state_delete(struct pipe_context
*pipe
, void *hwcso
)
750 struct nv50_program
*prog
= (struct nv50_program
*)hwcso
;
752 nv50_program_destroy(nv50_context(pipe
), prog
);
754 FREE((void *)prog
->pipe
.tokens
);
759 nv50_vp_state_create(struct pipe_context
*pipe
,
760 const struct pipe_shader_state
*cso
)
762 return nv50_sp_state_create(pipe
, cso
, PIPE_SHADER_VERTEX
);
766 nv50_vp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
768 struct nv50_context
*nv50
= nv50_context(pipe
);
770 nv50
->vertprog
= hwcso
;
771 nv50
->dirty
|= NV50_NEW_VERTPROG
;
775 nv50_fp_state_create(struct pipe_context
*pipe
,
776 const struct pipe_shader_state
*cso
)
778 return nv50_sp_state_create(pipe
, cso
, PIPE_SHADER_FRAGMENT
);
782 nv50_fp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
784 struct nv50_context
*nv50
= nv50_context(pipe
);
786 nv50
->fragprog
= hwcso
;
787 nv50
->dirty
|= NV50_NEW_FRAGPROG
;
791 nv50_gp_state_create(struct pipe_context
*pipe
,
792 const struct pipe_shader_state
*cso
)
794 return nv50_sp_state_create(pipe
, cso
, PIPE_SHADER_GEOMETRY
);
798 nv50_gp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
800 struct nv50_context
*nv50
= nv50_context(pipe
);
802 nv50
->gmtyprog
= hwcso
;
803 nv50
->dirty
|= NV50_NEW_GMTYPROG
;
807 nv50_cp_state_create(struct pipe_context
*pipe
,
808 const struct pipe_compute_state
*cso
)
810 struct nv50_program
*prog
;
812 prog
= CALLOC_STRUCT(nv50_program
);
815 prog
->type
= PIPE_SHADER_COMPUTE
;
817 prog
->cp
.smem_size
= cso
->req_local_mem
;
818 prog
->cp
.lmem_size
= cso
->req_private_mem
;
819 prog
->parm_size
= cso
->req_input_mem
;
821 prog
->pipe
.tokens
= tgsi_dup_tokens((const struct tgsi_token
*)cso
->prog
);
827 nv50_cp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
829 struct nv50_context
*nv50
= nv50_context(pipe
);
831 nv50
->compprog
= hwcso
;
832 nv50
->dirty_cp
|= NV50_NEW_CP_PROGRAM
;
836 nv50_set_constant_buffer(struct pipe_context
*pipe
, uint shader
, uint index
,
837 struct pipe_constant_buffer
*cb
)
839 struct nv50_context
*nv50
= nv50_context(pipe
);
840 struct pipe_resource
*res
= cb
? cb
->buffer
: NULL
;
841 const unsigned s
= nv50_context_shader_stage(shader
);
842 const unsigned i
= index
;
844 if (shader
== PIPE_SHADER_COMPUTE
)
847 assert(i
< NV50_MAX_PIPE_CONSTBUFS
);
848 if (nv50
->constbuf
[s
][i
].user
)
849 nv50
->constbuf
[s
][i
].u
.buf
= NULL
;
851 if (nv50
->constbuf
[s
][i
].u
.buf
)
852 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_CB(s
, i
));
854 pipe_resource_reference(&nv50
->constbuf
[s
][i
].u
.buf
, res
);
856 nv50
->constbuf
[s
][i
].user
= (cb
&& cb
->user_buffer
) ? true : false;
857 if (nv50
->constbuf
[s
][i
].user
) {
858 nv50
->constbuf
[s
][i
].u
.data
= cb
->user_buffer
;
859 nv50
->constbuf
[s
][i
].size
= MIN2(cb
->buffer_size
, 0x10000);
860 nv50
->constbuf_valid
[s
] |= 1 << i
;
861 nv50
->constbuf_coherent
[s
] &= ~(1 << i
);
864 nv50
->constbuf
[s
][i
].offset
= cb
->buffer_offset
;
865 nv50
->constbuf
[s
][i
].size
= MIN2(align(cb
->buffer_size
, 0x100), 0x10000);
866 nv50
->constbuf_valid
[s
] |= 1 << i
;
867 if (res
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
)
868 nv50
->constbuf_coherent
[s
] |= 1 << i
;
870 nv50
->constbuf_coherent
[s
] &= ~(1 << i
);
872 nv50
->constbuf_valid
[s
] &= ~(1 << i
);
873 nv50
->constbuf_coherent
[s
] &= ~(1 << i
);
875 nv50
->constbuf_dirty
[s
] |= 1 << i
;
877 nv50
->dirty
|= NV50_NEW_CONSTBUF
;
880 /* =============================================================================
884 nv50_set_blend_color(struct pipe_context
*pipe
,
885 const struct pipe_blend_color
*bcol
)
887 struct nv50_context
*nv50
= nv50_context(pipe
);
889 nv50
->blend_colour
= *bcol
;
890 nv50
->dirty
|= NV50_NEW_BLEND_COLOUR
;
894 nv50_set_stencil_ref(struct pipe_context
*pipe
,
895 const struct pipe_stencil_ref
*sr
)
897 struct nv50_context
*nv50
= nv50_context(pipe
);
899 nv50
->stencil_ref
= *sr
;
900 nv50
->dirty
|= NV50_NEW_STENCIL_REF
;
904 nv50_set_clip_state(struct pipe_context
*pipe
,
905 const struct pipe_clip_state
*clip
)
907 struct nv50_context
*nv50
= nv50_context(pipe
);
909 memcpy(nv50
->clip
.ucp
, clip
->ucp
, sizeof(clip
->ucp
));
911 nv50
->dirty
|= NV50_NEW_CLIP
;
915 nv50_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
917 struct nv50_context
*nv50
= nv50_context(pipe
);
919 nv50
->sample_mask
= sample_mask
;
920 nv50
->dirty
|= NV50_NEW_SAMPLE_MASK
;
924 nv50_set_min_samples(struct pipe_context
*pipe
, unsigned min_samples
)
926 struct nv50_context
*nv50
= nv50_context(pipe
);
928 if (nv50
->min_samples
!= min_samples
) {
929 nv50
->min_samples
= min_samples
;
930 nv50
->dirty
|= NV50_NEW_MIN_SAMPLES
;
935 nv50_set_framebuffer_state(struct pipe_context
*pipe
,
936 const struct pipe_framebuffer_state
*fb
)
938 struct nv50_context
*nv50
= nv50_context(pipe
);
941 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_FB
);
943 for (i
= 0; i
< fb
->nr_cbufs
; ++i
)
944 pipe_surface_reference(&nv50
->framebuffer
.cbufs
[i
], fb
->cbufs
[i
]);
945 for (; i
< nv50
->framebuffer
.nr_cbufs
; ++i
)
946 pipe_surface_reference(&nv50
->framebuffer
.cbufs
[i
], NULL
);
948 nv50
->framebuffer
.nr_cbufs
= fb
->nr_cbufs
;
950 nv50
->framebuffer
.width
= fb
->width
;
951 nv50
->framebuffer
.height
= fb
->height
;
953 pipe_surface_reference(&nv50
->framebuffer
.zsbuf
, fb
->zsbuf
);
955 nv50
->dirty
|= NV50_NEW_FRAMEBUFFER
;
959 nv50_set_polygon_stipple(struct pipe_context
*pipe
,
960 const struct pipe_poly_stipple
*stipple
)
962 struct nv50_context
*nv50
= nv50_context(pipe
);
964 nv50
->stipple
= *stipple
;
965 nv50
->dirty
|= NV50_NEW_STIPPLE
;
969 nv50_set_scissor_states(struct pipe_context
*pipe
,
971 unsigned num_scissors
,
972 const struct pipe_scissor_state
*scissor
)
974 struct nv50_context
*nv50
= nv50_context(pipe
);
977 assert(start_slot
+ num_scissors
<= NV50_MAX_VIEWPORTS
);
978 for (i
= 0; i
< num_scissors
; i
++) {
979 if (!memcmp(&nv50
->scissors
[start_slot
+ i
], &scissor
[i
], sizeof(*scissor
)))
981 nv50
->scissors
[start_slot
+ i
] = scissor
[i
];
982 nv50
->scissors_dirty
|= 1 << (start_slot
+ i
);
983 nv50
->dirty
|= NV50_NEW_SCISSOR
;
988 nv50_set_viewport_states(struct pipe_context
*pipe
,
990 unsigned num_viewports
,
991 const struct pipe_viewport_state
*vpt
)
993 struct nv50_context
*nv50
= nv50_context(pipe
);
996 assert(start_slot
+ num_viewports
<= NV50_MAX_VIEWPORTS
);
997 for (i
= 0; i
< num_viewports
; i
++) {
998 if (!memcmp(&nv50
->viewports
[start_slot
+ i
], &vpt
[i
], sizeof(*vpt
)))
1000 nv50
->viewports
[start_slot
+ i
] = vpt
[i
];
1001 nv50
->viewports_dirty
|= 1 << (start_slot
+ i
);
1002 nv50
->dirty
|= NV50_NEW_VIEWPORT
;
1007 nv50_set_vertex_buffers(struct pipe_context
*pipe
,
1008 unsigned start_slot
, unsigned count
,
1009 const struct pipe_vertex_buffer
*vb
)
1011 struct nv50_context
*nv50
= nv50_context(pipe
);
1014 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_VERTEX
);
1015 nv50
->dirty
|= NV50_NEW_ARRAYS
;
1017 util_set_vertex_buffers_count(nv50
->vtxbuf
, &nv50
->num_vtxbufs
, vb
,
1021 nv50
->vbo_user
&= ~(((1ull << count
) - 1) << start_slot
);
1022 nv50
->vbo_constant
&= ~(((1ull << count
) - 1) << start_slot
);
1023 nv50
->vtxbufs_coherent
&= ~(((1ull << count
) - 1) << start_slot
);
1027 for (i
= 0; i
< count
; ++i
) {
1028 unsigned dst_index
= start_slot
+ i
;
1030 if (!vb
[i
].buffer
&& vb
[i
].user_buffer
) {
1031 nv50
->vbo_user
|= 1 << dst_index
;
1033 nv50
->vbo_constant
|= 1 << dst_index
;
1035 nv50
->vbo_constant
&= ~(1 << dst_index
);
1036 nv50
->vtxbufs_coherent
&= ~(1 << dst_index
);
1038 nv50
->vbo_user
&= ~(1 << dst_index
);
1039 nv50
->vbo_constant
&= ~(1 << dst_index
);
1042 vb
[i
].buffer
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
)
1043 nv50
->vtxbufs_coherent
|= (1 << dst_index
);
1045 nv50
->vtxbufs_coherent
&= ~(1 << dst_index
);
1051 nv50_set_index_buffer(struct pipe_context
*pipe
,
1052 const struct pipe_index_buffer
*ib
)
1054 struct nv50_context
*nv50
= nv50_context(pipe
);
1056 if (nv50
->idxbuf
.buffer
)
1057 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_INDEX
);
1060 pipe_resource_reference(&nv50
->idxbuf
.buffer
, ib
->buffer
);
1061 nv50
->idxbuf
.index_size
= ib
->index_size
;
1063 nv50
->idxbuf
.offset
= ib
->offset
;
1064 BCTX_REFN(nv50
->bufctx_3d
, INDEX
, nv04_resource(ib
->buffer
), RD
);
1066 nv50
->idxbuf
.user_buffer
= ib
->user_buffer
;
1069 pipe_resource_reference(&nv50
->idxbuf
.buffer
, NULL
);
1074 nv50_vertex_state_bind(struct pipe_context
*pipe
, void *hwcso
)
1076 struct nv50_context
*nv50
= nv50_context(pipe
);
1078 nv50
->vertex
= hwcso
;
1079 nv50
->dirty
|= NV50_NEW_VERTEX
;
1082 static struct pipe_stream_output_target
*
1083 nv50_so_target_create(struct pipe_context
*pipe
,
1084 struct pipe_resource
*res
,
1085 unsigned offset
, unsigned size
)
1087 struct nv04_resource
*buf
= (struct nv04_resource
*)res
;
1088 struct nv50_so_target
*targ
= MALLOC_STRUCT(nv50_so_target
);
1092 if (nouveau_context(pipe
)->screen
->class_3d
>= NVA0_3D_CLASS
) {
1093 targ
->pq
= pipe
->create_query(pipe
,
1094 NVA0_HW_QUERY_STREAM_OUTPUT_BUFFER_OFFSET
, 0);
1104 targ
->pipe
.buffer_size
= size
;
1105 targ
->pipe
.buffer_offset
= offset
;
1106 targ
->pipe
.context
= pipe
;
1107 targ
->pipe
.buffer
= NULL
;
1108 pipe_resource_reference(&targ
->pipe
.buffer
, res
);
1109 pipe_reference_init(&targ
->pipe
.reference
, 1);
1111 assert(buf
->base
.target
== PIPE_BUFFER
);
1112 util_range_add(&buf
->valid_buffer_range
, offset
, offset
+ size
);
1118 nva0_so_target_save_offset(struct pipe_context
*pipe
,
1119 struct pipe_stream_output_target
*ptarg
,
1120 unsigned index
, bool serialize
)
1122 struct nv50_so_target
*targ
= nv50_so_target(ptarg
);
1125 struct nouveau_pushbuf
*push
= nv50_context(pipe
)->base
.pushbuf
;
1126 PUSH_SPACE(push
, 2);
1127 BEGIN_NV04(push
, SUBC_3D(NV50_GRAPH_SERIALIZE
), 1);
1128 PUSH_DATA (push
, 0);
1131 nv50_query(targ
->pq
)->index
= index
;
1132 pipe
->end_query(pipe
, targ
->pq
);
1136 nv50_so_target_destroy(struct pipe_context
*pipe
,
1137 struct pipe_stream_output_target
*ptarg
)
1139 struct nv50_so_target
*targ
= nv50_so_target(ptarg
);
1141 pipe
->destroy_query(pipe
, targ
->pq
);
1142 pipe_resource_reference(&targ
->pipe
.buffer
, NULL
);
1147 nv50_set_stream_output_targets(struct pipe_context
*pipe
,
1148 unsigned num_targets
,
1149 struct pipe_stream_output_target
**targets
,
1150 const unsigned *offsets
)
1152 struct nv50_context
*nv50
= nv50_context(pipe
);
1154 bool serialize
= true;
1155 const bool can_resume
= nv50
->screen
->base
.class_3d
>= NVA0_3D_CLASS
;
1157 assert(num_targets
<= 4);
1159 for (i
= 0; i
< num_targets
; ++i
) {
1160 const bool changed
= nv50
->so_target
[i
] != targets
[i
];
1161 const bool append
= (offsets
[i
] == (unsigned)-1);
1162 if (!changed
&& append
)
1164 nv50
->so_targets_dirty
|= 1 << i
;
1166 if (can_resume
&& changed
&& nv50
->so_target
[i
]) {
1167 nva0_so_target_save_offset(pipe
, nv50
->so_target
[i
], i
, serialize
);
1171 if (targets
[i
] && !append
)
1172 nv50_so_target(targets
[i
])->clean
= true;
1174 pipe_so_target_reference(&nv50
->so_target
[i
], targets
[i
]);
1176 for (; i
< nv50
->num_so_targets
; ++i
) {
1177 if (can_resume
&& nv50
->so_target
[i
]) {
1178 nva0_so_target_save_offset(pipe
, nv50
->so_target
[i
], i
, serialize
);
1181 pipe_so_target_reference(&nv50
->so_target
[i
], NULL
);
1182 nv50
->so_targets_dirty
|= 1 << i
;
1184 nv50
->num_so_targets
= num_targets
;
1186 if (nv50
->so_targets_dirty
)
1187 nv50
->dirty
|= NV50_NEW_STRMOUT
;
1191 nv50_set_compute_resources(struct pipe_context
*pipe
,
1192 unsigned start
, unsigned nr
,
1193 struct pipe_surface
**resources
)
1195 /* TODO: bind surfaces */
1199 nv50_set_global_handle(uint32_t *phandle
, struct pipe_resource
*res
)
1201 struct nv04_resource
*buf
= nv04_resource(res
);
1203 uint64_t limit
= (buf
->address
+ buf
->base
.width0
) - 1;
1204 if (limit
< (1ULL << 32)) {
1205 *phandle
= (uint32_t)buf
->address
;
1207 NOUVEAU_ERR("Cannot map into TGSI_RESOURCE_GLOBAL: "
1208 "resource not contained within 32-bit address space !\n");
1217 nv50_set_global_bindings(struct pipe_context
*pipe
,
1218 unsigned start
, unsigned nr
,
1219 struct pipe_resource
**resources
,
1222 struct nv50_context
*nv50
= nv50_context(pipe
);
1223 struct pipe_resource
**ptr
;
1225 const unsigned end
= start
+ nr
;
1227 if (nv50
->global_residents
.size
<= (end
* sizeof(struct pipe_resource
*))) {
1228 const unsigned old_size
= nv50
->global_residents
.size
;
1229 const unsigned req_size
= end
* sizeof(struct pipe_resource
*);
1230 util_dynarray_resize(&nv50
->global_residents
, req_size
);
1231 memset((uint8_t *)nv50
->global_residents
.data
+ old_size
, 0,
1232 req_size
- old_size
);
1236 ptr
= util_dynarray_element(
1237 &nv50
->global_residents
, struct pipe_resource
*, start
);
1238 for (i
= 0; i
< nr
; ++i
) {
1239 pipe_resource_reference(&ptr
[i
], resources
[i
]);
1240 nv50_set_global_handle(handles
[i
], resources
[i
]);
1243 ptr
= util_dynarray_element(
1244 &nv50
->global_residents
, struct pipe_resource
*, start
);
1245 for (i
= 0; i
< nr
; ++i
)
1246 pipe_resource_reference(&ptr
[i
], NULL
);
1249 nouveau_bufctx_reset(nv50
->bufctx_cp
, NV50_BIND_CP_GLOBAL
);
1251 nv50
->dirty_cp
= NV50_NEW_CP_GLOBALS
;
1255 nv50_init_state_functions(struct nv50_context
*nv50
)
1257 struct pipe_context
*pipe
= &nv50
->base
.pipe
;
1259 pipe
->create_blend_state
= nv50_blend_state_create
;
1260 pipe
->bind_blend_state
= nv50_blend_state_bind
;
1261 pipe
->delete_blend_state
= nv50_blend_state_delete
;
1263 pipe
->create_rasterizer_state
= nv50_rasterizer_state_create
;
1264 pipe
->bind_rasterizer_state
= nv50_rasterizer_state_bind
;
1265 pipe
->delete_rasterizer_state
= nv50_rasterizer_state_delete
;
1267 pipe
->create_depth_stencil_alpha_state
= nv50_zsa_state_create
;
1268 pipe
->bind_depth_stencil_alpha_state
= nv50_zsa_state_bind
;
1269 pipe
->delete_depth_stencil_alpha_state
= nv50_zsa_state_delete
;
1271 pipe
->create_sampler_state
= nv50_sampler_state_create
;
1272 pipe
->delete_sampler_state
= nv50_sampler_state_delete
;
1273 pipe
->bind_sampler_states
= nv50_bind_sampler_states
;
1275 pipe
->create_sampler_view
= nv50_create_sampler_view
;
1276 pipe
->sampler_view_destroy
= nv50_sampler_view_destroy
;
1277 pipe
->set_sampler_views
= nv50_set_sampler_views
;
1279 pipe
->create_vs_state
= nv50_vp_state_create
;
1280 pipe
->create_fs_state
= nv50_fp_state_create
;
1281 pipe
->create_gs_state
= nv50_gp_state_create
;
1282 pipe
->create_compute_state
= nv50_cp_state_create
;
1283 pipe
->bind_vs_state
= nv50_vp_state_bind
;
1284 pipe
->bind_fs_state
= nv50_fp_state_bind
;
1285 pipe
->bind_gs_state
= nv50_gp_state_bind
;
1286 pipe
->bind_compute_state
= nv50_cp_state_bind
;
1287 pipe
->delete_vs_state
= nv50_sp_state_delete
;
1288 pipe
->delete_fs_state
= nv50_sp_state_delete
;
1289 pipe
->delete_gs_state
= nv50_sp_state_delete
;
1290 pipe
->delete_compute_state
= nv50_sp_state_delete
;
1292 pipe
->set_blend_color
= nv50_set_blend_color
;
1293 pipe
->set_stencil_ref
= nv50_set_stencil_ref
;
1294 pipe
->set_clip_state
= nv50_set_clip_state
;
1295 pipe
->set_sample_mask
= nv50_set_sample_mask
;
1296 pipe
->set_min_samples
= nv50_set_min_samples
;
1297 pipe
->set_constant_buffer
= nv50_set_constant_buffer
;
1298 pipe
->set_framebuffer_state
= nv50_set_framebuffer_state
;
1299 pipe
->set_polygon_stipple
= nv50_set_polygon_stipple
;
1300 pipe
->set_scissor_states
= nv50_set_scissor_states
;
1301 pipe
->set_viewport_states
= nv50_set_viewport_states
;
1303 pipe
->create_vertex_elements_state
= nv50_vertex_state_create
;
1304 pipe
->delete_vertex_elements_state
= nv50_vertex_state_delete
;
1305 pipe
->bind_vertex_elements_state
= nv50_vertex_state_bind
;
1307 pipe
->set_vertex_buffers
= nv50_set_vertex_buffers
;
1308 pipe
->set_index_buffer
= nv50_set_index_buffer
;
1310 pipe
->create_stream_output_target
= nv50_so_target_create
;
1311 pipe
->stream_output_target_destroy
= nv50_so_target_destroy
;
1312 pipe
->set_stream_output_targets
= nv50_set_stream_output_targets
;
1314 pipe
->set_global_binding
= nv50_set_global_bindings
;
1315 pipe
->set_compute_resources
= nv50_set_compute_resources
;
1317 nv50
->sample_mask
= ~0;
1318 nv50
->min_samples
= 1;