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_framebuffer.h"
25 #include "util/u_helpers.h"
26 #include "util/u_inlines.h"
27 #include "util/u_transfer.h"
29 #include "tgsi/tgsi_parse.h"
31 #include "nvc0/nvc0_stateobj.h"
32 #include "nvc0/nvc0_context.h"
33 #include "nvc0/nvc0_query_hw.h"
35 #include "nvc0/nvc0_3d.xml.h"
37 #include "nouveau_gldefs.h"
39 static inline uint32_t
40 nvc0_colormask(unsigned mask
)
44 if (mask
& PIPE_MASK_R
)
46 if (mask
& PIPE_MASK_G
)
48 if (mask
& PIPE_MASK_B
)
50 if (mask
& PIPE_MASK_A
)
56 #define NVC0_BLEND_FACTOR_CASE(a, b) \
57 case PIPE_BLENDFACTOR_##a: return NV50_BLEND_FACTOR_##b
59 static inline uint32_t
60 nvc0_blend_fac(unsigned factor
)
63 NVC0_BLEND_FACTOR_CASE(ONE
, ONE
);
64 NVC0_BLEND_FACTOR_CASE(SRC_COLOR
, SRC_COLOR
);
65 NVC0_BLEND_FACTOR_CASE(SRC_ALPHA
, SRC_ALPHA
);
66 NVC0_BLEND_FACTOR_CASE(DST_ALPHA
, DST_ALPHA
);
67 NVC0_BLEND_FACTOR_CASE(DST_COLOR
, DST_COLOR
);
68 NVC0_BLEND_FACTOR_CASE(SRC_ALPHA_SATURATE
, SRC_ALPHA_SATURATE
);
69 NVC0_BLEND_FACTOR_CASE(CONST_COLOR
, CONSTANT_COLOR
);
70 NVC0_BLEND_FACTOR_CASE(CONST_ALPHA
, CONSTANT_ALPHA
);
71 NVC0_BLEND_FACTOR_CASE(SRC1_COLOR
, SRC1_COLOR
);
72 NVC0_BLEND_FACTOR_CASE(SRC1_ALPHA
, SRC1_ALPHA
);
73 NVC0_BLEND_FACTOR_CASE(ZERO
, ZERO
);
74 NVC0_BLEND_FACTOR_CASE(INV_SRC_COLOR
, ONE_MINUS_SRC_COLOR
);
75 NVC0_BLEND_FACTOR_CASE(INV_SRC_ALPHA
, ONE_MINUS_SRC_ALPHA
);
76 NVC0_BLEND_FACTOR_CASE(INV_DST_ALPHA
, ONE_MINUS_DST_ALPHA
);
77 NVC0_BLEND_FACTOR_CASE(INV_DST_COLOR
, ONE_MINUS_DST_COLOR
);
78 NVC0_BLEND_FACTOR_CASE(INV_CONST_COLOR
, ONE_MINUS_CONSTANT_COLOR
);
79 NVC0_BLEND_FACTOR_CASE(INV_CONST_ALPHA
, ONE_MINUS_CONSTANT_ALPHA
);
80 NVC0_BLEND_FACTOR_CASE(INV_SRC1_COLOR
, ONE_MINUS_SRC1_COLOR
);
81 NVC0_BLEND_FACTOR_CASE(INV_SRC1_ALPHA
, ONE_MINUS_SRC1_ALPHA
);
83 return NV50_BLEND_FACTOR_ZERO
;
88 nvc0_blend_state_create(struct pipe_context
*pipe
,
89 const struct pipe_blend_state
*cso
)
91 struct nvc0_blend_stateobj
*so
= CALLOC_STRUCT(nvc0_blend_stateobj
);
93 int r
; /* reference */
95 bool indep_masks
= false;
96 bool indep_funcs
= false;
100 /* check which states actually have differing values */
101 if (cso
->independent_blend_enable
) {
102 for (r
= 0; r
< 8 && !cso
->rt
[r
].blend_enable
; ++r
);
104 for (i
= r
+ 1; i
< 8; ++i
) {
105 if (!cso
->rt
[i
].blend_enable
)
108 if (cso
->rt
[i
].rgb_func
!= cso
->rt
[r
].rgb_func
||
109 cso
->rt
[i
].rgb_src_factor
!= cso
->rt
[r
].rgb_src_factor
||
110 cso
->rt
[i
].rgb_dst_factor
!= cso
->rt
[r
].rgb_dst_factor
||
111 cso
->rt
[i
].alpha_func
!= cso
->rt
[r
].alpha_func
||
112 cso
->rt
[i
].alpha_src_factor
!= cso
->rt
[r
].alpha_src_factor
||
113 cso
->rt
[i
].alpha_dst_factor
!= cso
->rt
[r
].alpha_dst_factor
) {
119 blend_en
|= (cso
->rt
[i
].blend_enable
? 1 : 0) << i
;
121 for (i
= 1; i
< 8; ++i
) {
122 if (cso
->rt
[i
].colormask
!= cso
->rt
[0].colormask
) {
129 if (cso
->rt
[0].blend_enable
)
133 if (cso
->logicop_enable
) {
134 SB_BEGIN_3D(so
, LOGIC_OP_ENABLE
, 2);
136 SB_DATA (so
, nvgl_logicop_func(cso
->logicop_func
));
138 SB_IMMED_3D(so
, MACRO_BLEND_ENABLES
, 0);
140 SB_IMMED_3D(so
, LOGIC_OP_ENABLE
, 0);
142 SB_IMMED_3D(so
, BLEND_INDEPENDENT
, indep_funcs
);
143 SB_IMMED_3D(so
, MACRO_BLEND_ENABLES
, blend_en
);
145 for (i
= 0; i
< 8; ++i
) {
146 if (cso
->rt
[i
].blend_enable
) {
147 SB_BEGIN_3D(so
, IBLEND_EQUATION_RGB(i
), 6);
148 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[i
].rgb_func
));
149 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[i
].rgb_src_factor
));
150 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[i
].rgb_dst_factor
));
151 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[i
].alpha_func
));
152 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[i
].alpha_src_factor
));
153 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[i
].alpha_dst_factor
));
158 SB_BEGIN_3D(so
, BLEND_EQUATION_RGB
, 5);
159 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[r
].rgb_func
));
160 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[r
].rgb_src_factor
));
161 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[r
].rgb_dst_factor
));
162 SB_DATA (so
, nvgl_blend_eqn(cso
->rt
[r
].alpha_func
));
163 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[r
].alpha_src_factor
));
164 SB_BEGIN_3D(so
, BLEND_FUNC_DST_ALPHA
, 1);
165 SB_DATA (so
, nvc0_blend_fac(cso
->rt
[r
].alpha_dst_factor
));
168 SB_IMMED_3D(so
, COLOR_MASK_COMMON
, !indep_masks
);
170 SB_BEGIN_3D(so
, COLOR_MASK(0), 8);
171 for (i
= 0; i
< 8; ++i
)
172 SB_DATA(so
, nvc0_colormask(cso
->rt
[i
].colormask
));
174 SB_BEGIN_3D(so
, COLOR_MASK(0), 1);
175 SB_DATA (so
, nvc0_colormask(cso
->rt
[0].colormask
));
179 assert(so
->size
<= ARRAY_SIZE(so
->state
));
184 nvc0_blend_state_bind(struct pipe_context
*pipe
, void *hwcso
)
186 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
189 nvc0
->dirty_3d
|= NVC0_NEW_3D_BLEND
;
193 nvc0_blend_state_delete(struct pipe_context
*pipe
, void *hwcso
)
198 /* NOTE: ignoring line_last_pixel */
200 nvc0_rasterizer_state_create(struct pipe_context
*pipe
,
201 const struct pipe_rasterizer_state
*cso
)
203 struct nvc0_rasterizer_stateobj
*so
;
206 so
= CALLOC_STRUCT(nvc0_rasterizer_stateobj
);
211 /* Scissor enables are handled in scissor state, we will not want to
212 * always emit 16 commands, one for each scissor rectangle, here.
215 SB_IMMED_3D(so
, PROVOKING_VERTEX_LAST
, !cso
->flatshade_first
);
216 SB_IMMED_3D(so
, VERTEX_TWO_SIDE_ENABLE
, cso
->light_twoside
);
218 SB_IMMED_3D(so
, VERT_COLOR_CLAMP_EN
, cso
->clamp_vertex_color
);
219 SB_BEGIN_3D(so
, FRAG_COLOR_CLAMP_EN
, 1);
220 SB_DATA (so
, cso
->clamp_fragment_color
? 0x11111111 : 0x00000000);
222 SB_IMMED_3D(so
, MULTISAMPLE_ENABLE
, cso
->multisample
);
224 SB_IMMED_3D(so
, LINE_SMOOTH_ENABLE
, cso
->line_smooth
);
225 if (cso
->line_smooth
|| cso
->multisample
)
226 SB_BEGIN_3D(so
, LINE_WIDTH_SMOOTH
, 1);
228 SB_BEGIN_3D(so
, LINE_WIDTH_ALIASED
, 1);
229 SB_DATA (so
, fui(cso
->line_width
));
231 SB_IMMED_3D(so
, LINE_STIPPLE_ENABLE
, cso
->line_stipple_enable
);
232 if (cso
->line_stipple_enable
) {
233 SB_BEGIN_3D(so
, LINE_STIPPLE_PATTERN
, 1);
234 SB_DATA (so
, (cso
->line_stipple_pattern
<< 8) |
235 cso
->line_stipple_factor
);
239 SB_IMMED_3D(so
, VP_POINT_SIZE
, cso
->point_size_per_vertex
);
240 if (!cso
->point_size_per_vertex
) {
241 SB_BEGIN_3D(so
, POINT_SIZE
, 1);
242 SB_DATA (so
, fui(cso
->point_size
));
245 reg
= (cso
->sprite_coord_mode
== PIPE_SPRITE_COORD_UPPER_LEFT
) ?
246 NVC0_3D_POINT_COORD_REPLACE_COORD_ORIGIN_UPPER_LEFT
:
247 NVC0_3D_POINT_COORD_REPLACE_COORD_ORIGIN_LOWER_LEFT
;
249 SB_BEGIN_3D(so
, POINT_COORD_REPLACE
, 1);
250 SB_DATA (so
, ((cso
->sprite_coord_enable
& 0xff) << 3) | reg
);
251 SB_IMMED_3D(so
, POINT_SPRITE_ENABLE
, cso
->point_quad_rasterization
);
252 SB_IMMED_3D(so
, POINT_SMOOTH_ENABLE
, cso
->point_smooth
);
254 SB_BEGIN_3D(so
, MACRO_POLYGON_MODE_FRONT
, 1);
255 SB_DATA (so
, nvgl_polygon_mode(cso
->fill_front
));
256 SB_BEGIN_3D(so
, MACRO_POLYGON_MODE_BACK
, 1);
257 SB_DATA (so
, nvgl_polygon_mode(cso
->fill_back
));
258 SB_IMMED_3D(so
, POLYGON_SMOOTH_ENABLE
, cso
->poly_smooth
);
260 SB_BEGIN_3D(so
, CULL_FACE_ENABLE
, 3);
261 SB_DATA (so
, cso
->cull_face
!= PIPE_FACE_NONE
);
262 SB_DATA (so
, cso
->front_ccw
? NVC0_3D_FRONT_FACE_CCW
:
263 NVC0_3D_FRONT_FACE_CW
);
264 switch (cso
->cull_face
) {
265 case PIPE_FACE_FRONT_AND_BACK
:
266 SB_DATA(so
, NVC0_3D_CULL_FACE_FRONT_AND_BACK
);
268 case PIPE_FACE_FRONT
:
269 SB_DATA(so
, NVC0_3D_CULL_FACE_FRONT
);
273 SB_DATA(so
, NVC0_3D_CULL_FACE_BACK
);
277 SB_IMMED_3D(so
, POLYGON_STIPPLE_ENABLE
, cso
->poly_stipple_enable
);
278 SB_BEGIN_3D(so
, POLYGON_OFFSET_POINT_ENABLE
, 3);
279 SB_DATA (so
, cso
->offset_point
);
280 SB_DATA (so
, cso
->offset_line
);
281 SB_DATA (so
, cso
->offset_tri
);
283 if (cso
->offset_point
|| cso
->offset_line
|| cso
->offset_tri
) {
284 SB_BEGIN_3D(so
, POLYGON_OFFSET_FACTOR
, 1);
285 SB_DATA (so
, fui(cso
->offset_scale
));
286 if (!cso
->offset_units_unscaled
) {
287 SB_BEGIN_3D(so
, POLYGON_OFFSET_UNITS
, 1);
288 SB_DATA (so
, fui(cso
->offset_units
* 2.0f
));
290 SB_BEGIN_3D(so
, POLYGON_OFFSET_CLAMP
, 1);
291 SB_DATA (so
, fui(cso
->offset_clamp
));
295 reg
= NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1
;
298 NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1
|
299 NVC0_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_NEAR
|
300 NVC0_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_FAR
|
301 NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK2
;
303 SB_BEGIN_3D(so
, VIEW_VOLUME_CLIP_CTRL
, 1);
306 SB_IMMED_3D(so
, DEPTH_CLIP_NEGATIVE_Z
, cso
->clip_halfz
);
308 SB_IMMED_3D(so
, PIXEL_CENTER_INTEGER
, !cso
->half_pixel_center
);
310 assert(so
->size
<= ARRAY_SIZE(so
->state
));
315 nvc0_rasterizer_state_bind(struct pipe_context
*pipe
, void *hwcso
)
317 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
320 nvc0
->dirty_3d
|= NVC0_NEW_3D_RASTERIZER
;
324 nvc0_rasterizer_state_delete(struct pipe_context
*pipe
, void *hwcso
)
330 nvc0_zsa_state_create(struct pipe_context
*pipe
,
331 const struct pipe_depth_stencil_alpha_state
*cso
)
333 struct nvc0_zsa_stateobj
*so
= CALLOC_STRUCT(nvc0_zsa_stateobj
);
337 SB_IMMED_3D(so
, DEPTH_TEST_ENABLE
, cso
->depth
.enabled
);
338 if (cso
->depth
.enabled
) {
339 SB_IMMED_3D(so
, DEPTH_WRITE_ENABLE
, cso
->depth
.writemask
);
340 SB_BEGIN_3D(so
, DEPTH_TEST_FUNC
, 1);
341 SB_DATA (so
, nvgl_comparison_op(cso
->depth
.func
));
344 SB_IMMED_3D(so
, DEPTH_BOUNDS_EN
, cso
->depth
.bounds_test
);
345 if (cso
->depth
.bounds_test
) {
346 SB_BEGIN_3D(so
, DEPTH_BOUNDS(0), 2);
347 SB_DATA (so
, fui(cso
->depth
.bounds_min
));
348 SB_DATA (so
, fui(cso
->depth
.bounds_max
));
351 if (cso
->stencil
[0].enabled
) {
352 SB_BEGIN_3D(so
, STENCIL_ENABLE
, 5);
354 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].fail_op
));
355 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].zfail_op
));
356 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[0].zpass_op
));
357 SB_DATA (so
, nvgl_comparison_op(cso
->stencil
[0].func
));
358 SB_BEGIN_3D(so
, STENCIL_FRONT_FUNC_MASK
, 2);
359 SB_DATA (so
, cso
->stencil
[0].valuemask
);
360 SB_DATA (so
, cso
->stencil
[0].writemask
);
362 SB_IMMED_3D(so
, STENCIL_ENABLE
, 0);
365 if (cso
->stencil
[1].enabled
) {
366 assert(cso
->stencil
[0].enabled
);
367 SB_BEGIN_3D(so
, STENCIL_TWO_SIDE_ENABLE
, 5);
369 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].fail_op
));
370 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].zfail_op
));
371 SB_DATA (so
, nvgl_stencil_op(cso
->stencil
[1].zpass_op
));
372 SB_DATA (so
, nvgl_comparison_op(cso
->stencil
[1].func
));
373 SB_BEGIN_3D(so
, STENCIL_BACK_MASK
, 2);
374 SB_DATA (so
, cso
->stencil
[1].writemask
);
375 SB_DATA (so
, cso
->stencil
[1].valuemask
);
377 if (cso
->stencil
[0].enabled
) {
378 SB_IMMED_3D(so
, STENCIL_TWO_SIDE_ENABLE
, 0);
381 SB_IMMED_3D(so
, ALPHA_TEST_ENABLE
, cso
->alpha
.enabled
);
382 if (cso
->alpha
.enabled
) {
383 SB_BEGIN_3D(so
, ALPHA_TEST_REF
, 2);
384 SB_DATA (so
, fui(cso
->alpha
.ref_value
));
385 SB_DATA (so
, nvgl_comparison_op(cso
->alpha
.func
));
388 assert(so
->size
<= ARRAY_SIZE(so
->state
));
393 nvc0_zsa_state_bind(struct pipe_context
*pipe
, void *hwcso
)
395 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
398 nvc0
->dirty_3d
|= NVC0_NEW_3D_ZSA
;
402 nvc0_zsa_state_delete(struct pipe_context
*pipe
, void *hwcso
)
407 /* ====================== SAMPLERS AND TEXTURES ================================
410 #define NV50_TSC_WRAP_CASE(n) \
411 case PIPE_TEX_WRAP_##n: return NV50_TSC_WRAP_##n
414 nvc0_sampler_state_delete(struct pipe_context
*pipe
, void *hwcso
)
418 for (s
= 0; s
< 6; ++s
)
419 for (i
= 0; i
< nvc0_context(pipe
)->num_samplers
[s
]; ++i
)
420 if (nvc0_context(pipe
)->samplers
[s
][i
] == hwcso
)
421 nvc0_context(pipe
)->samplers
[s
][i
] = NULL
;
423 nvc0_screen_tsc_free(nvc0_context(pipe
)->screen
, nv50_tsc_entry(hwcso
));
429 nvc0_stage_sampler_states_bind(struct nvc0_context
*nvc0
,
431 unsigned nr
, void **hwcso
)
435 for (i
= 0; i
< nr
; ++i
) {
436 struct nv50_tsc_entry
*old
= nvc0
->samplers
[s
][i
];
440 nvc0
->samplers_dirty
[s
] |= 1 << i
;
442 nvc0
->samplers
[s
][i
] = nv50_tsc_entry(hwcso
[i
]);
444 nvc0_screen_tsc_unlock(nvc0
->screen
, old
);
446 for (; i
< nvc0
->num_samplers
[s
]; ++i
) {
447 if (nvc0
->samplers
[s
][i
]) {
448 nvc0_screen_tsc_unlock(nvc0
->screen
, nvc0
->samplers
[s
][i
]);
449 nvc0
->samplers
[s
][i
] = NULL
;
453 nvc0
->num_samplers
[s
] = nr
;
457 nvc0_bind_sampler_states(struct pipe_context
*pipe
,
458 enum pipe_shader_type shader
,
459 unsigned start
, unsigned nr
, void **samplers
)
461 const unsigned s
= nvc0_shader_stage(shader
);
464 nvc0_stage_sampler_states_bind(nvc0_context(pipe
), s
, nr
, samplers
);
467 nvc0_context(pipe
)->dirty_cp
|= NVC0_NEW_CP_SAMPLERS
;
469 nvc0_context(pipe
)->dirty_3d
|= NVC0_NEW_3D_SAMPLERS
;
473 /* NOTE: only called when not referenced anywhere, won't be bound */
475 nvc0_sampler_view_destroy(struct pipe_context
*pipe
,
476 struct pipe_sampler_view
*view
)
478 pipe_resource_reference(&view
->texture
, NULL
);
480 nvc0_screen_tic_free(nvc0_context(pipe
)->screen
, nv50_tic_entry(view
));
482 FREE(nv50_tic_entry(view
));
486 nvc0_stage_set_sampler_views(struct nvc0_context
*nvc0
, int s
,
488 struct pipe_sampler_view
**views
)
492 for (i
= 0; i
< nr
; ++i
) {
493 struct nv50_tic_entry
*old
= nv50_tic_entry(nvc0
->textures
[s
][i
]);
495 if (views
[i
] == nvc0
->textures
[s
][i
])
497 nvc0
->textures_dirty
[s
] |= 1 << i
;
499 if (views
[i
] && views
[i
]->texture
) {
500 struct pipe_resource
*res
= views
[i
]->texture
;
501 if (res
->target
== PIPE_BUFFER
&&
502 (res
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
))
503 nvc0
->textures_coherent
[s
] |= 1 << i
;
505 nvc0
->textures_coherent
[s
] &= ~(1 << i
);
507 nvc0
->textures_coherent
[s
] &= ~(1 << i
);
512 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_TEX(i
));
514 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_TEX(s
, i
));
515 nvc0_screen_tic_unlock(nvc0
->screen
, old
);
518 pipe_sampler_view_reference(&nvc0
->textures
[s
][i
], views
[i
]);
521 for (i
= nr
; i
< nvc0
->num_textures
[s
]; ++i
) {
522 struct nv50_tic_entry
*old
= nv50_tic_entry(nvc0
->textures
[s
][i
]);
525 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_TEX(i
));
527 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_TEX(s
, i
));
528 nvc0_screen_tic_unlock(nvc0
->screen
, old
);
529 pipe_sampler_view_reference(&nvc0
->textures
[s
][i
], NULL
);
533 nvc0
->num_textures
[s
] = nr
;
537 nvc0_set_sampler_views(struct pipe_context
*pipe
, enum pipe_shader_type shader
,
538 unsigned start
, unsigned nr
,
539 struct pipe_sampler_view
**views
)
541 const unsigned s
= nvc0_shader_stage(shader
);
544 nvc0_stage_set_sampler_views(nvc0_context(pipe
), s
, nr
, views
);
547 nvc0_context(pipe
)->dirty_cp
|= NVC0_NEW_CP_TEXTURES
;
549 nvc0_context(pipe
)->dirty_3d
|= NVC0_NEW_3D_TEXTURES
;
552 /* ============================= SHADERS =======================================
556 nvc0_sp_state_create(struct pipe_context
*pipe
,
557 const struct pipe_shader_state
*cso
, unsigned type
)
559 struct nvc0_program
*prog
;
561 prog
= CALLOC_STRUCT(nvc0_program
);
568 prog
->pipe
.tokens
= tgsi_dup_tokens(cso
->tokens
);
570 if (cso
->stream_output
.num_outputs
)
571 prog
->pipe
.stream_output
= cso
->stream_output
;
573 prog
->translated
= nvc0_program_translate(
574 prog
, nvc0_context(pipe
)->screen
->base
.device
->chipset
,
575 &nouveau_context(pipe
)->debug
);
581 nvc0_sp_state_delete(struct pipe_context
*pipe
, void *hwcso
)
583 struct nvc0_program
*prog
= (struct nvc0_program
*)hwcso
;
585 nvc0_program_destroy(nvc0_context(pipe
), prog
);
587 FREE((void *)prog
->pipe
.tokens
);
592 nvc0_vp_state_create(struct pipe_context
*pipe
,
593 const struct pipe_shader_state
*cso
)
595 return nvc0_sp_state_create(pipe
, cso
, PIPE_SHADER_VERTEX
);
599 nvc0_vp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
601 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
603 nvc0
->vertprog
= hwcso
;
604 nvc0
->dirty_3d
|= NVC0_NEW_3D_VERTPROG
;
608 nvc0_fp_state_create(struct pipe_context
*pipe
,
609 const struct pipe_shader_state
*cso
)
611 return nvc0_sp_state_create(pipe
, cso
, PIPE_SHADER_FRAGMENT
);
615 nvc0_fp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
617 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
619 nvc0
->fragprog
= hwcso
;
620 nvc0
->dirty_3d
|= NVC0_NEW_3D_FRAGPROG
;
624 nvc0_gp_state_create(struct pipe_context
*pipe
,
625 const struct pipe_shader_state
*cso
)
627 return nvc0_sp_state_create(pipe
, cso
, PIPE_SHADER_GEOMETRY
);
631 nvc0_gp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
633 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
635 nvc0
->gmtyprog
= hwcso
;
636 nvc0
->dirty_3d
|= NVC0_NEW_3D_GMTYPROG
;
640 nvc0_tcp_state_create(struct pipe_context
*pipe
,
641 const struct pipe_shader_state
*cso
)
643 return nvc0_sp_state_create(pipe
, cso
, PIPE_SHADER_TESS_CTRL
);
647 nvc0_tcp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
649 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
651 nvc0
->tctlprog
= hwcso
;
652 nvc0
->dirty_3d
|= NVC0_NEW_3D_TCTLPROG
;
656 nvc0_tep_state_create(struct pipe_context
*pipe
,
657 const struct pipe_shader_state
*cso
)
659 return nvc0_sp_state_create(pipe
, cso
, PIPE_SHADER_TESS_EVAL
);
663 nvc0_tep_state_bind(struct pipe_context
*pipe
, void *hwcso
)
665 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
667 nvc0
->tevlprog
= hwcso
;
668 nvc0
->dirty_3d
|= NVC0_NEW_3D_TEVLPROG
;
672 nvc0_cp_state_create(struct pipe_context
*pipe
,
673 const struct pipe_compute_state
*cso
)
675 struct nvc0_program
*prog
;
677 prog
= CALLOC_STRUCT(nvc0_program
);
680 prog
->type
= PIPE_SHADER_COMPUTE
;
682 prog
->cp
.smem_size
= cso
->req_local_mem
;
683 prog
->cp
.lmem_size
= cso
->req_private_mem
;
684 prog
->parm_size
= cso
->req_input_mem
;
686 prog
->pipe
.tokens
= tgsi_dup_tokens((const struct tgsi_token
*)cso
->prog
);
692 nvc0_cp_state_bind(struct pipe_context
*pipe
, void *hwcso
)
694 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
696 nvc0
->compprog
= hwcso
;
697 nvc0
->dirty_cp
|= NVC0_NEW_CP_PROGRAM
;
701 nvc0_set_constant_buffer(struct pipe_context
*pipe
, uint shader
, uint index
,
702 const struct pipe_constant_buffer
*cb
)
704 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
705 struct pipe_resource
*res
= cb
? cb
->buffer
: NULL
;
706 const unsigned s
= nvc0_shader_stage(shader
);
707 const unsigned i
= index
;
709 if (unlikely(shader
== PIPE_SHADER_COMPUTE
)) {
710 if (nvc0
->constbuf
[s
][i
].user
)
711 nvc0
->constbuf
[s
][i
].u
.buf
= NULL
;
713 if (nvc0
->constbuf
[s
][i
].u
.buf
)
714 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_CB(i
));
716 nvc0
->dirty_cp
|= NVC0_NEW_CP_CONSTBUF
;
718 if (nvc0
->constbuf
[s
][i
].user
)
719 nvc0
->constbuf
[s
][i
].u
.buf
= NULL
;
721 if (nvc0
->constbuf
[s
][i
].u
.buf
)
722 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_CB(s
, i
));
724 nvc0
->dirty_3d
|= NVC0_NEW_3D_CONSTBUF
;
726 nvc0
->constbuf_dirty
[s
] |= 1 << i
;
728 if (nvc0
->constbuf
[s
][i
].u
.buf
)
729 nv04_resource(nvc0
->constbuf
[s
][i
].u
.buf
)->cb_bindings
[s
] &= ~(1 << i
);
730 pipe_resource_reference(&nvc0
->constbuf
[s
][i
].u
.buf
, res
);
732 nvc0
->constbuf
[s
][i
].user
= (cb
&& cb
->user_buffer
) ? true : false;
733 if (nvc0
->constbuf
[s
][i
].user
) {
734 nvc0
->constbuf
[s
][i
].u
.data
= cb
->user_buffer
;
735 nvc0
->constbuf
[s
][i
].size
= MIN2(cb
->buffer_size
, 0x10000);
736 nvc0
->constbuf_valid
[s
] |= 1 << i
;
737 nvc0
->constbuf_coherent
[s
] &= ~(1 << i
);
740 nvc0
->constbuf
[s
][i
].offset
= cb
->buffer_offset
;
741 nvc0
->constbuf
[s
][i
].size
= MIN2(align(cb
->buffer_size
, 0x100), 0x10000);
742 nvc0
->constbuf_valid
[s
] |= 1 << i
;
743 if (res
&& res
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
)
744 nvc0
->constbuf_coherent
[s
] |= 1 << i
;
746 nvc0
->constbuf_coherent
[s
] &= ~(1 << i
);
749 nvc0
->constbuf_valid
[s
] &= ~(1 << i
);
750 nvc0
->constbuf_coherent
[s
] &= ~(1 << i
);
754 /* =============================================================================
758 nvc0_set_blend_color(struct pipe_context
*pipe
,
759 const struct pipe_blend_color
*bcol
)
761 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
763 nvc0
->blend_colour
= *bcol
;
764 nvc0
->dirty_3d
|= NVC0_NEW_3D_BLEND_COLOUR
;
768 nvc0_set_stencil_ref(struct pipe_context
*pipe
,
769 const struct pipe_stencil_ref
*sr
)
771 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
773 nvc0
->stencil_ref
= *sr
;
774 nvc0
->dirty_3d
|= NVC0_NEW_3D_STENCIL_REF
;
778 nvc0_set_clip_state(struct pipe_context
*pipe
,
779 const struct pipe_clip_state
*clip
)
781 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
783 memcpy(nvc0
->clip
.ucp
, clip
->ucp
, sizeof(clip
->ucp
));
785 nvc0
->dirty_3d
|= NVC0_NEW_3D_CLIP
;
789 nvc0_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
791 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
793 nvc0
->sample_mask
= sample_mask
;
794 nvc0
->dirty_3d
|= NVC0_NEW_3D_SAMPLE_MASK
;
798 nvc0_set_min_samples(struct pipe_context
*pipe
, unsigned min_samples
)
800 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
802 if (nvc0
->min_samples
!= min_samples
) {
803 nvc0
->min_samples
= min_samples
;
804 nvc0
->dirty_3d
|= NVC0_NEW_3D_MIN_SAMPLES
;
809 nvc0_set_framebuffer_state(struct pipe_context
*pipe
,
810 const struct pipe_framebuffer_state
*fb
)
812 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
814 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_FB
);
816 util_copy_framebuffer_state(&nvc0
->framebuffer
, fb
);
818 nvc0
->dirty_3d
|= NVC0_NEW_3D_FRAMEBUFFER
;
822 nvc0_set_polygon_stipple(struct pipe_context
*pipe
,
823 const struct pipe_poly_stipple
*stipple
)
825 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
827 nvc0
->stipple
= *stipple
;
828 nvc0
->dirty_3d
|= NVC0_NEW_3D_STIPPLE
;
832 nvc0_set_scissor_states(struct pipe_context
*pipe
,
834 unsigned num_scissors
,
835 const struct pipe_scissor_state
*scissor
)
837 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
840 assert(start_slot
+ num_scissors
<= NVC0_MAX_VIEWPORTS
);
841 for (i
= 0; i
< num_scissors
; i
++) {
842 if (!memcmp(&nvc0
->scissors
[start_slot
+ i
], &scissor
[i
], sizeof(*scissor
)))
844 nvc0
->scissors
[start_slot
+ i
] = scissor
[i
];
845 nvc0
->scissors_dirty
|= 1 << (start_slot
+ i
);
846 nvc0
->dirty_3d
|= NVC0_NEW_3D_SCISSOR
;
851 nvc0_set_viewport_states(struct pipe_context
*pipe
,
853 unsigned num_viewports
,
854 const struct pipe_viewport_state
*vpt
)
856 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
859 assert(start_slot
+ num_viewports
<= NVC0_MAX_VIEWPORTS
);
860 for (i
= 0; i
< num_viewports
; i
++) {
861 if (!memcmp(&nvc0
->viewports
[start_slot
+ i
], &vpt
[i
], sizeof(*vpt
)))
863 nvc0
->viewports
[start_slot
+ i
] = vpt
[i
];
864 nvc0
->viewports_dirty
|= 1 << (start_slot
+ i
);
865 nvc0
->dirty_3d
|= NVC0_NEW_3D_VIEWPORT
;
871 nvc0_set_window_rectangles(struct pipe_context
*pipe
,
873 unsigned num_rectangles
,
874 const struct pipe_scissor_state
*rectangles
)
876 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
878 nvc0
->window_rect
.inclusive
= include
;
879 nvc0
->window_rect
.rects
= MIN2(num_rectangles
, NVC0_MAX_WINDOW_RECTANGLES
);
880 memcpy(nvc0
->window_rect
.rect
, rectangles
,
881 sizeof(struct pipe_scissor_state
) * nvc0
->window_rect
.rects
);
883 nvc0
->dirty_3d
|= NVC0_NEW_3D_WINDOW_RECTS
;
887 nvc0_set_tess_state(struct pipe_context
*pipe
,
888 const float default_tess_outer
[4],
889 const float default_tess_inner
[2])
891 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
893 memcpy(nvc0
->default_tess_outer
, default_tess_outer
, 4 * sizeof(float));
894 memcpy(nvc0
->default_tess_inner
, default_tess_inner
, 2 * sizeof(float));
895 nvc0
->dirty_3d
|= NVC0_NEW_3D_TESSFACTOR
;
899 nvc0_set_vertex_buffers(struct pipe_context
*pipe
,
900 unsigned start_slot
, unsigned count
,
901 const struct pipe_vertex_buffer
*vb
)
903 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
906 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_VTX
);
907 nvc0
->dirty_3d
|= NVC0_NEW_3D_ARRAYS
;
909 util_set_vertex_buffers_count(nvc0
->vtxbuf
, &nvc0
->num_vtxbufs
, vb
,
913 nvc0
->vbo_user
&= ~(((1ull << count
) - 1) << start_slot
);
914 nvc0
->constant_vbos
&= ~(((1ull << count
) - 1) << start_slot
);
915 nvc0
->vtxbufs_coherent
&= ~(((1ull << count
) - 1) << start_slot
);
919 for (i
= 0; i
< count
; ++i
) {
920 unsigned dst_index
= start_slot
+ i
;
922 if (vb
[i
].user_buffer
) {
923 nvc0
->vbo_user
|= 1 << dst_index
;
924 if (!vb
[i
].stride
&& nvc0
->screen
->eng3d
->oclass
< GM107_3D_CLASS
)
925 nvc0
->constant_vbos
|= 1 << dst_index
;
927 nvc0
->constant_vbos
&= ~(1 << dst_index
);
928 nvc0
->vtxbufs_coherent
&= ~(1 << dst_index
);
930 nvc0
->vbo_user
&= ~(1 << dst_index
);
931 nvc0
->constant_vbos
&= ~(1 << dst_index
);
934 vb
[i
].buffer
->flags
& PIPE_RESOURCE_FLAG_MAP_COHERENT
)
935 nvc0
->vtxbufs_coherent
|= (1 << dst_index
);
937 nvc0
->vtxbufs_coherent
&= ~(1 << dst_index
);
943 nvc0_set_index_buffer(struct pipe_context
*pipe
,
944 const struct pipe_index_buffer
*ib
)
946 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
948 if (nvc0
->idxbuf
.buffer
)
949 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_IDX
);
952 pipe_resource_reference(&nvc0
->idxbuf
.buffer
, ib
->buffer
);
953 nvc0
->idxbuf
.index_size
= ib
->index_size
;
955 nvc0
->idxbuf
.offset
= ib
->offset
;
956 nvc0
->dirty_3d
|= NVC0_NEW_3D_IDXBUF
;
958 nvc0
->idxbuf
.user_buffer
= ib
->user_buffer
;
959 nvc0
->dirty_3d
&= ~NVC0_NEW_3D_IDXBUF
;
962 nvc0
->dirty_3d
&= ~NVC0_NEW_3D_IDXBUF
;
963 pipe_resource_reference(&nvc0
->idxbuf
.buffer
, NULL
);
968 nvc0_vertex_state_bind(struct pipe_context
*pipe
, void *hwcso
)
970 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
972 nvc0
->vertex
= hwcso
;
973 nvc0
->dirty_3d
|= NVC0_NEW_3D_VERTEX
;
976 static struct pipe_stream_output_target
*
977 nvc0_so_target_create(struct pipe_context
*pipe
,
978 struct pipe_resource
*res
,
979 unsigned offset
, unsigned size
)
981 struct nv04_resource
*buf
= (struct nv04_resource
*)res
;
982 struct nvc0_so_target
*targ
= MALLOC_STRUCT(nvc0_so_target
);
986 targ
->pq
= pipe
->create_query(pipe
, NVC0_HW_QUERY_TFB_BUFFER_OFFSET
, 0);
993 targ
->pipe
.buffer_size
= size
;
994 targ
->pipe
.buffer_offset
= offset
;
995 targ
->pipe
.context
= pipe
;
996 targ
->pipe
.buffer
= NULL
;
997 pipe_resource_reference(&targ
->pipe
.buffer
, res
);
998 pipe_reference_init(&targ
->pipe
.reference
, 1);
1000 assert(buf
->base
.target
== PIPE_BUFFER
);
1001 util_range_add(&buf
->valid_buffer_range
, offset
, offset
+ size
);
1007 nvc0_so_target_save_offset(struct pipe_context
*pipe
,
1008 struct pipe_stream_output_target
*ptarg
,
1009 unsigned index
, bool *serialize
)
1011 struct nvc0_so_target
*targ
= nvc0_so_target(ptarg
);
1015 PUSH_SPACE(nvc0_context(pipe
)->base
.pushbuf
, 1);
1016 IMMED_NVC0(nvc0_context(pipe
)->base
.pushbuf
, NVC0_3D(SERIALIZE
), 0);
1018 NOUVEAU_DRV_STAT(nouveau_screen(pipe
->screen
), gpu_serialize_count
, 1);
1021 nvc0_query(targ
->pq
)->index
= index
;
1022 pipe
->end_query(pipe
, targ
->pq
);
1026 nvc0_so_target_destroy(struct pipe_context
*pipe
,
1027 struct pipe_stream_output_target
*ptarg
)
1029 struct nvc0_so_target
*targ
= nvc0_so_target(ptarg
);
1030 pipe
->destroy_query(pipe
, targ
->pq
);
1031 pipe_resource_reference(&targ
->pipe
.buffer
, NULL
);
1036 nvc0_set_transform_feedback_targets(struct pipe_context
*pipe
,
1037 unsigned num_targets
,
1038 struct pipe_stream_output_target
**targets
,
1039 const unsigned *offsets
)
1041 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
1043 bool serialize
= true;
1045 assert(num_targets
<= 4);
1047 for (i
= 0; i
< num_targets
; ++i
) {
1048 const bool changed
= nvc0
->tfbbuf
[i
] != targets
[i
];
1049 const bool append
= (offsets
[i
] == ((unsigned)-1));
1050 if (!changed
&& append
)
1052 nvc0
->tfbbuf_dirty
|= 1 << i
;
1054 if (nvc0
->tfbbuf
[i
] && changed
)
1055 nvc0_so_target_save_offset(pipe
, nvc0
->tfbbuf
[i
], i
, &serialize
);
1057 if (targets
[i
] && !append
)
1058 nvc0_so_target(targets
[i
])->clean
= true;
1060 pipe_so_target_reference(&nvc0
->tfbbuf
[i
], targets
[i
]);
1062 for (; i
< nvc0
->num_tfbbufs
; ++i
) {
1063 if (nvc0
->tfbbuf
[i
]) {
1064 nvc0
->tfbbuf_dirty
|= 1 << i
;
1065 nvc0_so_target_save_offset(pipe
, nvc0
->tfbbuf
[i
], i
, &serialize
);
1066 pipe_so_target_reference(&nvc0
->tfbbuf
[i
], NULL
);
1069 nvc0
->num_tfbbufs
= num_targets
;
1071 if (nvc0
->tfbbuf_dirty
) {
1072 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_TFB
);
1073 nvc0
->dirty_3d
|= NVC0_NEW_3D_TFB_TARGETS
;
1078 nvc0_bind_surfaces_range(struct nvc0_context
*nvc0
, const unsigned t
,
1079 unsigned start
, unsigned nr
,
1080 struct pipe_surface
**psurfaces
)
1082 const unsigned end
= start
+ nr
;
1083 const unsigned mask
= ((1 << nr
) - 1) << start
;
1087 for (i
= start
; i
< end
; ++i
) {
1088 const unsigned p
= i
- start
;
1090 nvc0
->surfaces_valid
[t
] |= (1 << i
);
1092 nvc0
->surfaces_valid
[t
] &= ~(1 << i
);
1093 pipe_surface_reference(&nvc0
->surfaces
[t
][i
], psurfaces
[p
]);
1096 for (i
= start
; i
< end
; ++i
)
1097 pipe_surface_reference(&nvc0
->surfaces
[t
][i
], NULL
);
1098 nvc0
->surfaces_valid
[t
] &= ~mask
;
1100 nvc0
->surfaces_dirty
[t
] |= mask
;
1103 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_SUF
);
1105 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_SUF
);
1109 nvc0_set_compute_resources(struct pipe_context
*pipe
,
1110 unsigned start
, unsigned nr
,
1111 struct pipe_surface
**resources
)
1113 nvc0_bind_surfaces_range(nvc0_context(pipe
), 1, start
, nr
, resources
);
1115 nvc0_context(pipe
)->dirty_cp
|= NVC0_NEW_CP_SURFACES
;
1119 nvc0_bind_images_range(struct nvc0_context
*nvc0
, const unsigned s
,
1120 unsigned start
, unsigned nr
,
1121 const struct pipe_image_view
*pimages
)
1123 const unsigned end
= start
+ nr
;
1130 for (i
= start
; i
< end
; ++i
) {
1131 struct pipe_image_view
*img
= &nvc0
->images
[s
][i
];
1132 const unsigned p
= i
- start
;
1134 if (img
->resource
== pimages
[p
].resource
&&
1135 img
->format
== pimages
[p
].format
&&
1136 img
->access
== pimages
[p
].access
) {
1137 if (img
->resource
== NULL
)
1139 if (img
->resource
->target
== PIPE_BUFFER
&&
1140 img
->u
.buf
.offset
== pimages
[p
].u
.buf
.offset
&&
1141 img
->u
.buf
.size
== pimages
[p
].u
.buf
.size
)
1143 if (img
->resource
->target
!= PIPE_BUFFER
&&
1144 img
->u
.tex
.first_layer
== pimages
[p
].u
.tex
.first_layer
&&
1145 img
->u
.tex
.last_layer
== pimages
[p
].u
.tex
.last_layer
&&
1146 img
->u
.tex
.level
== pimages
[p
].u
.tex
.level
)
1151 if (pimages
[p
].resource
)
1152 nvc0
->images_valid
[s
] |= (1 << i
);
1154 nvc0
->images_valid
[s
] &= ~(1 << i
);
1156 img
->format
= pimages
[p
].format
;
1157 img
->access
= pimages
[p
].access
;
1158 if (pimages
[p
].resource
&& pimages
[p
].resource
->target
== PIPE_BUFFER
)
1159 img
->u
.buf
= pimages
[p
].u
.buf
;
1161 img
->u
.tex
= pimages
[p
].u
.tex
;
1163 pipe_resource_reference(
1164 &img
->resource
, pimages
[p
].resource
);
1166 if (nvc0
->screen
->base
.class_3d
>= GM107_3D_CLASS
) {
1167 if (nvc0
->images_tic
[s
][i
]) {
1168 struct nv50_tic_entry
*old
=
1169 nv50_tic_entry(nvc0
->images_tic
[s
][i
]);
1170 nvc0_screen_tic_unlock(nvc0
->screen
, old
);
1171 pipe_sampler_view_reference(&nvc0
->images_tic
[s
][i
], NULL
);
1174 nvc0
->images_tic
[s
][i
] =
1175 gm107_create_texture_view_from_image(&nvc0
->base
.pipe
,
1182 mask
= ((1 << nr
) - 1) << start
;
1183 if (!(nvc0
->images_valid
[s
] & mask
))
1185 for (i
= start
; i
< end
; ++i
) {
1186 pipe_resource_reference(&nvc0
->images
[s
][i
].resource
, NULL
);
1187 if (nvc0
->screen
->base
.class_3d
>= GM107_3D_CLASS
) {
1188 struct nv50_tic_entry
*old
= nv50_tic_entry(nvc0
->images_tic
[s
][i
]);
1190 nvc0_screen_tic_unlock(nvc0
->screen
, old
);
1191 pipe_sampler_view_reference(&nvc0
->images_tic
[s
][i
], NULL
);
1195 nvc0
->images_valid
[s
] &= ~mask
;
1197 nvc0
->images_dirty
[s
] |= mask
;
1200 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_SUF
);
1202 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_SUF
);
1208 nvc0_set_shader_images(struct pipe_context
*pipe
,
1209 enum pipe_shader_type shader
,
1210 unsigned start
, unsigned nr
,
1211 const struct pipe_image_view
*images
)
1213 const unsigned s
= nvc0_shader_stage(shader
);
1214 if (!nvc0_bind_images_range(nvc0_context(pipe
), s
, start
, nr
, images
))
1218 nvc0_context(pipe
)->dirty_cp
|= NVC0_NEW_CP_SURFACES
;
1220 nvc0_context(pipe
)->dirty_3d
|= NVC0_NEW_3D_SURFACES
;
1224 nvc0_bind_buffers_range(struct nvc0_context
*nvc0
, const unsigned t
,
1225 unsigned start
, unsigned nr
,
1226 const struct pipe_shader_buffer
*pbuffers
)
1228 const unsigned end
= start
+ nr
;
1235 for (i
= start
; i
< end
; ++i
) {
1236 struct pipe_shader_buffer
*buf
= &nvc0
->buffers
[t
][i
];
1237 const unsigned p
= i
- start
;
1238 if (buf
->buffer
== pbuffers
[p
].buffer
&&
1239 buf
->buffer_offset
== pbuffers
[p
].buffer_offset
&&
1240 buf
->buffer_size
== pbuffers
[p
].buffer_size
)
1244 if (pbuffers
[p
].buffer
)
1245 nvc0
->buffers_valid
[t
] |= (1 << i
);
1247 nvc0
->buffers_valid
[t
] &= ~(1 << i
);
1248 buf
->buffer_offset
= pbuffers
[p
].buffer_offset
;
1249 buf
->buffer_size
= pbuffers
[p
].buffer_size
;
1250 pipe_resource_reference(&buf
->buffer
, pbuffers
[p
].buffer
);
1255 mask
= ((1 << nr
) - 1) << start
;
1256 if (!(nvc0
->buffers_valid
[t
] & mask
))
1258 for (i
= start
; i
< end
; ++i
)
1259 pipe_resource_reference(&nvc0
->buffers
[t
][i
].buffer
, NULL
);
1260 nvc0
->buffers_valid
[t
] &= ~mask
;
1262 nvc0
->buffers_dirty
[t
] |= mask
;
1265 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_BUF
);
1267 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_3D_BUF
);
1273 nvc0_set_shader_buffers(struct pipe_context
*pipe
,
1274 enum pipe_shader_type shader
,
1275 unsigned start
, unsigned nr
,
1276 const struct pipe_shader_buffer
*buffers
)
1278 const unsigned s
= nvc0_shader_stage(shader
);
1279 if (!nvc0_bind_buffers_range(nvc0_context(pipe
), s
, start
, nr
, buffers
))
1283 nvc0_context(pipe
)->dirty_cp
|= NVC0_NEW_CP_BUFFERS
;
1285 nvc0_context(pipe
)->dirty_3d
|= NVC0_NEW_3D_BUFFERS
;
1289 nvc0_set_global_handle(uint32_t *phandle
, struct pipe_resource
*res
)
1291 struct nv04_resource
*buf
= nv04_resource(res
);
1293 uint64_t limit
= (buf
->address
+ buf
->base
.width0
) - 1;
1294 if (limit
< (1ULL << 32)) {
1295 *phandle
= (uint32_t)buf
->address
;
1297 NOUVEAU_ERR("Cannot map into TGSI_RESOURCE_GLOBAL: "
1298 "resource not contained within 32-bit address space !\n");
1307 nvc0_set_global_bindings(struct pipe_context
*pipe
,
1308 unsigned start
, unsigned nr
,
1309 struct pipe_resource
**resources
,
1312 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
1313 struct pipe_resource
**ptr
;
1315 const unsigned end
= start
+ nr
;
1317 if (nvc0
->global_residents
.size
<= (end
* sizeof(struct pipe_resource
*))) {
1318 const unsigned old_size
= nvc0
->global_residents
.size
;
1319 const unsigned req_size
= end
* sizeof(struct pipe_resource
*);
1320 util_dynarray_resize(&nvc0
->global_residents
, req_size
);
1321 memset((uint8_t *)nvc0
->global_residents
.data
+ old_size
, 0,
1322 req_size
- old_size
);
1326 ptr
= util_dynarray_element(
1327 &nvc0
->global_residents
, struct pipe_resource
*, start
);
1328 for (i
= 0; i
< nr
; ++i
) {
1329 pipe_resource_reference(&ptr
[i
], resources
[i
]);
1330 nvc0_set_global_handle(handles
[i
], resources
[i
]);
1333 ptr
= util_dynarray_element(
1334 &nvc0
->global_residents
, struct pipe_resource
*, start
);
1335 for (i
= 0; i
< nr
; ++i
)
1336 pipe_resource_reference(&ptr
[i
], NULL
);
1339 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_GLOBAL
);
1341 nvc0
->dirty_cp
|= NVC0_NEW_CP_GLOBALS
;
1345 nvc0_init_state_functions(struct nvc0_context
*nvc0
)
1347 struct pipe_context
*pipe
= &nvc0
->base
.pipe
;
1349 pipe
->create_blend_state
= nvc0_blend_state_create
;
1350 pipe
->bind_blend_state
= nvc0_blend_state_bind
;
1351 pipe
->delete_blend_state
= nvc0_blend_state_delete
;
1353 pipe
->create_rasterizer_state
= nvc0_rasterizer_state_create
;
1354 pipe
->bind_rasterizer_state
= nvc0_rasterizer_state_bind
;
1355 pipe
->delete_rasterizer_state
= nvc0_rasterizer_state_delete
;
1357 pipe
->create_depth_stencil_alpha_state
= nvc0_zsa_state_create
;
1358 pipe
->bind_depth_stencil_alpha_state
= nvc0_zsa_state_bind
;
1359 pipe
->delete_depth_stencil_alpha_state
= nvc0_zsa_state_delete
;
1361 pipe
->create_sampler_state
= nv50_sampler_state_create
;
1362 pipe
->delete_sampler_state
= nvc0_sampler_state_delete
;
1363 pipe
->bind_sampler_states
= nvc0_bind_sampler_states
;
1365 pipe
->create_sampler_view
= nvc0_create_sampler_view
;
1366 pipe
->sampler_view_destroy
= nvc0_sampler_view_destroy
;
1367 pipe
->set_sampler_views
= nvc0_set_sampler_views
;
1369 pipe
->create_vs_state
= nvc0_vp_state_create
;
1370 pipe
->create_fs_state
= nvc0_fp_state_create
;
1371 pipe
->create_gs_state
= nvc0_gp_state_create
;
1372 pipe
->create_tcs_state
= nvc0_tcp_state_create
;
1373 pipe
->create_tes_state
= nvc0_tep_state_create
;
1374 pipe
->bind_vs_state
= nvc0_vp_state_bind
;
1375 pipe
->bind_fs_state
= nvc0_fp_state_bind
;
1376 pipe
->bind_gs_state
= nvc0_gp_state_bind
;
1377 pipe
->bind_tcs_state
= nvc0_tcp_state_bind
;
1378 pipe
->bind_tes_state
= nvc0_tep_state_bind
;
1379 pipe
->delete_vs_state
= nvc0_sp_state_delete
;
1380 pipe
->delete_fs_state
= nvc0_sp_state_delete
;
1381 pipe
->delete_gs_state
= nvc0_sp_state_delete
;
1382 pipe
->delete_tcs_state
= nvc0_sp_state_delete
;
1383 pipe
->delete_tes_state
= nvc0_sp_state_delete
;
1385 pipe
->create_compute_state
= nvc0_cp_state_create
;
1386 pipe
->bind_compute_state
= nvc0_cp_state_bind
;
1387 pipe
->delete_compute_state
= nvc0_sp_state_delete
;
1389 pipe
->set_blend_color
= nvc0_set_blend_color
;
1390 pipe
->set_stencil_ref
= nvc0_set_stencil_ref
;
1391 pipe
->set_clip_state
= nvc0_set_clip_state
;
1392 pipe
->set_sample_mask
= nvc0_set_sample_mask
;
1393 pipe
->set_min_samples
= nvc0_set_min_samples
;
1394 pipe
->set_constant_buffer
= nvc0_set_constant_buffer
;
1395 pipe
->set_framebuffer_state
= nvc0_set_framebuffer_state
;
1396 pipe
->set_polygon_stipple
= nvc0_set_polygon_stipple
;
1397 pipe
->set_scissor_states
= nvc0_set_scissor_states
;
1398 pipe
->set_viewport_states
= nvc0_set_viewport_states
;
1399 pipe
->set_window_rectangles
= nvc0_set_window_rectangles
;
1400 pipe
->set_tess_state
= nvc0_set_tess_state
;
1402 pipe
->create_vertex_elements_state
= nvc0_vertex_state_create
;
1403 pipe
->delete_vertex_elements_state
= nvc0_vertex_state_delete
;
1404 pipe
->bind_vertex_elements_state
= nvc0_vertex_state_bind
;
1406 pipe
->set_vertex_buffers
= nvc0_set_vertex_buffers
;
1407 pipe
->set_index_buffer
= nvc0_set_index_buffer
;
1409 pipe
->create_stream_output_target
= nvc0_so_target_create
;
1410 pipe
->stream_output_target_destroy
= nvc0_so_target_destroy
;
1411 pipe
->set_stream_output_targets
= nvc0_set_transform_feedback_targets
;
1413 pipe
->set_global_binding
= nvc0_set_global_bindings
;
1414 pipe
->set_compute_resources
= nvc0_set_compute_resources
;
1415 pipe
->set_shader_images
= nvc0_set_shader_images
;
1416 pipe
->set_shader_buffers
= nvc0_set_shader_buffers
;
1418 nvc0
->sample_mask
= ~0;
1419 nvc0
->min_samples
= 1;
1420 nvc0
->default_tess_outer
[0] =
1421 nvc0
->default_tess_outer
[1] =
1422 nvc0
->default_tess_outer
[2] =
1423 nvc0
->default_tess_outer
[3] = 1.0;
1424 nvc0
->default_tess_inner
[0] =
1425 nvc0
->default_tess_inner
[1] = 1.0;